his_api_controller.go 437KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250
  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. fmt.Println("wooooooooooooo", advicelist.ID)
  1590. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1591. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1592. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1593. //新增处方
  1594. if advicelist.ID == 0 {
  1595. all_count, _ := strconv.ParseFloat(totals, 64)
  1596. if prescribingNumberUnit == drug.MinUnit {
  1597. fmt.Println("prescribing_number", prescribing_number)
  1598. fmt.Println("all_count", all_count)
  1599. if drug.IsUse != 1 {
  1600. if drug.IsProject == 0 || drug.IsProject == 2 {
  1601. if all_count == 0 {
  1602. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1603. return
  1604. }
  1605. if prescribing_number > all_count {
  1606. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1607. return
  1608. }
  1609. }
  1610. }
  1611. }
  1612. if prescribingNumberUnit == drug.MaxUnit {
  1613. num := prescribing_number * float64(drug.MinNumber)
  1614. if drug.IsUse != 1 {
  1615. if drug.IsProject == 0 || drug.IsProject == 2 {
  1616. if all_count == 0 {
  1617. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1618. return
  1619. }
  1620. if num > all_count {
  1621. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1622. return
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1629. if drugOutConfig.IsOpen != 1 {
  1630. //修改处方
  1631. for _, advice := range advices {
  1632. var drug_id int64
  1633. var prescribing_number float64
  1634. var prescribingNumberUnit string
  1635. var prescribingNumber string
  1636. var adviceId int64
  1637. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1638. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1639. }
  1640. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1641. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1642. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1643. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1644. }
  1645. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1646. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1647. }
  1648. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1649. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1650. }
  1651. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1652. if drug.ID == 0 {
  1653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1654. return
  1655. }
  1656. //查询药品的所有库存
  1657. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1658. var total_count int64
  1659. for _, it := range list {
  1660. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1661. }
  1662. totals := strconv.FormatInt(total_count, 10)
  1663. //查询该药品是否存在开药记录
  1664. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1665. //新增处方
  1666. if advicelist.ID == 0 {
  1667. all_count, _ := strconv.ParseFloat(totals, 64)
  1668. if prescribingNumberUnit == drug.MinUnit {
  1669. if drug.IsUse != 1 {
  1670. if drug.IsProject == 0 || drug.IsProject == 2 {
  1671. if all_count == 0 {
  1672. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1673. return
  1674. }
  1675. if prescribing_number > all_count {
  1676. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1677. return
  1678. }
  1679. }
  1680. }
  1681. } else {
  1682. if prescribingNumberUnit == drug.MaxUnit {
  1683. num := prescribing_number * float64(drug.MinNumber)
  1684. if drug.IsUse != 1 {
  1685. if drug.IsProject == 0 || drug.IsProject == 2 {
  1686. if all_count == 0 {
  1687. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1688. return
  1689. }
  1690. if num > all_count {
  1691. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1692. return
  1693. }
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. //修改处方
  1700. if advicelist.ID > 0 {
  1701. var device_number int64
  1702. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1703. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1704. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1705. device_number = prescribingNumberInt * drug.MinNumber
  1706. }
  1707. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1708. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1709. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1710. device_number = prescribingNumberInt
  1711. }
  1712. var number_count int64
  1713. if prescribingNumberUnit == drug.MaxUnit {
  1714. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1715. number_count = prescribingNumberInt * drug.MinNumber
  1716. }
  1717. if prescribingNumberUnit == drug.MinUnit {
  1718. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1719. number_count = prescribingNumberInt
  1720. }
  1721. //如果修改的数量大于之前修改的数量
  1722. if (number_count - device_number) > 0 {
  1723. //如果修改的差数量 大于库存数量
  1724. if drug.IsUse != 1 {
  1725. if (number_count - device_number) > total_count {
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1727. return
  1728. }
  1729. }
  1730. }
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. }
  1738. }
  1739. }
  1740. }
  1741. //已发药和已收费限制逻辑
  1742. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1743. //校验库存总量
  1744. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1745. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1746. if len(prescriptions) > 0 {
  1747. for _, item := range prescriptions {
  1748. items := item.(map[string]interface{})
  1749. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1750. advices := items["advices"].([]interface{})
  1751. if len(advices) > 0 {
  1752. for _, advice := range advices {
  1753. var drug_id int64
  1754. var prescribing_number float64
  1755. var prescribingNumberUnit string
  1756. var adviceId int64
  1757. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1758. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1759. }
  1760. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1761. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1762. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1765. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1768. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1769. }
  1770. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1771. if drug.ID == 0 {
  1772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1773. return
  1774. }
  1775. //查询药品的所有库存
  1776. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1777. var total_count int64
  1778. for _, it := range list {
  1779. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1780. }
  1781. totals := strconv.FormatInt(total_count, 10)
  1782. //查询该药品是否存在开药记录
  1783. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1784. //查询最新批次库存
  1785. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1786. var batch_number_count int64
  1787. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1788. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1789. //新增处方
  1790. if advicelist.ID == 0 {
  1791. all_count, _ := strconv.ParseFloat(totals, 64)
  1792. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1793. if prescribingNumberUnit == drug.MinUnit {
  1794. if drug.IsUse != 1 {
  1795. if drug.IsProject == 0 || drug.IsProject == 2 {
  1796. if all_count == 0 {
  1797. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1798. return
  1799. }
  1800. if prescribing_number > all_count {
  1801. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1802. return
  1803. }
  1804. }
  1805. if adminInfo.CurrentOrgId == 10215 {
  1806. if prescribing_number > batch_number_all_count {
  1807. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1808. return
  1809. }
  1810. }
  1811. }
  1812. }
  1813. if prescribingNumberUnit == drug.MaxUnit {
  1814. num := prescribing_number * float64(drug.MinNumber)
  1815. if drug.IsUse != 1 {
  1816. if drug.IsProject == 0 || drug.IsProject == 2 {
  1817. if all_count == 0 {
  1818. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1819. return
  1820. }
  1821. if num > all_count {
  1822. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1823. return
  1824. }
  1825. }
  1826. if adminInfo.CurrentOrgId == 10215 {
  1827. if num > batch_number_all_count {
  1828. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1829. return
  1830. }
  1831. }
  1832. }
  1833. }
  1834. }
  1835. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1836. if drugOutConfig.IsOpen != 1 {
  1837. //修改处方
  1838. for _, advice := range advices {
  1839. var drug_id int64
  1840. var prescribing_number float64
  1841. var prescribingNumberUnit string
  1842. var prescribingNumber string
  1843. var adviceId int64
  1844. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1845. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1846. }
  1847. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1848. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1849. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1850. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1851. }
  1852. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1853. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1854. }
  1855. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1856. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1857. }
  1858. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1859. if drug.ID == 0 {
  1860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1861. return
  1862. }
  1863. //查询药品的所有库存
  1864. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1865. var total_count int64
  1866. for _, it := range list {
  1867. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1868. }
  1869. totals := strconv.FormatInt(total_count, 10)
  1870. //查询该药品是否存在开药记录
  1871. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1872. //新增处方
  1873. if advicelist.ID == 0 {
  1874. //查询最新批次库存
  1875. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1876. var batch_number_count int64
  1877. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1878. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1879. all_count, _ := strconv.ParseFloat(totals, 64)
  1880. if prescribingNumberUnit == drug.MinUnit {
  1881. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1882. if drug.IsUse != 1 {
  1883. if drug.IsProject == 0 || drug.IsProject == 2 {
  1884. if all_count == 0 {
  1885. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1886. return
  1887. }
  1888. if prescribing_number > all_count {
  1889. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1890. return
  1891. }
  1892. }
  1893. if adminInfo.CurrentOrgId == 10215 {
  1894. if prescribing_number > batch_number_all_count {
  1895. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1896. return
  1897. }
  1898. }
  1899. }
  1900. } else {
  1901. if prescribingNumberUnit == drug.MaxUnit {
  1902. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1903. num := prescribing_number * float64(drug.MinNumber)
  1904. if drug.IsUse != 1 {
  1905. if drug.IsProject == 0 || drug.IsProject == 2 {
  1906. if all_count == 0 {
  1907. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1908. return
  1909. }
  1910. if num > all_count {
  1911. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1912. return
  1913. }
  1914. }
  1915. if adminInfo.CurrentOrgId == 10215 {
  1916. if prescribing_number > batch_number_all_count {
  1917. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1918. return
  1919. }
  1920. }
  1921. }
  1922. }
  1923. }
  1924. }
  1925. //修改处方
  1926. if advicelist.ID > 0 {
  1927. //查询最新批次库存
  1928. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1929. var batch_number_count int64
  1930. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1931. var device_number int64
  1932. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1933. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1934. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1935. device_number = prescribingNumberInt * drug.MinNumber
  1936. }
  1937. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1938. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1939. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1940. device_number = prescribingNumberInt
  1941. }
  1942. var number_count int64
  1943. if prescribingNumberUnit == drug.MaxUnit {
  1944. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1945. number_count = prescribingNumberInt * drug.MinNumber
  1946. }
  1947. if prescribingNumberUnit == drug.MinUnit {
  1948. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1949. number_count = prescribingNumberInt
  1950. }
  1951. //如果修改的数量大于之前修改的数量
  1952. if (number_count - device_number) > 0 {
  1953. //如果修改的差数量 大于库存数量
  1954. if drug.IsUse != 1 {
  1955. if drug.IsProject == 0 || drug.IsProject == 2 {
  1956. if total_count == 0 {
  1957. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1958. return
  1959. }
  1960. if (number_count - device_number) > total_count {
  1961. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1962. return
  1963. }
  1964. if (number_count - device_number) > batch_number_count {
  1965. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1966. return
  1967. }
  1968. }
  1969. if adminInfo.CurrentOrgId == 10215 {
  1970. // 查询该药品最后一次出库记录
  1971. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1972. var out_count int64
  1973. var in_count int64
  1974. var stock_max_number int64
  1975. var stock_min_number int64
  1976. for _, it := range outInfo {
  1977. if it.CountUnit == drug.MaxUnit {
  1978. it.Count = it.Count * drug.MinNumber
  1979. }
  1980. out_count += it.Count
  1981. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1982. stock_max_number = warehouseInfoList.StockMaxNumber
  1983. stock_min_number = warehouseInfoList.StockMinNumber
  1984. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1985. }
  1986. if out_count > 0 {
  1987. if (number_count - device_number) > in_count {
  1988. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1989. return
  1990. }
  1991. }
  1992. // 未出库
  1993. if out_count == 0 {
  1994. var sum_in_count int64
  1995. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1996. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1997. fmt.Println("sum_in_count", sum_in_count)
  1998. //如果修改的数量大于有库存的第一个批次
  1999. if number_count > sum_in_count {
  2000. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2001. return
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2008. if pharmacyConfig.IsOpen != 1 {
  2009. if device_number != number_count {
  2010. // 查询该药品最后一次出库记录
  2011. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2012. //回退库存
  2013. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2014. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2015. }
  2016. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2017. var stock_max_number int64
  2018. var stock_min_number int64
  2019. if number_count >= drug.MinNumber {
  2020. stock_max_number = device_number / drug.MinNumber
  2021. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2022. stock_min_number = device_number % drug.MinNumber
  2023. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2024. } else {
  2025. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2026. }
  2027. }
  2028. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2029. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2030. }
  2031. //删除记录
  2032. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2033. //查询默认仓库剩余多少库存
  2034. var sum_count int64
  2035. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2036. for _, its := range stockInfo {
  2037. if its.MaxUnit == drug.MaxUnit {
  2038. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2039. }
  2040. sum_count += its.StockMaxNumber + its.StockMinNumber
  2041. }
  2042. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2043. }
  2044. }
  2045. }
  2046. }
  2047. }
  2048. //保存处方开药
  2049. if drugOutConfig.IsOpen == 1 {
  2050. //修改处方
  2051. for _, advice := range advices {
  2052. var drug_id int64
  2053. var prescribing_number float64
  2054. var prescribingNumberUnit string
  2055. var prescribingNumber string
  2056. var adviceId int64
  2057. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2058. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2059. }
  2060. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2061. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2062. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2063. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2064. }
  2065. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2066. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2067. }
  2068. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2069. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2070. }
  2071. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2072. if drug.ID == 0 {
  2073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2074. return
  2075. }
  2076. //查询药品的所有库存
  2077. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2078. var total_count int64
  2079. for _, it := range list {
  2080. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2081. }
  2082. totals := strconv.FormatInt(total_count, 10)
  2083. //查询该药品是否存在开药记录
  2084. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2085. //新增处方
  2086. if advicelist.ID == 0 {
  2087. //查询最新批次库存
  2088. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2089. var batch_number_count int64
  2090. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2091. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2092. all_count, _ := strconv.ParseFloat(totals, 64)
  2093. if prescribingNumberUnit == drug.MinUnit {
  2094. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2095. if drug.IsUse != 1 {
  2096. if drug.IsProject == 0 || drug.IsProject == 2 {
  2097. if all_count == 0 {
  2098. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2099. return
  2100. }
  2101. if prescribing_number > all_count {
  2102. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2103. return
  2104. }
  2105. }
  2106. if adminInfo.CurrentOrgId == 10215 {
  2107. if prescribing_number > batch_number_all_count {
  2108. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2109. return
  2110. }
  2111. }
  2112. }
  2113. } else {
  2114. if prescribingNumberUnit == drug.MaxUnit {
  2115. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2116. num := prescribing_number * float64(drug.MinNumber)
  2117. if drug.IsUse != 1 {
  2118. if drug.IsProject == 0 || drug.IsProject == 2 {
  2119. if all_count == 0 {
  2120. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2121. return
  2122. }
  2123. if num > all_count {
  2124. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2125. return
  2126. }
  2127. }
  2128. if adminInfo.CurrentOrgId == 10215 {
  2129. if prescribing_number > batch_number_all_count {
  2130. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2131. return
  2132. }
  2133. }
  2134. }
  2135. }
  2136. }
  2137. }
  2138. //修改处方
  2139. if advicelist.ID > 0 {
  2140. //查询最新批次库存
  2141. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2142. var batch_number_count int64
  2143. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2144. var device_number int64
  2145. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2146. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2147. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2148. device_number = prescribingNumberInt * drug.MinNumber
  2149. }
  2150. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2151. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2152. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2153. device_number = prescribingNumberInt
  2154. }
  2155. var number_count int64
  2156. if prescribingNumberUnit == drug.MaxUnit {
  2157. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2158. number_count = prescribingNumberInt * drug.MinNumber
  2159. }
  2160. if prescribingNumberUnit == drug.MinUnit {
  2161. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2162. number_count = prescribingNumberInt
  2163. }
  2164. //如果修改的数量大于之前修改的数量
  2165. if (number_count - device_number) > 0 {
  2166. //如果修改的差数量 大于库存数量
  2167. if drug.IsUse != 1 {
  2168. if drug.IsProject == 0 || drug.IsProject == 2 {
  2169. if total_count == 0 {
  2170. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2171. return
  2172. }
  2173. if (number_count - device_number) > total_count {
  2174. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2175. return
  2176. }
  2177. }
  2178. if adminInfo.CurrentOrgId == 10215 {
  2179. if (number_count - device_number) > batch_number_count {
  2180. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2181. return
  2182. }
  2183. }
  2184. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2185. //查询历史出库数据总批次
  2186. // 查询该药品最后一次出库记录
  2187. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2188. var out_count int64
  2189. var in_count int64
  2190. var stock_max_number int64
  2191. var stock_min_number int64
  2192. for _, it := range outInfo {
  2193. if it.CountUnit == drug.MaxUnit {
  2194. it.Count = it.Count * drug.MinNumber
  2195. }
  2196. out_count += it.Count
  2197. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2198. stock_max_number = warehouseInfoList.StockMaxNumber
  2199. stock_min_number = warehouseInfoList.StockMinNumber
  2200. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2201. }
  2202. if out_count > 0 {
  2203. if (number_count - device_number) > in_count {
  2204. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2205. return
  2206. }
  2207. }
  2208. // 未出库
  2209. if out_count == 0 {
  2210. var sum_in_count int64
  2211. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2212. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2213. if sum_in_count == 0 {
  2214. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2215. return
  2216. }
  2217. //如果修改的数量大于有库存的第一个批次
  2218. if number_count > sum_in_count {
  2219. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2220. return
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. }
  2235. }
  2236. //校验耗材库存
  2237. if goodOutConfig.IsOpen == 1 {
  2238. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2239. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2240. if len(prescriptions) > 0 {
  2241. for _, item := range prescriptions {
  2242. items := item.(map[string]interface{})
  2243. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2244. projects := items["project"].([]interface{})
  2245. if len(projects) > 0 {
  2246. for _, project := range projects {
  2247. var project_id int64
  2248. var project_type int64
  2249. var totals float64
  2250. var project_name string
  2251. var parsetotal int64
  2252. var id int64
  2253. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2254. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2255. }
  2256. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2257. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2258. }
  2259. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2260. total, _ := project.(map[string]interface{})["total"].(string)
  2261. totals, _ = strconv.ParseFloat(total, 64)
  2262. }
  2263. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2264. project_name = project.(map[string]interface{})["project_name"].(string)
  2265. }
  2266. if project_type == 3 {
  2267. //查找该耗材的出库记录
  2268. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2269. if len(goodWarehouseInfo) == 0 {
  2270. //查询耗材库存
  2271. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2272. var stock_count int64
  2273. for _, it := range list {
  2274. stock_count += it.StockCount
  2275. }
  2276. stock_counts := strconv.FormatInt(stock_count, 10)
  2277. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2278. if stock_total_count == 0 {
  2279. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2280. return
  2281. }
  2282. if totals > stock_total_count {
  2283. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2284. return
  2285. }
  2286. }
  2287. if len(goodWarehouseInfo) > 0 {
  2288. //查询该患者耗材的历史数据
  2289. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2290. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2291. //数量发生改变
  2292. if parsetotal != count {
  2293. //如果现在的数量大于历史数量,就要看库存是否足够
  2294. if parsetotal > count {
  2295. //查询耗材所有库存
  2296. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2297. var stock_count int64
  2298. for _, it := range list {
  2299. stock_count += it.StockCount
  2300. }
  2301. //库存不足
  2302. if stock_count == 0 {
  2303. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2304. return
  2305. }
  2306. if (parsetotal - count) > stock_count {
  2307. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2308. return
  2309. }
  2310. }
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. //不使用耗材保存处方出库
  2322. if goodOutConfig.IsOpen != 1 {
  2323. if stockConfig.IsOpen == 1 {
  2324. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2325. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2326. if len(prescriptions) > 0 {
  2327. for _, item := range prescriptions {
  2328. items := item.(map[string]interface{})
  2329. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2330. projects := items["project"].([]interface{})
  2331. if len(projects) > 0 {
  2332. for _, project := range projects {
  2333. var project_id int64
  2334. var project_type int64
  2335. var totals float64
  2336. var project_name string
  2337. var parsetotal int64
  2338. var id int64
  2339. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2340. id = int64(project.(map[string]interface{})["id"].(float64))
  2341. }
  2342. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2343. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2344. }
  2345. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2346. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2347. }
  2348. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2349. total, _ := project.(map[string]interface{})["total"].(string)
  2350. totals, _ = strconv.ParseFloat(total, 64)
  2351. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2352. }
  2353. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2354. project_name = project.(map[string]interface{})["project_name"].(string)
  2355. }
  2356. if project_type == 3 {
  2357. //查找该耗材的出库记录
  2358. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2359. //没有出库记录
  2360. if len(goodWarehouseInfo) == 0 {
  2361. //查询耗材库存
  2362. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2363. var stock_count int64
  2364. for _, it := range list {
  2365. stock_count += it.StockCount
  2366. }
  2367. stock_counts := strconv.FormatInt(stock_count, 10)
  2368. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2369. if stock_total_count == 0 {
  2370. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2371. return
  2372. }
  2373. if totals > stock_total_count {
  2374. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2375. return
  2376. }
  2377. //查找今日该患者已经出库的所有耗材
  2378. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2379. for _, item := range goodList {
  2380. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2381. var flush_count int64
  2382. for _, it := range goodListSix {
  2383. flush_count += it.StockCount
  2384. }
  2385. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2386. creater := adminInfo.AdminUser.Id
  2387. if errs != nil {
  2388. goodErrcode := models.XtGoodErrcode{
  2389. UserOrgId: item.OrgId,
  2390. Errcode: "手动出库更新剩余出库失败",
  2391. GoodId: item.GoodId,
  2392. Status: 1,
  2393. Ctime: time.Now().Unix(),
  2394. Mtime: 0,
  2395. Count: 0,
  2396. StockCount: 0,
  2397. Creater: creater,
  2398. BatchNumberId: 0,
  2399. WarehouseOutId: 0,
  2400. }
  2401. service.CreateGoodErrcode(goodErrcode)
  2402. }
  2403. }
  2404. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2405. }
  2406. //有出库记录
  2407. if len(goodWarehouseInfo) > 0 {
  2408. //查询该患者耗材的历史数据
  2409. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2410. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2411. //数量发生改变
  2412. if parsetotal != count {
  2413. //查找今日该患者已经出库的所有耗材
  2414. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2415. for _, item := range goodList {
  2416. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2417. var flush_count int64
  2418. for _, it := range goodListSix {
  2419. flush_count += it.StockCount
  2420. }
  2421. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2422. //减少出库数量
  2423. creater := adminInfo.AdminUser.Id
  2424. if errs != nil {
  2425. goodErrcode := models.XtGoodErrcode{
  2426. UserOrgId: item.OrgId,
  2427. Errcode: "手动出库更新剩余出库失败",
  2428. GoodId: item.GoodId,
  2429. Status: 1,
  2430. Ctime: time.Now().Unix(),
  2431. Mtime: 0,
  2432. Count: 0,
  2433. StockCount: 0,
  2434. Creater: creater,
  2435. BatchNumberId: 0,
  2436. WarehouseOutId: 0,
  2437. }
  2438. service.CreateGoodErrcode(goodErrcode)
  2439. }
  2440. //查询默认仓库
  2441. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2442. var total_count int64
  2443. for _, it := range stockList {
  2444. total_count += it.StockCount
  2445. }
  2446. //基础库插入数据
  2447. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2448. }
  2449. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2450. }
  2451. }
  2452. }
  2453. }
  2454. }
  2455. }
  2456. }
  2457. }
  2458. }
  2459. }
  2460. }
  2461. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2462. var hpInfo models.HisPrescriptionInfo
  2463. if info.ID == 0 {
  2464. var randNum int
  2465. randNum = rand.Intn(10000) + 1000
  2466. timestamp := time.Now().Unix()
  2467. tempTime := time.Unix(timestamp, 0)
  2468. timeFormat := tempTime.Format("20060102150405")
  2469. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2470. hpInfo = models.HisPrescriptionInfo{
  2471. HisPatientId: his_patient_id,
  2472. UserOrgId: adminInfo.CurrentOrgId,
  2473. RecordDate: theTime.Unix(),
  2474. PatientId: patient_id,
  2475. Status: 1,
  2476. Ctime: time.Now().Unix(),
  2477. Mtime: time.Now().Unix(),
  2478. Creator: adminInfo.AdminUser.Id,
  2479. Modifier: adminInfo.AdminUser.Id,
  2480. Diagnosis: diagnose,
  2481. SickHistory: sick_history,
  2482. Departments: department,
  2483. RegisterType: reg_type,
  2484. PrescriptionNumber: p_number,
  2485. PrescriptionStatus: 1,
  2486. Doctor: role.UserName,
  2487. DoctorId: doctor_id,
  2488. SickType: sick_type,
  2489. PType: p_type,
  2490. PatientDiagnosis: patient_diagnose,
  2491. }
  2492. service.SavePatientPrescriptionInfo(hpInfo)
  2493. //创建步骤表
  2494. finish := models.XtDialysisFinish{
  2495. IsFinish: 1,
  2496. UserOrgId: adminInfo.CurrentOrgId,
  2497. Status: 1,
  2498. Ctime: time.Now().Unix(),
  2499. Mtime: 0,
  2500. Module: 4,
  2501. RecordDate: theTime.Unix(),
  2502. Sourse: 1,
  2503. PatientId: patient_id,
  2504. }
  2505. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2506. if dialysisFinish.ID == 0 {
  2507. service.CreateDialysisFinish(finish)
  2508. }
  2509. redis := service.RedisClient()
  2510. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2511. redis.Set(key, "", time.Second)
  2512. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2513. redis.Set(keyOne, "", time.Second)
  2514. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2515. redis.Set(keySeven, "", time.Second)
  2516. defer redis.Close()
  2517. } else {
  2518. hpInfo = models.HisPrescriptionInfo{
  2519. ID: info.ID,
  2520. UserOrgId: adminInfo.CurrentOrgId,
  2521. RecordDate: info.RecordDate,
  2522. PatientId: info.PatientId,
  2523. Status: 1,
  2524. Ctime: info.Ctime,
  2525. Mtime: time.Now().Unix(),
  2526. Creator: info.Creator,
  2527. Modifier: adminInfo.AdminUser.Id,
  2528. Diagnosis: diagnose,
  2529. SickHistory: sick_history,
  2530. Departments: department,
  2531. RegisterType: reg_type,
  2532. PrescriptionNumber: info.PrescriptionNumber,
  2533. Doctor: role.UserName,
  2534. PrescriptionStatus: info.PrescriptionStatus,
  2535. DoctorId: doctor_id,
  2536. SickType: sick_type,
  2537. PType: info.PType,
  2538. HisPatientId: info.HisPatientId,
  2539. PatientDiagnosis: patient_diagnose,
  2540. }
  2541. service.SavePatientPrescriptionInfo(hpInfo)
  2542. //创建步骤表
  2543. finish := models.XtDialysisFinish{
  2544. IsFinish: 1,
  2545. UserOrgId: adminInfo.CurrentOrgId,
  2546. Status: 1,
  2547. Ctime: time.Now().Unix(),
  2548. Mtime: 0,
  2549. Module: 4,
  2550. RecordDate: info.RecordDate,
  2551. Sourse: 1,
  2552. PatientId: info.PatientId,
  2553. }
  2554. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2555. if dialysisFinish.ID == 0 {
  2556. service.CreateDialysisFinish(finish)
  2557. }
  2558. redis := service.RedisClient()
  2559. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2560. redis.Set(key, "", time.Second)
  2561. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2562. redis.Set(keyOne, "", time.Second)
  2563. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2564. redis.Set(keySeven, "", time.Second)
  2565. defer redis.Close()
  2566. }
  2567. //定义切片
  2568. var adviceList []models.HisDoctorAdviceInfo
  2569. var projectList []models.HisPrescriptionProject
  2570. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2571. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2572. var tempPrescription *models.HisPrescription
  2573. if len(prescriptions) > 0 {
  2574. for _, item := range prescriptions {
  2575. items := item.(map[string]interface{})
  2576. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2577. utils.ErrorLog("id")
  2578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2579. return
  2580. }
  2581. id := int64(items["id"].(float64))
  2582. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2583. tempPrescription = &new_prescription
  2584. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2585. utils.ErrorLog("type")
  2586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2587. return
  2588. }
  2589. types := int64(items["type"].(float64))
  2590. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2591. utils.ErrorLog("med_type")
  2592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2593. return
  2594. }
  2595. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2596. if med_type == "0" {
  2597. med_type = "14"
  2598. }
  2599. //if order_status == 0 {
  2600. // order_status = 1
  2601. //}
  2602. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2603. utils.ErrorLog("pre_time")
  2604. }
  2605. preTime, _ := items["pre_time"].(string)
  2606. timeLayout := "2006-01-02"
  2607. loc, _ := time.LoadLocation("Local")
  2608. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2609. if err != nil {
  2610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2611. return
  2612. }
  2613. pTime := theTime2.Unix()
  2614. ctime := time.Now().Unix()
  2615. if tempPrescription.ID == 0 {
  2616. prescription := &models.HisPrescription{
  2617. ID: 0,
  2618. PatientId: patient_id,
  2619. UserOrgId: adminInfo.CurrentOrgId,
  2620. RecordDate: recordDateTime,
  2621. Ctime: ctime,
  2622. Mtime: ctime,
  2623. Type: types,
  2624. Modifier: adminInfo.AdminUser.Id,
  2625. Creator: adminInfo.AdminUser.Id,
  2626. Status: 1,
  2627. Doctor: role.UserName,
  2628. HisPatientId: his_patient_id,
  2629. OrderStatus: 1,
  2630. BatchNumber: "",
  2631. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2632. PreTime: pTime,
  2633. PType: p_type,
  2634. MedType: med_type,
  2635. }
  2636. tempPrescription = prescription
  2637. service.SaveHisPrescription(tempPrescription)
  2638. redis := service.RedisClient()
  2639. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2640. redis.Set(key, "", time.Second)
  2641. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2642. redis.Set(keyOne, "", time.Second)
  2643. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2644. redis.Set(keySeven, "", time.Second)
  2645. defer redis.Close()
  2646. } else {
  2647. tempPrescription.ID = id
  2648. tempPrescription.Type = types
  2649. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2650. tempPrescription.Mtime = time.Now().Unix()
  2651. tempPrescription.Doctor = role.UserName
  2652. //tempPrescription.OrderStatus = order_status
  2653. tempPrescription.PreTime = pTime
  2654. tempPrescription.MedType = med_type
  2655. service.SaveHisPrescription(tempPrescription)
  2656. redis := service.RedisClient()
  2657. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2658. redis.Set(key, "", time.Second)
  2659. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2660. redis.Set(keyOne, "", time.Second)
  2661. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2662. redis.Set(keySeven, "", time.Second)
  2663. defer redis.Close()
  2664. }
  2665. //service.SaveHisPrescription(prescription)
  2666. //更改患者挂号状态
  2667. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2668. fmt.Println("更改失败", err2)
  2669. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2670. advices := items["advices"].([]interface{})
  2671. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2672. groupNo := int64(0)
  2673. ctime := time.Now().Unix()
  2674. mtime := ctime
  2675. if len(advices) > 0 {
  2676. for _, advice := range advices {
  2677. var s models.HisDoctorAdviceInfo
  2678. s.PrescriptionId = tempPrescription.ID
  2679. s.AdviceType = 2
  2680. s.AdviceDoctor = doctor_id
  2681. s.StopState = 2
  2682. s.ExecutionState = 2
  2683. s.AdviceDate = recordDateTime
  2684. s.Status = 1
  2685. s.UserOrgId = adminInfo.CurrentOrgId
  2686. s.RecordDate = recordDateTime
  2687. s.StartTime = tempPrescription.PreTime
  2688. s.Groupno = groupNo
  2689. s.CreatedTime = ctime
  2690. s.UpdatedTime = mtime
  2691. s.PatientId = patient_id
  2692. s.HisPatientId = his_patient_id
  2693. s.StartTime = pTime
  2694. s.IsSettle = 2
  2695. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2696. if errcode > 0 {
  2697. c.ServeFailJSONWithSGJErrorCode(errcode)
  2698. return
  2699. }
  2700. s.StartTime = pTime
  2701. var total_count int64 //处方总库存
  2702. //查询改药品信息
  2703. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2704. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2705. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2706. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2707. total_count += prescribingNumberSeven * medical.MinNumber
  2708. }
  2709. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2710. total_count += prescribingNumberSeven
  2711. }
  2712. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2713. total_count += prescribingNumberSeven
  2714. }
  2715. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2716. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2717. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2718. if s.Price != lastWarehouse.RetailPrice {
  2719. s.Price = lastWarehouse.RetailPrice
  2720. }
  2721. if s.Price == 0 {
  2722. s.Price = lastWarehouse.RetailPrice
  2723. }
  2724. }
  2725. service.CreateHisDoctorAdvice(&s)
  2726. //记录日志
  2727. byterequest, _ := json.Marshal(s)
  2728. adviceLog := models.XtDoctorAdviceLog{
  2729. UserOrgId: s.UserOrgId,
  2730. PatientId: s.PatientId,
  2731. AdminUserId: adminInfo.AdminUser.Id,
  2732. Module: 1,
  2733. ErrLog: string(byterequest),
  2734. Status: 1,
  2735. Ctime: time.Now().Unix(),
  2736. Mtime: 0,
  2737. Source: "电脑端新建his医嘱",
  2738. RecordDate: s.AdviceDate,
  2739. }
  2740. service.CreateDoctorAdviceLog(adviceLog)
  2741. //存储切片中
  2742. adviceList = append(adviceList, s)
  2743. redis := service.RedisClient()
  2744. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2745. redis.Set(key, "", time.Second)
  2746. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2747. redis.Set(keyOne, "", time.Second)
  2748. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2749. redis.Set(keySeven, "", time.Second)
  2750. var randNum int
  2751. randNum = rand.Intn(10000) + 1000
  2752. timestamp := time.Now().Unix()
  2753. tempTime := time.Unix(timestamp, 0)
  2754. timeFormat := tempTime.Format("20060102150405")
  2755. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2756. service.CreateHisDoctorAdvice(&s)
  2757. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2758. redis.Set(keySix, "", time.Second)
  2759. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2760. redis.Set(keyFive, "", time.Second)
  2761. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2762. redis.Set(keyEight, "", time.Second)
  2763. defer redis.Close()
  2764. }
  2765. }
  2766. }
  2767. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2768. projects := items["project"].([]interface{})
  2769. if len(projects) > 0 {
  2770. for _, project := range projects {
  2771. var p models.HisPrescriptionProject
  2772. p.PrescriptionId = tempPrescription.ID
  2773. p.Ctime = time.Now().Unix()
  2774. p.Mtime = time.Now().Unix()
  2775. p.PatientId = patient_id
  2776. p.RecordDate = recordDateTime
  2777. p.Doctor = doctor_id
  2778. p.UserOrgId = adminInfo.CurrentOrgId
  2779. p.HisPatientId = his_patient_id
  2780. p.Status = 1
  2781. p.StartTime = pTime
  2782. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2783. if errcode > 0 {
  2784. c.ServeFailJSONWithSGJErrorCode(errcode)
  2785. return
  2786. }
  2787. if p.ID == 0 {
  2788. p.IsOut = 2
  2789. }
  2790. if p.ID > 0 {
  2791. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2792. p.IsOut = projectDetail.IsOut
  2793. }
  2794. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2795. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2796. if p.Type == 3 {
  2797. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2798. if p.Price != lastWarehouse.PackingPrice {
  2799. p.Price = lastWarehouse.PackingPrice
  2800. }
  2801. if p.Unit == "" {
  2802. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2803. p.Unit = goodInfoOne.PackingUnit
  2804. }
  2805. }
  2806. }
  2807. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2808. //
  2809. // if p.Type == 3 {
  2810. // //查询该耗材是否停用
  2811. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2812. // //表示该耗材已经停用,不能保存
  2813. // if goodInfoSeven.ID == 0 {
  2814. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2815. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2816. // return
  2817. // }
  2818. // }
  2819. //
  2820. //}
  2821. service.CreateHisProjectTwo(&p)
  2822. //记录日志
  2823. byterequest, _ := json.Marshal(p)
  2824. adviceLog := models.XtDoctorAdviceLog{
  2825. UserOrgId: p.UserOrgId,
  2826. PatientId: p.PatientId,
  2827. AdminUserId: adminInfo.AdminUser.Id,
  2828. Module: 1,
  2829. ErrLog: string(byterequest),
  2830. Status: 1,
  2831. Ctime: time.Now().Unix(),
  2832. Mtime: 0,
  2833. Source: "电脑端新建his项目",
  2834. RecordDate: p.RecordDate,
  2835. }
  2836. service.CreateDoctorAdviceLog(adviceLog)
  2837. projectList = append(projectList, p)
  2838. var randNum int
  2839. randNum = rand.Intn(10000) + 1000
  2840. timestamp := time.Now().Unix()
  2841. tempTime := time.Unix(timestamp, 0)
  2842. timeFormat := tempTime.Format("20060102150405")
  2843. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2844. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2845. //新增或者编辑项目,修改对应的标签数据
  2846. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2847. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2848. var label models.HisLabelPrintInfo
  2849. project, _ := service.GetProjectDetail(p.ProjectId)
  2850. if project.CostClassify == 3 { //类别为检验检查
  2851. if p.TeamId > 0 { //检验检查组套
  2852. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2853. if tempLabel.ID == 0 {
  2854. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2855. label.Number = tempPrescription.PrescriptionNumber
  2856. label.ProjectId = project.ID
  2857. label.Status = 1
  2858. label.IsPrint = 2
  2859. label.DoctorId = info.DoctorId
  2860. label.UserOrgId = p.UserOrgId
  2861. label.PatientId = patient_id
  2862. label.RecordDate = recordDateTime
  2863. label.Ctime = time.Now().Unix()
  2864. label.Mtime = time.Now().Unix()
  2865. label.ItemId = p.TeamId
  2866. label.FeedetlSn = p.FeedetlSn
  2867. label.PProjectId = p.ID
  2868. label.ProjectName = team.ProjectTeam
  2869. label.PatientName = patient.Name
  2870. service.CreateHisLabelRecord(&label)
  2871. }
  2872. } else { //单条检验检查项目
  2873. label.Number = tempPrescription.PrescriptionNumber
  2874. label.ProjectId = project.ID
  2875. label.Status = 1
  2876. label.DoctorId = info.DoctorId
  2877. label.UserOrgId = p.UserOrgId
  2878. label.PatientId = patient_id
  2879. label.RecordDate = recordDateTime
  2880. label.IsPrint = 2
  2881. label.Ctime = time.Now().Unix()
  2882. label.Mtime = time.Now().Unix()
  2883. label.FeedetlSn = p.FeedetlSn
  2884. label.PProjectId = p.ID
  2885. label.ItemId = p.TeamId
  2886. label.ProjectName = project.ProjectName
  2887. label.PatientName = patient.Name
  2888. service.CreateHisLabelRecord(&label)
  2889. }
  2890. }
  2891. }
  2892. }
  2893. service.SaveHisProjectTwo(&p)
  2894. }
  2895. }
  2896. }
  2897. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2898. // addition := items["addition"].([]interface{})
  2899. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2900. // ctime := time.Now().Unix()
  2901. // mtime := ctime
  2902. // if len(addition) > 0 {
  2903. // for _, item := range addition {
  2904. // var s models.HisAdditionalCharge
  2905. // s.PrescriptionId = tempPrescription.ID
  2906. // s.Status = 1
  2907. // s.UserOrgId = adminInfo.CurrentOrgId
  2908. // s.RecordDate = recordDateTime
  2909. // s.CreatedTime = ctime
  2910. // s.UpdatedTime = mtime
  2911. // s.PatientId = patient_id
  2912. // s.HisPatientId = his_patient_id
  2913. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2914. // if errcode > 0 {
  2915. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2916. // return
  2917. // }
  2918. // service.CreateAdditionalCharge(&s)
  2919. // var randNum int
  2920. // randNum = rand.Intn(10000) + 1000
  2921. // timestamp := time.Now().Unix()
  2922. // tempTime := time.Unix(timestamp, 0)
  2923. // timeFormat := tempTime.Format("20060102150405")
  2924. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2925. // service.CreateAdditionalCharge(&s)
  2926. //
  2927. // }
  2928. // }
  2929. //}
  2930. }
  2931. }
  2932. //查询今日该患者开的药品处方
  2933. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2934. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2935. //药品出库
  2936. if drugOutConfig.IsOpen == 1 {
  2937. for _, item := range hisdoctorlist {
  2938. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2939. // 查询该药品最后一次出库记录
  2940. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2941. if len(druginfo) > 0 {
  2942. //回退库存
  2943. for _, it := range druginfo {
  2944. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2945. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2946. }
  2947. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2948. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2949. }
  2950. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2951. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2952. }
  2953. }
  2954. }
  2955. //删除记录
  2956. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2957. //查询最后一次数据
  2958. if drugOutConfig.IsOpen == 1 {
  2959. //出库
  2960. if drug.IsUse == 2 {
  2961. creater := adminInfo.AdminUser.Id
  2962. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2963. }
  2964. //更新字典里面的库存
  2965. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2966. var sum_count int64
  2967. for _, its := range stockInfo {
  2968. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2969. if its.MaxUnit == baseDrug.MaxUnit {
  2970. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2971. }
  2972. sum_count += its.StockMaxNumber + its.StockMinNumber
  2973. }
  2974. //更新基础库存
  2975. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2976. //剩余库存
  2977. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2978. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  2979. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2980. }
  2981. }
  2982. }
  2983. //耗材保存处方出库
  2984. if goodOutConfig.IsOpen == 1 {
  2985. //查询今日耗材出库数量
  2986. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2987. for _, item := range hisgoodlist {
  2988. //查询历史出库数据
  2989. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2990. var out_count_five int64
  2991. for _, item := range flowGood {
  2992. out_count_five += item.Count
  2993. }
  2994. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2995. if out_count_five != parseIntCount {
  2996. //查询耗材最后一次出库记录
  2997. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2998. //查询默认出库仓库库存
  2999. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3000. if len(wareOut) > 0 {
  3001. for _, it := range wareOut {
  3002. //回退库存
  3003. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3004. //删除出库记录
  3005. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3006. }
  3007. }
  3008. timeStr := time.Now().Format("2006-01-02")
  3009. timeArr := strings.Split(timeStr, "-")
  3010. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3011. total = total + 1
  3012. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3013. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3014. number = number + total
  3015. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3016. operation_time := time.Now().Unix()
  3017. creater := c.GetAdminUserInfo().AdminUser.Id
  3018. recordDateStr := time.Now().Format("2006-01-02")
  3019. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3020. nowtime := recordDate.Unix()
  3021. warehouseOut := models.WarehouseOut{
  3022. WarehouseOutOrderNumber: warehousing_out_order,
  3023. OperationTime: operation_time,
  3024. OrgId: adminInfo.CurrentOrgId,
  3025. Creater: creater,
  3026. Ctime: time.Now().Unix(),
  3027. Status: 1,
  3028. WarehouseOutTime: nowtime,
  3029. Type: 1,
  3030. StorehouseId: storeConfig.StorehouseOutInfo,
  3031. IsCheck: 1,
  3032. IsSys: 1,
  3033. }
  3034. //查询是否生成出库单
  3035. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3036. if out.ID == 0 {
  3037. service.AddSigleWarehouseOut(&warehouseOut)
  3038. }
  3039. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3040. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3041. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3042. dialyPrepareOne := models.DialysisBeforePrepare{
  3043. GoodTypeId: goodObj.GoodTypeId,
  3044. GoodId: item.ProjectId,
  3045. PatientId: item.PatientId,
  3046. RecordDate: item.RecordDate,
  3047. UserOrgId: adminInfo.CurrentOrgId,
  3048. Count: parseIntCount,
  3049. Ctime: time.Now().Unix(),
  3050. Creater: creater,
  3051. Status: 1,
  3052. StorehouseId: houseConfig.StorehouseOutInfo,
  3053. ProjectId: item.ID,
  3054. }
  3055. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3056. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3057. //查询历史出库数据
  3058. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3059. var out_count int64
  3060. for _, item := range flowGood {
  3061. out_count += item.Count
  3062. }
  3063. //如果历史数和当前数据不想等才进行退库出库
  3064. if out_count != parseIntCount {
  3065. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3066. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3067. detail := models.AutomaticReduceDetail{
  3068. WarehouseOutId: 0,
  3069. WarehouseOutOrderNumber: "",
  3070. PatientId: item.PatientId,
  3071. Ctime: time.Now().Unix(),
  3072. Mtime: 0,
  3073. Status: 1,
  3074. RecordTime: item.RecordDate,
  3075. OrgId: item.UserOrgId,
  3076. GoodId: item.ProjectId,
  3077. GoodTypeId: 0,
  3078. Count: parseIntCount,
  3079. Type: 0,
  3080. ProjectId: item.ID,
  3081. StorehouseId: 0,
  3082. }
  3083. service.CreateAutoDetail(detail)
  3084. //查询剩余库存
  3085. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3086. var sum_count int64
  3087. for _, item := range goodList {
  3088. sum_count += item.StockCount
  3089. }
  3090. //更新剩余库存
  3091. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3092. //耗材
  3093. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3094. }
  3095. }
  3096. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3097. //查询历史出库数据
  3098. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3099. var out_count int64
  3100. for _, item := range flowGood {
  3101. out_count += item.Count
  3102. }
  3103. //如果历史数和当前数据不想等才进行退库出库
  3104. if out_count != parseIntCount {
  3105. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3106. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3107. detail := models.AutomaticReduceDetail{
  3108. WarehouseOutId: 0,
  3109. WarehouseOutOrderNumber: "",
  3110. PatientId: item.PatientId,
  3111. Ctime: time.Now().Unix(),
  3112. Mtime: 0,
  3113. Status: 1,
  3114. RecordTime: item.RecordDate,
  3115. OrgId: item.UserOrgId,
  3116. GoodId: item.ProjectId,
  3117. GoodTypeId: 0,
  3118. Count: parseIntCount,
  3119. Type: 0,
  3120. ProjectId: item.ID,
  3121. StorehouseId: 0,
  3122. }
  3123. service.CreateAutoDetail(detail)
  3124. //查询剩余库存
  3125. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3126. var sum_count int64
  3127. for _, item := range goodList {
  3128. sum_count += item.StockCount
  3129. }
  3130. //更新剩余库存
  3131. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3132. //耗材
  3133. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3134. }
  3135. }
  3136. }
  3137. }
  3138. }
  3139. }
  3140. //redisClient := service.RedisClient()
  3141. //defer redisClient.Close()
  3142. //
  3143. //list := models.HisList{
  3144. // Patient_id: patient_id,
  3145. // Advice_id:0,
  3146. // Record_date: 0,
  3147. // Advice: adviceList,
  3148. // Project: nil,
  3149. //}
  3150. //hisLis = append(hisLis, list)
  3151. //
  3152. //advice_json, _ := json.Marshal(&hisLis)
  3153. //redisClient.RPush("111", advice_json).Result()
  3154. //result, _ := redisClient.RPop("111").Result()
  3155. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3156. //
  3157. //var dat []map[string]interface{}
  3158. //json.Unmarshal([]byte(result), &dat)
  3159. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3160. //
  3161. //for k,v:=range dat{
  3162. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3163. //}
  3164. //project_json, _ := json.Marshal(&projectList)
  3165. //redisClient.LPush("222", project_json).Result()
  3166. if err == nil {
  3167. c.ServeSuccessJSON(map[string]interface{}{
  3168. "msg": "保存成功",
  3169. })
  3170. return
  3171. } else {
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3173. return
  3174. }
  3175. }
  3176. func (c *HisApiController) EditHisPrescription() {
  3177. record_date := c.GetString("record_date")
  3178. patient_id, _ := c.GetInt64("patient_id")
  3179. reg_type, _ := c.GetInt64("reg_type")
  3180. //diagnose, _ := c.GetInt64("diagnose", 0)
  3181. diagnose := c.GetString("diagnose")
  3182. sick_type, _ := c.GetInt64("sick_type")
  3183. sick_history := c.GetString("sick_history")
  3184. doctor_id, _ := c.GetInt64("doctor", 0)
  3185. department, _ := c.GetInt64("department", 0)
  3186. his_patient_id, _ := c.GetInt64("his_patient_id")
  3187. p_type, _ := c.GetInt64("p_type")
  3188. dataBody := make(map[string]interface{}, 0)
  3189. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3190. if err != nil {
  3191. utils.ErrorLog(err.Error())
  3192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3193. return
  3194. }
  3195. timeLayout := "2006-01-02"
  3196. loc, _ := time.LoadLocation("Local")
  3197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3198. if err != nil {
  3199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3200. return
  3201. }
  3202. adminInfo := c.GetAdminUserInfo()
  3203. recordDateTime := theTime.Unix()
  3204. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3205. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3206. var hpInfo models.HisPrescriptionInfo
  3207. if info.ID == 0 {
  3208. var randNum int
  3209. randNum = rand.Intn(10000) + 1000
  3210. timestamp := time.Now().Unix()
  3211. tempTime := time.Unix(timestamp, 0)
  3212. timeFormat := tempTime.Format("20060102150405")
  3213. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3214. hpInfo = models.HisPrescriptionInfo{
  3215. UserOrgId: adminInfo.CurrentOrgId,
  3216. RecordDate: theTime.Unix(),
  3217. PatientId: patient_id,
  3218. Status: 1,
  3219. Ctime: time.Now().Unix(),
  3220. Mtime: time.Now().Unix(),
  3221. Creator: adminInfo.AdminUser.Id,
  3222. Modifier: adminInfo.AdminUser.Id,
  3223. Diagnosis: diagnose,
  3224. SickHistory: sick_history,
  3225. Departments: department,
  3226. RegisterType: reg_type,
  3227. PrescriptionNumber: p_number,
  3228. PrescriptionStatus: 1,
  3229. Doctor: role.UserName,
  3230. DoctorId: doctor_id,
  3231. SickType: sick_type,
  3232. PType: p_type,
  3233. }
  3234. service.SavePatientPrescriptionInfo(hpInfo)
  3235. } else {
  3236. hpInfo = models.HisPrescriptionInfo{
  3237. ID: info.ID,
  3238. UserOrgId: adminInfo.CurrentOrgId,
  3239. RecordDate: info.RecordDate,
  3240. PatientId: info.PatientId,
  3241. Status: 1,
  3242. Ctime: info.Ctime,
  3243. Mtime: time.Now().Unix(),
  3244. Creator: info.Creator,
  3245. Modifier: adminInfo.AdminUser.Id,
  3246. Diagnosis: diagnose,
  3247. SickHistory: sick_history,
  3248. Departments: department,
  3249. RegisterType: reg_type,
  3250. PrescriptionNumber: info.PrescriptionNumber,
  3251. Doctor: role.UserName,
  3252. PrescriptionStatus: info.PrescriptionStatus,
  3253. DoctorId: doctor_id,
  3254. SickType: sick_type,
  3255. PType: info.PType,
  3256. }
  3257. service.SavePatientPrescriptionInfo(hpInfo)
  3258. }
  3259. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3260. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3261. if len(prescriptions) > 0 {
  3262. for _, item := range prescriptions {
  3263. items := item.(map[string]interface{})
  3264. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3265. utils.ErrorLog("id")
  3266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3267. return
  3268. }
  3269. id := int64(items["id"].(float64))
  3270. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3271. utils.ErrorLog("type")
  3272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3273. return
  3274. }
  3275. types := int64(items["type"].(float64))
  3276. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3277. utils.ErrorLog("med_type")
  3278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3279. return
  3280. }
  3281. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3282. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3283. ctime := time.Now().Unix()
  3284. prescription := &models.HisPrescription{
  3285. ID: id,
  3286. PatientId: patient_id,
  3287. UserOrgId: adminInfo.CurrentOrgId,
  3288. RecordDate: recordDateTime,
  3289. Ctime: ctime,
  3290. Mtime: ctime,
  3291. Type: types,
  3292. Modifier: adminInfo.AdminUser.Id,
  3293. Creator: adminInfo.AdminUser.Id,
  3294. Status: 1,
  3295. Doctor: role.UserName,
  3296. HisPatientId: his_patient_id,
  3297. OrderStatus: 1,
  3298. BatchNumber: "",
  3299. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3300. PType: hpInfo.PType,
  3301. MedType: med_type,
  3302. }
  3303. if historyPrescription.ID > 0 {
  3304. prescription.PreTime = historyPrescription.PreTime
  3305. }
  3306. service.SaveHisPrescription(prescription)
  3307. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3308. advices := items["advices"].([]interface{})
  3309. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3310. groupNo := int64(0)
  3311. ctime := time.Now().Unix()
  3312. mtime := ctime
  3313. if len(advices) > 0 {
  3314. for _, advice := range advices {
  3315. var s models.HisDoctorAdviceInfo
  3316. s.PrescriptionId = prescription.ID
  3317. s.AdviceType = 2
  3318. s.AdviceDoctor = adminInfo.AdminUser.Id
  3319. s.StopState = 2
  3320. s.ExecutionState = 2
  3321. s.AdviceDate = recordDateTime
  3322. s.Status = 1
  3323. s.UserOrgId = adminInfo.CurrentOrgId
  3324. s.RecordDate = recordDateTime
  3325. s.StartTime = prescription.PreTime
  3326. s.Groupno = groupNo
  3327. s.CreatedTime = ctime
  3328. s.UpdatedTime = mtime
  3329. s.PatientId = patient_id
  3330. s.HisPatientId = his_patient_id
  3331. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3332. if errcode > 0 {
  3333. c.ServeFailJSONWithSGJErrorCode(errcode)
  3334. return
  3335. }
  3336. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3337. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3338. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3339. if s.Price == 0 {
  3340. s.Price = lastWarehouse.RetailPrice
  3341. }
  3342. }
  3343. service.CreateHisDoctorAdvice(&s)
  3344. //记录日志
  3345. byterequest, _ := json.Marshal(s)
  3346. adviceLog := models.XtDoctorAdviceLog{
  3347. UserOrgId: s.UserOrgId,
  3348. PatientId: s.PatientId,
  3349. AdminUserId: adminInfo.AdminUser.Id,
  3350. Module: 1,
  3351. ErrLog: string(byterequest),
  3352. Status: 1,
  3353. Ctime: time.Now().Unix(),
  3354. Mtime: 0,
  3355. Source: "电脑端his医嘱修改",
  3356. RecordDate: s.AdviceDate,
  3357. }
  3358. service.CreateDoctorAdviceLog(adviceLog)
  3359. redis := service.RedisClient()
  3360. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3361. redis.Set(key, "", time.Second)
  3362. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3363. fmt.Println("keyOne", keyOne)
  3364. redis.Set(keyOne, "", time.Second)
  3365. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3366. redis.Set(keySeven, "", time.Second)
  3367. redis.Close()
  3368. }
  3369. }
  3370. }
  3371. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3372. projects := items["project"].([]interface{})
  3373. if len(projects) > 0 {
  3374. for _, project := range projects {
  3375. var p models.HisPrescriptionProject
  3376. p.PrescriptionId = prescription.ID
  3377. p.Ctime = time.Now().Unix()
  3378. p.Mtime = time.Now().Unix()
  3379. p.PatientId = patient_id
  3380. p.RecordDate = recordDateTime
  3381. p.UserOrgId = adminInfo.CurrentOrgId
  3382. p.HisPatientId = his_patient_id
  3383. p.Status = 1
  3384. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3385. if errcode > 0 {
  3386. c.ServeFailJSONWithSGJErrorCode(errcode)
  3387. return
  3388. }
  3389. service.CreateHisProjectTwo(&p)
  3390. //记录日志
  3391. byterequest, _ := json.Marshal(p)
  3392. adviceLog := models.XtDoctorAdviceLog{
  3393. UserOrgId: p.UserOrgId,
  3394. PatientId: p.PatientId,
  3395. AdminUserId: adminInfo.AdminUser.Id,
  3396. Module: 1,
  3397. ErrLog: string(byterequest),
  3398. Status: 1,
  3399. Ctime: time.Now().Unix(),
  3400. Mtime: 0,
  3401. Source: "电脑端his项目修改",
  3402. RecordDate: p.RecordDate,
  3403. }
  3404. service.CreateDoctorAdviceLog(adviceLog)
  3405. }
  3406. }
  3407. }
  3408. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3409. addition := items["addition"].([]interface{})
  3410. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3411. ctime := time.Now().Unix()
  3412. mtime := ctime
  3413. if len(addition) > 0 {
  3414. for _, item := range addition {
  3415. var s models.HisAdditionalCharge
  3416. s.PrescriptionId = prescription.ID
  3417. s.Status = 1
  3418. s.UserOrgId = adminInfo.CurrentOrgId
  3419. s.RecordDate = recordDateTime
  3420. s.CreatedTime = ctime
  3421. s.UpdatedTime = mtime
  3422. s.PatientId = patient_id
  3423. s.HisPatientId = his_patient_id
  3424. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3425. if errcode > 0 {
  3426. c.ServeFailJSONWithSGJErrorCode(errcode)
  3427. return
  3428. }
  3429. service.CreateAdditionalCharge(&s)
  3430. }
  3431. }
  3432. }
  3433. }
  3434. }
  3435. }
  3436. if err == nil {
  3437. c.ServeSuccessJSON(map[string]interface{}{
  3438. "msg": "保存成功",
  3439. })
  3440. return
  3441. } else {
  3442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3443. return
  3444. }
  3445. }
  3446. func (c *HisApiController) DeletePrescription() {
  3447. prescription_id, _ := c.GetInt64("id")
  3448. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3449. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3450. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3451. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3452. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3453. //耗材保存处方出库
  3454. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3455. //已收费和已发药限制逻辑
  3456. isCharge := false
  3457. isMedicine := false
  3458. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3459. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3460. for _, item := range new_prescriptions {
  3461. if item.IsMedicine == 1 {
  3462. isMedicine = true
  3463. }
  3464. }
  3465. for _, item := range new_prescriptions {
  3466. if item.OrderStatus == 4 {
  3467. isCharge = true
  3468. }
  3469. }
  3470. if p_err != nil {
  3471. if new_prescription.ID > 0 {
  3472. if new_prescription.OrderStatus == 2 {
  3473. isCharge = true
  3474. }
  3475. }
  3476. }
  3477. for _, item := range advices {
  3478. if item.IsMedicine == 1 {
  3479. isMedicine = true
  3480. }
  3481. }
  3482. if isCharge {
  3483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3484. return
  3485. }
  3486. if isMedicine {
  3487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3488. return
  3489. }
  3490. //已收费和已发药限制逻辑
  3491. if len(projects) > 0 {
  3492. for _, item := range projects {
  3493. service.DeletePrintInfo(item.ID) //删除打印信息
  3494. if goodOutConfig.IsOpen != 1 {
  3495. if stockConfig.IsOpen == 1 {
  3496. if item.Type == 3 && item.IsOut == 1 {
  3497. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3498. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3499. good.Total = good.Total + f_count
  3500. service.UpdateGoodInfo(&good)
  3501. operation_time := time.Now().Unix()
  3502. creater := c.GetAdminUserInfo().AdminUser.Id
  3503. //创建退库单
  3504. timeStr := time.Now().Format("2006-01-02")
  3505. timeArr := strings.Split(timeStr, "-")
  3506. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3507. total = total + 1
  3508. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3509. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3510. cancelStock := models.CancelStock{
  3511. OrderNumber: orderNumber,
  3512. OperaTime: operation_time,
  3513. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3514. Creater: creater,
  3515. Ctime: time.Now().Unix(),
  3516. Status: 1,
  3517. ReturnTime: item.RecordDate,
  3518. Type: 1,
  3519. StorehouseId: houseConfig.StorehouseOutInfo,
  3520. IsCheck: 1,
  3521. }
  3522. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3523. if msgerrkonde == gorm.ErrRecordNotFound {
  3524. service.AddSigleCancelStock(&cancelStock)
  3525. }
  3526. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3527. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3528. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3529. //查询该耗材是否出库
  3530. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3531. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3532. deaerler, _ := service.GetDealerById(info.Dealer)
  3533. var total_count int64
  3534. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3535. total_count += count
  3536. if info.ID > 0 {
  3537. if info.Count >= total_count {
  3538. //回退库存
  3539. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3540. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3541. var flush_count int64
  3542. for _, it := range goodList {
  3543. flush_count += it.StockCount
  3544. }
  3545. cancelStockInfo := models.CancelStockInfo{
  3546. GoodId: item.ProjectId,
  3547. CancelStockId: cancel.ID,
  3548. GoodTypeId: good.GoodTypeId,
  3549. Count: prescribingNumber,
  3550. Price: info.Price,
  3551. Total: 0,
  3552. ProductDate: info.ProductDate,
  3553. ExpiryDate: info.ExpiryDate,
  3554. Ctime: time.Now().Unix(),
  3555. Status: 1,
  3556. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3557. OrderNumber: cancel.OrderNumber,
  3558. Type: 0,
  3559. Dealer: deaerler.DealerName,
  3560. Manufacturer: manufacturer.ManufacturerName,
  3561. Number: info.Number,
  3562. RegisterAccount: "",
  3563. Remark: "",
  3564. WarehouseInfoId: info.WarehouseInfotId,
  3565. PatientId: info.PatientId,
  3566. RecordDate: info.SysRecordTime,
  3567. StorehouseId: houseConfig.StorehouseOutInfo,
  3568. IsCheck: 1,
  3569. }
  3570. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3571. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3572. flow := models.VmStockFlow{
  3573. WarehousingId: info.WarehouseInfotId,
  3574. GoodId: item.ProjectId,
  3575. Number: info.Number,
  3576. LicenseNumber: info.LicenseNumber,
  3577. Count: prescribingNumber,
  3578. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3579. PatientId: item.PatientId,
  3580. SystemTime: info.SysRecordTime,
  3581. ConsumableType: 7,
  3582. IsSys: 0,
  3583. WarehousingOrder: "",
  3584. WarehouseOutId: info.WarehouseOutId,
  3585. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3586. IsEdit: 0,
  3587. CancelStockId: cancel.ID,
  3588. CancelOrderNumber: cancel.OrderNumber,
  3589. Manufacturer: manufacturer.ID,
  3590. Dealer: 0,
  3591. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3592. UpdateCreator: 0,
  3593. Status: 1,
  3594. Ctime: time.Now().Unix(),
  3595. Mtime: 0,
  3596. Price: info.Price,
  3597. WarehousingDetailId: info.WarehouseInfotId,
  3598. WarehouseOutDetailId: info.ID,
  3599. CancelOutDetailId: cancelInfo.ID,
  3600. ProductDate: info.ProductDate,
  3601. ExpireDate: info.ExpiryDate,
  3602. StorehouseId: houseConfig.StorehouseOutInfo,
  3603. OverCount: flush_count,
  3604. }
  3605. service.CreateStockFlowOne(flow)
  3606. //退库数量增加
  3607. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3608. //出库数量减少
  3609. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3610. }
  3611. if info.Count < total_count {
  3612. //回退库存
  3613. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3614. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3615. var flush_count int64
  3616. for _, it := range goodList {
  3617. flush_count += it.StockCount
  3618. }
  3619. cancelStockInfo := models.CancelStockInfo{
  3620. GoodId: item.ProjectId,
  3621. CancelStockId: cancel.ID,
  3622. GoodTypeId: good.GoodTypeId,
  3623. Count: info.Count,
  3624. Price: info.Price,
  3625. Total: 0,
  3626. ProductDate: info.ProductDate,
  3627. ExpiryDate: info.ExpiryDate,
  3628. Ctime: time.Now().Unix(),
  3629. Status: 1,
  3630. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3631. OrderNumber: cancel.OrderNumber,
  3632. Type: 0,
  3633. Dealer: deaerler.DealerName,
  3634. Manufacturer: manufacturer.ManufacturerName,
  3635. Number: info.Number,
  3636. RegisterAccount: "",
  3637. Remark: "",
  3638. WarehouseInfoId: info.WarehouseInfotId,
  3639. PatientId: info.PatientId,
  3640. RecordDate: info.SysRecordTime,
  3641. StorehouseId: houseConfig.StorehouseOutInfo,
  3642. IsCheck: 1,
  3643. }
  3644. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3645. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3646. flow := models.VmStockFlow{
  3647. WarehousingId: info.WarehouseInfotId,
  3648. GoodId: item.ProjectId,
  3649. Number: info.Number,
  3650. LicenseNumber: info.LicenseNumber,
  3651. Count: info.Count,
  3652. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3653. PatientId: item.PatientId,
  3654. SystemTime: info.SysRecordTime,
  3655. ConsumableType: 7,
  3656. IsSys: 0,
  3657. WarehousingOrder: "",
  3658. WarehouseOutId: info.WarehouseOutId,
  3659. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3660. IsEdit: 0,
  3661. CancelStockId: cancel.ID,
  3662. CancelOrderNumber: cancel.OrderNumber,
  3663. Manufacturer: manufacturer.ID,
  3664. Dealer: 0,
  3665. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3666. UpdateCreator: 0,
  3667. Status: 1,
  3668. Ctime: time.Now().Unix(),
  3669. Mtime: 0,
  3670. Price: info.Price,
  3671. WarehousingDetailId: info.WarehouseInfotId,
  3672. WarehouseOutDetailId: info.ID,
  3673. CancelOutDetailId: cancelInfo.ID,
  3674. ProductDate: info.ProductDate,
  3675. ExpireDate: info.ExpiryDate,
  3676. StorehouseId: houseConfig.StorehouseOutInfo,
  3677. OverCount: flush_count,
  3678. }
  3679. service.CreateStockFlowOne(flow)
  3680. //退库数量增加
  3681. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3682. //出库数量减少
  3683. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3684. }
  3685. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3686. var flush_count int64
  3687. for _, it := range goodList {
  3688. flush_count += it.StockCount
  3689. }
  3690. //查询已出库数量
  3691. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3692. if prescribingNumber < dialysisInfo.Count {
  3693. //改变数量
  3694. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3695. }
  3696. if prescribingNumber >= dialysisInfo.Count {
  3697. //删除出库表
  3698. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3699. }
  3700. //更新库存
  3701. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3702. //更新基础库库存
  3703. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3704. }
  3705. }
  3706. }
  3707. }
  3708. //保存耗材出库
  3709. if goodOutConfig.IsOpen == 1 {
  3710. if item.Type == 3 {
  3711. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3712. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3713. good.Total = good.Total + f_count
  3714. service.UpdateGoodInfo(&good)
  3715. operation_time := time.Now().Unix()
  3716. creater := c.GetAdminUserInfo().AdminUser.Id
  3717. //创建退库单
  3718. timeStr := time.Now().Format("2006-01-02")
  3719. timeArr := strings.Split(timeStr, "-")
  3720. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3721. total = total + 1
  3722. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3723. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3724. cancelStock := models.CancelStock{
  3725. OrderNumber: orderNumber,
  3726. OperaTime: operation_time,
  3727. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3728. Creater: creater,
  3729. Ctime: time.Now().Unix(),
  3730. Status: 1,
  3731. ReturnTime: item.RecordDate,
  3732. Type: 1,
  3733. StorehouseId: houseConfig.StorehouseOutInfo,
  3734. IsCheck: 1,
  3735. }
  3736. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3737. if msgerrkonde == gorm.ErrRecordNotFound {
  3738. service.AddSigleCancelStock(&cancelStock)
  3739. }
  3740. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3741. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3742. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3743. //查询该耗材是否出库
  3744. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3745. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3746. deaerler, _ := service.GetDealerById(info.Dealer)
  3747. var total_count int64
  3748. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3749. total_count += count
  3750. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3751. var flush_count int64
  3752. for _, it := range goodList {
  3753. flush_count += it.StockCount
  3754. }
  3755. fmt.Println("历史出库数据", info.Count)
  3756. fmt.Println("出库数量", total_count)
  3757. if info.ID > 0 {
  3758. cancelStockInfo := models.CancelStockInfo{
  3759. GoodId: item.ProjectId,
  3760. CancelStockId: cancel.ID,
  3761. GoodTypeId: good.GoodTypeId,
  3762. Count: prescribingNumber,
  3763. Price: info.Price,
  3764. Total: 0,
  3765. ProductDate: info.ProductDate,
  3766. ExpiryDate: info.ExpiryDate,
  3767. Ctime: time.Now().Unix(),
  3768. Status: 1,
  3769. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3770. OrderNumber: cancel.OrderNumber,
  3771. Type: 0,
  3772. Dealer: deaerler.DealerName,
  3773. Manufacturer: manufacturer.ManufacturerName,
  3774. Number: info.Number,
  3775. RegisterAccount: "",
  3776. Remark: "",
  3777. WarehouseInfoId: info.WarehouseInfotId,
  3778. PatientId: info.PatientId,
  3779. RecordDate: info.SysRecordTime,
  3780. StorehouseId: houseConfig.StorehouseOutInfo,
  3781. IsCheck: 1,
  3782. }
  3783. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3784. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3785. //查询出库数量
  3786. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3787. //出库数据 大于 退库数量
  3788. if len(list) > 0 {
  3789. for _, it := range list {
  3790. //回退库存
  3791. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3792. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3793. var flush_count_one int64
  3794. for _, it := range goodList {
  3795. flush_count_one += it.StockCount
  3796. }
  3797. //查询该批次是否有退库数据
  3798. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3799. creater := c.GetAdminUserInfo().AdminUser.Id
  3800. flow := models.VmStockFlow{
  3801. WarehousingId: it.WarehouseInfotId,
  3802. GoodId: it.GoodId,
  3803. Number: it.Number,
  3804. LicenseNumber: it.LicenseNumber,
  3805. Count: it.Count,
  3806. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3807. PatientId: it.PatientId,
  3808. SystemTime: it.SysRecordTime,
  3809. ConsumableType: 7,
  3810. IsSys: 0,
  3811. WarehousingOrder: "",
  3812. WarehouseOutId: it.WarehouseOutId,
  3813. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3814. IsEdit: 0,
  3815. CancelStockId: cancel.ID,
  3816. CancelOrderNumber: cancel.OrderNumber,
  3817. Manufacturer: manufacturer.ID,
  3818. Dealer: 0,
  3819. Creator: creater,
  3820. UpdateCreator: 0,
  3821. Status: 1,
  3822. Ctime: time.Now().Unix(),
  3823. Mtime: 0,
  3824. Price: it.Price,
  3825. WarehousingDetailId: it.WarehouseInfotId,
  3826. WarehouseOutDetailId: it.ID,
  3827. CancelOutDetailId: cancelInfo.ID,
  3828. ProductDate: it.ProductDate,
  3829. ExpireDate: it.ExpiryDate,
  3830. StorehouseId: houseConfig.StorehouseOutInfo,
  3831. OverCount: flush_count_one,
  3832. }
  3833. service.CreateStockFlowOne(flow)
  3834. //if flow.ID > 0 {
  3835. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3836. //}
  3837. }
  3838. }
  3839. //flow := models.VmStockFlow{
  3840. // WarehousingId: info.WarehouseInfotId,
  3841. // GoodId: item.ProjectId,
  3842. // Number: info.Number,
  3843. // LicenseNumber: info.LicenseNumber,
  3844. // Count: prescribingNumber,
  3845. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3846. // PatientId: item.PatientId,
  3847. // SystemTime: info.SysRecordTime,
  3848. // ConsumableType: 7,
  3849. // IsSys: 0,
  3850. // WarehousingOrder: "",
  3851. // WarehouseOutId: info.WarehouseOutId,
  3852. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3853. // IsEdit: 0,
  3854. // CancelStockId: cancel.ID,
  3855. // CancelOrderNumber: cancel.OrderNumber,
  3856. // Manufacturer: manufacturer.ID,
  3857. // Dealer: 0,
  3858. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3859. // UpdateCreator: 0,
  3860. // Status: 1,
  3861. // Ctime: time.Now().Unix(),
  3862. // Mtime: 0,
  3863. // Price: info.Price,
  3864. // WarehousingDetailId: info.WarehouseInfotId,
  3865. // WarehouseOutDetailId: info.ID,
  3866. // CancelOutDetailId: cancelInfo.ID,
  3867. // ProductDate: info.ProductDate,
  3868. // ExpireDate: info.ExpiryDate,
  3869. // StorehouseId: houseConfig.StorehouseOutInfo,
  3870. // OverCount: flush_count,
  3871. //}
  3872. //service.CreateStockFlowOne(flow)
  3873. //退库数量增加
  3874. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3875. //出库数量减少
  3876. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3877. //查询已出库数量
  3878. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3879. if prescribingNumber < dialysisInfo.Count {
  3880. //改变数量
  3881. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3882. }
  3883. if prescribingNumber >= dialysisInfo.Count {
  3884. //删除出库表
  3885. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3886. }
  3887. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3888. var flush_count_one int64
  3889. for _, it := range goodList {
  3890. flush_count_one += it.StockCount
  3891. }
  3892. //更新库存
  3893. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3894. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3895. //更新基础库库存
  3896. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3897. }
  3898. }
  3899. }
  3900. }
  3901. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3902. fmt.Println(err)
  3903. }
  3904. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3905. fmt.Println(err)
  3906. if len(advices) > 0 {
  3907. for _, item := range advices {
  3908. redis := service.RedisClient()
  3909. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3910. redis.Set(keyFive, "", time.Second)
  3911. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3912. redis.Set(keyOne, "", time.Second)
  3913. redis.Close()
  3914. }
  3915. }
  3916. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3917. if len(advices) > 0 {
  3918. for _, item := range advices {
  3919. creater := c.GetAdminUserInfo().AdminUser.Id
  3920. service.DrugAutoAddCancelInfo(item, creater)
  3921. }
  3922. }
  3923. } else {
  3924. if drugOutConfig.IsOpen == 1 {
  3925. if len(advices) > 0 {
  3926. for _, item := range advices {
  3927. creater := c.GetAdminUserInfo().AdminUser.Id
  3928. service.DrugAutoAddCancelInfo(item, creater)
  3929. }
  3930. }
  3931. } else {
  3932. if len(advices) > 0 {
  3933. for _, item := range advices {
  3934. creater := c.GetAdminUserInfo().AdminUser.Id
  3935. service.DrugAutoAddCancelInfo(item, creater)
  3936. }
  3937. }
  3938. }
  3939. }
  3940. c.ServeSuccessJSON(map[string]interface{}{
  3941. "msg": "删除成功",
  3942. })
  3943. return
  3944. }
  3945. func (c *HisApiController) DeleteDoctorAdvice() {
  3946. id, _ := c.GetInt64("id")
  3947. advice, _ := service.GetHisDoctorAdvicesById(id)
  3948. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3949. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3950. //已收费和已发药的限制逻辑
  3951. isCharge := false
  3952. isMedicine := false
  3953. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3954. //获取今天该患者所有处方,判断是否发药或者收费
  3955. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3956. for _, item := range new_prescriptions {
  3957. if item.IsMedicine == 1 {
  3958. isMedicine = true
  3959. }
  3960. }
  3961. for _, item := range new_prescriptions {
  3962. if item.OrderStatus == 4 {
  3963. isCharge = true
  3964. }
  3965. }
  3966. if isMedicine {
  3967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3968. return
  3969. }
  3970. if isCharge {
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3972. return
  3973. }
  3974. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3975. for _, item := range advices {
  3976. if item.IsMedicine == 1 {
  3977. isMedicine = true
  3978. }
  3979. }
  3980. if isMedicine {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3982. return
  3983. }
  3984. if new_prescription.ID > 0 {
  3985. if new_prescription.OrderStatus == 2 {
  3986. isCharge = true
  3987. }
  3988. }
  3989. if isCharge {
  3990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3991. return
  3992. }
  3993. //已收费和已发药的限制逻辑
  3994. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3995. redis := service.RedisClient()
  3996. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3997. redis.Set(keyFive, "", time.Second)
  3998. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3999. redis.Set(keyOne, "", time.Second)
  4000. defer redis.Close()
  4001. if err == nil {
  4002. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4003. //查询是否在处方中出库
  4004. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4005. if openConfig.IsOpen != 1 {
  4006. //判断该医嘱是否执行了
  4007. if advice.ExecutionState == 1 {
  4008. creater := c.GetAdminUserInfo().AdminUser.Id
  4009. service.DrugAutoAddCancelInfo(&advice, creater)
  4010. }
  4011. }
  4012. //开启保存处方扣减功能
  4013. if openConfig.IsOpen == 1 {
  4014. creater := c.GetAdminUserInfo().AdminUser.Id
  4015. service.DrugAutoAddCancelInfo(&advice, creater)
  4016. }
  4017. } else {
  4018. if drugOutConfig.IsOpen == 1 {
  4019. //查询是否在处方中出库
  4020. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4021. if openConfig.IsOpen != 1 {
  4022. //判断该医嘱是否执行了
  4023. if advice.ExecutionState == 1 {
  4024. creater := c.GetAdminUserInfo().AdminUser.Id
  4025. service.DrugAutoAddCancelInfo(&advice, creater)
  4026. }
  4027. }
  4028. //开启保存处方扣减功能
  4029. if openConfig.IsOpen == 1 {
  4030. creater := c.GetAdminUserInfo().AdminUser.Id
  4031. service.DrugAutoAddCancelInfo(&advice, creater)
  4032. }
  4033. } else {
  4034. //判断该医嘱是否执行了
  4035. if advice.ExecutionState == 1 {
  4036. creater := c.GetAdminUserInfo().AdminUser.Id
  4037. service.DrugAutoAddCancelInfo(&advice, creater)
  4038. }
  4039. }
  4040. }
  4041. c.ServeSuccessJSON(map[string]interface{}{
  4042. "msg": "删除成功",
  4043. })
  4044. return
  4045. } else {
  4046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4047. return
  4048. }
  4049. }
  4050. func (c *HisApiController) DeleteProject() {
  4051. id, _ := c.GetInt64("id")
  4052. adminInfo := c.GetAdminUserInfo()
  4053. project, _ := service.GetHisProjectByID(id)
  4054. // var consumable models.DialysisBeforePrepare
  4055. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4056. //耗材保存处方出库
  4057. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4058. isCharge := false
  4059. isMedicine := false
  4060. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4061. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4062. for _, item := range new_prescriptions {
  4063. if item.IsMedicine == 1 {
  4064. isMedicine = true
  4065. }
  4066. }
  4067. for _, item := range new_prescriptions {
  4068. if item.OrderStatus == 4 {
  4069. isCharge = true
  4070. }
  4071. }
  4072. if isMedicine {
  4073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4074. return
  4075. }
  4076. if isCharge {
  4077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4078. return
  4079. }
  4080. if new_prescription.ID > 0 {
  4081. if new_prescription.OrderStatus == 2 {
  4082. isCharge = true
  4083. }
  4084. }
  4085. if isCharge {
  4086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4087. return
  4088. }
  4089. service.DeletePrintInfo(id)
  4090. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4091. label.Status = 0
  4092. service.CreateHisLabelRecord(&label)
  4093. fmt.Println(goodOutConfig.IsOpen)
  4094. if goodOutConfig.IsOpen != 1 {
  4095. if stockConfig.IsOpen == 1 {
  4096. if project.Type == 2 {
  4097. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4098. fmt.Println(err)
  4099. }
  4100. if project.Type == 3 && project.IsOut == 1 {
  4101. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4102. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4103. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4104. operation_time := time.Now().Unix()
  4105. creater := adminInfo.AdminUser.Id
  4106. //创建退库单
  4107. timeStr := time.Now().Format("2006-01-02")
  4108. timeArr := strings.Split(timeStr, "-")
  4109. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4110. total = total + 1
  4111. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4112. cancelStock := models.CancelStock{
  4113. OrderNumber: orderNumber,
  4114. OperaTime: operation_time,
  4115. OrgId: adminInfo.CurrentOrgId,
  4116. Creater: creater,
  4117. Ctime: time.Now().Unix(),
  4118. Status: 1,
  4119. ReturnTime: project.RecordDate,
  4120. Type: 1,
  4121. StorehouseId: houseConfig.StorehouseOutInfo,
  4122. IsCheck: 1,
  4123. }
  4124. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4125. if msgerrkonde == gorm.ErrRecordNotFound {
  4126. service.AddSigleCancelStock(&cancelStock)
  4127. }
  4128. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4129. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4130. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4131. //查询是否有出库
  4132. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4133. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4134. deaerler, _ := service.GetDealerById(info.Dealer)
  4135. if info.ID > 0 {
  4136. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4137. if info.Count >= prescribingNumber {
  4138. cancelStockInfo := models.CancelStockInfo{
  4139. GoodId: project.ProjectId,
  4140. CancelStockId: cancel.ID,
  4141. GoodTypeId: good.GoodTypeId,
  4142. Count: prescribingNumber,
  4143. Price: info.Price,
  4144. Total: 0,
  4145. ProductDate: info.ProductDate,
  4146. ExpiryDate: info.ExpiryDate,
  4147. Ctime: time.Now().Unix(),
  4148. Status: 1,
  4149. OrgId: adminInfo.CurrentOrgId,
  4150. OrderNumber: cancel.OrderNumber,
  4151. Type: 0,
  4152. Dealer: deaerler.DealerName,
  4153. Manufacturer: manufacturer.ManufacturerName,
  4154. Number: info.Number,
  4155. RegisterAccount: "",
  4156. Remark: "",
  4157. WarehouseInfoId: info.WarehouseInfotId,
  4158. PatientId: info.PatientId,
  4159. RecordDate: info.SysRecordTime,
  4160. StorehouseId: houseConfig.StorehouseOutInfo,
  4161. IsCheck: 1,
  4162. }
  4163. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4164. //回退库存
  4165. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4166. //退库数量增加
  4167. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4168. //出库数量减少
  4169. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4170. }
  4171. if info.Count < prescribingNumber {
  4172. cancelStockInfo := models.CancelStockInfo{
  4173. GoodId: project.ProjectId,
  4174. CancelStockId: cancel.ID,
  4175. GoodTypeId: good.GoodTypeId,
  4176. Count: info.Count,
  4177. Price: info.Price,
  4178. Total: 0,
  4179. ProductDate: info.ProductDate,
  4180. ExpiryDate: info.ExpiryDate,
  4181. Ctime: time.Now().Unix(),
  4182. Status: 1,
  4183. OrgId: adminInfo.CurrentOrgId,
  4184. OrderNumber: cancel.OrderNumber,
  4185. Type: 0,
  4186. Dealer: deaerler.DealerName,
  4187. Manufacturer: manufacturer.ManufacturerName,
  4188. Number: info.Number,
  4189. RegisterAccount: "",
  4190. Remark: "",
  4191. WarehouseInfoId: info.WarehouseInfotId,
  4192. PatientId: info.PatientId,
  4193. RecordDate: info.SysRecordTime,
  4194. StorehouseId: houseConfig.StorehouseOutInfo,
  4195. IsCheck: 1,
  4196. }
  4197. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4198. //回退库存
  4199. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4200. //退库数量增加
  4201. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4202. //出库数量减少
  4203. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4204. }
  4205. //查询剩余库存
  4206. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4207. var over_count int64
  4208. for _, it := range goodList {
  4209. over_count += it.StockCount
  4210. }
  4211. //出库数据 大于 退库数量
  4212. if info.Count >= prescribingNumber {
  4213. flow := models.VmStockFlow{
  4214. WarehousingId: info.WarehouseInfotId,
  4215. GoodId: project.ProjectId,
  4216. Number: info.Number,
  4217. LicenseNumber: info.LicenseNumber,
  4218. Count: prescribingNumber,
  4219. UserOrgId: adminInfo.CurrentOrgId,
  4220. PatientId: project.PatientId,
  4221. SystemTime: info.SysRecordTime,
  4222. ConsumableType: 7,
  4223. IsSys: 0,
  4224. WarehousingOrder: "",
  4225. WarehouseOutId: info.WarehouseOutId,
  4226. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4227. IsEdit: 0,
  4228. CancelStockId: cancel.ID,
  4229. CancelOrderNumber: cancel.OrderNumber,
  4230. Manufacturer: manufacturer.ID,
  4231. Dealer: 0,
  4232. Creator: adminInfo.AdminUser.Id,
  4233. UpdateCreator: 0,
  4234. Status: 1,
  4235. Ctime: time.Now().Unix(),
  4236. Mtime: 0,
  4237. Price: info.Price,
  4238. WarehousingDetailId: info.WarehouseInfotId,
  4239. WarehouseOutDetailId: info.ID,
  4240. CancelOutDetailId: cancelInfo.ID,
  4241. ProductDate: info.ProductDate,
  4242. ExpireDate: info.ExpiryDate,
  4243. StorehouseId: houseConfig.StorehouseOutInfo,
  4244. OverCount: over_count,
  4245. }
  4246. service.CreateStockFlowOne(flow)
  4247. }
  4248. //出库数据小于退库数据
  4249. if info.Count < prescribingNumber {
  4250. flow := models.VmStockFlow{
  4251. WarehousingId: info.WarehouseInfotId,
  4252. GoodId: project.ProjectId,
  4253. Number: info.Number,
  4254. LicenseNumber: info.LicenseNumber,
  4255. Count: info.Count,
  4256. UserOrgId: adminInfo.CurrentOrgId,
  4257. PatientId: project.PatientId,
  4258. SystemTime: info.SysRecordTime,
  4259. ConsumableType: 7,
  4260. IsSys: 0,
  4261. WarehousingOrder: "",
  4262. WarehouseOutId: info.WarehouseOutId,
  4263. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4264. IsEdit: 0,
  4265. CancelStockId: cancel.ID,
  4266. CancelOrderNumber: cancel.OrderNumber,
  4267. Manufacturer: manufacturer.ID,
  4268. Dealer: 0,
  4269. Creator: adminInfo.AdminUser.Id,
  4270. UpdateCreator: 0,
  4271. Status: 1,
  4272. Ctime: time.Now().Unix(),
  4273. Mtime: 0,
  4274. Price: info.Price,
  4275. WarehousingDetailId: info.WarehouseInfotId,
  4276. WarehouseOutDetailId: info.ID,
  4277. CancelOutDetailId: cancelInfo.ID,
  4278. ProductDate: info.ProductDate,
  4279. ExpireDate: info.ExpiryDate,
  4280. StorehouseId: houseConfig.StorehouseOutInfo,
  4281. OverCount: over_count,
  4282. }
  4283. service.CreateStockFlowOne(flow)
  4284. }
  4285. //查询已出库数量
  4286. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4287. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4288. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4289. if prescribingNumber < dialysisInfo.Count {
  4290. //改变数量
  4291. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4292. }
  4293. if prescribingNumber >= dialysisInfo.Count {
  4294. //删除出库表
  4295. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4296. }
  4297. //更新剩余库存
  4298. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4299. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4300. var total_count_one int64
  4301. for _, it := range stockList {
  4302. total_count_one += it.StockCount
  4303. }
  4304. //基础库插入数据
  4305. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4306. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4307. var flush_count int64
  4308. for _, it := range goodListOne {
  4309. flush_count += it.StockCount
  4310. }
  4311. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4312. if errs != nil {
  4313. goodErrcode := models.XtGoodErrcode{
  4314. UserOrgId: project.UserOrgId,
  4315. Errcode: "手动出库更新剩余出库失败",
  4316. GoodId: project.ProjectId,
  4317. Status: 1,
  4318. Ctime: time.Now().Unix(),
  4319. Mtime: 0,
  4320. Count: 0,
  4321. StockCount: 0,
  4322. Creater: creater,
  4323. BatchNumberId: 0,
  4324. WarehouseOutId: 0,
  4325. }
  4326. service.CreateGoodErrcode(goodErrcode)
  4327. }
  4328. }
  4329. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4330. fmt.Println(err)
  4331. } else {
  4332. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4333. fmt.Println(err)
  4334. }
  4335. } else {
  4336. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4337. fmt.Println(err)
  4338. }
  4339. }
  4340. //保存处方出库
  4341. if goodOutConfig.IsOpen == 1 {
  4342. if project.Type == 3 {
  4343. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4344. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4345. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4346. operation_time := time.Now().Unix()
  4347. creater := adminInfo.AdminUser.Id
  4348. //创建退库单
  4349. timeStr := time.Now().Format("2006-01-02")
  4350. timeArr := strings.Split(timeStr, "-")
  4351. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4352. total = total + 1
  4353. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4354. cancelStock := models.CancelStock{
  4355. OrderNumber: orderNumber,
  4356. OperaTime: operation_time,
  4357. OrgId: adminInfo.CurrentOrgId,
  4358. Creater: creater,
  4359. Ctime: time.Now().Unix(),
  4360. Status: 1,
  4361. ReturnTime: project.RecordDate,
  4362. Type: 1,
  4363. StorehouseId: houseConfig.StorehouseOutInfo,
  4364. IsCheck: 1,
  4365. }
  4366. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4367. if msgerrkonde == gorm.ErrRecordNotFound {
  4368. service.AddSigleCancelStock(&cancelStock)
  4369. }
  4370. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4371. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4372. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4373. //获取出库数据
  4374. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4375. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4376. deaerler, _ := service.GetDealerById(info.Dealer)
  4377. if info.ID > 0 {
  4378. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4379. if info.Count >= prescribingNumber {
  4380. cancelStockInfo := models.CancelStockInfo{
  4381. GoodId: project.ProjectId,
  4382. CancelStockId: cancel.ID,
  4383. GoodTypeId: good.GoodTypeId,
  4384. Count: prescribingNumber,
  4385. Price: info.Price,
  4386. Total: 0,
  4387. ProductDate: info.ProductDate,
  4388. ExpiryDate: info.ExpiryDate,
  4389. Ctime: time.Now().Unix(),
  4390. Status: 1,
  4391. OrgId: adminInfo.CurrentOrgId,
  4392. OrderNumber: cancel.OrderNumber,
  4393. Type: 0,
  4394. Dealer: deaerler.DealerName,
  4395. Manufacturer: manufacturer.ManufacturerName,
  4396. Number: info.Number,
  4397. RegisterAccount: "",
  4398. Remark: "",
  4399. WarehouseInfoId: info.WarehouseInfotId,
  4400. PatientId: info.PatientId,
  4401. RecordDate: info.SysRecordTime,
  4402. StorehouseId: houseConfig.StorehouseOutInfo,
  4403. IsCheck: 1,
  4404. }
  4405. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4406. //退库数量增加
  4407. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4408. //出库数量减少
  4409. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4410. }
  4411. if info.Count < prescribingNumber {
  4412. cancelStockInfo := models.CancelStockInfo{
  4413. GoodId: project.ProjectId,
  4414. CancelStockId: cancel.ID,
  4415. GoodTypeId: good.GoodTypeId,
  4416. Count: prescribingNumber,
  4417. Price: info.Price,
  4418. Total: 0,
  4419. ProductDate: info.ProductDate,
  4420. ExpiryDate: info.ExpiryDate,
  4421. Ctime: time.Now().Unix(),
  4422. Status: 1,
  4423. OrgId: adminInfo.CurrentOrgId,
  4424. OrderNumber: cancel.OrderNumber,
  4425. Type: 0,
  4426. Dealer: deaerler.DealerName,
  4427. Manufacturer: manufacturer.ManufacturerName,
  4428. Number: info.Number,
  4429. RegisterAccount: "",
  4430. Remark: "",
  4431. WarehouseInfoId: info.WarehouseInfotId,
  4432. PatientId: info.PatientId,
  4433. RecordDate: info.SysRecordTime,
  4434. StorehouseId: houseConfig.StorehouseOutInfo,
  4435. IsCheck: 1,
  4436. }
  4437. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4438. //回退库存
  4439. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4440. }
  4441. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4442. var over_count int64
  4443. for _, it := range goodList {
  4444. over_count += it.StockCount
  4445. }
  4446. //查询出库数量
  4447. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4448. //出库数据 大于 退库数量
  4449. if len(list) > 0 {
  4450. for _, it := range list {
  4451. //回退库存
  4452. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4453. //退库数量增加
  4454. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4455. //出库数量减少
  4456. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4457. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4458. var over_count_one int64
  4459. for _, it := range goodList {
  4460. over_count_one += it.StockCount
  4461. }
  4462. //查询该批次是否有退库数据
  4463. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4464. flow := models.VmStockFlow{
  4465. WarehousingId: it.WarehouseInfotId,
  4466. GoodId: it.GoodId,
  4467. Number: it.Number,
  4468. LicenseNumber: it.LicenseNumber,
  4469. Count: it.Count,
  4470. UserOrgId: adminInfo.CurrentOrgId,
  4471. PatientId: it.PatientId,
  4472. SystemTime: it.SysRecordTime,
  4473. ConsumableType: 7,
  4474. IsSys: 0,
  4475. WarehousingOrder: "",
  4476. WarehouseOutId: it.WarehouseOutId,
  4477. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4478. IsEdit: 0,
  4479. CancelStockId: cancel.ID,
  4480. CancelOrderNumber: cancel.OrderNumber,
  4481. Manufacturer: manufacturer.ID,
  4482. Dealer: 0,
  4483. Creator: adminInfo.AdminUser.Id,
  4484. UpdateCreator: 0,
  4485. Status: 1,
  4486. Ctime: time.Now().Unix(),
  4487. Mtime: 0,
  4488. Price: it.Price,
  4489. WarehousingDetailId: it.WarehouseInfotId,
  4490. WarehouseOutDetailId: it.ID,
  4491. CancelOutDetailId: cancelInfo.ID,
  4492. ProductDate: it.ProductDate,
  4493. ExpireDate: it.ExpiryDate,
  4494. StorehouseId: houseConfig.StorehouseOutInfo,
  4495. OverCount: over_count_one,
  4496. }
  4497. service.CreateStockFlowOne(flow)
  4498. }
  4499. }
  4500. //查询已出库数量
  4501. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4502. if prescribingNumber < dialysisInfo.Count {
  4503. //改变数量
  4504. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4505. }
  4506. if prescribingNumber >= dialysisInfo.Count {
  4507. //删除出库表
  4508. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4509. }
  4510. //更新剩余库存
  4511. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4512. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4513. var total_count_one int64
  4514. for _, it := range stockList {
  4515. total_count_one += it.StockCount
  4516. }
  4517. //基础库插入数据
  4518. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4519. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4520. var flush_count int64
  4521. for _, it := range goodListOne {
  4522. flush_count += it.StockCount
  4523. }
  4524. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4525. if errs != nil {
  4526. goodErrcode := models.XtGoodErrcode{
  4527. UserOrgId: project.UserOrgId,
  4528. Errcode: "手动出库更新剩余出库失败",
  4529. GoodId: project.ProjectId,
  4530. Status: 1,
  4531. Ctime: time.Now().Unix(),
  4532. Mtime: 0,
  4533. Count: 0,
  4534. StockCount: 0,
  4535. Creater: creater,
  4536. BatchNumberId: 0,
  4537. WarehouseOutId: 0,
  4538. }
  4539. service.CreateGoodErrcode(goodErrcode)
  4540. }
  4541. }
  4542. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4543. fmt.Println(err)
  4544. } else {
  4545. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4546. fmt.Println(err)
  4547. }
  4548. }
  4549. c.ServeSuccessJSON(map[string]interface{}{
  4550. "msg": "删除成功",
  4551. })
  4552. return
  4553. }
  4554. func (c *HisApiController) CreateHisAdditionalCharge() {
  4555. his_patient_id, _ := c.GetInt64("his_patient_id")
  4556. patient_id, _ := c.GetInt64("patient_id")
  4557. record_date := c.GetString("record_date")
  4558. timeLayout := "2006-01-02"
  4559. loc, _ := time.LoadLocation("Local")
  4560. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4561. if err != nil {
  4562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. adminInfo := c.GetAdminUserInfo()
  4566. recordDateTime := theTime.Unix()
  4567. dataBody := make(map[string]interface{}, 0)
  4568. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4569. if err != nil {
  4570. utils.ErrorLog(err.Error())
  4571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4572. return
  4573. }
  4574. var additions []*models.HisAdditionalCharge
  4575. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4576. additions, _ := dataBody["addition"].([]interface{})
  4577. if len(additions) > 0 {
  4578. for _, item := range additions {
  4579. items := item.(map[string]interface{})
  4580. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4581. utils.ErrorLog("item_id")
  4582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4583. return
  4584. }
  4585. item_id := int64(items["item_id"].(float64))
  4586. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4587. utils.ErrorLog("item_name")
  4588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4589. return
  4590. }
  4591. item_name := items["item_name"].(string)
  4592. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4593. utils.ErrorLog("price")
  4594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4595. return
  4596. }
  4597. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4598. ctime := time.Now().Unix()
  4599. additional := &models.HisAdditionalCharge{
  4600. PatientId: patient_id,
  4601. HisPatientId: his_patient_id,
  4602. UserOrgId: adminInfo.CurrentOrgId,
  4603. RecordDate: recordDateTime,
  4604. CreatedTime: ctime,
  4605. UpdatedTime: ctime,
  4606. Modifier: adminInfo.AdminUser.Id,
  4607. Creator: adminInfo.AdminUser.Id,
  4608. Price: price,
  4609. ItemName: item_name,
  4610. ItemId: item_id,
  4611. Status: 1,
  4612. }
  4613. additions = append(additions, additional)
  4614. }
  4615. }
  4616. }
  4617. for _, item := range additions {
  4618. service.CreateAddtionalCharge(item)
  4619. }
  4620. c.ServeSuccessJSON(map[string]interface{}{
  4621. "msg": "创建成功",
  4622. })
  4623. }
  4624. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4625. blood_fat := c.GetString("blood_fat")
  4626. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4627. blood_sugar := c.GetString("blood_sugar")
  4628. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4629. chief_conplaint := c.GetString("chief_conplaint")
  4630. dbp := c.GetString("dbp")
  4631. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4632. delivery_way, _ := c.GetInt64("delivery_way")
  4633. diagnostic := c.GetString("diagnostic")
  4634. family_history := c.GetString("family_history")
  4635. height := c.GetString("height")
  4636. history_of_present_illness := c.GetString("history_of_present_illness")
  4637. is_infect, _ := c.GetInt64("is_infect")
  4638. past_history := c.GetString("past_history")
  4639. patient_id, _ := c.GetInt64("patient_id")
  4640. his_patient_id, _ := c.GetInt64("his_patient_id")
  4641. personal_history := c.GetString("personal_history")
  4642. pulse := c.GetString("pulse")
  4643. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4644. sbp := c.GetString("sbp")
  4645. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4646. heightfloat, _ := strconv.ParseFloat(height, 64)
  4647. sicktype := c.GetString("sick_type")
  4648. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4649. symptom := c.GetString("symptom")
  4650. sick_date := c.GetString("sick_date")
  4651. temperatures := c.GetString("temperature")
  4652. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4653. record_date := c.GetString("record_date")
  4654. breathing := c.GetString("breathing")
  4655. doctor_advice := c.GetString("doctor_advice")
  4656. remark := c.GetString("remark")
  4657. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4658. sick, _ := c.GetInt64("sick")
  4659. diagnose, _ := c.GetInt64("diagnose")
  4660. //id, _ := c.GetInt64("id")
  4661. timeLayout := "2006-01-02"
  4662. loc, _ := time.LoadLocation("Local")
  4663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4664. allergic_history := c.GetString("allergic_history")
  4665. if err != nil {
  4666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4667. return
  4668. }
  4669. recordDateTime := theTime.Unix()
  4670. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4671. if err != nil {
  4672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4673. return
  4674. }
  4675. sickTimes := sickTime.Unix()
  4676. ctime := time.Now().Unix()
  4677. primary_disease := c.GetString("primary_disease")
  4678. confirm_failure_date := c.GetString("confirm_failure_date")
  4679. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4680. drug_allergy_history := c.GetString("drug_allergy_history")
  4681. physical_examination := c.GetString("physical_examination")
  4682. special_inspection := c.GetString("special_inspection")
  4683. lab_apparatus := c.GetString("lab_apparatus")
  4684. caseHistory := models.HisPatientCaseHistory{
  4685. HisPatientId: his_patient_id,
  4686. PatientId: patient_id,
  4687. Temperature: temperature,
  4688. BloodSugar: bloodsugarfloat,
  4689. Pulse: pulsefloat,
  4690. Sbp: sbpfloat,
  4691. Dbp: dbpfloat,
  4692. Height: heightfloat,
  4693. BloodFat: bloodfatfloat,
  4694. SickType: sick_type,
  4695. Symptom: symptom,
  4696. SickDate: sickTimes,
  4697. IsInfect: is_infect,
  4698. HistoryOfPresentIllness: history_of_present_illness,
  4699. PastHistory: past_history,
  4700. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4701. ChiefConplaint: chief_conplaint,
  4702. PersonalHistory: personal_history,
  4703. FamilyHistory: family_history,
  4704. Diagnostic: diagnostic,
  4705. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4706. Status: 1,
  4707. Ctime: ctime,
  4708. Mtime: ctime,
  4709. RecordDate: recordDateTime,
  4710. DeliveryWay: delivery_way,
  4711. Breathing: breathingfloat,
  4712. DoctorAdvice: doctor_advice,
  4713. Remark: remark,
  4714. Sick: sick,
  4715. Diagnose: diagnose,
  4716. AllergicHistory: allergic_history,
  4717. PrimaryDisease: primary_disease,
  4718. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4719. DrugAllergyHistory: drug_allergy_history,
  4720. PhysicalExamination: physical_examination,
  4721. SpecialInspection: special_inspection,
  4722. LabApparatus: lab_apparatus,
  4723. }
  4724. //查询该患者是否有病历
  4725. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4726. if errcodes == gorm.ErrRecordNotFound {
  4727. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4728. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4729. if err != nil {
  4730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4731. return
  4732. }
  4733. c.ServeSuccessJSON(map[string]interface{}{
  4734. "caseHistory": caseHistory,
  4735. "historyInfo": historyInfo,
  4736. })
  4737. return
  4738. } else if errcodes == nil {
  4739. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4740. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4741. if err != nil {
  4742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4743. return
  4744. }
  4745. c.ServeSuccessJSON(map[string]interface{}{
  4746. "caseHistory": caseHistory,
  4747. "historyInfo": historyInfo,
  4748. })
  4749. }
  4750. //查询该患者是否有病历
  4751. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4752. //if errcode == gorm.ErrRecordNotFound {
  4753. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4754. // if err != nil {
  4755. // c.ServeSuccessJSON(map[string]interface{}{
  4756. // "msg": "保存成功",
  4757. // })
  4758. // }
  4759. //} else if errcode == nil {
  4760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4761. // return
  4762. //}
  4763. }
  4764. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4765. patient_id, _ := c.GetInt64("patient_id", 0)
  4766. adminUser := c.GetAdminUserInfo()
  4767. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4768. c.ServeSuccessJSON(map[string]interface{}{
  4769. "list": caseHistorys,
  4770. })
  4771. }
  4772. func (c *HisApiController) GetHisPatientCaseHistory() {
  4773. record_date, _ := c.GetInt64("record_date", 0)
  4774. patient_id, _ := c.GetInt64("patient_id", 0)
  4775. admin := c.GetAdminUserInfo()
  4776. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4777. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4778. c.ServeSuccessJSON(map[string]interface{}{
  4779. "info": info,
  4780. "case_history": case_history,
  4781. })
  4782. }
  4783. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4784. template_name := c.GetString("template_name")
  4785. template_remark := c.GetString("template_remark")
  4786. doctor := c.GetAdminUserInfo().AdminUser.Id
  4787. diagnostic := c.GetString("diagnostic")
  4788. chief_conplaint := c.GetString("chief_conplain")
  4789. history_of_present_illness := c.GetString("history_of_present_illness")
  4790. past_history := c.GetString("past_history")
  4791. personal_history := c.GetString("personal_history")
  4792. family_history := c.GetString("family_history")
  4793. user_name := c.GetString("user_name")
  4794. doctor_advice := c.GetString("doctor_advice")
  4795. remark := c.GetString("remark")
  4796. //record_date := c.GetString("record_date")
  4797. //fmt.Println("record_date--------",record_date)
  4798. //timeLayout := "2006-01-02"
  4799. //loc, _ := time.LoadLocation("Local")
  4800. //
  4801. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4802. //if err != nil {
  4803. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4804. // return
  4805. //}
  4806. //recordDateTime := theTime.Unix()
  4807. ctime := time.Now().Unix()
  4808. template := models.HisCaseHistoryTemplate{
  4809. HistoryOfPresentIllness: history_of_present_illness,
  4810. PastHistory: past_history,
  4811. ChiefConplaint: chief_conplaint,
  4812. PersonalHistory: personal_history,
  4813. FamilyHistory: family_history,
  4814. Diagnostic: diagnostic,
  4815. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4816. Status: 1,
  4817. Ctime: ctime,
  4818. Mtime: ctime,
  4819. RecordDate: time.Now().Unix(),
  4820. TemplateName: template_name,
  4821. TemplateRemark: template_remark,
  4822. Creator: doctor,
  4823. Modifier: doctor,
  4824. UserName: user_name,
  4825. DoctorAdvice: doctor_advice,
  4826. Remark: remark,
  4827. }
  4828. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4829. if err == nil {
  4830. c.ServeSuccessJSON(map[string]interface{}{
  4831. "msg": "保存成功",
  4832. })
  4833. } else {
  4834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4835. return
  4836. }
  4837. }
  4838. func (c *HisApiController) GetCaseHistoryTemplate() {
  4839. timeLayout := "2006-01-02"
  4840. loc, _ := time.LoadLocation("Local")
  4841. keyword := c.GetString("keyword")
  4842. start_time := c.GetString("start_time")
  4843. end_time := c.GetString("end_time")
  4844. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4845. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4846. admin := c.GetAdminUserInfo()
  4847. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4848. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4849. c.ServeSuccessJSON(map[string]interface{}{
  4850. "template": template,
  4851. //"history": history,
  4852. })
  4853. }
  4854. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4855. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4856. utils.ErrorLog("drug_name")
  4857. return enums.ErrorCodeParamWrong
  4858. }
  4859. adviceName, _ := json["drug_name"].(string)
  4860. if len(adviceName) == 0 {
  4861. utils.ErrorLog("len(advice_name) == 0")
  4862. return enums.ErrorCodeParamWrong
  4863. }
  4864. advice.AdviceName = adviceName
  4865. adviceDesc, _ := json["advice_desc"].(string)
  4866. advice.AdviceDesc = adviceDesc
  4867. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4868. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4869. advice.DrugSpec = drugSpec
  4870. }
  4871. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4872. remark, _ := json["remark"].(string)
  4873. advice.Remark = remark
  4874. }
  4875. if json["id"] == nil {
  4876. advice.DrugId = 0
  4877. } else {
  4878. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4879. drug_id := int64(json["id"].(float64))
  4880. advice.DrugId = drug_id
  4881. }
  4882. }
  4883. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4884. advice_id := int64(json["advice_id"].(float64))
  4885. advice.ID = advice_id
  4886. if advice.ID > 0 {
  4887. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4888. if err == nil {
  4889. if hisAdvice.ID > 0 {
  4890. advice.ExecutionTime = hisAdvice.ExecutionTime
  4891. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4892. advice.ExecutionState = hisAdvice.ExecutionState
  4893. advice.CheckTime = hisAdvice.CheckTime
  4894. advice.Checker = hisAdvice.Checker
  4895. advice.CheckState = hisAdvice.CheckState
  4896. advice.StartTime = hisAdvice.StartTime
  4897. advice.FeedetlSn = hisAdvice.FeedetlSn
  4898. }
  4899. }
  4900. }
  4901. }
  4902. //
  4903. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4904. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4905. // advice.ExecutionTime = execution_time
  4906. //}
  4907. //
  4908. //
  4909. //
  4910. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4911. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4912. // advice.ExecutionStaff = execution_staff
  4913. //}
  4914. //
  4915. //
  4916. //
  4917. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4918. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4919. // advice.ExecutionState = execution_state
  4920. //}
  4921. //
  4922. //
  4923. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4924. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4925. // advice.CheckTime = check_time
  4926. //}
  4927. //
  4928. //
  4929. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4930. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4931. // advice.CheckState = check_state
  4932. //}
  4933. //
  4934. //
  4935. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4936. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4937. // advice.Checker = checker
  4938. //}
  4939. //
  4940. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4941. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4942. // advice.StartTime = start_time
  4943. //}
  4944. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4945. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4946. advice.IsSelfDrug = is_self_drug
  4947. }
  4948. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  4949. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  4950. drug_way_count, _ := json["drug_way_count"].(string)
  4951. advice.DrugWayCount = drug_way_count
  4952. }
  4953. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4954. drugSpecUnit, _ := json["min_unit"].(string)
  4955. advice.DrugSpecUnit = drugSpecUnit
  4956. }
  4957. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4958. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4959. advice.SingleDose = singleDose
  4960. }
  4961. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4962. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4963. advice.SingleDoseUnit = singleDoseUnit
  4964. }
  4965. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4966. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4967. advice.PrescribingNumber = prescribingNumber
  4968. }
  4969. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4970. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4971. advice.PrescribingNumberUnit = prescribingNumberUnit
  4972. }
  4973. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4974. deliveryWay, _ := json["delivery_way"].(string)
  4975. advice.DeliveryWay = deliveryWay
  4976. }
  4977. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4978. executionFrequency, _ := json["execution_frequency"].(string)
  4979. advice.ExecutionFrequency = executionFrequency
  4980. }
  4981. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4982. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4983. advice.Price = price
  4984. }
  4985. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4986. med_list_codg, _ := json["medical_insurance_number"].(string)
  4987. advice.MedListCodg = med_list_codg
  4988. }
  4989. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4990. day := int64(json["day"].(float64))
  4991. advice.Day = day
  4992. }
  4993. return 0
  4994. }
  4995. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4996. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4997. id := int64(json["id"].(float64))
  4998. project.ID = id
  4999. historyProject, _ := service.GetHisProjectByID(id)
  5000. project.FeedetlSn = historyProject.FeedetlSn
  5001. }
  5002. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5003. project_id := int64(json["project_id"].(float64))
  5004. project.ProjectId = project_id
  5005. }
  5006. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5007. // price := int64(json["price"].(float64))
  5008. // formatInt_price := strconv.FormatInt(price, 10)
  5009. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5010. // project.Price = float_price
  5011. // }
  5012. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5013. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5014. project.Price = price
  5015. }
  5016. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5017. total, _ := json["total"].(string)
  5018. project.Count = total
  5019. }
  5020. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5021. medical_code, _ := json["medical_code"].(string)
  5022. project.MedListCodg = medical_code
  5023. }
  5024. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5025. single_dose, _ := json["single_dose"].(string)
  5026. project.SingleDose = single_dose
  5027. }
  5028. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5029. delivery_way, _ := json["delivery_way"].(string)
  5030. project.DeliveryWay = delivery_way
  5031. }
  5032. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5033. execution_frequency, _ := json["execution_frequency"].(string)
  5034. project.ExecutionFrequency = execution_frequency
  5035. }
  5036. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5037. remark, _ := json["remark"].(string)
  5038. project.Remark = remark
  5039. }
  5040. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5041. day, _ := json["number_days"].(string)
  5042. project.Day = day
  5043. }
  5044. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5045. unit, _ := json["unit"].(string)
  5046. project.Unit = unit
  5047. }
  5048. return 0
  5049. }
  5050. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5051. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5052. id := int64(json["id"].(float64))
  5053. historyAddtions, _ := service.GetHisAdditionByID(id)
  5054. additionalCharge.ID = id
  5055. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5056. }
  5057. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5058. item_id := int64(json["item_id"].(float64))
  5059. additionalCharge.ItemId = item_id
  5060. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5061. if config.ID > 0 {
  5062. if len(config.Code) > 0 {
  5063. additionalCharge.MedListCodg = config.Code
  5064. }
  5065. }
  5066. }
  5067. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5068. // price := int64(json["price"].(float64))
  5069. // formatInt_price := strconv.FormatInt(price, 10)
  5070. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5071. // additionalCharge.Price = float_price
  5072. // }
  5073. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5074. // price := int64(json["price"].(float64))
  5075. // formatInt_price := strconv.FormatInt(price, 10)
  5076. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5077. // additionalCharge.Price = float_price
  5078. //}
  5079. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5080. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5081. additionalCharge.Price = price
  5082. }
  5083. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5084. count, _ := json["count"].(string)
  5085. counts, _ := strconv.ParseInt(count, 10, 64)
  5086. additionalCharge.Count = counts
  5087. }
  5088. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5089. item_name, _ := json["item_name"].(string)
  5090. additionalCharge.ItemName = item_name
  5091. }
  5092. return 0
  5093. }
  5094. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5095. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5096. utils.ErrorLog("drug_name")
  5097. return enums.ErrorCodeParamWrong
  5098. }
  5099. adviceName, _ := json["drug_name"].(string)
  5100. if len(adviceName) == 0 {
  5101. utils.ErrorLog("len(advice_name) == 0")
  5102. return enums.ErrorCodeParamWrong
  5103. }
  5104. advice.AdviceName = adviceName
  5105. adviceDesc, _ := json["advice_desc"].(string)
  5106. advice.AdviceDesc = adviceDesc
  5107. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5108. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5109. advice.DrugSpec = drugSpec
  5110. }
  5111. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5112. remark, _ := json["remark"].(string)
  5113. advice.Remark = remark
  5114. }
  5115. if json["id"] == nil {
  5116. advice.DrugId = 0
  5117. } else {
  5118. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5119. drug_id := int64(json["id"].(float64))
  5120. advice.DrugId = drug_id
  5121. }
  5122. }
  5123. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5124. groupno := int64(json["groupno"].(float64))
  5125. advice.Groupno = groupno
  5126. }
  5127. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5128. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5129. advice.IsSelfDrug = is_self_drug
  5130. }
  5131. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5132. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5133. drug_way_count, _ := json["drug_way_count"].(string)
  5134. advice.DrugWayCount = drug_way_count
  5135. }
  5136. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5137. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5138. advice.HospApprFlag = hosp_appr_flag
  5139. }
  5140. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5141. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5142. advice.PrescribingNumber = prescribingNumber
  5143. }
  5144. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5145. // frequency_type := int64(json["frequency_type"].(float64))
  5146. // advice.FrequencyType = frequency_type
  5147. //}
  5148. //
  5149. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5150. // day_count := int64(json["day_count"].(float64))
  5151. // advice.DayCount = day_count
  5152. //}
  5153. //
  5154. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5155. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5156. // week_day, _ := json["week_day"].(string)
  5157. // advice.WeekDay = week_day
  5158. //}
  5159. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5160. drugSpecUnit, _ := json["min_unit"].(string)
  5161. advice.DrugSpecUnit = drugSpecUnit
  5162. }
  5163. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5164. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5165. advice.SingleDose = singleDose
  5166. }
  5167. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5168. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5169. advice.SingleDoseUnit = singleDoseUnit
  5170. }
  5171. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5172. deliveryWay, _ := json["delivery_way"].(string)
  5173. advice.DeliveryWay = deliveryWay
  5174. }
  5175. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5176. executionFrequency, _ := json["execution_frequency"].(string)
  5177. advice.ExecutionFrequency = executionFrequency
  5178. }
  5179. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5180. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5181. advice.Price = price
  5182. }
  5183. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5184. med_list_codg, _ := json["medical_insurance_number"].(string)
  5185. advice.MedListCodg = med_list_codg
  5186. }
  5187. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5188. day := int64(json["day"].(float64))
  5189. advice.Day = day
  5190. }
  5191. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5192. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5193. advice.PrescribingNumberUnit = prescribingNumberUnit
  5194. }
  5195. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5196. advice_id := int64(json["advice_id"].(float64))
  5197. advice.ID = advice_id
  5198. if advice.ID > 0 {
  5199. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5200. if err == nil {
  5201. if hisAdvice.ID > 0 {
  5202. advice.ExecutionTime = hisAdvice.ExecutionTime
  5203. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5204. advice.ExecutionState = hisAdvice.ExecutionState
  5205. advice.CheckTime = hisAdvice.CheckTime
  5206. advice.Checker = hisAdvice.Checker
  5207. advice.CheckState = hisAdvice.CheckState
  5208. advice.StartTime = hisAdvice.StartTime
  5209. advice.HospApprFlag = hisAdvice.HospApprFlag
  5210. advice.IsMedicine = hisAdvice.IsMedicine
  5211. if hisAdvice.UserOrgId == 10028 {
  5212. 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 {
  5213. advice.ExecutionTime = 0
  5214. advice.ExecutionStaff = 0
  5215. advice.ExecutionState = 2
  5216. advice.CheckTime = 0
  5217. advice.Checker = 0
  5218. advice.CheckState = 2
  5219. }
  5220. } else {
  5221. 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 {
  5222. advice.ExecutionTime = 0
  5223. advice.ExecutionStaff = 0
  5224. advice.ExecutionState = 2
  5225. advice.CheckTime = 0
  5226. advice.Checker = 0
  5227. advice.CheckState = 2
  5228. }
  5229. }
  5230. //advice.Groupno = hisAdvice.Groupno
  5231. }
  5232. }
  5233. }
  5234. }
  5235. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5236. //
  5237. //if drugStockConfig.IsOpen == 1 {
  5238. //
  5239. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5240. // if advice.ID == 0 { //医嘱不存在
  5241. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5242. // drug.Total = drug.Total - advice.PrescribingNumber
  5243. // service.UpdateBaseDrugLib(&drug)
  5244. //
  5245. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5246. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5247. // drug.Total = drug.Total - num
  5248. // service.UpdateBaseDrugLib(&drug)
  5249. // }
  5250. //
  5251. // } else if advice.ID > 0 { //医嘱存在
  5252. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5253. // var num float64
  5254. //
  5255. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5256. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5257. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5258. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5259. // drug.Total = drug.Total + num
  5260. // service.UpdateBaseDrugLib(&drug)
  5261. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5262. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5263. // drug.Total = drug.Total - num
  5264. // service.UpdateBaseDrugLib(&drug)
  5265. // }
  5266. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5267. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5268. // if num2 > advice.PrescribingNumber {
  5269. // num = num2 - advice.PrescribingNumber
  5270. // drug.Total = drug.Total + num
  5271. // service.UpdateBaseDrugLib(&drug)
  5272. // } else if num2 < advice.PrescribingNumber {
  5273. // num = advice.PrescribingNumber - num2
  5274. // drug.Total = drug.Total - num
  5275. // service.UpdateBaseDrugLib(&drug)
  5276. // }
  5277. //
  5278. // }
  5279. //
  5280. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5281. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5282. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5283. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5284. // if num1 > num2 {
  5285. // num = num1 - num2
  5286. // drug.Total = drug.Total + num
  5287. // service.UpdateBaseDrugLib(&drug)
  5288. // } else if num1 < num2 {
  5289. // num = num2 - num1
  5290. // drug.Total = drug.Total - num
  5291. // service.UpdateBaseDrugLib(&drug)
  5292. // }
  5293. //
  5294. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5295. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5296. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5297. // if hisAdvice.PrescribingNumber > num2 {
  5298. // num = hisAdvice.PrescribingNumber - num2
  5299. // drug.Total = drug.Total + num
  5300. // service.UpdateBaseDrugLib(&drug)
  5301. // } else if num2 < advice.PrescribingNumber {
  5302. // num = num2 - hisAdvice.PrescribingNumber
  5303. // drug.Total = drug.Total - num
  5304. // service.UpdateBaseDrugLib(&drug)
  5305. // }
  5306. //
  5307. // }
  5308. // }
  5309. // }
  5310. //}
  5311. //
  5312. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5313. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5314. // advice.ExecutionTime = execution_time
  5315. //}
  5316. //
  5317. //
  5318. //
  5319. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5320. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5321. // advice.ExecutionStaff = execution_staff
  5322. //}
  5323. //
  5324. //
  5325. //
  5326. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5327. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5328. // advice.ExecutionState = execution_state
  5329. //}
  5330. //
  5331. //
  5332. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5333. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5334. // advice.CheckTime = check_time
  5335. //}
  5336. //
  5337. //
  5338. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5339. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5340. // advice.CheckState = check_state
  5341. //}
  5342. //
  5343. //
  5344. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5345. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5346. // advice.Checker = checker
  5347. //}
  5348. //
  5349. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5350. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5351. // advice.StartTime = start_time
  5352. //}
  5353. return 0
  5354. }
  5355. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5356. project.ExecutionStaff = 0
  5357. project.ExecutionState = 2
  5358. project.ExecutionTime = 0
  5359. project.Checker = 0
  5360. project.CheckState = 2
  5361. project.CheckTime = 0
  5362. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5363. id := int64(json["id"].(float64))
  5364. project.ID = id
  5365. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5366. project.ExecutionStaff = temp_project.ExecutionStaff
  5367. project.ExecutionState = temp_project.ExecutionState
  5368. project.ExecutionTime = temp_project.ExecutionTime
  5369. project.Checker = temp_project.Checker
  5370. project.CheckState = temp_project.CheckState
  5371. project.CheckTime = temp_project.CheckTime
  5372. project.TeamId = temp_project.TeamId
  5373. }
  5374. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5375. types := int64(json["type"].(float64))
  5376. project.Type = types
  5377. }
  5378. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5379. project_id := int64(json["project_id"].(float64))
  5380. project.ProjectId = project_id
  5381. }
  5382. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5383. team_id := int64(json["team_id"].(float64))
  5384. project.TeamId = team_id
  5385. }
  5386. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5387. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5388. project.Price = price
  5389. }
  5390. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5391. total, _ := json["total"].(string)
  5392. //totals, _ := strconv.ParseInt(total, 10, 64)
  5393. project.Count = total
  5394. }
  5395. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5396. medical_code, _ := json["medical_code"].(string)
  5397. project.MedListCodg = medical_code
  5398. }
  5399. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5400. single_dose, _ := json["single_dose"].(string)
  5401. project.SingleDose = single_dose
  5402. }
  5403. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5404. delivery_way, _ := json["delivery_way"].(string)
  5405. project.DeliveryWay = delivery_way
  5406. }
  5407. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5408. execution_frequency, _ := json["execution_frequency"].(string)
  5409. project.ExecutionFrequency = execution_frequency
  5410. }
  5411. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5412. remark, _ := json["remark"].(string)
  5413. project.Remark = remark
  5414. }
  5415. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5416. day, _ := json["number_days"].(string)
  5417. project.Day = day
  5418. }
  5419. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5420. unit, _ := json["unit"].(string)
  5421. project.Unit = unit
  5422. }
  5423. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5424. // frequency_type := int64(json["frequency_type"].(float64))
  5425. // project.FrequencyType = frequency_type
  5426. //}
  5427. //
  5428. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5429. // day_count := int64(json["day_count"].(float64))
  5430. // project.DayCount = day_count
  5431. //}
  5432. //
  5433. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5434. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5435. // week_day, _ := json["week_day"].(string)
  5436. // project.WeekDay = week_day
  5437. //}
  5438. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5439. //
  5440. //if project.ID == 0 {
  5441. // if stockConfig.IsOpen == 1 {
  5442. // if project.Type == 3 {
  5443. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5444. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5445. // good.Total = good.Total - f_count
  5446. // service.UpdateGoodInfo(&good)
  5447. // }
  5448. // }
  5449. //
  5450. //} else {
  5451. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5452. //
  5453. // if stockConfig.IsOpen == 1 {
  5454. // if project.Type == 3 {
  5455. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5456. // if project.Count < temp_project.Count {
  5457. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5458. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5459. //
  5460. // other_count := f_count_two - f_count_one
  5461. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5462. // good.Total = good.Total + other_count_two
  5463. // service.UpdateGoodInfo(&good)
  5464. // } else if project.Count > temp_project.Count {
  5465. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5466. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5467. //
  5468. // other_count := f_count_one - f_count_two
  5469. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5470. // good.Total = good.Total - other_count_two
  5471. // service.UpdateGoodInfo(&good)
  5472. // }
  5473. //
  5474. // }
  5475. // }
  5476. //
  5477. //}
  5478. return 0
  5479. }
  5480. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5481. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5482. id := int64(json["id"].(float64))
  5483. additionalCharge.ID = id
  5484. }
  5485. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5486. item_id := int64(json["item_id"].(float64))
  5487. additionalCharge.ItemId = item_id
  5488. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5489. if config.ID > 0 {
  5490. if len(config.Code) > 0 {
  5491. additionalCharge.MedListCodg = config.Code
  5492. }
  5493. }
  5494. }
  5495. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5496. // price := int64(json["price"].(float64))
  5497. // formatInt_price := strconv.FormatInt(price, 10)
  5498. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5499. // additionalCharge.Price = float_price
  5500. // }
  5501. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5502. // price := int64(json["price"].(float64))
  5503. // formatInt_price := strconv.FormatInt(price, 10)
  5504. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5505. // additionalCharge.Price = float_price
  5506. //}
  5507. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5508. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5509. additionalCharge.Price = price
  5510. }
  5511. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5512. count, _ := json["count"].(string)
  5513. counts, _ := strconv.ParseInt(count, 10, 64)
  5514. additionalCharge.Count = counts
  5515. }
  5516. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5517. item_name, _ := json["item_name"].(string)
  5518. additionalCharge.ItemName = item_name
  5519. }
  5520. return 0
  5521. }
  5522. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5523. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5524. utils.ErrorLog("drug_name")
  5525. return enums.ErrorCodeParamWrong
  5526. }
  5527. adviceName, _ := json["drug_name"].(string)
  5528. if len(adviceName) == 0 {
  5529. utils.ErrorLog("len(advice_name) == 0")
  5530. return enums.ErrorCodeParamWrong
  5531. }
  5532. advice.AdviceName = adviceName
  5533. adviceDesc, _ := json["advice_desc"].(string)
  5534. advice.AdviceDesc = adviceDesc
  5535. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5536. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5537. advice.DrugSpec = drugSpec
  5538. }
  5539. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5540. remark, _ := json["remark"].(string)
  5541. advice.Remark = remark
  5542. }
  5543. if json["id"] == nil {
  5544. advice.DrugId = 0
  5545. } else {
  5546. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5547. drug_id := int64(json["id"].(float64))
  5548. advice.DrugId = drug_id
  5549. }
  5550. }
  5551. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5552. groupno := int64(json["groupno"].(float64))
  5553. advice.Groupno = groupno
  5554. }
  5555. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5556. drugSpecUnit, _ := json["min_unit"].(string)
  5557. advice.DrugSpecUnit = drugSpecUnit
  5558. }
  5559. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5560. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5561. advice.SingleDose = singleDose
  5562. }
  5563. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5564. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5565. advice.SingleDoseUnit = singleDoseUnit
  5566. }
  5567. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5568. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5569. advice.PrescribingNumber = prescribingNumber
  5570. }
  5571. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5572. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5573. advice.PrescribingNumberUnit = prescribingNumberUnit
  5574. }
  5575. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5576. deliveryWay, _ := json["delivery_way"].(string)
  5577. advice.DeliveryWay = deliveryWay
  5578. }
  5579. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5580. executionFrequency, _ := json["execution_frequency"].(string)
  5581. advice.ExecutionFrequency = executionFrequency
  5582. }
  5583. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5584. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5585. advice.Price = price
  5586. }
  5587. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5588. med_list_codg, _ := json["medical_insurance_number"].(string)
  5589. advice.MedListCodg = med_list_codg
  5590. }
  5591. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5592. day := int64(json["day"].(float64))
  5593. advice.Day = day
  5594. }
  5595. advice.FrequencyType = 1
  5596. return 0
  5597. }
  5598. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5599. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5600. types := int64(json["type"].(float64))
  5601. project.Type = types
  5602. }
  5603. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5604. project_id := int64(json["project_id"].(float64))
  5605. project.ProjectId = project_id
  5606. }
  5607. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5608. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5609. project.Price = price
  5610. }
  5611. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5612. total, _ := json["total"].(string)
  5613. //totals, _ := strconv.ParseInt(total, 10, 64)
  5614. project.Count = total
  5615. }
  5616. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5617. medical_code, _ := json["medical_code"].(string)
  5618. project.MedListCodg = medical_code
  5619. }
  5620. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5621. single_dose, _ := json["single_dose"].(string)
  5622. project.SingleDose = single_dose
  5623. }
  5624. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5625. delivery_way, _ := json["delivery_way"].(string)
  5626. project.DeliveryWay = delivery_way
  5627. }
  5628. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5629. execution_frequency, _ := json["execution_frequency"].(string)
  5630. project.ExecutionFrequency = execution_frequency
  5631. }
  5632. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5633. remark, _ := json["remark"].(string)
  5634. project.Remark = remark
  5635. }
  5636. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5637. day, _ := json["number_days"].(string)
  5638. project.Day = day
  5639. }
  5640. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5641. unit, _ := json["unit"].(string)
  5642. project.Unit = unit
  5643. }
  5644. project.FrequencyType = 1
  5645. return 0
  5646. }
  5647. func (c *HisApiController) GetHisOrderList() {
  5648. page, _ := c.GetInt64("page", -1)
  5649. limit, _ := c.GetInt64("limit", -1)
  5650. start_time := c.GetString("start_time")
  5651. end_time := c.GetString("end_time")
  5652. types, _ := c.GetInt64("type", 0)
  5653. keywords := c.GetString("keywords")
  5654. p_type, _ := c.GetInt64("p_type", 0)
  5655. sort_type, _ := c.GetInt64("sort_type", 0)
  5656. charge_type, _ := c.GetInt64("charge_type", 0)
  5657. sch_type, _ := c.GetInt64("sch_type", 0)
  5658. zone_type, _ := c.GetInt64("zone_type", 0)
  5659. med_type, _ := c.GetInt64("med_type", 0)
  5660. timeLayout := "2006-01-02"
  5661. loc, _ := time.LoadLocation("Local")
  5662. var startTime int64
  5663. if len(start_time) > 0 {
  5664. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5665. if err != nil {
  5666. //fmt.Println(err)
  5667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5668. return
  5669. }
  5670. startTime = theTime.Unix()
  5671. }
  5672. var endTime int64
  5673. if len(end_time) > 0 {
  5674. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5675. if err != nil {
  5676. utils.ErrorLog(err.Error())
  5677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5678. return
  5679. }
  5680. endTime = theTime.Unix()
  5681. }
  5682. adminUser := c.GetAdminUserInfo()
  5683. org_id := adminUser.CurrentOrgId
  5684. 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)
  5685. for _, item := range order {
  5686. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5687. item.DoctorName = info.Doctor
  5688. item.DepartmentName = info.XtHisDepartment.Name
  5689. }
  5690. if err == nil {
  5691. c.ServeSuccessJSON(map[string]interface{}{
  5692. "order": order,
  5693. "total": total,
  5694. })
  5695. } else {
  5696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5697. return
  5698. }
  5699. }
  5700. func (c *HisApiController) GetHisOrder() {
  5701. patient_id, _ := c.GetInt64("patient_id", 0)
  5702. number := c.GetString("number")
  5703. adminInfo := c.GetAdminUserInfo()
  5704. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5705. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5706. if err == nil {
  5707. c.ServeSuccessJSON(map[string]interface{}{
  5708. "order": order,
  5709. "prescription": prescriptions,
  5710. })
  5711. } else {
  5712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5713. return
  5714. }
  5715. }
  5716. func (c *HisApiController) GetHisPrescriptionList() {
  5717. record_date := c.GetString("record_date")
  5718. keywords := c.GetString("keywords")
  5719. page, _ := c.GetInt64("page")
  5720. limit, _ := c.GetInt64("limit")
  5721. sch_type, _ := c.GetInt64("sch_type")
  5722. timeLayout := "2006-01-02"
  5723. loc, _ := time.LoadLocation("Local")
  5724. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5725. if err != nil {
  5726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5727. return
  5728. }
  5729. recordDateTime := theTime.Unix()
  5730. adminInfo := c.GetAdminUserInfo()
  5731. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5732. //adminInfo := c.GetAdminUserInfo()
  5733. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5734. //fmt.Println(prescriptionOrder)
  5735. if err == nil {
  5736. c.ServeSuccessJSON(map[string]interface{}{
  5737. "order": prescriptionOrder,
  5738. "total": total,
  5739. })
  5740. } else {
  5741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5742. return
  5743. }
  5744. }
  5745. func (c *HisApiController) GetHisPrescriptionInfo() {
  5746. id, _ := c.GetInt64("id")
  5747. adminInfo := c.GetAdminUserInfo()
  5748. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5749. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5750. if err == nil {
  5751. c.ServeSuccessJSON(map[string]interface{}{
  5752. "order": prescriptionOrder,
  5753. "prescription": prescription,
  5754. })
  5755. } else {
  5756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5757. return
  5758. }
  5759. }
  5760. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5761. adminUser := c.GetAdminUserInfo()
  5762. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5763. c.ServeSuccessJSON(map[string]interface{}{
  5764. "config": config,
  5765. })
  5766. }
  5767. type ResultTwo struct {
  5768. ErrMsg interface{} `json:"err_msg"`
  5769. InfRefmsgid string `json:"inf_refmsgid"`
  5770. Infcode int64 `json:"infcode"`
  5771. Output struct {
  5772. Baseinfo struct {
  5773. Age float64 `json:"age"`
  5774. Brdy string `json:"brdy"`
  5775. Certno string `json:"certno"`
  5776. Gend string `json:"gend"`
  5777. Naty string `json:"naty"`
  5778. PsnCertType string `json:"psn_cert_type"`
  5779. PsnName string `json:"psn_name"`
  5780. PsnNo string `json:"psn_no"`
  5781. } `json:"baseinfo"`
  5782. Idetinfo []interface{} `json:"idetinfo"`
  5783. Iinfo []struct {
  5784. Balc float64 `json:"balc"`
  5785. CvlservFlag string `json:"cvlserv_flag"`
  5786. EmpName string `json:"emp_name"`
  5787. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5788. Insutype string `json:"insutype"`
  5789. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5790. PausInsuDate interface{} `json:"paus_insu_date"`
  5791. PsnInsuDate string `json:"psn_insu_date"`
  5792. PsnInsuStas string `json:"psn_insu_stas"`
  5793. PsnType string `json:"psn_type"`
  5794. } `json:"insuinfo"`
  5795. } `json:"output"`
  5796. RefmsgTime string `json:"refmsg_time"`
  5797. RespondTime string `json:"respond_time"`
  5798. Signtype interface{} `json:"signtype"`
  5799. WarnInfo interface{} `json:"warn_info"`
  5800. }
  5801. type ResultThree struct {
  5802. Cainfo interface{} `json:"cainfo"`
  5803. ErrMsg interface{} `json:"err_msg"`
  5804. InfRefmsgid string `json:"inf_refmsgid"`
  5805. Infcode int64 `json:"infcode"`
  5806. Output struct {
  5807. Data struct {
  5808. IptOtpNo string `json:"ipt_otp_no"`
  5809. MdtrtID string `json:"mdtrt_id"`
  5810. PsnNo string `json:"psn_no"`
  5811. } `json:"data"`
  5812. } `json:"output"`
  5813. RefmsgTime string `json:"refmsg_time"`
  5814. RespondTime string `json:"respond_time"`
  5815. Signtype interface{} `json:"signtype"`
  5816. WarnMsg interface{} `json:"warn_msg"`
  5817. }
  5818. type ResultFour struct {
  5819. Cainfo string `json:"cainfo"`
  5820. ErrMsg string `json:"err_msg"`
  5821. InfRefmsgid string `json:"inf_refmsgid"`
  5822. Infcode int64 `json:"infcode"`
  5823. Output struct {
  5824. Result []struct {
  5825. BasMednFlag string `json:"bas_medn_flag"`
  5826. ChldMedcFlag string `json:"chld_medc_flag"`
  5827. ChrgitmLv string `json:"chrgitm_lv"`
  5828. Cnt float64 `json:"cnt"`
  5829. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5830. DrtReimFlag string `json:"drt_reim_flag"`
  5831. FeedetlSn string `json:"feedetl_sn"`
  5832. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5833. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5834. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5835. ListSpItemFlag string `json:"list_sp_item_flag"`
  5836. LmtUsedFlag string `json:"lmt_used_flag"`
  5837. MedChrgitmType string `json:"med_chrgitm_type"`
  5838. Memo string `json:"memo"`
  5839. OverlmtAmt float64 `json:"overlmt_amt"`
  5840. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5841. Pric float64 `json:"pric"`
  5842. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5843. SelfpayProp float64 `json:"selfpay_prop"`
  5844. } `json:"result"`
  5845. } `json:"output"`
  5846. RefmsgTime string `json:"refmsg_time"`
  5847. RespondTime string `json:"respond_time"`
  5848. Signtype string `json:"signtype"`
  5849. WarnMsg string `json:"warn_msg"`
  5850. }
  5851. type ResultFive struct {
  5852. Insutype string `json:"insutype"`
  5853. }
  5854. type ResultSix struct {
  5855. Cainfo interface{} `json:"cainfo"`
  5856. ErrMsg interface{} `json:"err_msg"`
  5857. InfRefmsgid string `json:"inf_refmsgid"`
  5858. Infcode int64 `json:"infcode"`
  5859. Output struct {
  5860. } `json:"output"`
  5861. RefmsgTime string `json:"refmsg_time"`
  5862. RespondTime string `json:"respond_time"`
  5863. Signtype interface{} `json:"signtype"`
  5864. WarnMsg interface{} `json:"warn_msg"`
  5865. }
  5866. type ResultSeven struct {
  5867. Cainfo string `json:"cainfo"`
  5868. ErrMsg string `json:"err_msg"`
  5869. InfRefmsgid string `json:"inf_refmsgid"`
  5870. Infcode int64 `json:"infcode"`
  5871. Output struct {
  5872. Setldetail []interface{} `json:"setldetail"`
  5873. Setlinfo struct {
  5874. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5875. AcctPay float64 `json:"acct_pay"`
  5876. ActPayDedc float64 `json:"act_pay_dedc"`
  5877. Age float64 `json:"age"`
  5878. Balc float64 `json:"balc"`
  5879. Brdy string `json:"brdy"`
  5880. Certno string `json:"certno"`
  5881. ClrOptins string `json:"clr_optins"`
  5882. ClrType string `json:"clr_type"`
  5883. ClrWay string `json:"clr_way"`
  5884. CvlservFlag string `json:"cvlserv_flag"`
  5885. CvlservPay float64 `json:"cvlserv_pay"`
  5886. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5887. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5888. Gend string `json:"gend"`
  5889. HifesPay float64 `json:"hifes_pay"`
  5890. HifmiPay float64 `json:"hifmi_pay"`
  5891. HifobPay float64 `json:"hifob_pay"`
  5892. HifpPay float64 `json:"hifp_pay"`
  5893. HospPartAmt float64 `json:"hosp_part_amt"`
  5894. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5895. Insutype string `json:"insutype"`
  5896. MafPay float64 `json:"maf_pay"`
  5897. MdtrtCertType string `json:"mdtrt_cert_type"`
  5898. MdtrtID string `json:"mdtrt_id"`
  5899. MedType string `json:"med_type"`
  5900. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5901. MedinsSetlID string `json:"medins_setl_id"`
  5902. Naty string `json:"naty"`
  5903. OthPay float64 `json:"oth_pay"`
  5904. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5905. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5906. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5907. PsnCashPay float64 `json:"psn_cash_pay"`
  5908. PsnCertType string `json:"psn_cert_type"`
  5909. PsnName string `json:"psn_name"`
  5910. PsnNo string `json:"psn_no"`
  5911. PsnPartAmt float64 `json:"psn_part_amt"`
  5912. PsnType string `json:"psn_type"`
  5913. SetlID string `json:"setl_id"`
  5914. SetlTime string `json:"setl_time"`
  5915. } `json:"setlinfo"`
  5916. } `json:"output"`
  5917. RefmsgTime string `json:"refmsg_time"`
  5918. RespondTime string `json:"respond_time"`
  5919. Signtype interface{} `json:"signtype"`
  5920. WarnMsg interface{} `json:"warn_msg"`
  5921. }
  5922. type ResultEight struct {
  5923. Cainfo string `json:"cainfo"`
  5924. ErrMsg string `json:"err_msg"`
  5925. InfRefmsgid string `json:"inf_refmsgid"`
  5926. Infcode int64 `json:"infcode"`
  5927. Output struct {
  5928. Stmtinfo struct {
  5929. SetlOptins string `json:"setl_optins"`
  5930. StmtRslt string `json:"stmt_rslt"`
  5931. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5932. } `json:"stmtinfo"`
  5933. } `json:"output"`
  5934. RefmsgTime string `json:"refmsg_time"`
  5935. RespondTime string `json:"respond_time"`
  5936. Signtype interface{} `json:"signtype"`
  5937. WarnMsg interface{} `json:"warn_msg"`
  5938. }
  5939. type ResultNine struct {
  5940. Cainfo string `json:"cainfo"`
  5941. ErrMsg string `json:"err_msg"`
  5942. InfRefmsgid string `json:"inf_refmsgid"`
  5943. Infcode int64 `json:"infcode"`
  5944. Output struct {
  5945. FileQuryNo string `json:"file_qury_no"`
  5946. } `json:"output"`
  5947. RefmsgTime string `json:"refmsg_time"`
  5948. RespondTime string `json:"respond_time"`
  5949. Signtype interface{} `json:"signtype"`
  5950. WarnMsg interface{} `json:"warn_msg"`
  5951. }
  5952. type ResultTen struct {
  5953. Cainfo string `json:"cainfo"`
  5954. ErrMsg string `json:"err_msg"`
  5955. InfRefmsgid string `json:"inf_refmsgid"`
  5956. Infcode int64 `json:"infcode"`
  5957. Output struct {
  5958. DldEndtime string `json:"dld_endtime"`
  5959. FileQuryNo string `json:"file_qury_no"`
  5960. Filename string `json:"filename"`
  5961. } `json:"output"`
  5962. RefmsgTime string `json:"refmsg_time"`
  5963. RespondTime string `json:"respond_time"`
  5964. Signtype interface{} `json:"signtype"`
  5965. WarnMsg interface{} `json:"warn_msg"`
  5966. }
  5967. type ResultEleven struct {
  5968. Cainfo string `json:"cainfo"`
  5969. ErrMsg string `json:"err_msg"`
  5970. InfRefmsgid string `json:"inf_refmsgid"`
  5971. Infcode int64 `json:"infcode"`
  5972. Output struct {
  5973. Setlinfo struct {
  5974. FixmedinsName string `json:"fixmedins_name"`
  5975. FixmedinsCode string `json:"fixmedins_code"`
  5976. PsnNo string `json:"psn_no"`
  5977. PsnName string `json:"psn_name"`
  5978. HifobPay float64 `json:"hifob_pay"`
  5979. Gend string `json:"gend"`
  5980. Brdy string `json:"brdy"`
  5981. PsnCertType string `json:"psn_cert_type"`
  5982. PsnType string `json:"psn_type"`
  5983. EmpName string `json:"emp_name"`
  5984. Certno string `json:"certno"`
  5985. Insutype string `json:"insutype"`
  5986. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5987. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5988. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5989. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5990. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5991. ActPayDedc float64 `json:"act_pay_dedc"`
  5992. HifpPay float64 `json:"hifp_pay"`
  5993. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5994. CvlservPay float64 `json:"cvlserv_pay"`
  5995. HifesPay float64 `json:"hifes_pay"`
  5996. HifmiPay float64 `json:"hifmi_pay"`
  5997. MafPay float64 `json:"maf_pay"`
  5998. OthPay float64 `json:"oth_pay"`
  5999. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6000. PsnPay float64 `json:"psn_pay"`
  6001. AcctPay float64 `json:"acct_pay"`
  6002. CashPayamt float64 `json:"cash_payamt"`
  6003. Balc float64 `json:"balc"`
  6004. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6005. MedinsSetlId string `json:"medins_setl_id"`
  6006. RefdSetlFlag string `json:"refd_setl_flag"`
  6007. SetlTime string `json:"setl_time"`
  6008. MedType string `json:"med_type"`
  6009. } `json:"setlinfo"`
  6010. } `json:"output"`
  6011. RefmsgTime string `json:"refmsg_time"`
  6012. RespondTime string `json:"respond_time"`
  6013. Signtype interface{} `json:"signtype"`
  6014. WarnMsg interface{} `json:"warn_msg"`
  6015. }
  6016. type Custom struct {
  6017. DetItemFeeSumamt string
  6018. Cut string
  6019. FeedetlSn string
  6020. Price string
  6021. MedListCodg string
  6022. Type int64
  6023. AdviceId int64
  6024. ProjectId int64
  6025. ItemId int64
  6026. }
  6027. // 获取个人信息----挂号-----上传就诊信息
  6028. func (c *HisApiController) GetRegisterInfo() {
  6029. id, _ := c.GetInt64("id")
  6030. record_time := c.GetString("record_time")
  6031. settlementValue, _ := c.GetInt64("settlement_value")
  6032. medical_insurance_card := c.GetString("medical_insurance_card")
  6033. name := c.GetString("name")
  6034. id_card_type, _ := c.GetInt64("id_card_type")
  6035. certificates, _ := c.GetInt64("certificates")
  6036. medical_care, _ := c.GetInt64("medical_care")
  6037. birthday := c.GetString("birthday")
  6038. age, _ := c.GetInt64("age")
  6039. id_card := c.GetString("id_card")
  6040. register_type, _ := c.GetInt64("register")
  6041. doctor, _ := c.GetInt64("doctor")
  6042. department, _ := c.GetInt64("department")
  6043. gender, _ := c.GetInt64("sex")
  6044. phone := c.GetString("phone")
  6045. registration_fee, _ := c.GetFloat("registration_fee")
  6046. medical_expenses, _ := c.GetFloat("medical_expenses")
  6047. social_type, _ := c.GetInt64("social_type")
  6048. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6049. diagnosis_ids := c.GetString("diagnosis")
  6050. sick_type, _ := c.GetInt64("sick_type")
  6051. reg_type := c.GetString("p_type")
  6052. timeLayout := "2006-01-02"
  6053. loc, _ := time.LoadLocation("Local")
  6054. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6055. birthUnix := birthdays.Unix()
  6056. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6057. if err != nil {
  6058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6059. return
  6060. }
  6061. recordDateTime := theTime.Unix()
  6062. adminInfo := c.GetAdminUserInfo()
  6063. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6064. if tempPatient.ID == 0 {
  6065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6066. return
  6067. }
  6068. var patient service.Patients
  6069. if id == 0 {
  6070. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6071. } else {
  6072. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6073. }
  6074. if patient.ID == 0 {
  6075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6076. return
  6077. }
  6078. if len(patient.IdCardNo) == 0 {
  6079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6080. return
  6081. }
  6082. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6083. if len(his) >= 1 {
  6084. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6085. if len(his) >= 1 && order.ID == 0 {
  6086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6087. return
  6088. }
  6089. }
  6090. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6091. fmt.Println(timeStr)
  6092. timeArr := strings.Split(timeStr, " ")
  6093. fmt.Println(timeArr)
  6094. timeArrTwo := strings.Split(timeArr[0], "-")
  6095. timeArrThree := strings.Split(timeArr[1], ":")
  6096. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6097. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6098. if len(lists) == 0 {
  6099. var hisPatient models.XtHisPatient
  6100. hisPatient = models.XtHisPatient{
  6101. Name: name,
  6102. Age: age,
  6103. Gender: gender,
  6104. Birthday: birthUnix,
  6105. Phone: phone,
  6106. MedicalTreatmentType: medical_care,
  6107. IdType: certificates,
  6108. IdCardNo: id_card,
  6109. BalanceAccountsType: settlementValue,
  6110. SocialType: social_type,
  6111. MedicalInsuranceNumber: medical_insurance_card,
  6112. RegisterType: register_type,
  6113. RegisterCost: registration_fee,
  6114. TreatmentCost: medical_expenses,
  6115. AdminUserId: adminInfo.AdminUser.Id,
  6116. UserOrgId: adminInfo.CurrentOrgId,
  6117. Status: 1,
  6118. RecordDate: recordDateTime,
  6119. IsReturn: 1,
  6120. PatientId: patient.ID,
  6121. Ctime: time.Now().Unix(),
  6122. Mtime: time.Now().Unix(),
  6123. Number: str,
  6124. IdCardType: id_card_type,
  6125. Departments: department,
  6126. Doctor: doctor,
  6127. PType: reg_type,
  6128. Diagnosis: diagnosis_ids,
  6129. SickType: sick_type,
  6130. }
  6131. service.CreateHisPatient(&hisPatient)
  6132. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6133. c.ServeSuccessJSON(map[string]interface{}{
  6134. "his_info": hisPatient,
  6135. })
  6136. } else {
  6137. //chrgBchno := rand.Intn(1000000) + 10000
  6138. var hisPatient models.XtHisPatient
  6139. hisPatient = models.XtHisPatient{
  6140. Name: name,
  6141. Age: age,
  6142. Gender: gender,
  6143. Birthday: birthUnix,
  6144. Phone: phone,
  6145. MedicalTreatmentType: medical_care,
  6146. IdType: certificates,
  6147. IdCardNo: id_card,
  6148. BalanceAccountsType: settlementValue,
  6149. SocialType: social_type,
  6150. MedicalInsuranceNumber: medical_insurance_card,
  6151. RegisterType: register_type,
  6152. RegisterCost: registration_fee,
  6153. TreatmentCost: medical_expenses,
  6154. AdminUserId: adminInfo.AdminUser.Id,
  6155. UserOrgId: adminInfo.CurrentOrgId,
  6156. Status: 1,
  6157. RecordDate: recordDateTime,
  6158. IsReturn: 1,
  6159. PatientId: patient.ID,
  6160. Ctime: time.Now().Unix(),
  6161. Mtime: time.Now().Unix(),
  6162. Number: str,
  6163. IdCardType: id_card_type,
  6164. Departments: department,
  6165. Doctor: doctor,
  6166. PType: reg_type,
  6167. Diagnosis: diagnosis_ids,
  6168. SickType: sick_type,
  6169. }
  6170. service.CreateHisPatient(&hisPatient)
  6171. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6172. c.ServeSuccessJSON(map[string]interface{}{
  6173. "his_info": hisPatient,
  6174. })
  6175. }
  6176. }
  6177. // 上传明细----结算
  6178. func (c *HisApiController) GetUploadInfo() {
  6179. id, _ := c.GetInt64("id")
  6180. record_time := c.GetString("record_time")
  6181. his_patient_id, _ := c.GetInt64("his_patient_id")
  6182. oth_desc := c.GetString("oth_desc")
  6183. pay_way, _ := c.GetInt64("pay_way")
  6184. pay_ways := c.GetString("pay_ways")
  6185. pay_price, _ := c.GetFloat("pay_price")
  6186. pay_card_no := c.GetString("pay_card_no")
  6187. discount_price, _ := c.GetFloat("discount_price")
  6188. preferential_price, _ := c.GetFloat("preferential_price")
  6189. reality_price, _ := c.GetFloat("reality_price")
  6190. found_price, _ := c.GetFloat("found_price")
  6191. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6192. private_price, _ := c.GetFloat("private_price")
  6193. timeLayout := "2006-01-02"
  6194. loc, _ := time.LoadLocation("Local")
  6195. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6196. fapiao_code := c.GetString("fapiao_code")
  6197. fapiao_number := c.GetString("fapiao_number")
  6198. diagnosis_id := c.GetString("diagnosis")
  6199. sick_type, _ := c.GetInt64("sick_type")
  6200. reg_type, _ := c.GetInt64("p_type")
  6201. order_id, _ := c.GetInt64("order_id")
  6202. cash_pay := c.GetString("cash_pay")
  6203. wechat_pay := c.GetString("wechat_pay")
  6204. ali_pay := c.GetString("ali_pay")
  6205. jifen_pay := c.GetString("jifen_pay")
  6206. band_card_pay := c.GetString("band_card_pay")
  6207. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6208. tmp_decimal := c.GetString("tmp_decimal")
  6209. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6210. var decimal float64 //本次使用的押金
  6211. var errmsg error
  6212. tx := service.XTWriteDB().Begin() //开了事务
  6213. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6214. defer func() {
  6215. if errmsg != nil {
  6216. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6217. tx.Rollback()
  6218. } else {
  6219. tx.Commit()
  6220. }
  6221. }()
  6222. fmt.Println("dec_way", dec_way)
  6223. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6224. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6225. return
  6226. }
  6227. if len(tmp_decimal) > 0 {
  6228. if tmp_decimal[0] == 45 {
  6229. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6230. return
  6231. }
  6232. }
  6233. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6234. fmt.Println(errs)
  6235. decimal = tt
  6236. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6237. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6238. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6239. if err != nil {
  6240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6241. return
  6242. }
  6243. recordDateTime := theTime.Unix()
  6244. adminUser := c.GetAdminUserInfo()
  6245. var prescriptions []*models.HisPrescription
  6246. var prescriptionsOne []*models.HisPrescription
  6247. var start_time int64
  6248. var end_time int64
  6249. ids_str := c.GetString("ids")
  6250. ids_arr := strings.Split(ids_str, ",")
  6251. if tempOrder.ID == 0 {
  6252. if settle_accounts_type == 1 { //日结
  6253. fmt.Println(reg_type)
  6254. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6255. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6256. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6257. } else {
  6258. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6259. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6260. }
  6261. } else { //月结
  6262. start_time_str := c.GetString("start_time")
  6263. end_time_str := c.GetString("end_time")
  6264. timeLayout := "2006-01-02"
  6265. loc, _ := time.LoadLocation("Local")
  6266. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6267. if err != nil {
  6268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6269. return
  6270. }
  6271. recordStartTime := theStartTime.Unix()
  6272. start_time = recordStartTime
  6273. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6274. if err != nil {
  6275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6276. return
  6277. }
  6278. recordEndTime := theEndTime.Unix()
  6279. end_time = recordEndTime
  6280. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6281. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6282. }
  6283. var goods []*models.DialysisBeforePrepareGoods
  6284. var newGoods []*models.NewDialysisBeforePrepareGoods
  6285. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6286. var infos []*models.HisDoctorAdviceInfo
  6287. var infoList []*models.HisDoctorAdviceInfo
  6288. var hisAdvice []*models.HisDoctorAdviceInfo
  6289. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6290. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6291. //判断库存不足
  6292. //结算出库开关
  6293. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6294. if settConfig.IsOpen == 1 {
  6295. //判断库存的地方
  6296. for _, info := range prescriptions {
  6297. if info.Type == 1 {
  6298. infos = append(infos, info.HisDoctorAdviceInfo...)
  6299. }
  6300. if info.Type == 2 {
  6301. for _, sumItem := range info.HisPrescriptionProject {
  6302. if sumItem.Type == 3 {
  6303. var good models.DialysisBeforePrepareGoods
  6304. var newGood models.NewDialysisBeforePrepareGoods
  6305. good.GoodId = sumItem.GoodInfo.ID
  6306. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6307. count, _ := strconv.Atoi(sumItem.Count)
  6308. good.Count = int64(count)
  6309. good.StorehouseId = houseConfig.StorehouseOutInfo
  6310. good.ProjectId = sumItem.ID
  6311. goods = append(goods, &good)
  6312. newGood.GoodId = sumItem.GoodInfo.ID
  6313. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6314. count2, _ := strconv.Atoi(sumItem.Count)
  6315. newGood.Count = int64(count2)
  6316. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6317. newGood.ProjectId = sumItem.ID
  6318. newGoods = append(newGoods, &newGood)
  6319. }
  6320. }
  6321. }
  6322. }
  6323. for _, info := range prescriptionsOne {
  6324. if info.Type == 1 {
  6325. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6326. }
  6327. if info.Type == 2 {
  6328. for _, sumItem := range info.HisPrescriptionProject {
  6329. if sumItem.Type == 3 {
  6330. var newGood models.NewDialysisBeforePrepareGoods
  6331. newGood.GoodId = sumItem.GoodInfo.ID
  6332. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6333. count2, _ := strconv.Atoi(sumItem.Count)
  6334. newGood.Count = int64(count2)
  6335. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6336. newGood.ProjectId = sumItem.ID
  6337. newGoodOne = append(newGoodOne, &newGood)
  6338. }
  6339. }
  6340. }
  6341. }
  6342. //判断
  6343. for _, itemOne := range infos {
  6344. for _, itemTwo := range hisAdvice {
  6345. if itemOne.DrugId == itemTwo.DrugId {
  6346. itemTwo.Child = append(itemTwo.Child, itemOne)
  6347. }
  6348. }
  6349. }
  6350. for _, itemTwo := range hisAdvice {
  6351. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6352. var sum_out_count int64
  6353. for _, itemThree := range itemTwo.Child {
  6354. var prescribing_number int64
  6355. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6356. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6357. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6358. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6359. }
  6360. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6361. prescribing_number = parseIntPrescribingNumber
  6362. }
  6363. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6364. prescribing_number = parseIntPrescribingNumber
  6365. }
  6366. sum_out_count += prescribing_number
  6367. }
  6368. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6369. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6370. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6371. if sum_out_count > drugStockOut.FlushCount {
  6372. c.ServeSuccessJSON(map[string]interface{}{
  6373. "msg": "2",
  6374. "drug": medical,
  6375. })
  6376. return
  6377. }
  6378. }
  6379. fmt.Println("newGoods99999988882os", newGoods)
  6380. for _, itemOne := range newGoods {
  6381. for _, item := range newGoodOne {
  6382. if itemOne.GoodId == item.GoodId {
  6383. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6384. }
  6385. }
  6386. }
  6387. for _, item := range newGoodOne {
  6388. var sum_out_count_one int64
  6389. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6390. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6391. sum_out_count_one += itemOne.Count
  6392. }
  6393. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6394. fmt.Println("sum_out_count_one", sum_out_count_one)
  6395. fmt.Println("list.FlushCount", list.FlushCount)
  6396. if sum_out_count_one > list.FlushCount {
  6397. c.ServeSuccessJSON(map[string]interface{}{
  6398. "msg": "3",
  6399. "good": good,
  6400. })
  6401. return
  6402. }
  6403. }
  6404. }
  6405. timestamp := time.Now().Unix()
  6406. tempTime := time.Unix(timestamp, 0)
  6407. timeFormat := tempTime.Format("20060102150405")
  6408. chrgBchno := rand.Intn(100000) + 10000
  6409. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6410. strconv.FormatInt(his.PatientId, 10)
  6411. var ids []int64
  6412. for _, item := range prescriptions {
  6413. ids = append(ids, item.ID)
  6414. }
  6415. var total float64
  6416. for _, item := range prescriptions {
  6417. fmt.Println(item)
  6418. if item.Type == 1 { //药品
  6419. for _, subItem := range item.HisDoctorAdviceInfo {
  6420. total = total + (subItem.Price * subItem.PrescribingNumber)
  6421. }
  6422. }
  6423. if item.Type == 2 { //项目
  6424. for _, subItem := range item.HisPrescriptionProject {
  6425. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6426. total = total + (subItem.Price * cnt)
  6427. }
  6428. }
  6429. for _, subItem := range item.HisAdditionalCharge {
  6430. total = total + (subItem.Price * float64(subItem.Count))
  6431. }
  6432. }
  6433. if reg_type == 1111 || reg_type == 1112 {
  6434. reg_type = 11
  6435. }
  6436. tm := time.Unix(time.Now().Unix(), 0)
  6437. allTotal := fmt.Sprintf("%.4f", total)
  6438. totals, _ := strconv.ParseFloat(allTotal, 64)
  6439. order := &models.HisOrder{
  6440. UserOrgId: adminUser.CurrentOrgId,
  6441. HisPatientId: his.ID,
  6442. PatientId: id,
  6443. SettleAccountsDate: recordDateTime,
  6444. Ctime: time.Now().Unix(),
  6445. Mtime: time.Now().Unix(),
  6446. Status: 1,
  6447. OrderStatus: 2,
  6448. MdtrtId: his.Number,
  6449. Number: chrg_bchno,
  6450. MedfeeSumamt: totals,
  6451. PayWay: pay_way,
  6452. PayWays: pay_ways,
  6453. PayPrice: pay_price,
  6454. MedType: strconv.Itoa(int(reg_type)),
  6455. PayCardNo: pay_card_no,
  6456. DiscountPrice: discount_price,
  6457. PreferentialPrice: preferential_price,
  6458. RealityPrice: reality_price,
  6459. FoundPrice: found_price,
  6460. MedicalInsurancePrice: medical_insurance_price,
  6461. PrivatePrice: private_price,
  6462. SettleEndTime: end_time,
  6463. SettleStartTime: start_time,
  6464. PsnPartAmt: totals,
  6465. PsnCashPay: totals,
  6466. SettleType: settle_accounts_type,
  6467. FaPiaoCode: fapiao_code,
  6468. FaPiaoNumber: fapiao_number,
  6469. Diagnosis: diagnosis_id,
  6470. PType: 2,
  6471. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6472. Decimal: decimal,
  6473. OthDesc: oth_desc,
  6474. CashPay: cash_pay,
  6475. WechatPay: wechat_pay,
  6476. AliPay: ali_pay,
  6477. JifenPay: jifen_pay,
  6478. BandCardPay: band_card_pay,
  6479. }
  6480. err = service.CreateOrderTX(order, tx)
  6481. if err != nil {
  6482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6483. return
  6484. }
  6485. var customs []*Custom
  6486. for _, item := range prescriptions {
  6487. if item.Type == 1 { //药品a
  6488. for _, subItem := range item.HisDoctorAdviceInfo {
  6489. cus := &Custom{
  6490. AdviceId: subItem.ID,
  6491. ProjectId: 0,
  6492. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6493. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6494. FeedetlSn: subItem.FeedetlSn,
  6495. Price: fmt.Sprintf("%.4f", subItem.Price),
  6496. MedListCodg: subItem.MedListCodg,
  6497. Type: 1,
  6498. }
  6499. customs = append(customs, cus)
  6500. }
  6501. }
  6502. if item.Type == 2 { //项目
  6503. for _, subItem := range item.HisPrescriptionProject {
  6504. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6505. cus := &Custom{
  6506. AdviceId: 0,
  6507. ProjectId: subItem.ID,
  6508. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6509. Cut: fmt.Sprintf("%.4f", cnt),
  6510. FeedetlSn: subItem.FeedetlSn,
  6511. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6512. MedListCodg: subItem.MedListCodg,
  6513. Type: 2,
  6514. }
  6515. customs = append(customs, cus)
  6516. }
  6517. }
  6518. for _, item := range item.HisAdditionalCharge {
  6519. cus := &Custom{
  6520. ItemId: item.ID,
  6521. AdviceId: 0,
  6522. ProjectId: 0,
  6523. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6524. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6525. FeedetlSn: item.FeedetlSn,
  6526. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6527. MedListCodg: item.XtHisAddtionConfig.Code,
  6528. Type: 3,
  6529. }
  6530. customs = append(customs, cus)
  6531. }
  6532. }
  6533. for _, item := range customs {
  6534. var advice_id int64 = 0
  6535. var project_id int64 = 0
  6536. var item_id int64 = 0
  6537. var types int64 = 0
  6538. if item.Type == 1 {
  6539. advice_id = item.AdviceId
  6540. project_id = 0
  6541. item_id = 0
  6542. } else if item.Type == 2 {
  6543. advice_id = 0
  6544. item_id = 0
  6545. project_id = item.ProjectId
  6546. } else if item.Type == 3 {
  6547. advice_id = 0
  6548. item_id = item.ItemId
  6549. project_id = 0
  6550. }
  6551. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6552. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6553. pric, _ := strconv.ParseFloat(item.Price, 32)
  6554. info := &models.HisOrderInfo{
  6555. OrderNumber: order.Number,
  6556. UploadDate: time.Now().Unix(),
  6557. AdviceId: advice_id,
  6558. DetItemFeeSumamt: detItemFeeSumamt,
  6559. Cnt: cut,
  6560. Pric: pric,
  6561. PatientId: id,
  6562. Status: 1,
  6563. Mtime: time.Now().Unix(),
  6564. Ctime: time.Now().Unix(),
  6565. UserOrgId: adminUser.CurrentOrgId,
  6566. HisPatientId: his.ID,
  6567. OrderId: order.ID,
  6568. ProjectId: project_id,
  6569. Type: types,
  6570. ItemId: item_id,
  6571. }
  6572. service.CreateOrderInfoTX(info, tx)
  6573. }
  6574. his.Diagnosis = diagnosis_id
  6575. his.SickType = sick_type
  6576. his.RegisterType = reg_type
  6577. his.MedicalTreatmentType = reg_type
  6578. service.UpdataHisPateintTX(&his, tx)
  6579. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6580. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6581. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6582. //判断是否使用了押金
  6583. if dec_way == "true" {
  6584. tmpstring := strconv.FormatInt(order.ID, 10)
  6585. //扣押金
  6586. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6587. order.Decimal = decimal
  6588. service.UpDateOrderTwo(order, tx)
  6589. if errmsg != nil {
  6590. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6591. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6592. return
  6593. }
  6594. }
  6595. if err == nil {
  6596. for _, info := range prescriptions {
  6597. if info.Type == 1 {
  6598. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6599. }
  6600. if info.Type == 2 {
  6601. for _, sumItem := range info.HisPrescriptionProject {
  6602. if sumItem.Type == 3 {
  6603. var good models.DialysisBeforePrepareGoods
  6604. var newGood models.NewDialysisBeforePrepareGoods
  6605. var oldGood models.OldDialysisBeforePrepareGoods
  6606. good.GoodId = sumItem.GoodInfo.ID
  6607. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6608. count, _ := strconv.Atoi(sumItem.Count)
  6609. good.Count = int64(count)
  6610. good.StorehouseId = houseConfig.StorehouseOutInfo
  6611. good.ProjectId = sumItem.ID
  6612. good.PatientId = sumItem.PatientId
  6613. goods = append(goods, &good)
  6614. newGood.GoodId = sumItem.GoodInfo.ID
  6615. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6616. count2, _ := strconv.Atoi(sumItem.Count)
  6617. newGood.Count = int64(count2)
  6618. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6619. newGood.ProjectId = sumItem.ID
  6620. newGood.PatientId = sumItem.HisPatientId
  6621. newGoods = append(newGoods, &newGood)
  6622. oldGood.GoodId = sumItem.GoodInfo.ID
  6623. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6624. count3, _ := strconv.Atoi(sumItem.Count)
  6625. oldGood.Count = int64(count3)
  6626. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6627. oldGood.ProjectId = sumItem.ID
  6628. oldGood.RecordDate = sumItem.RecordDate
  6629. oldGood.PatientId = sumItem.HisPatientId
  6630. oldGoods = append(oldGoods, &oldGood)
  6631. }
  6632. }
  6633. }
  6634. }
  6635. if settConfig.IsOpen == 1 {
  6636. for _, item := range infoList {
  6637. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6638. if medical.IsUse == 2 {
  6639. //药品出库
  6640. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6641. //查询默认仓库
  6642. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6643. //查询默认仓库剩余多少库存
  6644. var sum_count int64
  6645. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6646. for _, its := range stockInfo {
  6647. if its.MaxUnit == medical.MaxUnit {
  6648. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6649. }
  6650. sum_count += its.StockMaxNumber + its.StockMinNumber
  6651. }
  6652. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6653. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6654. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6655. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6656. }
  6657. }
  6658. orgId := c.GetAdminUserInfo().CurrentOrgId
  6659. if len(oldGoods) > 0 {
  6660. timeStr := time.Now().Format("2006-01-02")
  6661. timeArr := strings.Split(timeStr, "-")
  6662. total, _ := service.FindAllWarehouseOut(orgId)
  6663. total = total + 1
  6664. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6665. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6666. number = number + total
  6667. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6668. operation_time := time.Now().Unix()
  6669. creater := c.GetAdminUserInfo().AdminUser.Id
  6670. //查询默认出库仓库库存
  6671. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6672. recordDateStr := time.Now().Format("2006-01-02")
  6673. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6674. nowtime := recordDate.Unix()
  6675. warehouseOut := models.WarehouseOut{
  6676. WarehouseOutOrderNumber: warehousing_out_order,
  6677. OperationTime: operation_time,
  6678. OrgId: orgId,
  6679. Creater: creater,
  6680. Ctime: time.Now().Unix(),
  6681. Status: 1,
  6682. WarehouseOutTime: nowtime,
  6683. Type: 1,
  6684. StorehouseId: storeConfig.StorehouseOutInfo,
  6685. IsCheck: 1,
  6686. OrderId: order.ID,
  6687. IsSys: 5,
  6688. }
  6689. //查询是否生成出库单
  6690. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6691. if out.ID == 0 {
  6692. service.AddSigleWarehouseOut(&warehouseOut)
  6693. }
  6694. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6695. for _, item := range oldGoods {
  6696. dialyPrepareOne := models.DialysisBeforePrepare{
  6697. GoodTypeId: item.GoodTypeId,
  6698. GoodId: item.GoodId,
  6699. PatientId: his.PatientId,
  6700. RecordDate: item.RecordDate,
  6701. UserOrgId: adminUser.CurrentOrgId,
  6702. Count: item.Count,
  6703. Ctime: time.Now().Unix(),
  6704. Creater: adminUser.AdminUser.Id,
  6705. CommdityCode: item.CommdityCode,
  6706. Status: 1,
  6707. StorehouseId: houseConfig.StorehouseOutInfo,
  6708. }
  6709. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6710. //非零用
  6711. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6712. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6713. //查询剩余库存
  6714. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6715. var sum_count int64
  6716. for _, item := range goodList {
  6717. sum_count += item.StockCount
  6718. }
  6719. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6720. //耗材
  6721. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6722. }
  6723. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6724. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6725. //查询剩余库存
  6726. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6727. var sum_count int64
  6728. for _, item := range goodList {
  6729. sum_count += item.StockCount
  6730. }
  6731. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6732. //耗材
  6733. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6734. }
  6735. }
  6736. }
  6737. }
  6738. c.ServeSuccessJSON(map[string]interface{}{
  6739. "msg": "结算成功",
  6740. })
  6741. }
  6742. }
  6743. }
  6744. // 退款
  6745. func (c *HisApiController) Refund() {
  6746. order_id, _ := c.GetInt64("order_id")
  6747. order, _ := service.GetHisOrderByID(order_id)
  6748. adminUser := c.GetAdminUserInfo()
  6749. orgid := c.GetAdminUserInfo().CurrentOrgId
  6750. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6751. if err != nil {
  6752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6753. return
  6754. }
  6755. tmp := strconv.FormatInt(order.ID, 10)
  6756. //当押金不为零时产生退费记录
  6757. if order.Decimal != 0 {
  6758. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6759. if err != nil {
  6760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6761. return
  6762. }
  6763. }
  6764. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6765. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6766. var goods []*models.DialysisBeforePrepareGoods
  6767. var newGoods []*models.NewDialysisBeforePrepareGoods
  6768. var infos []*models.HisDoctorAdviceInfo
  6769. for _, info := range orders {
  6770. if info.AdviceId > 0 && info.ProjectId == 0 {
  6771. infos = append(infos, &info.HisDoctorAdviceInfo)
  6772. }
  6773. if info.ProjectId > 0 && info.AdviceId == 0 {
  6774. if info.HisPrescriptionProject.Type == 3 {
  6775. var good models.DialysisBeforePrepareGoods
  6776. var newGood models.NewDialysisBeforePrepareGoods
  6777. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6778. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6779. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6780. good.Count = int64(count)
  6781. good.StorehouseId = houseConfig.StorehouseOutInfo
  6782. good.ProjectId = info.HisPrescriptionProject.ID
  6783. good.PatientId = info.PatientId
  6784. good.OrderId = order_id
  6785. goods = append(goods, &good)
  6786. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6787. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6788. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6789. newGood.Count = int64(count2)
  6790. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6791. newGood.ProjectId = info.HisPrescriptionProject.ID
  6792. newGood.RecordDate = order.SettleAccountsDate
  6793. newGood.UserOrgId = order.UserOrgId
  6794. newGood.PatientId = info.PatientId
  6795. newGood.OrderId = order_id
  6796. newGoods = append(newGoods, &newGood)
  6797. }
  6798. }
  6799. }
  6800. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6801. if settConfig.IsOpen == 1 {
  6802. for _, item := range infos {
  6803. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6804. }
  6805. for _, item := range newGoods {
  6806. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6807. }
  6808. }
  6809. c.ServeSuccessJSON(map[string]interface{}{
  6810. "msg": "退费成功",
  6811. })
  6812. }
  6813. func (c *HisApiController) RefundNumber() {
  6814. his_patient_id, _ := c.GetInt64("id")
  6815. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6816. info.Status = 0
  6817. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6818. if count > 0 {
  6819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6820. return
  6821. }
  6822. err := service.SaveHisPatient(info)
  6823. if err == nil {
  6824. c.ServeSuccessJSON(map[string]interface{}{
  6825. "msg": "退号成功",
  6826. })
  6827. } else {
  6828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6829. return
  6830. }
  6831. }
  6832. func (this *HisApiController) AdditionalCharge() {
  6833. dataBody := make(map[string]interface{}, 0)
  6834. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6835. fmt.Println(err)
  6836. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6837. patient_id := int64(dataBody["patient_id"].(float64))
  6838. medicineData, _ := dataBody["medicineData"].([]interface{})
  6839. adminUserInfo := this.GetAdminUserInfo()
  6840. orgId := adminUserInfo.CurrentOrgId
  6841. admin_user_id := adminUserInfo.AdminUser.Id
  6842. timeStr := time.Now().Format("2006-01-02")
  6843. timeLayout := "2006-01-02 15:04:05"
  6844. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6845. timenow := timeStringToTime.Unix()
  6846. var additionalCharges []*models.HisAdditionalCharge
  6847. for _, item := range medicineData {
  6848. var randNum int
  6849. randNum = rand.Intn(10000) + 1000
  6850. timestamp := time.Now().Unix()
  6851. tempTime := time.Unix(timestamp, 0)
  6852. timeFormat := tempTime.Format("20060102150405")
  6853. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6854. items := item.(map[string]interface{})
  6855. money := items["price"].(string)
  6856. item_id_str := items["item_id"].(string)
  6857. name := items["name"].(string)
  6858. id_str := items["id"].(string)
  6859. moneys, _ := strconv.ParseInt(money, 10, 64)
  6860. monStr := strconv.FormatInt(moneys, 10)
  6861. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6862. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6863. id, _ := strconv.ParseInt(id_str, 10, 64)
  6864. additionalCharge := &models.HisAdditionalCharge{
  6865. ID: id,
  6866. HisPatientId: his_patient_id,
  6867. UserOrgId: orgId,
  6868. PatientId: patient_id,
  6869. RecordDate: timenow,
  6870. Price: monneyStr,
  6871. Status: 1,
  6872. ItemName: name,
  6873. ItemId: item_id,
  6874. AdminUserId: admin_user_id,
  6875. CreatedTime: time.Now().Unix(),
  6876. OrderStatus: 0,
  6877. PrescriptionNumber: "",
  6878. BatchNumber: "",
  6879. FeedetlSn: p_number,
  6880. }
  6881. service.CreateAdditionalCharge(additionalCharge)
  6882. additionalCharges = append(additionalCharges, additionalCharge)
  6883. }
  6884. this.ServeSuccessJSON(map[string]interface{}{
  6885. "msg": "添加成功",
  6886. "additional_charges": additionalCharges,
  6887. })
  6888. }
  6889. func (this *HisApiController) DeleteAddition() {
  6890. id, _ := this.GetInt64("id")
  6891. //TODO 需要判断是否已经结算
  6892. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6893. if err == nil {
  6894. this.ServeSuccessJSON(map[string]interface{}{
  6895. "msg": "删除成功",
  6896. })
  6897. return
  6898. } else {
  6899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6900. return
  6901. }
  6902. }
  6903. func (this *HisApiController) GetAdminUsers() {
  6904. adminUser := this.GetAdminUserInfo()
  6905. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6906. this.ServeSuccessJSON(map[string]interface{}{
  6907. "doctors": doctors,
  6908. })
  6909. }
  6910. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6911. change_type, _ := this.GetInt64("type", 0)
  6912. record_date := this.GetString("record_time")
  6913. patient_id, _ := this.GetInt64("patient_id", 0)
  6914. p_type, _ := this.GetInt64("p_type", 0)
  6915. timeLayout := "2006-01-02"
  6916. loc, _ := time.LoadLocation("Local")
  6917. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6918. record_time := theAdviceRecordTime.Unix()
  6919. adminUserInfo := this.GetAdminUserInfo()
  6920. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6921. if err == nil {
  6922. if len(prescriptions) == 0 {
  6923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6924. return
  6925. } else {
  6926. this.ServeSuccessJSON(map[string]interface{}{
  6927. "prescriptions": prescriptions,
  6928. })
  6929. return
  6930. }
  6931. } else {
  6932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6933. return
  6934. }
  6935. }
  6936. func (this *HisApiController) GetCallHisPrescription() {
  6937. patient_id, _ := this.GetInt64("patient_id", 0)
  6938. timeLayout := "2006-01-02"
  6939. loc, _ := time.LoadLocation("Local")
  6940. start_time := this.GetString("start_time")
  6941. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6942. end_time := this.GetString("end_time")
  6943. p_type, _ := this.GetInt64("p_type")
  6944. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6945. adminUserInfo := this.GetAdminUserInfo()
  6946. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6947. if err == nil {
  6948. this.ServeSuccessJSON(map[string]interface{}{
  6949. "prescriptions": prescriptions,
  6950. })
  6951. return
  6952. } else {
  6953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6954. return
  6955. }
  6956. }
  6957. func (this *HisApiController) GetHisDayPrescription() {
  6958. timeLayout := "2006-01-02"
  6959. loc, _ := time.LoadLocation("Local")
  6960. start_time := this.GetString("start_time")
  6961. patient_id, _ := this.GetInt64("patient_id", 0)
  6962. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6963. end_time := this.GetString("end_time")
  6964. p_type, _ := this.GetInt64("p_type")
  6965. order_status, _ := this.GetInt64("type")
  6966. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6967. adminUserInfo := this.GetAdminUserInfo()
  6968. var dayHisPrescription []*models.HisPrescription
  6969. var err error
  6970. if order_status == 1 || order_status == 0 {
  6971. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6972. } else if order_status == 2 {
  6973. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6974. }
  6975. var settle_total float64
  6976. for _, item := range dayHisPrescription {
  6977. if len(item.HisPrescriptionProject) > 0 {
  6978. for _, subItem := range item.HisPrescriptionProject {
  6979. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6980. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6981. settle_total = settle_total + total
  6982. }
  6983. }
  6984. if len(item.HisDoctorAdviceInfo) > 0 {
  6985. for _, subItem := range item.HisDoctorAdviceInfo {
  6986. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6987. settle_total = settle_total + total
  6988. }
  6989. }
  6990. }
  6991. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6992. if err == nil {
  6993. this.ServeSuccessJSON(map[string]interface{}{
  6994. "day_prescription": dayHisPrescription,
  6995. "settle_total": settle_total,
  6996. })
  6997. return
  6998. } else {
  6999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7000. return
  7001. }
  7002. }
  7003. func (c *HisApiController) GetHisChargePatientList() {
  7004. record_date := c.GetString("record_date")
  7005. order_status, _ := c.GetInt64("type")
  7006. sch_type, _ := c.GetInt64("sch_type")
  7007. timeLayout := "2006-01-02"
  7008. loc, _ := time.LoadLocation("Local")
  7009. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7010. if err != nil {
  7011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7012. return
  7013. }
  7014. recordDateTime := theTime.Unix()
  7015. adminInfo := c.GetAdminUserInfo()
  7016. var tempPatients []*service.NewTempPatients
  7017. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7018. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7019. if order_status != 2 {
  7020. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7021. } else {
  7022. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7023. }
  7024. } else {
  7025. if order_status != 2 {
  7026. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7027. } else {
  7028. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7029. }
  7030. }
  7031. var patients []*service.NewTempPatients
  7032. var patients_two []*service.NewTempPatients
  7033. for _, item := range tempPatients {
  7034. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7035. //过滤掉没挂号的和没开处方的
  7036. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7037. patients = append(patients, item)
  7038. }
  7039. //过滤掉没挂号的
  7040. if len(item.HisPatient) > 0 {
  7041. patients_two = append(patients_two, item)
  7042. }
  7043. } else {
  7044. if len(item.HisPrescription) > 0 {
  7045. patients = append(patients, item)
  7046. }
  7047. }
  7048. }
  7049. c.ServeSuccessJSON(map[string]interface{}{
  7050. "list": patients,
  7051. "list_two": patients_two,
  7052. })
  7053. }
  7054. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7055. record_date := c.GetString("record_date")
  7056. timeLayout := "2006-01-02"
  7057. loc, _ := time.LoadLocation("Local")
  7058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7059. if err != nil {
  7060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7061. return
  7062. }
  7063. recordDateTime := theTime.Unix()
  7064. adminUser := c.GetAdminUserInfo()
  7065. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7066. var patients []*service.Patients
  7067. for _, item := range tempPatients {
  7068. if item.HisPatient.ID == 0 {
  7069. patients = append(patients, item)
  7070. }
  7071. }
  7072. c.ServeSuccessJSON(map[string]interface{}{
  7073. "list": patients,
  7074. //"list_two": patients_two,
  7075. })
  7076. }
  7077. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7078. newArr = make([]*service.Patients, 0)
  7079. for i := 0; i < len(patient); i++ {
  7080. repeat := false
  7081. for j := i + 1; j < len(patient); j++ {
  7082. if patient[i].ID == patient[j].ID {
  7083. repeat = true
  7084. break
  7085. }
  7086. }
  7087. if !repeat {
  7088. newArr = append(newArr, patient[i])
  7089. }
  7090. }
  7091. return
  7092. }
  7093. func (c *HisApiController) GetHisChargePatientInfo() {
  7094. patient_id, _ := c.GetInt64("patient_id")
  7095. his_patient_id, _ := c.GetInt64("his_patient_id")
  7096. record_date := c.GetString("record_date")
  7097. //start_time := c.GetString("start_time")
  7098. //end_time := c.GetString("end_time")
  7099. order_status, _ := c.GetInt64("type", 0)
  7100. p_type, _ := c.GetInt64("p_type", 0)
  7101. order_id, _ := c.GetInt64("order_id", 0)
  7102. timeLayout := "2006-01-02"
  7103. loc, _ := time.LoadLocation("Local")
  7104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7105. if err != nil {
  7106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7107. return
  7108. }
  7109. recordDateTime := theTime.Unix()
  7110. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7111. //if err != nil {
  7112. //
  7113. //}
  7114. //startRecordDateTime := startTime.Unix()
  7115. //
  7116. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7117. //if err != nil {
  7118. //
  7119. //}
  7120. //endRecordDateTime := endTime.Unix()
  7121. admin := c.GetAdminUserInfo()
  7122. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7123. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7124. var prescriptions []*models.HisPrescription
  7125. //var unChargeMonthPrescriptions []*models.HisPrescription
  7126. order, _ := service.GetHisOrderByID(order_id)
  7127. if order_status == 1 || order_status == 0 {
  7128. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7129. } else if order_status == 2 {
  7130. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7131. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7132. }
  7133. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7134. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7135. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7136. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7137. //获取所有科室信息
  7138. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7139. c.ServeSuccessJSON(map[string]interface{}{
  7140. "his_info": his_patient_info,
  7141. "xt_info": xt_patient_info,
  7142. "prescription": prescriptions,
  7143. "case_history": case_history,
  7144. "info": patientPrescriptionInfo,
  7145. "last_info": lastPatientPrescriptionInfo,
  7146. "order": order,
  7147. "doctors": doctors,
  7148. "department": department,
  7149. })
  7150. return
  7151. }
  7152. func (c *HisApiController) GetAllOrderDetail() {
  7153. order_id, _ := c.GetInt64("id", 0)
  7154. order, _ := service.GetHisOrderByID(order_id)
  7155. if order.ID == 0 {
  7156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7157. return
  7158. }
  7159. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7160. org_id := c.GetAdminUserInfo().CurrentOrgId
  7161. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7162. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7163. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7164. c.ServeSuccessJSON(map[string]interface{}{
  7165. "order": order,
  7166. "order_info": order_info,
  7167. "patient": patient,
  7168. "admin_info": adminInfo,
  7169. "hospital_record": record,
  7170. })
  7171. return
  7172. }
  7173. func (c *HisApiController) GetAllOrderDetailCollect() {
  7174. order_id, _ := c.GetInt64("id", 0)
  7175. order, _ := service.GetHisOrderByID(order_id)
  7176. if order.ID == 0 {
  7177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7178. return
  7179. }
  7180. org_id := c.GetAdminUserInfo().CurrentOrgId
  7181. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7182. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7183. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7184. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7185. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7186. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7187. var bedCostTotal float64 = 0 //床位总费
  7188. //var bedCostSelfTotal float64 = 0 //床位自费
  7189. var operationCostTotal float64 = 0 //手术费
  7190. //var operationCostSelfTotal float64 = 0 //手术费
  7191. var otherCostTotal float64 = 0 //其他费用
  7192. //var otherCostSelfTotal float64 = 0 //其他费用
  7193. var materialCostTotal float64 = 0 //材料费
  7194. //var materialCostSelfTotal float64 = 0 //材料费
  7195. var westernMedicineCostTotal float64 = 0 //西药费
  7196. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7197. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7198. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7199. var checkCostTotal float64 = 0 //检查费
  7200. //var checkCostSelfTotal float64 = 0 //检查费
  7201. var laboratoryCostTotal float64 = 0 //化验费
  7202. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7203. var treatCostTotal float64 = 0 //治疗费用
  7204. //var treatCostSelfTotal float64 = 0 //治疗费用
  7205. var zhenChaCostTotal float64 = 0 //其他费用
  7206. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7207. decimal.DivisionPrecision = 2
  7208. var BalanceAccountsType int64
  7209. if his.ID > 0 {
  7210. BalanceAccountsType = his.BalanceAccountsType
  7211. } else {
  7212. BalanceAccountsType = record.BalanceAccountsType
  7213. }
  7214. if BalanceAccountsType != 2 {
  7215. for _, item := range order_info {
  7216. if org_id == 10215 {
  7217. if item.MedChrgitmType == "01" { //床位费
  7218. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7219. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7220. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7221. }
  7222. if item.MedChrgitmType == "02" { //诊察费
  7223. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7224. //zhenChaCostSelfTotal = zhenChaCostTotal
  7225. }
  7226. if item.MedChrgitmType == "03" { //检查费
  7227. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7228. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7229. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7230. }
  7231. //if item.MedChrgitmType == "02" { //检查费
  7232. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7233. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7234. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7235. //}
  7236. if item.MedChrgitmType == "04" { //化验费
  7237. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7238. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7239. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7240. }
  7241. if item.MedChrgitmType == "05" { //治疗费
  7242. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7243. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7244. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7245. }
  7246. if item.MedChrgitmType == "06" { //手术费
  7247. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7248. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7249. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7250. }
  7251. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7252. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7253. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7254. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7255. }
  7256. if item.MedChrgitmType == "09" { //西药费
  7257. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7258. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7259. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7260. }
  7261. if item.MedChrgitmType == "11" { //中成费
  7262. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7263. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7264. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7265. }
  7266. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7267. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7268. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7269. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7270. }
  7271. } else if org_id == 10188 || org_id == 10217 {
  7272. if item.MedChrgitmType == "01" { //床位费
  7273. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7274. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7275. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7276. }
  7277. if item.MedChrgitmType == "02" { //诊察费
  7278. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7279. //zhenChaCostSelfTotal = zhenChaCostTotal
  7280. }
  7281. if item.MedChrgitmType == "03" { //检查费
  7282. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7283. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7284. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7285. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7286. }
  7287. //if item.MedChrgitmType == "02" { //检查费
  7288. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7289. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7290. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7291. //}
  7292. if item.MedChrgitmType == "04" { //化验费
  7293. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7294. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7295. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7296. }
  7297. if item.MedChrgitmType == "05" { //治疗费
  7298. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7299. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7300. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7301. }
  7302. if item.MedChrgitmType == "06" { //手术费
  7303. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7304. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7305. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7306. }
  7307. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7308. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7309. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7310. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7311. }
  7312. if item.MedChrgitmType == "09" { //西药费
  7313. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7314. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7315. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7316. }
  7317. if item.MedChrgitmType == "11" { //中成费
  7318. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7319. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7320. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7321. }
  7322. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7323. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7324. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7325. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7326. }
  7327. } else {
  7328. if item.MedChrgitmType == "01" { //床位费
  7329. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7330. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7331. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7332. }
  7333. //if item.MedChrgitmType == "02" { //诊察费
  7334. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7336. //}
  7337. if item.MedChrgitmType == "03" { //检查费
  7338. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7339. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7340. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7341. }
  7342. //if item.MedChrgitmType == "02" { //检查费
  7343. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7344. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7345. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7346. //}
  7347. if item.MedChrgitmType == "04" { //化验费
  7348. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7349. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7350. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7351. }
  7352. if item.MedChrgitmType == "05" { //治疗费
  7353. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7354. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7355. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7356. }
  7357. if item.MedChrgitmType == "06" { //手术费
  7358. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7359. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7360. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7361. }
  7362. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7363. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7364. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7365. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7366. }
  7367. if item.MedChrgitmType == "09" { //西药费
  7368. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7369. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7370. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7371. }
  7372. if item.MedChrgitmType == "11" { //中成费
  7373. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7374. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7375. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7376. }
  7377. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7378. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7379. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7380. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7381. }
  7382. }
  7383. }
  7384. c.ServeSuccessJSON(map[string]interface{}{
  7385. "order": order,
  7386. "order_info": order_info,
  7387. "patient": patient,
  7388. "admin_info": adminInfo,
  7389. "his_hospital": record,
  7390. "bedCostTotal": bedCostTotal,
  7391. "operationCostTotal": operationCostTotal,
  7392. "otherCostTotal": otherCostTotal,
  7393. "materialCostTotal": materialCostTotal,
  7394. "westernMedicineCostTotal": westernMedicineCostTotal,
  7395. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7396. "checkCostTotal": checkCostTotal,
  7397. "zhenChaCostTotal": zhenChaCostTotal,
  7398. "laboratoryCostTotal": laboratoryCostTotal,
  7399. "treatCostTotal": treatCostTotal,
  7400. })
  7401. } else {
  7402. for _, item := range order_info {
  7403. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7404. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7405. item.MedChrgitmType = "09"
  7406. }
  7407. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7408. if item.HisPrescriptionProject.Type == 2 {
  7409. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7410. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7411. case 0:
  7412. item.MedChrgitmType = "0"
  7413. break
  7414. case 1:
  7415. item.MedChrgitmType = "14"
  7416. break
  7417. case 2:
  7418. item.MedChrgitmType = "05"
  7419. break
  7420. case 3:
  7421. item.MedChrgitmType = "03"
  7422. break
  7423. case 4:
  7424. item.MedChrgitmType = "03"
  7425. break
  7426. case 5:
  7427. item.MedChrgitmType = "08"
  7428. break
  7429. case 6:
  7430. item.MedChrgitmType = "14"
  7431. break
  7432. case 7:
  7433. item.MedChrgitmType = "14"
  7434. break
  7435. case 8:
  7436. item.MedChrgitmType = "03"
  7437. break
  7438. case 9:
  7439. item.MedChrgitmType = "14"
  7440. break
  7441. case 10:
  7442. item.MedChrgitmType = "14"
  7443. break
  7444. case 11:
  7445. item.MedChrgitmType = "06"
  7446. break
  7447. case 12:
  7448. item.MedChrgitmType = "12"
  7449. break
  7450. case 13:
  7451. item.MedChrgitmType = "01"
  7452. break
  7453. case 14:
  7454. item.MedChrgitmType = "04"
  7455. break
  7456. case 15:
  7457. item.MedChrgitmType = "14"
  7458. break
  7459. }
  7460. } else {
  7461. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7462. case 1:
  7463. item.MedChrgitmType = "14"
  7464. break
  7465. case 2:
  7466. item.MedChrgitmType = "05"
  7467. break
  7468. case 3:
  7469. item.MedChrgitmType = "04"
  7470. break
  7471. case 4:
  7472. item.MedChrgitmType = "14"
  7473. break
  7474. case 5:
  7475. item.MedChrgitmType = "08"
  7476. break
  7477. case 6:
  7478. item.MedChrgitmType = "14"
  7479. break
  7480. case 7:
  7481. item.MedChrgitmType = "14"
  7482. break
  7483. case 8:
  7484. item.MedChrgitmType = "03"
  7485. break
  7486. case 9:
  7487. item.MedChrgitmType = "14"
  7488. break
  7489. }
  7490. }
  7491. } else if item.HisPrescriptionProject.Type == 3 {
  7492. item.MedChrgitmType = "08"
  7493. }
  7494. }
  7495. }
  7496. for _, item := range order_info {
  7497. if org_id == 10215 {
  7498. if item.MedChrgitmType == "01" { //床位费
  7499. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7500. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7501. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7502. }
  7503. if item.MedChrgitmType == "02" { //诊察费
  7504. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7505. //zhenChaCostSelfTotal = zhenChaCostTotal
  7506. }
  7507. if item.MedChrgitmType == "03" { //检查费
  7508. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7509. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7510. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7511. }
  7512. //if item.MedChrgitmType == "02" { //检查费
  7513. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7514. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7515. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7516. //}
  7517. if item.MedChrgitmType == "04" { //化验费
  7518. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7519. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7520. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7521. }
  7522. if item.MedChrgitmType == "05" { //治疗费
  7523. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7524. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7525. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7526. }
  7527. if item.MedChrgitmType == "06" { //手术费
  7528. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7529. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7530. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7531. }
  7532. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7533. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7534. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7535. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7536. }
  7537. if item.MedChrgitmType == "09" { //西药费
  7538. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7539. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7540. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7541. }
  7542. if item.MedChrgitmType == "11" { //中成费
  7543. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7544. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7545. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7546. }
  7547. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7548. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7549. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7550. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7551. }
  7552. } else {
  7553. if item.MedChrgitmType == "01" { //床位费
  7554. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7555. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7556. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7557. }
  7558. //if item.MedChrgitmType == "02" { //诊察费
  7559. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7560. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7561. //}
  7562. if item.MedChrgitmType == "03" { //检查费
  7563. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7564. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7565. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7566. }
  7567. //if item.MedChrgitmType == "02" { //检查费
  7568. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7569. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7570. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7571. //}
  7572. if item.MedChrgitmType == "04" { //化验费
  7573. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7574. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7575. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7576. }
  7577. if item.MedChrgitmType == "05" { //治疗费
  7578. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7579. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7580. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7581. }
  7582. if item.MedChrgitmType == "06" { //手术费
  7583. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7584. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7585. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7586. }
  7587. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7588. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7589. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7590. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7591. }
  7592. if item.MedChrgitmType == "09" { //西药费
  7593. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7594. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7595. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7596. }
  7597. if item.MedChrgitmType == "11" { //中成费
  7598. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7599. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7600. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7601. }
  7602. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7603. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7604. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7605. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7606. }
  7607. }
  7608. }
  7609. c.ServeSuccessJSON(map[string]interface{}{
  7610. "order": order,
  7611. "order_info": order_info,
  7612. "patient": patient,
  7613. "admin_info": adminInfo,
  7614. "his_hospital": record,
  7615. "bedCostTotal": bedCostTotal,
  7616. "operationCostTotal": operationCostTotal,
  7617. "otherCostTotal": otherCostTotal,
  7618. "materialCostTotal": materialCostTotal,
  7619. "westernMedicineCostTotal": westernMedicineCostTotal,
  7620. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7621. "checkCostTotal": checkCostTotal,
  7622. "zhenChaCostTotal": zhenChaCostTotal,
  7623. "laboratoryCostTotal": laboratoryCostTotal,
  7624. "treatCostTotal": treatCostTotal,
  7625. })
  7626. }
  7627. }
  7628. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7629. page, _ := c.GetInt64("page")
  7630. limit, _ := c.GetInt64("limit")
  7631. keywords := c.GetString("keywords")
  7632. start_time := c.GetString("start_time")
  7633. end_time := c.GetString("end_time")
  7634. //clr_type := c.GetString("clr_type")
  7635. insutype := c.GetString("insutype")
  7636. timeLayout := "2006-01-02"
  7637. loc, _ := time.LoadLocation("Local")
  7638. var theStartTIme int64
  7639. if len(start_time) > 0 {
  7640. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7641. theStartTIme = theTime.Unix()
  7642. }
  7643. var theEndtTIme int64
  7644. if len(end_time) > 0 {
  7645. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7646. theEndtTIme = theTime.Unix()
  7647. }
  7648. if page <= 0 {
  7649. page = 1
  7650. }
  7651. if limit <= 0 {
  7652. limit = 10
  7653. }
  7654. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7655. c.ServeSuccessJSON(map[string]interface{}{
  7656. "total": total,
  7657. "list": list,
  7658. })
  7659. return
  7660. }
  7661. func (c *HisApiController) GetPutOnRecordList() {
  7662. page, _ := c.GetInt64("page")
  7663. limit, _ := c.GetInt64("limit")
  7664. keywords := c.GetString("keywords")
  7665. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7666. if page <= 0 {
  7667. page = 1
  7668. }
  7669. if limit <= 0 {
  7670. limit = 10
  7671. }
  7672. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7673. c.ServeSuccessJSON(map[string]interface{}{
  7674. "total": total,
  7675. "list": list,
  7676. })
  7677. return
  7678. }
  7679. func (c *HisApiController) GetCompareData() {
  7680. start_time := c.GetString("start_time")
  7681. end_time := c.GetString("end_time")
  7682. insutype := c.GetString("insutype")
  7683. clr_type := c.GetString("clr_type")
  7684. timeLayout := "2006-01-02"
  7685. loc, _ := time.LoadLocation("Local")
  7686. var theStartTIme int64
  7687. if len(start_time) > 0 {
  7688. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7689. if err != nil {
  7690. theStartTIme = 0
  7691. }
  7692. theStartTIme = theTime.Unix()
  7693. }
  7694. var theEndtTIme int64
  7695. if len(end_time) > 0 {
  7696. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7697. if err != nil {
  7698. theEndtTIme = 0
  7699. }
  7700. theEndtTIme = theTime.Unix()
  7701. }
  7702. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7703. fmt.Println(err)
  7704. if err == nil {
  7705. c.ServeSuccessJSON(map[string]interface{}{
  7706. "list": formData,
  7707. })
  7708. } else {
  7709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7710. return
  7711. }
  7712. }
  7713. func (c *HisApiController) GetFaPiaoData() {
  7714. order_id, _ := c.GetInt64("order_id")
  7715. patient_id, _ := c.GetInt64("patient_id")
  7716. //number := c.GetString("number")
  7717. adminUser := c.GetAdminUserInfo()
  7718. order, _ := service.GetHisOrderByID(order_id)
  7719. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7720. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7721. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7722. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7723. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7724. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7725. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7726. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7727. var bedCostTotal float64 = 0 //床位总费
  7728. var bedCostSelfTotal float64 = 0 //床位自费
  7729. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7730. var operationCostTotal float64 = 0 //手术费
  7731. var operationCostSelfTotal float64 = 0 //手术费
  7732. var operationCostPartSelfTotal float64 = 0 //手术费
  7733. var otherCostTotal float64 = 0 //其他费用
  7734. var otherCostSelfTotal float64 = 0 //其他费用
  7735. var otherCostPartSelfTotal float64 = 0 //其他费用
  7736. var materialCostTotal float64 = 0 //材料费
  7737. var materialCostSelfTotal float64 = 0 //材料费
  7738. var materialCostPartSelfTotal float64 = 0 //材料费
  7739. var westernMedicineCostTotal float64 = 0 //西药费
  7740. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7741. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7742. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7743. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7744. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7745. var checkCostTotal float64 = 0 //检查费
  7746. var checkCostSelfTotal float64 = 0 //检查费
  7747. var checkCostPartSelfTotal float64 = 0 //检查费
  7748. var hiliCostTotal float64 = 0 //护理费
  7749. var hiliCostSelfTotal float64 = 0 //护理费
  7750. var hiliCostPartSelfTotal float64 = 0 //护理费
  7751. var laboratoryCostTotal float64 = 0 //化验费
  7752. var laboratoryCostSelfTotal float64 = 0 //化验费
  7753. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7754. var treatCostTotal float64 = 0 //治疗费用
  7755. var treatCostSelfTotal float64 = 0 //治疗费用
  7756. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7757. var zhenChaCostTotal float64 = 0 //其他费用
  7758. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7759. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7760. decimal.DivisionPrecision = 2
  7761. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7762. var balanceAccountsType int64
  7763. if his.ID > 0 {
  7764. balanceAccountsType = his.BalanceAccountsType
  7765. } else {
  7766. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7767. }
  7768. if balanceAccountsType == 2 {
  7769. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7770. for _, item := range orderInfos_two {
  7771. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7772. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7773. item.MedChrgitmType = "09"
  7774. }
  7775. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7776. if item.HisPrescriptionProject.Type == 2 {
  7777. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7778. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7779. case 0:
  7780. item.MedChrgitmType = "0"
  7781. break
  7782. case 1:
  7783. item.MedChrgitmType = "14"
  7784. break
  7785. case 2:
  7786. item.MedChrgitmType = "05"
  7787. break
  7788. case 3:
  7789. item.MedChrgitmType = "03"
  7790. break
  7791. case 4:
  7792. item.MedChrgitmType = "03"
  7793. break
  7794. case 5:
  7795. item.MedChrgitmType = "08"
  7796. break
  7797. case 6:
  7798. item.MedChrgitmType = "14"
  7799. break
  7800. case 7:
  7801. item.MedChrgitmType = "14"
  7802. break
  7803. case 8:
  7804. item.MedChrgitmType = "03"
  7805. break
  7806. case 9:
  7807. item.MedChrgitmType = "14"
  7808. break
  7809. case 10:
  7810. item.MedChrgitmType = "14"
  7811. break
  7812. case 11:
  7813. item.MedChrgitmType = "06"
  7814. break
  7815. case 12:
  7816. item.MedChrgitmType = "12"
  7817. break
  7818. case 13:
  7819. item.MedChrgitmType = "01"
  7820. break
  7821. case 14:
  7822. item.MedChrgitmType = "04"
  7823. break
  7824. case 15:
  7825. item.MedChrgitmType = "02"
  7826. break
  7827. }
  7828. } else {
  7829. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7830. case 1:
  7831. item.MedChrgitmType = "14"
  7832. break
  7833. case 2:
  7834. item.MedChrgitmType = "05"
  7835. break
  7836. case 3:
  7837. item.MedChrgitmType = "03"
  7838. break
  7839. case 4:
  7840. item.MedChrgitmType = "03"
  7841. break
  7842. case 5:
  7843. item.MedChrgitmType = "08"
  7844. break
  7845. case 6:
  7846. item.MedChrgitmType = "14"
  7847. break
  7848. case 7:
  7849. item.MedChrgitmType = "14"
  7850. break
  7851. case 8:
  7852. item.MedChrgitmType = "03"
  7853. break
  7854. case 9:
  7855. item.MedChrgitmType = "14"
  7856. break
  7857. }
  7858. }
  7859. } else if item.HisPrescriptionProject.Type == 3 {
  7860. item.MedChrgitmType = "08"
  7861. }
  7862. }
  7863. }
  7864. for _, item := range orderInfos_two {
  7865. fmt.Println(item.MedChrgitmType)
  7866. if item.MedChrgitmType == "07" { //床位费
  7867. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7868. hiliCostSelfTotal = hiliCostTotal
  7869. }
  7870. if item.MedChrgitmType == "01" { //床位费
  7871. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7872. bedCostSelfTotal = bedCostTotal
  7873. }
  7874. if item.MedChrgitmType == "02" { //诊察费
  7875. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7876. zhenChaCostSelfTotal = zhenChaCostTotal
  7877. }
  7878. if item.MedChrgitmType == "03" { //检查费
  7879. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7880. checkCostSelfTotal = checkCostTotal
  7881. }
  7882. if item.MedChrgitmType == "04" { //化验费
  7883. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7884. laboratoryCostSelfTotal = laboratoryCostTotal
  7885. }
  7886. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7887. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7888. treatCostSelfTotal = treatCostTotal
  7889. }
  7890. if item.MedChrgitmType == "06" { //手术费
  7891. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7892. operationCostSelfTotal = treatCostTotal
  7893. }
  7894. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7895. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7896. materialCostSelfTotal = materialCostTotal
  7897. }
  7898. if item.MedChrgitmType == "09" { //西药费
  7899. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7900. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7901. }
  7902. if item.MedChrgitmType == "11" { //中成费
  7903. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7904. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7905. }
  7906. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7907. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7908. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7909. otherCostSelfTotal = otherCostTotal
  7910. }
  7911. } else {
  7912. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7913. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7914. otherCostSelfTotal = otherCostTotal
  7915. }
  7916. }
  7917. }
  7918. } else {
  7919. for _, item := range orderInfos {
  7920. if item.MedChrgitmType == "01" { //床位费
  7921. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7922. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7923. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7924. }
  7925. if item.MedChrgitmType == "02" { //诊察费
  7926. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7927. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7928. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7929. }
  7930. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7931. if item.MedChrgitmType == "03" { //检查费
  7932. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7933. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7934. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7935. }
  7936. } else {
  7937. if item.MedChrgitmType == "03" { //检查费
  7938. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7939. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7940. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7941. }
  7942. }
  7943. if item.MedChrgitmType == "04" { //化验费
  7944. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7945. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7946. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7947. }
  7948. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7949. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7950. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7951. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7952. }
  7953. if item.MedChrgitmType == "06" { //手术费
  7954. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7955. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7956. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7957. }
  7958. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  7959. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7960. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7961. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7962. }
  7963. if item.MedChrgitmType == "07" { //西药费
  7964. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7965. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7966. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7967. }
  7968. if item.MedChrgitmType == "09" { //西药费
  7969. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7970. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7971. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7972. }
  7973. if item.MedChrgitmType == "11" { //中成费
  7974. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7975. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7976. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7977. }
  7978. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7979. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7980. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7981. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7982. }
  7983. }
  7984. }
  7985. timeLayout := "2006-01-02"
  7986. loc, _ := time.LoadLocation("Local")
  7987. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7988. if err != nil {
  7989. }
  7990. startRecordDateTime := startTime.Unix()
  7991. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7992. if err != nil {
  7993. }
  7994. endRecordDateTime := endTime.Unix()
  7995. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7996. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7997. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7998. c.ServeSuccessJSON(map[string]interface{}{
  7999. "order_number": order.Number, //业务流水号
  8000. "id_card_no": his.IdCardNo, //社会保障号
  8001. "patient": patient,
  8002. "department_name": department.Name, //科室
  8003. "number": his.Number, //门诊号
  8004. "date": order.SettleAccountsDate, //结算日期
  8005. "name": order.PsnName, //姓名
  8006. "gender": patient.Gender, //性别
  8007. "psn_cash_money": order.PsnCashPay, //个人支付
  8008. "pay_way": "门诊", //结算方式
  8009. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8010. "admin_user_name": admin.UserName, //收款员
  8011. "order": order,
  8012. "order_info": orderInfos_two,
  8013. "his": his,
  8014. "bedCostTotal": bedCostTotal,
  8015. "bedCostSelfTotal": bedCostSelfTotal,
  8016. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8017. "operationCostTotal": operationCostTotal,
  8018. "operationCostSelfTotal": operationCostSelfTotal,
  8019. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8020. "otherCostTotal": otherCostTotal,
  8021. "otherCostSelfTotal": otherCostSelfTotal,
  8022. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8023. "materialCostTotal": materialCostTotal,
  8024. "materialCostSelfTotal": materialCostSelfTotal,
  8025. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8026. "westernMedicineCostTotal": westernMedicineCostTotal,
  8027. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8028. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8029. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8030. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8031. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8032. "checkCostTotal": checkCostTotal,
  8033. "checkCostSelfTotal": checkCostSelfTotal,
  8034. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8035. "laboratoryCostTotal": laboratoryCostTotal,
  8036. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8037. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8038. "treatCostTotal": treatCostTotal,
  8039. "treatCostSelfTotal": treatCostSelfTotal,
  8040. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8041. "zhenChaCostTotal": zhenChaCostTotal,
  8042. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8043. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8044. "his_hospital_record": his_hospital_record,
  8045. "pre_pay_money": pre_pay_money,
  8046. "refund_sum": sum,
  8047. "doctor_info": doctor_info,
  8048. "hiliCostTotal": hiliCostTotal,
  8049. "hiliCostSelfTotal": hiliCostSelfTotal,
  8050. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8051. })
  8052. }
  8053. //func (c *HisApiController) GetFaPiaoDatas() {
  8054. // order_ids := c.GetString("order_ids")
  8055. // patient_id, _ := c.GetInt64("patient_id")
  8056. // adminUser := c.GetAdminUserInfo()
  8057. //
  8058. // orders := strings.Split(order_ids, ",")
  8059. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8060. //
  8061. // for _, item := range orders {
  8062. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8063. // order, _ := service.GetHisOrderByID(order_id)
  8064. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8065. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8066. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8067. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8068. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8069. //
  8070. // }
  8071. //
  8072. // var bedCostTotal float64 = 0 //床位总费
  8073. // var bedCostSelfTotal float64 = 0 //床位自费
  8074. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8075. //
  8076. // var operationCostTotal float64 = 0 //手术费
  8077. // var operationCostSelfTotal float64 = 0 //手术费
  8078. // var operationCostPartSelfTotal float64 = 0 //手术费
  8079. //
  8080. // var otherCostTotal float64 = 0 //其他费用
  8081. // var otherCostSelfTotal float64 = 0 //其他费用
  8082. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8083. //
  8084. // var materialCostTotal float64 = 0 //材料费
  8085. // var materialCostSelfTotal float64 = 0 //材料费
  8086. // var materialCostPartSelfTotal float64 = 0 //材料费
  8087. //
  8088. // var westernMedicineCostTotal float64 = 0 //西药费
  8089. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8090. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8091. //
  8092. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8093. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8094. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8095. //
  8096. // var checkCostTotal float64 = 0 //检查费
  8097. // var checkCostSelfTotal float64 = 0 //检查费
  8098. // var checkCostPartSelfTotal float64 = 0 //检查费
  8099. //
  8100. // var laboratoryCostTotal float64 = 0 //化验费
  8101. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8102. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8103. //
  8104. // var treatCostTotal float64 = 0 //治疗费用
  8105. // var treatCostSelfTotal float64 = 0 //治疗费用
  8106. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8107. //
  8108. // var zhenChaCostTotal float64 = 0 //其他费用
  8109. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8110. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8111. //
  8112. // decimal.DivisionPrecision = 2
  8113. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8114. //
  8115. // var balanceAccountsType int64
  8116. // if his.ID > 0 {
  8117. // balanceAccountsType = his.BalanceAccountsType
  8118. // } else {
  8119. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8120. // }
  8121. // if balanceAccountsType == 2 {
  8122. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8123. // for _, item := range orderInfos_two {
  8124. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8125. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8126. // item.MedChrgitmType = "09"
  8127. // }
  8128. //
  8129. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8130. // if item.HisPrescriptionProject.Type == 2 {
  8131. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8132. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8133. // case 0:
  8134. // item.MedChrgitmType = "0"
  8135. // break
  8136. // case 1:
  8137. // item.MedChrgitmType = "14"
  8138. // break
  8139. // case 2:
  8140. // item.MedChrgitmType = "05"
  8141. //
  8142. // break
  8143. // case 3:
  8144. // item.MedChrgitmType = "03"
  8145. //
  8146. // break
  8147. // case 4:
  8148. // item.MedChrgitmType = "03"
  8149. //
  8150. // break
  8151. // case 5:
  8152. // item.MedChrgitmType = "08"
  8153. //
  8154. // break
  8155. // case 6:
  8156. // item.MedChrgitmType = "14"
  8157. //
  8158. // break
  8159. // case 7:
  8160. // item.MedChrgitmType = "14"
  8161. //
  8162. // break
  8163. // case 8:
  8164. // item.MedChrgitmType = "03"
  8165. // break
  8166. // case 9:
  8167. // item.MedChrgitmType = "14"
  8168. // break
  8169. // case 10:
  8170. // item.MedChrgitmType = "14"
  8171. // break
  8172. // case 11:
  8173. // item.MedChrgitmType = "06"
  8174. // break
  8175. // case 12:
  8176. // item.MedChrgitmType = "12"
  8177. // break
  8178. // case 13:
  8179. // item.MedChrgitmType = "01"
  8180. // break
  8181. // case 14:
  8182. // item.MedChrgitmType = "04"
  8183. // break
  8184. // case 15:
  8185. // item.MedChrgitmType = "02"
  8186. // break
  8187. //
  8188. // }
  8189. //
  8190. // } else {
  8191. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8192. //
  8193. // case 1:
  8194. // item.MedChrgitmType = "14"
  8195. // break
  8196. // case 2:
  8197. // item.MedChrgitmType = "05"
  8198. //
  8199. // break
  8200. // case 3:
  8201. // item.MedChrgitmType = "03"
  8202. //
  8203. // break
  8204. // case 4:
  8205. // item.MedChrgitmType = "03"
  8206. //
  8207. // break
  8208. // case 5:
  8209. // item.MedChrgitmType = "08"
  8210. //
  8211. // break
  8212. // case 6:
  8213. // item.MedChrgitmType = "14"
  8214. //
  8215. // break
  8216. // case 7:
  8217. // item.MedChrgitmType = "14"
  8218. //
  8219. // break
  8220. // case 8:
  8221. // item.MedChrgitmType = "03"
  8222. // break
  8223. // case 9:
  8224. // item.MedChrgitmType = "14"
  8225. // break
  8226. //
  8227. // }
  8228. //
  8229. // }
  8230. //
  8231. // } else if item.HisPrescriptionProject.Type == 3 {
  8232. // item.MedChrgitmType = "08"
  8233. // }
  8234. // }
  8235. // }
  8236. //
  8237. // for _, item := range orderInfos_two {
  8238. // fmt.Println(item.MedChrgitmType)
  8239. // if item.MedChrgitmType == "01" { //床位费
  8240. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8241. // bedCostSelfTotal = bedCostTotal
  8242. // }
  8243. //
  8244. // if item.MedChrgitmType == "02" { //诊察费
  8245. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8246. // zhenChaCostSelfTotal = zhenChaCostTotal
  8247. // }
  8248. //
  8249. // if item.MedChrgitmType == "03" { //检查费
  8250. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8251. // checkCostSelfTotal = checkCostTotal
  8252. // }
  8253. //
  8254. // if item.MedChrgitmType == "04" { //化验费
  8255. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8256. // laboratoryCostSelfTotal = laboratoryCostTotal
  8257. // }
  8258. //
  8259. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8260. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8261. // treatCostSelfTotal = treatCostTotal
  8262. // }
  8263. //
  8264. // if item.MedChrgitmType == "06" { //手术费
  8265. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8266. // operationCostSelfTotal = treatCostTotal
  8267. // }
  8268. //
  8269. // if item.MedChrgitmType == "08" { //材料费
  8270. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8271. // materialCostSelfTotal = materialCostTotal
  8272. // }
  8273. //
  8274. // if item.MedChrgitmType == "09" { //西药费
  8275. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8276. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8277. // }
  8278. //
  8279. // if item.MedChrgitmType == "11" { //中成费
  8280. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8281. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8282. // }
  8283. //
  8284. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8285. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8286. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8287. // otherCostSelfTotal = otherCostTotal
  8288. // }
  8289. // } else {
  8290. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8291. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8292. // otherCostSelfTotal = otherCostTotal
  8293. // }
  8294. //
  8295. // }
  8296. //
  8297. // }
  8298. //
  8299. // } else {
  8300. // for _, item := range orderInfos {
  8301. // if item.MedChrgitmType == "01" { //床位费
  8302. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8303. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8304. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8305. // }
  8306. //
  8307. // if item.MedChrgitmType == "02" { //诊察费
  8308. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8309. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8310. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8311. // }
  8312. //
  8313. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8314. // if item.MedChrgitmType == "03" { //检查费
  8315. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8316. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8317. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8318. //
  8319. // }
  8320. // } else {
  8321. // if item.MedChrgitmType == "03" { //检查费
  8322. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8323. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8324. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8325. // }
  8326. //
  8327. // }
  8328. //
  8329. // if item.MedChrgitmType == "04" { //化验费
  8330. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8331. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8332. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8333. //
  8334. // }
  8335. //
  8336. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8337. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8338. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8339. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8340. //
  8341. // }
  8342. //
  8343. // if item.MedChrgitmType == "06" { //手术费
  8344. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8345. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8346. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8347. // }
  8348. //
  8349. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8350. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8351. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8352. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8353. // }
  8354. //
  8355. // if item.MedChrgitmType == "09" { //西药费
  8356. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8357. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8358. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8359. // }
  8360. //
  8361. // if item.MedChrgitmType == "11" { //中成费
  8362. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8363. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8364. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8365. // }
  8366. //
  8367. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8368. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8369. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8370. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8371. // }
  8372. //
  8373. // }
  8374. // }
  8375. // timeLayout := "2006-01-02"
  8376. // loc, _ := time.LoadLocation("Local")
  8377. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8378. // if err != nil {
  8379. // }
  8380. // startRecordDateTime := startTime.Unix()
  8381. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8382. // if err != nil {
  8383. // }
  8384. // endRecordDateTime := endTime.Unix()
  8385. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8386. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8387. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8388. //
  8389. // c.ServeSuccessJSON(map[string]interface{}{
  8390. // "order_number": order.Number, //业务流水号
  8391. // "id_card_no": his.IdCardNo, //社会保障号
  8392. // "department_name": department.Name, //科室
  8393. // "number": his.Number, //门诊号
  8394. // "date": order.SettleAccountsDate, //结算日期
  8395. // "name": order.PsnName, //姓名
  8396. // "gender": patient.Gender, //性别
  8397. // "psn_cash_money": order.PsnCashPay, //个人支付
  8398. // "pay_way": "门诊", //结算方式
  8399. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8400. // "admin_user_name": admin.UserName, //收款员
  8401. // "order": order,
  8402. // "order_info": orderInfos_two,
  8403. // "his": his,
  8404. // "bedCostTotal": bedCostTotal,
  8405. // "bedCostSelfTotal": bedCostSelfTotal,
  8406. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8407. // "operationCostTotal": operationCostTotal,
  8408. // "operationCostSelfTotal": operationCostSelfTotal,
  8409. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8410. // "otherCostTotal": otherCostTotal,
  8411. // "otherCostSelfTotal": otherCostSelfTotal,
  8412. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8413. // "materialCostTotal": materialCostTotal,
  8414. // "materialCostSelfTotal": materialCostSelfTotal,
  8415. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8416. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8417. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8418. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8419. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8420. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8421. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8422. // "checkCostTotal": checkCostTotal,
  8423. // "checkCostSelfTotal": checkCostSelfTotal,
  8424. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8425. // "laboratoryCostTotal": laboratoryCostTotal,
  8426. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8427. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8428. // "treatCostTotal": treatCostTotal,
  8429. // "treatCostSelfTotal": treatCostSelfTotal,
  8430. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8431. // "zhenChaCostTotal": zhenChaCostTotal,
  8432. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8433. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8434. // "his_hospital_record": his_hospital_record,
  8435. // "pre_pay_money": pre_pay_money,
  8436. // "refund_sum": sum,
  8437. // })
  8438. //
  8439. //}
  8440. func (this *HisApiController) GetIncomeStatisticsData() {
  8441. start_time := this.GetString("start_time")
  8442. end_time := this.GetString("end_time")
  8443. key_words := this.GetString("key_words")
  8444. limit, _ := this.GetInt64("limit")
  8445. page, _ := this.GetInt64("page")
  8446. if page <= 0 {
  8447. page = 1
  8448. }
  8449. if limit <= 0 {
  8450. limit = 10
  8451. }
  8452. statistics_type, _ := this.GetInt64("statistics_type")
  8453. admin := this.GetAdminUserInfo()
  8454. timeLayout := "2006-01-02"
  8455. loc, _ := time.LoadLocation("Local")
  8456. var theStartTIme int64
  8457. if len(start_time) > 0 {
  8458. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8459. if err != nil {
  8460. theStartTIme = 0
  8461. }
  8462. theStartTIme = theTime.Unix()
  8463. }
  8464. var theEndtTIme int64
  8465. if len(end_time) > 0 {
  8466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8467. if err != nil {
  8468. theEndtTIme = 0
  8469. }
  8470. theEndtTIme = theTime.Unix()
  8471. }
  8472. if statistics_type == 1 {
  8473. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8474. this.ServeSuccessJSON(map[string]interface{}{
  8475. "list": list,
  8476. "total": total,
  8477. })
  8478. } else {
  8479. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8480. this.ServeSuccessJSON(map[string]interface{}{
  8481. "list": list,
  8482. "total": total,
  8483. })
  8484. }
  8485. }
  8486. func (c *HisApiController) PostProjectInformation() {
  8487. adminUser := c.GetAdminUserInfo()
  8488. orgId := adminUser.CurrentOrgId
  8489. dataBody := make(map[string]interface{}, 0)
  8490. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8491. if err != nil {
  8492. utils.ErrorLog(err.Error())
  8493. return
  8494. }
  8495. utils.ErrorLog("%v", dataBody)
  8496. var projectList []*models.HisProject
  8497. var total_goods []interface{}
  8498. tempProjects := dataBody["projects"].([]interface{})
  8499. total_goods = tempProjects
  8500. for index, projectMap := range tempProjects {
  8501. projectM := projectMap.(map[string]interface{})
  8502. var project models.HisProject
  8503. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8504. utils.ErrorLog("project_name")
  8505. return
  8506. }
  8507. project_name, _ := projectM["project_name"].(string)
  8508. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8509. err_log := models.ExportErrLog{
  8510. LogType: 6,
  8511. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8512. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8513. Status: 1,
  8514. CreateTime: time.Now().Unix(),
  8515. UpdateTime: time.Now().Unix(),
  8516. ExportTime: time.Now().Unix(),
  8517. }
  8518. service.CreateExportErrLog(&err_log)
  8519. continue
  8520. }
  8521. project.ProjectName = project_name
  8522. prices := projectM["price"].(string)
  8523. price, _ := strconv.ParseFloat(prices, 64)
  8524. if price <= 0 { //名字为空则生成一条导入错误日志
  8525. err_log := models.ExportErrLog{
  8526. LogType: 6,
  8527. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8528. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8529. Status: 1,
  8530. CreateTime: time.Now().Unix(),
  8531. UpdateTime: time.Now().Unix(),
  8532. ExportTime: time.Now().Unix(),
  8533. }
  8534. service.CreateExportErrLog(&err_log)
  8535. continue
  8536. }
  8537. project.Price = price
  8538. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8539. utils.ErrorLog("unit_id")
  8540. return
  8541. }
  8542. unit := projectM["unit"].(string)
  8543. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8544. err_log := models.ExportErrLog{
  8545. LogType: 6,
  8546. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8547. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8548. Status: 1,
  8549. CreateTime: time.Now().Unix(),
  8550. UpdateTime: time.Now().Unix(),
  8551. ExportTime: time.Now().Unix(),
  8552. }
  8553. service.CreateExportErrLog(&err_log)
  8554. continue
  8555. }
  8556. project.Unit = unit
  8557. cost_classify := projectM["cost_classify"].(string)
  8558. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8559. err_log := models.ExportErrLog{
  8560. LogType: 6,
  8561. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8562. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8563. Status: 1,
  8564. CreateTime: time.Now().Unix(),
  8565. UpdateTime: time.Now().Unix(),
  8566. ExportTime: time.Now().Unix(),
  8567. }
  8568. service.CreateExportErrLog(&err_log)
  8569. continue
  8570. }
  8571. var costClassify = "费用类别"
  8572. var cost_classify_id int64
  8573. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8574. if len(cost_classify) != 0 {
  8575. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8576. if errcode == gorm.ErrRecordNotFound {
  8577. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8578. dataconfig := models.DictDataconfig{
  8579. ParentId: costClassifyConfig.ID,
  8580. Module: "system",
  8581. OrgId: orgId,
  8582. Name: cost_classify,
  8583. FieldName: "",
  8584. Value: costConfig.Value + 1,
  8585. CreatedTime: "",
  8586. UpdatedTime: "",
  8587. CreateUserId: adminUser.AdminUser.Id,
  8588. Status: 1,
  8589. Remark: "",
  8590. DeleteIdSystem: 0,
  8591. Title: "",
  8592. Content: "",
  8593. Order: 0,
  8594. Code: "",
  8595. }
  8596. service.CreatedDicConfig(&dataconfig)
  8597. }
  8598. }
  8599. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8600. for _, it := range costClassList {
  8601. if cost_classify == it.Name {
  8602. cost_classify_id = int64(it.Value)
  8603. }
  8604. }
  8605. project.CostClassify = cost_classify_id
  8606. executive_section := projectM["executive_section"].(string)
  8607. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8608. err_log := models.ExportErrLog{
  8609. LogType: 6,
  8610. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8611. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8612. Status: 1,
  8613. CreateTime: time.Now().Unix(),
  8614. UpdateTime: time.Now().Unix(),
  8615. ExportTime: time.Now().Unix(),
  8616. }
  8617. service.CreateExportErrLog(&err_log)
  8618. continue
  8619. }
  8620. if len(executive_section) != 0 {
  8621. //查找科室是否有内容
  8622. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8623. if errcodedepart == gorm.ErrRecordNotFound {
  8624. department := models.XtHisDepartment{
  8625. Name: executive_section,
  8626. Status: 1,
  8627. UserOrgId: adminUser.CurrentOrgId,
  8628. CreatedTime: time.Now().Unix(),
  8629. }
  8630. service.CreateDePartment(&department)
  8631. }
  8632. }
  8633. var executive_section_id int64
  8634. departMentList, _ := service.GetAllDepartMent(orgId)
  8635. for _, it := range departMentList {
  8636. if executive_section == it.Name {
  8637. executive_section_id = it.ID
  8638. }
  8639. }
  8640. project.ExecutiveSection = executive_section_id
  8641. medical_coverage := projectM["medical_coverage"].(string)
  8642. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8643. err_log := models.ExportErrLog{
  8644. LogType: 6,
  8645. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8646. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8647. Status: 1,
  8648. CreateTime: time.Now().Unix(),
  8649. UpdateTime: time.Now().Unix(),
  8650. ExportTime: time.Now().Unix(),
  8651. }
  8652. service.CreateExportErrLog(&err_log)
  8653. continue
  8654. }
  8655. var medicalCoverage = "医保等级"
  8656. var medical_coverage_id int64
  8657. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8658. if len(medical_coverage) != 0 {
  8659. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8660. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8661. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8662. dataconfig := models.DictDataconfig{
  8663. ParentId: medicalCoverageConfig.ID,
  8664. Module: "system",
  8665. OrgId: orgId,
  8666. Name: medical_coverage,
  8667. FieldName: "",
  8668. Value: medicalCoverageConfig.Value + 1,
  8669. CreatedTime: "",
  8670. UpdatedTime: "",
  8671. CreateUserId: adminUser.AdminUser.Id,
  8672. Status: 1,
  8673. Remark: "",
  8674. DeleteIdSystem: 0,
  8675. Title: "",
  8676. Content: "",
  8677. Order: 0,
  8678. Code: "",
  8679. }
  8680. service.CreatedDicConfig(&dataconfig)
  8681. }
  8682. }
  8683. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8684. for _, it := range medicalCoverageList {
  8685. if medical_coverage == it.Name {
  8686. medical_coverage_id = int64(it.Value)
  8687. }
  8688. }
  8689. project.MedicalCoverage = medical_coverage_id
  8690. pinyin := projectM["pinyin"].(string)
  8691. project.Pinyin = pinyin
  8692. wubi := projectM["wubi"].(string)
  8693. project.Wubi = wubi
  8694. statistical_classification := projectM["statistical_classification"].(string)
  8695. var statisticalClassification = "统计分类"
  8696. var statistical_classification_id int64
  8697. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8698. if len(statistical_classification) != 0 {
  8699. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8700. if classificationerrcodes == gorm.ErrRecordNotFound {
  8701. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8702. dataconfig := models.DictDataconfig{
  8703. ParentId: classiFication.ID,
  8704. Module: "system",
  8705. OrgId: orgId,
  8706. Name: statistical_classification,
  8707. FieldName: "",
  8708. Value: classiFicationConfig.Value + 1,
  8709. CreatedTime: "",
  8710. UpdatedTime: "",
  8711. CreateUserId: adminUser.AdminUser.Id,
  8712. Status: 1,
  8713. Remark: "",
  8714. DeleteIdSystem: 0,
  8715. Title: "",
  8716. Content: "",
  8717. Order: 0,
  8718. Code: "",
  8719. }
  8720. service.CreatedDicConfig(&dataconfig)
  8721. }
  8722. }
  8723. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8724. for _, it := range classiFicationList {
  8725. if statistical_classification == it.Name {
  8726. statistical_classification_id = int64(it.Value)
  8727. }
  8728. }
  8729. project.StatisticalClassification = statistical_classification_id
  8730. disease_directory := int64(projectM["disease_directory"].(float64))
  8731. project.DiseaseDirectory = disease_directory
  8732. is_record := int64(projectM["is_record"].(float64))
  8733. project.IsRecord = is_record
  8734. medical_code := projectM["medical_code"].(string)
  8735. project.MedicalCode = medical_code
  8736. tube_color := projectM["tube_color"].(string)
  8737. var tubeColor = "试管颜色"
  8738. var tube_color_id int64
  8739. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8740. if len(tube_color) != 0 {
  8741. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8742. if errcodetube == gorm.ErrRecordNotFound {
  8743. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8744. dataconfig := models.DictDataconfig{
  8745. ParentId: tubeColorConfig.ID,
  8746. Module: "system",
  8747. OrgId: orgId,
  8748. Name: tube_color,
  8749. FieldName: "",
  8750. Value: tubeConfig.Value + 1,
  8751. CreatedTime: "",
  8752. UpdatedTime: "",
  8753. CreateUserId: adminUser.AdminUser.Id,
  8754. Status: 1,
  8755. Remark: "",
  8756. DeleteIdSystem: 0,
  8757. Title: "",
  8758. Content: "",
  8759. Order: 0,
  8760. Code: "",
  8761. }
  8762. service.CreatedDicConfig(&dataconfig)
  8763. }
  8764. }
  8765. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8766. for _, it := range tubeColorList {
  8767. if tube_color == it.Name {
  8768. tube_color_id = int64(it.Value)
  8769. }
  8770. }
  8771. project.TubeColor = tube_color_id
  8772. single_dose := projectM["single_dose"].(string)
  8773. project.SingleDose = single_dose
  8774. execution_frequency := projectM["execution_frequency"].(string)
  8775. project.ExecutionFrequency = execution_frequency
  8776. delivery_way := projectM["delivery_way"].(string)
  8777. project.DeliveryWay = delivery_way
  8778. number_days := projectM["number_days"].(string)
  8779. project.NumberDays = number_days
  8780. total := projectM["total"].(string)
  8781. project.Total = total
  8782. medical_status := int64(projectM["medical_status"].(float64))
  8783. project.MedicalStatus = medical_status
  8784. category := int64(projectM["category"].(float64))
  8785. project.Category = category
  8786. specail_project := int64(projectM["specail_project"].(float64))
  8787. project.SpecailProject = specail_project
  8788. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8789. project.SocialSecurityDirectoryCode = social_security_directory_code
  8790. remark := projectM["remark"].(string)
  8791. project.Remark = remark
  8792. record_date := projectM["record_date"].(string)
  8793. timeLayout := "2006-01-02"
  8794. loc, _ := time.LoadLocation("Local")
  8795. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8796. project.RecordDate = theTime.Unix()
  8797. projectList = append(projectList, &project)
  8798. }
  8799. export_time := time.Now().Unix()
  8800. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8801. if len(projectList) > 0 {
  8802. for _, item := range projectList {
  8803. project := models.HisProject{
  8804. ProjectName: item.ProjectName,
  8805. Price: item.Price,
  8806. Unit: item.Unit,
  8807. CostClassify: item.CostClassify,
  8808. ExecutiveSection: item.ExecutiveSection,
  8809. MedicalCoverage: item.MedicalCoverage,
  8810. UserOrgId: orgId,
  8811. Status: 1,
  8812. CreatedTime: time.Now().Unix(),
  8813. Pinyin: item.Pinyin,
  8814. Wubi: item.Wubi,
  8815. StatisticalClassification: item.StatisticalClassification,
  8816. DiseaseDirectory: item.DiseaseDirectory,
  8817. IsRecord: item.IsRecord,
  8818. MedicalCode: item.MedicalCode,
  8819. TubeColor: item.TubeColor,
  8820. SingleDose: item.SingleDose,
  8821. DeliveryWay: item.DeliveryWay,
  8822. NumberDays: item.NumberDays,
  8823. Total: item.Total,
  8824. Category: item.Category,
  8825. MedicalStatus: item.MedicalStatus,
  8826. SpecailProject: item.SpecailProject,
  8827. RecordDate: item.RecordDate,
  8828. Remark: item.Remark,
  8829. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8830. ExecutionFrequency: item.ExecutionFrequency,
  8831. }
  8832. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8833. if errcodeproject == gorm.ErrRecordNotFound {
  8834. service.CreateProjectInfomation(&project)
  8835. } else if errcodeproject == nil {
  8836. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8837. }
  8838. log := models.ExportLog{
  8839. LogType: 6,
  8840. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8841. TotalNum: int64(len(total_goods)),
  8842. FailNum: int64(len(errLogs)),
  8843. SuccessNum: int64(len(projectList)),
  8844. CreateTime: time.Now().Unix(),
  8845. UpdateTime: time.Now().Unix(),
  8846. ExportTime: export_time,
  8847. Status: 1,
  8848. }
  8849. service.CreateExportLog(&log)
  8850. c.ServeSuccessJSON(map[string]interface{}{
  8851. "msg": "导入成功",
  8852. "total_num": len(total_goods),
  8853. "success_num": len(projectList),
  8854. "fail_num": int64(len(errLogs)),
  8855. })
  8856. }
  8857. } else {
  8858. log := models.ExportLog{
  8859. LogType: 6,
  8860. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8861. TotalNum: int64(len(total_goods)),
  8862. FailNum: int64(len(errLogs)),
  8863. SuccessNum: int64(len(projectList)),
  8864. CreateTime: time.Now().Unix(),
  8865. UpdateTime: time.Now().Unix(),
  8866. ExportTime: export_time,
  8867. Status: 1,
  8868. }
  8869. service.CreateExportLog(&log)
  8870. c.ServeSuccessJSON(map[string]interface{}{
  8871. "msg": "导入成功",
  8872. "total_num": len(total_goods),
  8873. "success_num": len(projectList),
  8874. "fail_num": int64(len(errLogs)),
  8875. })
  8876. }
  8877. }
  8878. //func (this *HisApiController) EditProjectInformation(){
  8879. //
  8880. // id, _ := this.GetInt64("id")
  8881. // project_team := this.GetString("project_team")
  8882. // price := this.GetString("price")
  8883. // price_float, _ := strconv.ParseFloat(price, 64)
  8884. // pinyin := this.GetString("pinyin")
  8885. // wubi := this.GetString("wubi")
  8886. // tube_color, _ := this.GetInt64("tube_color")
  8887. // team_type, _ := this.GetInt64("team_type")
  8888. // remark := this.GetString("remark")
  8889. // ids := this.GetString("ids")
  8890. // item_id := this.GetString("item_id")
  8891. // projectTeam := models.XtHisProjectTeam{
  8892. // ProjectTeam: project_team,
  8893. // Price: price_float,
  8894. // Pinyin: pinyin,
  8895. // Wubi: wubi,
  8896. // TubeColor: tube_color,
  8897. // TeamType: team_type,
  8898. // Remark: remark,
  8899. // ProjectId: ids,
  8900. // ItemId: item_id,
  8901. // }
  8902. //
  8903. //
  8904. // dataBody := make(map[string]interface{}, 0)
  8905. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8906. // if err != nil {
  8907. // utils.ErrorLog(err.Error())
  8908. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8909. // return
  8910. // }
  8911. //
  8912. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8913. //
  8914. //
  8915. // if err != nil {
  8916. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8917. // return
  8918. // }
  8919. //
  8920. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8921. // infos, _ := dataBody["info"].([]interface{})
  8922. // if len(infos) > 0 {
  8923. // var ids []string
  8924. //
  8925. // for _, item := range infos {
  8926. // items := item.(map[string]interface{})
  8927. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8928. // utils.ErrorLog("id")
  8929. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8930. // return
  8931. // }
  8932. // id := int64(items["id"].(float64))
  8933. //
  8934. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8935. // utils.ErrorLog("type")
  8936. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8937. // return
  8938. // }
  8939. // types := int64(items["type"].(float64))
  8940. //
  8941. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8942. // utils.ErrorLog("number")
  8943. // }
  8944. //
  8945. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8946. //
  8947. // projectList := models.XtHisProjectList{
  8948. // Number: number,
  8949. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8950. // ProjectId: id,
  8951. // Status: 1,
  8952. // CreatedTime: time.Now().Unix(),
  8953. // UpdatedTime: time.Now().Unix(),
  8954. // TeamId: projectTeam.ID,
  8955. // Type: types,
  8956. // }
  8957. // list := projectList
  8958. //
  8959. // service.CreateProjectList(&list)
  8960. //
  8961. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8962. //
  8963. // }
  8964. // ids_str := strings.Join(ids, ",")
  8965. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8966. // service.SaveProjectTeam(&projectTeam)
  8967. // this.ServeSuccessJSON(map[string]interface{}{
  8968. // "projectTeam": projectTeam,
  8969. // })
  8970. // }
  8971. // }
  8972. //}
  8973. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8974. name := c.GetString("name")
  8975. mode_id, _ := c.GetInt64("mode", 0)
  8976. types, _ := c.GetInt64("type", 0)
  8977. patient_id, _ := c.GetInt64("patient_id", 0)
  8978. types = 1
  8979. adminInfo := c.GetAdminUserInfo()
  8980. template := &models.HisPrescriptionTemplate{
  8981. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8982. PatientId: patient_id,
  8983. Type: types,
  8984. Status: 1,
  8985. Ctime: time.Now().Unix(),
  8986. Mtime: time.Now().Unix(),
  8987. Name: name,
  8988. Mode: mode_id,
  8989. }
  8990. dataBody := make(map[string]interface{}, 0)
  8991. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8992. if err != nil {
  8993. utils.ErrorLog(err.Error())
  8994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8995. return
  8996. }
  8997. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8998. //如果已经存在记录则删除处方
  8999. if template_one.ID > 0 {
  9000. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9001. for _, item := range ps {
  9002. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  9003. }
  9004. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9005. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9006. if len(prescriptions) > 0 {
  9007. for _, item := range prescriptions {
  9008. items := item.(map[string]interface{})
  9009. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9010. utils.ErrorLog("type")
  9011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9012. return
  9013. }
  9014. types := int64(items["type"].(float64))
  9015. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9016. utils.ErrorLog("med_type")
  9017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9018. return
  9019. }
  9020. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9021. ctime := time.Now().Unix()
  9022. prescription := &models.HisPrescriptionInfoTemplate{
  9023. PatientId: patient_id,
  9024. UserOrgId: adminInfo.CurrentOrgId,
  9025. Ctime: ctime,
  9026. Mtime: ctime,
  9027. Type: types,
  9028. Modifier: adminInfo.AdminUser.Id,
  9029. Creator: adminInfo.AdminUser.Id,
  9030. Status: 1,
  9031. PTemplateId: template_one.ID,
  9032. MedType: med_type,
  9033. }
  9034. service.CreateHisPrescriptionInfoTemplate(prescription)
  9035. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9036. advices := items["advices"].([]interface{})
  9037. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9038. ctime := time.Now().Unix()
  9039. mtime := ctime
  9040. if len(advices) > 0 {
  9041. for _, advice := range advices {
  9042. var s models.HisPrescriptionAdviceTemplate
  9043. s.PrescriptionId = prescription.ID
  9044. s.AdviceType = 2
  9045. s.StopState = 2
  9046. s.ExecutionState = 2
  9047. s.Status = 1
  9048. s.UserOrgId = adminInfo.CurrentOrgId
  9049. s.CreatedTime = ctime
  9050. s.UpdatedTime = mtime
  9051. s.PatientId = patient_id
  9052. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9053. if errcode > 0 {
  9054. c.ServeFailJSONWithSGJErrorCode(errcode)
  9055. return
  9056. }
  9057. service.CreateHisPrescriptionAdviceTemplate(&s)
  9058. }
  9059. }
  9060. }
  9061. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9062. projects := items["project"].([]interface{})
  9063. if len(projects) > 0 {
  9064. for _, project := range projects {
  9065. var p models.HisPrescriptionProjectTemplate
  9066. p.PrescriptionId = prescription.ID
  9067. p.Ctime = time.Now().Unix()
  9068. p.Mtime = time.Now().Unix()
  9069. p.PatientId = patient_id
  9070. p.UserOrgId = adminInfo.CurrentOrgId
  9071. p.Status = 1
  9072. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9073. if errcode > 0 {
  9074. c.ServeFailJSONWithSGJErrorCode(errcode)
  9075. return
  9076. }
  9077. service.CreateHisPrescriptionProjectTemplate(&p)
  9078. }
  9079. }
  9080. }
  9081. }
  9082. c.ServeSuccessJSON(map[string]interface{}{
  9083. "msg": "创建成功",
  9084. })
  9085. }
  9086. }
  9087. } else {
  9088. err = service.CreateHisPrescriptionTemplate(template)
  9089. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9090. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9091. if len(prescriptions) > 0 {
  9092. for _, item := range prescriptions {
  9093. items := item.(map[string]interface{})
  9094. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9095. utils.ErrorLog("type")
  9096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9097. return
  9098. }
  9099. types := int64(items["type"].(float64))
  9100. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9101. utils.ErrorLog("med_type")
  9102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9103. return
  9104. }
  9105. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9106. ctime := time.Now().Unix()
  9107. prescription := &models.HisPrescriptionInfoTemplate{
  9108. PatientId: patient_id,
  9109. UserOrgId: adminInfo.CurrentOrgId,
  9110. Ctime: ctime,
  9111. Mtime: ctime,
  9112. Type: types,
  9113. Modifier: adminInfo.AdminUser.Id,
  9114. Creator: adminInfo.AdminUser.Id,
  9115. Status: 1,
  9116. PTemplateId: template.ID,
  9117. MedType: med_type,
  9118. }
  9119. service.CreateHisPrescriptionInfoTemplate(prescription)
  9120. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9121. advices := items["advices"].([]interface{})
  9122. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9123. ctime := time.Now().Unix()
  9124. mtime := ctime
  9125. if len(advices) > 0 {
  9126. for _, advice := range advices {
  9127. var s models.HisPrescriptionAdviceTemplate
  9128. s.PrescriptionId = prescription.ID
  9129. s.AdviceType = 2
  9130. s.StopState = 2
  9131. s.ExecutionState = 2
  9132. s.Status = 1
  9133. s.UserOrgId = adminInfo.CurrentOrgId
  9134. s.CreatedTime = ctime
  9135. s.UpdatedTime = mtime
  9136. s.PatientId = patient_id
  9137. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9138. if errcode > 0 {
  9139. c.ServeFailJSONWithSGJErrorCode(errcode)
  9140. return
  9141. }
  9142. service.CreateHisPrescriptionAdviceTemplate(&s)
  9143. }
  9144. }
  9145. }
  9146. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9147. projects := items["project"].([]interface{})
  9148. if len(projects) > 0 {
  9149. for _, project := range projects {
  9150. var p models.HisPrescriptionProjectTemplate
  9151. p.PrescriptionId = prescription.ID
  9152. p.Ctime = time.Now().Unix()
  9153. p.Mtime = time.Now().Unix()
  9154. p.PatientId = patient_id
  9155. p.UserOrgId = adminInfo.CurrentOrgId
  9156. p.Status = 1
  9157. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9158. if errcode > 0 {
  9159. c.ServeFailJSONWithSGJErrorCode(errcode)
  9160. return
  9161. }
  9162. service.CreateHisPrescriptionProjectTemplate(&p)
  9163. }
  9164. }
  9165. }
  9166. }
  9167. c.ServeSuccessJSON(map[string]interface{}{
  9168. "msg": "创建成功",
  9169. })
  9170. }
  9171. }
  9172. }
  9173. }
  9174. func (c *HisApiController) PreSettle() {
  9175. id, _ := c.GetInt64("id")
  9176. record_time := c.GetString("record_time")
  9177. his_patient_id, _ := c.GetInt64("his_patient_id")
  9178. timeLayout := "2006-01-02"
  9179. loc, _ := time.LoadLocation("Local")
  9180. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9181. diagnosis_id := c.GetString("diagnosis")
  9182. sick_type, _ := c.GetInt64("sick_type")
  9183. reg_type, _ := c.GetInt64("p_type")
  9184. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9185. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9186. if err != nil {
  9187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9188. return
  9189. }
  9190. recordDateTime := theTime.Unix()
  9191. adminUser := c.GetAdminUserInfo()
  9192. var prescriptions []*models.HisPrescription
  9193. var start_time int64
  9194. var end_time int64
  9195. ids_str := c.GetString("ids")
  9196. ids_arr := strings.Split(ids_str, ",")
  9197. fmt.Println(reg_type)
  9198. if settle_accounts_type == 1 { //日结
  9199. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9200. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9201. } else {
  9202. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9203. }
  9204. fmt.Println(prescriptions)
  9205. } else { //月结
  9206. start_time_str := c.GetString("start_time")
  9207. end_time_str := c.GetString("end_time")
  9208. timeLayout := "2006-01-02"
  9209. loc, _ := time.LoadLocation("Local")
  9210. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9211. if err != nil {
  9212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9213. return
  9214. }
  9215. recordStartTime := theStartTime.Unix()
  9216. start_time = recordStartTime
  9217. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9218. if err != nil {
  9219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9220. return
  9221. }
  9222. recordEndTime := theEndTime.Unix()
  9223. end_time = recordEndTime
  9224. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9225. }
  9226. if reg_type == 1111 || reg_type == 1112 {
  9227. reg_type = 11
  9228. }
  9229. timestamp := time.Now().Unix()
  9230. tempTime := time.Unix(timestamp, 0)
  9231. timeFormat := tempTime.Format("20060102150405")
  9232. chrgBchno := rand.Intn(100000) + 10000
  9233. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9234. strconv.FormatInt(his.PatientId, 10)
  9235. var ids []int64
  9236. for _, item := range prescriptions {
  9237. ids = append(ids, item.ID)
  9238. }
  9239. fmt.Println(ids)
  9240. var total float64
  9241. for _, item := range prescriptions {
  9242. fmt.Println(item)
  9243. if item.Type == 1 { //药品
  9244. for _, subItem := range item.HisDoctorAdviceInfo {
  9245. total = total + (subItem.Price * subItem.PrescribingNumber)
  9246. }
  9247. }
  9248. if item.Type == 2 { //项目
  9249. for _, subItem := range item.HisPrescriptionProject {
  9250. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9251. total = total + (subItem.Price * cnt)
  9252. }
  9253. }
  9254. for _, subItem := range item.HisAdditionalCharge {
  9255. total = total + (subItem.Price * float64(subItem.Count))
  9256. }
  9257. }
  9258. allTotal := fmt.Sprintf("%.2f", total)
  9259. totals, _ := strconv.ParseFloat(allTotal, 64)
  9260. order := &models.HisOrder{
  9261. UserOrgId: adminUser.CurrentOrgId,
  9262. HisPatientId: his.ID,
  9263. PatientId: id,
  9264. SettleAccountsDate: recordDateTime,
  9265. Ctime: time.Now().Unix(),
  9266. Mtime: time.Now().Unix(),
  9267. Status: 1,
  9268. OrderStatus: 1,
  9269. MdtrtId: his.Number,
  9270. Number: chrg_bchno,
  9271. MedfeeSumamt: totals,
  9272. SettleEndTime: end_time,
  9273. SettleStartTime: start_time,
  9274. SettleType: settle_accounts_type,
  9275. PsnPartAmt: totals,
  9276. PsnCashPay: totals,
  9277. PType: 2,
  9278. IsPre: 1,
  9279. MedType: strconv.Itoa(int(reg_type)),
  9280. Diagnosis: diagnosis_id,
  9281. }
  9282. err = service.CreateOrder(order)
  9283. if err != nil {
  9284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9285. return
  9286. }
  9287. var customs []*Custom
  9288. for _, item := range prescriptions {
  9289. fmt.Println(item.Type)
  9290. if item.Type == 1 { //药品
  9291. for _, subItem := range item.HisDoctorAdviceInfo {
  9292. cus := &Custom{
  9293. AdviceId: subItem.ID,
  9294. ProjectId: 0,
  9295. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9296. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9297. FeedetlSn: subItem.FeedetlSn,
  9298. Price: fmt.Sprintf("%.2f", subItem.Price),
  9299. MedListCodg: subItem.MedListCodg,
  9300. Type: 1,
  9301. }
  9302. customs = append(customs, cus)
  9303. }
  9304. }
  9305. if item.Type == 2 { //项目
  9306. for _, subItem := range item.HisPrescriptionProject {
  9307. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9308. cus := &Custom{
  9309. AdviceId: 0,
  9310. ProjectId: subItem.ID,
  9311. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9312. Cut: fmt.Sprintf("%.2f", cnt),
  9313. FeedetlSn: subItem.FeedetlSn,
  9314. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9315. MedListCodg: subItem.MedListCodg,
  9316. Type: 2,
  9317. }
  9318. customs = append(customs, cus)
  9319. }
  9320. }
  9321. for _, item := range item.HisAdditionalCharge {
  9322. cus := &Custom{
  9323. ItemId: item.ID,
  9324. AdviceId: 0,
  9325. ProjectId: 0,
  9326. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9327. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9328. FeedetlSn: item.FeedetlSn,
  9329. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9330. MedListCodg: item.XtHisAddtionConfig.Code,
  9331. Type: 3,
  9332. }
  9333. customs = append(customs, cus)
  9334. }
  9335. }
  9336. fmt.Println(customs)
  9337. for _, item := range customs {
  9338. var advice_id int64 = 0
  9339. var project_id int64 = 0
  9340. var item_id int64 = 0
  9341. var types int64 = 0
  9342. if item.Type == 1 {
  9343. advice_id = item.AdviceId
  9344. project_id = 0
  9345. item_id = 0
  9346. } else if item.Type == 2 {
  9347. advice_id = 0
  9348. item_id = 0
  9349. project_id = item.ProjectId
  9350. } else if item.Type == 3 {
  9351. advice_id = 0
  9352. item_id = item.ItemId
  9353. project_id = 0
  9354. }
  9355. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9356. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9357. pric, _ := strconv.ParseFloat(item.Price, 32)
  9358. info := &models.HisOrderInfo{
  9359. OrderNumber: order.Number,
  9360. UploadDate: time.Now().Unix(),
  9361. AdviceId: advice_id,
  9362. DetItemFeeSumamt: detItemFeeSumamt,
  9363. Cnt: cut,
  9364. Pric: pric,
  9365. PatientId: id,
  9366. Status: 1,
  9367. Mtime: time.Now().Unix(),
  9368. Ctime: time.Now().Unix(),
  9369. UserOrgId: adminUser.CurrentOrgId,
  9370. HisPatientId: his.ID,
  9371. OrderId: order.ID,
  9372. ProjectId: project_id,
  9373. Type: types,
  9374. ItemId: item_id,
  9375. }
  9376. service.CreateOrderInfo(info)
  9377. }
  9378. his.SickType = sick_type
  9379. service.UpdataHisPateint(&his)
  9380. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9381. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9382. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9383. if err == nil {
  9384. c.ServeSuccessJSON(map[string]interface{}{
  9385. "msg": "结算成功",
  9386. })
  9387. }
  9388. }
  9389. type CustomOrderInfo struct {
  9390. Name string
  9391. Spec string
  9392. Unit string
  9393. Count float64
  9394. Price float64
  9395. Total float64
  9396. }
  9397. func (c *HisApiController) GetPrivateExpensesInfo() {
  9398. order_id, _ := c.GetInt64("id", 0)
  9399. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9400. order, _ := service.GetHisOrderByID(order_id)
  9401. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9402. if order.ID == 0 {
  9403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9404. return
  9405. }
  9406. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9407. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9408. org_id := c.GetAdminUserInfo().CurrentOrgId
  9409. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9410. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9411. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9412. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9413. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9414. //var orderInfos_four []*models.HisOrderInfoTwo
  9415. //for _, item := range orderInfos_three {
  9416. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9417. // item.HisPrescriptionProject.IsCheckTeam = 1
  9418. // orderInfos_four = append(orderInfos_four, item)
  9419. //
  9420. // }
  9421. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9422. // item.HisPrescriptionProject.IsCheckTeam = 2
  9423. // orderInfos_two = append(orderInfos_two, item)
  9424. // }
  9425. //}
  9426. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9427. //var cus_slice []CustomOrderInfo
  9428. //for _, item := range new_order_info {
  9429. // var cus CustomOrderInfo
  9430. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9431. // cus.Unit = ""
  9432. // cus.Spec = ""
  9433. // var total float64
  9434. // for _, subItem := range orderInfos_four {
  9435. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9436. // total = total + subItem.DetItemFeeSumamt
  9437. // fmt.Println(subItem.DetItemFeeSumamt)
  9438. // }
  9439. // }
  9440. // cus.Count = 1
  9441. // cus.Total = total
  9442. // cus_slice = append(cus_slice, cus)
  9443. //}
  9444. orderInfos = append(orderInfos, orderInfos_two...)
  9445. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9446. //orderInfos = append(orderInfos, orderInfos_three...)
  9447. //}/**/
  9448. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9449. c.ServeSuccessJSON(map[string]interface{}{
  9450. "order": order,
  9451. "order_info": orderInfos,
  9452. "patient": patient,
  9453. "admin_info": adminInfo,
  9454. "his": his,
  9455. "current_admin": role,
  9456. "org_config": miConfig,
  9457. //"new_order_info": cus_slice,
  9458. })
  9459. }
  9460. func (this *HisApiController) ChangeMedType() {
  9461. med_type := this.GetString("med_type")
  9462. old_med_type := this.GetString("old_med_type")
  9463. ids := this.GetString("ids")
  9464. settle_type, _ := this.GetInt64("settle_type")
  9465. start_time := this.GetString("start_time")
  9466. end_time := this.GetString("end_time")
  9467. ids_arr := strings.Split(ids, ",")
  9468. if settle_type == 1 { //日结
  9469. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9470. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9471. prescription.MedType = med_type
  9472. err := service.SaveHisPrescription(&prescription)
  9473. if err == nil {
  9474. this.ServeSuccessJSON(map[string]interface{}{
  9475. "msg": "修改成功",
  9476. })
  9477. } else {
  9478. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9479. return
  9480. }
  9481. } else if settle_type == 2 {
  9482. timeLayout := "2006-01-02"
  9483. loc, _ := time.LoadLocation("Local")
  9484. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9485. if err != nil {
  9486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9487. return
  9488. }
  9489. recordStartTime := theStartTime.Unix()
  9490. start_time_timestamp := recordStartTime
  9491. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9492. if err != nil {
  9493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9494. return
  9495. }
  9496. recordEndTime := theEndTime.Unix()
  9497. end_time_timestamp := recordEndTime
  9498. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9499. if updateErr == nil {
  9500. this.ServeSuccessJSON(map[string]interface{}{
  9501. "msg": "修改成功",
  9502. })
  9503. } else {
  9504. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9505. return
  9506. }
  9507. }
  9508. }
  9509. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9510. patient_id, _ := c.GetInt64("patient_id")
  9511. his_patient_id, _ := c.GetInt64("his_patient_id")
  9512. record_date := c.GetString("record_date")
  9513. start_time := c.GetString("start_time")
  9514. end_time := c.GetString("end_time")
  9515. order_status, _ := c.GetInt64("type", 0)
  9516. p_type, _ := c.GetInt64("p_type", 0)
  9517. order_id, _ := c.GetInt64("order_id", 0)
  9518. timeLayout := "2006-01-02"
  9519. loc, _ := time.LoadLocation("Local")
  9520. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9521. if err != nil {
  9522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9523. return
  9524. }
  9525. recordDateTime := theTime.Unix()
  9526. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9527. if err != nil {
  9528. }
  9529. startRecordDateTime := startTime.Unix()
  9530. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9531. if err != nil {
  9532. }
  9533. endRecordDateTime := endTime.Unix()
  9534. admin := c.GetAdminUserInfo()
  9535. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9536. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9537. order, _ := service.GetHisOrderByID(order_id)
  9538. var monthPrescriptions []*models.HisPrescription
  9539. if order_status == 1 || order_status == 0 {
  9540. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9541. } else if order_status == 2 {
  9542. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9543. }
  9544. var settle_total float64
  9545. for _, item := range monthPrescriptions {
  9546. if len(item.HisPrescriptionProject) > 0 {
  9547. for _, subItem := range item.HisPrescriptionProject {
  9548. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9549. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9550. settle_total = settle_total + total
  9551. }
  9552. }
  9553. if len(item.HisDoctorAdviceInfo) > 0 {
  9554. for _, subItem := range item.HisDoctorAdviceInfo {
  9555. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9556. settle_total = settle_total + total
  9557. }
  9558. }
  9559. }
  9560. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9561. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9562. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9563. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9564. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9565. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9566. //获取所有科室信息
  9567. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9568. var dia string
  9569. for _, item := range month_p_info {
  9570. if len(dia) == 0 {
  9571. dia = item.Diagnosis
  9572. } else {
  9573. dia = dia + "," + item.Diagnosis
  9574. }
  9575. }
  9576. dia_arr := removeDuplicates(strings.Split(dia, ","))
  9577. dia_arr = removeEmptyStrings(dia_arr)
  9578. c.ServeSuccessJSON(map[string]interface{}{
  9579. "his_info": his_patient_info,
  9580. "xt_info": xt_patient_info,
  9581. "case_history": case_history,
  9582. "info": patientPrescriptionInfo,
  9583. "last_info": lastPatientPrescriptionInfo,
  9584. "month_prescriptions": monthPrescriptions,
  9585. "order": order,
  9586. "doctors": doctors,
  9587. "department": department,
  9588. "settle_total": settle_total,
  9589. "dia_arr": dia_arr,
  9590. })
  9591. return
  9592. }
  9593. func removeEmptyStrings(input []string) []string {
  9594. var output []string
  9595. for _, s := range input {
  9596. if s != "" {
  9597. output = append(output, s)
  9598. }
  9599. }
  9600. return output
  9601. }
  9602. func removeDuplicates(input []string) []string {
  9603. seen := make(map[string]bool)
  9604. output := []string{}
  9605. for _, s := range input {
  9606. if _, exists := seen[s]; !exists {
  9607. seen[s] = true
  9608. output = append(output, s)
  9609. }
  9610. }
  9611. return output
  9612. }
  9613. func (c *HisApiController) GetHisMonthPatientInfo() {
  9614. patient_id, _ := c.GetInt64("patient_id")
  9615. his_patient_id, _ := c.GetInt64("his_patient_id")
  9616. record_date := c.GetString("record_date")
  9617. number := c.GetString("number")
  9618. start_time := c.GetString("start_time")
  9619. end_time := c.GetString("end_time")
  9620. p_type, _ := c.GetInt64("p_type")
  9621. timeLayout := "2006-01-02"
  9622. loc, _ := time.LoadLocation("Local")
  9623. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9624. if err != nil {
  9625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9626. return
  9627. }
  9628. recordDateTime := theTime.Unix()
  9629. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9630. if err != nil {
  9631. }
  9632. startRecordDateTime := startTime.Unix()
  9633. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9634. if err != nil {
  9635. }
  9636. endRecordDateTime := endTime.Unix()
  9637. admin := c.GetAdminUserInfo()
  9638. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9639. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9640. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9641. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9642. var settle_total float64
  9643. for _, item := range monthPrescriptions {
  9644. if len(item.HisPrescriptionProject) > 0 {
  9645. for _, subItem := range item.HisPrescriptionProject {
  9646. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9647. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9648. settle_total = settle_total + total
  9649. }
  9650. }
  9651. if len(item.HisDoctorAdviceInfo) > 0 {
  9652. for _, subItem := range item.HisDoctorAdviceInfo {
  9653. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9654. settle_total = settle_total + total
  9655. }
  9656. }
  9657. }
  9658. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9659. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9660. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9661. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9662. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9663. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9664. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9665. //获取所有科室信息
  9666. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9667. c.ServeSuccessJSON(map[string]interface{}{
  9668. "his_info": his_patient_info,
  9669. "xt_info": xt_patient_info,
  9670. "case_history": case_history,
  9671. "info": patientPrescriptionInfo,
  9672. "month_prescriptions": monthPrescriptions,
  9673. "order": order,
  9674. "doctors": doctors,
  9675. "department": department,
  9676. "count": count,
  9677. "drugStockConfig": drugStockConfig,
  9678. "last_info": lastPatientPrescriptionInfo,
  9679. "settle_total": settle_total,
  9680. })
  9681. return
  9682. }
  9683. func (c *HisApiController) GetAllOrder() {
  9684. org_id := c.GetAdminUserInfo().CurrentOrgId
  9685. orders, _ := service.GetNewHisOrderList(org_id)
  9686. c.ServeSuccessJSON(map[string]interface{}{
  9687. "order": orders,
  9688. })
  9689. return
  9690. }
  9691. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9692. newArr = make([]*models.HisOrderInfoTwo, 0)
  9693. for i := 0; i < len(arr); i++ {
  9694. repeat := false
  9695. for j := i + 1; j < len(arr); j++ {
  9696. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9697. repeat = true
  9698. break
  9699. }
  9700. }
  9701. if !repeat {
  9702. newArr = append(newArr, arr[i])
  9703. }
  9704. }
  9705. return
  9706. }
  9707. // 修改处方退库操作 参数传修改之前的处方数据
  9708. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9709. if advice.ExecutionState == 1 {
  9710. //查询该病人该药品是否有库存记录
  9711. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9712. if errcode == gorm.ErrRecordNotFound {
  9713. } else {
  9714. //退库
  9715. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9716. if advice.PrescribingNumberUnit == drug.MinUnit {
  9717. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9718. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9719. //退库
  9720. warehouseInfo := models.DrugWarehouseInfo{
  9721. StockMinNumber: prescribingNumber,
  9722. }
  9723. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9724. operation_time := time.Now().Unix()
  9725. creater := advice.AdviceDoctor
  9726. ctime := time.Now().Unix()
  9727. timeStr := time.Now().Format("2006-01-02")
  9728. timeArr := strings.Split(timeStr, "-")
  9729. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9730. total = total + 1
  9731. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9732. cancelStock := models.DrugCancelStock{
  9733. OrderNumber: orderNumber,
  9734. OperaTime: operation_time,
  9735. OrgId: advice.UserOrgId,
  9736. Creater: creater,
  9737. Ctime: ctime,
  9738. Status: 1,
  9739. ReturnTime: advice.AdviceDate,
  9740. Dealer: info.Dealer,
  9741. Manufacturer: info.Manufacturer,
  9742. Type: 1,
  9743. }
  9744. service.AddSigleDrugCancelStock(&cancelStock)
  9745. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9746. dealer, _ := service.GetDealerById(info.Dealer)
  9747. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9748. cancelStockInfo := models.DrugCancelStockInfo{
  9749. OrderNumber: cancelInfo.OrderNumber,
  9750. CancelStockId: cancelInfo.ID,
  9751. DrugId: info.DrugId,
  9752. Count: info.Count,
  9753. Status: 1,
  9754. Ctime: ctime,
  9755. OrgId: advice.UserOrgId,
  9756. Type: 1,
  9757. Manufacturer: manufactureName.ManufacturerName,
  9758. Dealer: dealer.DealerName,
  9759. Total: 0,
  9760. RetailPrice: info.RetailPrice,
  9761. RetailTotalPrice: info.RetailTotalPrice,
  9762. Price: info.Price,
  9763. RegisterAccount: "",
  9764. Remark: info.Remark,
  9765. BatchNumber: info.BatchNumber,
  9766. MaxUnit: info.CountUnit,
  9767. ProductDate: info.ProductDate,
  9768. ExpiryDate: info.ExpiryDate,
  9769. BatchNumberId: info.WarehouseInfoId,
  9770. }
  9771. flow := models.DrugFlow{
  9772. WarehousingId: 0,
  9773. DrugId: info.DrugId,
  9774. Number: "",
  9775. BatchNumber: info.BatchNumber,
  9776. Count: info.Count,
  9777. UserOrgId: advice.UserOrgId,
  9778. PatientId: 0,
  9779. SystemTime: ctime,
  9780. ConsumableType: 4,
  9781. IsSys: 0,
  9782. WarehousingOrder: "",
  9783. WarehouseOutId: 0,
  9784. WarehouseOutOrderNumber: "",
  9785. IsEdit: 0,
  9786. CancelStockId: cancelStock.ID,
  9787. CancelOrderNumber: cancelStock.OrderNumber,
  9788. Manufacturer: info.Manufacturer,
  9789. Dealer: info.Dealer,
  9790. Creator: advice.UserOrgId,
  9791. UpdateCreator: 0,
  9792. Status: 1,
  9793. Ctime: time.Now().Unix(),
  9794. Mtime: 0,
  9795. Price: info.Price,
  9796. WarehousingDetailId: 0,
  9797. WarehouseOutDetailId: 0,
  9798. CancelOutDetailId: 0,
  9799. ExpireDate: info.ExpiryDate,
  9800. ProductDate: info.ProductDate,
  9801. MaxUnit: info.CountUnit,
  9802. MinUnit: "",
  9803. }
  9804. service.CreatedCancelStock(cancelStockInfo)
  9805. service.CreateDrugFlowOne(flow)
  9806. } else {
  9807. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9808. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9809. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9810. warehouseInfo := models.DrugWarehouseInfo{
  9811. StockMinNumber: prescribingNumber,
  9812. }
  9813. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9814. }
  9815. operation_time := time.Now().Unix()
  9816. creater := advice.AdviceDoctor
  9817. ctime := time.Now().Unix()
  9818. timeStr := time.Now().Format("2006-01-02")
  9819. timeArr := strings.Split(timeStr, "-")
  9820. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9821. total = total + 1
  9822. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9823. cancelStock := models.DrugCancelStock{
  9824. OrderNumber: orderNumber,
  9825. OperaTime: operation_time,
  9826. OrgId: advice.UserOrgId,
  9827. Creater: creater,
  9828. Ctime: ctime,
  9829. Status: 1,
  9830. ReturnTime: advice.AdviceDate,
  9831. Dealer: info.Dealer,
  9832. Manufacturer: info.Manufacturer,
  9833. Type: 1,
  9834. }
  9835. service.AddSigleDrugCancelStock(&cancelStock)
  9836. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9837. dealer, _ := service.GetDealerById(info.Dealer)
  9838. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9839. cancelStockInfo := models.DrugCancelStockInfo{
  9840. OrderNumber: cancelInfo.OrderNumber,
  9841. CancelStockId: cancelInfo.ID,
  9842. DrugId: info.DrugId,
  9843. Count: info.Count,
  9844. Status: 1,
  9845. Ctime: ctime,
  9846. OrgId: advice.UserOrgId,
  9847. Type: 1,
  9848. Manufacturer: manufactureName.ManufacturerName,
  9849. Dealer: dealer.DealerName,
  9850. Total: 0,
  9851. RetailPrice: info.RetailPrice,
  9852. RetailTotalPrice: info.RetailTotalPrice,
  9853. Price: info.Price,
  9854. RegisterAccount: "",
  9855. Remark: info.Remark,
  9856. BatchNumber: info.BatchNumber,
  9857. MaxUnit: info.CountUnit,
  9858. ProductDate: info.ProductDate,
  9859. ExpiryDate: info.ExpiryDate,
  9860. BatchNumberId: info.WarehouseInfoId,
  9861. }
  9862. flow := models.DrugFlow{
  9863. WarehousingId: 0,
  9864. DrugId: info.DrugId,
  9865. Number: "",
  9866. BatchNumber: info.BatchNumber,
  9867. Count: info.Count,
  9868. UserOrgId: advice.UserOrgId,
  9869. PatientId: 0,
  9870. SystemTime: ctime,
  9871. ConsumableType: 4,
  9872. IsSys: 0,
  9873. WarehousingOrder: "",
  9874. WarehouseOutId: 0,
  9875. WarehouseOutOrderNumber: "",
  9876. IsEdit: 0,
  9877. CancelStockId: cancelStock.ID,
  9878. CancelOrderNumber: cancelStock.OrderNumber,
  9879. Manufacturer: info.Manufacturer,
  9880. Dealer: info.Dealer,
  9881. Creator: advice.AdviceDoctor,
  9882. UpdateCreator: 0,
  9883. Status: 1,
  9884. Ctime: time.Now().Unix(),
  9885. Mtime: 0,
  9886. Price: info.Price,
  9887. WarehousingDetailId: 0,
  9888. WarehouseOutDetailId: 0,
  9889. CancelOutDetailId: 0,
  9890. ExpireDate: info.ExpiryDate,
  9891. ProductDate: info.ProductDate,
  9892. MaxUnit: info.CountUnit,
  9893. MinUnit: "",
  9894. }
  9895. service.CreatedCancelStock(cancelStockInfo)
  9896. service.CreateDrugFlowOne(flow)
  9897. }
  9898. }
  9899. }
  9900. return err
  9901. }
  9902. func (this *HisApiController) DeleteNCDS() {
  9903. id, _ := this.GetInt64("id", 0)
  9904. if id > 0 {
  9905. service.DeletePsnNCDSRecordById(id)
  9906. this.ServeSuccessJSON(map[string]interface{}{
  9907. "msg": "删除成功",
  9908. })
  9909. } else {
  9910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9911. return
  9912. }
  9913. }
  9914. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9915. id, _ := c.GetInt64("id")
  9916. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9917. c.ServeSuccessJSON(map[string]interface{}{
  9918. "advice": advice,
  9919. })
  9920. return
  9921. }
  9922. func (c *HisApiController) GetHisMonthChargePatientList() {
  9923. record_date := c.GetString("record_date")
  9924. start_time := c.GetString("start_time")
  9925. end_time := c.GetString("end_time")
  9926. timeLayout := "2006-01-02"
  9927. loc, _ := time.LoadLocation("Local")
  9928. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9929. if err != nil {
  9930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9931. return
  9932. }
  9933. if err != nil {
  9934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9935. return
  9936. }
  9937. recordDateTime := theTime.Unix()
  9938. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9939. if err != nil {
  9940. }
  9941. startRecordDateTime := startTime.Unix()
  9942. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9943. if err != nil {
  9944. }
  9945. endRecordDateTime := endTime.Unix()
  9946. adminInfo := c.GetAdminUserInfo()
  9947. var tempMonthChargePatients []*service.MonthChargePatients
  9948. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9949. for _, item := range tempPatients {
  9950. //过滤没有处方的
  9951. if len(item.HisPrescription) == 0 {
  9952. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9953. }
  9954. }
  9955. c.ServeSuccessJSON(map[string]interface{}{
  9956. "list": tempMonthChargePatients,
  9957. })
  9958. }