his_api_controller.go 436KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. 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. }
  88. func (c *HisApiController) GetFaPiaoNumber() {
  89. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  90. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  91. fmt.Println(count)
  92. var zero string
  93. number := count + 1
  94. if number >= 1000 {
  95. zero = "0000" + strconv.FormatInt(number, 10)
  96. } else if number >= 10000 {
  97. zero = "000" + strconv.FormatInt(number, 10)
  98. } else if number >= 100000 {
  99. zero = "00" + strconv.FormatInt(number, 10)
  100. } else if number >= 1000000 {
  101. zero = "0" + strconv.FormatInt(number, 10)
  102. } else {
  103. zero = strconv.FormatInt(number, 10)
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "fapiao_number": zero,
  107. })
  108. return
  109. }
  110. func (c *HisApiController) ChangeOrderDesc() {
  111. id, _ := c.GetInt64("id")
  112. desc := c.GetString("desc")
  113. change_type := c.GetString("change_type")
  114. order, _ := service.GetHisOrderByID(id)
  115. if order.ID == 0 {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. switch change_type {
  120. case "oth_desc":
  121. order.OthDesc = desc
  122. break
  123. case "cash_pay":
  124. order.CashPay = desc
  125. break
  126. case "jifen_pay":
  127. order.JifenPay = desc
  128. break
  129. case "band_card_pay":
  130. order.BandCardPay = desc
  131. break
  132. case "ali_pay":
  133. order.AliPay = desc
  134. break
  135. case "wechat_pay":
  136. order.WechatPay = desc
  137. break
  138. case "fa_piao_number":
  139. order.FaPiaoNumber = desc
  140. break
  141. case "fa_piao_code":
  142. order.FaPiaoCode = desc
  143. break
  144. }
  145. err := service.SaveHisOrder(&order)
  146. if err == nil {
  147. c.ServeSuccessJSON(map[string]interface{}{
  148. "msg": "修改成功",
  149. })
  150. return
  151. } else {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  153. return
  154. }
  155. }
  156. func (c *HisApiController) GetMonthHisPatient() {
  157. record_date := c.GetString("record_date")
  158. //order_status, _ := c.GetInt64("type")
  159. timeLayout := "2006-01-02"
  160. loc, _ := time.LoadLocation("Local")
  161. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  162. if err != nil {
  163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  164. return
  165. }
  166. recordDateTime := theTime.Unix()
  167. adminInfo := c.GetAdminUserInfo()
  168. var tempPatients []service.NewTempPatients
  169. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  170. // 获取当前时间
  171. now := time.Now()
  172. // 获取本月的第一天
  173. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  174. // 获取下个月的第一天
  175. nextMonth := firstDay.AddDate(0, 1, 0)
  176. // 获取本月的最后一天
  177. lastDay := nextMonth.Add(-time.Nanosecond)
  178. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  179. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  180. var patients []service.NewTempPatients
  181. var patients_two []service.NewTempPatients
  182. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  183. for _, item := range tempPatients {
  184. //过滤掉没挂号的和没开处方的
  185. if len(item.HisPrescription) > 0 {
  186. patients = append(patients, item)
  187. patients_two = append(patients_two, item)
  188. }
  189. ////过滤掉没挂号的
  190. //if len(item.HisPatient) > 0 {
  191. //}
  192. }
  193. } else {
  194. for _, item := range tempPatients {
  195. //过滤掉没挂号的和没开处方的
  196. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  197. patients = append(patients, item)
  198. }
  199. ////过滤掉没挂号的
  200. //if len(item.HisPatient) > 0 {
  201. // patients_two = append(patients_two, item)
  202. //}
  203. }
  204. }
  205. c.ServeSuccessJSON(map[string]interface{}{
  206. "list": patients,
  207. "list_two": patients_two,
  208. "chargePatients": chargePatients,
  209. })
  210. }
  211. func (c *HisApiController) GetBatchSettleAccounts() {
  212. order_ids := c.GetString("order_ids")
  213. admin_user_id, _ := c.GetInt64("admin_user_id")
  214. adminUser := c.GetAdminUserInfo()
  215. orders := strings.Split(order_ids, ",")
  216. var newOrders []models.Orders
  217. for _, item := range orders {
  218. order, _ := service.GetHisOrderByIDTenOne(item)
  219. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  220. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  221. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  222. orderInfos = append(orderInfos, orderInfos_two...)
  223. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  224. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  225. var diagnosis_ids []string
  226. if his.ID > 0 {
  227. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  228. } else {
  229. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  230. }
  231. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  232. var dia_config []*models.HisXtDiagnoseConfig
  233. var name string
  234. for _, item := range diagnosis_ids {
  235. id, _ := strconv.ParseInt(item, 10, 64)
  236. diagnosisConfig, _ := service.FindDiagnoseById(id)
  237. dia_config = append(dia_config, diagnosisConfig)
  238. if len(name) == 0 {
  239. name = diagnosisConfig.ClassName
  240. } else {
  241. name = name + "," + diagnosisConfig.ClassName
  242. }
  243. }
  244. var bedCostTotal float64 = 0 //床位总费
  245. var bedCostSelfTotal float64 = 0 //床位自费
  246. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  247. var bedSelfTotal float64 = 0 //床位部分项目自费
  248. var bedInscpTotal float64 = 0 //床位部分项目自费
  249. var operationCostTotal float64 = 0 //手术费
  250. var operationCostSelfTotal float64 = 0 //手术费
  251. var operationCostPartSelfTotal float64 = 0 //手术费
  252. var operationSelfTotal float64 = 0 //床位部分项目自费
  253. var operationInscpTotal float64 = 0 //床位部分项目自费
  254. var otherCostTotal float64 = 0 //其他费用
  255. var otherCostSelfTotal float64 = 0 //其他费用
  256. var otherCostPartSelfTotal float64 = 0 //其他费用
  257. var otherSelfTotal float64 = 0 //床位部分项目自费
  258. var otherInscpTotal float64 = 0 //床位部分项目自费
  259. var materialCostTotal float64 = 0 //材料费
  260. var materialCostSelfTotal float64 = 0 //材料费
  261. var materialCostPartSelfTotal float64 = 0 //材料费
  262. var materialSelfTotal float64 = 0 //床位部分项目自费
  263. var materialInscpTotal float64 = 0 //床位部分项目自费
  264. var westernMedicineCostTotal float64 = 0 //西药费
  265. var westernMedicineCostSelfTotal float64 = 0 //西药费
  266. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  267. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  268. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  269. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  270. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  271. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  272. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  273. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  274. var checkCostTotal float64 = 0 //检查费
  275. var checkCostSelfTotal float64 = 0 //检查费
  276. var checkCostPartSelfTotal float64 = 0 //检查费
  277. var checkSelfTotal float64 = 0 //床位部分项目自费
  278. var checkInscpTotal float64 = 0 //床位部分项目自费
  279. var laboratoryCostTotal float64 = 0 //化验费
  280. var laboratoryCostSelfTotal float64 = 0 //化验费
  281. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  282. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  283. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  284. var treatCostTotal float64 = 0 //治疗费用
  285. var treatCostSelfTotal float64 = 0 //治疗费用
  286. var treatCostPartSelfTotal float64 = 0 //治疗费用
  287. var treatSelfTotal float64 = 0 //床位部分项目自费
  288. var treatInscpTotal float64 = 0 //床位部分项目自费
  289. decimal.DivisionPrecision = 2
  290. for _, item := range orderInfos {
  291. if item.MedChrgitmType == "01" { //床位费
  292. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  293. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  294. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  295. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  296. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  297. }
  298. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  299. if item.MedChrgitmType == "03" { //检查费
  300. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  301. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  302. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  303. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  304. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  305. }
  306. } else {
  307. if item.MedChrgitmType == "03" { //检查费
  308. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  309. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  310. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  311. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  312. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  313. }
  314. }
  315. if item.MedChrgitmType == "04" { //化验费
  316. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  320. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  321. }
  322. if item.MedChrgitmType == "05" { //治疗费
  323. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  324. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  325. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  326. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  327. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  328. }
  329. if item.MedChrgitmType == "06" { //手术费
  330. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  331. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  332. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  333. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  334. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  335. }
  336. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  337. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  338. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  339. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  340. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  341. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  342. }
  343. if item.MedChrgitmType == "09" { //西药费
  344. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  345. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  346. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  347. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  348. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "11" { //中成费
  351. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  355. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  356. }
  357. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  358. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  359. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  360. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  361. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  362. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  363. }
  364. }
  365. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  366. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  367. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  368. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  369. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  370. var doctor_name string
  371. if roles.ID == 0 {
  372. doctor_name = "管理员"
  373. } else {
  374. doctor_name = roles.UserName
  375. }
  376. yiliao_leibie := ""
  377. switch order.MedType {
  378. case "11":
  379. yiliao_leibie = "普通门诊"
  380. break
  381. case "12":
  382. yiliao_leibie = "门诊挂号"
  383. break
  384. case "13":
  385. yiliao_leibie = "急诊"
  386. break
  387. case "14":
  388. yiliao_leibie = "门诊特殊病"
  389. break
  390. case "15":
  391. yiliao_leibie = "门诊统筹"
  392. break
  393. case "16":
  394. yiliao_leibie = "门诊慢性病"
  395. break
  396. case "21":
  397. yiliao_leibie = "普通住院"
  398. break
  399. }
  400. var newOrder models.Orders
  401. newOrder.Diagnosis = name
  402. newOrder.OrderInfos = orderInfos
  403. newOrder.Number = order.MdtrtId
  404. newOrder.Date = order.SettleAccountsDate
  405. newOrder.ChargeAdmin = charge_admin
  406. newOrder.PrintorAdmin = printor_admin
  407. newOrder.Order = order
  408. newOrder.BedCostTotal = bedCostTotal
  409. newOrder.BedCostSelfTotal = bedCostSelfTotal
  410. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  411. newOrder.BedSelfTotal = bedSelfTotal
  412. newOrder.BedInscpTotal = bedInscpTotal
  413. newOrder.OperationCostTotal = operationCostTotal
  414. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  415. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  416. newOrder.OperationSelfTotal = operationSelfTotal
  417. newOrder.OperationInscpTotal = operationInscpTotal
  418. newOrder.OtherCostTotal = otherCostTotal
  419. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  420. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  421. newOrder.OtherSelfTotal = otherSelfTotal
  422. newOrder.OtherInscpTotal = otherInscpTotal
  423. newOrder.MaterialCostTotal = materialCostTotal
  424. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  425. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  426. newOrder.MaterialSelfTotal = materialSelfTotal
  427. newOrder.MaterialInscpTotal = materialInscpTotal
  428. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  429. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  430. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  431. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  432. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  433. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  434. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  435. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  436. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  437. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  438. newOrder.CheckCostTotal = checkCostTotal
  439. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  440. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  441. newOrder.CheckSelfTotal = checkSelfTotal
  442. newOrder.CheckInscpTotal = checkInscpTotal
  443. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  444. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  445. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  446. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  447. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  448. newOrder.TreatCostTotal = treatCostTotal
  449. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  450. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  451. newOrder.TreatSelfTotal = treatSelfTotal
  452. newOrder.TreatInscpTotal = treatInscpTotal
  453. newOrder.DoctorInfo = doctor_info
  454. newOrder.DoctorName = doctor_name
  455. newOrder.HealthCardNo = order.PsnNo
  456. newOrder.YiliaoLeibie = yiliao_leibie
  457. newOrder.Patient = patient
  458. newOrder.OrgName = miConfig.OrgName
  459. newOrder.OrgCode = miConfig.Code
  460. newOrder.OrderNumber = order.Number
  461. newOrder.HisPatient = his
  462. newOrder.DiaConfig = dia_config
  463. newOrders = append(newOrders, newOrder)
  464. }
  465. c.ServeSuccessJSON(map[string]interface{}{
  466. "orders": newOrders,
  467. })
  468. }
  469. func (c *HisApiController) GetTestOrder() {
  470. order_id, _ := c.GetInt64("order_id")
  471. admin_user_id, _ := c.GetInt64("admin_user_id")
  472. adminUser := c.GetAdminUserInfo()
  473. order, _ := service.GetHisOrderByID(order_id)
  474. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  475. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  476. orderInfos = append(orderInfos, orderInfos_two...)
  477. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  478. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  479. var dia_config []*models.HisXtDiagnoseConfig
  480. var name string
  481. var bedCostTotal float64 = 0 //床位总费
  482. var bedCostSelfTotal float64 = 0 //床位自费
  483. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  484. var bedSelfTotal float64 = 0 //床位部分项目自费
  485. var bedInscpTotal float64 = 0 //床位部分项目自费
  486. var operationCostTotal float64 = 0 //手术费
  487. var operationCostSelfTotal float64 = 0 //手术费
  488. var operationCostPartSelfTotal float64 = 0 //手术费
  489. var operationSelfTotal float64 = 0 //床位部分项目自费
  490. var operationInscpTotal float64 = 0 //床位部分项目自费
  491. var otherCostTotal float64 = 0 //其他费用
  492. var otherCostSelfTotal float64 = 0 //其他费用
  493. var otherCostPartSelfTotal float64 = 0 //其他费用
  494. var otherSelfTotal float64 = 0 //床位部分项目自费
  495. var otherInscpTotal float64 = 0 //床位部分项目自费
  496. var materialCostTotal float64 = 0 //材料费
  497. var materialCostSelfTotal float64 = 0 //材料费
  498. var materialCostPartSelfTotal float64 = 0 //材料费
  499. var materialSelfTotal float64 = 0 //床位部分项目自费
  500. var materialInscpTotal float64 = 0 //床位部分项目自费
  501. var westernMedicineCostTotal float64 = 0 //西药费
  502. var westernMedicineCostSelfTotal float64 = 0 //西药费
  503. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  504. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  505. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  506. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  507. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  508. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  509. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  510. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  511. var checkCostTotal float64 = 0 //检查费
  512. var checkCostSelfTotal float64 = 0 //检查费
  513. var checkCostPartSelfTotal float64 = 0 //检查费
  514. var checkSelfTotal float64 = 0 //床位部分项目自费
  515. var checkInscpTotal float64 = 0 //床位部分项目自费
  516. var laboratoryCostTotal float64 = 0 //化验费
  517. var laboratoryCostSelfTotal float64 = 0 //化验费
  518. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  519. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  520. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  521. var treatCostTotal float64 = 0 //治疗费用
  522. var treatCostSelfTotal float64 = 0 //治疗费用
  523. var treatCostPartSelfTotal float64 = 0 //治疗费用
  524. var treatSelfTotal float64 = 0 //床位部分项目自费
  525. var treatInscpTotal float64 = 0 //床位部分项目自费
  526. decimal.DivisionPrecision = 2
  527. for _, item := range orderInfos {
  528. if item.MedChrgitmType == "01" { //床位费
  529. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  530. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  531. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  532. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  533. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  534. }
  535. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  536. if item.MedChrgitmType == "03" { //检查费
  537. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  538. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  539. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  540. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  541. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  542. }
  543. } else {
  544. if item.MedChrgitmType == "03" { //检查费
  545. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  546. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  547. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  548. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  549. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  550. }
  551. }
  552. if item.MedChrgitmType == "04" { //化验费
  553. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  555. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  556. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  557. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  558. }
  559. if item.MedChrgitmType == "05" { //治疗费
  560. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  561. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  562. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  563. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  564. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  565. }
  566. if item.MedChrgitmType == "06" { //手术费
  567. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  568. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  569. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  570. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  571. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  572. }
  573. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  574. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  575. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  576. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  577. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  578. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  579. }
  580. if item.MedChrgitmType == "09" { //西药费
  581. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  582. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  583. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  584. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  585. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  586. }
  587. if item.MedChrgitmType == "11" { //中成费
  588. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  589. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  590. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  591. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  592. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  593. }
  594. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  595. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  596. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  597. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  598. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  599. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  600. }
  601. }
  602. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  603. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  604. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  605. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  606. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  607. var doctor_name string
  608. if roles.ID == 0 {
  609. doctor_name = "管理员"
  610. } else {
  611. doctor_name = roles.UserName
  612. }
  613. yiliao_leibie := ""
  614. switch order.MedType {
  615. case "11":
  616. yiliao_leibie = "普通门诊"
  617. break
  618. case "12":
  619. yiliao_leibie = "门诊挂号"
  620. break
  621. case "13":
  622. yiliao_leibie = "急诊"
  623. break
  624. case "14":
  625. yiliao_leibie = "门诊特殊病"
  626. break
  627. case "15":
  628. yiliao_leibie = "门诊统筹"
  629. break
  630. case "16":
  631. yiliao_leibie = "门诊慢性病"
  632. break
  633. case "21":
  634. yiliao_leibie = "普通住院"
  635. break
  636. }
  637. c.ServeSuccessJSON(map[string]interface{}{
  638. "diagnosis": name,
  639. "order_infos": orderInfos,
  640. "number": order.MdtrtId,
  641. "date": order.SettleAccountsDate,
  642. "charge_admin": charge_admin,
  643. "printor_admin": printor_admin,
  644. "info": order,
  645. "order": order,
  646. "bedCostTotal": bedCostTotal,
  647. "bedCostSelfTotal": bedCostSelfTotal,
  648. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  649. "bedSelfTotal": bedSelfTotal,
  650. "bedInscpTotal": bedInscpTotal,
  651. "operationCostTotal": operationCostTotal,
  652. "operationCostSelfTotal": operationCostSelfTotal,
  653. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  654. "operationSelfTotal": operationSelfTotal,
  655. "operationInscpTotal": operationInscpTotal,
  656. "otherCostTotal": otherCostTotal,
  657. "otherCostSelfTotal": otherCostSelfTotal,
  658. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  659. "otherSelfTotal": otherSelfTotal,
  660. "otherInscpTotal": otherInscpTotal,
  661. "materialCostTotal": materialCostTotal,
  662. "materialCostSelfTotal": materialCostSelfTotal,
  663. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  664. "materialSelfTotal": materialSelfTotal,
  665. "materialInscpTotal": materialInscpTotal,
  666. "westernMedicineCostTotal": westernMedicineCostTotal,
  667. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  668. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  669. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  670. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  671. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  672. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  673. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  674. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  675. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  676. "checkCostTotal": checkCostTotal,
  677. "checkCostSelfTotal": checkCostSelfTotal,
  678. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  679. "checkSelfTotal": checkSelfTotal,
  680. "checkInscpTotal": checkInscpTotal,
  681. "laboratoryCostTotal": laboratoryCostTotal,
  682. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  683. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  684. "laboratorySelfTotal": laboratorySelfTotal,
  685. "laboratoryInscpTotal": laboratoryInscpTotal,
  686. "treatCostTotal": treatCostTotal,
  687. "treatCostSelfTotal": treatCostSelfTotal,
  688. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  689. "treatSelfTotal": treatSelfTotal,
  690. "treatInscpTotal": treatInscpTotal,
  691. "doctor_info": doctor_info,
  692. "doctor_name": doctor_name,
  693. "health_card_no": order.PsnNo,
  694. "yiliao_leibie": yiliao_leibie,
  695. "patient": patient,
  696. "org_name": miConfig.OrgName,
  697. "org_code": miConfig.Code,
  698. "order_number": order.Number,
  699. "his_hospital": his_hospital,
  700. "dia_config": dia_config,
  701. })
  702. }
  703. func (c *PublicApiController) GetBaiLinExportData() {
  704. data := service.GetBaiLinOrderData()
  705. fmt.Println(len(data))
  706. var new_data []*models.NewCustomHisOrder
  707. for _, item := range data {
  708. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  709. new_data = append(new_data, item)
  710. }
  711. }
  712. fmt.Println(len(new_data))
  713. c.ServeSuccessJSON(map[string]interface{}{
  714. "list": new_data,
  715. })
  716. }
  717. func (c *HisApiController) GetHisUnChargePatientList() {
  718. record_date := c.GetString("record_date")
  719. sch_type, _ := c.GetInt64("sch_type")
  720. timeLayout := "2006-01-02"
  721. loc, _ := time.LoadLocation("Local")
  722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  723. if err != nil {
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  725. return
  726. }
  727. recordDateTime := theTime.Unix()
  728. adminInfo := c.GetAdminUserInfo()
  729. var tempPatients []*service.NewTempPatients
  730. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  731. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  732. var patients []*service.NewTempPatients
  733. var patients_two []*service.NewTempPatients
  734. for _, item := range tempPatients {
  735. //过滤掉没挂号的和没开处方的
  736. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  737. patients = append(patients, item)
  738. }
  739. //过滤掉没挂号的
  740. if len(item.HisPatient) > 0 {
  741. patients_two = append(patients_two, item)
  742. }
  743. }
  744. c.ServeSuccessJSON(map[string]interface{}{
  745. "list": patients,
  746. "list_two": patients_two,
  747. })
  748. }
  749. func (c *HisApiController) GetPrivateExpensesOrder() {
  750. //id, _ := c.GetInt64("id")
  751. //record_time := c.GetString("record_time")
  752. order_id, _ := c.GetInt64("order_id")
  753. admin_user_id, _ := c.GetInt64("admin_user_id")
  754. //timeLayout := "2006-01-02"
  755. //loc, _ := time.LoadLocation("Local")
  756. //
  757. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  758. //if err != nil {
  759. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  760. // return
  761. //}
  762. //recordDateTime := theTime.Unix()
  763. adminUser := c.GetAdminUserInfo()
  764. order, _ := service.GetHisOrderByID(order_id)
  765. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  766. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  767. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  768. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  769. //var config []*models.HisXtDiagnoseConfig
  770. var name string
  771. if order.PType == 1 {
  772. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  773. for _, item := range diagnosis_ids {
  774. id, _ := strconv.ParseInt(item, 10, 64)
  775. diagnosisConfig, _ := service.FindDiagnoseById(id)
  776. if len(name) == 0 {
  777. name = diagnosisConfig.ClassName
  778. } else {
  779. name = name + "," + diagnosisConfig.ClassName
  780. }
  781. }
  782. } else {
  783. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  784. for _, item := range diagnosis_ids {
  785. id, _ := strconv.ParseInt(item, 10, 64)
  786. diagnosisConfig, _ := service.FindDiagnoseById(id)
  787. if len(name) == 0 {
  788. name = diagnosisConfig.ClassName
  789. } else {
  790. name = name + "," + diagnosisConfig.ClassName
  791. }
  792. }
  793. }
  794. var bedCostTotal float64 = 0 //床位总费
  795. //var bedCostSelfTotal float64 = 0 //床位自费
  796. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  797. var operationCostTotal float64 = 0 //手术费
  798. //var operationCostSelfTotal float64 = 0 //手术费
  799. var operationCostPartSelfTotal float64 = 0 //手术费
  800. var otherCostTotal float64 = 0 //其他费用
  801. //var otherCostSelfTotal float64 = 0 //其他费用
  802. var otherCostPartSelfTotal float64 = 0 //其他费用
  803. var materialCostTotal float64 = 0 //材料费
  804. //var materialCostSelfTotal float64 = 0 //材料费
  805. var materialCostPartSelfTotal float64 = 0 //材料费
  806. var westernMedicineCostTotal float64 = 0 //西药费
  807. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  808. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  809. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  810. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  811. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  812. var checkCostTotal float64 = 0 //检查费
  813. //var checkCostSelfTotal float64 = 0 //检查费
  814. var checkCostPartSelfTotal float64 = 0 //检查费
  815. var laboratoryCostTotal float64 = 0 //化验费
  816. //var laboratoryCostSelfTotal float64 = 0 //化验费
  817. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  818. var treatCostTotal float64 = 0 //治疗费用
  819. //var treatCostSelfTotal float64 = 0 //治疗费用
  820. var treatCostPartSelfTotal float64 = 0 //治疗费用
  821. var zhenChaCostTotal float64 = 0 //其他费用
  822. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  823. decimal.DivisionPrecision = 2
  824. for _, item := range orderInfos {
  825. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  826. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  827. item.MedChrgitmType = "09"
  828. }
  829. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  830. if item.HisPrescriptionProject.Type == 2 {
  831. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  832. fmt.Println("CostClassify")
  833. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  834. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  835. case 0:
  836. item.MedChrgitmType = "0"
  837. break
  838. case 1:
  839. item.MedChrgitmType = "14"
  840. break
  841. case 2:
  842. item.MedChrgitmType = "05"
  843. break
  844. case 3:
  845. item.MedChrgitmType = "03"
  846. break
  847. case 4:
  848. item.MedChrgitmType = "03"
  849. break
  850. case 5:
  851. item.MedChrgitmType = "08"
  852. break
  853. case 6:
  854. item.MedChrgitmType = "14"
  855. break
  856. case 7:
  857. item.MedChrgitmType = "14"
  858. break
  859. case 8:
  860. item.MedChrgitmType = "03"
  861. break
  862. case 9:
  863. item.MedChrgitmType = "14"
  864. break
  865. case 10:
  866. item.MedChrgitmType = "14"
  867. break
  868. case 11:
  869. item.MedChrgitmType = "06"
  870. break
  871. case 12:
  872. item.MedChrgitmType = "12"
  873. break
  874. case 13:
  875. item.MedChrgitmType = "01"
  876. break
  877. case 14:
  878. item.MedChrgitmType = "04"
  879. break
  880. case 15:
  881. item.MedChrgitmType = "14"
  882. break
  883. }
  884. } else {
  885. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  886. case 1:
  887. item.MedChrgitmType = "14"
  888. break
  889. case 2:
  890. item.MedChrgitmType = "05"
  891. break
  892. case 3:
  893. item.MedChrgitmType = "04"
  894. break
  895. case 4:
  896. item.MedChrgitmType = "14"
  897. break
  898. case 5:
  899. item.MedChrgitmType = "08"
  900. break
  901. case 6:
  902. item.MedChrgitmType = "14"
  903. break
  904. case 7:
  905. item.MedChrgitmType = "14"
  906. break
  907. case 8:
  908. item.MedChrgitmType = "03"
  909. break
  910. case 9:
  911. item.MedChrgitmType = "14"
  912. break
  913. default:
  914. item.MedChrgitmType = "14"
  915. break
  916. }
  917. }
  918. } else if item.HisPrescriptionProject.Type == 3 {
  919. item.MedChrgitmType = "08"
  920. }
  921. }
  922. }
  923. order.PsnCashPay = order.MedfeeSumamt
  924. for _, item := range orderInfos {
  925. if item.MedChrgitmType == "01" { //床位费
  926. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  927. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  928. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  929. }
  930. if item.MedChrgitmType == "02" { //诊察费
  931. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  932. //zhenChaCostSelfTotal = zhenChaCostTotal
  933. }
  934. if item.MedChrgitmType == "03" { //检查费
  935. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  936. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  937. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  938. }
  939. if item.MedChrgitmType == "02" { //检查费
  940. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  941. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  942. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  943. }
  944. if item.MedChrgitmType == "04" { //化验费
  945. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  946. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  947. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  948. }
  949. if item.MedChrgitmType == "05" { //治疗费
  950. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  951. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  952. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  953. }
  954. if item.MedChrgitmType == "06" { //手术费
  955. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  956. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  957. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  958. }
  959. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  960. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  961. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  962. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  963. }
  964. if item.MedChrgitmType == "09" { //西药费
  965. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  966. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  967. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  968. }
  969. if item.MedChrgitmType == "11" { //中成费
  970. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  971. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  972. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  973. }
  974. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  975. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  976. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  977. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  978. }
  979. }
  980. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  981. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  982. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  983. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  984. c.ServeSuccessJSON(map[string]interface{}{
  985. "patient": patient,
  986. "order_infos": orderInfos,
  987. "diagnosis": name,
  988. "bedCostTotal": bedCostTotal,
  989. "bedCostSelfTotal": bedCostTotal,
  990. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  991. "operationCostTotal": operationCostTotal,
  992. "operationCostSelfTotal": operationCostTotal,
  993. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  994. "otherCostTotal": otherCostTotal,
  995. "otherCostSelfTotal": otherCostTotal,
  996. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  997. "materialCostTotal": materialCostTotal,
  998. "materialCostSelfTotal": materialCostTotal,
  999. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1000. "westernMedicineCostTotal": westernMedicineCostTotal,
  1001. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1002. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1003. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1004. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1005. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1006. "checkCostTotal": checkCostTotal,
  1007. "checkCostSelfTotal": checkCostTotal,
  1008. "zhenChaCostTotal": zhenChaCostTotal,
  1009. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1010. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1011. "laboratoryCostTotal": laboratoryCostTotal,
  1012. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1013. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1014. "treatCostTotal": treatCostTotal,
  1015. "treatCostSelfTotal": treatCostTotal,
  1016. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1017. "charge_admin": charge_admin,
  1018. "printor_admin": printor_admin,
  1019. "org_name": org.OrgName,
  1020. "org_code": miConfig.Code,
  1021. "name": patient.Name,
  1022. "number": order.MdtrtId,
  1023. "date": order.SettleAccountsDate,
  1024. "info": order,
  1025. "his_hospital": his_hospital,
  1026. "his": his,
  1027. })
  1028. }
  1029. func (c *HisApiController) RefudDetail() {
  1030. order_id, _ := c.GetInt64("order_id")
  1031. order, _ := service.GetHisOrderByID(order_id)
  1032. adminUser := c.GetAdminUserInfo()
  1033. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1034. c.ServeSuccessJSON(map[string]interface{}{
  1035. "msg": "撤销成功",
  1036. })
  1037. }
  1038. func (c *HisApiController) Sscard() {
  1039. //r := CardInit()
  1040. //if r == 0 {
  1041. // GetBaseInfo()
  1042. //}
  1043. //c.ServeSuccessJSON(map[string]interface{}{
  1044. // "list": "11",
  1045. //})
  1046. }
  1047. func GetBaseInfo() error {
  1048. //handle := syscall.MustLoadDLL("SSCard.dll")
  1049. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1050. //
  1051. //str := make([]byte, 256)
  1052. //str1 := make([]byte, 256)
  1053. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1054. //if ferr != nil {
  1055. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1056. // return ferr
  1057. //}
  1058. //
  1059. //fmt.Println(string(str))
  1060. //
  1061. //fmt.Println(r)
  1062. return nil
  1063. }
  1064. func CardInit() int {
  1065. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1066. //add := DllTestDef.MustFindProc("Init")
  1067. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1068. //if err != nil {
  1069. // fmt.Println("SSCard的运算结果为:", ret)
  1070. //}
  1071. //result := int(ret)
  1072. return 0
  1073. }
  1074. func IntPtr(n int) uintptr {
  1075. return uintptr(n)
  1076. }
  1077. func StrPtr(s string) uintptr {
  1078. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1079. }
  1080. func (c *HisApiController) GetHisPatientList() {
  1081. //types, _ := c.GetInt64("type", 0)
  1082. record_date := c.GetString("record_date")
  1083. sch_type, _ := c.GetInt64("sch_type")
  1084. timeLayout := "2006-01-02"
  1085. loc, _ := time.LoadLocation("Local")
  1086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1087. if err != nil {
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. return
  1090. }
  1091. recordDateTime := theTime.Unix()
  1092. adminInfo := c.GetAdminUserInfo()
  1093. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1094. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1095. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1096. //获取当前用户的信息
  1097. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1098. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1099. //获取所有科室信息
  1100. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1101. c.ServeSuccessJSON(map[string]interface{}{
  1102. "list": patients,
  1103. "list_two": patients_two,
  1104. "info": adminUserInfo,
  1105. "doctors": doctors,
  1106. "department": department,
  1107. })
  1108. }
  1109. type CustomTemplate struct {
  1110. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1111. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1112. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1113. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1114. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1115. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1116. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1117. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1118. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1119. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1120. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1121. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1122. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1123. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1124. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1125. }
  1126. func (c *HisApiController) GetHisPatientInfo() {
  1127. patient_id, _ := c.GetInt64("patient_id")
  1128. his_patient_id, _ := c.GetInt64("his_patient_id")
  1129. record_date := c.GetString("record_date")
  1130. number := c.GetString("number")
  1131. //start_time := c.GetString("start_time")
  1132. //end_time := c.GetString("end_time")
  1133. p_type, _ := c.GetInt64("p_type")
  1134. timeLayout := "2006-01-02"
  1135. loc, _ := time.LoadLocation("Local")
  1136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1137. if err != nil {
  1138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1139. return
  1140. }
  1141. recordDateTime := theTime.Unix()
  1142. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1143. //if err != nil {
  1144. //
  1145. //}
  1146. //startRecordDateTime := startTime.Unix()
  1147. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1148. //if err != nil {
  1149. //
  1150. //}
  1151. //endRecordDateTime := endTime.Unix()
  1152. admin := c.GetAdminUserInfo()
  1153. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1154. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1155. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1156. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1157. var prescriptions []*models.HisPrescription
  1158. var last_prescriptions []*models.HisPrescription
  1159. var sch_prescriptions []CustomTemplate
  1160. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1161. if p_type == 1 { //住院
  1162. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1163. for _, item := range prescriptions {
  1164. for _, subItem := range item.HisDoctorAdviceInfo {
  1165. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1166. if info.RetailPrice > 0 {
  1167. subItem.Drug.MinPrice = info.RetailPrice
  1168. }
  1169. }
  1170. }
  1171. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1172. } else { //门诊
  1173. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1174. for _, item := range prescriptions {
  1175. for _, subItem := range item.HisDoctorAdviceInfo {
  1176. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1177. if info.RetailPrice > 0 {
  1178. subItem.Drug.MinPrice = info.RetailPrice
  1179. }
  1180. }
  1181. }
  1182. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1183. }
  1184. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1185. if sch.ID > 0 {
  1186. var week string
  1187. t := time.Now()
  1188. switch t.Weekday().String() {
  1189. case "Monday":
  1190. week = "周一"
  1191. break
  1192. case "Tuesday":
  1193. week = "周二"
  1194. break
  1195. case "Wednesday":
  1196. week = "周三"
  1197. break
  1198. case "Thursday":
  1199. week = "周四"
  1200. break
  1201. case "Friday":
  1202. week = "周五"
  1203. break
  1204. case "Saturday":
  1205. week = "周六"
  1206. break
  1207. case "Sunday":
  1208. week = "周日"
  1209. break
  1210. }
  1211. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1212. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1213. //根据推送频率组装新的数组
  1214. for _, item := range temp_sch_prescriptions {
  1215. var cus CustomTemplate
  1216. cus.ID = item.ID
  1217. cus.UserOrgId = item.UserOrgId
  1218. cus.PatientId = item.PatientId
  1219. cus.MedType = item.MedType
  1220. cus.RecordDate = item.RecordDate
  1221. cus.Type = item.Type
  1222. cus.PType = item.PType
  1223. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1224. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1225. if subItem.FrequencyType == 1 { //每次必推
  1226. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1227. }
  1228. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1229. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1230. }
  1231. if subItem.FrequencyType == 2 { //按照天数频率
  1232. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1233. now := p.Unix()
  1234. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1235. dayStr2 := "-" + dayStr
  1236. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1237. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1238. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1239. if len(advices) == 0 {
  1240. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1241. }
  1242. }
  1243. }
  1244. }
  1245. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1246. if subItem.Type == 2 {
  1247. if subItem.XtHisProject.MedicalStatus != 1 {
  1248. if subItem.FrequencyType == 1 {
  1249. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1250. }
  1251. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1252. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1253. }
  1254. if subItem.FrequencyType == 2 {
  1255. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1256. now := p.Unix()
  1257. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1258. dayStr2 := "-" + dayStr
  1259. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1260. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1261. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1262. if len(projects) == 0 {
  1263. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1264. }
  1265. }
  1266. }
  1267. } else if subItem.Type == 3 {
  1268. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1269. if subItem.FrequencyType == 1 {
  1270. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1271. }
  1272. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1273. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1274. }
  1275. if subItem.FrequencyType == 2 {
  1276. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1277. now := p.Unix()
  1278. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1279. dayStr2 := "-" + dayStr
  1280. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1281. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1282. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1283. if len(projects) == 0 {
  1284. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. sch_prescriptions = append(sch_prescriptions, cus)
  1291. }
  1292. for _, item := range sch_prescriptions {
  1293. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1294. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1295. }
  1296. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1297. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1298. }
  1299. }
  1300. }
  1301. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1302. if config.ID > 0 && config.IsOpen == 1 {
  1303. for _, item := range sch_prescriptions {
  1304. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1305. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1306. if info.RetailPrice > 0 {
  1307. subItem.Drug.MinPrice = info.RetailPrice
  1308. }
  1309. }
  1310. }
  1311. }
  1312. if config.ID > 0 && config.IsOpen == 1 {
  1313. for _, item := range sch_prescriptions {
  1314. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1315. if subItem.Type == 3 {
  1316. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1317. if info.Price > 0 {
  1318. subItem.GoodInfo.PackingPrice = info.Price
  1319. }
  1320. }
  1321. }
  1322. }
  1323. }
  1324. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1325. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1326. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1327. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1328. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1329. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1330. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1331. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1332. //获取所有科室信息
  1333. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1334. c.ServeSuccessJSON(map[string]interface{}{
  1335. "his_info": his_patient_info,
  1336. "xt_info": xt_patient_info,
  1337. "prescription": prescriptions,
  1338. "case_history": case_history,
  1339. "info": patientPrescriptionInfo,
  1340. //"month_prescriptions": monthPrescriptions,
  1341. "order": order,
  1342. "doctors": doctors,
  1343. "department": department,
  1344. "sch_prescriptions": sch_prescriptions,
  1345. "last_prescriptions": last_prescriptions,
  1346. "schedule": sch,
  1347. "count": count,
  1348. "drugStockConfig": drugStockConfig,
  1349. "last_info": lastPatientPrescriptionInfo,
  1350. })
  1351. return
  1352. }
  1353. func (c *HisApiController) GetHisPrescriptionConfig() {
  1354. adminInfo := c.GetAdminUserInfo()
  1355. //获取医嘱模版
  1356. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1357. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1358. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1359. //获取所有基础药
  1360. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1361. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1362. if config.ID > 0 && config.IsOpen == 1 {
  1363. for _, item := range drugs {
  1364. var index = 0
  1365. for _, subItem := range item.OtherDrugWarehouseInfo {
  1366. if index == 0 {
  1367. index = index + 1
  1368. if subItem.RetailPrice > 0 {
  1369. item.MinPrice = subItem.RetailPrice
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1376. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1377. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1378. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1379. //获取所有科室信息
  1380. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1381. //获取诊断信息
  1382. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1383. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1384. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1385. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1386. //获取是否开启保存耗材出库的开关
  1387. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1388. c.ServeSuccessJSON(map[string]interface{}{
  1389. "drugs": drugs,
  1390. "advices_template": advices,
  1391. "drugways": drugways,
  1392. "efs": efs,
  1393. "doctors": doctors,
  1394. "department": department,
  1395. "sick": sick,
  1396. "additions": additions,
  1397. "diagnose": diagnose,
  1398. "manufacturers": manufacturers,
  1399. "goodOutOpen": goodOutOpen,
  1400. "patientDiagnose": patientDiagnose,
  1401. })
  1402. }
  1403. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1404. //获取所有基础药
  1405. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1406. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1407. if config.ID > 0 && config.IsOpen == 1 {
  1408. for _, item := range drugs {
  1409. var index = 0
  1410. for _, subItem := range item.OtherDrugWarehouseInfo {
  1411. if index == 0 {
  1412. index = index + 1
  1413. if subItem.RetailPrice > 0 {
  1414. item.MinPrice = subItem.RetailPrice
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1421. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1422. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1423. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1424. //获取所有科室信息
  1425. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1426. //获取诊断信息
  1427. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1428. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1429. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1430. //获取是否开启保存耗材出库的开关
  1431. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1432. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1433. c.ServeSuccessJSON(map[string]interface{}{
  1434. "drugs": drugs,
  1435. "advices_template": advices,
  1436. "drugways": drugways,
  1437. "efs": efs,
  1438. "doctors": doctors,
  1439. "department": department,
  1440. "sick": sick,
  1441. "additions": additions,
  1442. "diagnose": diagnose,
  1443. "manufacturers": manufacturers,
  1444. "goodOutOpen": goodOutOpen,
  1445. "patientDiagnose": patientDiagnose,
  1446. })
  1447. }
  1448. }
  1449. func (c *HisApiController) CreateHisPrescription() {
  1450. record_date := c.GetString("record_date")
  1451. patient_id, _ := c.GetInt64("patient_id")
  1452. reg_type, _ := c.GetInt64("reg_type")
  1453. diagnose := c.GetString("diagnose")
  1454. sick_type, _ := c.GetInt64("sick_type")
  1455. sick_history := c.GetString("sick_history")
  1456. doctor_id, _ := c.GetInt64("doctor", 0)
  1457. department, _ := c.GetInt64("department", 0)
  1458. his_patient_id, _ := c.GetInt64("his_patient_id")
  1459. p_type, _ := c.GetInt64("p_type")
  1460. patient_diagnose := c.GetString("patient_diagnose")
  1461. dataBody := make(map[string]interface{}, 0)
  1462. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1463. if err != nil {
  1464. utils.ErrorLog(err.Error())
  1465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1466. return
  1467. }
  1468. timeLayout := "2006-01-02"
  1469. loc, _ := time.LoadLocation("Local")
  1470. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1471. if err != nil {
  1472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1473. return
  1474. }
  1475. adminInfo := c.GetAdminUserInfo()
  1476. recordDateTime := theTime.Unix()
  1477. //查询默认出库仓库库存
  1478. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1479. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1480. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1481. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1482. if len(lists) == 1 {
  1483. his_patient_id = lists[0].ID
  1484. }
  1485. }
  1486. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1487. //保存处方出库
  1488. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1489. //自动出库
  1490. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1491. //耗材保存处方出库
  1492. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1493. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1494. //已发药和已收费限制逻辑
  1495. isMidicine := false
  1496. isCharge := false
  1497. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1498. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1499. if len(prescriptions) > 0 {
  1500. for _, item := range prescriptions {
  1501. items := item.(map[string]interface{})
  1502. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1503. utils.ErrorLog("id")
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1505. return
  1506. }
  1507. id := int64(items["id"].(float64))
  1508. if id > 0 {
  1509. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1510. if err != nil {
  1511. if new_prescription.OrderStatus == 4 {
  1512. isCharge = true
  1513. }
  1514. }
  1515. }
  1516. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1517. advices := items["advices"].([]interface{})
  1518. if len(advices) > 0 {
  1519. for _, advice := range advices {
  1520. var adviceId int64
  1521. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1522. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1523. }
  1524. if adviceId > 0 {
  1525. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1526. if err == nil {
  1527. if his_advice_info.IsMedicine == 1 {
  1528. isMidicine = true
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. }
  1538. if isMidicine == true {
  1539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1540. return
  1541. }
  1542. if isCharge == true {
  1543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1544. return
  1545. }
  1546. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1547. //药品发药出库
  1548. if pharmacyConfig.IsOpen == 1 {
  1549. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1550. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1551. if len(prescriptions) > 0 {
  1552. for _, item := range prescriptions {
  1553. items := item.(map[string]interface{})
  1554. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1555. advices := items["advices"].([]interface{})
  1556. if len(advices) > 0 {
  1557. for _, advice := range advices {
  1558. var drug_id int64
  1559. var prescribing_number float64
  1560. var prescribingNumberUnit string
  1561. var adviceId int64
  1562. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1563. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1564. }
  1565. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1566. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1567. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1568. }
  1569. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1570. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1571. }
  1572. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1573. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1574. }
  1575. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1576. if drug.ID == 0 {
  1577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1578. return
  1579. }
  1580. //查询药品的所有库存
  1581. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1582. var total_count int64
  1583. for _, it := range list {
  1584. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1585. }
  1586. totals := strconv.FormatInt(total_count, 10)
  1587. //查询该药品是否存在开药记录
  1588. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1589. //新增处方
  1590. if advicelist.ID == 0 {
  1591. all_count, _ := strconv.ParseFloat(totals, 64)
  1592. if prescribingNumberUnit == drug.MinUnit {
  1593. if drug.IsUse != 1 {
  1594. if drug.IsProject == 0 || drug.IsProject == 2 {
  1595. if all_count == 0 {
  1596. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1597. return
  1598. }
  1599. if prescribing_number > all_count {
  1600. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1601. return
  1602. }
  1603. }
  1604. }
  1605. }
  1606. if prescribingNumberUnit == drug.MaxUnit {
  1607. num := prescribing_number * float64(drug.MinNumber)
  1608. if drug.IsUse != 1 {
  1609. if drug.IsProject == 0 || drug.IsProject == 2 {
  1610. if all_count == 0 {
  1611. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1612. return
  1613. }
  1614. if num > all_count {
  1615. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1616. return
  1617. }
  1618. }
  1619. }
  1620. }
  1621. }
  1622. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1623. if drugOutConfig.IsOpen != 1 {
  1624. //修改处方
  1625. for _, advice := range advices {
  1626. var drug_id int64
  1627. var prescribing_number float64
  1628. var prescribingNumberUnit string
  1629. var prescribingNumber string
  1630. var adviceId int64
  1631. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1632. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1633. }
  1634. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1635. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1636. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1637. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1638. }
  1639. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1640. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1641. }
  1642. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1643. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1644. }
  1645. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1646. if drug.ID == 0 {
  1647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1648. return
  1649. }
  1650. //查询药品的所有库存
  1651. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1652. var total_count int64
  1653. for _, it := range list {
  1654. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1655. }
  1656. totals := strconv.FormatInt(total_count, 10)
  1657. //查询该药品是否存在开药记录
  1658. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1659. //新增处方
  1660. if advicelist.ID == 0 {
  1661. all_count, _ := strconv.ParseFloat(totals, 64)
  1662. if prescribingNumberUnit == drug.MinUnit {
  1663. if drug.IsUse != 1 {
  1664. if drug.IsProject == 0 || drug.IsProject == 2 {
  1665. if all_count == 0 {
  1666. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1667. return
  1668. }
  1669. if prescribing_number > all_count {
  1670. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1671. return
  1672. }
  1673. }
  1674. }
  1675. } else {
  1676. if prescribingNumberUnit == drug.MaxUnit {
  1677. num := prescribing_number * float64(drug.MinNumber)
  1678. if drug.IsUse != 1 {
  1679. if drug.IsProject == 0 || drug.IsProject == 2 {
  1680. if all_count == 0 {
  1681. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1682. return
  1683. }
  1684. if num > all_count {
  1685. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1686. return
  1687. }
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. //修改处方
  1694. if advicelist.ID > 0 {
  1695. var device_number int64
  1696. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1697. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1698. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1699. device_number = prescribingNumberInt * drug.MinNumber
  1700. }
  1701. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1702. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1703. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1704. device_number = prescribingNumberInt
  1705. }
  1706. var number_count int64
  1707. if prescribingNumberUnit == drug.MaxUnit {
  1708. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1709. number_count = prescribingNumberInt * drug.MinNumber
  1710. }
  1711. if prescribingNumberUnit == drug.MinUnit {
  1712. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1713. number_count = prescribingNumberInt
  1714. }
  1715. //如果修改的数量大于之前修改的数量
  1716. if (number_count - device_number) > 0 {
  1717. //如果修改的差数量 大于库存数量
  1718. if drug.IsUse != 1 {
  1719. if (number_count - device_number) > total_count {
  1720. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1721. return
  1722. }
  1723. }
  1724. }
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. }
  1733. }
  1734. }
  1735. //已发药和已收费限制逻辑
  1736. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1737. //校验库存总量
  1738. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1739. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1740. if len(prescriptions) > 0 {
  1741. for _, item := range prescriptions {
  1742. items := item.(map[string]interface{})
  1743. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1744. advices := items["advices"].([]interface{})
  1745. if len(advices) > 0 {
  1746. for _, advice := range advices {
  1747. var drug_id int64
  1748. var prescribing_number float64
  1749. var prescribingNumberUnit string
  1750. var adviceId int64
  1751. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1752. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1753. }
  1754. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1755. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1756. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1757. }
  1758. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1759. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1760. }
  1761. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1762. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1763. }
  1764. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1765. if drug.ID == 0 {
  1766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1767. return
  1768. }
  1769. //查询药品的所有库存
  1770. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1771. var total_count int64
  1772. for _, it := range list {
  1773. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1774. }
  1775. totals := strconv.FormatInt(total_count, 10)
  1776. //查询该药品是否存在开药记录
  1777. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1778. //查询最新批次库存
  1779. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1780. var batch_number_count int64
  1781. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1782. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1783. //新增处方
  1784. if advicelist.ID == 0 {
  1785. all_count, _ := strconv.ParseFloat(totals, 64)
  1786. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1787. if prescribingNumberUnit == drug.MinUnit {
  1788. if drug.IsUse != 1 {
  1789. if drug.IsProject == 0 || drug.IsProject == 2 {
  1790. if all_count == 0 {
  1791. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1792. return
  1793. }
  1794. if prescribing_number > all_count {
  1795. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1796. return
  1797. }
  1798. }
  1799. if adminInfo.CurrentOrgId == 10215 {
  1800. if prescribing_number > batch_number_all_count {
  1801. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1802. return
  1803. }
  1804. }
  1805. }
  1806. }
  1807. if prescribingNumberUnit == drug.MaxUnit {
  1808. num := prescribing_number * float64(drug.MinNumber)
  1809. if drug.IsUse != 1 {
  1810. if drug.IsProject == 0 || drug.IsProject == 2 {
  1811. if all_count == 0 {
  1812. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1813. return
  1814. }
  1815. if num > all_count {
  1816. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1817. return
  1818. }
  1819. }
  1820. if adminInfo.CurrentOrgId == 10215 {
  1821. if num > batch_number_all_count {
  1822. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1823. return
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1830. if drugOutConfig.IsOpen != 1 {
  1831. //修改处方
  1832. for _, advice := range advices {
  1833. var drug_id int64
  1834. var prescribing_number float64
  1835. var prescribingNumberUnit string
  1836. var prescribingNumber string
  1837. var adviceId int64
  1838. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1839. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1840. }
  1841. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1842. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1843. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1844. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1845. }
  1846. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1847. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1848. }
  1849. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1850. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1851. }
  1852. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1853. if drug.ID == 0 {
  1854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1855. return
  1856. }
  1857. //查询药品的所有库存
  1858. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1859. var total_count int64
  1860. for _, it := range list {
  1861. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1862. }
  1863. totals := strconv.FormatInt(total_count, 10)
  1864. //查询该药品是否存在开药记录
  1865. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1866. //新增处方
  1867. if advicelist.ID == 0 {
  1868. //查询最新批次库存
  1869. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1870. var batch_number_count int64
  1871. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1872. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1873. all_count, _ := strconv.ParseFloat(totals, 64)
  1874. if prescribingNumberUnit == drug.MinUnit {
  1875. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1876. if drug.IsUse != 1 {
  1877. if drug.IsProject == 0 || drug.IsProject == 2 {
  1878. if all_count == 0 {
  1879. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1880. return
  1881. }
  1882. if prescribing_number > all_count {
  1883. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1884. return
  1885. }
  1886. }
  1887. if adminInfo.CurrentOrgId == 10215 {
  1888. if prescribing_number > batch_number_all_count {
  1889. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1890. return
  1891. }
  1892. }
  1893. }
  1894. } else {
  1895. if prescribingNumberUnit == drug.MaxUnit {
  1896. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1897. num := prescribing_number * float64(drug.MinNumber)
  1898. if drug.IsUse != 1 {
  1899. if drug.IsProject == 0 || drug.IsProject == 2 {
  1900. if all_count == 0 {
  1901. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1902. return
  1903. }
  1904. if num > all_count {
  1905. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1906. return
  1907. }
  1908. }
  1909. if adminInfo.CurrentOrgId == 10215 {
  1910. if prescribing_number > batch_number_all_count {
  1911. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1912. return
  1913. }
  1914. }
  1915. }
  1916. }
  1917. }
  1918. }
  1919. //修改处方
  1920. if advicelist.ID > 0 {
  1921. //查询最新批次库存
  1922. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1923. var batch_number_count int64
  1924. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1925. var device_number int64
  1926. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1927. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1928. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1929. device_number = prescribingNumberInt * drug.MinNumber
  1930. }
  1931. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1932. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1933. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1934. device_number = prescribingNumberInt
  1935. }
  1936. var number_count int64
  1937. if prescribingNumberUnit == drug.MaxUnit {
  1938. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1939. number_count = prescribingNumberInt * drug.MinNumber
  1940. }
  1941. if prescribingNumberUnit == drug.MinUnit {
  1942. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1943. number_count = prescribingNumberInt
  1944. }
  1945. //如果修改的数量大于之前修改的数量
  1946. if (number_count - device_number) > 0 {
  1947. //如果修改的差数量 大于库存数量
  1948. if drug.IsUse != 1 {
  1949. if drug.IsProject == 0 || drug.IsProject == 2 {
  1950. if total_count == 0 {
  1951. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1952. return
  1953. }
  1954. if (number_count - device_number) > total_count {
  1955. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1956. return
  1957. }
  1958. if (number_count - device_number) > batch_number_count {
  1959. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1960. return
  1961. }
  1962. }
  1963. if adminInfo.CurrentOrgId == 10215 {
  1964. // 查询该药品最后一次出库记录
  1965. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1966. var out_count int64
  1967. var in_count int64
  1968. var stock_max_number int64
  1969. var stock_min_number int64
  1970. for _, it := range outInfo {
  1971. if it.CountUnit == drug.MaxUnit {
  1972. it.Count = it.Count * drug.MinNumber
  1973. }
  1974. out_count += it.Count
  1975. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1976. stock_max_number = warehouseInfoList.StockMaxNumber
  1977. stock_min_number = warehouseInfoList.StockMinNumber
  1978. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1979. }
  1980. if out_count > 0 {
  1981. if (number_count - device_number) > in_count {
  1982. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1983. return
  1984. }
  1985. }
  1986. // 未出库
  1987. if out_count == 0 {
  1988. var sum_in_count int64
  1989. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1990. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1991. //如果修改的数量大于有库存的第一个批次
  1992. if number_count > sum_in_count {
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1994. return
  1995. }
  1996. }
  1997. }
  1998. }
  1999. }
  2000. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2001. if pharmacyConfig.IsOpen != 1 {
  2002. if device_number != number_count {
  2003. // 查询该药品最后一次出库记录
  2004. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2005. //回退库存
  2006. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2007. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2008. }
  2009. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2010. var stock_max_number int64
  2011. var stock_min_number int64
  2012. if number_count >= drug.MinNumber {
  2013. stock_max_number = device_number / drug.MinNumber
  2014. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2015. stock_min_number = device_number % drug.MinNumber
  2016. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2017. } else {
  2018. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2019. }
  2020. }
  2021. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2022. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2023. }
  2024. //删除记录
  2025. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2026. //查询默认仓库剩余多少库存
  2027. var sum_count int64
  2028. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2029. for _, its := range stockInfo {
  2030. if its.MaxUnit == drug.MaxUnit {
  2031. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2032. }
  2033. sum_count += its.StockMaxNumber + its.StockMinNumber
  2034. }
  2035. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2036. }
  2037. }
  2038. }
  2039. }
  2040. }
  2041. //保存处方开药
  2042. if drugOutConfig.IsOpen == 1 {
  2043. //修改处方
  2044. for _, advice := range advices {
  2045. var drug_id int64
  2046. var prescribing_number float64
  2047. var prescribingNumberUnit string
  2048. var prescribingNumber string
  2049. var adviceId int64
  2050. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2051. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2052. }
  2053. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2054. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2055. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2056. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2057. }
  2058. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2059. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2060. }
  2061. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2062. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2063. }
  2064. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2065. if drug.ID == 0 {
  2066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2067. return
  2068. }
  2069. //查询药品的所有库存
  2070. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2071. var total_count int64
  2072. for _, it := range list {
  2073. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2074. }
  2075. totals := strconv.FormatInt(total_count, 10)
  2076. //查询该药品是否存在开药记录
  2077. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2078. //新增处方
  2079. if advicelist.ID == 0 {
  2080. //查询最新批次库存
  2081. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2082. var batch_number_count int64
  2083. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2084. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2085. all_count, _ := strconv.ParseFloat(totals, 64)
  2086. if prescribingNumberUnit == drug.MinUnit {
  2087. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2088. if drug.IsUse != 1 {
  2089. if drug.IsProject == 0 || drug.IsProject == 2 {
  2090. if all_count == 0 {
  2091. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2092. return
  2093. }
  2094. if prescribing_number > all_count {
  2095. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2096. return
  2097. }
  2098. }
  2099. if adminInfo.CurrentOrgId == 10215 {
  2100. if prescribing_number > batch_number_all_count {
  2101. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2102. return
  2103. }
  2104. }
  2105. }
  2106. } else {
  2107. if prescribingNumberUnit == drug.MaxUnit {
  2108. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2109. num := prescribing_number * float64(drug.MinNumber)
  2110. if drug.IsUse != 1 {
  2111. if drug.IsProject == 0 || drug.IsProject == 2 {
  2112. if all_count == 0 {
  2113. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2114. return
  2115. }
  2116. if num > all_count {
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. }
  2121. if adminInfo.CurrentOrgId == 10215 {
  2122. if prescribing_number > batch_number_all_count {
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2124. return
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. //修改处方
  2132. if advicelist.ID > 0 {
  2133. //查询最新批次库存
  2134. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2135. var batch_number_count int64
  2136. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2137. var device_number int64
  2138. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2139. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2140. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2141. device_number = prescribingNumberInt * drug.MinNumber
  2142. }
  2143. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2144. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2145. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2146. device_number = prescribingNumberInt
  2147. }
  2148. var number_count int64
  2149. if prescribingNumberUnit == drug.MaxUnit {
  2150. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2151. number_count = prescribingNumberInt * drug.MinNumber
  2152. }
  2153. if prescribingNumberUnit == drug.MinUnit {
  2154. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2155. number_count = prescribingNumberInt
  2156. }
  2157. //如果修改的数量大于之前修改的数量
  2158. if (number_count - device_number) > 0 {
  2159. //如果修改的差数量 大于库存数量
  2160. if drug.IsUse != 1 {
  2161. if drug.IsProject == 0 || drug.IsProject == 2 {
  2162. if total_count == 0 {
  2163. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2164. return
  2165. }
  2166. if (number_count - device_number) > total_count {
  2167. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2168. return
  2169. }
  2170. }
  2171. if adminInfo.CurrentOrgId == 10215 {
  2172. if (number_count - device_number) > batch_number_count {
  2173. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2174. return
  2175. }
  2176. }
  2177. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2178. //查询历史出库数据总批次
  2179. // 查询该药品最后一次出库记录
  2180. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2181. var out_count int64
  2182. var in_count int64
  2183. var stock_max_number int64
  2184. var stock_min_number int64
  2185. for _, it := range outInfo {
  2186. if it.CountUnit == drug.MaxUnit {
  2187. it.Count = it.Count * drug.MinNumber
  2188. }
  2189. out_count += it.Count
  2190. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2191. stock_max_number = warehouseInfoList.StockMaxNumber
  2192. stock_min_number = warehouseInfoList.StockMinNumber
  2193. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2194. }
  2195. if out_count > 0 {
  2196. if (number_count - device_number) > in_count {
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2198. return
  2199. }
  2200. }
  2201. // 未出库
  2202. if out_count == 0 {
  2203. var sum_in_count int64
  2204. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2205. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2206. if sum_in_count == 0 {
  2207. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2208. return
  2209. }
  2210. //如果修改的数量大于有库存的第一个批次
  2211. if number_count > sum_in_count {
  2212. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2213. return
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. //校验耗材库存
  2230. if goodOutConfig.IsOpen == 1 {
  2231. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2232. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2233. if len(prescriptions) > 0 {
  2234. for _, item := range prescriptions {
  2235. items := item.(map[string]interface{})
  2236. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2237. projects := items["project"].([]interface{})
  2238. if len(projects) > 0 {
  2239. for _, project := range projects {
  2240. var project_id int64
  2241. var project_type int64
  2242. var totals float64
  2243. var project_name string
  2244. var parsetotal int64
  2245. var id int64
  2246. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2247. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2248. }
  2249. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2250. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2251. }
  2252. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2253. total, _ := project.(map[string]interface{})["total"].(string)
  2254. totals, _ = strconv.ParseFloat(total, 64)
  2255. }
  2256. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2257. project_name = project.(map[string]interface{})["project_name"].(string)
  2258. }
  2259. if project_type == 3 {
  2260. //查找该耗材的出库记录
  2261. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2262. if len(goodWarehouseInfo) == 0 {
  2263. //查询耗材库存
  2264. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2265. var stock_count int64
  2266. for _, it := range list {
  2267. stock_count += it.StockCount
  2268. }
  2269. stock_counts := strconv.FormatInt(stock_count, 10)
  2270. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2271. if stock_total_count == 0 {
  2272. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2273. return
  2274. }
  2275. if totals > stock_total_count {
  2276. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2277. return
  2278. }
  2279. }
  2280. if len(goodWarehouseInfo) > 0 {
  2281. //查询该患者耗材的历史数据
  2282. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2283. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2284. //数量发生改变
  2285. if parsetotal != count {
  2286. //如果现在的数量大于历史数量,就要看库存是否足够
  2287. if parsetotal > count {
  2288. //查询耗材所有库存
  2289. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2290. var stock_count int64
  2291. for _, it := range list {
  2292. stock_count += it.StockCount
  2293. }
  2294. //库存不足
  2295. if stock_count == 0 {
  2296. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2297. return
  2298. }
  2299. if (parsetotal - count) > stock_count {
  2300. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2301. return
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. }
  2313. }
  2314. //不使用耗材保存处方出库
  2315. if goodOutConfig.IsOpen != 1 {
  2316. if stockConfig.IsOpen == 1 {
  2317. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2318. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2319. if len(prescriptions) > 0 {
  2320. for _, item := range prescriptions {
  2321. items := item.(map[string]interface{})
  2322. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2323. projects := items["project"].([]interface{})
  2324. if len(projects) > 0 {
  2325. for _, project := range projects {
  2326. var project_id int64
  2327. var project_type int64
  2328. var totals float64
  2329. var project_name string
  2330. var parsetotal int64
  2331. var id int64
  2332. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2333. id = int64(project.(map[string]interface{})["id"].(float64))
  2334. }
  2335. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2336. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2337. }
  2338. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2339. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2340. }
  2341. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2342. total, _ := project.(map[string]interface{})["total"].(string)
  2343. totals, _ = strconv.ParseFloat(total, 64)
  2344. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2345. }
  2346. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2347. project_name = project.(map[string]interface{})["project_name"].(string)
  2348. }
  2349. if project_type == 3 {
  2350. //查找该耗材的出库记录
  2351. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2352. //没有出库记录
  2353. if len(goodWarehouseInfo) == 0 {
  2354. //查询耗材库存
  2355. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2356. var stock_count int64
  2357. for _, it := range list {
  2358. stock_count += it.StockCount
  2359. }
  2360. stock_counts := strconv.FormatInt(stock_count, 10)
  2361. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2362. if stock_total_count == 0 {
  2363. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2364. return
  2365. }
  2366. if totals > stock_total_count {
  2367. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2368. return
  2369. }
  2370. //查找今日该患者已经出库的所有耗材
  2371. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2372. for _, item := range goodList {
  2373. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2374. var flush_count int64
  2375. for _, it := range goodListSix {
  2376. flush_count += it.StockCount
  2377. }
  2378. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2379. creater := adminInfo.AdminUser.Id
  2380. if errs != nil {
  2381. goodErrcode := models.XtGoodErrcode{
  2382. UserOrgId: item.OrgId,
  2383. Errcode: "手动出库更新剩余出库失败",
  2384. GoodId: item.GoodId,
  2385. Status: 1,
  2386. Ctime: time.Now().Unix(),
  2387. Mtime: 0,
  2388. Count: 0,
  2389. StockCount: 0,
  2390. Creater: creater,
  2391. BatchNumberId: 0,
  2392. WarehouseOutId: 0,
  2393. }
  2394. service.CreateGoodErrcode(goodErrcode)
  2395. }
  2396. }
  2397. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2398. }
  2399. //有出库记录
  2400. if len(goodWarehouseInfo) > 0 {
  2401. //查询该患者耗材的历史数据
  2402. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2403. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2404. //数量发生改变
  2405. if parsetotal != count {
  2406. //查找今日该患者已经出库的所有耗材
  2407. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2408. for _, item := range goodList {
  2409. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2410. var flush_count int64
  2411. for _, it := range goodListSix {
  2412. flush_count += it.StockCount
  2413. }
  2414. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2415. //减少出库数量
  2416. creater := adminInfo.AdminUser.Id
  2417. if errs != nil {
  2418. goodErrcode := models.XtGoodErrcode{
  2419. UserOrgId: item.OrgId,
  2420. Errcode: "手动出库更新剩余出库失败",
  2421. GoodId: item.GoodId,
  2422. Status: 1,
  2423. Ctime: time.Now().Unix(),
  2424. Mtime: 0,
  2425. Count: 0,
  2426. StockCount: 0,
  2427. Creater: creater,
  2428. BatchNumberId: 0,
  2429. WarehouseOutId: 0,
  2430. }
  2431. service.CreateGoodErrcode(goodErrcode)
  2432. }
  2433. //查询默认仓库
  2434. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2435. var total_count int64
  2436. for _, it := range stockList {
  2437. total_count += it.StockCount
  2438. }
  2439. //基础库插入数据
  2440. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2441. }
  2442. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2443. }
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. }
  2453. }
  2454. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2455. var hpInfo models.HisPrescriptionInfo
  2456. if info.ID == 0 {
  2457. var randNum int
  2458. randNum = rand.Intn(10000) + 1000
  2459. timestamp := time.Now().Unix()
  2460. tempTime := time.Unix(timestamp, 0)
  2461. timeFormat := tempTime.Format("20060102150405")
  2462. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2463. hpInfo = models.HisPrescriptionInfo{
  2464. HisPatientId: his_patient_id,
  2465. UserOrgId: adminInfo.CurrentOrgId,
  2466. RecordDate: theTime.Unix(),
  2467. PatientId: patient_id,
  2468. Status: 1,
  2469. Ctime: time.Now().Unix(),
  2470. Mtime: time.Now().Unix(),
  2471. Creator: adminInfo.AdminUser.Id,
  2472. Modifier: adminInfo.AdminUser.Id,
  2473. Diagnosis: diagnose,
  2474. SickHistory: sick_history,
  2475. Departments: department,
  2476. RegisterType: reg_type,
  2477. PrescriptionNumber: p_number,
  2478. PrescriptionStatus: 1,
  2479. Doctor: role.UserName,
  2480. DoctorId: doctor_id,
  2481. SickType: sick_type,
  2482. PType: p_type,
  2483. PatientDiagnosis: patient_diagnose,
  2484. }
  2485. service.SavePatientPrescriptionInfo(hpInfo)
  2486. //创建步骤表
  2487. finish := models.XtDialysisFinish{
  2488. IsFinish: 1,
  2489. UserOrgId: adminInfo.CurrentOrgId,
  2490. Status: 1,
  2491. Ctime: time.Now().Unix(),
  2492. Mtime: 0,
  2493. Module: 4,
  2494. RecordDate: theTime.Unix(),
  2495. Sourse: 1,
  2496. PatientId: patient_id,
  2497. }
  2498. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2499. if dialysisFinish.ID == 0 {
  2500. service.CreateDialysisFinish(finish)
  2501. }
  2502. redis := service.RedisClient()
  2503. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2504. redis.Set(key, "", time.Second)
  2505. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2506. redis.Set(keyOne, "", time.Second)
  2507. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2508. redis.Set(keySeven, "", time.Second)
  2509. defer redis.Close()
  2510. } else {
  2511. hpInfo = models.HisPrescriptionInfo{
  2512. ID: info.ID,
  2513. UserOrgId: adminInfo.CurrentOrgId,
  2514. RecordDate: info.RecordDate,
  2515. PatientId: info.PatientId,
  2516. Status: 1,
  2517. Ctime: info.Ctime,
  2518. Mtime: time.Now().Unix(),
  2519. Creator: info.Creator,
  2520. Modifier: adminInfo.AdminUser.Id,
  2521. Diagnosis: diagnose,
  2522. SickHistory: sick_history,
  2523. Departments: department,
  2524. RegisterType: reg_type,
  2525. PrescriptionNumber: info.PrescriptionNumber,
  2526. Doctor: role.UserName,
  2527. PrescriptionStatus: info.PrescriptionStatus,
  2528. DoctorId: doctor_id,
  2529. SickType: sick_type,
  2530. PType: info.PType,
  2531. HisPatientId: info.HisPatientId,
  2532. PatientDiagnosis: patient_diagnose,
  2533. }
  2534. service.SavePatientPrescriptionInfo(hpInfo)
  2535. //创建步骤表
  2536. finish := models.XtDialysisFinish{
  2537. IsFinish: 1,
  2538. UserOrgId: adminInfo.CurrentOrgId,
  2539. Status: 1,
  2540. Ctime: time.Now().Unix(),
  2541. Mtime: 0,
  2542. Module: 4,
  2543. RecordDate: info.RecordDate,
  2544. Sourse: 1,
  2545. PatientId: info.PatientId,
  2546. }
  2547. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2548. if dialysisFinish.ID == 0 {
  2549. service.CreateDialysisFinish(finish)
  2550. }
  2551. redis := service.RedisClient()
  2552. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2553. redis.Set(key, "", time.Second)
  2554. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2555. redis.Set(keyOne, "", time.Second)
  2556. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2557. redis.Set(keySeven, "", time.Second)
  2558. defer redis.Close()
  2559. }
  2560. //定义切片
  2561. var adviceList []models.HisDoctorAdviceInfo
  2562. var projectList []models.HisPrescriptionProject
  2563. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2564. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2565. var tempPrescription *models.HisPrescription
  2566. if len(prescriptions) > 0 {
  2567. for _, item := range prescriptions {
  2568. items := item.(map[string]interface{})
  2569. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2570. utils.ErrorLog("id")
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2572. return
  2573. }
  2574. id := int64(items["id"].(float64))
  2575. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2576. tempPrescription = &new_prescription
  2577. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2578. utils.ErrorLog("type")
  2579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2580. return
  2581. }
  2582. types := int64(items["type"].(float64))
  2583. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2584. utils.ErrorLog("med_type")
  2585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2586. return
  2587. }
  2588. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2589. if med_type == "0" {
  2590. med_type = "14"
  2591. }
  2592. //if order_status == 0 {
  2593. // order_status = 1
  2594. //}
  2595. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2596. utils.ErrorLog("pre_time")
  2597. }
  2598. preTime, _ := items["pre_time"].(string)
  2599. timeLayout := "2006-01-02"
  2600. loc, _ := time.LoadLocation("Local")
  2601. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2602. if err != nil {
  2603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2604. return
  2605. }
  2606. pTime := theTime2.Unix()
  2607. ctime := time.Now().Unix()
  2608. if tempPrescription.ID == 0 {
  2609. prescription := &models.HisPrescription{
  2610. ID: 0,
  2611. PatientId: patient_id,
  2612. UserOrgId: adminInfo.CurrentOrgId,
  2613. RecordDate: recordDateTime,
  2614. Ctime: ctime,
  2615. Mtime: ctime,
  2616. Type: types,
  2617. Modifier: adminInfo.AdminUser.Id,
  2618. Creator: adminInfo.AdminUser.Id,
  2619. Status: 1,
  2620. Doctor: role.UserName,
  2621. HisPatientId: his_patient_id,
  2622. OrderStatus: 1,
  2623. BatchNumber: "",
  2624. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2625. PreTime: pTime,
  2626. PType: p_type,
  2627. MedType: med_type,
  2628. }
  2629. tempPrescription = prescription
  2630. service.SaveHisPrescription(tempPrescription)
  2631. redis := service.RedisClient()
  2632. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2633. redis.Set(key, "", time.Second)
  2634. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2635. redis.Set(keyOne, "", time.Second)
  2636. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2637. redis.Set(keySeven, "", time.Second)
  2638. defer redis.Close()
  2639. } else {
  2640. tempPrescription.ID = id
  2641. tempPrescription.Type = types
  2642. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2643. tempPrescription.Mtime = time.Now().Unix()
  2644. tempPrescription.Doctor = role.UserName
  2645. //tempPrescription.OrderStatus = order_status
  2646. tempPrescription.PreTime = pTime
  2647. tempPrescription.MedType = med_type
  2648. service.SaveHisPrescription(tempPrescription)
  2649. redis := service.RedisClient()
  2650. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2651. redis.Set(key, "", time.Second)
  2652. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2653. redis.Set(keyOne, "", time.Second)
  2654. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2655. redis.Set(keySeven, "", time.Second)
  2656. defer redis.Close()
  2657. }
  2658. //service.SaveHisPrescription(prescription)
  2659. //更改患者挂号状态
  2660. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2661. fmt.Println("更改失败", err2)
  2662. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2663. advices := items["advices"].([]interface{})
  2664. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2665. groupNo := int64(0)
  2666. ctime := time.Now().Unix()
  2667. mtime := ctime
  2668. if len(advices) > 0 {
  2669. for _, advice := range advices {
  2670. var s models.HisDoctorAdviceInfo
  2671. s.PrescriptionId = tempPrescription.ID
  2672. s.AdviceType = 2
  2673. s.AdviceDoctor = doctor_id
  2674. s.StopState = 2
  2675. s.ExecutionState = 2
  2676. s.AdviceDate = recordDateTime
  2677. s.Status = 1
  2678. s.UserOrgId = adminInfo.CurrentOrgId
  2679. s.RecordDate = recordDateTime
  2680. s.StartTime = tempPrescription.PreTime
  2681. s.Groupno = groupNo
  2682. s.CreatedTime = ctime
  2683. s.UpdatedTime = mtime
  2684. s.PatientId = patient_id
  2685. s.HisPatientId = his_patient_id
  2686. s.StartTime = pTime
  2687. s.IsSettle = 2
  2688. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2689. if errcode > 0 {
  2690. c.ServeFailJSONWithSGJErrorCode(errcode)
  2691. return
  2692. }
  2693. s.StartTime = pTime
  2694. var total_count int64 //处方总库存
  2695. //查询改药品信息
  2696. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2697. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2698. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2699. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2700. total_count += prescribingNumberSeven * medical.MinNumber
  2701. }
  2702. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2703. total_count += prescribingNumberSeven
  2704. }
  2705. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2706. total_count += prescribingNumberSeven
  2707. }
  2708. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2709. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2710. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2711. if s.Price != lastWarehouse.RetailPrice {
  2712. s.Price = lastWarehouse.RetailPrice
  2713. }
  2714. if s.Price == 0 {
  2715. s.Price = lastWarehouse.RetailPrice
  2716. }
  2717. }
  2718. service.CreateHisDoctorAdvice(&s)
  2719. //记录日志
  2720. byterequest, _ := json.Marshal(s)
  2721. adviceLog := models.XtDoctorAdviceLog{
  2722. UserOrgId: s.UserOrgId,
  2723. PatientId: s.PatientId,
  2724. AdminUserId: adminInfo.AdminUser.Id,
  2725. Module: 1,
  2726. ErrLog: string(byterequest),
  2727. Status: 1,
  2728. Ctime: time.Now().Unix(),
  2729. Mtime: 0,
  2730. Source: "电脑端新建his医嘱",
  2731. RecordDate: s.AdviceDate,
  2732. }
  2733. service.CreateDoctorAdviceLog(adviceLog)
  2734. //存储切片中
  2735. adviceList = append(adviceList, s)
  2736. redis := service.RedisClient()
  2737. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2738. redis.Set(key, "", time.Second)
  2739. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2740. redis.Set(keyOne, "", time.Second)
  2741. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2742. redis.Set(keySeven, "", time.Second)
  2743. var randNum int
  2744. randNum = rand.Intn(10000) + 1000
  2745. timestamp := time.Now().Unix()
  2746. tempTime := time.Unix(timestamp, 0)
  2747. timeFormat := tempTime.Format("20060102150405")
  2748. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2749. service.CreateHisDoctorAdvice(&s)
  2750. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2751. redis.Set(keySix, "", time.Second)
  2752. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2753. redis.Set(keyFive, "", time.Second)
  2754. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2755. redis.Set(keyEight, "", time.Second)
  2756. defer redis.Close()
  2757. }
  2758. }
  2759. }
  2760. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2761. projects := items["project"].([]interface{})
  2762. if len(projects) > 0 {
  2763. for _, project := range projects {
  2764. var p models.HisPrescriptionProject
  2765. p.PrescriptionId = tempPrescription.ID
  2766. p.Ctime = time.Now().Unix()
  2767. p.Mtime = time.Now().Unix()
  2768. p.PatientId = patient_id
  2769. p.RecordDate = recordDateTime
  2770. p.Doctor = doctor_id
  2771. p.UserOrgId = adminInfo.CurrentOrgId
  2772. p.HisPatientId = his_patient_id
  2773. p.Status = 1
  2774. p.StartTime = pTime
  2775. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2776. if errcode > 0 {
  2777. c.ServeFailJSONWithSGJErrorCode(errcode)
  2778. return
  2779. }
  2780. if p.ID == 0 {
  2781. p.IsOut = 2
  2782. }
  2783. if p.ID > 0 {
  2784. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2785. p.IsOut = projectDetail.IsOut
  2786. }
  2787. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2788. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2789. if p.Type == 3 {
  2790. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2791. if p.Price != lastWarehouse.PackingPrice {
  2792. p.Price = lastWarehouse.PackingPrice
  2793. }
  2794. if p.Unit == "" {
  2795. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2796. p.Unit = goodInfoOne.PackingUnit
  2797. }
  2798. }
  2799. }
  2800. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2801. //
  2802. // if p.Type == 3 {
  2803. // //查询该耗材是否停用
  2804. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2805. // //表示该耗材已经停用,不能保存
  2806. // if goodInfoSeven.ID == 0 {
  2807. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2808. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2809. // return
  2810. // }
  2811. // }
  2812. //
  2813. //}
  2814. service.CreateHisProjectTwo(&p)
  2815. //记录日志
  2816. byterequest, _ := json.Marshal(p)
  2817. adviceLog := models.XtDoctorAdviceLog{
  2818. UserOrgId: p.UserOrgId,
  2819. PatientId: p.PatientId,
  2820. AdminUserId: adminInfo.AdminUser.Id,
  2821. Module: 1,
  2822. ErrLog: string(byterequest),
  2823. Status: 1,
  2824. Ctime: time.Now().Unix(),
  2825. Mtime: 0,
  2826. Source: "电脑端新建his项目",
  2827. RecordDate: p.RecordDate,
  2828. }
  2829. service.CreateDoctorAdviceLog(adviceLog)
  2830. projectList = append(projectList, p)
  2831. var randNum int
  2832. randNum = rand.Intn(10000) + 1000
  2833. timestamp := time.Now().Unix()
  2834. tempTime := time.Unix(timestamp, 0)
  2835. timeFormat := tempTime.Format("20060102150405")
  2836. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2837. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2838. //新增或者编辑项目,修改对应的标签数据
  2839. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2840. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2841. var label models.HisLabelPrintInfo
  2842. project, _ := service.GetProjectDetail(p.ProjectId)
  2843. if project.CostClassify == 3 { //类别为检验检查
  2844. if p.TeamId > 0 { //检验检查组套
  2845. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2846. if tempLabel.ID == 0 {
  2847. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2848. label.Number = tempPrescription.PrescriptionNumber
  2849. label.ProjectId = project.ID
  2850. label.Status = 1
  2851. label.IsPrint = 2
  2852. label.DoctorId = info.DoctorId
  2853. label.UserOrgId = p.UserOrgId
  2854. label.PatientId = patient_id
  2855. label.RecordDate = recordDateTime
  2856. label.Ctime = time.Now().Unix()
  2857. label.Mtime = time.Now().Unix()
  2858. label.ItemId = p.TeamId
  2859. label.FeedetlSn = p.FeedetlSn
  2860. label.PProjectId = p.ID
  2861. label.ProjectName = team.ProjectTeam
  2862. label.PatientName = patient.Name
  2863. service.CreateHisLabelRecord(&label)
  2864. }
  2865. } else { //单条检验检查项目
  2866. label.Number = tempPrescription.PrescriptionNumber
  2867. label.ProjectId = project.ID
  2868. label.Status = 1
  2869. label.DoctorId = info.DoctorId
  2870. label.UserOrgId = p.UserOrgId
  2871. label.PatientId = patient_id
  2872. label.RecordDate = recordDateTime
  2873. label.IsPrint = 2
  2874. label.Ctime = time.Now().Unix()
  2875. label.Mtime = time.Now().Unix()
  2876. label.FeedetlSn = p.FeedetlSn
  2877. label.PProjectId = p.ID
  2878. label.ItemId = p.TeamId
  2879. label.ProjectName = project.ProjectName
  2880. label.PatientName = patient.Name
  2881. service.CreateHisLabelRecord(&label)
  2882. }
  2883. }
  2884. }
  2885. }
  2886. service.SaveHisProjectTwo(&p)
  2887. }
  2888. }
  2889. }
  2890. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2891. // addition := items["addition"].([]interface{})
  2892. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2893. // ctime := time.Now().Unix()
  2894. // mtime := ctime
  2895. // if len(addition) > 0 {
  2896. // for _, item := range addition {
  2897. // var s models.HisAdditionalCharge
  2898. // s.PrescriptionId = tempPrescription.ID
  2899. // s.Status = 1
  2900. // s.UserOrgId = adminInfo.CurrentOrgId
  2901. // s.RecordDate = recordDateTime
  2902. // s.CreatedTime = ctime
  2903. // s.UpdatedTime = mtime
  2904. // s.PatientId = patient_id
  2905. // s.HisPatientId = his_patient_id
  2906. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2907. // if errcode > 0 {
  2908. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2909. // return
  2910. // }
  2911. // service.CreateAdditionalCharge(&s)
  2912. // var randNum int
  2913. // randNum = rand.Intn(10000) + 1000
  2914. // timestamp := time.Now().Unix()
  2915. // tempTime := time.Unix(timestamp, 0)
  2916. // timeFormat := tempTime.Format("20060102150405")
  2917. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2918. // service.CreateAdditionalCharge(&s)
  2919. //
  2920. // }
  2921. // }
  2922. //}
  2923. }
  2924. }
  2925. //查询今日该患者开的药品处方
  2926. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2927. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2928. //药品出库
  2929. if drugOutConfig.IsOpen == 1 {
  2930. for _, item := range hisdoctorlist {
  2931. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2932. // 查询该药品最后一次出库记录
  2933. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2934. if len(druginfo) > 0 {
  2935. //回退库存
  2936. for _, it := range druginfo {
  2937. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2938. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2939. }
  2940. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2941. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2942. }
  2943. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2944. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2945. }
  2946. }
  2947. }
  2948. //删除记录
  2949. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2950. //查询最后一次数据
  2951. if drugOutConfig.IsOpen == 1 {
  2952. //出库
  2953. if drug.IsUse == 2 {
  2954. creater := adminInfo.AdminUser.Id
  2955. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2956. }
  2957. //更新字典里面的库存
  2958. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2959. var sum_count int64
  2960. for _, its := range stockInfo {
  2961. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2962. if its.MaxUnit == baseDrug.MaxUnit {
  2963. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2964. }
  2965. sum_count += its.StockMaxNumber + its.StockMinNumber
  2966. }
  2967. //更新基础库存
  2968. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2969. //剩余库存
  2970. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2971. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  2972. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2973. }
  2974. }
  2975. }
  2976. //耗材保存处方出库
  2977. if goodOutConfig.IsOpen == 1 {
  2978. //查询今日耗材出库数量
  2979. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2980. for _, item := range hisgoodlist {
  2981. //查询历史出库数据
  2982. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2983. var out_count_five int64
  2984. for _, item := range flowGood {
  2985. out_count_five += item.Count
  2986. }
  2987. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2988. if out_count_five != parseIntCount {
  2989. //查询耗材最后一次出库记录
  2990. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2991. //查询默认出库仓库库存
  2992. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2993. if len(wareOut) > 0 {
  2994. for _, it := range wareOut {
  2995. //回退库存
  2996. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2997. //删除出库记录
  2998. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2999. }
  3000. }
  3001. timeStr := time.Now().Format("2006-01-02")
  3002. timeArr := strings.Split(timeStr, "-")
  3003. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3004. total = total + 1
  3005. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3006. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3007. number = number + total
  3008. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3009. operation_time := time.Now().Unix()
  3010. creater := c.GetAdminUserInfo().AdminUser.Id
  3011. recordDateStr := time.Now().Format("2006-01-02")
  3012. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3013. nowtime := recordDate.Unix()
  3014. warehouseOut := models.WarehouseOut{
  3015. WarehouseOutOrderNumber: warehousing_out_order,
  3016. OperationTime: operation_time,
  3017. OrgId: adminInfo.CurrentOrgId,
  3018. Creater: creater,
  3019. Ctime: time.Now().Unix(),
  3020. Status: 1,
  3021. WarehouseOutTime: nowtime,
  3022. Type: 1,
  3023. StorehouseId: storeConfig.StorehouseOutInfo,
  3024. IsCheck: 1,
  3025. IsSys: 1,
  3026. }
  3027. //查询是否生成出库单
  3028. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3029. if out.ID == 0 {
  3030. service.AddSigleWarehouseOut(&warehouseOut)
  3031. }
  3032. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3033. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3034. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3035. dialyPrepareOne := models.DialysisBeforePrepare{
  3036. GoodTypeId: goodObj.GoodTypeId,
  3037. GoodId: item.ProjectId,
  3038. PatientId: item.PatientId,
  3039. RecordDate: item.RecordDate,
  3040. UserOrgId: adminInfo.CurrentOrgId,
  3041. Count: parseIntCount,
  3042. Ctime: time.Now().Unix(),
  3043. Creater: creater,
  3044. Status: 1,
  3045. StorehouseId: houseConfig.StorehouseOutInfo,
  3046. ProjectId: item.ID,
  3047. }
  3048. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3049. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3050. //查询历史出库数据
  3051. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3052. var out_count int64
  3053. for _, item := range flowGood {
  3054. out_count += item.Count
  3055. }
  3056. //如果历史数和当前数据不想等才进行退库出库
  3057. if out_count != parseIntCount {
  3058. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3059. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3060. detail := models.AutomaticReduceDetail{
  3061. WarehouseOutId: 0,
  3062. WarehouseOutOrderNumber: "",
  3063. PatientId: item.PatientId,
  3064. Ctime: time.Now().Unix(),
  3065. Mtime: 0,
  3066. Status: 1,
  3067. RecordTime: item.RecordDate,
  3068. OrgId: item.UserOrgId,
  3069. GoodId: item.ProjectId,
  3070. GoodTypeId: 0,
  3071. Count: parseIntCount,
  3072. Type: 0,
  3073. ProjectId: item.ID,
  3074. StorehouseId: 0,
  3075. }
  3076. service.CreateAutoDetail(detail)
  3077. //查询剩余库存
  3078. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3079. var sum_count int64
  3080. for _, item := range goodList {
  3081. sum_count += item.StockCount
  3082. }
  3083. //更新剩余库存
  3084. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3085. //耗材
  3086. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3087. }
  3088. }
  3089. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3090. //查询历史出库数据
  3091. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3092. var out_count int64
  3093. for _, item := range flowGood {
  3094. out_count += item.Count
  3095. }
  3096. //如果历史数和当前数据不想等才进行退库出库
  3097. if out_count != parseIntCount {
  3098. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3099. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3100. detail := models.AutomaticReduceDetail{
  3101. WarehouseOutId: 0,
  3102. WarehouseOutOrderNumber: "",
  3103. PatientId: item.PatientId,
  3104. Ctime: time.Now().Unix(),
  3105. Mtime: 0,
  3106. Status: 1,
  3107. RecordTime: item.RecordDate,
  3108. OrgId: item.UserOrgId,
  3109. GoodId: item.ProjectId,
  3110. GoodTypeId: 0,
  3111. Count: parseIntCount,
  3112. Type: 0,
  3113. ProjectId: item.ID,
  3114. StorehouseId: 0,
  3115. }
  3116. service.CreateAutoDetail(detail)
  3117. //查询剩余库存
  3118. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3119. var sum_count int64
  3120. for _, item := range goodList {
  3121. sum_count += item.StockCount
  3122. }
  3123. //更新剩余库存
  3124. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3125. //耗材
  3126. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3127. }
  3128. }
  3129. }
  3130. }
  3131. }
  3132. }
  3133. //redisClient := service.RedisClient()
  3134. //defer redisClient.Close()
  3135. //
  3136. //list := models.HisList{
  3137. // Patient_id: patient_id,
  3138. // Advice_id:0,
  3139. // Record_date: 0,
  3140. // Advice: adviceList,
  3141. // Project: nil,
  3142. //}
  3143. //hisLis = append(hisLis, list)
  3144. //
  3145. //advice_json, _ := json.Marshal(&hisLis)
  3146. //redisClient.RPush("111", advice_json).Result()
  3147. //result, _ := redisClient.RPop("111").Result()
  3148. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3149. //
  3150. //var dat []map[string]interface{}
  3151. //json.Unmarshal([]byte(result), &dat)
  3152. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3153. //
  3154. //for k,v:=range dat{
  3155. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3156. //}
  3157. //project_json, _ := json.Marshal(&projectList)
  3158. //redisClient.LPush("222", project_json).Result()
  3159. if err == nil {
  3160. c.ServeSuccessJSON(map[string]interface{}{
  3161. "msg": "保存成功",
  3162. })
  3163. return
  3164. } else {
  3165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3166. return
  3167. }
  3168. }
  3169. func (c *HisApiController) EditHisPrescription() {
  3170. record_date := c.GetString("record_date")
  3171. patient_id, _ := c.GetInt64("patient_id")
  3172. reg_type, _ := c.GetInt64("reg_type")
  3173. //diagnose, _ := c.GetInt64("diagnose", 0)
  3174. diagnose := c.GetString("diagnose")
  3175. sick_type, _ := c.GetInt64("sick_type")
  3176. sick_history := c.GetString("sick_history")
  3177. doctor_id, _ := c.GetInt64("doctor", 0)
  3178. department, _ := c.GetInt64("department", 0)
  3179. his_patient_id, _ := c.GetInt64("his_patient_id")
  3180. p_type, _ := c.GetInt64("p_type")
  3181. dataBody := make(map[string]interface{}, 0)
  3182. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3183. if err != nil {
  3184. utils.ErrorLog(err.Error())
  3185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3186. return
  3187. }
  3188. timeLayout := "2006-01-02"
  3189. loc, _ := time.LoadLocation("Local")
  3190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3191. if err != nil {
  3192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3193. return
  3194. }
  3195. adminInfo := c.GetAdminUserInfo()
  3196. recordDateTime := theTime.Unix()
  3197. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3198. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3199. var hpInfo models.HisPrescriptionInfo
  3200. if info.ID == 0 {
  3201. var randNum int
  3202. randNum = rand.Intn(10000) + 1000
  3203. timestamp := time.Now().Unix()
  3204. tempTime := time.Unix(timestamp, 0)
  3205. timeFormat := tempTime.Format("20060102150405")
  3206. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3207. hpInfo = models.HisPrescriptionInfo{
  3208. UserOrgId: adminInfo.CurrentOrgId,
  3209. RecordDate: theTime.Unix(),
  3210. PatientId: patient_id,
  3211. Status: 1,
  3212. Ctime: time.Now().Unix(),
  3213. Mtime: time.Now().Unix(),
  3214. Creator: adminInfo.AdminUser.Id,
  3215. Modifier: adminInfo.AdminUser.Id,
  3216. Diagnosis: diagnose,
  3217. SickHistory: sick_history,
  3218. Departments: department,
  3219. RegisterType: reg_type,
  3220. PrescriptionNumber: p_number,
  3221. PrescriptionStatus: 1,
  3222. Doctor: role.UserName,
  3223. DoctorId: doctor_id,
  3224. SickType: sick_type,
  3225. PType: p_type,
  3226. }
  3227. service.SavePatientPrescriptionInfo(hpInfo)
  3228. } else {
  3229. hpInfo = models.HisPrescriptionInfo{
  3230. ID: info.ID,
  3231. UserOrgId: adminInfo.CurrentOrgId,
  3232. RecordDate: info.RecordDate,
  3233. PatientId: info.PatientId,
  3234. Status: 1,
  3235. Ctime: info.Ctime,
  3236. Mtime: time.Now().Unix(),
  3237. Creator: info.Creator,
  3238. Modifier: adminInfo.AdminUser.Id,
  3239. Diagnosis: diagnose,
  3240. SickHistory: sick_history,
  3241. Departments: department,
  3242. RegisterType: reg_type,
  3243. PrescriptionNumber: info.PrescriptionNumber,
  3244. Doctor: role.UserName,
  3245. PrescriptionStatus: info.PrescriptionStatus,
  3246. DoctorId: doctor_id,
  3247. SickType: sick_type,
  3248. PType: info.PType,
  3249. }
  3250. service.SavePatientPrescriptionInfo(hpInfo)
  3251. }
  3252. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3253. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3254. if len(prescriptions) > 0 {
  3255. for _, item := range prescriptions {
  3256. items := item.(map[string]interface{})
  3257. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3258. utils.ErrorLog("id")
  3259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3260. return
  3261. }
  3262. id := int64(items["id"].(float64))
  3263. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3264. utils.ErrorLog("type")
  3265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3266. return
  3267. }
  3268. types := int64(items["type"].(float64))
  3269. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3270. utils.ErrorLog("med_type")
  3271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3272. return
  3273. }
  3274. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3275. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3276. ctime := time.Now().Unix()
  3277. prescription := &models.HisPrescription{
  3278. ID: id,
  3279. PatientId: patient_id,
  3280. UserOrgId: adminInfo.CurrentOrgId,
  3281. RecordDate: recordDateTime,
  3282. Ctime: ctime,
  3283. Mtime: ctime,
  3284. Type: types,
  3285. Modifier: adminInfo.AdminUser.Id,
  3286. Creator: adminInfo.AdminUser.Id,
  3287. Status: 1,
  3288. Doctor: role.UserName,
  3289. HisPatientId: his_patient_id,
  3290. OrderStatus: 1,
  3291. BatchNumber: "",
  3292. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3293. PType: hpInfo.PType,
  3294. MedType: med_type,
  3295. }
  3296. if historyPrescription.ID > 0 {
  3297. prescription.PreTime = historyPrescription.PreTime
  3298. }
  3299. service.SaveHisPrescription(prescription)
  3300. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3301. advices := items["advices"].([]interface{})
  3302. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3303. groupNo := int64(0)
  3304. ctime := time.Now().Unix()
  3305. mtime := ctime
  3306. if len(advices) > 0 {
  3307. for _, advice := range advices {
  3308. var s models.HisDoctorAdviceInfo
  3309. s.PrescriptionId = prescription.ID
  3310. s.AdviceType = 2
  3311. s.AdviceDoctor = adminInfo.AdminUser.Id
  3312. s.StopState = 2
  3313. s.ExecutionState = 2
  3314. s.AdviceDate = recordDateTime
  3315. s.Status = 1
  3316. s.UserOrgId = adminInfo.CurrentOrgId
  3317. s.RecordDate = recordDateTime
  3318. s.StartTime = prescription.PreTime
  3319. s.Groupno = groupNo
  3320. s.CreatedTime = ctime
  3321. s.UpdatedTime = mtime
  3322. s.PatientId = patient_id
  3323. s.HisPatientId = his_patient_id
  3324. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3325. if errcode > 0 {
  3326. c.ServeFailJSONWithSGJErrorCode(errcode)
  3327. return
  3328. }
  3329. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3330. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3331. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3332. if s.Price == 0 {
  3333. s.Price = lastWarehouse.RetailPrice
  3334. }
  3335. }
  3336. service.CreateHisDoctorAdvice(&s)
  3337. //记录日志
  3338. byterequest, _ := json.Marshal(s)
  3339. adviceLog := models.XtDoctorAdviceLog{
  3340. UserOrgId: s.UserOrgId,
  3341. PatientId: s.PatientId,
  3342. AdminUserId: adminInfo.AdminUser.Id,
  3343. Module: 1,
  3344. ErrLog: string(byterequest),
  3345. Status: 1,
  3346. Ctime: time.Now().Unix(),
  3347. Mtime: 0,
  3348. Source: "电脑端his医嘱修改",
  3349. RecordDate: s.AdviceDate,
  3350. }
  3351. service.CreateDoctorAdviceLog(adviceLog)
  3352. redis := service.RedisClient()
  3353. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3354. redis.Set(key, "", time.Second)
  3355. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3356. fmt.Println("keyOne", keyOne)
  3357. redis.Set(keyOne, "", time.Second)
  3358. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3359. redis.Set(keySeven, "", time.Second)
  3360. redis.Close()
  3361. }
  3362. }
  3363. }
  3364. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3365. projects := items["project"].([]interface{})
  3366. if len(projects) > 0 {
  3367. for _, project := range projects {
  3368. var p models.HisPrescriptionProject
  3369. p.PrescriptionId = prescription.ID
  3370. p.Ctime = time.Now().Unix()
  3371. p.Mtime = time.Now().Unix()
  3372. p.PatientId = patient_id
  3373. p.RecordDate = recordDateTime
  3374. p.UserOrgId = adminInfo.CurrentOrgId
  3375. p.HisPatientId = his_patient_id
  3376. p.Status = 1
  3377. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3378. if errcode > 0 {
  3379. c.ServeFailJSONWithSGJErrorCode(errcode)
  3380. return
  3381. }
  3382. service.CreateHisProjectTwo(&p)
  3383. //记录日志
  3384. byterequest, _ := json.Marshal(p)
  3385. adviceLog := models.XtDoctorAdviceLog{
  3386. UserOrgId: p.UserOrgId,
  3387. PatientId: p.PatientId,
  3388. AdminUserId: adminInfo.AdminUser.Id,
  3389. Module: 1,
  3390. ErrLog: string(byterequest),
  3391. Status: 1,
  3392. Ctime: time.Now().Unix(),
  3393. Mtime: 0,
  3394. Source: "电脑端his项目修改",
  3395. RecordDate: p.RecordDate,
  3396. }
  3397. service.CreateDoctorAdviceLog(adviceLog)
  3398. }
  3399. }
  3400. }
  3401. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3402. addition := items["addition"].([]interface{})
  3403. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3404. ctime := time.Now().Unix()
  3405. mtime := ctime
  3406. if len(addition) > 0 {
  3407. for _, item := range addition {
  3408. var s models.HisAdditionalCharge
  3409. s.PrescriptionId = prescription.ID
  3410. s.Status = 1
  3411. s.UserOrgId = adminInfo.CurrentOrgId
  3412. s.RecordDate = recordDateTime
  3413. s.CreatedTime = ctime
  3414. s.UpdatedTime = mtime
  3415. s.PatientId = patient_id
  3416. s.HisPatientId = his_patient_id
  3417. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3418. if errcode > 0 {
  3419. c.ServeFailJSONWithSGJErrorCode(errcode)
  3420. return
  3421. }
  3422. service.CreateAdditionalCharge(&s)
  3423. }
  3424. }
  3425. }
  3426. }
  3427. }
  3428. }
  3429. if err == nil {
  3430. c.ServeSuccessJSON(map[string]interface{}{
  3431. "msg": "保存成功",
  3432. })
  3433. return
  3434. } else {
  3435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3436. return
  3437. }
  3438. }
  3439. func (c *HisApiController) DeletePrescription() {
  3440. prescription_id, _ := c.GetInt64("id")
  3441. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3442. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3443. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3444. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3445. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3446. //耗材保存处方出库
  3447. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3448. //已收费和已发药限制逻辑
  3449. isCharge := false
  3450. isMedicine := false
  3451. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3452. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3453. for _, item := range new_prescriptions {
  3454. if item.IsMedicine == 1 {
  3455. isMedicine = true
  3456. }
  3457. }
  3458. for _, item := range new_prescriptions {
  3459. if item.OrderStatus == 4 {
  3460. isCharge = true
  3461. }
  3462. }
  3463. if p_err != nil {
  3464. if new_prescription.ID > 0 {
  3465. if new_prescription.OrderStatus == 2 {
  3466. isCharge = true
  3467. }
  3468. }
  3469. }
  3470. for _, item := range advices {
  3471. if item.IsMedicine == 1 {
  3472. isMedicine = true
  3473. }
  3474. }
  3475. if isCharge {
  3476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3477. return
  3478. }
  3479. if isMedicine {
  3480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3481. return
  3482. }
  3483. //已收费和已发药限制逻辑
  3484. if len(projects) > 0 {
  3485. for _, item := range projects {
  3486. service.DeletePrintInfo(item.ID) //删除打印信息
  3487. if goodOutConfig.IsOpen != 1 {
  3488. if stockConfig.IsOpen == 1 {
  3489. if item.Type == 3 && item.IsOut == 1 {
  3490. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3491. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3492. good.Total = good.Total + f_count
  3493. service.UpdateGoodInfo(&good)
  3494. operation_time := time.Now().Unix()
  3495. creater := c.GetAdminUserInfo().AdminUser.Id
  3496. //创建退库单
  3497. timeStr := time.Now().Format("2006-01-02")
  3498. timeArr := strings.Split(timeStr, "-")
  3499. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3500. total = total + 1
  3501. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3502. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3503. cancelStock := models.CancelStock{
  3504. OrderNumber: orderNumber,
  3505. OperaTime: operation_time,
  3506. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3507. Creater: creater,
  3508. Ctime: time.Now().Unix(),
  3509. Status: 1,
  3510. ReturnTime: item.RecordDate,
  3511. Type: 1,
  3512. StorehouseId: houseConfig.StorehouseOutInfo,
  3513. IsCheck: 1,
  3514. }
  3515. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3516. if msgerrkonde == gorm.ErrRecordNotFound {
  3517. service.AddSigleCancelStock(&cancelStock)
  3518. }
  3519. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3520. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3521. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3522. //查询该耗材是否出库
  3523. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3524. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3525. deaerler, _ := service.GetDealerById(info.Dealer)
  3526. var total_count int64
  3527. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3528. total_count += count
  3529. if info.ID > 0 {
  3530. if info.Count >= total_count {
  3531. //回退库存
  3532. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3533. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3534. var flush_count int64
  3535. for _, it := range goodList {
  3536. flush_count += it.StockCount
  3537. }
  3538. cancelStockInfo := models.CancelStockInfo{
  3539. GoodId: item.ProjectId,
  3540. CancelStockId: cancel.ID,
  3541. GoodTypeId: good.GoodTypeId,
  3542. Count: prescribingNumber,
  3543. Price: info.Price,
  3544. Total: 0,
  3545. ProductDate: info.ProductDate,
  3546. ExpiryDate: info.ExpiryDate,
  3547. Ctime: time.Now().Unix(),
  3548. Status: 1,
  3549. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3550. OrderNumber: cancel.OrderNumber,
  3551. Type: 0,
  3552. Dealer: deaerler.DealerName,
  3553. Manufacturer: manufacturer.ManufacturerName,
  3554. Number: info.Number,
  3555. RegisterAccount: "",
  3556. Remark: "",
  3557. WarehouseInfoId: info.WarehouseInfotId,
  3558. PatientId: info.PatientId,
  3559. RecordDate: info.SysRecordTime,
  3560. StorehouseId: houseConfig.StorehouseOutInfo,
  3561. IsCheck: 1,
  3562. }
  3563. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3564. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3565. flow := models.VmStockFlow{
  3566. WarehousingId: info.WarehouseInfotId,
  3567. GoodId: item.ProjectId,
  3568. Number: info.Number,
  3569. LicenseNumber: info.LicenseNumber,
  3570. Count: prescribingNumber,
  3571. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3572. PatientId: item.PatientId,
  3573. SystemTime: info.SysRecordTime,
  3574. ConsumableType: 7,
  3575. IsSys: 0,
  3576. WarehousingOrder: "",
  3577. WarehouseOutId: info.WarehouseOutId,
  3578. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3579. IsEdit: 0,
  3580. CancelStockId: cancel.ID,
  3581. CancelOrderNumber: cancel.OrderNumber,
  3582. Manufacturer: manufacturer.ID,
  3583. Dealer: 0,
  3584. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3585. UpdateCreator: 0,
  3586. Status: 1,
  3587. Ctime: time.Now().Unix(),
  3588. Mtime: 0,
  3589. Price: info.Price,
  3590. WarehousingDetailId: info.WarehouseInfotId,
  3591. WarehouseOutDetailId: info.ID,
  3592. CancelOutDetailId: cancelInfo.ID,
  3593. ProductDate: info.ProductDate,
  3594. ExpireDate: info.ExpiryDate,
  3595. StorehouseId: houseConfig.StorehouseOutInfo,
  3596. OverCount: flush_count,
  3597. }
  3598. service.CreateStockFlowOne(flow)
  3599. //退库数量增加
  3600. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3601. //出库数量减少
  3602. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3603. }
  3604. if info.Count < total_count {
  3605. //回退库存
  3606. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3607. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3608. var flush_count int64
  3609. for _, it := range goodList {
  3610. flush_count += it.StockCount
  3611. }
  3612. cancelStockInfo := models.CancelStockInfo{
  3613. GoodId: item.ProjectId,
  3614. CancelStockId: cancel.ID,
  3615. GoodTypeId: good.GoodTypeId,
  3616. Count: info.Count,
  3617. Price: info.Price,
  3618. Total: 0,
  3619. ProductDate: info.ProductDate,
  3620. ExpiryDate: info.ExpiryDate,
  3621. Ctime: time.Now().Unix(),
  3622. Status: 1,
  3623. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3624. OrderNumber: cancel.OrderNumber,
  3625. Type: 0,
  3626. Dealer: deaerler.DealerName,
  3627. Manufacturer: manufacturer.ManufacturerName,
  3628. Number: info.Number,
  3629. RegisterAccount: "",
  3630. Remark: "",
  3631. WarehouseInfoId: info.WarehouseInfotId,
  3632. PatientId: info.PatientId,
  3633. RecordDate: info.SysRecordTime,
  3634. StorehouseId: houseConfig.StorehouseOutInfo,
  3635. IsCheck: 1,
  3636. }
  3637. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3638. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3639. flow := models.VmStockFlow{
  3640. WarehousingId: info.WarehouseInfotId,
  3641. GoodId: item.ProjectId,
  3642. Number: info.Number,
  3643. LicenseNumber: info.LicenseNumber,
  3644. Count: info.Count,
  3645. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3646. PatientId: item.PatientId,
  3647. SystemTime: info.SysRecordTime,
  3648. ConsumableType: 7,
  3649. IsSys: 0,
  3650. WarehousingOrder: "",
  3651. WarehouseOutId: info.WarehouseOutId,
  3652. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3653. IsEdit: 0,
  3654. CancelStockId: cancel.ID,
  3655. CancelOrderNumber: cancel.OrderNumber,
  3656. Manufacturer: manufacturer.ID,
  3657. Dealer: 0,
  3658. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3659. UpdateCreator: 0,
  3660. Status: 1,
  3661. Ctime: time.Now().Unix(),
  3662. Mtime: 0,
  3663. Price: info.Price,
  3664. WarehousingDetailId: info.WarehouseInfotId,
  3665. WarehouseOutDetailId: info.ID,
  3666. CancelOutDetailId: cancelInfo.ID,
  3667. ProductDate: info.ProductDate,
  3668. ExpireDate: info.ExpiryDate,
  3669. StorehouseId: houseConfig.StorehouseOutInfo,
  3670. OverCount: flush_count,
  3671. }
  3672. service.CreateStockFlowOne(flow)
  3673. //退库数量增加
  3674. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3675. //出库数量减少
  3676. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3677. }
  3678. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3679. var flush_count int64
  3680. for _, it := range goodList {
  3681. flush_count += it.StockCount
  3682. }
  3683. //查询已出库数量
  3684. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3685. if prescribingNumber < dialysisInfo.Count {
  3686. //改变数量
  3687. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3688. }
  3689. if prescribingNumber >= dialysisInfo.Count {
  3690. //删除出库表
  3691. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3692. }
  3693. //更新库存
  3694. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3695. //更新基础库库存
  3696. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3697. }
  3698. }
  3699. }
  3700. }
  3701. //保存耗材出库
  3702. if goodOutConfig.IsOpen == 1 {
  3703. if item.Type == 3 {
  3704. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3705. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3706. good.Total = good.Total + f_count
  3707. service.UpdateGoodInfo(&good)
  3708. operation_time := time.Now().Unix()
  3709. creater := c.GetAdminUserInfo().AdminUser.Id
  3710. //创建退库单
  3711. timeStr := time.Now().Format("2006-01-02")
  3712. timeArr := strings.Split(timeStr, "-")
  3713. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3714. total = total + 1
  3715. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3716. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3717. cancelStock := models.CancelStock{
  3718. OrderNumber: orderNumber,
  3719. OperaTime: operation_time,
  3720. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3721. Creater: creater,
  3722. Ctime: time.Now().Unix(),
  3723. Status: 1,
  3724. ReturnTime: item.RecordDate,
  3725. Type: 1,
  3726. StorehouseId: houseConfig.StorehouseOutInfo,
  3727. IsCheck: 1,
  3728. }
  3729. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3730. if msgerrkonde == gorm.ErrRecordNotFound {
  3731. service.AddSigleCancelStock(&cancelStock)
  3732. }
  3733. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3734. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3735. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3736. //查询该耗材是否出库
  3737. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3738. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3739. deaerler, _ := service.GetDealerById(info.Dealer)
  3740. var total_count int64
  3741. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3742. total_count += count
  3743. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3744. var flush_count int64
  3745. for _, it := range goodList {
  3746. flush_count += it.StockCount
  3747. }
  3748. fmt.Println("历史出库数据", info.Count)
  3749. fmt.Println("出库数量", total_count)
  3750. if info.ID > 0 {
  3751. cancelStockInfo := models.CancelStockInfo{
  3752. GoodId: item.ProjectId,
  3753. CancelStockId: cancel.ID,
  3754. GoodTypeId: good.GoodTypeId,
  3755. Count: prescribingNumber,
  3756. Price: info.Price,
  3757. Total: 0,
  3758. ProductDate: info.ProductDate,
  3759. ExpiryDate: info.ExpiryDate,
  3760. Ctime: time.Now().Unix(),
  3761. Status: 1,
  3762. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3763. OrderNumber: cancel.OrderNumber,
  3764. Type: 0,
  3765. Dealer: deaerler.DealerName,
  3766. Manufacturer: manufacturer.ManufacturerName,
  3767. Number: info.Number,
  3768. RegisterAccount: "",
  3769. Remark: "",
  3770. WarehouseInfoId: info.WarehouseInfotId,
  3771. PatientId: info.PatientId,
  3772. RecordDate: info.SysRecordTime,
  3773. StorehouseId: houseConfig.StorehouseOutInfo,
  3774. IsCheck: 1,
  3775. }
  3776. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3777. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3778. //查询出库数量
  3779. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3780. //出库数据 大于 退库数量
  3781. if len(list) > 0 {
  3782. for _, it := range list {
  3783. //回退库存
  3784. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3785. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3786. var flush_count_one int64
  3787. for _, it := range goodList {
  3788. flush_count_one += it.StockCount
  3789. }
  3790. //查询该批次是否有退库数据
  3791. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3792. creater := c.GetAdminUserInfo().AdminUser.Id
  3793. flow := models.VmStockFlow{
  3794. WarehousingId: it.WarehouseInfotId,
  3795. GoodId: it.GoodId,
  3796. Number: it.Number,
  3797. LicenseNumber: it.LicenseNumber,
  3798. Count: it.Count,
  3799. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3800. PatientId: it.PatientId,
  3801. SystemTime: it.SysRecordTime,
  3802. ConsumableType: 7,
  3803. IsSys: 0,
  3804. WarehousingOrder: "",
  3805. WarehouseOutId: it.WarehouseOutId,
  3806. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3807. IsEdit: 0,
  3808. CancelStockId: cancel.ID,
  3809. CancelOrderNumber: cancel.OrderNumber,
  3810. Manufacturer: manufacturer.ID,
  3811. Dealer: 0,
  3812. Creator: creater,
  3813. UpdateCreator: 0,
  3814. Status: 1,
  3815. Ctime: time.Now().Unix(),
  3816. Mtime: 0,
  3817. Price: it.Price,
  3818. WarehousingDetailId: it.WarehouseInfotId,
  3819. WarehouseOutDetailId: it.ID,
  3820. CancelOutDetailId: cancelInfo.ID,
  3821. ProductDate: it.ProductDate,
  3822. ExpireDate: it.ExpiryDate,
  3823. StorehouseId: houseConfig.StorehouseOutInfo,
  3824. OverCount: flush_count_one,
  3825. }
  3826. service.CreateStockFlowOne(flow)
  3827. //if flow.ID > 0 {
  3828. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3829. //}
  3830. }
  3831. }
  3832. //flow := models.VmStockFlow{
  3833. // WarehousingId: info.WarehouseInfotId,
  3834. // GoodId: item.ProjectId,
  3835. // Number: info.Number,
  3836. // LicenseNumber: info.LicenseNumber,
  3837. // Count: prescribingNumber,
  3838. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3839. // PatientId: item.PatientId,
  3840. // SystemTime: info.SysRecordTime,
  3841. // ConsumableType: 7,
  3842. // IsSys: 0,
  3843. // WarehousingOrder: "",
  3844. // WarehouseOutId: info.WarehouseOutId,
  3845. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3846. // IsEdit: 0,
  3847. // CancelStockId: cancel.ID,
  3848. // CancelOrderNumber: cancel.OrderNumber,
  3849. // Manufacturer: manufacturer.ID,
  3850. // Dealer: 0,
  3851. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3852. // UpdateCreator: 0,
  3853. // Status: 1,
  3854. // Ctime: time.Now().Unix(),
  3855. // Mtime: 0,
  3856. // Price: info.Price,
  3857. // WarehousingDetailId: info.WarehouseInfotId,
  3858. // WarehouseOutDetailId: info.ID,
  3859. // CancelOutDetailId: cancelInfo.ID,
  3860. // ProductDate: info.ProductDate,
  3861. // ExpireDate: info.ExpiryDate,
  3862. // StorehouseId: houseConfig.StorehouseOutInfo,
  3863. // OverCount: flush_count,
  3864. //}
  3865. //service.CreateStockFlowOne(flow)
  3866. //退库数量增加
  3867. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3868. //出库数量减少
  3869. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3870. //查询已出库数量
  3871. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3872. if prescribingNumber < dialysisInfo.Count {
  3873. //改变数量
  3874. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3875. }
  3876. if prescribingNumber >= dialysisInfo.Count {
  3877. //删除出库表
  3878. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3879. }
  3880. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3881. var flush_count_one int64
  3882. for _, it := range goodList {
  3883. flush_count_one += it.StockCount
  3884. }
  3885. //更新库存
  3886. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3887. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3888. //更新基础库库存
  3889. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3890. }
  3891. }
  3892. }
  3893. }
  3894. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3895. fmt.Println(err)
  3896. }
  3897. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3898. fmt.Println(err)
  3899. if len(advices) > 0 {
  3900. for _, item := range advices {
  3901. redis := service.RedisClient()
  3902. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3903. redis.Set(keyFive, "", time.Second)
  3904. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3905. redis.Set(keyOne, "", time.Second)
  3906. redis.Close()
  3907. }
  3908. }
  3909. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3910. if len(advices) > 0 {
  3911. for _, item := range advices {
  3912. creater := c.GetAdminUserInfo().AdminUser.Id
  3913. service.DrugAutoAddCancelInfo(item, creater)
  3914. }
  3915. }
  3916. } else {
  3917. if drugOutConfig.IsOpen == 1 {
  3918. if len(advices) > 0 {
  3919. for _, item := range advices {
  3920. creater := c.GetAdminUserInfo().AdminUser.Id
  3921. service.DrugAutoAddCancelInfo(item, creater)
  3922. }
  3923. }
  3924. } else {
  3925. if len(advices) > 0 {
  3926. for _, item := range advices {
  3927. creater := c.GetAdminUserInfo().AdminUser.Id
  3928. service.DrugAutoAddCancelInfo(item, creater)
  3929. }
  3930. }
  3931. }
  3932. }
  3933. c.ServeSuccessJSON(map[string]interface{}{
  3934. "msg": "删除成功",
  3935. })
  3936. return
  3937. }
  3938. func (c *HisApiController) DeleteDoctorAdvice() {
  3939. id, _ := c.GetInt64("id")
  3940. advice, _ := service.GetHisDoctorAdvicesById(id)
  3941. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3942. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3943. //已收费和已发药的限制逻辑
  3944. isCharge := false
  3945. isMedicine := false
  3946. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3947. //获取今天该患者所有处方,判断是否发药或者收费
  3948. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3949. for _, item := range new_prescriptions {
  3950. if item.IsMedicine == 1 {
  3951. isMedicine = true
  3952. }
  3953. }
  3954. for _, item := range new_prescriptions {
  3955. if item.OrderStatus == 4 {
  3956. isCharge = true
  3957. }
  3958. }
  3959. if isMedicine {
  3960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3961. return
  3962. }
  3963. if isCharge {
  3964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3965. return
  3966. }
  3967. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3968. for _, item := range advices {
  3969. if item.IsMedicine == 1 {
  3970. isMedicine = true
  3971. }
  3972. }
  3973. if isMedicine {
  3974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3975. return
  3976. }
  3977. if new_prescription.ID > 0 {
  3978. if new_prescription.OrderStatus == 2 {
  3979. isCharge = true
  3980. }
  3981. }
  3982. if isCharge {
  3983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3984. return
  3985. }
  3986. //已收费和已发药的限制逻辑
  3987. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3988. redis := service.RedisClient()
  3989. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3990. redis.Set(keyFive, "", time.Second)
  3991. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3992. redis.Set(keyOne, "", time.Second)
  3993. defer redis.Close()
  3994. if err == nil {
  3995. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3996. //查询是否在处方中出库
  3997. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3998. if openConfig.IsOpen != 1 {
  3999. //判断该医嘱是否执行了
  4000. if advice.ExecutionState == 1 {
  4001. creater := c.GetAdminUserInfo().AdminUser.Id
  4002. service.DrugAutoAddCancelInfo(&advice, creater)
  4003. }
  4004. }
  4005. //开启保存处方扣减功能
  4006. if openConfig.IsOpen == 1 {
  4007. creater := c.GetAdminUserInfo().AdminUser.Id
  4008. service.DrugAutoAddCancelInfo(&advice, creater)
  4009. }
  4010. } else {
  4011. if drugOutConfig.IsOpen == 1 {
  4012. //查询是否在处方中出库
  4013. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4014. if openConfig.IsOpen != 1 {
  4015. //判断该医嘱是否执行了
  4016. if advice.ExecutionState == 1 {
  4017. creater := c.GetAdminUserInfo().AdminUser.Id
  4018. service.DrugAutoAddCancelInfo(&advice, creater)
  4019. }
  4020. }
  4021. //开启保存处方扣减功能
  4022. if openConfig.IsOpen == 1 {
  4023. creater := c.GetAdminUserInfo().AdminUser.Id
  4024. service.DrugAutoAddCancelInfo(&advice, creater)
  4025. }
  4026. } else {
  4027. //判断该医嘱是否执行了
  4028. if advice.ExecutionState == 1 {
  4029. creater := c.GetAdminUserInfo().AdminUser.Id
  4030. service.DrugAutoAddCancelInfo(&advice, creater)
  4031. }
  4032. }
  4033. }
  4034. c.ServeSuccessJSON(map[string]interface{}{
  4035. "msg": "删除成功",
  4036. })
  4037. return
  4038. } else {
  4039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4040. return
  4041. }
  4042. }
  4043. func (c *HisApiController) DeleteProject() {
  4044. id, _ := c.GetInt64("id")
  4045. adminInfo := c.GetAdminUserInfo()
  4046. project, _ := service.GetHisProjectByID(id)
  4047. // var consumable models.DialysisBeforePrepare
  4048. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4049. //耗材保存处方出库
  4050. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4051. isCharge := false
  4052. isMedicine := false
  4053. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4054. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4055. for _, item := range new_prescriptions {
  4056. if item.IsMedicine == 1 {
  4057. isMedicine = true
  4058. }
  4059. }
  4060. for _, item := range new_prescriptions {
  4061. if item.OrderStatus == 4 {
  4062. isCharge = true
  4063. }
  4064. }
  4065. if isMedicine {
  4066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4067. return
  4068. }
  4069. if isCharge {
  4070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4071. return
  4072. }
  4073. if new_prescription.ID > 0 {
  4074. if new_prescription.OrderStatus == 2 {
  4075. isCharge = true
  4076. }
  4077. }
  4078. if isCharge {
  4079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4080. return
  4081. }
  4082. service.DeletePrintInfo(id)
  4083. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4084. label.Status = 0
  4085. service.CreateHisLabelRecord(&label)
  4086. fmt.Println(goodOutConfig.IsOpen)
  4087. if goodOutConfig.IsOpen != 1 {
  4088. if stockConfig.IsOpen == 1 {
  4089. if project.Type == 2 {
  4090. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4091. fmt.Println(err)
  4092. }
  4093. if project.Type == 3 && project.IsOut == 1 {
  4094. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4095. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4096. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4097. operation_time := time.Now().Unix()
  4098. creater := adminInfo.AdminUser.Id
  4099. //创建退库单
  4100. timeStr := time.Now().Format("2006-01-02")
  4101. timeArr := strings.Split(timeStr, "-")
  4102. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4103. total = total + 1
  4104. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4105. cancelStock := models.CancelStock{
  4106. OrderNumber: orderNumber,
  4107. OperaTime: operation_time,
  4108. OrgId: adminInfo.CurrentOrgId,
  4109. Creater: creater,
  4110. Ctime: time.Now().Unix(),
  4111. Status: 1,
  4112. ReturnTime: project.RecordDate,
  4113. Type: 1,
  4114. StorehouseId: houseConfig.StorehouseOutInfo,
  4115. IsCheck: 1,
  4116. }
  4117. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4118. if msgerrkonde == gorm.ErrRecordNotFound {
  4119. service.AddSigleCancelStock(&cancelStock)
  4120. }
  4121. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4122. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4123. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4124. //查询是否有出库
  4125. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4126. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4127. deaerler, _ := service.GetDealerById(info.Dealer)
  4128. if info.ID > 0 {
  4129. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4130. if info.Count >= prescribingNumber {
  4131. cancelStockInfo := models.CancelStockInfo{
  4132. GoodId: project.ProjectId,
  4133. CancelStockId: cancel.ID,
  4134. GoodTypeId: good.GoodTypeId,
  4135. Count: prescribingNumber,
  4136. Price: info.Price,
  4137. Total: 0,
  4138. ProductDate: info.ProductDate,
  4139. ExpiryDate: info.ExpiryDate,
  4140. Ctime: time.Now().Unix(),
  4141. Status: 1,
  4142. OrgId: adminInfo.CurrentOrgId,
  4143. OrderNumber: cancel.OrderNumber,
  4144. Type: 0,
  4145. Dealer: deaerler.DealerName,
  4146. Manufacturer: manufacturer.ManufacturerName,
  4147. Number: info.Number,
  4148. RegisterAccount: "",
  4149. Remark: "",
  4150. WarehouseInfoId: info.WarehouseInfotId,
  4151. PatientId: info.PatientId,
  4152. RecordDate: info.SysRecordTime,
  4153. StorehouseId: houseConfig.StorehouseOutInfo,
  4154. IsCheck: 1,
  4155. }
  4156. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4157. //回退库存
  4158. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4159. //退库数量增加
  4160. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4161. //出库数量减少
  4162. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4163. }
  4164. if info.Count < prescribingNumber {
  4165. cancelStockInfo := models.CancelStockInfo{
  4166. GoodId: project.ProjectId,
  4167. CancelStockId: cancel.ID,
  4168. GoodTypeId: good.GoodTypeId,
  4169. Count: info.Count,
  4170. Price: info.Price,
  4171. Total: 0,
  4172. ProductDate: info.ProductDate,
  4173. ExpiryDate: info.ExpiryDate,
  4174. Ctime: time.Now().Unix(),
  4175. Status: 1,
  4176. OrgId: adminInfo.CurrentOrgId,
  4177. OrderNumber: cancel.OrderNumber,
  4178. Type: 0,
  4179. Dealer: deaerler.DealerName,
  4180. Manufacturer: manufacturer.ManufacturerName,
  4181. Number: info.Number,
  4182. RegisterAccount: "",
  4183. Remark: "",
  4184. WarehouseInfoId: info.WarehouseInfotId,
  4185. PatientId: info.PatientId,
  4186. RecordDate: info.SysRecordTime,
  4187. StorehouseId: houseConfig.StorehouseOutInfo,
  4188. IsCheck: 1,
  4189. }
  4190. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4191. //回退库存
  4192. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4193. //退库数量增加
  4194. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4195. //出库数量减少
  4196. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4197. }
  4198. //查询剩余库存
  4199. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4200. var over_count int64
  4201. for _, it := range goodList {
  4202. over_count += it.StockCount
  4203. }
  4204. //出库数据 大于 退库数量
  4205. if info.Count >= prescribingNumber {
  4206. flow := models.VmStockFlow{
  4207. WarehousingId: info.WarehouseInfotId,
  4208. GoodId: project.ProjectId,
  4209. Number: info.Number,
  4210. LicenseNumber: info.LicenseNumber,
  4211. Count: prescribingNumber,
  4212. UserOrgId: adminInfo.CurrentOrgId,
  4213. PatientId: project.PatientId,
  4214. SystemTime: info.SysRecordTime,
  4215. ConsumableType: 7,
  4216. IsSys: 0,
  4217. WarehousingOrder: "",
  4218. WarehouseOutId: info.WarehouseOutId,
  4219. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4220. IsEdit: 0,
  4221. CancelStockId: cancel.ID,
  4222. CancelOrderNumber: cancel.OrderNumber,
  4223. Manufacturer: manufacturer.ID,
  4224. Dealer: 0,
  4225. Creator: adminInfo.AdminUser.Id,
  4226. UpdateCreator: 0,
  4227. Status: 1,
  4228. Ctime: time.Now().Unix(),
  4229. Mtime: 0,
  4230. Price: info.Price,
  4231. WarehousingDetailId: info.WarehouseInfotId,
  4232. WarehouseOutDetailId: info.ID,
  4233. CancelOutDetailId: cancelInfo.ID,
  4234. ProductDate: info.ProductDate,
  4235. ExpireDate: info.ExpiryDate,
  4236. StorehouseId: houseConfig.StorehouseOutInfo,
  4237. OverCount: over_count,
  4238. }
  4239. service.CreateStockFlowOne(flow)
  4240. }
  4241. //出库数据小于退库数据
  4242. if info.Count < prescribingNumber {
  4243. flow := models.VmStockFlow{
  4244. WarehousingId: info.WarehouseInfotId,
  4245. GoodId: project.ProjectId,
  4246. Number: info.Number,
  4247. LicenseNumber: info.LicenseNumber,
  4248. Count: info.Count,
  4249. UserOrgId: adminInfo.CurrentOrgId,
  4250. PatientId: project.PatientId,
  4251. SystemTime: info.SysRecordTime,
  4252. ConsumableType: 7,
  4253. IsSys: 0,
  4254. WarehousingOrder: "",
  4255. WarehouseOutId: info.WarehouseOutId,
  4256. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4257. IsEdit: 0,
  4258. CancelStockId: cancel.ID,
  4259. CancelOrderNumber: cancel.OrderNumber,
  4260. Manufacturer: manufacturer.ID,
  4261. Dealer: 0,
  4262. Creator: adminInfo.AdminUser.Id,
  4263. UpdateCreator: 0,
  4264. Status: 1,
  4265. Ctime: time.Now().Unix(),
  4266. Mtime: 0,
  4267. Price: info.Price,
  4268. WarehousingDetailId: info.WarehouseInfotId,
  4269. WarehouseOutDetailId: info.ID,
  4270. CancelOutDetailId: cancelInfo.ID,
  4271. ProductDate: info.ProductDate,
  4272. ExpireDate: info.ExpiryDate,
  4273. StorehouseId: houseConfig.StorehouseOutInfo,
  4274. OverCount: over_count,
  4275. }
  4276. service.CreateStockFlowOne(flow)
  4277. }
  4278. //查询已出库数量
  4279. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4280. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4281. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4282. if prescribingNumber < dialysisInfo.Count {
  4283. //改变数量
  4284. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4285. }
  4286. if prescribingNumber >= dialysisInfo.Count {
  4287. //删除出库表
  4288. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4289. }
  4290. //更新剩余库存
  4291. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4292. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4293. var total_count_one int64
  4294. for _, it := range stockList {
  4295. total_count_one += it.StockCount
  4296. }
  4297. //基础库插入数据
  4298. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4299. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4300. var flush_count int64
  4301. for _, it := range goodListOne {
  4302. flush_count += it.StockCount
  4303. }
  4304. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4305. if errs != nil {
  4306. goodErrcode := models.XtGoodErrcode{
  4307. UserOrgId: project.UserOrgId,
  4308. Errcode: "手动出库更新剩余出库失败",
  4309. GoodId: project.ProjectId,
  4310. Status: 1,
  4311. Ctime: time.Now().Unix(),
  4312. Mtime: 0,
  4313. Count: 0,
  4314. StockCount: 0,
  4315. Creater: creater,
  4316. BatchNumberId: 0,
  4317. WarehouseOutId: 0,
  4318. }
  4319. service.CreateGoodErrcode(goodErrcode)
  4320. }
  4321. }
  4322. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4323. fmt.Println(err)
  4324. } else {
  4325. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4326. fmt.Println(err)
  4327. }
  4328. } else {
  4329. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4330. fmt.Println(err)
  4331. }
  4332. }
  4333. //保存处方出库
  4334. if goodOutConfig.IsOpen == 1 {
  4335. if project.Type == 3 {
  4336. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4337. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4338. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4339. operation_time := time.Now().Unix()
  4340. creater := adminInfo.AdminUser.Id
  4341. //创建退库单
  4342. timeStr := time.Now().Format("2006-01-02")
  4343. timeArr := strings.Split(timeStr, "-")
  4344. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4345. total = total + 1
  4346. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4347. cancelStock := models.CancelStock{
  4348. OrderNumber: orderNumber,
  4349. OperaTime: operation_time,
  4350. OrgId: adminInfo.CurrentOrgId,
  4351. Creater: creater,
  4352. Ctime: time.Now().Unix(),
  4353. Status: 1,
  4354. ReturnTime: project.RecordDate,
  4355. Type: 1,
  4356. StorehouseId: houseConfig.StorehouseOutInfo,
  4357. IsCheck: 1,
  4358. }
  4359. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4360. if msgerrkonde == gorm.ErrRecordNotFound {
  4361. service.AddSigleCancelStock(&cancelStock)
  4362. }
  4363. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4364. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4365. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4366. //获取出库数据
  4367. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4368. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4369. deaerler, _ := service.GetDealerById(info.Dealer)
  4370. if info.ID > 0 {
  4371. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4372. if info.Count >= prescribingNumber {
  4373. cancelStockInfo := models.CancelStockInfo{
  4374. GoodId: project.ProjectId,
  4375. CancelStockId: cancel.ID,
  4376. GoodTypeId: good.GoodTypeId,
  4377. Count: prescribingNumber,
  4378. Price: info.Price,
  4379. Total: 0,
  4380. ProductDate: info.ProductDate,
  4381. ExpiryDate: info.ExpiryDate,
  4382. Ctime: time.Now().Unix(),
  4383. Status: 1,
  4384. OrgId: adminInfo.CurrentOrgId,
  4385. OrderNumber: cancel.OrderNumber,
  4386. Type: 0,
  4387. Dealer: deaerler.DealerName,
  4388. Manufacturer: manufacturer.ManufacturerName,
  4389. Number: info.Number,
  4390. RegisterAccount: "",
  4391. Remark: "",
  4392. WarehouseInfoId: info.WarehouseInfotId,
  4393. PatientId: info.PatientId,
  4394. RecordDate: info.SysRecordTime,
  4395. StorehouseId: houseConfig.StorehouseOutInfo,
  4396. IsCheck: 1,
  4397. }
  4398. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4399. //退库数量增加
  4400. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4401. //出库数量减少
  4402. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4403. }
  4404. if info.Count < prescribingNumber {
  4405. cancelStockInfo := models.CancelStockInfo{
  4406. GoodId: project.ProjectId,
  4407. CancelStockId: cancel.ID,
  4408. GoodTypeId: good.GoodTypeId,
  4409. Count: prescribingNumber,
  4410. Price: info.Price,
  4411. Total: 0,
  4412. ProductDate: info.ProductDate,
  4413. ExpiryDate: info.ExpiryDate,
  4414. Ctime: time.Now().Unix(),
  4415. Status: 1,
  4416. OrgId: adminInfo.CurrentOrgId,
  4417. OrderNumber: cancel.OrderNumber,
  4418. Type: 0,
  4419. Dealer: deaerler.DealerName,
  4420. Manufacturer: manufacturer.ManufacturerName,
  4421. Number: info.Number,
  4422. RegisterAccount: "",
  4423. Remark: "",
  4424. WarehouseInfoId: info.WarehouseInfotId,
  4425. PatientId: info.PatientId,
  4426. RecordDate: info.SysRecordTime,
  4427. StorehouseId: houseConfig.StorehouseOutInfo,
  4428. IsCheck: 1,
  4429. }
  4430. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4431. //回退库存
  4432. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4433. }
  4434. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4435. var over_count int64
  4436. for _, it := range goodList {
  4437. over_count += it.StockCount
  4438. }
  4439. //查询出库数量
  4440. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4441. //出库数据 大于 退库数量
  4442. if len(list) > 0 {
  4443. for _, it := range list {
  4444. //回退库存
  4445. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4446. //退库数量增加
  4447. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4448. //出库数量减少
  4449. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4450. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4451. var over_count_one int64
  4452. for _, it := range goodList {
  4453. over_count_one += it.StockCount
  4454. }
  4455. //查询该批次是否有退库数据
  4456. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4457. flow := models.VmStockFlow{
  4458. WarehousingId: it.WarehouseInfotId,
  4459. GoodId: it.GoodId,
  4460. Number: it.Number,
  4461. LicenseNumber: it.LicenseNumber,
  4462. Count: it.Count,
  4463. UserOrgId: adminInfo.CurrentOrgId,
  4464. PatientId: it.PatientId,
  4465. SystemTime: it.SysRecordTime,
  4466. ConsumableType: 7,
  4467. IsSys: 0,
  4468. WarehousingOrder: "",
  4469. WarehouseOutId: it.WarehouseOutId,
  4470. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4471. IsEdit: 0,
  4472. CancelStockId: cancel.ID,
  4473. CancelOrderNumber: cancel.OrderNumber,
  4474. Manufacturer: manufacturer.ID,
  4475. Dealer: 0,
  4476. Creator: adminInfo.AdminUser.Id,
  4477. UpdateCreator: 0,
  4478. Status: 1,
  4479. Ctime: time.Now().Unix(),
  4480. Mtime: 0,
  4481. Price: it.Price,
  4482. WarehousingDetailId: it.WarehouseInfotId,
  4483. WarehouseOutDetailId: it.ID,
  4484. CancelOutDetailId: cancelInfo.ID,
  4485. ProductDate: it.ProductDate,
  4486. ExpireDate: it.ExpiryDate,
  4487. StorehouseId: houseConfig.StorehouseOutInfo,
  4488. OverCount: over_count_one,
  4489. }
  4490. service.CreateStockFlowOne(flow)
  4491. }
  4492. }
  4493. //查询已出库数量
  4494. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4495. if prescribingNumber < dialysisInfo.Count {
  4496. //改变数量
  4497. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4498. }
  4499. if prescribingNumber >= dialysisInfo.Count {
  4500. //删除出库表
  4501. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4502. }
  4503. //更新剩余库存
  4504. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4505. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4506. var total_count_one int64
  4507. for _, it := range stockList {
  4508. total_count_one += it.StockCount
  4509. }
  4510. //基础库插入数据
  4511. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4512. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4513. var flush_count int64
  4514. for _, it := range goodListOne {
  4515. flush_count += it.StockCount
  4516. }
  4517. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4518. if errs != nil {
  4519. goodErrcode := models.XtGoodErrcode{
  4520. UserOrgId: project.UserOrgId,
  4521. Errcode: "手动出库更新剩余出库失败",
  4522. GoodId: project.ProjectId,
  4523. Status: 1,
  4524. Ctime: time.Now().Unix(),
  4525. Mtime: 0,
  4526. Count: 0,
  4527. StockCount: 0,
  4528. Creater: creater,
  4529. BatchNumberId: 0,
  4530. WarehouseOutId: 0,
  4531. }
  4532. service.CreateGoodErrcode(goodErrcode)
  4533. }
  4534. }
  4535. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4536. fmt.Println(err)
  4537. } else {
  4538. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4539. fmt.Println(err)
  4540. }
  4541. }
  4542. c.ServeSuccessJSON(map[string]interface{}{
  4543. "msg": "删除成功",
  4544. })
  4545. return
  4546. }
  4547. func (c *HisApiController) CreateHisAdditionalCharge() {
  4548. his_patient_id, _ := c.GetInt64("his_patient_id")
  4549. patient_id, _ := c.GetInt64("patient_id")
  4550. record_date := c.GetString("record_date")
  4551. timeLayout := "2006-01-02"
  4552. loc, _ := time.LoadLocation("Local")
  4553. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4554. if err != nil {
  4555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4556. return
  4557. }
  4558. adminInfo := c.GetAdminUserInfo()
  4559. recordDateTime := theTime.Unix()
  4560. dataBody := make(map[string]interface{}, 0)
  4561. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4562. if err != nil {
  4563. utils.ErrorLog(err.Error())
  4564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4565. return
  4566. }
  4567. var additions []*models.HisAdditionalCharge
  4568. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4569. additions, _ := dataBody["addition"].([]interface{})
  4570. if len(additions) > 0 {
  4571. for _, item := range additions {
  4572. items := item.(map[string]interface{})
  4573. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4574. utils.ErrorLog("item_id")
  4575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4576. return
  4577. }
  4578. item_id := int64(items["item_id"].(float64))
  4579. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4580. utils.ErrorLog("item_name")
  4581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4582. return
  4583. }
  4584. item_name := items["item_name"].(string)
  4585. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4586. utils.ErrorLog("price")
  4587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4588. return
  4589. }
  4590. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4591. ctime := time.Now().Unix()
  4592. additional := &models.HisAdditionalCharge{
  4593. PatientId: patient_id,
  4594. HisPatientId: his_patient_id,
  4595. UserOrgId: adminInfo.CurrentOrgId,
  4596. RecordDate: recordDateTime,
  4597. CreatedTime: ctime,
  4598. UpdatedTime: ctime,
  4599. Modifier: adminInfo.AdminUser.Id,
  4600. Creator: adminInfo.AdminUser.Id,
  4601. Price: price,
  4602. ItemName: item_name,
  4603. ItemId: item_id,
  4604. Status: 1,
  4605. }
  4606. additions = append(additions, additional)
  4607. }
  4608. }
  4609. }
  4610. for _, item := range additions {
  4611. service.CreateAddtionalCharge(item)
  4612. }
  4613. c.ServeSuccessJSON(map[string]interface{}{
  4614. "msg": "创建成功",
  4615. })
  4616. }
  4617. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4618. blood_fat := c.GetString("blood_fat")
  4619. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4620. blood_sugar := c.GetString("blood_sugar")
  4621. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4622. chief_conplaint := c.GetString("chief_conplaint")
  4623. dbp := c.GetString("dbp")
  4624. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4625. delivery_way, _ := c.GetInt64("delivery_way")
  4626. diagnostic := c.GetString("diagnostic")
  4627. family_history := c.GetString("family_history")
  4628. height := c.GetString("height")
  4629. history_of_present_illness := c.GetString("history_of_present_illness")
  4630. is_infect, _ := c.GetInt64("is_infect")
  4631. past_history := c.GetString("past_history")
  4632. patient_id, _ := c.GetInt64("patient_id")
  4633. his_patient_id, _ := c.GetInt64("his_patient_id")
  4634. personal_history := c.GetString("personal_history")
  4635. pulse := c.GetString("pulse")
  4636. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4637. sbp := c.GetString("sbp")
  4638. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4639. heightfloat, _ := strconv.ParseFloat(height, 64)
  4640. sicktype := c.GetString("sick_type")
  4641. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4642. symptom := c.GetString("symptom")
  4643. sick_date := c.GetString("sick_date")
  4644. temperatures := c.GetString("temperature")
  4645. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4646. record_date := c.GetString("record_date")
  4647. breathing := c.GetString("breathing")
  4648. doctor_advice := c.GetString("doctor_advice")
  4649. remark := c.GetString("remark")
  4650. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4651. sick, _ := c.GetInt64("sick")
  4652. diagnose, _ := c.GetInt64("diagnose")
  4653. //id, _ := c.GetInt64("id")
  4654. timeLayout := "2006-01-02"
  4655. loc, _ := time.LoadLocation("Local")
  4656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4657. allergic_history := c.GetString("allergic_history")
  4658. if err != nil {
  4659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4660. return
  4661. }
  4662. recordDateTime := theTime.Unix()
  4663. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4664. if err != nil {
  4665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4666. return
  4667. }
  4668. sickTimes := sickTime.Unix()
  4669. ctime := time.Now().Unix()
  4670. primary_disease := c.GetString("primary_disease")
  4671. confirm_failure_date := c.GetString("confirm_failure_date")
  4672. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4673. drug_allergy_history := c.GetString("drug_allergy_history")
  4674. physical_examination := c.GetString("physical_examination")
  4675. special_inspection := c.GetString("special_inspection")
  4676. lab_apparatus := c.GetString("lab_apparatus")
  4677. caseHistory := models.HisPatientCaseHistory{
  4678. HisPatientId: his_patient_id,
  4679. PatientId: patient_id,
  4680. Temperature: temperature,
  4681. BloodSugar: bloodsugarfloat,
  4682. Pulse: pulsefloat,
  4683. Sbp: sbpfloat,
  4684. Dbp: dbpfloat,
  4685. Height: heightfloat,
  4686. BloodFat: bloodfatfloat,
  4687. SickType: sick_type,
  4688. Symptom: symptom,
  4689. SickDate: sickTimes,
  4690. IsInfect: is_infect,
  4691. HistoryOfPresentIllness: history_of_present_illness,
  4692. PastHistory: past_history,
  4693. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4694. ChiefConplaint: chief_conplaint,
  4695. PersonalHistory: personal_history,
  4696. FamilyHistory: family_history,
  4697. Diagnostic: diagnostic,
  4698. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4699. Status: 1,
  4700. Ctime: ctime,
  4701. Mtime: ctime,
  4702. RecordDate: recordDateTime,
  4703. DeliveryWay: delivery_way,
  4704. Breathing: breathingfloat,
  4705. DoctorAdvice: doctor_advice,
  4706. Remark: remark,
  4707. Sick: sick,
  4708. Diagnose: diagnose,
  4709. AllergicHistory: allergic_history,
  4710. PrimaryDisease: primary_disease,
  4711. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4712. DrugAllergyHistory: drug_allergy_history,
  4713. PhysicalExamination: physical_examination,
  4714. SpecialInspection: special_inspection,
  4715. LabApparatus: lab_apparatus,
  4716. }
  4717. //查询该患者是否有病历
  4718. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4719. if errcodes == gorm.ErrRecordNotFound {
  4720. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4721. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4722. if err != nil {
  4723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4724. return
  4725. }
  4726. c.ServeSuccessJSON(map[string]interface{}{
  4727. "caseHistory": caseHistory,
  4728. "historyInfo": historyInfo,
  4729. })
  4730. return
  4731. } else if errcodes == nil {
  4732. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4733. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4734. if err != nil {
  4735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4736. return
  4737. }
  4738. c.ServeSuccessJSON(map[string]interface{}{
  4739. "caseHistory": caseHistory,
  4740. "historyInfo": historyInfo,
  4741. })
  4742. }
  4743. //查询该患者是否有病历
  4744. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4745. //if errcode == gorm.ErrRecordNotFound {
  4746. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4747. // if err != nil {
  4748. // c.ServeSuccessJSON(map[string]interface{}{
  4749. // "msg": "保存成功",
  4750. // })
  4751. // }
  4752. //} else if errcode == nil {
  4753. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4754. // return
  4755. //}
  4756. }
  4757. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4758. patient_id, _ := c.GetInt64("patient_id", 0)
  4759. adminUser := c.GetAdminUserInfo()
  4760. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4761. c.ServeSuccessJSON(map[string]interface{}{
  4762. "list": caseHistorys,
  4763. })
  4764. }
  4765. func (c *HisApiController) GetHisPatientCaseHistory() {
  4766. record_date, _ := c.GetInt64("record_date", 0)
  4767. patient_id, _ := c.GetInt64("patient_id", 0)
  4768. admin := c.GetAdminUserInfo()
  4769. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4770. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4771. c.ServeSuccessJSON(map[string]interface{}{
  4772. "info": info,
  4773. "case_history": case_history,
  4774. })
  4775. }
  4776. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4777. template_name := c.GetString("template_name")
  4778. template_remark := c.GetString("template_remark")
  4779. doctor := c.GetAdminUserInfo().AdminUser.Id
  4780. diagnostic := c.GetString("diagnostic")
  4781. chief_conplaint := c.GetString("chief_conplain")
  4782. history_of_present_illness := c.GetString("history_of_present_illness")
  4783. past_history := c.GetString("past_history")
  4784. personal_history := c.GetString("personal_history")
  4785. family_history := c.GetString("family_history")
  4786. user_name := c.GetString("user_name")
  4787. doctor_advice := c.GetString("doctor_advice")
  4788. remark := c.GetString("remark")
  4789. //record_date := c.GetString("record_date")
  4790. //fmt.Println("record_date--------",record_date)
  4791. //timeLayout := "2006-01-02"
  4792. //loc, _ := time.LoadLocation("Local")
  4793. //
  4794. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4795. //if err != nil {
  4796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4797. // return
  4798. //}
  4799. //recordDateTime := theTime.Unix()
  4800. ctime := time.Now().Unix()
  4801. template := models.HisCaseHistoryTemplate{
  4802. HistoryOfPresentIllness: history_of_present_illness,
  4803. PastHistory: past_history,
  4804. ChiefConplaint: chief_conplaint,
  4805. PersonalHistory: personal_history,
  4806. FamilyHistory: family_history,
  4807. Diagnostic: diagnostic,
  4808. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4809. Status: 1,
  4810. Ctime: ctime,
  4811. Mtime: ctime,
  4812. RecordDate: time.Now().Unix(),
  4813. TemplateName: template_name,
  4814. TemplateRemark: template_remark,
  4815. Creator: doctor,
  4816. Modifier: doctor,
  4817. UserName: user_name,
  4818. DoctorAdvice: doctor_advice,
  4819. Remark: remark,
  4820. }
  4821. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4822. if err == nil {
  4823. c.ServeSuccessJSON(map[string]interface{}{
  4824. "msg": "保存成功",
  4825. })
  4826. } else {
  4827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4828. return
  4829. }
  4830. }
  4831. func (c *HisApiController) GetCaseHistoryTemplate() {
  4832. timeLayout := "2006-01-02"
  4833. loc, _ := time.LoadLocation("Local")
  4834. keyword := c.GetString("keyword")
  4835. start_time := c.GetString("start_time")
  4836. end_time := c.GetString("end_time")
  4837. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4838. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4839. admin := c.GetAdminUserInfo()
  4840. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4841. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4842. c.ServeSuccessJSON(map[string]interface{}{
  4843. "template": template,
  4844. //"history": history,
  4845. })
  4846. }
  4847. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4848. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4849. utils.ErrorLog("drug_name")
  4850. return enums.ErrorCodeParamWrong
  4851. }
  4852. adviceName, _ := json["drug_name"].(string)
  4853. if len(adviceName) == 0 {
  4854. utils.ErrorLog("len(advice_name) == 0")
  4855. return enums.ErrorCodeParamWrong
  4856. }
  4857. advice.AdviceName = adviceName
  4858. adviceDesc, _ := json["advice_desc"].(string)
  4859. advice.AdviceDesc = adviceDesc
  4860. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4861. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4862. advice.DrugSpec = drugSpec
  4863. }
  4864. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4865. remark, _ := json["remark"].(string)
  4866. advice.Remark = remark
  4867. }
  4868. if json["id"] == nil {
  4869. advice.DrugId = 0
  4870. } else {
  4871. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4872. drug_id := int64(json["id"].(float64))
  4873. advice.DrugId = drug_id
  4874. }
  4875. }
  4876. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4877. advice_id := int64(json["advice_id"].(float64))
  4878. advice.ID = advice_id
  4879. if advice.ID > 0 {
  4880. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4881. if err == nil {
  4882. if hisAdvice.ID > 0 {
  4883. advice.ExecutionTime = hisAdvice.ExecutionTime
  4884. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4885. advice.ExecutionState = hisAdvice.ExecutionState
  4886. advice.CheckTime = hisAdvice.CheckTime
  4887. advice.Checker = hisAdvice.Checker
  4888. advice.CheckState = hisAdvice.CheckState
  4889. advice.StartTime = hisAdvice.StartTime
  4890. advice.FeedetlSn = hisAdvice.FeedetlSn
  4891. }
  4892. }
  4893. }
  4894. }
  4895. //
  4896. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4897. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4898. // advice.ExecutionTime = execution_time
  4899. //}
  4900. //
  4901. //
  4902. //
  4903. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4904. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4905. // advice.ExecutionStaff = execution_staff
  4906. //}
  4907. //
  4908. //
  4909. //
  4910. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4911. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4912. // advice.ExecutionState = execution_state
  4913. //}
  4914. //
  4915. //
  4916. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4917. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4918. // advice.CheckTime = check_time
  4919. //}
  4920. //
  4921. //
  4922. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4923. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4924. // advice.CheckState = check_state
  4925. //}
  4926. //
  4927. //
  4928. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4929. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4930. // advice.Checker = checker
  4931. //}
  4932. //
  4933. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4934. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4935. // advice.StartTime = start_time
  4936. //}
  4937. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4938. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4939. advice.IsSelfDrug = is_self_drug
  4940. }
  4941. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  4942. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  4943. drug_way_count, _ := json["drug_way_count"].(string)
  4944. advice.DrugWayCount = drug_way_count
  4945. }
  4946. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4947. drugSpecUnit, _ := json["min_unit"].(string)
  4948. advice.DrugSpecUnit = drugSpecUnit
  4949. }
  4950. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4951. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4952. advice.SingleDose = singleDose
  4953. }
  4954. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4955. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4956. advice.SingleDoseUnit = singleDoseUnit
  4957. }
  4958. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4959. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4960. advice.PrescribingNumber = prescribingNumber
  4961. }
  4962. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4963. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4964. advice.PrescribingNumberUnit = prescribingNumberUnit
  4965. }
  4966. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4967. deliveryWay, _ := json["delivery_way"].(string)
  4968. advice.DeliveryWay = deliveryWay
  4969. }
  4970. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4971. executionFrequency, _ := json["execution_frequency"].(string)
  4972. advice.ExecutionFrequency = executionFrequency
  4973. }
  4974. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4975. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4976. advice.Price = price
  4977. }
  4978. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4979. med_list_codg, _ := json["medical_insurance_number"].(string)
  4980. advice.MedListCodg = med_list_codg
  4981. }
  4982. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4983. day := int64(json["day"].(float64))
  4984. advice.Day = day
  4985. }
  4986. return 0
  4987. }
  4988. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4989. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4990. id := int64(json["id"].(float64))
  4991. project.ID = id
  4992. historyProject, _ := service.GetHisProjectByID(id)
  4993. project.FeedetlSn = historyProject.FeedetlSn
  4994. }
  4995. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4996. project_id := int64(json["project_id"].(float64))
  4997. project.ProjectId = project_id
  4998. }
  4999. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5000. // price := int64(json["price"].(float64))
  5001. // formatInt_price := strconv.FormatInt(price, 10)
  5002. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5003. // project.Price = float_price
  5004. // }
  5005. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5006. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5007. project.Price = price
  5008. }
  5009. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5010. total, _ := json["total"].(string)
  5011. project.Count = total
  5012. }
  5013. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5014. medical_code, _ := json["medical_code"].(string)
  5015. project.MedListCodg = medical_code
  5016. }
  5017. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5018. single_dose, _ := json["single_dose"].(string)
  5019. project.SingleDose = single_dose
  5020. }
  5021. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5022. delivery_way, _ := json["delivery_way"].(string)
  5023. project.DeliveryWay = delivery_way
  5024. }
  5025. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5026. execution_frequency, _ := json["execution_frequency"].(string)
  5027. project.ExecutionFrequency = execution_frequency
  5028. }
  5029. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5030. remark, _ := json["remark"].(string)
  5031. project.Remark = remark
  5032. }
  5033. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5034. day, _ := json["number_days"].(string)
  5035. project.Day = day
  5036. }
  5037. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5038. unit, _ := json["unit"].(string)
  5039. project.Unit = unit
  5040. }
  5041. return 0
  5042. }
  5043. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5044. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5045. id := int64(json["id"].(float64))
  5046. historyAddtions, _ := service.GetHisAdditionByID(id)
  5047. additionalCharge.ID = id
  5048. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5049. }
  5050. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5051. item_id := int64(json["item_id"].(float64))
  5052. additionalCharge.ItemId = item_id
  5053. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5054. if config.ID > 0 {
  5055. if len(config.Code) > 0 {
  5056. additionalCharge.MedListCodg = config.Code
  5057. }
  5058. }
  5059. }
  5060. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5061. // price := int64(json["price"].(float64))
  5062. // formatInt_price := strconv.FormatInt(price, 10)
  5063. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5064. // additionalCharge.Price = float_price
  5065. // }
  5066. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5067. // price := int64(json["price"].(float64))
  5068. // formatInt_price := strconv.FormatInt(price, 10)
  5069. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5070. // additionalCharge.Price = float_price
  5071. //}
  5072. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5073. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5074. additionalCharge.Price = price
  5075. }
  5076. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5077. count, _ := json["count"].(string)
  5078. counts, _ := strconv.ParseInt(count, 10, 64)
  5079. additionalCharge.Count = counts
  5080. }
  5081. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5082. item_name, _ := json["item_name"].(string)
  5083. additionalCharge.ItemName = item_name
  5084. }
  5085. return 0
  5086. }
  5087. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5088. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5089. utils.ErrorLog("drug_name")
  5090. return enums.ErrorCodeParamWrong
  5091. }
  5092. adviceName, _ := json["drug_name"].(string)
  5093. if len(adviceName) == 0 {
  5094. utils.ErrorLog("len(advice_name) == 0")
  5095. return enums.ErrorCodeParamWrong
  5096. }
  5097. advice.AdviceName = adviceName
  5098. adviceDesc, _ := json["advice_desc"].(string)
  5099. advice.AdviceDesc = adviceDesc
  5100. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5101. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5102. advice.DrugSpec = drugSpec
  5103. }
  5104. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5105. remark, _ := json["remark"].(string)
  5106. advice.Remark = remark
  5107. }
  5108. if json["id"] == nil {
  5109. advice.DrugId = 0
  5110. } else {
  5111. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5112. drug_id := int64(json["id"].(float64))
  5113. advice.DrugId = drug_id
  5114. }
  5115. }
  5116. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5117. groupno := int64(json["groupno"].(float64))
  5118. advice.Groupno = groupno
  5119. }
  5120. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5121. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5122. advice.IsSelfDrug = is_self_drug
  5123. }
  5124. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5125. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5126. drug_way_count, _ := json["drug_way_count"].(string)
  5127. advice.DrugWayCount = drug_way_count
  5128. }
  5129. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5130. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5131. advice.HospApprFlag = hosp_appr_flag
  5132. }
  5133. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5134. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5135. advice.PrescribingNumber = prescribingNumber
  5136. }
  5137. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5138. // frequency_type := int64(json["frequency_type"].(float64))
  5139. // advice.FrequencyType = frequency_type
  5140. //}
  5141. //
  5142. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5143. // day_count := int64(json["day_count"].(float64))
  5144. // advice.DayCount = day_count
  5145. //}
  5146. //
  5147. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5148. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5149. // week_day, _ := json["week_day"].(string)
  5150. // advice.WeekDay = week_day
  5151. //}
  5152. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5153. drugSpecUnit, _ := json["min_unit"].(string)
  5154. advice.DrugSpecUnit = drugSpecUnit
  5155. }
  5156. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5157. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5158. advice.SingleDose = singleDose
  5159. }
  5160. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5161. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5162. advice.SingleDoseUnit = singleDoseUnit
  5163. }
  5164. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5165. deliveryWay, _ := json["delivery_way"].(string)
  5166. advice.DeliveryWay = deliveryWay
  5167. }
  5168. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5169. executionFrequency, _ := json["execution_frequency"].(string)
  5170. advice.ExecutionFrequency = executionFrequency
  5171. }
  5172. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5173. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5174. advice.Price = price
  5175. }
  5176. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5177. med_list_codg, _ := json["medical_insurance_number"].(string)
  5178. advice.MedListCodg = med_list_codg
  5179. }
  5180. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5181. day := int64(json["day"].(float64))
  5182. advice.Day = day
  5183. }
  5184. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5185. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5186. advice.PrescribingNumberUnit = prescribingNumberUnit
  5187. }
  5188. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5189. advice_id := int64(json["advice_id"].(float64))
  5190. advice.ID = advice_id
  5191. if advice.ID > 0 {
  5192. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5193. if err == nil {
  5194. if hisAdvice.ID > 0 {
  5195. advice.ExecutionTime = hisAdvice.ExecutionTime
  5196. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5197. advice.ExecutionState = hisAdvice.ExecutionState
  5198. advice.CheckTime = hisAdvice.CheckTime
  5199. advice.Checker = hisAdvice.Checker
  5200. advice.CheckState = hisAdvice.CheckState
  5201. advice.StartTime = hisAdvice.StartTime
  5202. advice.HospApprFlag = hisAdvice.HospApprFlag
  5203. advice.IsMedicine = hisAdvice.IsMedicine
  5204. if hisAdvice.UserOrgId == 10028 {
  5205. 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 {
  5206. advice.ExecutionTime = 0
  5207. advice.ExecutionStaff = 0
  5208. advice.ExecutionState = 2
  5209. advice.CheckTime = 0
  5210. advice.Checker = 0
  5211. advice.CheckState = 2
  5212. }
  5213. } else {
  5214. 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 {
  5215. advice.ExecutionTime = 0
  5216. advice.ExecutionStaff = 0
  5217. advice.ExecutionState = 2
  5218. advice.CheckTime = 0
  5219. advice.Checker = 0
  5220. advice.CheckState = 2
  5221. }
  5222. }
  5223. //advice.Groupno = hisAdvice.Groupno
  5224. }
  5225. }
  5226. }
  5227. }
  5228. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5229. //
  5230. //if drugStockConfig.IsOpen == 1 {
  5231. //
  5232. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5233. // if advice.ID == 0 { //医嘱不存在
  5234. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5235. // drug.Total = drug.Total - advice.PrescribingNumber
  5236. // service.UpdateBaseDrugLib(&drug)
  5237. //
  5238. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5239. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5240. // drug.Total = drug.Total - num
  5241. // service.UpdateBaseDrugLib(&drug)
  5242. // }
  5243. //
  5244. // } else if advice.ID > 0 { //医嘱存在
  5245. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5246. // var num float64
  5247. //
  5248. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5249. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5250. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5251. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5252. // drug.Total = drug.Total + num
  5253. // service.UpdateBaseDrugLib(&drug)
  5254. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5255. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5256. // drug.Total = drug.Total - num
  5257. // service.UpdateBaseDrugLib(&drug)
  5258. // }
  5259. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5260. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5261. // if num2 > advice.PrescribingNumber {
  5262. // num = num2 - advice.PrescribingNumber
  5263. // drug.Total = drug.Total + num
  5264. // service.UpdateBaseDrugLib(&drug)
  5265. // } else if num2 < advice.PrescribingNumber {
  5266. // num = advice.PrescribingNumber - num2
  5267. // drug.Total = drug.Total - num
  5268. // service.UpdateBaseDrugLib(&drug)
  5269. // }
  5270. //
  5271. // }
  5272. //
  5273. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5274. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5275. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5276. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5277. // if num1 > num2 {
  5278. // num = num1 - num2
  5279. // drug.Total = drug.Total + num
  5280. // service.UpdateBaseDrugLib(&drug)
  5281. // } else if num1 < num2 {
  5282. // num = num2 - num1
  5283. // drug.Total = drug.Total - num
  5284. // service.UpdateBaseDrugLib(&drug)
  5285. // }
  5286. //
  5287. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5288. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5289. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5290. // if hisAdvice.PrescribingNumber > num2 {
  5291. // num = hisAdvice.PrescribingNumber - num2
  5292. // drug.Total = drug.Total + num
  5293. // service.UpdateBaseDrugLib(&drug)
  5294. // } else if num2 < advice.PrescribingNumber {
  5295. // num = num2 - hisAdvice.PrescribingNumber
  5296. // drug.Total = drug.Total - num
  5297. // service.UpdateBaseDrugLib(&drug)
  5298. // }
  5299. //
  5300. // }
  5301. // }
  5302. // }
  5303. //}
  5304. //
  5305. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5306. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5307. // advice.ExecutionTime = execution_time
  5308. //}
  5309. //
  5310. //
  5311. //
  5312. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5313. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5314. // advice.ExecutionStaff = execution_staff
  5315. //}
  5316. //
  5317. //
  5318. //
  5319. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5320. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5321. // advice.ExecutionState = execution_state
  5322. //}
  5323. //
  5324. //
  5325. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5326. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5327. // advice.CheckTime = check_time
  5328. //}
  5329. //
  5330. //
  5331. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5332. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5333. // advice.CheckState = check_state
  5334. //}
  5335. //
  5336. //
  5337. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5338. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5339. // advice.Checker = checker
  5340. //}
  5341. //
  5342. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5343. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5344. // advice.StartTime = start_time
  5345. //}
  5346. return 0
  5347. }
  5348. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5349. project.ExecutionStaff = 0
  5350. project.ExecutionState = 2
  5351. project.ExecutionTime = 0
  5352. project.Checker = 0
  5353. project.CheckState = 2
  5354. project.CheckTime = 0
  5355. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5356. id := int64(json["id"].(float64))
  5357. project.ID = id
  5358. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5359. project.ExecutionStaff = temp_project.ExecutionStaff
  5360. project.ExecutionState = temp_project.ExecutionState
  5361. project.ExecutionTime = temp_project.ExecutionTime
  5362. project.Checker = temp_project.Checker
  5363. project.CheckState = temp_project.CheckState
  5364. project.CheckTime = temp_project.CheckTime
  5365. project.TeamId = temp_project.TeamId
  5366. }
  5367. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5368. types := int64(json["type"].(float64))
  5369. project.Type = types
  5370. }
  5371. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5372. project_id := int64(json["project_id"].(float64))
  5373. project.ProjectId = project_id
  5374. }
  5375. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5376. team_id := int64(json["team_id"].(float64))
  5377. project.TeamId = team_id
  5378. }
  5379. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5380. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5381. project.Price = price
  5382. }
  5383. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5384. total, _ := json["total"].(string)
  5385. //totals, _ := strconv.ParseInt(total, 10, 64)
  5386. project.Count = total
  5387. }
  5388. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5389. medical_code, _ := json["medical_code"].(string)
  5390. project.MedListCodg = medical_code
  5391. }
  5392. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5393. single_dose, _ := json["single_dose"].(string)
  5394. project.SingleDose = single_dose
  5395. }
  5396. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5397. delivery_way, _ := json["delivery_way"].(string)
  5398. project.DeliveryWay = delivery_way
  5399. }
  5400. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5401. execution_frequency, _ := json["execution_frequency"].(string)
  5402. project.ExecutionFrequency = execution_frequency
  5403. }
  5404. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5405. remark, _ := json["remark"].(string)
  5406. project.Remark = remark
  5407. }
  5408. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5409. day, _ := json["number_days"].(string)
  5410. project.Day = day
  5411. }
  5412. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5413. unit, _ := json["unit"].(string)
  5414. project.Unit = unit
  5415. }
  5416. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5417. // frequency_type := int64(json["frequency_type"].(float64))
  5418. // project.FrequencyType = frequency_type
  5419. //}
  5420. //
  5421. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5422. // day_count := int64(json["day_count"].(float64))
  5423. // project.DayCount = day_count
  5424. //}
  5425. //
  5426. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5427. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5428. // week_day, _ := json["week_day"].(string)
  5429. // project.WeekDay = week_day
  5430. //}
  5431. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5432. //
  5433. //if project.ID == 0 {
  5434. // if stockConfig.IsOpen == 1 {
  5435. // if project.Type == 3 {
  5436. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5437. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5438. // good.Total = good.Total - f_count
  5439. // service.UpdateGoodInfo(&good)
  5440. // }
  5441. // }
  5442. //
  5443. //} else {
  5444. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5445. //
  5446. // if stockConfig.IsOpen == 1 {
  5447. // if project.Type == 3 {
  5448. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5449. // if project.Count < temp_project.Count {
  5450. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5451. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5452. //
  5453. // other_count := f_count_two - f_count_one
  5454. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5455. // good.Total = good.Total + other_count_two
  5456. // service.UpdateGoodInfo(&good)
  5457. // } else if project.Count > temp_project.Count {
  5458. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5459. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5460. //
  5461. // other_count := f_count_one - f_count_two
  5462. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5463. // good.Total = good.Total - other_count_two
  5464. // service.UpdateGoodInfo(&good)
  5465. // }
  5466. //
  5467. // }
  5468. // }
  5469. //
  5470. //}
  5471. return 0
  5472. }
  5473. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5474. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5475. id := int64(json["id"].(float64))
  5476. additionalCharge.ID = id
  5477. }
  5478. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5479. item_id := int64(json["item_id"].(float64))
  5480. additionalCharge.ItemId = item_id
  5481. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5482. if config.ID > 0 {
  5483. if len(config.Code) > 0 {
  5484. additionalCharge.MedListCodg = config.Code
  5485. }
  5486. }
  5487. }
  5488. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5489. // price := int64(json["price"].(float64))
  5490. // formatInt_price := strconv.FormatInt(price, 10)
  5491. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5492. // additionalCharge.Price = float_price
  5493. // }
  5494. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5495. // price := int64(json["price"].(float64))
  5496. // formatInt_price := strconv.FormatInt(price, 10)
  5497. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5498. // additionalCharge.Price = float_price
  5499. //}
  5500. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5501. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5502. additionalCharge.Price = price
  5503. }
  5504. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5505. count, _ := json["count"].(string)
  5506. counts, _ := strconv.ParseInt(count, 10, 64)
  5507. additionalCharge.Count = counts
  5508. }
  5509. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5510. item_name, _ := json["item_name"].(string)
  5511. additionalCharge.ItemName = item_name
  5512. }
  5513. return 0
  5514. }
  5515. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5516. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5517. utils.ErrorLog("drug_name")
  5518. return enums.ErrorCodeParamWrong
  5519. }
  5520. adviceName, _ := json["drug_name"].(string)
  5521. if len(adviceName) == 0 {
  5522. utils.ErrorLog("len(advice_name) == 0")
  5523. return enums.ErrorCodeParamWrong
  5524. }
  5525. advice.AdviceName = adviceName
  5526. adviceDesc, _ := json["advice_desc"].(string)
  5527. advice.AdviceDesc = adviceDesc
  5528. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5529. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5530. advice.DrugSpec = drugSpec
  5531. }
  5532. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5533. remark, _ := json["remark"].(string)
  5534. advice.Remark = remark
  5535. }
  5536. if json["id"] == nil {
  5537. advice.DrugId = 0
  5538. } else {
  5539. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5540. drug_id := int64(json["id"].(float64))
  5541. advice.DrugId = drug_id
  5542. }
  5543. }
  5544. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5545. groupno := int64(json["groupno"].(float64))
  5546. advice.Groupno = groupno
  5547. }
  5548. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5549. drugSpecUnit, _ := json["min_unit"].(string)
  5550. advice.DrugSpecUnit = drugSpecUnit
  5551. }
  5552. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5553. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5554. advice.SingleDose = singleDose
  5555. }
  5556. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5557. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5558. advice.SingleDoseUnit = singleDoseUnit
  5559. }
  5560. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5561. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5562. advice.PrescribingNumber = prescribingNumber
  5563. }
  5564. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5565. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5566. advice.PrescribingNumberUnit = prescribingNumberUnit
  5567. }
  5568. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5569. deliveryWay, _ := json["delivery_way"].(string)
  5570. advice.DeliveryWay = deliveryWay
  5571. }
  5572. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5573. executionFrequency, _ := json["execution_frequency"].(string)
  5574. advice.ExecutionFrequency = executionFrequency
  5575. }
  5576. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5577. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5578. advice.Price = price
  5579. }
  5580. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5581. med_list_codg, _ := json["medical_insurance_number"].(string)
  5582. advice.MedListCodg = med_list_codg
  5583. }
  5584. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5585. day := int64(json["day"].(float64))
  5586. advice.Day = day
  5587. }
  5588. advice.FrequencyType = 1
  5589. return 0
  5590. }
  5591. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5592. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5593. types := int64(json["type"].(float64))
  5594. project.Type = types
  5595. }
  5596. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5597. project_id := int64(json["project_id"].(float64))
  5598. project.ProjectId = project_id
  5599. }
  5600. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5601. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5602. project.Price = price
  5603. }
  5604. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5605. total, _ := json["total"].(string)
  5606. //totals, _ := strconv.ParseInt(total, 10, 64)
  5607. project.Count = total
  5608. }
  5609. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5610. medical_code, _ := json["medical_code"].(string)
  5611. project.MedListCodg = medical_code
  5612. }
  5613. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5614. single_dose, _ := json["single_dose"].(string)
  5615. project.SingleDose = single_dose
  5616. }
  5617. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5618. delivery_way, _ := json["delivery_way"].(string)
  5619. project.DeliveryWay = delivery_way
  5620. }
  5621. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5622. execution_frequency, _ := json["execution_frequency"].(string)
  5623. project.ExecutionFrequency = execution_frequency
  5624. }
  5625. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5626. remark, _ := json["remark"].(string)
  5627. project.Remark = remark
  5628. }
  5629. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5630. day, _ := json["number_days"].(string)
  5631. project.Day = day
  5632. }
  5633. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5634. unit, _ := json["unit"].(string)
  5635. project.Unit = unit
  5636. }
  5637. project.FrequencyType = 1
  5638. return 0
  5639. }
  5640. func (c *HisApiController) GetHisOrderList() {
  5641. page, _ := c.GetInt64("page", -1)
  5642. limit, _ := c.GetInt64("limit", -1)
  5643. start_time := c.GetString("start_time")
  5644. end_time := c.GetString("end_time")
  5645. types, _ := c.GetInt64("type", 0)
  5646. keywords := c.GetString("keywords")
  5647. p_type, _ := c.GetInt64("p_type", 0)
  5648. sort_type, _ := c.GetInt64("sort_type", 0)
  5649. charge_type, _ := c.GetInt64("charge_type", 0)
  5650. sch_type, _ := c.GetInt64("sch_type", 0)
  5651. zone_type, _ := c.GetInt64("zone_type", 0)
  5652. med_type, _ := c.GetInt64("med_type", 0)
  5653. timeLayout := "2006-01-02"
  5654. loc, _ := time.LoadLocation("Local")
  5655. var startTime int64
  5656. if len(start_time) > 0 {
  5657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5658. if err != nil {
  5659. //fmt.Println(err)
  5660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5661. return
  5662. }
  5663. startTime = theTime.Unix()
  5664. }
  5665. var endTime int64
  5666. if len(end_time) > 0 {
  5667. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5668. if err != nil {
  5669. utils.ErrorLog(err.Error())
  5670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5671. return
  5672. }
  5673. endTime = theTime.Unix()
  5674. }
  5675. adminUser := c.GetAdminUserInfo()
  5676. org_id := adminUser.CurrentOrgId
  5677. 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)
  5678. for _, item := range order {
  5679. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5680. item.DoctorName = info.Doctor
  5681. item.DepartmentName = info.XtHisDepartment.Name
  5682. }
  5683. if err == nil {
  5684. c.ServeSuccessJSON(map[string]interface{}{
  5685. "order": order,
  5686. "total": total,
  5687. })
  5688. } else {
  5689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5690. return
  5691. }
  5692. }
  5693. func (c *HisApiController) GetHisOrder() {
  5694. patient_id, _ := c.GetInt64("patient_id", 0)
  5695. number := c.GetString("number")
  5696. adminInfo := c.GetAdminUserInfo()
  5697. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5698. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5699. if err == nil {
  5700. c.ServeSuccessJSON(map[string]interface{}{
  5701. "order": order,
  5702. "prescription": prescriptions,
  5703. })
  5704. } else {
  5705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5706. return
  5707. }
  5708. }
  5709. func (c *HisApiController) GetHisPrescriptionList() {
  5710. record_date := c.GetString("record_date")
  5711. keywords := c.GetString("keywords")
  5712. page, _ := c.GetInt64("page")
  5713. limit, _ := c.GetInt64("limit")
  5714. sch_type, _ := c.GetInt64("sch_type")
  5715. timeLayout := "2006-01-02"
  5716. loc, _ := time.LoadLocation("Local")
  5717. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5718. if err != nil {
  5719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5720. return
  5721. }
  5722. recordDateTime := theTime.Unix()
  5723. adminInfo := c.GetAdminUserInfo()
  5724. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5725. //adminInfo := c.GetAdminUserInfo()
  5726. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5727. //fmt.Println(prescriptionOrder)
  5728. if err == nil {
  5729. c.ServeSuccessJSON(map[string]interface{}{
  5730. "order": prescriptionOrder,
  5731. "total": total,
  5732. })
  5733. } else {
  5734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5735. return
  5736. }
  5737. }
  5738. func (c *HisApiController) GetHisPrescriptionInfo() {
  5739. id, _ := c.GetInt64("id")
  5740. adminInfo := c.GetAdminUserInfo()
  5741. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5742. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5743. if err == nil {
  5744. c.ServeSuccessJSON(map[string]interface{}{
  5745. "order": prescriptionOrder,
  5746. "prescription": prescription,
  5747. })
  5748. } else {
  5749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5750. return
  5751. }
  5752. }
  5753. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5754. adminUser := c.GetAdminUserInfo()
  5755. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5756. c.ServeSuccessJSON(map[string]interface{}{
  5757. "config": config,
  5758. })
  5759. }
  5760. type ResultTwo struct {
  5761. ErrMsg interface{} `json:"err_msg"`
  5762. InfRefmsgid string `json:"inf_refmsgid"`
  5763. Infcode int64 `json:"infcode"`
  5764. Output struct {
  5765. Baseinfo struct {
  5766. Age float64 `json:"age"`
  5767. Brdy string `json:"brdy"`
  5768. Certno string `json:"certno"`
  5769. Gend string `json:"gend"`
  5770. Naty string `json:"naty"`
  5771. PsnCertType string `json:"psn_cert_type"`
  5772. PsnName string `json:"psn_name"`
  5773. PsnNo string `json:"psn_no"`
  5774. } `json:"baseinfo"`
  5775. Idetinfo []interface{} `json:"idetinfo"`
  5776. Iinfo []struct {
  5777. Balc float64 `json:"balc"`
  5778. CvlservFlag string `json:"cvlserv_flag"`
  5779. EmpName string `json:"emp_name"`
  5780. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5781. Insutype string `json:"insutype"`
  5782. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5783. PausInsuDate interface{} `json:"paus_insu_date"`
  5784. PsnInsuDate string `json:"psn_insu_date"`
  5785. PsnInsuStas string `json:"psn_insu_stas"`
  5786. PsnType string `json:"psn_type"`
  5787. } `json:"insuinfo"`
  5788. } `json:"output"`
  5789. RefmsgTime string `json:"refmsg_time"`
  5790. RespondTime string `json:"respond_time"`
  5791. Signtype interface{} `json:"signtype"`
  5792. WarnInfo interface{} `json:"warn_info"`
  5793. }
  5794. type ResultThree struct {
  5795. Cainfo interface{} `json:"cainfo"`
  5796. ErrMsg interface{} `json:"err_msg"`
  5797. InfRefmsgid string `json:"inf_refmsgid"`
  5798. Infcode int64 `json:"infcode"`
  5799. Output struct {
  5800. Data struct {
  5801. IptOtpNo string `json:"ipt_otp_no"`
  5802. MdtrtID string `json:"mdtrt_id"`
  5803. PsnNo string `json:"psn_no"`
  5804. } `json:"data"`
  5805. } `json:"output"`
  5806. RefmsgTime string `json:"refmsg_time"`
  5807. RespondTime string `json:"respond_time"`
  5808. Signtype interface{} `json:"signtype"`
  5809. WarnMsg interface{} `json:"warn_msg"`
  5810. }
  5811. type ResultFour struct {
  5812. Cainfo string `json:"cainfo"`
  5813. ErrMsg string `json:"err_msg"`
  5814. InfRefmsgid string `json:"inf_refmsgid"`
  5815. Infcode int64 `json:"infcode"`
  5816. Output struct {
  5817. Result []struct {
  5818. BasMednFlag string `json:"bas_medn_flag"`
  5819. ChldMedcFlag string `json:"chld_medc_flag"`
  5820. ChrgitmLv string `json:"chrgitm_lv"`
  5821. Cnt float64 `json:"cnt"`
  5822. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5823. DrtReimFlag string `json:"drt_reim_flag"`
  5824. FeedetlSn string `json:"feedetl_sn"`
  5825. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5826. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5827. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5828. ListSpItemFlag string `json:"list_sp_item_flag"`
  5829. LmtUsedFlag string `json:"lmt_used_flag"`
  5830. MedChrgitmType string `json:"med_chrgitm_type"`
  5831. Memo string `json:"memo"`
  5832. OverlmtAmt float64 `json:"overlmt_amt"`
  5833. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5834. Pric float64 `json:"pric"`
  5835. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5836. SelfpayProp float64 `json:"selfpay_prop"`
  5837. } `json:"result"`
  5838. } `json:"output"`
  5839. RefmsgTime string `json:"refmsg_time"`
  5840. RespondTime string `json:"respond_time"`
  5841. Signtype string `json:"signtype"`
  5842. WarnMsg string `json:"warn_msg"`
  5843. }
  5844. type ResultFive struct {
  5845. Insutype string `json:"insutype"`
  5846. }
  5847. type ResultSix struct {
  5848. Cainfo interface{} `json:"cainfo"`
  5849. ErrMsg interface{} `json:"err_msg"`
  5850. InfRefmsgid string `json:"inf_refmsgid"`
  5851. Infcode int64 `json:"infcode"`
  5852. Output struct {
  5853. } `json:"output"`
  5854. RefmsgTime string `json:"refmsg_time"`
  5855. RespondTime string `json:"respond_time"`
  5856. Signtype interface{} `json:"signtype"`
  5857. WarnMsg interface{} `json:"warn_msg"`
  5858. }
  5859. type ResultSeven struct {
  5860. Cainfo string `json:"cainfo"`
  5861. ErrMsg string `json:"err_msg"`
  5862. InfRefmsgid string `json:"inf_refmsgid"`
  5863. Infcode int64 `json:"infcode"`
  5864. Output struct {
  5865. Setldetail []interface{} `json:"setldetail"`
  5866. Setlinfo struct {
  5867. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5868. AcctPay float64 `json:"acct_pay"`
  5869. ActPayDedc float64 `json:"act_pay_dedc"`
  5870. Age float64 `json:"age"`
  5871. Balc float64 `json:"balc"`
  5872. Brdy string `json:"brdy"`
  5873. Certno string `json:"certno"`
  5874. ClrOptins string `json:"clr_optins"`
  5875. ClrType string `json:"clr_type"`
  5876. ClrWay string `json:"clr_way"`
  5877. CvlservFlag string `json:"cvlserv_flag"`
  5878. CvlservPay float64 `json:"cvlserv_pay"`
  5879. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5880. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5881. Gend string `json:"gend"`
  5882. HifesPay float64 `json:"hifes_pay"`
  5883. HifmiPay float64 `json:"hifmi_pay"`
  5884. HifobPay float64 `json:"hifob_pay"`
  5885. HifpPay float64 `json:"hifp_pay"`
  5886. HospPartAmt float64 `json:"hosp_part_amt"`
  5887. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5888. Insutype string `json:"insutype"`
  5889. MafPay float64 `json:"maf_pay"`
  5890. MdtrtCertType string `json:"mdtrt_cert_type"`
  5891. MdtrtID string `json:"mdtrt_id"`
  5892. MedType string `json:"med_type"`
  5893. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5894. MedinsSetlID string `json:"medins_setl_id"`
  5895. Naty string `json:"naty"`
  5896. OthPay float64 `json:"oth_pay"`
  5897. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5898. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5899. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5900. PsnCashPay float64 `json:"psn_cash_pay"`
  5901. PsnCertType string `json:"psn_cert_type"`
  5902. PsnName string `json:"psn_name"`
  5903. PsnNo string `json:"psn_no"`
  5904. PsnPartAmt float64 `json:"psn_part_amt"`
  5905. PsnType string `json:"psn_type"`
  5906. SetlID string `json:"setl_id"`
  5907. SetlTime string `json:"setl_time"`
  5908. } `json:"setlinfo"`
  5909. } `json:"output"`
  5910. RefmsgTime string `json:"refmsg_time"`
  5911. RespondTime string `json:"respond_time"`
  5912. Signtype interface{} `json:"signtype"`
  5913. WarnMsg interface{} `json:"warn_msg"`
  5914. }
  5915. type ResultEight struct {
  5916. Cainfo string `json:"cainfo"`
  5917. ErrMsg string `json:"err_msg"`
  5918. InfRefmsgid string `json:"inf_refmsgid"`
  5919. Infcode int64 `json:"infcode"`
  5920. Output struct {
  5921. Stmtinfo struct {
  5922. SetlOptins string `json:"setl_optins"`
  5923. StmtRslt string `json:"stmt_rslt"`
  5924. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5925. } `json:"stmtinfo"`
  5926. } `json:"output"`
  5927. RefmsgTime string `json:"refmsg_time"`
  5928. RespondTime string `json:"respond_time"`
  5929. Signtype interface{} `json:"signtype"`
  5930. WarnMsg interface{} `json:"warn_msg"`
  5931. }
  5932. type ResultNine struct {
  5933. Cainfo string `json:"cainfo"`
  5934. ErrMsg string `json:"err_msg"`
  5935. InfRefmsgid string `json:"inf_refmsgid"`
  5936. Infcode int64 `json:"infcode"`
  5937. Output struct {
  5938. FileQuryNo string `json:"file_qury_no"`
  5939. } `json:"output"`
  5940. RefmsgTime string `json:"refmsg_time"`
  5941. RespondTime string `json:"respond_time"`
  5942. Signtype interface{} `json:"signtype"`
  5943. WarnMsg interface{} `json:"warn_msg"`
  5944. }
  5945. type ResultTen struct {
  5946. Cainfo string `json:"cainfo"`
  5947. ErrMsg string `json:"err_msg"`
  5948. InfRefmsgid string `json:"inf_refmsgid"`
  5949. Infcode int64 `json:"infcode"`
  5950. Output struct {
  5951. DldEndtime string `json:"dld_endtime"`
  5952. FileQuryNo string `json:"file_qury_no"`
  5953. Filename string `json:"filename"`
  5954. } `json:"output"`
  5955. RefmsgTime string `json:"refmsg_time"`
  5956. RespondTime string `json:"respond_time"`
  5957. Signtype interface{} `json:"signtype"`
  5958. WarnMsg interface{} `json:"warn_msg"`
  5959. }
  5960. type ResultEleven struct {
  5961. Cainfo string `json:"cainfo"`
  5962. ErrMsg string `json:"err_msg"`
  5963. InfRefmsgid string `json:"inf_refmsgid"`
  5964. Infcode int64 `json:"infcode"`
  5965. Output struct {
  5966. Setlinfo struct {
  5967. FixmedinsName string `json:"fixmedins_name"`
  5968. FixmedinsCode string `json:"fixmedins_code"`
  5969. PsnNo string `json:"psn_no"`
  5970. PsnName string `json:"psn_name"`
  5971. HifobPay float64 `json:"hifob_pay"`
  5972. Gend string `json:"gend"`
  5973. Brdy string `json:"brdy"`
  5974. PsnCertType string `json:"psn_cert_type"`
  5975. PsnType string `json:"psn_type"`
  5976. EmpName string `json:"emp_name"`
  5977. Certno string `json:"certno"`
  5978. Insutype string `json:"insutype"`
  5979. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5980. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5981. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5982. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5983. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5984. ActPayDedc float64 `json:"act_pay_dedc"`
  5985. HifpPay float64 `json:"hifp_pay"`
  5986. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5987. CvlservPay float64 `json:"cvlserv_pay"`
  5988. HifesPay float64 `json:"hifes_pay"`
  5989. HifmiPay float64 `json:"hifmi_pay"`
  5990. MafPay float64 `json:"maf_pay"`
  5991. OthPay float64 `json:"oth_pay"`
  5992. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5993. PsnPay float64 `json:"psn_pay"`
  5994. AcctPay float64 `json:"acct_pay"`
  5995. CashPayamt float64 `json:"cash_payamt"`
  5996. Balc float64 `json:"balc"`
  5997. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5998. MedinsSetlId string `json:"medins_setl_id"`
  5999. RefdSetlFlag string `json:"refd_setl_flag"`
  6000. SetlTime string `json:"setl_time"`
  6001. MedType string `json:"med_type"`
  6002. } `json:"setlinfo"`
  6003. } `json:"output"`
  6004. RefmsgTime string `json:"refmsg_time"`
  6005. RespondTime string `json:"respond_time"`
  6006. Signtype interface{} `json:"signtype"`
  6007. WarnMsg interface{} `json:"warn_msg"`
  6008. }
  6009. type Custom struct {
  6010. DetItemFeeSumamt string
  6011. Cut string
  6012. FeedetlSn string
  6013. Price string
  6014. MedListCodg string
  6015. Type int64
  6016. AdviceId int64
  6017. ProjectId int64
  6018. ItemId int64
  6019. }
  6020. // 获取个人信息----挂号-----上传就诊信息
  6021. func (c *HisApiController) GetRegisterInfo() {
  6022. id, _ := c.GetInt64("id")
  6023. record_time := c.GetString("record_time")
  6024. settlementValue, _ := c.GetInt64("settlement_value")
  6025. medical_insurance_card := c.GetString("medical_insurance_card")
  6026. name := c.GetString("name")
  6027. id_card_type, _ := c.GetInt64("id_card_type")
  6028. certificates, _ := c.GetInt64("certificates")
  6029. medical_care, _ := c.GetInt64("medical_care")
  6030. birthday := c.GetString("birthday")
  6031. age, _ := c.GetInt64("age")
  6032. id_card := c.GetString("id_card")
  6033. register_type, _ := c.GetInt64("register")
  6034. doctor, _ := c.GetInt64("doctor")
  6035. department, _ := c.GetInt64("department")
  6036. gender, _ := c.GetInt64("sex")
  6037. phone := c.GetString("phone")
  6038. registration_fee, _ := c.GetFloat("registration_fee")
  6039. medical_expenses, _ := c.GetFloat("medical_expenses")
  6040. social_type, _ := c.GetInt64("social_type")
  6041. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6042. diagnosis_ids := c.GetString("diagnosis")
  6043. sick_type, _ := c.GetInt64("sick_type")
  6044. reg_type := c.GetString("p_type")
  6045. timeLayout := "2006-01-02"
  6046. loc, _ := time.LoadLocation("Local")
  6047. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6048. birthUnix := birthdays.Unix()
  6049. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6050. if err != nil {
  6051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6052. return
  6053. }
  6054. recordDateTime := theTime.Unix()
  6055. adminInfo := c.GetAdminUserInfo()
  6056. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6057. if tempPatient.ID == 0 {
  6058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6059. return
  6060. }
  6061. var patient service.Patients
  6062. if id == 0 {
  6063. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6064. } else {
  6065. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6066. }
  6067. if patient.ID == 0 {
  6068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6069. return
  6070. }
  6071. if len(patient.IdCardNo) == 0 {
  6072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6073. return
  6074. }
  6075. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6076. if len(his) >= 1 {
  6077. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6078. if len(his) >= 1 && order.ID == 0 {
  6079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6080. return
  6081. }
  6082. }
  6083. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6084. fmt.Println(timeStr)
  6085. timeArr := strings.Split(timeStr, " ")
  6086. fmt.Println(timeArr)
  6087. timeArrTwo := strings.Split(timeArr[0], "-")
  6088. timeArrThree := strings.Split(timeArr[1], ":")
  6089. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6090. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6091. if len(lists) == 0 {
  6092. var hisPatient models.XtHisPatient
  6093. hisPatient = models.XtHisPatient{
  6094. Name: name,
  6095. Age: age,
  6096. Gender: gender,
  6097. Birthday: birthUnix,
  6098. Phone: phone,
  6099. MedicalTreatmentType: medical_care,
  6100. IdType: certificates,
  6101. IdCardNo: id_card,
  6102. BalanceAccountsType: settlementValue,
  6103. SocialType: social_type,
  6104. MedicalInsuranceNumber: medical_insurance_card,
  6105. RegisterType: register_type,
  6106. RegisterCost: registration_fee,
  6107. TreatmentCost: medical_expenses,
  6108. AdminUserId: adminInfo.AdminUser.Id,
  6109. UserOrgId: adminInfo.CurrentOrgId,
  6110. Status: 1,
  6111. RecordDate: recordDateTime,
  6112. IsReturn: 1,
  6113. PatientId: patient.ID,
  6114. Ctime: time.Now().Unix(),
  6115. Mtime: time.Now().Unix(),
  6116. Number: str,
  6117. IdCardType: id_card_type,
  6118. Departments: department,
  6119. Doctor: doctor,
  6120. PType: reg_type,
  6121. Diagnosis: diagnosis_ids,
  6122. SickType: sick_type,
  6123. }
  6124. service.CreateHisPatient(&hisPatient)
  6125. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6126. c.ServeSuccessJSON(map[string]interface{}{
  6127. "his_info": hisPatient,
  6128. })
  6129. } else {
  6130. //chrgBchno := rand.Intn(1000000) + 10000
  6131. var hisPatient models.XtHisPatient
  6132. hisPatient = models.XtHisPatient{
  6133. Name: name,
  6134. Age: age,
  6135. Gender: gender,
  6136. Birthday: birthUnix,
  6137. Phone: phone,
  6138. MedicalTreatmentType: medical_care,
  6139. IdType: certificates,
  6140. IdCardNo: id_card,
  6141. BalanceAccountsType: settlementValue,
  6142. SocialType: social_type,
  6143. MedicalInsuranceNumber: medical_insurance_card,
  6144. RegisterType: register_type,
  6145. RegisterCost: registration_fee,
  6146. TreatmentCost: medical_expenses,
  6147. AdminUserId: adminInfo.AdminUser.Id,
  6148. UserOrgId: adminInfo.CurrentOrgId,
  6149. Status: 1,
  6150. RecordDate: recordDateTime,
  6151. IsReturn: 1,
  6152. PatientId: patient.ID,
  6153. Ctime: time.Now().Unix(),
  6154. Mtime: time.Now().Unix(),
  6155. Number: str,
  6156. IdCardType: id_card_type,
  6157. Departments: department,
  6158. Doctor: doctor,
  6159. PType: reg_type,
  6160. Diagnosis: diagnosis_ids,
  6161. SickType: sick_type,
  6162. }
  6163. service.CreateHisPatient(&hisPatient)
  6164. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6165. c.ServeSuccessJSON(map[string]interface{}{
  6166. "his_info": hisPatient,
  6167. })
  6168. }
  6169. }
  6170. // 上传明细----结算
  6171. func (c *HisApiController) GetUploadInfo() {
  6172. id, _ := c.GetInt64("id")
  6173. record_time := c.GetString("record_time")
  6174. his_patient_id, _ := c.GetInt64("his_patient_id")
  6175. oth_desc := c.GetString("oth_desc")
  6176. pay_way, _ := c.GetInt64("pay_way")
  6177. pay_ways := c.GetString("pay_ways")
  6178. pay_price, _ := c.GetFloat("pay_price")
  6179. pay_card_no := c.GetString("pay_card_no")
  6180. discount_price, _ := c.GetFloat("discount_price")
  6181. preferential_price, _ := c.GetFloat("preferential_price")
  6182. reality_price, _ := c.GetFloat("reality_price")
  6183. found_price, _ := c.GetFloat("found_price")
  6184. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6185. private_price, _ := c.GetFloat("private_price")
  6186. timeLayout := "2006-01-02"
  6187. loc, _ := time.LoadLocation("Local")
  6188. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6189. fapiao_code := c.GetString("fapiao_code")
  6190. fapiao_number := c.GetString("fapiao_number")
  6191. diagnosis_id := c.GetString("diagnosis")
  6192. sick_type, _ := c.GetInt64("sick_type")
  6193. reg_type, _ := c.GetInt64("p_type")
  6194. order_id, _ := c.GetInt64("order_id")
  6195. cash_pay := c.GetString("cash_pay")
  6196. wechat_pay := c.GetString("wechat_pay")
  6197. ali_pay := c.GetString("ali_pay")
  6198. jifen_pay := c.GetString("jifen_pay")
  6199. band_card_pay := c.GetString("band_card_pay")
  6200. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6201. tmp_decimal := c.GetString("tmp_decimal")
  6202. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6203. var decimal float64 //本次使用的押金
  6204. var errmsg error
  6205. tx := service.XTWriteDB().Begin() //开了事务
  6206. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6207. defer func() {
  6208. if errmsg != nil {
  6209. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6210. tx.Rollback()
  6211. } else {
  6212. tx.Commit()
  6213. }
  6214. }()
  6215. fmt.Println("dec_way", dec_way)
  6216. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6217. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6218. return
  6219. }
  6220. if len(tmp_decimal) > 0 {
  6221. if tmp_decimal[0] == 45 {
  6222. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6223. return
  6224. }
  6225. }
  6226. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6227. fmt.Println(errs)
  6228. decimal = tt
  6229. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6230. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6232. if err != nil {
  6233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6234. return
  6235. }
  6236. recordDateTime := theTime.Unix()
  6237. adminUser := c.GetAdminUserInfo()
  6238. var prescriptions []*models.HisPrescription
  6239. var prescriptionsOne []*models.HisPrescription
  6240. var start_time int64
  6241. var end_time int64
  6242. ids_str := c.GetString("ids")
  6243. ids_arr := strings.Split(ids_str, ",")
  6244. if tempOrder.ID == 0 {
  6245. if settle_accounts_type == 1 { //日结
  6246. fmt.Println(reg_type)
  6247. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6248. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6249. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6250. } else {
  6251. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6252. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6253. }
  6254. } else { //月结
  6255. start_time_str := c.GetString("start_time")
  6256. end_time_str := c.GetString("end_time")
  6257. timeLayout := "2006-01-02"
  6258. loc, _ := time.LoadLocation("Local")
  6259. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6260. if err != nil {
  6261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6262. return
  6263. }
  6264. recordStartTime := theStartTime.Unix()
  6265. start_time = recordStartTime
  6266. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6267. if err != nil {
  6268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6269. return
  6270. }
  6271. recordEndTime := theEndTime.Unix()
  6272. end_time = recordEndTime
  6273. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6274. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6275. }
  6276. var goods []*models.DialysisBeforePrepareGoods
  6277. var newGoods []*models.NewDialysisBeforePrepareGoods
  6278. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6279. var infos []*models.HisDoctorAdviceInfo
  6280. var infoList []*models.HisDoctorAdviceInfo
  6281. var hisAdvice []*models.HisDoctorAdviceInfo
  6282. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6283. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6284. //判断库存不足
  6285. //结算出库开关
  6286. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6287. if settConfig.IsOpen == 1 {
  6288. //判断库存的地方
  6289. for _, info := range prescriptions {
  6290. if info.Type == 1 {
  6291. infos = append(infos, info.HisDoctorAdviceInfo...)
  6292. }
  6293. if info.Type == 2 {
  6294. for _, sumItem := range info.HisPrescriptionProject {
  6295. if sumItem.Type == 3 {
  6296. var good models.DialysisBeforePrepareGoods
  6297. var newGood models.NewDialysisBeforePrepareGoods
  6298. good.GoodId = sumItem.GoodInfo.ID
  6299. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6300. count, _ := strconv.Atoi(sumItem.Count)
  6301. good.Count = int64(count)
  6302. good.StorehouseId = houseConfig.StorehouseOutInfo
  6303. good.ProjectId = sumItem.ID
  6304. goods = append(goods, &good)
  6305. newGood.GoodId = sumItem.GoodInfo.ID
  6306. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6307. count2, _ := strconv.Atoi(sumItem.Count)
  6308. newGood.Count = int64(count2)
  6309. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6310. newGood.ProjectId = sumItem.ID
  6311. newGoods = append(newGoods, &newGood)
  6312. }
  6313. }
  6314. }
  6315. }
  6316. for _, info := range prescriptionsOne {
  6317. if info.Type == 1 {
  6318. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6319. }
  6320. if info.Type == 2 {
  6321. for _, sumItem := range info.HisPrescriptionProject {
  6322. if sumItem.Type == 3 {
  6323. var newGood models.NewDialysisBeforePrepareGoods
  6324. newGood.GoodId = sumItem.GoodInfo.ID
  6325. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6326. count2, _ := strconv.Atoi(sumItem.Count)
  6327. newGood.Count = int64(count2)
  6328. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6329. newGood.ProjectId = sumItem.ID
  6330. newGoodOne = append(newGoodOne, &newGood)
  6331. }
  6332. }
  6333. }
  6334. }
  6335. //判断
  6336. for _, itemOne := range infos {
  6337. for _, itemTwo := range hisAdvice {
  6338. if itemOne.DrugId == itemTwo.DrugId {
  6339. itemTwo.Child = append(itemTwo.Child, itemOne)
  6340. }
  6341. }
  6342. }
  6343. for _, itemTwo := range hisAdvice {
  6344. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6345. var sum_out_count int64
  6346. for _, itemThree := range itemTwo.Child {
  6347. var prescribing_number int64
  6348. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6349. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6350. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6351. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6352. }
  6353. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6354. prescribing_number = parseIntPrescribingNumber
  6355. }
  6356. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6357. prescribing_number = parseIntPrescribingNumber
  6358. }
  6359. sum_out_count += prescribing_number
  6360. }
  6361. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6362. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6363. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6364. if sum_out_count > drugStockOut.FlushCount {
  6365. c.ServeSuccessJSON(map[string]interface{}{
  6366. "msg": "2",
  6367. "drug": medical,
  6368. })
  6369. return
  6370. }
  6371. }
  6372. fmt.Println("newGoods99999988882os", newGoods)
  6373. for _, itemOne := range newGoods {
  6374. for _, item := range newGoodOne {
  6375. if itemOne.GoodId == item.GoodId {
  6376. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6377. }
  6378. }
  6379. }
  6380. for _, item := range newGoodOne {
  6381. var sum_out_count_one int64
  6382. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6383. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6384. sum_out_count_one += itemOne.Count
  6385. }
  6386. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6387. fmt.Println("sum_out_count_one", sum_out_count_one)
  6388. fmt.Println("list.FlushCount", list.FlushCount)
  6389. if sum_out_count_one > list.FlushCount {
  6390. c.ServeSuccessJSON(map[string]interface{}{
  6391. "msg": "3",
  6392. "good": good,
  6393. })
  6394. return
  6395. }
  6396. }
  6397. }
  6398. timestamp := time.Now().Unix()
  6399. tempTime := time.Unix(timestamp, 0)
  6400. timeFormat := tempTime.Format("20060102150405")
  6401. chrgBchno := rand.Intn(100000) + 10000
  6402. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6403. strconv.FormatInt(his.PatientId, 10)
  6404. var ids []int64
  6405. for _, item := range prescriptions {
  6406. ids = append(ids, item.ID)
  6407. }
  6408. var total float64
  6409. for _, item := range prescriptions {
  6410. fmt.Println(item)
  6411. if item.Type == 1 { //药品
  6412. for _, subItem := range item.HisDoctorAdviceInfo {
  6413. total = total + (subItem.Price * subItem.PrescribingNumber)
  6414. }
  6415. }
  6416. if item.Type == 2 { //项目
  6417. for _, subItem := range item.HisPrescriptionProject {
  6418. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6419. total = total + (subItem.Price * cnt)
  6420. }
  6421. }
  6422. for _, subItem := range item.HisAdditionalCharge {
  6423. total = total + (subItem.Price * float64(subItem.Count))
  6424. }
  6425. }
  6426. if reg_type == 1111 || reg_type == 1112 {
  6427. reg_type = 11
  6428. }
  6429. tm := time.Unix(time.Now().Unix(), 0)
  6430. allTotal := fmt.Sprintf("%.4f", total)
  6431. totals, _ := strconv.ParseFloat(allTotal, 64)
  6432. order := &models.HisOrder{
  6433. UserOrgId: adminUser.CurrentOrgId,
  6434. HisPatientId: his.ID,
  6435. PatientId: id,
  6436. SettleAccountsDate: recordDateTime,
  6437. Ctime: time.Now().Unix(),
  6438. Mtime: time.Now().Unix(),
  6439. Status: 1,
  6440. OrderStatus: 2,
  6441. MdtrtId: his.Number,
  6442. Number: chrg_bchno,
  6443. MedfeeSumamt: totals,
  6444. PayWay: pay_way,
  6445. PayWays: pay_ways,
  6446. PayPrice: pay_price,
  6447. MedType: strconv.Itoa(int(reg_type)),
  6448. PayCardNo: pay_card_no,
  6449. DiscountPrice: discount_price,
  6450. PreferentialPrice: preferential_price,
  6451. RealityPrice: reality_price,
  6452. FoundPrice: found_price,
  6453. MedicalInsurancePrice: medical_insurance_price,
  6454. PrivatePrice: private_price,
  6455. SettleEndTime: end_time,
  6456. SettleStartTime: start_time,
  6457. PsnPartAmt: totals,
  6458. PsnCashPay: totals,
  6459. SettleType: settle_accounts_type,
  6460. FaPiaoCode: fapiao_code,
  6461. FaPiaoNumber: fapiao_number,
  6462. Diagnosis: diagnosis_id,
  6463. PType: 2,
  6464. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6465. Decimal: decimal,
  6466. OthDesc: oth_desc,
  6467. CashPay: cash_pay,
  6468. WechatPay: wechat_pay,
  6469. AliPay: ali_pay,
  6470. JifenPay: jifen_pay,
  6471. BandCardPay: band_card_pay,
  6472. }
  6473. err = service.CreateOrderTX(order, tx)
  6474. if err != nil {
  6475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6476. return
  6477. }
  6478. var customs []*Custom
  6479. for _, item := range prescriptions {
  6480. if item.Type == 1 { //药品a
  6481. for _, subItem := range item.HisDoctorAdviceInfo {
  6482. cus := &Custom{
  6483. AdviceId: subItem.ID,
  6484. ProjectId: 0,
  6485. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6486. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6487. FeedetlSn: subItem.FeedetlSn,
  6488. Price: fmt.Sprintf("%.4f", subItem.Price),
  6489. MedListCodg: subItem.MedListCodg,
  6490. Type: 1,
  6491. }
  6492. customs = append(customs, cus)
  6493. }
  6494. }
  6495. if item.Type == 2 { //项目
  6496. for _, subItem := range item.HisPrescriptionProject {
  6497. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6498. cus := &Custom{
  6499. AdviceId: 0,
  6500. ProjectId: subItem.ID,
  6501. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6502. Cut: fmt.Sprintf("%.4f", cnt),
  6503. FeedetlSn: subItem.FeedetlSn,
  6504. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6505. MedListCodg: subItem.MedListCodg,
  6506. Type: 2,
  6507. }
  6508. customs = append(customs, cus)
  6509. }
  6510. }
  6511. for _, item := range item.HisAdditionalCharge {
  6512. cus := &Custom{
  6513. ItemId: item.ID,
  6514. AdviceId: 0,
  6515. ProjectId: 0,
  6516. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6517. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6518. FeedetlSn: item.FeedetlSn,
  6519. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6520. MedListCodg: item.XtHisAddtionConfig.Code,
  6521. Type: 3,
  6522. }
  6523. customs = append(customs, cus)
  6524. }
  6525. }
  6526. for _, item := range customs {
  6527. var advice_id int64 = 0
  6528. var project_id int64 = 0
  6529. var item_id int64 = 0
  6530. var types int64 = 0
  6531. if item.Type == 1 {
  6532. advice_id = item.AdviceId
  6533. project_id = 0
  6534. item_id = 0
  6535. } else if item.Type == 2 {
  6536. advice_id = 0
  6537. item_id = 0
  6538. project_id = item.ProjectId
  6539. } else if item.Type == 3 {
  6540. advice_id = 0
  6541. item_id = item.ItemId
  6542. project_id = 0
  6543. }
  6544. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6545. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6546. pric, _ := strconv.ParseFloat(item.Price, 32)
  6547. info := &models.HisOrderInfo{
  6548. OrderNumber: order.Number,
  6549. UploadDate: time.Now().Unix(),
  6550. AdviceId: advice_id,
  6551. DetItemFeeSumamt: detItemFeeSumamt,
  6552. Cnt: cut,
  6553. Pric: pric,
  6554. PatientId: id,
  6555. Status: 1,
  6556. Mtime: time.Now().Unix(),
  6557. Ctime: time.Now().Unix(),
  6558. UserOrgId: adminUser.CurrentOrgId,
  6559. HisPatientId: his.ID,
  6560. OrderId: order.ID,
  6561. ProjectId: project_id,
  6562. Type: types,
  6563. ItemId: item_id,
  6564. }
  6565. service.CreateOrderInfoTX(info, tx)
  6566. }
  6567. his.Diagnosis = diagnosis_id
  6568. his.SickType = sick_type
  6569. his.RegisterType = reg_type
  6570. his.MedicalTreatmentType = reg_type
  6571. service.UpdataHisPateintTX(&his, tx)
  6572. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6573. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6574. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6575. //判断是否使用了押金
  6576. if dec_way == "true" {
  6577. tmpstring := strconv.FormatInt(order.ID, 10)
  6578. //扣押金
  6579. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6580. order.Decimal = decimal
  6581. service.UpDateOrderTwo(order, tx)
  6582. if errmsg != nil {
  6583. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6584. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6585. return
  6586. }
  6587. }
  6588. if err == nil {
  6589. for _, info := range prescriptions {
  6590. if info.Type == 1 {
  6591. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6592. }
  6593. if info.Type == 2 {
  6594. for _, sumItem := range info.HisPrescriptionProject {
  6595. if sumItem.Type == 3 {
  6596. var good models.DialysisBeforePrepareGoods
  6597. var newGood models.NewDialysisBeforePrepareGoods
  6598. var oldGood models.OldDialysisBeforePrepareGoods
  6599. good.GoodId = sumItem.GoodInfo.ID
  6600. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6601. count, _ := strconv.Atoi(sumItem.Count)
  6602. good.Count = int64(count)
  6603. good.StorehouseId = houseConfig.StorehouseOutInfo
  6604. good.ProjectId = sumItem.ID
  6605. good.PatientId = sumItem.PatientId
  6606. goods = append(goods, &good)
  6607. newGood.GoodId = sumItem.GoodInfo.ID
  6608. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6609. count2, _ := strconv.Atoi(sumItem.Count)
  6610. newGood.Count = int64(count2)
  6611. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6612. newGood.ProjectId = sumItem.ID
  6613. newGood.PatientId = sumItem.HisPatientId
  6614. newGoods = append(newGoods, &newGood)
  6615. oldGood.GoodId = sumItem.GoodInfo.ID
  6616. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6617. count3, _ := strconv.Atoi(sumItem.Count)
  6618. oldGood.Count = int64(count3)
  6619. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6620. oldGood.ProjectId = sumItem.ID
  6621. oldGood.RecordDate = sumItem.RecordDate
  6622. oldGood.PatientId = sumItem.HisPatientId
  6623. oldGoods = append(oldGoods, &oldGood)
  6624. }
  6625. }
  6626. }
  6627. }
  6628. if settConfig.IsOpen == 1 {
  6629. for _, item := range infoList {
  6630. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6631. if medical.IsUse == 2 {
  6632. //药品出库
  6633. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6634. //查询默认仓库
  6635. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6636. //查询默认仓库剩余多少库存
  6637. var sum_count int64
  6638. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6639. for _, its := range stockInfo {
  6640. if its.MaxUnit == medical.MaxUnit {
  6641. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6642. }
  6643. sum_count += its.StockMaxNumber + its.StockMinNumber
  6644. }
  6645. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6646. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6647. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6648. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6649. }
  6650. }
  6651. orgId := c.GetAdminUserInfo().CurrentOrgId
  6652. if len(oldGoods) > 0 {
  6653. timeStr := time.Now().Format("2006-01-02")
  6654. timeArr := strings.Split(timeStr, "-")
  6655. total, _ := service.FindAllWarehouseOut(orgId)
  6656. total = total + 1
  6657. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6658. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6659. number = number + total
  6660. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6661. operation_time := time.Now().Unix()
  6662. creater := c.GetAdminUserInfo().AdminUser.Id
  6663. //查询默认出库仓库库存
  6664. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6665. recordDateStr := time.Now().Format("2006-01-02")
  6666. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6667. nowtime := recordDate.Unix()
  6668. warehouseOut := models.WarehouseOut{
  6669. WarehouseOutOrderNumber: warehousing_out_order,
  6670. OperationTime: operation_time,
  6671. OrgId: orgId,
  6672. Creater: creater,
  6673. Ctime: time.Now().Unix(),
  6674. Status: 1,
  6675. WarehouseOutTime: nowtime,
  6676. Type: 1,
  6677. StorehouseId: storeConfig.StorehouseOutInfo,
  6678. IsCheck: 1,
  6679. OrderId: order.ID,
  6680. IsSys: 5,
  6681. }
  6682. //查询是否生成出库单
  6683. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6684. if out.ID == 0 {
  6685. service.AddSigleWarehouseOut(&warehouseOut)
  6686. }
  6687. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6688. for _, item := range oldGoods {
  6689. dialyPrepareOne := models.DialysisBeforePrepare{
  6690. GoodTypeId: item.GoodTypeId,
  6691. GoodId: item.GoodId,
  6692. PatientId: his.PatientId,
  6693. RecordDate: item.RecordDate,
  6694. UserOrgId: adminUser.CurrentOrgId,
  6695. Count: item.Count,
  6696. Ctime: time.Now().Unix(),
  6697. Creater: adminUser.AdminUser.Id,
  6698. CommdityCode: item.CommdityCode,
  6699. Status: 1,
  6700. StorehouseId: houseConfig.StorehouseOutInfo,
  6701. }
  6702. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6703. //非零用
  6704. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6705. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6706. //查询剩余库存
  6707. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6708. var sum_count int64
  6709. for _, item := range goodList {
  6710. sum_count += item.StockCount
  6711. }
  6712. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6713. //耗材
  6714. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6715. }
  6716. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6717. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6718. //查询剩余库存
  6719. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6720. var sum_count int64
  6721. for _, item := range goodList {
  6722. sum_count += item.StockCount
  6723. }
  6724. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6725. //耗材
  6726. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6727. }
  6728. }
  6729. }
  6730. }
  6731. c.ServeSuccessJSON(map[string]interface{}{
  6732. "msg": "结算成功",
  6733. })
  6734. }
  6735. }
  6736. }
  6737. // 退款
  6738. func (c *HisApiController) Refund() {
  6739. order_id, _ := c.GetInt64("order_id")
  6740. order, _ := service.GetHisOrderByID(order_id)
  6741. adminUser := c.GetAdminUserInfo()
  6742. orgid := c.GetAdminUserInfo().CurrentOrgId
  6743. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6744. if err != nil {
  6745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6746. return
  6747. }
  6748. tmp := strconv.FormatInt(order.ID, 10)
  6749. //当押金不为零时产生退费记录
  6750. if order.Decimal != 0 {
  6751. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6752. if err != nil {
  6753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6754. return
  6755. }
  6756. }
  6757. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6758. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6759. var goods []*models.DialysisBeforePrepareGoods
  6760. var newGoods []*models.NewDialysisBeforePrepareGoods
  6761. var infos []*models.HisDoctorAdviceInfo
  6762. for _, info := range orders {
  6763. if info.AdviceId > 0 && info.ProjectId == 0 {
  6764. infos = append(infos, &info.HisDoctorAdviceInfo)
  6765. }
  6766. if info.ProjectId > 0 && info.AdviceId == 0 {
  6767. if info.HisPrescriptionProject.Type == 3 {
  6768. var good models.DialysisBeforePrepareGoods
  6769. var newGood models.NewDialysisBeforePrepareGoods
  6770. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6771. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6772. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6773. good.Count = int64(count)
  6774. good.StorehouseId = houseConfig.StorehouseOutInfo
  6775. good.ProjectId = info.HisPrescriptionProject.ID
  6776. good.PatientId = info.PatientId
  6777. good.OrderId = order_id
  6778. goods = append(goods, &good)
  6779. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6780. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6781. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6782. newGood.Count = int64(count2)
  6783. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6784. newGood.ProjectId = info.HisPrescriptionProject.ID
  6785. newGood.RecordDate = order.SettleAccountsDate
  6786. newGood.UserOrgId = order.UserOrgId
  6787. newGood.PatientId = info.PatientId
  6788. newGood.OrderId = order_id
  6789. newGoods = append(newGoods, &newGood)
  6790. }
  6791. }
  6792. }
  6793. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6794. if settConfig.IsOpen == 1 {
  6795. for _, item := range infos {
  6796. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6797. }
  6798. for _, item := range newGoods {
  6799. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6800. }
  6801. }
  6802. c.ServeSuccessJSON(map[string]interface{}{
  6803. "msg": "退费成功",
  6804. })
  6805. }
  6806. func (c *HisApiController) RefundNumber() {
  6807. his_patient_id, _ := c.GetInt64("id")
  6808. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6809. info.Status = 0
  6810. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6811. if count > 0 {
  6812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6813. return
  6814. }
  6815. err := service.SaveHisPatient(info)
  6816. if err == nil {
  6817. c.ServeSuccessJSON(map[string]interface{}{
  6818. "msg": "退号成功",
  6819. })
  6820. } else {
  6821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6822. return
  6823. }
  6824. }
  6825. func (this *HisApiController) AdditionalCharge() {
  6826. dataBody := make(map[string]interface{}, 0)
  6827. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6828. fmt.Println(err)
  6829. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6830. patient_id := int64(dataBody["patient_id"].(float64))
  6831. medicineData, _ := dataBody["medicineData"].([]interface{})
  6832. adminUserInfo := this.GetAdminUserInfo()
  6833. orgId := adminUserInfo.CurrentOrgId
  6834. admin_user_id := adminUserInfo.AdminUser.Id
  6835. timeStr := time.Now().Format("2006-01-02")
  6836. timeLayout := "2006-01-02 15:04:05"
  6837. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6838. timenow := timeStringToTime.Unix()
  6839. var additionalCharges []*models.HisAdditionalCharge
  6840. for _, item := range medicineData {
  6841. var randNum int
  6842. randNum = rand.Intn(10000) + 1000
  6843. timestamp := time.Now().Unix()
  6844. tempTime := time.Unix(timestamp, 0)
  6845. timeFormat := tempTime.Format("20060102150405")
  6846. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6847. items := item.(map[string]interface{})
  6848. money := items["price"].(string)
  6849. item_id_str := items["item_id"].(string)
  6850. name := items["name"].(string)
  6851. id_str := items["id"].(string)
  6852. moneys, _ := strconv.ParseInt(money, 10, 64)
  6853. monStr := strconv.FormatInt(moneys, 10)
  6854. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6855. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6856. id, _ := strconv.ParseInt(id_str, 10, 64)
  6857. additionalCharge := &models.HisAdditionalCharge{
  6858. ID: id,
  6859. HisPatientId: his_patient_id,
  6860. UserOrgId: orgId,
  6861. PatientId: patient_id,
  6862. RecordDate: timenow,
  6863. Price: monneyStr,
  6864. Status: 1,
  6865. ItemName: name,
  6866. ItemId: item_id,
  6867. AdminUserId: admin_user_id,
  6868. CreatedTime: time.Now().Unix(),
  6869. OrderStatus: 0,
  6870. PrescriptionNumber: "",
  6871. BatchNumber: "",
  6872. FeedetlSn: p_number,
  6873. }
  6874. service.CreateAdditionalCharge(additionalCharge)
  6875. additionalCharges = append(additionalCharges, additionalCharge)
  6876. }
  6877. this.ServeSuccessJSON(map[string]interface{}{
  6878. "msg": "添加成功",
  6879. "additional_charges": additionalCharges,
  6880. })
  6881. }
  6882. func (this *HisApiController) DeleteAddition() {
  6883. id, _ := this.GetInt64("id")
  6884. //TODO 需要判断是否已经结算
  6885. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6886. if err == nil {
  6887. this.ServeSuccessJSON(map[string]interface{}{
  6888. "msg": "删除成功",
  6889. })
  6890. return
  6891. } else {
  6892. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6893. return
  6894. }
  6895. }
  6896. func (this *HisApiController) GetAdminUsers() {
  6897. adminUser := this.GetAdminUserInfo()
  6898. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6899. this.ServeSuccessJSON(map[string]interface{}{
  6900. "doctors": doctors,
  6901. })
  6902. }
  6903. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6904. change_type, _ := this.GetInt64("type", 0)
  6905. record_date := this.GetString("record_time")
  6906. patient_id, _ := this.GetInt64("patient_id", 0)
  6907. p_type, _ := this.GetInt64("p_type", 0)
  6908. timeLayout := "2006-01-02"
  6909. loc, _ := time.LoadLocation("Local")
  6910. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6911. record_time := theAdviceRecordTime.Unix()
  6912. adminUserInfo := this.GetAdminUserInfo()
  6913. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6914. if err == nil {
  6915. if len(prescriptions) == 0 {
  6916. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6917. return
  6918. } else {
  6919. this.ServeSuccessJSON(map[string]interface{}{
  6920. "prescriptions": prescriptions,
  6921. })
  6922. return
  6923. }
  6924. } else {
  6925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6926. return
  6927. }
  6928. }
  6929. func (this *HisApiController) GetCallHisPrescription() {
  6930. patient_id, _ := this.GetInt64("patient_id", 0)
  6931. timeLayout := "2006-01-02"
  6932. loc, _ := time.LoadLocation("Local")
  6933. start_time := this.GetString("start_time")
  6934. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6935. end_time := this.GetString("end_time")
  6936. p_type, _ := this.GetInt64("p_type")
  6937. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6938. adminUserInfo := this.GetAdminUserInfo()
  6939. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6940. if err == nil {
  6941. this.ServeSuccessJSON(map[string]interface{}{
  6942. "prescriptions": prescriptions,
  6943. })
  6944. return
  6945. } else {
  6946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6947. return
  6948. }
  6949. }
  6950. func (this *HisApiController) GetHisDayPrescription() {
  6951. timeLayout := "2006-01-02"
  6952. loc, _ := time.LoadLocation("Local")
  6953. start_time := this.GetString("start_time")
  6954. patient_id, _ := this.GetInt64("patient_id", 0)
  6955. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6956. end_time := this.GetString("end_time")
  6957. p_type, _ := this.GetInt64("p_type")
  6958. order_status, _ := this.GetInt64("type")
  6959. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6960. adminUserInfo := this.GetAdminUserInfo()
  6961. var dayHisPrescription []*models.HisPrescription
  6962. var err error
  6963. if order_status == 1 || order_status == 0 {
  6964. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6965. } else if order_status == 2 {
  6966. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6967. }
  6968. var settle_total float64
  6969. for _, item := range dayHisPrescription {
  6970. if len(item.HisPrescriptionProject) > 0 {
  6971. for _, subItem := range item.HisPrescriptionProject {
  6972. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6973. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6974. settle_total = settle_total + total
  6975. }
  6976. }
  6977. if len(item.HisDoctorAdviceInfo) > 0 {
  6978. for _, subItem := range item.HisDoctorAdviceInfo {
  6979. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6980. settle_total = settle_total + total
  6981. }
  6982. }
  6983. }
  6984. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6985. if err == nil {
  6986. this.ServeSuccessJSON(map[string]interface{}{
  6987. "day_prescription": dayHisPrescription,
  6988. "settle_total": settle_total,
  6989. })
  6990. return
  6991. } else {
  6992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6993. return
  6994. }
  6995. }
  6996. func (c *HisApiController) GetHisChargePatientList() {
  6997. record_date := c.GetString("record_date")
  6998. order_status, _ := c.GetInt64("type")
  6999. sch_type, _ := c.GetInt64("sch_type")
  7000. timeLayout := "2006-01-02"
  7001. loc, _ := time.LoadLocation("Local")
  7002. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7003. if err != nil {
  7004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7005. return
  7006. }
  7007. recordDateTime := theTime.Unix()
  7008. adminInfo := c.GetAdminUserInfo()
  7009. var tempPatients []*service.NewTempPatients
  7010. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7011. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7012. if order_status != 2 {
  7013. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7014. } else {
  7015. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7016. }
  7017. } else {
  7018. if order_status != 2 {
  7019. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7020. } else {
  7021. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7022. }
  7023. }
  7024. var patients []*service.NewTempPatients
  7025. var patients_two []*service.NewTempPatients
  7026. for _, item := range tempPatients {
  7027. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7028. //过滤掉没挂号的和没开处方的
  7029. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7030. patients = append(patients, item)
  7031. }
  7032. //过滤掉没挂号的
  7033. if len(item.HisPatient) > 0 {
  7034. patients_two = append(patients_two, item)
  7035. }
  7036. } else {
  7037. if len(item.HisPrescription) > 0 {
  7038. patients = append(patients, item)
  7039. }
  7040. }
  7041. }
  7042. c.ServeSuccessJSON(map[string]interface{}{
  7043. "list": patients,
  7044. "list_two": patients_two,
  7045. })
  7046. }
  7047. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7048. record_date := c.GetString("record_date")
  7049. timeLayout := "2006-01-02"
  7050. loc, _ := time.LoadLocation("Local")
  7051. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7052. if err != nil {
  7053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7054. return
  7055. }
  7056. recordDateTime := theTime.Unix()
  7057. adminUser := c.GetAdminUserInfo()
  7058. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7059. var patients []*service.Patients
  7060. for _, item := range tempPatients {
  7061. if item.HisPatient.ID == 0 {
  7062. patients = append(patients, item)
  7063. }
  7064. }
  7065. c.ServeSuccessJSON(map[string]interface{}{
  7066. "list": patients,
  7067. //"list_two": patients_two,
  7068. })
  7069. }
  7070. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7071. newArr = make([]*service.Patients, 0)
  7072. for i := 0; i < len(patient); i++ {
  7073. repeat := false
  7074. for j := i + 1; j < len(patient); j++ {
  7075. if patient[i].ID == patient[j].ID {
  7076. repeat = true
  7077. break
  7078. }
  7079. }
  7080. if !repeat {
  7081. newArr = append(newArr, patient[i])
  7082. }
  7083. }
  7084. return
  7085. }
  7086. func (c *HisApiController) GetHisChargePatientInfo() {
  7087. patient_id, _ := c.GetInt64("patient_id")
  7088. his_patient_id, _ := c.GetInt64("his_patient_id")
  7089. record_date := c.GetString("record_date")
  7090. //start_time := c.GetString("start_time")
  7091. //end_time := c.GetString("end_time")
  7092. order_status, _ := c.GetInt64("type", 0)
  7093. p_type, _ := c.GetInt64("p_type", 0)
  7094. order_id, _ := c.GetInt64("order_id", 0)
  7095. timeLayout := "2006-01-02"
  7096. loc, _ := time.LoadLocation("Local")
  7097. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7098. if err != nil {
  7099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7100. return
  7101. }
  7102. recordDateTime := theTime.Unix()
  7103. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7104. //if err != nil {
  7105. //
  7106. //}
  7107. //startRecordDateTime := startTime.Unix()
  7108. //
  7109. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7110. //if err != nil {
  7111. //
  7112. //}
  7113. //endRecordDateTime := endTime.Unix()
  7114. admin := c.GetAdminUserInfo()
  7115. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7116. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7117. var prescriptions []*models.HisPrescription
  7118. //var unChargeMonthPrescriptions []*models.HisPrescription
  7119. order, _ := service.GetHisOrderByID(order_id)
  7120. if order_status == 1 || order_status == 0 {
  7121. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7122. } else if order_status == 2 {
  7123. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7124. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7125. }
  7126. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7127. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7128. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7129. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7130. //获取所有科室信息
  7131. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7132. c.ServeSuccessJSON(map[string]interface{}{
  7133. "his_info": his_patient_info,
  7134. "xt_info": xt_patient_info,
  7135. "prescription": prescriptions,
  7136. "case_history": case_history,
  7137. "info": patientPrescriptionInfo,
  7138. "last_info": lastPatientPrescriptionInfo,
  7139. "order": order,
  7140. "doctors": doctors,
  7141. "department": department,
  7142. })
  7143. return
  7144. }
  7145. func (c *HisApiController) GetAllOrderDetail() {
  7146. order_id, _ := c.GetInt64("id", 0)
  7147. order, _ := service.GetHisOrderByID(order_id)
  7148. if order.ID == 0 {
  7149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7150. return
  7151. }
  7152. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7153. org_id := c.GetAdminUserInfo().CurrentOrgId
  7154. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7155. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7156. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7157. c.ServeSuccessJSON(map[string]interface{}{
  7158. "order": order,
  7159. "order_info": order_info,
  7160. "patient": patient,
  7161. "admin_info": adminInfo,
  7162. "hospital_record": record,
  7163. })
  7164. return
  7165. }
  7166. func (c *HisApiController) GetAllOrderDetailCollect() {
  7167. order_id, _ := c.GetInt64("id", 0)
  7168. order, _ := service.GetHisOrderByID(order_id)
  7169. if order.ID == 0 {
  7170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7171. return
  7172. }
  7173. org_id := c.GetAdminUserInfo().CurrentOrgId
  7174. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7175. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7176. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7177. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7178. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7179. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7180. var bedCostTotal float64 = 0 //床位总费
  7181. //var bedCostSelfTotal float64 = 0 //床位自费
  7182. var operationCostTotal float64 = 0 //手术费
  7183. //var operationCostSelfTotal float64 = 0 //手术费
  7184. var otherCostTotal float64 = 0 //其他费用
  7185. //var otherCostSelfTotal float64 = 0 //其他费用
  7186. var materialCostTotal float64 = 0 //材料费
  7187. //var materialCostSelfTotal float64 = 0 //材料费
  7188. var westernMedicineCostTotal float64 = 0 //西药费
  7189. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7190. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7191. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7192. var checkCostTotal float64 = 0 //检查费
  7193. //var checkCostSelfTotal float64 = 0 //检查费
  7194. var laboratoryCostTotal float64 = 0 //化验费
  7195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7196. var treatCostTotal float64 = 0 //治疗费用
  7197. //var treatCostSelfTotal float64 = 0 //治疗费用
  7198. var zhenChaCostTotal float64 = 0 //其他费用
  7199. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7200. decimal.DivisionPrecision = 2
  7201. var BalanceAccountsType int64
  7202. if his.ID > 0 {
  7203. BalanceAccountsType = his.BalanceAccountsType
  7204. } else {
  7205. BalanceAccountsType = record.BalanceAccountsType
  7206. }
  7207. if BalanceAccountsType != 2 {
  7208. for _, item := range order_info {
  7209. if org_id == 10215 {
  7210. if item.MedChrgitmType == "01" { //床位费
  7211. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7212. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7213. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7214. }
  7215. if item.MedChrgitmType == "02" { //诊察费
  7216. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7217. //zhenChaCostSelfTotal = zhenChaCostTotal
  7218. }
  7219. if item.MedChrgitmType == "03" { //检查费
  7220. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7221. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7222. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7223. }
  7224. //if item.MedChrgitmType == "02" { //检查费
  7225. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7226. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7227. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7228. //}
  7229. if item.MedChrgitmType == "04" { //化验费
  7230. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7231. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7232. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7233. }
  7234. if item.MedChrgitmType == "05" { //治疗费
  7235. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7236. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7237. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7238. }
  7239. if item.MedChrgitmType == "06" { //手术费
  7240. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7241. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7242. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7243. }
  7244. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7245. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7246. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7247. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7248. }
  7249. if item.MedChrgitmType == "09" { //西药费
  7250. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7251. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7252. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7253. }
  7254. if item.MedChrgitmType == "11" { //中成费
  7255. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7256. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7257. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7258. }
  7259. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7260. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7261. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7262. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7263. }
  7264. } else if org_id == 10188 || org_id == 10217 {
  7265. if item.MedChrgitmType == "01" { //床位费
  7266. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7267. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7268. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7269. }
  7270. if item.MedChrgitmType == "02" { //诊察费
  7271. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7272. //zhenChaCostSelfTotal = zhenChaCostTotal
  7273. }
  7274. if item.MedChrgitmType == "03" { //检查费
  7275. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7276. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7277. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7278. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7279. }
  7280. //if item.MedChrgitmType == "02" { //检查费
  7281. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7282. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7283. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7284. //}
  7285. if item.MedChrgitmType == "04" { //化验费
  7286. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7287. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7288. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7289. }
  7290. if item.MedChrgitmType == "05" { //治疗费
  7291. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7292. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7293. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7294. }
  7295. if item.MedChrgitmType == "06" { //手术费
  7296. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7297. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7298. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7299. }
  7300. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7301. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7302. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7303. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7304. }
  7305. if item.MedChrgitmType == "09" { //西药费
  7306. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7307. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7308. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7309. }
  7310. if item.MedChrgitmType == "11" { //中成费
  7311. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7312. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7313. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7314. }
  7315. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7316. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7317. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7318. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7319. }
  7320. } else {
  7321. if item.MedChrgitmType == "01" { //床位费
  7322. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7323. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7324. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7325. }
  7326. //if item.MedChrgitmType == "02" { //诊察费
  7327. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7328. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7329. //}
  7330. if item.MedChrgitmType == "03" { //检查费
  7331. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7332. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7333. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7334. }
  7335. //if item.MedChrgitmType == "02" { //检查费
  7336. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7337. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7338. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7339. //}
  7340. if item.MedChrgitmType == "04" { //化验费
  7341. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7342. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7343. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7344. }
  7345. if item.MedChrgitmType == "05" { //治疗费
  7346. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7347. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7348. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7349. }
  7350. if item.MedChrgitmType == "06" { //手术费
  7351. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7352. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7353. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7354. }
  7355. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7356. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7357. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7358. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7359. }
  7360. if item.MedChrgitmType == "09" { //西药费
  7361. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7362. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7363. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7364. }
  7365. if item.MedChrgitmType == "11" { //中成费
  7366. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7367. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7368. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7369. }
  7370. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7371. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7372. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7373. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7374. }
  7375. }
  7376. }
  7377. c.ServeSuccessJSON(map[string]interface{}{
  7378. "order": order,
  7379. "order_info": order_info,
  7380. "patient": patient,
  7381. "admin_info": adminInfo,
  7382. "his_hospital": record,
  7383. "bedCostTotal": bedCostTotal,
  7384. "operationCostTotal": operationCostTotal,
  7385. "otherCostTotal": otherCostTotal,
  7386. "materialCostTotal": materialCostTotal,
  7387. "westernMedicineCostTotal": westernMedicineCostTotal,
  7388. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7389. "checkCostTotal": checkCostTotal,
  7390. "zhenChaCostTotal": zhenChaCostTotal,
  7391. "laboratoryCostTotal": laboratoryCostTotal,
  7392. "treatCostTotal": treatCostTotal,
  7393. })
  7394. } else {
  7395. for _, item := range order_info {
  7396. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7397. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7398. item.MedChrgitmType = "09"
  7399. }
  7400. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7401. if item.HisPrescriptionProject.Type == 2 {
  7402. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7403. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7404. case 0:
  7405. item.MedChrgitmType = "0"
  7406. break
  7407. case 1:
  7408. item.MedChrgitmType = "14"
  7409. break
  7410. case 2:
  7411. item.MedChrgitmType = "05"
  7412. break
  7413. case 3:
  7414. item.MedChrgitmType = "03"
  7415. break
  7416. case 4:
  7417. item.MedChrgitmType = "03"
  7418. break
  7419. case 5:
  7420. item.MedChrgitmType = "08"
  7421. break
  7422. case 6:
  7423. item.MedChrgitmType = "14"
  7424. break
  7425. case 7:
  7426. item.MedChrgitmType = "14"
  7427. break
  7428. case 8:
  7429. item.MedChrgitmType = "03"
  7430. break
  7431. case 9:
  7432. item.MedChrgitmType = "14"
  7433. break
  7434. case 10:
  7435. item.MedChrgitmType = "14"
  7436. break
  7437. case 11:
  7438. item.MedChrgitmType = "06"
  7439. break
  7440. case 12:
  7441. item.MedChrgitmType = "12"
  7442. break
  7443. case 13:
  7444. item.MedChrgitmType = "01"
  7445. break
  7446. case 14:
  7447. item.MedChrgitmType = "04"
  7448. break
  7449. case 15:
  7450. item.MedChrgitmType = "14"
  7451. break
  7452. }
  7453. } else {
  7454. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7455. case 1:
  7456. item.MedChrgitmType = "14"
  7457. break
  7458. case 2:
  7459. item.MedChrgitmType = "05"
  7460. break
  7461. case 3:
  7462. item.MedChrgitmType = "04"
  7463. break
  7464. case 4:
  7465. item.MedChrgitmType = "14"
  7466. break
  7467. case 5:
  7468. item.MedChrgitmType = "08"
  7469. break
  7470. case 6:
  7471. item.MedChrgitmType = "14"
  7472. break
  7473. case 7:
  7474. item.MedChrgitmType = "14"
  7475. break
  7476. case 8:
  7477. item.MedChrgitmType = "03"
  7478. break
  7479. case 9:
  7480. item.MedChrgitmType = "14"
  7481. break
  7482. }
  7483. }
  7484. } else if item.HisPrescriptionProject.Type == 3 {
  7485. item.MedChrgitmType = "08"
  7486. }
  7487. }
  7488. }
  7489. for _, item := range order_info {
  7490. if org_id == 10215 {
  7491. if item.MedChrgitmType == "01" { //床位费
  7492. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7493. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7494. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7495. }
  7496. if item.MedChrgitmType == "02" { //诊察费
  7497. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7498. //zhenChaCostSelfTotal = zhenChaCostTotal
  7499. }
  7500. if item.MedChrgitmType == "03" { //检查费
  7501. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7502. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7503. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7504. }
  7505. //if item.MedChrgitmType == "02" { //检查费
  7506. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7507. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7508. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7509. //}
  7510. if item.MedChrgitmType == "04" { //化验费
  7511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7512. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7513. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7514. }
  7515. if item.MedChrgitmType == "05" { //治疗费
  7516. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7517. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7518. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7519. }
  7520. if item.MedChrgitmType == "06" { //手术费
  7521. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7522. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7523. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7524. }
  7525. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7526. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7527. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7528. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7529. }
  7530. if item.MedChrgitmType == "09" { //西药费
  7531. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7532. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7533. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7534. }
  7535. if item.MedChrgitmType == "11" { //中成费
  7536. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7537. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7538. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7539. }
  7540. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7541. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7542. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7543. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7544. }
  7545. } else {
  7546. if item.MedChrgitmType == "01" { //床位费
  7547. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7548. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7549. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7550. }
  7551. //if item.MedChrgitmType == "02" { //诊察费
  7552. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7553. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7554. //}
  7555. if item.MedChrgitmType == "03" { //检查费
  7556. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7557. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7558. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7559. }
  7560. //if item.MedChrgitmType == "02" { //检查费
  7561. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7562. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7563. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7564. //}
  7565. if item.MedChrgitmType == "04" { //化验费
  7566. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7567. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7568. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7569. }
  7570. if item.MedChrgitmType == "05" { //治疗费
  7571. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7572. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7573. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7574. }
  7575. if item.MedChrgitmType == "06" { //手术费
  7576. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7577. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7578. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7579. }
  7580. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7581. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7582. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7583. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7584. }
  7585. if item.MedChrgitmType == "09" { //西药费
  7586. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7587. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7588. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7589. }
  7590. if item.MedChrgitmType == "11" { //中成费
  7591. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7592. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7593. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7594. }
  7595. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7596. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7597. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7598. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7599. }
  7600. }
  7601. }
  7602. c.ServeSuccessJSON(map[string]interface{}{
  7603. "order": order,
  7604. "order_info": order_info,
  7605. "patient": patient,
  7606. "admin_info": adminInfo,
  7607. "his_hospital": record,
  7608. "bedCostTotal": bedCostTotal,
  7609. "operationCostTotal": operationCostTotal,
  7610. "otherCostTotal": otherCostTotal,
  7611. "materialCostTotal": materialCostTotal,
  7612. "westernMedicineCostTotal": westernMedicineCostTotal,
  7613. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7614. "checkCostTotal": checkCostTotal,
  7615. "zhenChaCostTotal": zhenChaCostTotal,
  7616. "laboratoryCostTotal": laboratoryCostTotal,
  7617. "treatCostTotal": treatCostTotal,
  7618. })
  7619. }
  7620. }
  7621. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7622. page, _ := c.GetInt64("page")
  7623. limit, _ := c.GetInt64("limit")
  7624. keywords := c.GetString("keywords")
  7625. start_time := c.GetString("start_time")
  7626. end_time := c.GetString("end_time")
  7627. //clr_type := c.GetString("clr_type")
  7628. insutype := c.GetString("insutype")
  7629. timeLayout := "2006-01-02"
  7630. loc, _ := time.LoadLocation("Local")
  7631. var theStartTIme int64
  7632. if len(start_time) > 0 {
  7633. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7634. theStartTIme = theTime.Unix()
  7635. }
  7636. var theEndtTIme int64
  7637. if len(end_time) > 0 {
  7638. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7639. theEndtTIme = theTime.Unix()
  7640. }
  7641. if page <= 0 {
  7642. page = 1
  7643. }
  7644. if limit <= 0 {
  7645. limit = 10
  7646. }
  7647. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7648. c.ServeSuccessJSON(map[string]interface{}{
  7649. "total": total,
  7650. "list": list,
  7651. })
  7652. return
  7653. }
  7654. func (c *HisApiController) GetPutOnRecordList() {
  7655. page, _ := c.GetInt64("page")
  7656. limit, _ := c.GetInt64("limit")
  7657. keywords := c.GetString("keywords")
  7658. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7659. if page <= 0 {
  7660. page = 1
  7661. }
  7662. if limit <= 0 {
  7663. limit = 10
  7664. }
  7665. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7666. c.ServeSuccessJSON(map[string]interface{}{
  7667. "total": total,
  7668. "list": list,
  7669. })
  7670. return
  7671. }
  7672. func (c *HisApiController) GetCompareData() {
  7673. start_time := c.GetString("start_time")
  7674. end_time := c.GetString("end_time")
  7675. insutype := c.GetString("insutype")
  7676. clr_type := c.GetString("clr_type")
  7677. timeLayout := "2006-01-02"
  7678. loc, _ := time.LoadLocation("Local")
  7679. var theStartTIme int64
  7680. if len(start_time) > 0 {
  7681. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7682. if err != nil {
  7683. theStartTIme = 0
  7684. }
  7685. theStartTIme = theTime.Unix()
  7686. }
  7687. var theEndtTIme int64
  7688. if len(end_time) > 0 {
  7689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7690. if err != nil {
  7691. theEndtTIme = 0
  7692. }
  7693. theEndtTIme = theTime.Unix()
  7694. }
  7695. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7696. fmt.Println(err)
  7697. if err == nil {
  7698. c.ServeSuccessJSON(map[string]interface{}{
  7699. "list": formData,
  7700. })
  7701. } else {
  7702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7703. return
  7704. }
  7705. }
  7706. func (c *HisApiController) GetFaPiaoData() {
  7707. order_id, _ := c.GetInt64("order_id")
  7708. patient_id, _ := c.GetInt64("patient_id")
  7709. //number := c.GetString("number")
  7710. adminUser := c.GetAdminUserInfo()
  7711. order, _ := service.GetHisOrderByID(order_id)
  7712. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7713. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7714. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7715. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7716. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7717. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7718. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7719. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7720. var bedCostTotal float64 = 0 //床位总费
  7721. var bedCostSelfTotal float64 = 0 //床位自费
  7722. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7723. var operationCostTotal float64 = 0 //手术费
  7724. var operationCostSelfTotal float64 = 0 //手术费
  7725. var operationCostPartSelfTotal float64 = 0 //手术费
  7726. var otherCostTotal float64 = 0 //其他费用
  7727. var otherCostSelfTotal float64 = 0 //其他费用
  7728. var otherCostPartSelfTotal float64 = 0 //其他费用
  7729. var materialCostTotal float64 = 0 //材料费
  7730. var materialCostSelfTotal float64 = 0 //材料费
  7731. var materialCostPartSelfTotal float64 = 0 //材料费
  7732. var westernMedicineCostTotal float64 = 0 //西药费
  7733. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7734. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7735. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7736. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7737. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7738. var checkCostTotal float64 = 0 //检查费
  7739. var checkCostSelfTotal float64 = 0 //检查费
  7740. var checkCostPartSelfTotal float64 = 0 //检查费
  7741. var hiliCostTotal float64 = 0 //护理费
  7742. var hiliCostSelfTotal float64 = 0 //护理费
  7743. var hiliCostPartSelfTotal float64 = 0 //护理费
  7744. var laboratoryCostTotal float64 = 0 //化验费
  7745. var laboratoryCostSelfTotal float64 = 0 //化验费
  7746. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7747. var treatCostTotal float64 = 0 //治疗费用
  7748. var treatCostSelfTotal float64 = 0 //治疗费用
  7749. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7750. var zhenChaCostTotal float64 = 0 //其他费用
  7751. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7752. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7753. decimal.DivisionPrecision = 2
  7754. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7755. var balanceAccountsType int64
  7756. if his.ID > 0 {
  7757. balanceAccountsType = his.BalanceAccountsType
  7758. } else {
  7759. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7760. }
  7761. if balanceAccountsType == 2 {
  7762. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7763. for _, item := range orderInfos_two {
  7764. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7765. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7766. item.MedChrgitmType = "09"
  7767. }
  7768. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7769. if item.HisPrescriptionProject.Type == 2 {
  7770. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7771. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7772. case 0:
  7773. item.MedChrgitmType = "0"
  7774. break
  7775. case 1:
  7776. item.MedChrgitmType = "14"
  7777. break
  7778. case 2:
  7779. item.MedChrgitmType = "05"
  7780. break
  7781. case 3:
  7782. item.MedChrgitmType = "03"
  7783. break
  7784. case 4:
  7785. item.MedChrgitmType = "03"
  7786. break
  7787. case 5:
  7788. item.MedChrgitmType = "08"
  7789. break
  7790. case 6:
  7791. item.MedChrgitmType = "14"
  7792. break
  7793. case 7:
  7794. item.MedChrgitmType = "14"
  7795. break
  7796. case 8:
  7797. item.MedChrgitmType = "03"
  7798. break
  7799. case 9:
  7800. item.MedChrgitmType = "14"
  7801. break
  7802. case 10:
  7803. item.MedChrgitmType = "14"
  7804. break
  7805. case 11:
  7806. item.MedChrgitmType = "06"
  7807. break
  7808. case 12:
  7809. item.MedChrgitmType = "12"
  7810. break
  7811. case 13:
  7812. item.MedChrgitmType = "01"
  7813. break
  7814. case 14:
  7815. item.MedChrgitmType = "04"
  7816. break
  7817. case 15:
  7818. item.MedChrgitmType = "02"
  7819. break
  7820. }
  7821. } else {
  7822. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7823. case 1:
  7824. item.MedChrgitmType = "14"
  7825. break
  7826. case 2:
  7827. item.MedChrgitmType = "05"
  7828. break
  7829. case 3:
  7830. item.MedChrgitmType = "03"
  7831. break
  7832. case 4:
  7833. item.MedChrgitmType = "03"
  7834. break
  7835. case 5:
  7836. item.MedChrgitmType = "08"
  7837. break
  7838. case 6:
  7839. item.MedChrgitmType = "14"
  7840. break
  7841. case 7:
  7842. item.MedChrgitmType = "14"
  7843. break
  7844. case 8:
  7845. item.MedChrgitmType = "03"
  7846. break
  7847. case 9:
  7848. item.MedChrgitmType = "14"
  7849. break
  7850. }
  7851. }
  7852. } else if item.HisPrescriptionProject.Type == 3 {
  7853. item.MedChrgitmType = "08"
  7854. }
  7855. }
  7856. }
  7857. for _, item := range orderInfos_two {
  7858. fmt.Println(item.MedChrgitmType)
  7859. if item.MedChrgitmType == "07" { //床位费
  7860. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7861. hiliCostSelfTotal = hiliCostTotal
  7862. }
  7863. if item.MedChrgitmType == "01" { //床位费
  7864. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7865. bedCostSelfTotal = bedCostTotal
  7866. }
  7867. if item.MedChrgitmType == "02" { //诊察费
  7868. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7869. zhenChaCostSelfTotal = zhenChaCostTotal
  7870. }
  7871. if item.MedChrgitmType == "03" { //检查费
  7872. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7873. checkCostSelfTotal = checkCostTotal
  7874. }
  7875. if item.MedChrgitmType == "04" { //化验费
  7876. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7877. laboratoryCostSelfTotal = laboratoryCostTotal
  7878. }
  7879. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7880. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7881. treatCostSelfTotal = treatCostTotal
  7882. }
  7883. if item.MedChrgitmType == "06" { //手术费
  7884. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7885. operationCostSelfTotal = treatCostTotal
  7886. }
  7887. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7888. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7889. materialCostSelfTotal = materialCostTotal
  7890. }
  7891. if item.MedChrgitmType == "09" { //西药费
  7892. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7893. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7894. }
  7895. if item.MedChrgitmType == "11" { //中成费
  7896. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7897. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7898. }
  7899. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7900. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7901. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7902. otherCostSelfTotal = otherCostTotal
  7903. }
  7904. } else {
  7905. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7906. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7907. otherCostSelfTotal = otherCostTotal
  7908. }
  7909. }
  7910. }
  7911. } else {
  7912. for _, item := range orderInfos {
  7913. if item.MedChrgitmType == "01" { //床位费
  7914. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7915. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7916. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7917. }
  7918. if item.MedChrgitmType == "02" { //诊察费
  7919. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7920. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7921. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7922. }
  7923. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7924. if item.MedChrgitmType == "03" { //检查费
  7925. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7926. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7927. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7928. }
  7929. } else {
  7930. if item.MedChrgitmType == "03" { //检查费
  7931. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7932. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7933. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7934. }
  7935. }
  7936. if item.MedChrgitmType == "04" { //化验费
  7937. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7938. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7939. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7940. }
  7941. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7942. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7943. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7944. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7945. }
  7946. if item.MedChrgitmType == "06" { //手术费
  7947. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7948. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7949. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7950. }
  7951. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  7952. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7953. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7954. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7955. }
  7956. if item.MedChrgitmType == "07" { //西药费
  7957. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7958. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7959. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7960. }
  7961. if item.MedChrgitmType == "09" { //西药费
  7962. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7963. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7964. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7965. }
  7966. if item.MedChrgitmType == "11" { //中成费
  7967. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7968. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7969. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7970. }
  7971. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7972. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7973. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7974. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7975. }
  7976. }
  7977. }
  7978. timeLayout := "2006-01-02"
  7979. loc, _ := time.LoadLocation("Local")
  7980. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7981. if err != nil {
  7982. }
  7983. startRecordDateTime := startTime.Unix()
  7984. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7985. if err != nil {
  7986. }
  7987. endRecordDateTime := endTime.Unix()
  7988. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7989. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7990. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7991. c.ServeSuccessJSON(map[string]interface{}{
  7992. "order_number": order.Number, //业务流水号
  7993. "id_card_no": his.IdCardNo, //社会保障号
  7994. "patient": patient,
  7995. "department_name": department.Name, //科室
  7996. "number": his.Number, //门诊号
  7997. "date": order.SettleAccountsDate, //结算日期
  7998. "name": order.PsnName, //姓名
  7999. "gender": patient.Gender, //性别
  8000. "psn_cash_money": order.PsnCashPay, //个人支付
  8001. "pay_way": "门诊", //结算方式
  8002. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8003. "admin_user_name": admin.UserName, //收款员
  8004. "order": order,
  8005. "order_info": orderInfos_two,
  8006. "his": his,
  8007. "bedCostTotal": bedCostTotal,
  8008. "bedCostSelfTotal": bedCostSelfTotal,
  8009. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8010. "operationCostTotal": operationCostTotal,
  8011. "operationCostSelfTotal": operationCostSelfTotal,
  8012. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8013. "otherCostTotal": otherCostTotal,
  8014. "otherCostSelfTotal": otherCostSelfTotal,
  8015. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8016. "materialCostTotal": materialCostTotal,
  8017. "materialCostSelfTotal": materialCostSelfTotal,
  8018. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8019. "westernMedicineCostTotal": westernMedicineCostTotal,
  8020. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8021. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8022. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8023. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8024. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8025. "checkCostTotal": checkCostTotal,
  8026. "checkCostSelfTotal": checkCostSelfTotal,
  8027. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8028. "laboratoryCostTotal": laboratoryCostTotal,
  8029. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8030. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8031. "treatCostTotal": treatCostTotal,
  8032. "treatCostSelfTotal": treatCostSelfTotal,
  8033. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8034. "zhenChaCostTotal": zhenChaCostTotal,
  8035. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8036. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8037. "his_hospital_record": his_hospital_record,
  8038. "pre_pay_money": pre_pay_money,
  8039. "refund_sum": sum,
  8040. "doctor_info": doctor_info,
  8041. "hiliCostTotal": hiliCostTotal,
  8042. "hiliCostSelfTotal": hiliCostSelfTotal,
  8043. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8044. })
  8045. }
  8046. //func (c *HisApiController) GetFaPiaoDatas() {
  8047. // order_ids := c.GetString("order_ids")
  8048. // patient_id, _ := c.GetInt64("patient_id")
  8049. // adminUser := c.GetAdminUserInfo()
  8050. //
  8051. // orders := strings.Split(order_ids, ",")
  8052. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8053. //
  8054. // for _, item := range orders {
  8055. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8056. // order, _ := service.GetHisOrderByID(order_id)
  8057. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8058. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8059. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8060. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8061. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8062. //
  8063. // }
  8064. //
  8065. // var bedCostTotal float64 = 0 //床位总费
  8066. // var bedCostSelfTotal float64 = 0 //床位自费
  8067. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8068. //
  8069. // var operationCostTotal float64 = 0 //手术费
  8070. // var operationCostSelfTotal float64 = 0 //手术费
  8071. // var operationCostPartSelfTotal float64 = 0 //手术费
  8072. //
  8073. // var otherCostTotal float64 = 0 //其他费用
  8074. // var otherCostSelfTotal float64 = 0 //其他费用
  8075. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8076. //
  8077. // var materialCostTotal float64 = 0 //材料费
  8078. // var materialCostSelfTotal float64 = 0 //材料费
  8079. // var materialCostPartSelfTotal float64 = 0 //材料费
  8080. //
  8081. // var westernMedicineCostTotal float64 = 0 //西药费
  8082. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8083. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8084. //
  8085. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8086. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8087. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8088. //
  8089. // var checkCostTotal float64 = 0 //检查费
  8090. // var checkCostSelfTotal float64 = 0 //检查费
  8091. // var checkCostPartSelfTotal float64 = 0 //检查费
  8092. //
  8093. // var laboratoryCostTotal float64 = 0 //化验费
  8094. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8095. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8096. //
  8097. // var treatCostTotal float64 = 0 //治疗费用
  8098. // var treatCostSelfTotal float64 = 0 //治疗费用
  8099. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8100. //
  8101. // var zhenChaCostTotal float64 = 0 //其他费用
  8102. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8103. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8104. //
  8105. // decimal.DivisionPrecision = 2
  8106. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8107. //
  8108. // var balanceAccountsType int64
  8109. // if his.ID > 0 {
  8110. // balanceAccountsType = his.BalanceAccountsType
  8111. // } else {
  8112. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8113. // }
  8114. // if balanceAccountsType == 2 {
  8115. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8116. // for _, item := range orderInfos_two {
  8117. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8118. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8119. // item.MedChrgitmType = "09"
  8120. // }
  8121. //
  8122. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8123. // if item.HisPrescriptionProject.Type == 2 {
  8124. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8125. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8126. // case 0:
  8127. // item.MedChrgitmType = "0"
  8128. // break
  8129. // case 1:
  8130. // item.MedChrgitmType = "14"
  8131. // break
  8132. // case 2:
  8133. // item.MedChrgitmType = "05"
  8134. //
  8135. // break
  8136. // case 3:
  8137. // item.MedChrgitmType = "03"
  8138. //
  8139. // break
  8140. // case 4:
  8141. // item.MedChrgitmType = "03"
  8142. //
  8143. // break
  8144. // case 5:
  8145. // item.MedChrgitmType = "08"
  8146. //
  8147. // break
  8148. // case 6:
  8149. // item.MedChrgitmType = "14"
  8150. //
  8151. // break
  8152. // case 7:
  8153. // item.MedChrgitmType = "14"
  8154. //
  8155. // break
  8156. // case 8:
  8157. // item.MedChrgitmType = "03"
  8158. // break
  8159. // case 9:
  8160. // item.MedChrgitmType = "14"
  8161. // break
  8162. // case 10:
  8163. // item.MedChrgitmType = "14"
  8164. // break
  8165. // case 11:
  8166. // item.MedChrgitmType = "06"
  8167. // break
  8168. // case 12:
  8169. // item.MedChrgitmType = "12"
  8170. // break
  8171. // case 13:
  8172. // item.MedChrgitmType = "01"
  8173. // break
  8174. // case 14:
  8175. // item.MedChrgitmType = "04"
  8176. // break
  8177. // case 15:
  8178. // item.MedChrgitmType = "02"
  8179. // break
  8180. //
  8181. // }
  8182. //
  8183. // } else {
  8184. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8185. //
  8186. // case 1:
  8187. // item.MedChrgitmType = "14"
  8188. // break
  8189. // case 2:
  8190. // item.MedChrgitmType = "05"
  8191. //
  8192. // break
  8193. // case 3:
  8194. // item.MedChrgitmType = "03"
  8195. //
  8196. // break
  8197. // case 4:
  8198. // item.MedChrgitmType = "03"
  8199. //
  8200. // break
  8201. // case 5:
  8202. // item.MedChrgitmType = "08"
  8203. //
  8204. // break
  8205. // case 6:
  8206. // item.MedChrgitmType = "14"
  8207. //
  8208. // break
  8209. // case 7:
  8210. // item.MedChrgitmType = "14"
  8211. //
  8212. // break
  8213. // case 8:
  8214. // item.MedChrgitmType = "03"
  8215. // break
  8216. // case 9:
  8217. // item.MedChrgitmType = "14"
  8218. // break
  8219. //
  8220. // }
  8221. //
  8222. // }
  8223. //
  8224. // } else if item.HisPrescriptionProject.Type == 3 {
  8225. // item.MedChrgitmType = "08"
  8226. // }
  8227. // }
  8228. // }
  8229. //
  8230. // for _, item := range orderInfos_two {
  8231. // fmt.Println(item.MedChrgitmType)
  8232. // if item.MedChrgitmType == "01" { //床位费
  8233. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8234. // bedCostSelfTotal = bedCostTotal
  8235. // }
  8236. //
  8237. // if item.MedChrgitmType == "02" { //诊察费
  8238. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8239. // zhenChaCostSelfTotal = zhenChaCostTotal
  8240. // }
  8241. //
  8242. // if item.MedChrgitmType == "03" { //检查费
  8243. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8244. // checkCostSelfTotal = checkCostTotal
  8245. // }
  8246. //
  8247. // if item.MedChrgitmType == "04" { //化验费
  8248. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8249. // laboratoryCostSelfTotal = laboratoryCostTotal
  8250. // }
  8251. //
  8252. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8253. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8254. // treatCostSelfTotal = treatCostTotal
  8255. // }
  8256. //
  8257. // if item.MedChrgitmType == "06" { //手术费
  8258. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8259. // operationCostSelfTotal = treatCostTotal
  8260. // }
  8261. //
  8262. // if item.MedChrgitmType == "08" { //材料费
  8263. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8264. // materialCostSelfTotal = materialCostTotal
  8265. // }
  8266. //
  8267. // if item.MedChrgitmType == "09" { //西药费
  8268. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8269. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8270. // }
  8271. //
  8272. // if item.MedChrgitmType == "11" { //中成费
  8273. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8274. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8275. // }
  8276. //
  8277. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8278. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8279. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8280. // otherCostSelfTotal = otherCostTotal
  8281. // }
  8282. // } else {
  8283. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8284. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8285. // otherCostSelfTotal = otherCostTotal
  8286. // }
  8287. //
  8288. // }
  8289. //
  8290. // }
  8291. //
  8292. // } else {
  8293. // for _, item := range orderInfos {
  8294. // if item.MedChrgitmType == "01" { //床位费
  8295. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8296. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8297. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8298. // }
  8299. //
  8300. // if item.MedChrgitmType == "02" { //诊察费
  8301. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8302. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8303. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8304. // }
  8305. //
  8306. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8307. // if item.MedChrgitmType == "03" { //检查费
  8308. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8309. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8310. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8311. //
  8312. // }
  8313. // } else {
  8314. // if item.MedChrgitmType == "03" { //检查费
  8315. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8316. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8317. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8318. // }
  8319. //
  8320. // }
  8321. //
  8322. // if item.MedChrgitmType == "04" { //化验费
  8323. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8324. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8325. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8326. //
  8327. // }
  8328. //
  8329. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8330. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8331. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8332. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8333. //
  8334. // }
  8335. //
  8336. // if item.MedChrgitmType == "06" { //手术费
  8337. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8338. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8339. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8340. // }
  8341. //
  8342. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8343. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8344. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8345. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8346. // }
  8347. //
  8348. // if item.MedChrgitmType == "09" { //西药费
  8349. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8350. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8351. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8352. // }
  8353. //
  8354. // if item.MedChrgitmType == "11" { //中成费
  8355. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8356. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8357. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8358. // }
  8359. //
  8360. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8361. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8362. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8363. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8364. // }
  8365. //
  8366. // }
  8367. // }
  8368. // timeLayout := "2006-01-02"
  8369. // loc, _ := time.LoadLocation("Local")
  8370. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8371. // if err != nil {
  8372. // }
  8373. // startRecordDateTime := startTime.Unix()
  8374. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8375. // if err != nil {
  8376. // }
  8377. // endRecordDateTime := endTime.Unix()
  8378. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8379. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8380. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8381. //
  8382. // c.ServeSuccessJSON(map[string]interface{}{
  8383. // "order_number": order.Number, //业务流水号
  8384. // "id_card_no": his.IdCardNo, //社会保障号
  8385. // "department_name": department.Name, //科室
  8386. // "number": his.Number, //门诊号
  8387. // "date": order.SettleAccountsDate, //结算日期
  8388. // "name": order.PsnName, //姓名
  8389. // "gender": patient.Gender, //性别
  8390. // "psn_cash_money": order.PsnCashPay, //个人支付
  8391. // "pay_way": "门诊", //结算方式
  8392. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8393. // "admin_user_name": admin.UserName, //收款员
  8394. // "order": order,
  8395. // "order_info": orderInfos_two,
  8396. // "his": his,
  8397. // "bedCostTotal": bedCostTotal,
  8398. // "bedCostSelfTotal": bedCostSelfTotal,
  8399. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8400. // "operationCostTotal": operationCostTotal,
  8401. // "operationCostSelfTotal": operationCostSelfTotal,
  8402. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8403. // "otherCostTotal": otherCostTotal,
  8404. // "otherCostSelfTotal": otherCostSelfTotal,
  8405. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8406. // "materialCostTotal": materialCostTotal,
  8407. // "materialCostSelfTotal": materialCostSelfTotal,
  8408. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8409. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8410. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8411. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8412. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8413. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8414. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8415. // "checkCostTotal": checkCostTotal,
  8416. // "checkCostSelfTotal": checkCostSelfTotal,
  8417. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8418. // "laboratoryCostTotal": laboratoryCostTotal,
  8419. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8420. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8421. // "treatCostTotal": treatCostTotal,
  8422. // "treatCostSelfTotal": treatCostSelfTotal,
  8423. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8424. // "zhenChaCostTotal": zhenChaCostTotal,
  8425. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8426. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8427. // "his_hospital_record": his_hospital_record,
  8428. // "pre_pay_money": pre_pay_money,
  8429. // "refund_sum": sum,
  8430. // })
  8431. //
  8432. //}
  8433. func (this *HisApiController) GetIncomeStatisticsData() {
  8434. start_time := this.GetString("start_time")
  8435. end_time := this.GetString("end_time")
  8436. key_words := this.GetString("key_words")
  8437. limit, _ := this.GetInt64("limit")
  8438. page, _ := this.GetInt64("page")
  8439. if page <= 0 {
  8440. page = 1
  8441. }
  8442. if limit <= 0 {
  8443. limit = 10
  8444. }
  8445. statistics_type, _ := this.GetInt64("statistics_type")
  8446. admin := this.GetAdminUserInfo()
  8447. timeLayout := "2006-01-02"
  8448. loc, _ := time.LoadLocation("Local")
  8449. var theStartTIme int64
  8450. if len(start_time) > 0 {
  8451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8452. if err != nil {
  8453. theStartTIme = 0
  8454. }
  8455. theStartTIme = theTime.Unix()
  8456. }
  8457. var theEndtTIme int64
  8458. if len(end_time) > 0 {
  8459. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8460. if err != nil {
  8461. theEndtTIme = 0
  8462. }
  8463. theEndtTIme = theTime.Unix()
  8464. }
  8465. if statistics_type == 1 {
  8466. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8467. this.ServeSuccessJSON(map[string]interface{}{
  8468. "list": list,
  8469. "total": total,
  8470. })
  8471. } else {
  8472. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8473. this.ServeSuccessJSON(map[string]interface{}{
  8474. "list": list,
  8475. "total": total,
  8476. })
  8477. }
  8478. }
  8479. func (c *HisApiController) PostProjectInformation() {
  8480. adminUser := c.GetAdminUserInfo()
  8481. orgId := adminUser.CurrentOrgId
  8482. dataBody := make(map[string]interface{}, 0)
  8483. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8484. if err != nil {
  8485. utils.ErrorLog(err.Error())
  8486. return
  8487. }
  8488. utils.ErrorLog("%v", dataBody)
  8489. var projectList []*models.HisProject
  8490. var total_goods []interface{}
  8491. tempProjects := dataBody["projects"].([]interface{})
  8492. total_goods = tempProjects
  8493. for index, projectMap := range tempProjects {
  8494. projectM := projectMap.(map[string]interface{})
  8495. var project models.HisProject
  8496. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8497. utils.ErrorLog("project_name")
  8498. return
  8499. }
  8500. project_name, _ := projectM["project_name"].(string)
  8501. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8502. err_log := models.ExportErrLog{
  8503. LogType: 6,
  8504. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8505. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8506. Status: 1,
  8507. CreateTime: time.Now().Unix(),
  8508. UpdateTime: time.Now().Unix(),
  8509. ExportTime: time.Now().Unix(),
  8510. }
  8511. service.CreateExportErrLog(&err_log)
  8512. continue
  8513. }
  8514. project.ProjectName = project_name
  8515. prices := projectM["price"].(string)
  8516. price, _ := strconv.ParseFloat(prices, 64)
  8517. if price <= 0 { //名字为空则生成一条导入错误日志
  8518. err_log := models.ExportErrLog{
  8519. LogType: 6,
  8520. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8521. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8522. Status: 1,
  8523. CreateTime: time.Now().Unix(),
  8524. UpdateTime: time.Now().Unix(),
  8525. ExportTime: time.Now().Unix(),
  8526. }
  8527. service.CreateExportErrLog(&err_log)
  8528. continue
  8529. }
  8530. project.Price = price
  8531. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8532. utils.ErrorLog("unit_id")
  8533. return
  8534. }
  8535. unit := projectM["unit"].(string)
  8536. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8537. err_log := models.ExportErrLog{
  8538. LogType: 6,
  8539. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8540. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8541. Status: 1,
  8542. CreateTime: time.Now().Unix(),
  8543. UpdateTime: time.Now().Unix(),
  8544. ExportTime: time.Now().Unix(),
  8545. }
  8546. service.CreateExportErrLog(&err_log)
  8547. continue
  8548. }
  8549. project.Unit = unit
  8550. cost_classify := projectM["cost_classify"].(string)
  8551. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8552. err_log := models.ExportErrLog{
  8553. LogType: 6,
  8554. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8555. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8556. Status: 1,
  8557. CreateTime: time.Now().Unix(),
  8558. UpdateTime: time.Now().Unix(),
  8559. ExportTime: time.Now().Unix(),
  8560. }
  8561. service.CreateExportErrLog(&err_log)
  8562. continue
  8563. }
  8564. var costClassify = "费用类别"
  8565. var cost_classify_id int64
  8566. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8567. if len(cost_classify) != 0 {
  8568. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8569. if errcode == gorm.ErrRecordNotFound {
  8570. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8571. dataconfig := models.DictDataconfig{
  8572. ParentId: costClassifyConfig.ID,
  8573. Module: "system",
  8574. OrgId: orgId,
  8575. Name: cost_classify,
  8576. FieldName: "",
  8577. Value: costConfig.Value + 1,
  8578. CreatedTime: "",
  8579. UpdatedTime: "",
  8580. CreateUserId: adminUser.AdminUser.Id,
  8581. Status: 1,
  8582. Remark: "",
  8583. DeleteIdSystem: 0,
  8584. Title: "",
  8585. Content: "",
  8586. Order: 0,
  8587. Code: "",
  8588. }
  8589. service.CreatedDicConfig(&dataconfig)
  8590. }
  8591. }
  8592. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8593. for _, it := range costClassList {
  8594. if cost_classify == it.Name {
  8595. cost_classify_id = int64(it.Value)
  8596. }
  8597. }
  8598. project.CostClassify = cost_classify_id
  8599. executive_section := projectM["executive_section"].(string)
  8600. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8601. err_log := models.ExportErrLog{
  8602. LogType: 6,
  8603. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8604. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8605. Status: 1,
  8606. CreateTime: time.Now().Unix(),
  8607. UpdateTime: time.Now().Unix(),
  8608. ExportTime: time.Now().Unix(),
  8609. }
  8610. service.CreateExportErrLog(&err_log)
  8611. continue
  8612. }
  8613. if len(executive_section) != 0 {
  8614. //查找科室是否有内容
  8615. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8616. if errcodedepart == gorm.ErrRecordNotFound {
  8617. department := models.XtHisDepartment{
  8618. Name: executive_section,
  8619. Status: 1,
  8620. UserOrgId: adminUser.CurrentOrgId,
  8621. CreatedTime: time.Now().Unix(),
  8622. }
  8623. service.CreateDePartment(&department)
  8624. }
  8625. }
  8626. var executive_section_id int64
  8627. departMentList, _ := service.GetAllDepartMent(orgId)
  8628. for _, it := range departMentList {
  8629. if executive_section == it.Name {
  8630. executive_section_id = it.ID
  8631. }
  8632. }
  8633. project.ExecutiveSection = executive_section_id
  8634. medical_coverage := projectM["medical_coverage"].(string)
  8635. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8636. err_log := models.ExportErrLog{
  8637. LogType: 6,
  8638. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8639. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8640. Status: 1,
  8641. CreateTime: time.Now().Unix(),
  8642. UpdateTime: time.Now().Unix(),
  8643. ExportTime: time.Now().Unix(),
  8644. }
  8645. service.CreateExportErrLog(&err_log)
  8646. continue
  8647. }
  8648. var medicalCoverage = "医保等级"
  8649. var medical_coverage_id int64
  8650. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8651. if len(medical_coverage) != 0 {
  8652. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8653. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8654. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8655. dataconfig := models.DictDataconfig{
  8656. ParentId: medicalCoverageConfig.ID,
  8657. Module: "system",
  8658. OrgId: orgId,
  8659. Name: medical_coverage,
  8660. FieldName: "",
  8661. Value: medicalCoverageConfig.Value + 1,
  8662. CreatedTime: "",
  8663. UpdatedTime: "",
  8664. CreateUserId: adminUser.AdminUser.Id,
  8665. Status: 1,
  8666. Remark: "",
  8667. DeleteIdSystem: 0,
  8668. Title: "",
  8669. Content: "",
  8670. Order: 0,
  8671. Code: "",
  8672. }
  8673. service.CreatedDicConfig(&dataconfig)
  8674. }
  8675. }
  8676. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8677. for _, it := range medicalCoverageList {
  8678. if medical_coverage == it.Name {
  8679. medical_coverage_id = int64(it.Value)
  8680. }
  8681. }
  8682. project.MedicalCoverage = medical_coverage_id
  8683. pinyin := projectM["pinyin"].(string)
  8684. project.Pinyin = pinyin
  8685. wubi := projectM["wubi"].(string)
  8686. project.Wubi = wubi
  8687. statistical_classification := projectM["statistical_classification"].(string)
  8688. var statisticalClassification = "统计分类"
  8689. var statistical_classification_id int64
  8690. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8691. if len(statistical_classification) != 0 {
  8692. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8693. if classificationerrcodes == gorm.ErrRecordNotFound {
  8694. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8695. dataconfig := models.DictDataconfig{
  8696. ParentId: classiFication.ID,
  8697. Module: "system",
  8698. OrgId: orgId,
  8699. Name: statistical_classification,
  8700. FieldName: "",
  8701. Value: classiFicationConfig.Value + 1,
  8702. CreatedTime: "",
  8703. UpdatedTime: "",
  8704. CreateUserId: adminUser.AdminUser.Id,
  8705. Status: 1,
  8706. Remark: "",
  8707. DeleteIdSystem: 0,
  8708. Title: "",
  8709. Content: "",
  8710. Order: 0,
  8711. Code: "",
  8712. }
  8713. service.CreatedDicConfig(&dataconfig)
  8714. }
  8715. }
  8716. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8717. for _, it := range classiFicationList {
  8718. if statistical_classification == it.Name {
  8719. statistical_classification_id = int64(it.Value)
  8720. }
  8721. }
  8722. project.StatisticalClassification = statistical_classification_id
  8723. disease_directory := int64(projectM["disease_directory"].(float64))
  8724. project.DiseaseDirectory = disease_directory
  8725. is_record := int64(projectM["is_record"].(float64))
  8726. project.IsRecord = is_record
  8727. medical_code := projectM["medical_code"].(string)
  8728. project.MedicalCode = medical_code
  8729. tube_color := projectM["tube_color"].(string)
  8730. var tubeColor = "试管颜色"
  8731. var tube_color_id int64
  8732. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8733. if len(tube_color) != 0 {
  8734. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8735. if errcodetube == gorm.ErrRecordNotFound {
  8736. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8737. dataconfig := models.DictDataconfig{
  8738. ParentId: tubeColorConfig.ID,
  8739. Module: "system",
  8740. OrgId: orgId,
  8741. Name: tube_color,
  8742. FieldName: "",
  8743. Value: tubeConfig.Value + 1,
  8744. CreatedTime: "",
  8745. UpdatedTime: "",
  8746. CreateUserId: adminUser.AdminUser.Id,
  8747. Status: 1,
  8748. Remark: "",
  8749. DeleteIdSystem: 0,
  8750. Title: "",
  8751. Content: "",
  8752. Order: 0,
  8753. Code: "",
  8754. }
  8755. service.CreatedDicConfig(&dataconfig)
  8756. }
  8757. }
  8758. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8759. for _, it := range tubeColorList {
  8760. if tube_color == it.Name {
  8761. tube_color_id = int64(it.Value)
  8762. }
  8763. }
  8764. project.TubeColor = tube_color_id
  8765. single_dose := projectM["single_dose"].(string)
  8766. project.SingleDose = single_dose
  8767. execution_frequency := projectM["execution_frequency"].(string)
  8768. project.ExecutionFrequency = execution_frequency
  8769. delivery_way := projectM["delivery_way"].(string)
  8770. project.DeliveryWay = delivery_way
  8771. number_days := projectM["number_days"].(string)
  8772. project.NumberDays = number_days
  8773. total := projectM["total"].(string)
  8774. project.Total = total
  8775. medical_status := int64(projectM["medical_status"].(float64))
  8776. project.MedicalStatus = medical_status
  8777. category := int64(projectM["category"].(float64))
  8778. project.Category = category
  8779. specail_project := int64(projectM["specail_project"].(float64))
  8780. project.SpecailProject = specail_project
  8781. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8782. project.SocialSecurityDirectoryCode = social_security_directory_code
  8783. remark := projectM["remark"].(string)
  8784. project.Remark = remark
  8785. record_date := projectM["record_date"].(string)
  8786. timeLayout := "2006-01-02"
  8787. loc, _ := time.LoadLocation("Local")
  8788. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8789. project.RecordDate = theTime.Unix()
  8790. projectList = append(projectList, &project)
  8791. }
  8792. export_time := time.Now().Unix()
  8793. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8794. if len(projectList) > 0 {
  8795. for _, item := range projectList {
  8796. project := models.HisProject{
  8797. ProjectName: item.ProjectName,
  8798. Price: item.Price,
  8799. Unit: item.Unit,
  8800. CostClassify: item.CostClassify,
  8801. ExecutiveSection: item.ExecutiveSection,
  8802. MedicalCoverage: item.MedicalCoverage,
  8803. UserOrgId: orgId,
  8804. Status: 1,
  8805. CreatedTime: time.Now().Unix(),
  8806. Pinyin: item.Pinyin,
  8807. Wubi: item.Wubi,
  8808. StatisticalClassification: item.StatisticalClassification,
  8809. DiseaseDirectory: item.DiseaseDirectory,
  8810. IsRecord: item.IsRecord,
  8811. MedicalCode: item.MedicalCode,
  8812. TubeColor: item.TubeColor,
  8813. SingleDose: item.SingleDose,
  8814. DeliveryWay: item.DeliveryWay,
  8815. NumberDays: item.NumberDays,
  8816. Total: item.Total,
  8817. Category: item.Category,
  8818. MedicalStatus: item.MedicalStatus,
  8819. SpecailProject: item.SpecailProject,
  8820. RecordDate: item.RecordDate,
  8821. Remark: item.Remark,
  8822. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8823. ExecutionFrequency: item.ExecutionFrequency,
  8824. }
  8825. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8826. if errcodeproject == gorm.ErrRecordNotFound {
  8827. service.CreateProjectInfomation(&project)
  8828. } else if errcodeproject == nil {
  8829. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8830. }
  8831. log := models.ExportLog{
  8832. LogType: 6,
  8833. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8834. TotalNum: int64(len(total_goods)),
  8835. FailNum: int64(len(errLogs)),
  8836. SuccessNum: int64(len(projectList)),
  8837. CreateTime: time.Now().Unix(),
  8838. UpdateTime: time.Now().Unix(),
  8839. ExportTime: export_time,
  8840. Status: 1,
  8841. }
  8842. service.CreateExportLog(&log)
  8843. c.ServeSuccessJSON(map[string]interface{}{
  8844. "msg": "导入成功",
  8845. "total_num": len(total_goods),
  8846. "success_num": len(projectList),
  8847. "fail_num": int64(len(errLogs)),
  8848. })
  8849. }
  8850. } else {
  8851. log := models.ExportLog{
  8852. LogType: 6,
  8853. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8854. TotalNum: int64(len(total_goods)),
  8855. FailNum: int64(len(errLogs)),
  8856. SuccessNum: int64(len(projectList)),
  8857. CreateTime: time.Now().Unix(),
  8858. UpdateTime: time.Now().Unix(),
  8859. ExportTime: export_time,
  8860. Status: 1,
  8861. }
  8862. service.CreateExportLog(&log)
  8863. c.ServeSuccessJSON(map[string]interface{}{
  8864. "msg": "导入成功",
  8865. "total_num": len(total_goods),
  8866. "success_num": len(projectList),
  8867. "fail_num": int64(len(errLogs)),
  8868. })
  8869. }
  8870. }
  8871. //func (this *HisApiController) EditProjectInformation(){
  8872. //
  8873. // id, _ := this.GetInt64("id")
  8874. // project_team := this.GetString("project_team")
  8875. // price := this.GetString("price")
  8876. // price_float, _ := strconv.ParseFloat(price, 64)
  8877. // pinyin := this.GetString("pinyin")
  8878. // wubi := this.GetString("wubi")
  8879. // tube_color, _ := this.GetInt64("tube_color")
  8880. // team_type, _ := this.GetInt64("team_type")
  8881. // remark := this.GetString("remark")
  8882. // ids := this.GetString("ids")
  8883. // item_id := this.GetString("item_id")
  8884. // projectTeam := models.XtHisProjectTeam{
  8885. // ProjectTeam: project_team,
  8886. // Price: price_float,
  8887. // Pinyin: pinyin,
  8888. // Wubi: wubi,
  8889. // TubeColor: tube_color,
  8890. // TeamType: team_type,
  8891. // Remark: remark,
  8892. // ProjectId: ids,
  8893. // ItemId: item_id,
  8894. // }
  8895. //
  8896. //
  8897. // dataBody := make(map[string]interface{}, 0)
  8898. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8899. // if err != nil {
  8900. // utils.ErrorLog(err.Error())
  8901. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8902. // return
  8903. // }
  8904. //
  8905. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8906. //
  8907. //
  8908. // if err != nil {
  8909. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8910. // return
  8911. // }
  8912. //
  8913. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8914. // infos, _ := dataBody["info"].([]interface{})
  8915. // if len(infos) > 0 {
  8916. // var ids []string
  8917. //
  8918. // for _, item := range infos {
  8919. // items := item.(map[string]interface{})
  8920. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8921. // utils.ErrorLog("id")
  8922. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8923. // return
  8924. // }
  8925. // id := int64(items["id"].(float64))
  8926. //
  8927. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8928. // utils.ErrorLog("type")
  8929. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8930. // return
  8931. // }
  8932. // types := int64(items["type"].(float64))
  8933. //
  8934. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8935. // utils.ErrorLog("number")
  8936. // }
  8937. //
  8938. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8939. //
  8940. // projectList := models.XtHisProjectList{
  8941. // Number: number,
  8942. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8943. // ProjectId: id,
  8944. // Status: 1,
  8945. // CreatedTime: time.Now().Unix(),
  8946. // UpdatedTime: time.Now().Unix(),
  8947. // TeamId: projectTeam.ID,
  8948. // Type: types,
  8949. // }
  8950. // list := projectList
  8951. //
  8952. // service.CreateProjectList(&list)
  8953. //
  8954. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8955. //
  8956. // }
  8957. // ids_str := strings.Join(ids, ",")
  8958. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8959. // service.SaveProjectTeam(&projectTeam)
  8960. // this.ServeSuccessJSON(map[string]interface{}{
  8961. // "projectTeam": projectTeam,
  8962. // })
  8963. // }
  8964. // }
  8965. //}
  8966. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8967. name := c.GetString("name")
  8968. mode_id, _ := c.GetInt64("mode", 0)
  8969. types, _ := c.GetInt64("type", 0)
  8970. patient_id, _ := c.GetInt64("patient_id", 0)
  8971. types = 1
  8972. adminInfo := c.GetAdminUserInfo()
  8973. template := &models.HisPrescriptionTemplate{
  8974. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8975. PatientId: patient_id,
  8976. Type: types,
  8977. Status: 1,
  8978. Ctime: time.Now().Unix(),
  8979. Mtime: time.Now().Unix(),
  8980. Name: name,
  8981. Mode: mode_id,
  8982. }
  8983. dataBody := make(map[string]interface{}, 0)
  8984. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8985. if err != nil {
  8986. utils.ErrorLog(err.Error())
  8987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8988. return
  8989. }
  8990. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8991. //如果已经存在记录则删除处方
  8992. if template_one.ID > 0 {
  8993. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8994. for _, item := range ps {
  8995. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8996. }
  8997. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8998. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8999. if len(prescriptions) > 0 {
  9000. for _, item := range prescriptions {
  9001. items := item.(map[string]interface{})
  9002. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9003. utils.ErrorLog("type")
  9004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9005. return
  9006. }
  9007. types := int64(items["type"].(float64))
  9008. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9009. utils.ErrorLog("med_type")
  9010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9011. return
  9012. }
  9013. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9014. ctime := time.Now().Unix()
  9015. prescription := &models.HisPrescriptionInfoTemplate{
  9016. PatientId: patient_id,
  9017. UserOrgId: adminInfo.CurrentOrgId,
  9018. Ctime: ctime,
  9019. Mtime: ctime,
  9020. Type: types,
  9021. Modifier: adminInfo.AdminUser.Id,
  9022. Creator: adminInfo.AdminUser.Id,
  9023. Status: 1,
  9024. PTemplateId: template_one.ID,
  9025. MedType: med_type,
  9026. }
  9027. service.CreateHisPrescriptionInfoTemplate(prescription)
  9028. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9029. advices := items["advices"].([]interface{})
  9030. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9031. ctime := time.Now().Unix()
  9032. mtime := ctime
  9033. if len(advices) > 0 {
  9034. for _, advice := range advices {
  9035. var s models.HisPrescriptionAdviceTemplate
  9036. s.PrescriptionId = prescription.ID
  9037. s.AdviceType = 2
  9038. s.StopState = 2
  9039. s.ExecutionState = 2
  9040. s.Status = 1
  9041. s.UserOrgId = adminInfo.CurrentOrgId
  9042. s.CreatedTime = ctime
  9043. s.UpdatedTime = mtime
  9044. s.PatientId = patient_id
  9045. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9046. if errcode > 0 {
  9047. c.ServeFailJSONWithSGJErrorCode(errcode)
  9048. return
  9049. }
  9050. service.CreateHisPrescriptionAdviceTemplate(&s)
  9051. }
  9052. }
  9053. }
  9054. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9055. projects := items["project"].([]interface{})
  9056. if len(projects) > 0 {
  9057. for _, project := range projects {
  9058. var p models.HisPrescriptionProjectTemplate
  9059. p.PrescriptionId = prescription.ID
  9060. p.Ctime = time.Now().Unix()
  9061. p.Mtime = time.Now().Unix()
  9062. p.PatientId = patient_id
  9063. p.UserOrgId = adminInfo.CurrentOrgId
  9064. p.Status = 1
  9065. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9066. if errcode > 0 {
  9067. c.ServeFailJSONWithSGJErrorCode(errcode)
  9068. return
  9069. }
  9070. service.CreateHisPrescriptionProjectTemplate(&p)
  9071. }
  9072. }
  9073. }
  9074. }
  9075. c.ServeSuccessJSON(map[string]interface{}{
  9076. "msg": "创建成功",
  9077. })
  9078. }
  9079. }
  9080. } else {
  9081. err = service.CreateHisPrescriptionTemplate(template)
  9082. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9083. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9084. if len(prescriptions) > 0 {
  9085. for _, item := range prescriptions {
  9086. items := item.(map[string]interface{})
  9087. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9088. utils.ErrorLog("type")
  9089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9090. return
  9091. }
  9092. types := int64(items["type"].(float64))
  9093. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9094. utils.ErrorLog("med_type")
  9095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9096. return
  9097. }
  9098. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9099. ctime := time.Now().Unix()
  9100. prescription := &models.HisPrescriptionInfoTemplate{
  9101. PatientId: patient_id,
  9102. UserOrgId: adminInfo.CurrentOrgId,
  9103. Ctime: ctime,
  9104. Mtime: ctime,
  9105. Type: types,
  9106. Modifier: adminInfo.AdminUser.Id,
  9107. Creator: adminInfo.AdminUser.Id,
  9108. Status: 1,
  9109. PTemplateId: template.ID,
  9110. MedType: med_type,
  9111. }
  9112. service.CreateHisPrescriptionInfoTemplate(prescription)
  9113. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9114. advices := items["advices"].([]interface{})
  9115. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9116. ctime := time.Now().Unix()
  9117. mtime := ctime
  9118. if len(advices) > 0 {
  9119. for _, advice := range advices {
  9120. var s models.HisPrescriptionAdviceTemplate
  9121. s.PrescriptionId = prescription.ID
  9122. s.AdviceType = 2
  9123. s.StopState = 2
  9124. s.ExecutionState = 2
  9125. s.Status = 1
  9126. s.UserOrgId = adminInfo.CurrentOrgId
  9127. s.CreatedTime = ctime
  9128. s.UpdatedTime = mtime
  9129. s.PatientId = patient_id
  9130. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9131. if errcode > 0 {
  9132. c.ServeFailJSONWithSGJErrorCode(errcode)
  9133. return
  9134. }
  9135. service.CreateHisPrescriptionAdviceTemplate(&s)
  9136. }
  9137. }
  9138. }
  9139. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9140. projects := items["project"].([]interface{})
  9141. if len(projects) > 0 {
  9142. for _, project := range projects {
  9143. var p models.HisPrescriptionProjectTemplate
  9144. p.PrescriptionId = prescription.ID
  9145. p.Ctime = time.Now().Unix()
  9146. p.Mtime = time.Now().Unix()
  9147. p.PatientId = patient_id
  9148. p.UserOrgId = adminInfo.CurrentOrgId
  9149. p.Status = 1
  9150. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9151. if errcode > 0 {
  9152. c.ServeFailJSONWithSGJErrorCode(errcode)
  9153. return
  9154. }
  9155. service.CreateHisPrescriptionProjectTemplate(&p)
  9156. }
  9157. }
  9158. }
  9159. }
  9160. c.ServeSuccessJSON(map[string]interface{}{
  9161. "msg": "创建成功",
  9162. })
  9163. }
  9164. }
  9165. }
  9166. }
  9167. func (c *HisApiController) PreSettle() {
  9168. id, _ := c.GetInt64("id")
  9169. record_time := c.GetString("record_time")
  9170. his_patient_id, _ := c.GetInt64("his_patient_id")
  9171. timeLayout := "2006-01-02"
  9172. loc, _ := time.LoadLocation("Local")
  9173. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9174. diagnosis_id := c.GetString("diagnosis")
  9175. sick_type, _ := c.GetInt64("sick_type")
  9176. reg_type, _ := c.GetInt64("p_type")
  9177. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9178. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9179. if err != nil {
  9180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9181. return
  9182. }
  9183. recordDateTime := theTime.Unix()
  9184. adminUser := c.GetAdminUserInfo()
  9185. var prescriptions []*models.HisPrescription
  9186. var start_time int64
  9187. var end_time int64
  9188. ids_str := c.GetString("ids")
  9189. ids_arr := strings.Split(ids_str, ",")
  9190. fmt.Println(reg_type)
  9191. if settle_accounts_type == 1 { //日结
  9192. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9193. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9194. } else {
  9195. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9196. }
  9197. fmt.Println(prescriptions)
  9198. } else { //月结
  9199. start_time_str := c.GetString("start_time")
  9200. end_time_str := c.GetString("end_time")
  9201. timeLayout := "2006-01-02"
  9202. loc, _ := time.LoadLocation("Local")
  9203. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9204. if err != nil {
  9205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9206. return
  9207. }
  9208. recordStartTime := theStartTime.Unix()
  9209. start_time = recordStartTime
  9210. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9211. if err != nil {
  9212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9213. return
  9214. }
  9215. recordEndTime := theEndTime.Unix()
  9216. end_time = recordEndTime
  9217. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9218. }
  9219. if reg_type == 1111 || reg_type == 1112 {
  9220. reg_type = 11
  9221. }
  9222. timestamp := time.Now().Unix()
  9223. tempTime := time.Unix(timestamp, 0)
  9224. timeFormat := tempTime.Format("20060102150405")
  9225. chrgBchno := rand.Intn(100000) + 10000
  9226. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9227. strconv.FormatInt(his.PatientId, 10)
  9228. var ids []int64
  9229. for _, item := range prescriptions {
  9230. ids = append(ids, item.ID)
  9231. }
  9232. fmt.Println(ids)
  9233. var total float64
  9234. for _, item := range prescriptions {
  9235. fmt.Println(item)
  9236. if item.Type == 1 { //药品
  9237. for _, subItem := range item.HisDoctorAdviceInfo {
  9238. total = total + (subItem.Price * subItem.PrescribingNumber)
  9239. }
  9240. }
  9241. if item.Type == 2 { //项目
  9242. for _, subItem := range item.HisPrescriptionProject {
  9243. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9244. total = total + (subItem.Price * cnt)
  9245. }
  9246. }
  9247. for _, subItem := range item.HisAdditionalCharge {
  9248. total = total + (subItem.Price * float64(subItem.Count))
  9249. }
  9250. }
  9251. allTotal := fmt.Sprintf("%.2f", total)
  9252. totals, _ := strconv.ParseFloat(allTotal, 64)
  9253. order := &models.HisOrder{
  9254. UserOrgId: adminUser.CurrentOrgId,
  9255. HisPatientId: his.ID,
  9256. PatientId: id,
  9257. SettleAccountsDate: recordDateTime,
  9258. Ctime: time.Now().Unix(),
  9259. Mtime: time.Now().Unix(),
  9260. Status: 1,
  9261. OrderStatus: 1,
  9262. MdtrtId: his.Number,
  9263. Number: chrg_bchno,
  9264. MedfeeSumamt: totals,
  9265. SettleEndTime: end_time,
  9266. SettleStartTime: start_time,
  9267. SettleType: settle_accounts_type,
  9268. PsnPartAmt: totals,
  9269. PsnCashPay: totals,
  9270. PType: 2,
  9271. IsPre: 1,
  9272. MedType: strconv.Itoa(int(reg_type)),
  9273. Diagnosis: diagnosis_id,
  9274. }
  9275. err = service.CreateOrder(order)
  9276. if err != nil {
  9277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9278. return
  9279. }
  9280. var customs []*Custom
  9281. for _, item := range prescriptions {
  9282. fmt.Println(item.Type)
  9283. if item.Type == 1 { //药品
  9284. for _, subItem := range item.HisDoctorAdviceInfo {
  9285. cus := &Custom{
  9286. AdviceId: subItem.ID,
  9287. ProjectId: 0,
  9288. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9289. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9290. FeedetlSn: subItem.FeedetlSn,
  9291. Price: fmt.Sprintf("%.2f", subItem.Price),
  9292. MedListCodg: subItem.MedListCodg,
  9293. Type: 1,
  9294. }
  9295. customs = append(customs, cus)
  9296. }
  9297. }
  9298. if item.Type == 2 { //项目
  9299. for _, subItem := range item.HisPrescriptionProject {
  9300. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9301. cus := &Custom{
  9302. AdviceId: 0,
  9303. ProjectId: subItem.ID,
  9304. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9305. Cut: fmt.Sprintf("%.2f", cnt),
  9306. FeedetlSn: subItem.FeedetlSn,
  9307. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9308. MedListCodg: subItem.MedListCodg,
  9309. Type: 2,
  9310. }
  9311. customs = append(customs, cus)
  9312. }
  9313. }
  9314. for _, item := range item.HisAdditionalCharge {
  9315. cus := &Custom{
  9316. ItemId: item.ID,
  9317. AdviceId: 0,
  9318. ProjectId: 0,
  9319. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9320. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9321. FeedetlSn: item.FeedetlSn,
  9322. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9323. MedListCodg: item.XtHisAddtionConfig.Code,
  9324. Type: 3,
  9325. }
  9326. customs = append(customs, cus)
  9327. }
  9328. }
  9329. fmt.Println(customs)
  9330. for _, item := range customs {
  9331. var advice_id int64 = 0
  9332. var project_id int64 = 0
  9333. var item_id int64 = 0
  9334. var types int64 = 0
  9335. if item.Type == 1 {
  9336. advice_id = item.AdviceId
  9337. project_id = 0
  9338. item_id = 0
  9339. } else if item.Type == 2 {
  9340. advice_id = 0
  9341. item_id = 0
  9342. project_id = item.ProjectId
  9343. } else if item.Type == 3 {
  9344. advice_id = 0
  9345. item_id = item.ItemId
  9346. project_id = 0
  9347. }
  9348. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9349. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9350. pric, _ := strconv.ParseFloat(item.Price, 32)
  9351. info := &models.HisOrderInfo{
  9352. OrderNumber: order.Number,
  9353. UploadDate: time.Now().Unix(),
  9354. AdviceId: advice_id,
  9355. DetItemFeeSumamt: detItemFeeSumamt,
  9356. Cnt: cut,
  9357. Pric: pric,
  9358. PatientId: id,
  9359. Status: 1,
  9360. Mtime: time.Now().Unix(),
  9361. Ctime: time.Now().Unix(),
  9362. UserOrgId: adminUser.CurrentOrgId,
  9363. HisPatientId: his.ID,
  9364. OrderId: order.ID,
  9365. ProjectId: project_id,
  9366. Type: types,
  9367. ItemId: item_id,
  9368. }
  9369. service.CreateOrderInfo(info)
  9370. }
  9371. his.SickType = sick_type
  9372. service.UpdataHisPateint(&his)
  9373. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9374. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9375. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9376. if err == nil {
  9377. c.ServeSuccessJSON(map[string]interface{}{
  9378. "msg": "结算成功",
  9379. })
  9380. }
  9381. }
  9382. type CustomOrderInfo struct {
  9383. Name string
  9384. Spec string
  9385. Unit string
  9386. Count float64
  9387. Price float64
  9388. Total float64
  9389. }
  9390. func (c *HisApiController) GetPrivateExpensesInfo() {
  9391. order_id, _ := c.GetInt64("id", 0)
  9392. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9393. order, _ := service.GetHisOrderByID(order_id)
  9394. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9395. if order.ID == 0 {
  9396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9397. return
  9398. }
  9399. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9400. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9401. org_id := c.GetAdminUserInfo().CurrentOrgId
  9402. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9403. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9404. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9405. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9406. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9407. //var orderInfos_four []*models.HisOrderInfoTwo
  9408. //for _, item := range orderInfos_three {
  9409. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9410. // item.HisPrescriptionProject.IsCheckTeam = 1
  9411. // orderInfos_four = append(orderInfos_four, item)
  9412. //
  9413. // }
  9414. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9415. // item.HisPrescriptionProject.IsCheckTeam = 2
  9416. // orderInfos_two = append(orderInfos_two, item)
  9417. // }
  9418. //}
  9419. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9420. //var cus_slice []CustomOrderInfo
  9421. //for _, item := range new_order_info {
  9422. // var cus CustomOrderInfo
  9423. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9424. // cus.Unit = ""
  9425. // cus.Spec = ""
  9426. // var total float64
  9427. // for _, subItem := range orderInfos_four {
  9428. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9429. // total = total + subItem.DetItemFeeSumamt
  9430. // fmt.Println(subItem.DetItemFeeSumamt)
  9431. // }
  9432. // }
  9433. // cus.Count = 1
  9434. // cus.Total = total
  9435. // cus_slice = append(cus_slice, cus)
  9436. //}
  9437. orderInfos = append(orderInfos, orderInfos_two...)
  9438. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9439. //orderInfos = append(orderInfos, orderInfos_three...)
  9440. //}/**/
  9441. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9442. c.ServeSuccessJSON(map[string]interface{}{
  9443. "order": order,
  9444. "order_info": orderInfos,
  9445. "patient": patient,
  9446. "admin_info": adminInfo,
  9447. "his": his,
  9448. "current_admin": role,
  9449. "org_config": miConfig,
  9450. //"new_order_info": cus_slice,
  9451. })
  9452. }
  9453. func (this *HisApiController) ChangeMedType() {
  9454. med_type := this.GetString("med_type")
  9455. old_med_type := this.GetString("old_med_type")
  9456. ids := this.GetString("ids")
  9457. settle_type, _ := this.GetInt64("settle_type")
  9458. start_time := this.GetString("start_time")
  9459. end_time := this.GetString("end_time")
  9460. ids_arr := strings.Split(ids, ",")
  9461. if settle_type == 1 { //日结
  9462. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9463. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9464. prescription.MedType = med_type
  9465. err := service.SaveHisPrescription(&prescription)
  9466. if err == nil {
  9467. this.ServeSuccessJSON(map[string]interface{}{
  9468. "msg": "修改成功",
  9469. })
  9470. } else {
  9471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9472. return
  9473. }
  9474. } else if settle_type == 2 {
  9475. timeLayout := "2006-01-02"
  9476. loc, _ := time.LoadLocation("Local")
  9477. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9478. if err != nil {
  9479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9480. return
  9481. }
  9482. recordStartTime := theStartTime.Unix()
  9483. start_time_timestamp := recordStartTime
  9484. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9485. if err != nil {
  9486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9487. return
  9488. }
  9489. recordEndTime := theEndTime.Unix()
  9490. end_time_timestamp := recordEndTime
  9491. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9492. if updateErr == nil {
  9493. this.ServeSuccessJSON(map[string]interface{}{
  9494. "msg": "修改成功",
  9495. })
  9496. } else {
  9497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9498. return
  9499. }
  9500. }
  9501. }
  9502. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9503. patient_id, _ := c.GetInt64("patient_id")
  9504. his_patient_id, _ := c.GetInt64("his_patient_id")
  9505. record_date := c.GetString("record_date")
  9506. start_time := c.GetString("start_time")
  9507. end_time := c.GetString("end_time")
  9508. order_status, _ := c.GetInt64("type", 0)
  9509. p_type, _ := c.GetInt64("p_type", 0)
  9510. order_id, _ := c.GetInt64("order_id", 0)
  9511. timeLayout := "2006-01-02"
  9512. loc, _ := time.LoadLocation("Local")
  9513. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9514. if err != nil {
  9515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9516. return
  9517. }
  9518. recordDateTime := theTime.Unix()
  9519. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9520. if err != nil {
  9521. }
  9522. startRecordDateTime := startTime.Unix()
  9523. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9524. if err != nil {
  9525. }
  9526. endRecordDateTime := endTime.Unix()
  9527. admin := c.GetAdminUserInfo()
  9528. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9529. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9530. order, _ := service.GetHisOrderByID(order_id)
  9531. var monthPrescriptions []*models.HisPrescription
  9532. if order_status == 1 || order_status == 0 {
  9533. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9534. } else if order_status == 2 {
  9535. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9536. }
  9537. var settle_total float64
  9538. for _, item := range monthPrescriptions {
  9539. if len(item.HisPrescriptionProject) > 0 {
  9540. for _, subItem := range item.HisPrescriptionProject {
  9541. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9542. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9543. settle_total = settle_total + total
  9544. }
  9545. }
  9546. if len(item.HisDoctorAdviceInfo) > 0 {
  9547. for _, subItem := range item.HisDoctorAdviceInfo {
  9548. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9549. settle_total = settle_total + total
  9550. }
  9551. }
  9552. }
  9553. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9554. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9555. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9556. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9557. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9558. //获取所有科室信息
  9559. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9560. c.ServeSuccessJSON(map[string]interface{}{
  9561. "his_info": his_patient_info,
  9562. "xt_info": xt_patient_info,
  9563. "case_history": case_history,
  9564. "info": patientPrescriptionInfo,
  9565. "last_info": lastPatientPrescriptionInfo,
  9566. "month_prescriptions": monthPrescriptions,
  9567. "order": order,
  9568. "doctors": doctors,
  9569. "department": department,
  9570. "settle_total": settle_total,
  9571. })
  9572. return
  9573. }
  9574. func (c *HisApiController) GetHisMonthPatientInfo() {
  9575. patient_id, _ := c.GetInt64("patient_id")
  9576. his_patient_id, _ := c.GetInt64("his_patient_id")
  9577. record_date := c.GetString("record_date")
  9578. number := c.GetString("number")
  9579. start_time := c.GetString("start_time")
  9580. end_time := c.GetString("end_time")
  9581. p_type, _ := c.GetInt64("p_type")
  9582. timeLayout := "2006-01-02"
  9583. loc, _ := time.LoadLocation("Local")
  9584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9585. if err != nil {
  9586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9587. return
  9588. }
  9589. recordDateTime := theTime.Unix()
  9590. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9591. if err != nil {
  9592. }
  9593. startRecordDateTime := startTime.Unix()
  9594. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9595. if err != nil {
  9596. }
  9597. endRecordDateTime := endTime.Unix()
  9598. admin := c.GetAdminUserInfo()
  9599. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9600. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9601. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9602. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9603. var settle_total float64
  9604. for _, item := range monthPrescriptions {
  9605. if len(item.HisPrescriptionProject) > 0 {
  9606. for _, subItem := range item.HisPrescriptionProject {
  9607. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9608. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9609. settle_total = settle_total + total
  9610. }
  9611. }
  9612. if len(item.HisDoctorAdviceInfo) > 0 {
  9613. for _, subItem := range item.HisDoctorAdviceInfo {
  9614. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9615. settle_total = settle_total + total
  9616. }
  9617. }
  9618. }
  9619. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9620. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9621. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9622. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9623. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9624. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9625. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9626. //获取所有科室信息
  9627. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9628. c.ServeSuccessJSON(map[string]interface{}{
  9629. "his_info": his_patient_info,
  9630. "xt_info": xt_patient_info,
  9631. "case_history": case_history,
  9632. "info": patientPrescriptionInfo,
  9633. "month_prescriptions": monthPrescriptions,
  9634. "order": order,
  9635. "doctors": doctors,
  9636. "department": department,
  9637. "count": count,
  9638. "drugStockConfig": drugStockConfig,
  9639. "last_info": lastPatientPrescriptionInfo,
  9640. "settle_total": settle_total,
  9641. })
  9642. return
  9643. }
  9644. func (c *HisApiController) GetAllOrder() {
  9645. org_id := c.GetAdminUserInfo().CurrentOrgId
  9646. orders, _ := service.GetNewHisOrderList(org_id)
  9647. c.ServeSuccessJSON(map[string]interface{}{
  9648. "order": orders,
  9649. })
  9650. return
  9651. }
  9652. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9653. newArr = make([]*models.HisOrderInfoTwo, 0)
  9654. for i := 0; i < len(arr); i++ {
  9655. repeat := false
  9656. for j := i + 1; j < len(arr); j++ {
  9657. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9658. repeat = true
  9659. break
  9660. }
  9661. }
  9662. if !repeat {
  9663. newArr = append(newArr, arr[i])
  9664. }
  9665. }
  9666. return
  9667. }
  9668. // 修改处方退库操作 参数传修改之前的处方数据
  9669. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9670. if advice.ExecutionState == 1 {
  9671. //查询该病人该药品是否有库存记录
  9672. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9673. if errcode == gorm.ErrRecordNotFound {
  9674. } else {
  9675. //退库
  9676. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9677. if advice.PrescribingNumberUnit == drug.MinUnit {
  9678. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9679. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9680. //退库
  9681. warehouseInfo := models.DrugWarehouseInfo{
  9682. StockMinNumber: prescribingNumber,
  9683. }
  9684. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9685. operation_time := time.Now().Unix()
  9686. creater := advice.AdviceDoctor
  9687. ctime := time.Now().Unix()
  9688. timeStr := time.Now().Format("2006-01-02")
  9689. timeArr := strings.Split(timeStr, "-")
  9690. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9691. total = total + 1
  9692. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9693. cancelStock := models.DrugCancelStock{
  9694. OrderNumber: orderNumber,
  9695. OperaTime: operation_time,
  9696. OrgId: advice.UserOrgId,
  9697. Creater: creater,
  9698. Ctime: ctime,
  9699. Status: 1,
  9700. ReturnTime: advice.AdviceDate,
  9701. Dealer: info.Dealer,
  9702. Manufacturer: info.Manufacturer,
  9703. Type: 1,
  9704. }
  9705. service.AddSigleDrugCancelStock(&cancelStock)
  9706. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9707. dealer, _ := service.GetDealerById(info.Dealer)
  9708. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9709. cancelStockInfo := models.DrugCancelStockInfo{
  9710. OrderNumber: cancelInfo.OrderNumber,
  9711. CancelStockId: cancelInfo.ID,
  9712. DrugId: info.DrugId,
  9713. Count: info.Count,
  9714. Status: 1,
  9715. Ctime: ctime,
  9716. OrgId: advice.UserOrgId,
  9717. Type: 1,
  9718. Manufacturer: manufactureName.ManufacturerName,
  9719. Dealer: dealer.DealerName,
  9720. Total: 0,
  9721. RetailPrice: info.RetailPrice,
  9722. RetailTotalPrice: info.RetailTotalPrice,
  9723. Price: info.Price,
  9724. RegisterAccount: "",
  9725. Remark: info.Remark,
  9726. BatchNumber: info.BatchNumber,
  9727. MaxUnit: info.CountUnit,
  9728. ProductDate: info.ProductDate,
  9729. ExpiryDate: info.ExpiryDate,
  9730. BatchNumberId: info.WarehouseInfoId,
  9731. }
  9732. flow := models.DrugFlow{
  9733. WarehousingId: 0,
  9734. DrugId: info.DrugId,
  9735. Number: "",
  9736. BatchNumber: info.BatchNumber,
  9737. Count: info.Count,
  9738. UserOrgId: advice.UserOrgId,
  9739. PatientId: 0,
  9740. SystemTime: ctime,
  9741. ConsumableType: 4,
  9742. IsSys: 0,
  9743. WarehousingOrder: "",
  9744. WarehouseOutId: 0,
  9745. WarehouseOutOrderNumber: "",
  9746. IsEdit: 0,
  9747. CancelStockId: cancelStock.ID,
  9748. CancelOrderNumber: cancelStock.OrderNumber,
  9749. Manufacturer: info.Manufacturer,
  9750. Dealer: info.Dealer,
  9751. Creator: advice.UserOrgId,
  9752. UpdateCreator: 0,
  9753. Status: 1,
  9754. Ctime: time.Now().Unix(),
  9755. Mtime: 0,
  9756. Price: info.Price,
  9757. WarehousingDetailId: 0,
  9758. WarehouseOutDetailId: 0,
  9759. CancelOutDetailId: 0,
  9760. ExpireDate: info.ExpiryDate,
  9761. ProductDate: info.ProductDate,
  9762. MaxUnit: info.CountUnit,
  9763. MinUnit: "",
  9764. }
  9765. service.CreatedCancelStock(cancelStockInfo)
  9766. service.CreateDrugFlowOne(flow)
  9767. } else {
  9768. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9769. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9770. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9771. warehouseInfo := models.DrugWarehouseInfo{
  9772. StockMinNumber: prescribingNumber,
  9773. }
  9774. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9775. }
  9776. operation_time := time.Now().Unix()
  9777. creater := advice.AdviceDoctor
  9778. ctime := time.Now().Unix()
  9779. timeStr := time.Now().Format("2006-01-02")
  9780. timeArr := strings.Split(timeStr, "-")
  9781. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9782. total = total + 1
  9783. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9784. cancelStock := models.DrugCancelStock{
  9785. OrderNumber: orderNumber,
  9786. OperaTime: operation_time,
  9787. OrgId: advice.UserOrgId,
  9788. Creater: creater,
  9789. Ctime: ctime,
  9790. Status: 1,
  9791. ReturnTime: advice.AdviceDate,
  9792. Dealer: info.Dealer,
  9793. Manufacturer: info.Manufacturer,
  9794. Type: 1,
  9795. }
  9796. service.AddSigleDrugCancelStock(&cancelStock)
  9797. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9798. dealer, _ := service.GetDealerById(info.Dealer)
  9799. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9800. cancelStockInfo := models.DrugCancelStockInfo{
  9801. OrderNumber: cancelInfo.OrderNumber,
  9802. CancelStockId: cancelInfo.ID,
  9803. DrugId: info.DrugId,
  9804. Count: info.Count,
  9805. Status: 1,
  9806. Ctime: ctime,
  9807. OrgId: advice.UserOrgId,
  9808. Type: 1,
  9809. Manufacturer: manufactureName.ManufacturerName,
  9810. Dealer: dealer.DealerName,
  9811. Total: 0,
  9812. RetailPrice: info.RetailPrice,
  9813. RetailTotalPrice: info.RetailTotalPrice,
  9814. Price: info.Price,
  9815. RegisterAccount: "",
  9816. Remark: info.Remark,
  9817. BatchNumber: info.BatchNumber,
  9818. MaxUnit: info.CountUnit,
  9819. ProductDate: info.ProductDate,
  9820. ExpiryDate: info.ExpiryDate,
  9821. BatchNumberId: info.WarehouseInfoId,
  9822. }
  9823. flow := models.DrugFlow{
  9824. WarehousingId: 0,
  9825. DrugId: info.DrugId,
  9826. Number: "",
  9827. BatchNumber: info.BatchNumber,
  9828. Count: info.Count,
  9829. UserOrgId: advice.UserOrgId,
  9830. PatientId: 0,
  9831. SystemTime: ctime,
  9832. ConsumableType: 4,
  9833. IsSys: 0,
  9834. WarehousingOrder: "",
  9835. WarehouseOutId: 0,
  9836. WarehouseOutOrderNumber: "",
  9837. IsEdit: 0,
  9838. CancelStockId: cancelStock.ID,
  9839. CancelOrderNumber: cancelStock.OrderNumber,
  9840. Manufacturer: info.Manufacturer,
  9841. Dealer: info.Dealer,
  9842. Creator: advice.AdviceDoctor,
  9843. UpdateCreator: 0,
  9844. Status: 1,
  9845. Ctime: time.Now().Unix(),
  9846. Mtime: 0,
  9847. Price: info.Price,
  9848. WarehousingDetailId: 0,
  9849. WarehouseOutDetailId: 0,
  9850. CancelOutDetailId: 0,
  9851. ExpireDate: info.ExpiryDate,
  9852. ProductDate: info.ProductDate,
  9853. MaxUnit: info.CountUnit,
  9854. MinUnit: "",
  9855. }
  9856. service.CreatedCancelStock(cancelStockInfo)
  9857. service.CreateDrugFlowOne(flow)
  9858. }
  9859. }
  9860. }
  9861. return err
  9862. }
  9863. func (this *HisApiController) DeleteNCDS() {
  9864. id, _ := this.GetInt64("id", 0)
  9865. if id > 0 {
  9866. service.DeletePsnNCDSRecordById(id)
  9867. this.ServeSuccessJSON(map[string]interface{}{
  9868. "msg": "删除成功",
  9869. })
  9870. } else {
  9871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9872. return
  9873. }
  9874. }
  9875. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9876. id, _ := c.GetInt64("id")
  9877. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9878. c.ServeSuccessJSON(map[string]interface{}{
  9879. "advice": advice,
  9880. })
  9881. return
  9882. }
  9883. func (c *HisApiController) GetHisMonthChargePatientList() {
  9884. record_date := c.GetString("record_date")
  9885. start_time := c.GetString("start_time")
  9886. end_time := c.GetString("end_time")
  9887. timeLayout := "2006-01-02"
  9888. loc, _ := time.LoadLocation("Local")
  9889. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9890. if err != nil {
  9891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9892. return
  9893. }
  9894. if err != nil {
  9895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9896. return
  9897. }
  9898. recordDateTime := theTime.Unix()
  9899. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9900. if err != nil {
  9901. }
  9902. startRecordDateTime := startTime.Unix()
  9903. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9904. if err != nil {
  9905. }
  9906. endRecordDateTime := endTime.Unix()
  9907. adminInfo := c.GetAdminUserInfo()
  9908. var tempMonthChargePatients []*service.MonthChargePatients
  9909. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9910. for _, item := range tempPatients {
  9911. //过滤没有处方的
  9912. if len(item.HisPrescription) == 0 {
  9913. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9914. }
  9915. }
  9916. c.ServeSuccessJSON(map[string]interface{}{
  9917. "list": tempMonthChargePatients,
  9918. })
  9919. }