his_api_controller.go 369KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699
  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. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. for _, item := range prescriptions {
  540. for _, subItem := range item.HisDoctorAdviceInfo {
  541. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  542. if info.RetailPrice > 0 {
  543. subItem.Drug.MinPrice = info.RetailPrice
  544. }
  545. }
  546. }
  547. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  548. } else { //门诊
  549. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  550. for _, item := range prescriptions {
  551. for _, subItem := range item.HisDoctorAdviceInfo {
  552. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  553. if info.RetailPrice > 0 {
  554. subItem.Drug.MinPrice = info.RetailPrice
  555. }
  556. }
  557. }
  558. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  559. }
  560. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  561. if sch.ID > 0 {
  562. var week string
  563. t := time.Now()
  564. switch t.Weekday().String() {
  565. case "Monday":
  566. week = "周一"
  567. break
  568. case "Tuesday":
  569. week = "周二"
  570. break
  571. case "Wednesday":
  572. week = "周三"
  573. break
  574. case "Thursday":
  575. week = "周四"
  576. break
  577. case "Friday":
  578. week = "周五"
  579. break
  580. case "Saturday":
  581. week = "周六"
  582. break
  583. case "Sunday":
  584. week = "周日"
  585. break
  586. }
  587. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  588. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  589. //根据推送频率组装新的数组
  590. for _, item := range temp_sch_prescriptions {
  591. var cus CustomTemplate
  592. cus.ID = item.ID
  593. cus.UserOrgId = item.UserOrgId
  594. cus.PatientId = item.PatientId
  595. cus.MedType = item.MedType
  596. cus.RecordDate = item.RecordDate
  597. cus.Type = item.Type
  598. cus.PType = item.PType
  599. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  600. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  601. if subItem.FrequencyType == 1 { //每次必推
  602. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  603. }
  604. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  605. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  606. }
  607. if subItem.FrequencyType == 2 { //按照天数频率
  608. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  609. now := p.Unix()
  610. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  611. dayStr2 := "-" + dayStr
  612. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  613. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  614. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  615. if len(advices) == 0 {
  616. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  617. }
  618. }
  619. }
  620. }
  621. for _, subItem := range item.HisPrescriptionProjectTemplate {
  622. if subItem.Type == 2 {
  623. if subItem.XtHisProject.MedicalStatus != 1 {
  624. if subItem.FrequencyType == 1 {
  625. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  626. }
  627. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  628. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  629. }
  630. if subItem.FrequencyType == 2 {
  631. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  632. now := p.Unix()
  633. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  634. dayStr2 := "-" + dayStr
  635. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  636. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  637. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  638. if len(projects) == 0 {
  639. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  640. }
  641. }
  642. }
  643. } else if subItem.Type == 3 {
  644. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  645. if subItem.FrequencyType == 1 {
  646. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  647. }
  648. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  649. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  650. }
  651. if subItem.FrequencyType == 2 {
  652. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  653. now := p.Unix()
  654. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  655. dayStr2 := "-" + dayStr
  656. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  657. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  658. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  659. if len(projects) == 0 {
  660. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  661. }
  662. }
  663. }
  664. }
  665. }
  666. sch_prescriptions = append(sch_prescriptions, cus)
  667. }
  668. for _, item := range sch_prescriptions {
  669. if len(item.HisPrescriptionProjectTemplate) == 0 {
  670. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  671. }
  672. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  673. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  674. }
  675. }
  676. }
  677. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  678. if config.ID > 0 && config.IsOpen == 1 {
  679. for _, item := range sch_prescriptions {
  680. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  681. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  682. if info.RetailPrice > 0 {
  683. subItem.Drug.MinPrice = info.RetailPrice
  684. }
  685. }
  686. }
  687. }
  688. if config.ID > 0 && config.IsOpen == 1 {
  689. for _, item := range sch_prescriptions {
  690. for _, subItem := range item.HisPrescriptionProjectTemplate {
  691. if subItem.Type == 3 {
  692. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  693. if info.Price > 0 {
  694. subItem.GoodInfo.PackingPrice = info.Price
  695. }
  696. }
  697. }
  698. }
  699. }
  700. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  701. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  702. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  703. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  704. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  705. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  706. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  707. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  708. //获取所有科室信息
  709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "his_info": his_patient_info,
  712. "xt_info": xt_patient_info,
  713. "prescription": prescriptions,
  714. "case_history": case_history,
  715. "info": patientPrescriptionInfo,
  716. //"month_prescriptions": monthPrescriptions,
  717. "order": order,
  718. "doctors": doctors,
  719. "department": department,
  720. "sch_prescriptions": sch_prescriptions,
  721. "last_prescriptions": last_prescriptions,
  722. "schedule": sch,
  723. "count": count,
  724. "drugStockConfig": drugStockConfig,
  725. "last_info": lastPatientPrescriptionInfo,
  726. })
  727. return
  728. }
  729. func (c *HisApiController) GetHisPrescriptionConfig() {
  730. adminInfo := c.GetAdminUserInfo()
  731. //获取医嘱模版
  732. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  733. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  734. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  735. //获取所有基础药
  736. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  737. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  738. if config.ID > 0 && config.IsOpen == 1 {
  739. for _, item := range drugs {
  740. var index = 0
  741. for _, subItem := range item.OtherDrugWarehouseInfo {
  742. if index == 0 {
  743. index = index + 1
  744. if subItem.RetailPrice > 0 {
  745. item.MinPrice = subItem.RetailPrice
  746. }
  747. }
  748. }
  749. }
  750. }
  751. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  752. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  753. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  754. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  755. //获取所有科室信息
  756. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  757. //获取诊断信息
  758. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  759. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  760. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  761. c.ServeSuccessJSON(map[string]interface{}{
  762. "drugs": drugs,
  763. "advices_template": advices,
  764. "drugways": drugways,
  765. "efs": efs,
  766. "doctors": doctors,
  767. "department": department,
  768. "sick": sick,
  769. "additions": additions,
  770. "diagnose": diagnose,
  771. "manufacturers": manufacturers,
  772. })
  773. }
  774. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  775. //获取所有基础药
  776. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  777. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  778. if config.ID > 0 && config.IsOpen == 1 {
  779. for _, item := range drugs {
  780. var index = 0
  781. for _, subItem := range item.OtherDrugWarehouseInfo {
  782. if index == 0 {
  783. index = index + 1
  784. if subItem.RetailPrice > 0 {
  785. item.MinPrice = subItem.RetailPrice
  786. }
  787. }
  788. }
  789. }
  790. }
  791. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  792. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  793. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  794. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  795. //获取所有科室信息
  796. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  797. //获取诊断信息
  798. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  799. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  800. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  801. c.ServeSuccessJSON(map[string]interface{}{
  802. "drugs": drugs,
  803. "advices_template": advices,
  804. "drugways": drugways,
  805. "efs": efs,
  806. "doctors": doctors,
  807. "department": department,
  808. "sick": sick,
  809. "additions": additions,
  810. "diagnose": diagnose,
  811. "manufacturers": manufacturers,
  812. })
  813. }
  814. }
  815. func (c *HisApiController) CreateHisPrescription() {
  816. record_date := c.GetString("record_date")
  817. patient_id, _ := c.GetInt64("patient_id")
  818. reg_type, _ := c.GetInt64("reg_type")
  819. diagnose := c.GetString("diagnose")
  820. sick_type, _ := c.GetInt64("sick_type")
  821. sick_history := c.GetString("sick_history")
  822. doctor_id, _ := c.GetInt64("doctor", 0)
  823. department, _ := c.GetInt64("department", 0)
  824. his_patient_id, _ := c.GetInt64("his_patient_id")
  825. p_type, _ := c.GetInt64("p_type")
  826. dataBody := make(map[string]interface{}, 0)
  827. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  828. if err != nil {
  829. utils.ErrorLog(err.Error())
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. adminInfo := c.GetAdminUserInfo()
  841. recordDateTime := theTime.Unix()
  842. //查询默认出库仓库库存
  843. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  844. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  845. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  846. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  847. if len(lists) == 1 {
  848. his_patient_id = lists[0].ID
  849. }
  850. }
  851. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  852. //保存处方出库
  853. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  854. //自动出库
  855. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  856. //耗材保存处方出库
  857. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  858. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  859. //已发药和已收费限制逻辑
  860. isMidicine := false
  861. isCharge := false
  862. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  863. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  864. if len(prescriptions) > 0 {
  865. for _, item := range prescriptions {
  866. items := item.(map[string]interface{})
  867. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  868. utils.ErrorLog("id")
  869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  870. return
  871. }
  872. id := int64(items["id"].(float64))
  873. if id > 0 {
  874. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  875. if err != nil {
  876. if new_prescription.OrderStatus == 4 {
  877. isCharge = true
  878. }
  879. }
  880. }
  881. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  882. advices := items["advices"].([]interface{})
  883. if len(advices) > 0 {
  884. for _, advice := range advices {
  885. var adviceId int64
  886. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  887. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  888. }
  889. if adviceId > 0 {
  890. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  891. if err == nil {
  892. if his_advice_info.IsMedicine == 1 {
  893. isMidicine = true
  894. }
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. }
  902. }
  903. if isMidicine == true {
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  905. return
  906. }
  907. if isCharge == true {
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  909. return
  910. }
  911. //已发药和已收费限制逻辑
  912. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  913. //校验库存总量
  914. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  915. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  916. if len(prescriptions) > 0 {
  917. for _, item := range prescriptions {
  918. items := item.(map[string]interface{})
  919. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  920. advices := items["advices"].([]interface{})
  921. if len(advices) > 0 {
  922. for _, advice := range advices {
  923. var drug_id int64
  924. var prescribing_number float64
  925. var prescribingNumberUnit string
  926. var adviceId int64
  927. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  928. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  929. }
  930. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  931. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  932. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  933. }
  934. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  935. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  936. }
  937. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  938. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  939. }
  940. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  941. if drug.ID == 0 {
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  943. return
  944. }
  945. //查询药品的所有库存
  946. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  947. var total_count int64
  948. for _, it := range list {
  949. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  950. }
  951. totals := strconv.FormatInt(total_count, 10)
  952. //查询该药品是否存在开药记录
  953. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  954. //查询最新批次库存
  955. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  956. var batch_number_count int64
  957. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  958. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  959. //新增处方
  960. if advicelist.ID == 0 {
  961. all_count, _ := strconv.ParseFloat(totals, 64)
  962. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  963. if prescribingNumberUnit == drug.MinUnit {
  964. if drug.IsUse != 1 {
  965. if prescribing_number > all_count {
  966. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  967. return
  968. }
  969. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  970. if prescribing_number > batch_number_all_count {
  971. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  972. return
  973. }
  974. }
  975. }
  976. }
  977. if prescribingNumberUnit == drug.MaxUnit {
  978. num := prescribing_number * float64(drug.MinNumber)
  979. if drug.IsUse != 1 {
  980. if num > all_count {
  981. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  982. return
  983. }
  984. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  985. if num > batch_number_all_count {
  986. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  987. return
  988. }
  989. }
  990. }
  991. }
  992. }
  993. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  994. if drugOutConfig.IsOpen != 1 {
  995. //修改处方
  996. for _, advice := range advices {
  997. var drug_id int64
  998. var prescribing_number float64
  999. var prescribingNumberUnit string
  1000. var prescribingNumber string
  1001. var adviceId int64
  1002. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1003. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1004. }
  1005. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1006. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1007. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1008. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1009. }
  1010. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1011. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1012. }
  1013. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1014. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1015. }
  1016. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1017. if drug.ID == 0 {
  1018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1019. return
  1020. }
  1021. //查询药品的所有库存
  1022. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1023. var total_count int64
  1024. for _, it := range list {
  1025. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1026. }
  1027. totals := strconv.FormatInt(total_count, 10)
  1028. //查询该药品是否存在开药记录
  1029. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1030. //新增处方
  1031. if advicelist.ID == 0 {
  1032. //查询最新批次库存
  1033. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1034. var batch_number_count int64
  1035. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1036. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1037. all_count, _ := strconv.ParseFloat(totals, 64)
  1038. if prescribingNumberUnit == drug.MinUnit {
  1039. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1040. if drug.IsUse != 1 {
  1041. if prescribing_number > all_count {
  1042. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1043. return
  1044. }
  1045. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1046. if prescribing_number > batch_number_all_count {
  1047. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1048. return
  1049. }
  1050. }
  1051. }
  1052. } else {
  1053. if prescribingNumberUnit == drug.MaxUnit {
  1054. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1055. num := prescribing_number * float64(drug.MinNumber)
  1056. if drug.IsUse != 1 {
  1057. if num > all_count {
  1058. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1059. return
  1060. }
  1061. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1062. if prescribing_number > batch_number_all_count {
  1063. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1064. return
  1065. }
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. //修改处方
  1072. if advicelist.ID > 0 {
  1073. //查询最新批次库存
  1074. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1075. var batch_number_count int64
  1076. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1077. var device_number int64
  1078. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1079. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1080. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1081. device_number = prescribingNumberInt * drug.MinNumber
  1082. }
  1083. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1084. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1085. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1086. device_number = prescribingNumberInt
  1087. }
  1088. var number_count int64
  1089. if prescribingNumberUnit == drug.MaxUnit {
  1090. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1091. number_count = prescribingNumberInt * drug.MinNumber
  1092. }
  1093. if prescribingNumberUnit == drug.MinUnit {
  1094. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1095. number_count = prescribingNumberInt
  1096. }
  1097. //如果修改的数量大于之前修改的数量
  1098. if (number_count - device_number) > 0 {
  1099. //如果修改的差数量 大于库存数量
  1100. if drug.IsUse != 1 {
  1101. if (number_count - device_number) > total_count {
  1102. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1103. return
  1104. }
  1105. if (number_count - device_number) > batch_number_count {
  1106. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1107. return
  1108. }
  1109. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
  1110. // 查询该药品最后一次出库记录
  1111. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1112. var out_count int64
  1113. var in_count int64
  1114. var stock_max_number int64
  1115. var stock_min_number int64
  1116. for _, it := range outInfo {
  1117. if it.CountUnit == drug.MaxUnit {
  1118. it.Count = it.Count * drug.MinNumber
  1119. }
  1120. out_count += it.Count
  1121. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1122. stock_max_number = warehouseInfoList.StockMaxNumber
  1123. stock_min_number = warehouseInfoList.StockMinNumber
  1124. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1125. }
  1126. if out_count > 0 {
  1127. if (number_count - device_number) > in_count {
  1128. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1129. return
  1130. }
  1131. }
  1132. // 未出库
  1133. if out_count == 0 {
  1134. var sum_in_count int64
  1135. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1136. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1137. fmt.Println("sum_in_count", sum_in_count)
  1138. //如果修改的数量大于有库存的第一个批次
  1139. if number_count > sum_in_count {
  1140. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1141. return
  1142. }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1148. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1149. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1150. if pharmacyConfig.IsOpen != 1 {
  1151. if device_number != number_count {
  1152. // 查询该药品最后一次出库记录
  1153. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1154. //回退库存
  1155. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1156. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1157. }
  1158. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1159. var stock_max_number int64
  1160. var stock_min_number int64
  1161. if number_count >= drug.MinNumber {
  1162. stock_max_number = device_number / drug.MinNumber
  1163. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1164. stock_min_number = device_number % drug.MinNumber
  1165. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1166. } else {
  1167. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1168. }
  1169. }
  1170. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1171. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1172. }
  1173. //删除记录
  1174. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1175. //查询默认仓库剩余多少库存
  1176. var sum_count int64
  1177. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1178. for _, its := range stockInfo {
  1179. if its.MaxUnit == drug.MaxUnit {
  1180. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1181. }
  1182. sum_count += its.StockMaxNumber + its.StockMinNumber
  1183. }
  1184. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. //保存处方开药
  1191. if drugOutConfig.IsOpen == 1 {
  1192. //修改处方
  1193. for _, advice := range advices {
  1194. var drug_id int64
  1195. var prescribing_number float64
  1196. var prescribingNumberUnit string
  1197. var prescribingNumber string
  1198. var adviceId int64
  1199. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1200. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1201. }
  1202. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1203. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1204. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1205. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1206. }
  1207. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1208. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1209. }
  1210. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1211. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1212. }
  1213. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1214. if drug.ID == 0 {
  1215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1216. return
  1217. }
  1218. //查询药品的所有库存
  1219. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1220. var total_count int64
  1221. for _, it := range list {
  1222. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1223. }
  1224. totals := strconv.FormatInt(total_count, 10)
  1225. //查询该药品是否存在开药记录
  1226. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1227. //新增处方
  1228. if advicelist.ID == 0 {
  1229. //查询最新批次库存
  1230. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1231. var batch_number_count int64
  1232. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1233. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1234. all_count, _ := strconv.ParseFloat(totals, 64)
  1235. if prescribingNumberUnit == drug.MinUnit {
  1236. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1237. if drug.IsUse != 1 {
  1238. if prescribing_number > all_count {
  1239. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1240. return
  1241. }
  1242. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1243. if prescribing_number > batch_number_all_count {
  1244. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1245. return
  1246. }
  1247. }
  1248. }
  1249. } else {
  1250. if prescribingNumberUnit == drug.MaxUnit {
  1251. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1252. num := prescribing_number * float64(drug.MinNumber)
  1253. if drug.IsUse != 1 {
  1254. if num > all_count {
  1255. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1256. return
  1257. }
  1258. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1259. if prescribing_number > batch_number_all_count {
  1260. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1261. return
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. //修改处方
  1269. if advicelist.ID > 0 {
  1270. //查询最新批次库存
  1271. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1272. var batch_number_count int64
  1273. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1274. var device_number int64
  1275. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1276. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1277. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1278. device_number = prescribingNumberInt * drug.MinNumber
  1279. }
  1280. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1281. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1282. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1283. device_number = prescribingNumberInt
  1284. }
  1285. var number_count int64
  1286. if prescribingNumberUnit == drug.MaxUnit {
  1287. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1288. number_count = prescribingNumberInt * drug.MinNumber
  1289. }
  1290. if prescribingNumberUnit == drug.MinUnit {
  1291. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1292. number_count = prescribingNumberInt
  1293. }
  1294. //如果修改的数量大于之前修改的数量
  1295. if (number_count - device_number) > 0 {
  1296. //如果修改的差数量 大于库存数量
  1297. if drug.IsUse != 1 {
  1298. if (number_count - device_number) > total_count {
  1299. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1300. return
  1301. }
  1302. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1303. if (number_count - device_number) > batch_number_count {
  1304. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1305. return
  1306. }
  1307. }
  1308. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1309. //查询历史出库数据总批次
  1310. // 查询该药品最后一次出库记录
  1311. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1312. var out_count int64
  1313. var in_count int64
  1314. var stock_max_number int64
  1315. var stock_min_number int64
  1316. for _, it := range outInfo {
  1317. if it.CountUnit == drug.MaxUnit {
  1318. it.Count = it.Count * drug.MinNumber
  1319. }
  1320. out_count += it.Count
  1321. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1322. stock_max_number = warehouseInfoList.StockMaxNumber
  1323. stock_min_number = warehouseInfoList.StockMinNumber
  1324. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1325. }
  1326. if out_count > 0 {
  1327. if (number_count - device_number) > in_count {
  1328. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1329. return
  1330. }
  1331. }
  1332. // 未出库
  1333. if out_count == 0 {
  1334. var sum_in_count int64
  1335. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1336. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1337. //如果修改的数量大于有库存的第一个批次
  1338. if number_count > sum_in_count {
  1339. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1340. return
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. }
  1356. //校验耗材库存
  1357. if goodOutConfig.IsOpen == 1 {
  1358. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1359. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1360. if len(prescriptions) > 0 {
  1361. for _, item := range prescriptions {
  1362. items := item.(map[string]interface{})
  1363. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1364. projects := items["project"].([]interface{})
  1365. if len(projects) > 0 {
  1366. for _, project := range projects {
  1367. var project_id int64
  1368. var project_type int64
  1369. var totals float64
  1370. var project_name string
  1371. var parsetotal int64
  1372. var id int64
  1373. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1374. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1375. }
  1376. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1377. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1378. }
  1379. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1380. total, _ := project.(map[string]interface{})["total"].(string)
  1381. totals, _ = strconv.ParseFloat(total, 64)
  1382. }
  1383. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1384. project_name = project.(map[string]interface{})["project_name"].(string)
  1385. }
  1386. if project_type == 3 {
  1387. //查找该耗材的出库记录
  1388. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1389. if len(goodWarehouseInfo) == 0 {
  1390. //查询耗材库存
  1391. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1392. var stock_count int64
  1393. for _, it := range list {
  1394. stock_count += it.StockCount
  1395. }
  1396. stock_counts := strconv.FormatInt(stock_count, 10)
  1397. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1398. if totals > stock_total_count {
  1399. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1400. return
  1401. }
  1402. }
  1403. if len(goodWarehouseInfo) > 0 {
  1404. //查询该患者耗材的历史数据
  1405. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1406. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1407. //数量发生改变
  1408. if parsetotal != count {
  1409. //如果现在的数量大于历史数量,就要看库存是否足够
  1410. if parsetotal > count {
  1411. //查询耗材所有库存
  1412. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1413. var stock_count int64
  1414. for _, it := range list {
  1415. stock_count += it.StockCount
  1416. }
  1417. //库存不足
  1418. if (parsetotal - count) > stock_count {
  1419. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1420. return
  1421. }
  1422. }
  1423. }
  1424. }
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. //不使用耗材保存处方出库
  1434. if goodOutConfig.IsOpen != 1 {
  1435. if stockConfig.IsOpen == 1 {
  1436. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1437. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1438. if len(prescriptions) > 0 {
  1439. for _, item := range prescriptions {
  1440. items := item.(map[string]interface{})
  1441. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1442. projects := items["project"].([]interface{})
  1443. if len(projects) > 0 {
  1444. for _, project := range projects {
  1445. var project_id int64
  1446. var project_type int64
  1447. var totals float64
  1448. var project_name string
  1449. var parsetotal int64
  1450. var id int64
  1451. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1452. id = int64(project.(map[string]interface{})["id"].(float64))
  1453. }
  1454. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1455. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1456. }
  1457. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1458. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1459. }
  1460. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1461. total, _ := project.(map[string]interface{})["total"].(string)
  1462. totals, _ = strconv.ParseFloat(total, 64)
  1463. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1464. }
  1465. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1466. project_name = project.(map[string]interface{})["project_name"].(string)
  1467. }
  1468. if project_type == 3 {
  1469. //查找该耗材的出库记录
  1470. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1471. if len(goodWarehouseInfo) == 0 {
  1472. //查询耗材库存
  1473. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1474. var stock_count int64
  1475. for _, it := range list {
  1476. stock_count += it.StockCount
  1477. }
  1478. stock_counts := strconv.FormatInt(stock_count, 10)
  1479. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1480. if totals > stock_total_count {
  1481. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1482. return
  1483. }
  1484. //查找今日该患者已经出库的所有耗材
  1485. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1486. for _, item := range goodList {
  1487. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1488. var flush_count int64
  1489. for _, it := range goodListSix {
  1490. flush_count += it.StockCount
  1491. }
  1492. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1493. creater := adminInfo.AdminUser.Id
  1494. if errs != nil {
  1495. goodErrcode := models.XtGoodErrcode{
  1496. UserOrgId: item.OrgId,
  1497. Errcode: "手动出库更新剩余出库失败",
  1498. GoodId: item.GoodId,
  1499. Status: 1,
  1500. Ctime: time.Now().Unix(),
  1501. Mtime: 0,
  1502. Count: 0,
  1503. StockCount: 0,
  1504. Creater: creater,
  1505. BatchNumberId: 0,
  1506. WarehouseOutId: 0,
  1507. }
  1508. service.CreateGoodErrcode(goodErrcode)
  1509. }
  1510. }
  1511. //删除记录
  1512. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1513. }
  1514. if len(goodWarehouseInfo) > 0 {
  1515. //查询该患者耗材的历史数据
  1516. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1517. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1518. //数量发生改变
  1519. if parsetotal != count {
  1520. //查找今日该患者已经出库的所有耗材
  1521. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1522. for _, item := range goodList {
  1523. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1524. var flush_count int64
  1525. for _, it := range goodListSix {
  1526. flush_count += it.StockCount
  1527. }
  1528. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1529. //减少出库数量
  1530. creater := adminInfo.AdminUser.Id
  1531. if errs != nil {
  1532. goodErrcode := models.XtGoodErrcode{
  1533. UserOrgId: item.OrgId,
  1534. Errcode: "手动出库更新剩余出库失败",
  1535. GoodId: item.GoodId,
  1536. Status: 1,
  1537. Ctime: time.Now().Unix(),
  1538. Mtime: 0,
  1539. Count: 0,
  1540. StockCount: 0,
  1541. Creater: creater,
  1542. BatchNumberId: 0,
  1543. WarehouseOutId: 0,
  1544. }
  1545. service.CreateGoodErrcode(goodErrcode)
  1546. }
  1547. //查询默认仓库
  1548. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1549. var total_count int64
  1550. for _, it := range stockList {
  1551. total_count += it.StockCount
  1552. }
  1553. //基础库插入数据
  1554. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1555. }
  1556. //删除记录
  1557. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1570. var hpInfo models.HisPrescriptionInfo
  1571. if info.ID == 0 {
  1572. var randNum int
  1573. randNum = rand.Intn(10000) + 1000
  1574. timestamp := time.Now().Unix()
  1575. tempTime := time.Unix(timestamp, 0)
  1576. timeFormat := tempTime.Format("20060102150405")
  1577. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1578. hpInfo = models.HisPrescriptionInfo{
  1579. HisPatientId: his_patient_id,
  1580. UserOrgId: adminInfo.CurrentOrgId,
  1581. RecordDate: theTime.Unix(),
  1582. PatientId: patient_id,
  1583. Status: 1,
  1584. Ctime: time.Now().Unix(),
  1585. Mtime: time.Now().Unix(),
  1586. Creator: adminInfo.AdminUser.Id,
  1587. Modifier: adminInfo.AdminUser.Id,
  1588. Diagnosis: diagnose,
  1589. SickHistory: sick_history,
  1590. Departments: department,
  1591. RegisterType: reg_type,
  1592. PrescriptionNumber: p_number,
  1593. PrescriptionStatus: 1,
  1594. Doctor: role.UserName,
  1595. DoctorId: doctor_id,
  1596. SickType: sick_type,
  1597. PType: p_type,
  1598. }
  1599. service.SavePatientPrescriptionInfo(hpInfo)
  1600. redis := service.RedisClient()
  1601. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1602. redis.Set(key, "", time.Second)
  1603. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1604. redis.Set(keyOne, "", time.Second)
  1605. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1606. redis.Set(keySeven, "", time.Second)
  1607. defer redis.Close()
  1608. } else {
  1609. hpInfo = models.HisPrescriptionInfo{
  1610. ID: info.ID,
  1611. UserOrgId: adminInfo.CurrentOrgId,
  1612. RecordDate: info.RecordDate,
  1613. PatientId: info.PatientId,
  1614. Status: 1,
  1615. Ctime: info.Ctime,
  1616. Mtime: time.Now().Unix(),
  1617. Creator: info.Creator,
  1618. Modifier: adminInfo.AdminUser.Id,
  1619. Diagnosis: diagnose,
  1620. SickHistory: sick_history,
  1621. Departments: department,
  1622. RegisterType: reg_type,
  1623. PrescriptionNumber: info.PrescriptionNumber,
  1624. Doctor: role.UserName,
  1625. PrescriptionStatus: info.PrescriptionStatus,
  1626. DoctorId: doctor_id,
  1627. SickType: sick_type,
  1628. PType: info.PType,
  1629. HisPatientId: info.HisPatientId,
  1630. }
  1631. service.SavePatientPrescriptionInfo(hpInfo)
  1632. redis := service.RedisClient()
  1633. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1634. redis.Set(key, "", time.Second)
  1635. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1636. redis.Set(keyOne, "", time.Second)
  1637. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1638. redis.Set(keySeven, "", time.Second)
  1639. defer redis.Close()
  1640. }
  1641. //定义切片
  1642. var adviceList []models.HisDoctorAdviceInfo
  1643. var projectList []models.HisPrescriptionProject
  1644. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1645. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1646. var tempPrescription *models.HisPrescription
  1647. if len(prescriptions) > 0 {
  1648. for _, item := range prescriptions {
  1649. items := item.(map[string]interface{})
  1650. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1651. utils.ErrorLog("id")
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. id := int64(items["id"].(float64))
  1656. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1657. tempPrescription = &new_prescription
  1658. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1659. utils.ErrorLog("type")
  1660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1661. return
  1662. }
  1663. types := int64(items["type"].(float64))
  1664. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1665. utils.ErrorLog("med_type")
  1666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1667. return
  1668. }
  1669. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1670. if med_type == "0" {
  1671. med_type = "14"
  1672. }
  1673. //if order_status == 0 {
  1674. // order_status = 1
  1675. //}
  1676. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1677. utils.ErrorLog("pre_time")
  1678. }
  1679. preTime, _ := items["pre_time"].(string)
  1680. timeLayout := "2006-01-02"
  1681. loc, _ := time.LoadLocation("Local")
  1682. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1683. if err != nil {
  1684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1685. return
  1686. }
  1687. pTime := theTime2.Unix()
  1688. ctime := time.Now().Unix()
  1689. if tempPrescription.ID == 0 {
  1690. prescription := &models.HisPrescription{
  1691. ID: 0,
  1692. PatientId: patient_id,
  1693. UserOrgId: adminInfo.CurrentOrgId,
  1694. RecordDate: recordDateTime,
  1695. Ctime: ctime,
  1696. Mtime: ctime,
  1697. Type: types,
  1698. Modifier: adminInfo.AdminUser.Id,
  1699. Creator: adminInfo.AdminUser.Id,
  1700. Status: 1,
  1701. Doctor: role.UserName,
  1702. HisPatientId: his_patient_id,
  1703. OrderStatus: 1,
  1704. BatchNumber: "",
  1705. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1706. PreTime: pTime,
  1707. PType: p_type,
  1708. MedType: med_type,
  1709. }
  1710. tempPrescription = prescription
  1711. service.SaveHisPrescription(tempPrescription)
  1712. redis := service.RedisClient()
  1713. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1714. redis.Set(key, "", time.Second)
  1715. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1716. redis.Set(keyOne, "", time.Second)
  1717. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1718. redis.Set(keySeven, "", time.Second)
  1719. defer redis.Close()
  1720. } else {
  1721. tempPrescription.ID = id
  1722. tempPrescription.Type = types
  1723. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1724. tempPrescription.Mtime = time.Now().Unix()
  1725. tempPrescription.Doctor = role.UserName
  1726. //tempPrescription.OrderStatus = order_status
  1727. tempPrescription.PreTime = pTime
  1728. tempPrescription.MedType = med_type
  1729. service.SaveHisPrescription(tempPrescription)
  1730. redis := service.RedisClient()
  1731. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1732. redis.Set(key, "", time.Second)
  1733. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1734. redis.Set(keyOne, "", time.Second)
  1735. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1736. redis.Set(keySeven, "", time.Second)
  1737. defer redis.Close()
  1738. }
  1739. //service.SaveHisPrescription(prescription)
  1740. //更改患者挂号状态
  1741. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1742. fmt.Println("更改失败", err2)
  1743. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1744. advices := items["advices"].([]interface{})
  1745. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1746. groupNo := int64(0)
  1747. ctime := time.Now().Unix()
  1748. mtime := ctime
  1749. if len(advices) > 0 {
  1750. for _, advice := range advices {
  1751. var s models.HisDoctorAdviceInfo
  1752. s.PrescriptionId = tempPrescription.ID
  1753. s.AdviceType = 2
  1754. s.AdviceDoctor = doctor_id
  1755. s.StopState = 2
  1756. s.ExecutionState = 2
  1757. s.AdviceDate = recordDateTime
  1758. s.Status = 1
  1759. s.UserOrgId = adminInfo.CurrentOrgId
  1760. s.RecordDate = recordDateTime
  1761. s.StartTime = tempPrescription.PreTime
  1762. s.Groupno = groupNo
  1763. s.CreatedTime = ctime
  1764. s.UpdatedTime = mtime
  1765. s.PatientId = patient_id
  1766. s.HisPatientId = his_patient_id
  1767. s.StartTime = pTime
  1768. s.IsSettle = 2
  1769. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1770. if errcode > 0 {
  1771. c.ServeFailJSONWithSGJErrorCode(errcode)
  1772. return
  1773. }
  1774. s.StartTime = pTime
  1775. var total_count int64 //处方总库存
  1776. //查询改药品信息
  1777. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  1778. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  1779. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  1780. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1781. total_count += prescribingNumberSeven * medical.MinNumber
  1782. }
  1783. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1784. total_count += prescribingNumberSeven
  1785. }
  1786. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1787. total_count += prescribingNumberSeven
  1788. }
  1789. service.CreateHisDoctorAdvice(&s)
  1790. //存储切片中
  1791. adviceList = append(adviceList, s)
  1792. redis := service.RedisClient()
  1793. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1794. redis.Set(key, "", time.Second)
  1795. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1796. redis.Set(keyOne, "", time.Second)
  1797. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1798. redis.Set(keySeven, "", time.Second)
  1799. var randNum int
  1800. randNum = rand.Intn(10000) + 1000
  1801. timestamp := time.Now().Unix()
  1802. tempTime := time.Unix(timestamp, 0)
  1803. timeFormat := tempTime.Format("20060102150405")
  1804. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1805. service.CreateHisDoctorAdvice(&s)
  1806. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1807. redis.Set(keySix, "", time.Second)
  1808. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1809. redis.Set(keyFive, "", time.Second)
  1810. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1811. redis.Set(keyEight, "", time.Second)
  1812. defer redis.Close()
  1813. }
  1814. }
  1815. }
  1816. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1817. projects := items["project"].([]interface{})
  1818. if len(projects) > 0 {
  1819. for _, project := range projects {
  1820. var p models.HisPrescriptionProject
  1821. p.PrescriptionId = tempPrescription.ID
  1822. p.Ctime = time.Now().Unix()
  1823. p.Mtime = time.Now().Unix()
  1824. p.PatientId = patient_id
  1825. p.RecordDate = recordDateTime
  1826. p.Doctor = doctor_id
  1827. p.UserOrgId = adminInfo.CurrentOrgId
  1828. p.HisPatientId = his_patient_id
  1829. p.Status = 1
  1830. p.StartTime = pTime
  1831. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1832. if errcode > 0 {
  1833. c.ServeFailJSONWithSGJErrorCode(errcode)
  1834. return
  1835. }
  1836. if p.ID == 0 {
  1837. p.IsOut = 2
  1838. }
  1839. if p.ID > 0 {
  1840. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  1841. p.IsOut = projectDetail.IsOut
  1842. }
  1843. service.CreateHisProjectTwo(&p)
  1844. projectList = append(projectList, p)
  1845. var randNum int
  1846. randNum = rand.Intn(10000) + 1000
  1847. timestamp := time.Now().Unix()
  1848. tempTime := time.Unix(timestamp, 0)
  1849. timeFormat := tempTime.Format("20060102150405")
  1850. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1851. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1852. //新增或者编辑项目,修改对应的标签数据
  1853. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1854. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1855. var label models.HisLabelPrintInfo
  1856. project, _ := service.GetProjectDetail(p.ProjectId)
  1857. if project.CostClassify == 3 { //类别为检验检查
  1858. if p.TeamId > 0 { //检验检查组套
  1859. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1860. if tempLabel.ID == 0 {
  1861. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1862. label.Number = tempPrescription.PrescriptionNumber
  1863. label.ProjectId = project.ID
  1864. label.Status = 1
  1865. label.IsPrint = 2
  1866. label.DoctorId = info.DoctorId
  1867. label.UserOrgId = p.UserOrgId
  1868. label.PatientId = patient_id
  1869. label.RecordDate = recordDateTime
  1870. label.Ctime = time.Now().Unix()
  1871. label.Mtime = time.Now().Unix()
  1872. label.ItemId = p.TeamId
  1873. label.FeedetlSn = p.FeedetlSn
  1874. label.PProjectId = p.ID
  1875. label.ProjectName = team.ProjectTeam
  1876. label.PatientName = patient.Name
  1877. service.CreateHisLabelRecord(&label)
  1878. }
  1879. } else { //单条检验检查项目
  1880. label.Number = tempPrescription.PrescriptionNumber
  1881. label.ProjectId = project.ID
  1882. label.Status = 1
  1883. label.DoctorId = info.DoctorId
  1884. label.UserOrgId = p.UserOrgId
  1885. label.PatientId = patient_id
  1886. label.RecordDate = recordDateTime
  1887. label.IsPrint = 2
  1888. label.Ctime = time.Now().Unix()
  1889. label.Mtime = time.Now().Unix()
  1890. label.FeedetlSn = p.FeedetlSn
  1891. label.PProjectId = p.ID
  1892. label.ItemId = p.TeamId
  1893. label.ProjectName = project.ProjectName
  1894. label.PatientName = patient.Name
  1895. service.CreateHisLabelRecord(&label)
  1896. }
  1897. }
  1898. }
  1899. }
  1900. service.SaveHisProjectTwo(&p)
  1901. }
  1902. }
  1903. }
  1904. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1905. // addition := items["addition"].([]interface{})
  1906. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1907. // ctime := time.Now().Unix()
  1908. // mtime := ctime
  1909. // if len(addition) > 0 {
  1910. // for _, item := range addition {
  1911. // var s models.HisAdditionalCharge
  1912. // s.PrescriptionId = tempPrescription.ID
  1913. // s.Status = 1
  1914. // s.UserOrgId = adminInfo.CurrentOrgId
  1915. // s.RecordDate = recordDateTime
  1916. // s.CreatedTime = ctime
  1917. // s.UpdatedTime = mtime
  1918. // s.PatientId = patient_id
  1919. // s.HisPatientId = his_patient_id
  1920. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1921. // if errcode > 0 {
  1922. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1923. // return
  1924. // }
  1925. // service.CreateAdditionalCharge(&s)
  1926. // var randNum int
  1927. // randNum = rand.Intn(10000) + 1000
  1928. // timestamp := time.Now().Unix()
  1929. // tempTime := time.Unix(timestamp, 0)
  1930. // timeFormat := tempTime.Format("20060102150405")
  1931. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1932. // service.CreateAdditionalCharge(&s)
  1933. //
  1934. // }
  1935. // }
  1936. //}
  1937. }
  1938. }
  1939. //查询今日该患者开的药品处方
  1940. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1941. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1942. //药品出库
  1943. if drugOutConfig.IsOpen == 1 {
  1944. for _, item := range hisdoctorlist {
  1945. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  1946. // 查询该药品最后一次出库记录
  1947. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  1948. if len(druginfo) > 0 {
  1949. //回退库存
  1950. for _, it := range druginfo {
  1951. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1952. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1953. }
  1954. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1955. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1956. }
  1957. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  1958. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1959. }
  1960. }
  1961. }
  1962. //删除记录
  1963. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  1964. //查询最后一次数据
  1965. if drugOutConfig.IsOpen == 1 {
  1966. //出库
  1967. if drug.IsUse == 2 {
  1968. creater := adminInfo.AdminUser.Id
  1969. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  1970. }
  1971. //更新字典里面的库存
  1972. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1973. var sum_count int64
  1974. for _, its := range stockInfo {
  1975. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1976. if its.MaxUnit == baseDrug.MaxUnit {
  1977. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1978. }
  1979. sum_count += its.StockMaxNumber + its.StockMinNumber
  1980. }
  1981. //更新基础库存
  1982. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1983. //剩余库存
  1984. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  1985. }
  1986. }
  1987. }
  1988. //耗材保存处方出库
  1989. if goodOutConfig.IsOpen == 1 {
  1990. //查询今日耗材出库数量
  1991. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1992. for _, item := range hisgoodlist {
  1993. //查询耗材最后一次出库记录
  1994. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  1995. fmt.Println("hh23h232323o23o23o2o32o23o2o3o2o23o32o23o2o323o23o23o23o23o23o")
  1996. //查询默认出库仓库库存
  1997. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1998. if len(wareOut) > 0 {
  1999. for _, it := range wareOut {
  2000. //回退库存
  2001. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2002. //删除出库记录
  2003. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2004. //出库数量减少
  2005. service.UpdateSumCount(it.OrgId, storeConfig.StorehouseOutInfo, it.ProjectId, it.Count)
  2006. }
  2007. }
  2008. timeStr := time.Now().Format("2006-01-02")
  2009. timeArr := strings.Split(timeStr, "-")
  2010. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2011. total = total + 1
  2012. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2013. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2014. number = number + total
  2015. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2016. operation_time := time.Now().Unix()
  2017. creater := c.GetAdminUserInfo().AdminUser.Id
  2018. recordDateStr := time.Now().Format("2006-01-02")
  2019. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2020. nowtime := recordDate.Unix()
  2021. warehouseOut := models.WarehouseOut{
  2022. WarehouseOutOrderNumber: warehousing_out_order,
  2023. OperationTime: operation_time,
  2024. OrgId: adminInfo.CurrentOrgId,
  2025. Creater: creater,
  2026. Ctime: time.Now().Unix(),
  2027. Status: 1,
  2028. WarehouseOutTime: nowtime,
  2029. Type: 1,
  2030. StorehouseId: storeConfig.StorehouseOutInfo,
  2031. IsCheck: 1,
  2032. IsSys: 1,
  2033. }
  2034. //查询是否生成出库单
  2035. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2036. if out.ID == 0 {
  2037. service.AddSigleWarehouseOut(&warehouseOut)
  2038. }
  2039. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2040. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2041. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2042. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2043. dialyPrepareOne := models.DialysisBeforePrepare{
  2044. GoodTypeId: goodObj.GoodTypeId,
  2045. GoodId: item.ProjectId,
  2046. PatientId: item.PatientId,
  2047. RecordDate: item.RecordDate,
  2048. UserOrgId: adminInfo.CurrentOrgId,
  2049. Count: parseIntCount,
  2050. Ctime: time.Now().Unix(),
  2051. Creater: creater,
  2052. Status: 1,
  2053. StorehouseId: houseConfig.StorehouseOutInfo,
  2054. ProjectId: item.ID,
  2055. }
  2056. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2057. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2058. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2059. //查询剩余库存
  2060. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2061. var sum_count int64
  2062. for _, item := range goodList {
  2063. sum_count += item.StockCount
  2064. }
  2065. //更新剩余库存
  2066. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2067. //耗材
  2068. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2069. }
  2070. }
  2071. }
  2072. }
  2073. //redisClient := service.RedisClient()
  2074. //defer redisClient.Close()
  2075. //
  2076. //list := models.HisList{
  2077. // Patient_id: patient_id,
  2078. // Advice_id:0,
  2079. // Record_date: 0,
  2080. // Advice: adviceList,
  2081. // Project: nil,
  2082. //}
  2083. //hisLis = append(hisLis, list)
  2084. //
  2085. //advice_json, _ := json.Marshal(&hisLis)
  2086. //redisClient.RPush("111", advice_json).Result()
  2087. //result, _ := redisClient.RPop("111").Result()
  2088. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2089. //
  2090. //var dat []map[string]interface{}
  2091. //json.Unmarshal([]byte(result), &dat)
  2092. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2093. //
  2094. //for k,v:=range dat{
  2095. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2096. //}
  2097. //project_json, _ := json.Marshal(&projectList)
  2098. //redisClient.LPush("222", project_json).Result()
  2099. if err == nil {
  2100. c.ServeSuccessJSON(map[string]interface{}{
  2101. "msg": "保存成功",
  2102. })
  2103. return
  2104. } else {
  2105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2106. return
  2107. }
  2108. }
  2109. func (c *HisApiController) EditHisPrescription() {
  2110. record_date := c.GetString("record_date")
  2111. patient_id, _ := c.GetInt64("patient_id")
  2112. reg_type, _ := c.GetInt64("reg_type")
  2113. //diagnose, _ := c.GetInt64("diagnose", 0)
  2114. diagnose := c.GetString("diagnose")
  2115. sick_type, _ := c.GetInt64("sick_type")
  2116. sick_history := c.GetString("sick_history")
  2117. doctor_id, _ := c.GetInt64("doctor", 0)
  2118. department, _ := c.GetInt64("department", 0)
  2119. his_patient_id, _ := c.GetInt64("his_patient_id")
  2120. p_type, _ := c.GetInt64("p_type")
  2121. dataBody := make(map[string]interface{}, 0)
  2122. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2123. if err != nil {
  2124. utils.ErrorLog(err.Error())
  2125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2126. return
  2127. }
  2128. timeLayout := "2006-01-02"
  2129. loc, _ := time.LoadLocation("Local")
  2130. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2131. if err != nil {
  2132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2133. return
  2134. }
  2135. adminInfo := c.GetAdminUserInfo()
  2136. recordDateTime := theTime.Unix()
  2137. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2138. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2139. var hpInfo models.HisPrescriptionInfo
  2140. if info.ID == 0 {
  2141. var randNum int
  2142. randNum = rand.Intn(10000) + 1000
  2143. timestamp := time.Now().Unix()
  2144. tempTime := time.Unix(timestamp, 0)
  2145. timeFormat := tempTime.Format("20060102150405")
  2146. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2147. hpInfo = models.HisPrescriptionInfo{
  2148. UserOrgId: adminInfo.CurrentOrgId,
  2149. RecordDate: theTime.Unix(),
  2150. PatientId: patient_id,
  2151. Status: 1,
  2152. Ctime: time.Now().Unix(),
  2153. Mtime: time.Now().Unix(),
  2154. Creator: adminInfo.AdminUser.Id,
  2155. Modifier: adminInfo.AdminUser.Id,
  2156. Diagnosis: diagnose,
  2157. SickHistory: sick_history,
  2158. Departments: department,
  2159. RegisterType: reg_type,
  2160. PrescriptionNumber: p_number,
  2161. PrescriptionStatus: 1,
  2162. Doctor: role.UserName,
  2163. DoctorId: doctor_id,
  2164. SickType: sick_type,
  2165. PType: p_type,
  2166. }
  2167. service.SavePatientPrescriptionInfo(hpInfo)
  2168. } else {
  2169. hpInfo = models.HisPrescriptionInfo{
  2170. ID: info.ID,
  2171. UserOrgId: adminInfo.CurrentOrgId,
  2172. RecordDate: info.RecordDate,
  2173. PatientId: info.PatientId,
  2174. Status: 1,
  2175. Ctime: info.Ctime,
  2176. Mtime: time.Now().Unix(),
  2177. Creator: info.Creator,
  2178. Modifier: adminInfo.AdminUser.Id,
  2179. Diagnosis: diagnose,
  2180. SickHistory: sick_history,
  2181. Departments: department,
  2182. RegisterType: reg_type,
  2183. PrescriptionNumber: info.PrescriptionNumber,
  2184. Doctor: role.UserName,
  2185. PrescriptionStatus: info.PrescriptionStatus,
  2186. DoctorId: doctor_id,
  2187. SickType: sick_type,
  2188. PType: info.PType,
  2189. }
  2190. service.SavePatientPrescriptionInfo(hpInfo)
  2191. }
  2192. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2193. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2194. if len(prescriptions) > 0 {
  2195. for _, item := range prescriptions {
  2196. items := item.(map[string]interface{})
  2197. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2198. utils.ErrorLog("id")
  2199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2200. return
  2201. }
  2202. id := int64(items["id"].(float64))
  2203. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2204. utils.ErrorLog("type")
  2205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2206. return
  2207. }
  2208. types := int64(items["type"].(float64))
  2209. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2210. utils.ErrorLog("med_type")
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2212. return
  2213. }
  2214. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2215. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2216. ctime := time.Now().Unix()
  2217. prescription := &models.HisPrescription{
  2218. ID: id,
  2219. PatientId: patient_id,
  2220. UserOrgId: adminInfo.CurrentOrgId,
  2221. RecordDate: recordDateTime,
  2222. Ctime: ctime,
  2223. Mtime: ctime,
  2224. Type: types,
  2225. Modifier: adminInfo.AdminUser.Id,
  2226. Creator: adminInfo.AdminUser.Id,
  2227. Status: 1,
  2228. Doctor: role.UserName,
  2229. HisPatientId: his_patient_id,
  2230. OrderStatus: 1,
  2231. BatchNumber: "",
  2232. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2233. PType: hpInfo.PType,
  2234. MedType: med_type,
  2235. }
  2236. if historyPrescription.ID > 0 {
  2237. prescription.PreTime = historyPrescription.PreTime
  2238. }
  2239. service.SaveHisPrescription(prescription)
  2240. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2241. advices := items["advices"].([]interface{})
  2242. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2243. groupNo := int64(0)
  2244. ctime := time.Now().Unix()
  2245. mtime := ctime
  2246. if len(advices) > 0 {
  2247. for _, advice := range advices {
  2248. var s models.HisDoctorAdviceInfo
  2249. s.PrescriptionId = prescription.ID
  2250. s.AdviceType = 2
  2251. s.AdviceDoctor = adminInfo.AdminUser.Id
  2252. s.StopState = 2
  2253. s.ExecutionState = 2
  2254. s.AdviceDate = recordDateTime
  2255. s.Status = 1
  2256. s.UserOrgId = adminInfo.CurrentOrgId
  2257. s.RecordDate = recordDateTime
  2258. s.StartTime = prescription.PreTime
  2259. s.Groupno = groupNo
  2260. s.CreatedTime = ctime
  2261. s.UpdatedTime = mtime
  2262. s.PatientId = patient_id
  2263. s.HisPatientId = his_patient_id
  2264. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2265. if errcode > 0 {
  2266. c.ServeFailJSONWithSGJErrorCode(errcode)
  2267. return
  2268. }
  2269. service.CreateHisDoctorAdvice(&s)
  2270. redis := service.RedisClient()
  2271. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2272. redis.Set(key, "", time.Second)
  2273. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2274. fmt.Println("keyOne", keyOne)
  2275. redis.Set(keyOne, "", time.Second)
  2276. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2277. redis.Set(keySeven, "", time.Second)
  2278. redis.Close()
  2279. }
  2280. }
  2281. }
  2282. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2283. projects := items["project"].([]interface{})
  2284. if len(projects) > 0 {
  2285. for _, project := range projects {
  2286. var p models.HisPrescriptionProject
  2287. p.PrescriptionId = prescription.ID
  2288. p.Ctime = time.Now().Unix()
  2289. p.Mtime = time.Now().Unix()
  2290. p.PatientId = patient_id
  2291. p.RecordDate = recordDateTime
  2292. p.UserOrgId = adminInfo.CurrentOrgId
  2293. p.HisPatientId = his_patient_id
  2294. p.Status = 1
  2295. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2296. if errcode > 0 {
  2297. c.ServeFailJSONWithSGJErrorCode(errcode)
  2298. return
  2299. }
  2300. service.CreateHisProjectTwo(&p)
  2301. }
  2302. }
  2303. }
  2304. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2305. addition := items["addition"].([]interface{})
  2306. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2307. ctime := time.Now().Unix()
  2308. mtime := ctime
  2309. if len(addition) > 0 {
  2310. for _, item := range addition {
  2311. var s models.HisAdditionalCharge
  2312. s.PrescriptionId = prescription.ID
  2313. s.Status = 1
  2314. s.UserOrgId = adminInfo.CurrentOrgId
  2315. s.RecordDate = recordDateTime
  2316. s.CreatedTime = ctime
  2317. s.UpdatedTime = mtime
  2318. s.PatientId = patient_id
  2319. s.HisPatientId = his_patient_id
  2320. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2321. if errcode > 0 {
  2322. c.ServeFailJSONWithSGJErrorCode(errcode)
  2323. return
  2324. }
  2325. service.CreateAdditionalCharge(&s)
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. }
  2332. if err == nil {
  2333. c.ServeSuccessJSON(map[string]interface{}{
  2334. "msg": "保存成功",
  2335. })
  2336. return
  2337. } else {
  2338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2339. return
  2340. }
  2341. }
  2342. func (c *HisApiController) DeletePrescription() {
  2343. prescription_id, _ := c.GetInt64("id")
  2344. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2345. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2346. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2347. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2348. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2349. //耗材保存处方出库
  2350. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2351. //已收费和已发药限制逻辑
  2352. isCharge := false
  2353. isMedicine := false
  2354. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2355. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2356. for _, item := range new_prescriptions {
  2357. if item.IsMedicine == 1 {
  2358. isMedicine = true
  2359. }
  2360. }
  2361. for _, item := range new_prescriptions {
  2362. if item.OrderStatus == 4 {
  2363. isCharge = true
  2364. }
  2365. }
  2366. if p_err != nil {
  2367. if new_prescription.ID > 0 {
  2368. if new_prescription.OrderStatus == 2 {
  2369. isCharge = true
  2370. }
  2371. }
  2372. }
  2373. for _, item := range advices {
  2374. if item.IsMedicine == 1 {
  2375. isMedicine = true
  2376. }
  2377. }
  2378. if isCharge {
  2379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2380. return
  2381. }
  2382. if isMedicine {
  2383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2384. return
  2385. }
  2386. //已收费和已发药限制逻辑
  2387. if len(projects) > 0 {
  2388. for _, item := range projects {
  2389. service.DeletePrintInfo(item.ID) //删除打印信息
  2390. if goodOutConfig.IsOpen != 1 {
  2391. if stockConfig.IsOpen == 1 {
  2392. if item.Type == 3 && item.IsOut == 1 {
  2393. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2394. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2395. good.Total = good.Total + f_count
  2396. service.UpdateGoodInfo(&good)
  2397. operation_time := time.Now().Unix()
  2398. creater := c.GetAdminUserInfo().AdminUser.Id
  2399. //创建退库单
  2400. timeStr := time.Now().Format("2006-01-02")
  2401. timeArr := strings.Split(timeStr, "-")
  2402. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2403. total = total + 1
  2404. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2405. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2406. cancelStock := models.CancelStock{
  2407. OrderNumber: orderNumber,
  2408. OperaTime: operation_time,
  2409. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2410. Creater: creater,
  2411. Ctime: time.Now().Unix(),
  2412. Status: 1,
  2413. ReturnTime: item.RecordDate,
  2414. Type: 1,
  2415. StorehouseId: houseConfig.StorehouseOutInfo,
  2416. IsCheck: 1,
  2417. }
  2418. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2419. if msgerrkonde == gorm.ErrRecordNotFound {
  2420. service.AddSigleCancelStock(&cancelStock)
  2421. }
  2422. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2423. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2424. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2425. //查询该耗材是否出库
  2426. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2427. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2428. deaerler, _ := service.GetDealerById(info.Dealer)
  2429. var total_count int64
  2430. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2431. total_count += count
  2432. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2433. var flush_count int64
  2434. for _, it := range goodList {
  2435. flush_count += it.StockCount
  2436. }
  2437. if info.ID > 0 {
  2438. if info.Count >= total_count {
  2439. //回退库存
  2440. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2441. cancelStockInfo := models.CancelStockInfo{
  2442. GoodId: item.ProjectId,
  2443. CancelStockId: cancel.ID,
  2444. GoodTypeId: good.GoodTypeId,
  2445. Count: prescribingNumber,
  2446. Price: info.Price,
  2447. Total: 0,
  2448. ProductDate: info.ProductDate,
  2449. ExpiryDate: info.ExpiryDate,
  2450. Ctime: time.Now().Unix(),
  2451. Status: 1,
  2452. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2453. OrderNumber: cancel.OrderNumber,
  2454. Type: 0,
  2455. Dealer: deaerler.DealerName,
  2456. Manufacturer: manufacturer.ManufacturerName,
  2457. Number: info.Number,
  2458. RegisterAccount: "",
  2459. Remark: "",
  2460. WarehouseInfoId: info.WarehouseInfotId,
  2461. PatientId: info.PatientId,
  2462. RecordDate: info.SysRecordTime,
  2463. StorehouseId: houseConfig.StorehouseOutInfo,
  2464. IsCheck: 1,
  2465. }
  2466. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2467. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2468. flow := models.VmStockFlow{
  2469. WarehousingId: info.WarehouseInfotId,
  2470. GoodId: item.ProjectId,
  2471. Number: info.Number,
  2472. LicenseNumber: info.LicenseNumber,
  2473. Count: prescribingNumber,
  2474. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2475. PatientId: item.PatientId,
  2476. SystemTime: info.SysRecordTime,
  2477. ConsumableType: 7,
  2478. IsSys: 0,
  2479. WarehousingOrder: "",
  2480. WarehouseOutId: info.WarehouseOutId,
  2481. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2482. IsEdit: 0,
  2483. CancelStockId: cancel.ID,
  2484. CancelOrderNumber: cancel.OrderNumber,
  2485. Manufacturer: manufacturer.ID,
  2486. Dealer: 0,
  2487. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2488. UpdateCreator: 0,
  2489. Status: 1,
  2490. Ctime: time.Now().Unix(),
  2491. Mtime: 0,
  2492. Price: info.Price,
  2493. WarehousingDetailId: info.WarehouseInfotId,
  2494. WarehouseOutDetailId: info.ID,
  2495. CancelOutDetailId: cancelInfo.ID,
  2496. ProductDate: info.ProductDate,
  2497. ExpireDate: info.ExpiryDate,
  2498. StorehouseId: houseConfig.StorehouseOutInfo,
  2499. OverCount: flush_count,
  2500. }
  2501. service.CreateStockFlowOne(flow)
  2502. //退库数量增加
  2503. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2504. //出库数量减少
  2505. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2506. }
  2507. if info.Count < total_count {
  2508. //回退库存
  2509. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2510. cancelStockInfo := models.CancelStockInfo{
  2511. GoodId: item.ProjectId,
  2512. CancelStockId: cancel.ID,
  2513. GoodTypeId: good.GoodTypeId,
  2514. Count: info.Count,
  2515. Price: info.Price,
  2516. Total: 0,
  2517. ProductDate: info.ProductDate,
  2518. ExpiryDate: info.ExpiryDate,
  2519. Ctime: time.Now().Unix(),
  2520. Status: 1,
  2521. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2522. OrderNumber: cancel.OrderNumber,
  2523. Type: 0,
  2524. Dealer: deaerler.DealerName,
  2525. Manufacturer: manufacturer.ManufacturerName,
  2526. Number: info.Number,
  2527. RegisterAccount: "",
  2528. Remark: "",
  2529. WarehouseInfoId: info.WarehouseInfotId,
  2530. PatientId: info.PatientId,
  2531. RecordDate: info.SysRecordTime,
  2532. StorehouseId: houseConfig.StorehouseOutInfo,
  2533. IsCheck: 1,
  2534. }
  2535. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2536. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2537. flow := models.VmStockFlow{
  2538. WarehousingId: info.WarehouseInfotId,
  2539. GoodId: item.ProjectId,
  2540. Number: info.Number,
  2541. LicenseNumber: info.LicenseNumber,
  2542. Count: info.Count,
  2543. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2544. PatientId: item.PatientId,
  2545. SystemTime: info.SysRecordTime,
  2546. ConsumableType: 7,
  2547. IsSys: 0,
  2548. WarehousingOrder: "",
  2549. WarehouseOutId: info.WarehouseOutId,
  2550. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2551. IsEdit: 0,
  2552. CancelStockId: cancel.ID,
  2553. CancelOrderNumber: cancel.OrderNumber,
  2554. Manufacturer: manufacturer.ID,
  2555. Dealer: 0,
  2556. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2557. UpdateCreator: 0,
  2558. Status: 1,
  2559. Ctime: time.Now().Unix(),
  2560. Mtime: 0,
  2561. Price: info.Price,
  2562. WarehousingDetailId: info.WarehouseInfotId,
  2563. WarehouseOutDetailId: info.ID,
  2564. CancelOutDetailId: cancelInfo.ID,
  2565. ProductDate: info.ProductDate,
  2566. ExpireDate: info.ExpiryDate,
  2567. StorehouseId: houseConfig.StorehouseOutInfo,
  2568. OverCount: flush_count,
  2569. }
  2570. service.CreateStockFlowOne(flow)
  2571. //退库数量增加
  2572. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2573. //出库数量减少
  2574. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2575. }
  2576. //查询已出库数量
  2577. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2578. if prescribingNumber < dialysisInfo.Count {
  2579. //改变数量
  2580. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2581. }
  2582. if prescribingNumber >= dialysisInfo.Count {
  2583. //删除出库表
  2584. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  2585. }
  2586. //更新库存
  2587. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  2588. //更新基础库库存
  2589. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  2590. //查询今日该耗材退库数量
  2591. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2592. //var cancel_Count int64
  2593. //for _, items := range cancelInfoOne {
  2594. // cancel_Count += items.Count
  2595. //}
  2596. //
  2597. //cha_count = total_count - cancel_Count
  2598. //
  2599. //if total_count > cancel_Count {
  2600. //
  2601. // out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  2602. // if err == gorm.ErrRecordNotFound {
  2603. // //没有记录,则创建出库单
  2604. // timeStr := time.Now().Format("2006-01-02")
  2605. // timeArr := strings.Split(timeStr, "-")
  2606. // total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  2607. // total = total + 1
  2608. // warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2609. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2610. // number = number + total
  2611. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2612. // warehouseOut := models.WarehouseOut{
  2613. // WarehouseOutOrderNumber: warehousing_out_order,
  2614. // OperationTime: time.Now().Unix(),
  2615. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2616. // Creater: creater,
  2617. // Ctime: time.Now().Unix(),
  2618. // Status: 1,
  2619. // WarehouseOutTime: info.SysRecordTime,
  2620. // Dealer: 0,
  2621. // Manufacturer: 0,
  2622. // Type: 1,
  2623. // IsSys: 1,
  2624. // StorehouseId: houseConfig.StorehouseOutInfo,
  2625. // IsCheck: 1,
  2626. // }
  2627. // err := service.AddSigleWarehouseOut(&warehouseOut)
  2628. // if err != nil {
  2629. // utils.TraceLog("创建出库单失败 err = %v", err)
  2630. // return
  2631. // }
  2632. // prepare := &models.DialysisBeforePrepare{
  2633. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2634. // PatientId: info.PatientId,
  2635. // RecordDate: info.SysRecordTime,
  2636. // GoodId: item.ProjectId,
  2637. // GoodTypeId: info.GoodTypeId,
  2638. // Count: cha_count,
  2639. // StorehouseId: houseConfig.StorehouseOutInfo,
  2640. // }
  2641. // //出库
  2642. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2643. // } else if err == nil {
  2644. //
  2645. // prepare := &models.DialysisBeforePrepare{
  2646. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2647. // PatientId: info.PatientId,
  2648. // RecordDate: info.SysRecordTime,
  2649. // GoodId: item.ProjectId,
  2650. // GoodTypeId: info.GoodTypeId,
  2651. // Count: cha_count,
  2652. // StorehouseId: houseConfig.StorehouseOutInfo,
  2653. // }
  2654. // //出库
  2655. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2656. // }
  2657. //
  2658. //}
  2659. }
  2660. }
  2661. }
  2662. }
  2663. //保存耗材出库
  2664. if goodOutConfig.IsOpen == 1 {
  2665. if item.Type == 3 {
  2666. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2667. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2668. good.Total = good.Total + f_count
  2669. service.UpdateGoodInfo(&good)
  2670. operation_time := time.Now().Unix()
  2671. creater := c.GetAdminUserInfo().AdminUser.Id
  2672. //创建退库单
  2673. timeStr := time.Now().Format("2006-01-02")
  2674. timeArr := strings.Split(timeStr, "-")
  2675. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2676. total = total + 1
  2677. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2678. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2679. cancelStock := models.CancelStock{
  2680. OrderNumber: orderNumber,
  2681. OperaTime: operation_time,
  2682. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2683. Creater: creater,
  2684. Ctime: time.Now().Unix(),
  2685. Status: 1,
  2686. ReturnTime: item.RecordDate,
  2687. Type: 1,
  2688. StorehouseId: houseConfig.StorehouseOutInfo,
  2689. IsCheck: 1,
  2690. }
  2691. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2692. if msgerrkonde == gorm.ErrRecordNotFound {
  2693. service.AddSigleCancelStock(&cancelStock)
  2694. }
  2695. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2696. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2697. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2698. //查询该耗材是否出库
  2699. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2700. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2701. deaerler, _ := service.GetDealerById(info.Dealer)
  2702. var total_count int64
  2703. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2704. total_count += count
  2705. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2706. var flush_count int64
  2707. for _, it := range goodList {
  2708. flush_count += it.StockCount
  2709. }
  2710. fmt.Println("历史出库数据", info.Count)
  2711. fmt.Println("出库数量", total_count)
  2712. if info.ID > 0 {
  2713. //回退库存
  2714. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2715. cancelStockInfo := models.CancelStockInfo{
  2716. GoodId: item.ProjectId,
  2717. CancelStockId: cancel.ID,
  2718. GoodTypeId: good.GoodTypeId,
  2719. Count: prescribingNumber,
  2720. Price: info.Price,
  2721. Total: 0,
  2722. ProductDate: info.ProductDate,
  2723. ExpiryDate: info.ExpiryDate,
  2724. Ctime: time.Now().Unix(),
  2725. Status: 1,
  2726. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2727. OrderNumber: cancel.OrderNumber,
  2728. Type: 0,
  2729. Dealer: deaerler.DealerName,
  2730. Manufacturer: manufacturer.ManufacturerName,
  2731. Number: info.Number,
  2732. RegisterAccount: "",
  2733. Remark: "",
  2734. WarehouseInfoId: info.WarehouseInfotId,
  2735. PatientId: info.PatientId,
  2736. RecordDate: info.SysRecordTime,
  2737. StorehouseId: houseConfig.StorehouseOutInfo,
  2738. IsCheck: 1,
  2739. }
  2740. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2741. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2742. flow := models.VmStockFlow{
  2743. WarehousingId: info.WarehouseInfotId,
  2744. GoodId: item.ProjectId,
  2745. Number: info.Number,
  2746. LicenseNumber: info.LicenseNumber,
  2747. Count: prescribingNumber,
  2748. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2749. PatientId: item.PatientId,
  2750. SystemTime: info.SysRecordTime,
  2751. ConsumableType: 7,
  2752. IsSys: 0,
  2753. WarehousingOrder: "",
  2754. WarehouseOutId: info.WarehouseOutId,
  2755. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2756. IsEdit: 0,
  2757. CancelStockId: cancel.ID,
  2758. CancelOrderNumber: cancel.OrderNumber,
  2759. Manufacturer: manufacturer.ID,
  2760. Dealer: 0,
  2761. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2762. UpdateCreator: 0,
  2763. Status: 1,
  2764. Ctime: time.Now().Unix(),
  2765. Mtime: 0,
  2766. Price: info.Price,
  2767. WarehousingDetailId: info.WarehouseInfotId,
  2768. WarehouseOutDetailId: info.ID,
  2769. CancelOutDetailId: cancelInfo.ID,
  2770. ProductDate: info.ProductDate,
  2771. ExpireDate: info.ExpiryDate,
  2772. StorehouseId: houseConfig.StorehouseOutInfo,
  2773. OverCount: flush_count,
  2774. }
  2775. service.CreateStockFlowOne(flow)
  2776. //退库数量增加
  2777. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2778. //出库数量减少
  2779. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2780. //if info.Count < total_count {
  2781. // //回退库存
  2782. // service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2783. // cancelStockInfo := models.CancelStockInfo{
  2784. // GoodId: item.ProjectId,
  2785. // CancelStockId: cancel.ID,
  2786. // GoodTypeId: good.GoodTypeId,
  2787. // Count: info.Count,
  2788. // Price: info.Price,
  2789. // Total: 0,
  2790. // ProductDate: info.ProductDate,
  2791. // ExpiryDate: info.ExpiryDate,
  2792. // Ctime: time.Now().Unix(),
  2793. // Status: 1,
  2794. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2795. // OrderNumber: cancel.OrderNumber,
  2796. // Type: 0,
  2797. // Dealer: deaerler.DealerName,
  2798. // Manufacturer: manufacturer.ManufacturerName,
  2799. // Number: info.Number,
  2800. // RegisterAccount: "",
  2801. // Remark: "",
  2802. // WarehouseInfoId: info.WarehouseInfotId,
  2803. // PatientId: info.PatientId,
  2804. // RecordDate: info.SysRecordTime,
  2805. // StorehouseId: houseConfig.StorehouseOutInfo,
  2806. // IsCheck: 1,
  2807. // }
  2808. //
  2809. // service.CreateCancelStockInfoOne(&cancelStockInfo)
  2810. //
  2811. // cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2812. //
  2813. // flow := models.VmStockFlow{
  2814. // WarehousingId: info.WarehouseInfotId,
  2815. // GoodId: item.ProjectId,
  2816. // Number: info.Number,
  2817. // LicenseNumber: info.LicenseNumber,
  2818. // Count: info.Count,
  2819. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2820. // PatientId: item.PatientId,
  2821. // SystemTime: info.SysRecordTime,
  2822. // ConsumableType: 7,
  2823. // IsSys: 0,
  2824. // WarehousingOrder: "",
  2825. // WarehouseOutId: info.WarehouseOutId,
  2826. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2827. // IsEdit: 0,
  2828. // CancelStockId: cancel.ID,
  2829. // CancelOrderNumber: cancel.OrderNumber,
  2830. // Manufacturer: manufacturer.ID,
  2831. // Dealer: 0,
  2832. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  2833. // UpdateCreator: 0,
  2834. // Status: 1,
  2835. // Ctime: time.Now().Unix(),
  2836. // Mtime: 0,
  2837. // Price: info.Price,
  2838. // WarehousingDetailId: info.WarehouseInfotId,
  2839. // WarehouseOutDetailId: info.ID,
  2840. // CancelOutDetailId: cancelInfo.ID,
  2841. // ProductDate: info.ProductDate,
  2842. // ExpireDate: info.ExpiryDate,
  2843. // StorehouseId: houseConfig.StorehouseOutInfo,
  2844. // OverCount: flush_count,
  2845. // }
  2846. // service.CreateStockFlowOne(flow)
  2847. //
  2848. // //退库数量增加
  2849. // service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2850. // //出库数量减少
  2851. // service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2852. //
  2853. //}
  2854. //查询已出库数量
  2855. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2856. if prescribingNumber < dialysisInfo.Count {
  2857. //改变数量
  2858. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2859. }
  2860. if prescribingNumber >= dialysisInfo.Count {
  2861. //删除出库表
  2862. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  2863. }
  2864. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2865. var flush_count_one int64
  2866. for _, it := range goodList {
  2867. flush_count_one += it.StockCount
  2868. }
  2869. //更新库存
  2870. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  2871. fmt.Println("msgerrkonde23332323", msgerrkonde)
  2872. //更新基础库库存
  2873. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  2874. }
  2875. }
  2876. }
  2877. }
  2878. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2879. fmt.Println(err)
  2880. }
  2881. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2882. fmt.Println(err)
  2883. if len(advices) > 0 {
  2884. for _, item := range advices {
  2885. redis := service.RedisClient()
  2886. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2887. redis.Set(keyFive, "", time.Second)
  2888. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2889. redis.Set(keyOne, "", time.Second)
  2890. redis.Close()
  2891. }
  2892. }
  2893. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2894. if len(advices) > 0 {
  2895. for _, item := range advices {
  2896. creater := c.GetAdminUserInfo().AdminUser.Id
  2897. service.DrugAutoAddCancelInfo(item, creater)
  2898. }
  2899. }
  2900. } else {
  2901. if drugOutConfig.IsOpen == 1 {
  2902. if len(advices) > 0 {
  2903. for _, item := range advices {
  2904. creater := c.GetAdminUserInfo().AdminUser.Id
  2905. service.DrugAutoAddCancelInfo(item, creater)
  2906. }
  2907. }
  2908. }
  2909. }
  2910. c.ServeSuccessJSON(map[string]interface{}{
  2911. "msg": "删除成功",
  2912. })
  2913. return
  2914. }
  2915. func (c *HisApiController) DeleteDoctorAdvice() {
  2916. id, _ := c.GetInt64("id")
  2917. advice, _ := service.GetHisDoctorAdvicesById(id)
  2918. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2919. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2920. //已收费和已发药的限制逻辑
  2921. isCharge := false
  2922. isMedicine := false
  2923. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2924. //获取今天该患者所有处方,判断是否发药或者收费
  2925. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2926. for _, item := range new_prescriptions {
  2927. if item.IsMedicine == 1 {
  2928. isMedicine = true
  2929. }
  2930. }
  2931. for _, item := range new_prescriptions {
  2932. if item.OrderStatus == 4 {
  2933. isCharge = true
  2934. }
  2935. }
  2936. if isMedicine {
  2937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2938. return
  2939. }
  2940. if isCharge {
  2941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2942. return
  2943. }
  2944. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  2945. for _, item := range advices {
  2946. if item.IsMedicine == 1 {
  2947. isMedicine = true
  2948. }
  2949. }
  2950. if isMedicine {
  2951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  2952. return
  2953. }
  2954. if new_prescription.ID > 0 {
  2955. if new_prescription.OrderStatus == 2 {
  2956. isCharge = true
  2957. }
  2958. }
  2959. if isCharge {
  2960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2961. return
  2962. }
  2963. //已收费和已发药的限制逻辑
  2964. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2965. redis := service.RedisClient()
  2966. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2967. redis.Set(keyFive, "", time.Second)
  2968. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2969. redis.Set(keyOne, "", time.Second)
  2970. defer redis.Close()
  2971. if err == nil {
  2972. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2973. //查询是否在处方中出库
  2974. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2975. if openConfig.IsOpen != 1 {
  2976. //判断该医嘱是否执行了
  2977. if advice.ExecutionState == 1 {
  2978. creater := c.GetAdminUserInfo().AdminUser.Id
  2979. service.DrugAutoAddCancelInfo(&advice, creater)
  2980. }
  2981. }
  2982. //开启保存处方扣减功能
  2983. if openConfig.IsOpen == 1 {
  2984. creater := c.GetAdminUserInfo().AdminUser.Id
  2985. service.DrugAutoAddCancelInfo(&advice, creater)
  2986. }
  2987. } else {
  2988. if drugOutConfig.IsOpen == 1 {
  2989. //查询是否在处方中出库
  2990. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2991. if openConfig.IsOpen != 1 {
  2992. //判断该医嘱是否执行了
  2993. if advice.ExecutionState == 1 {
  2994. creater := c.GetAdminUserInfo().AdminUser.Id
  2995. service.DrugAutoAddCancelInfo(&advice, creater)
  2996. }
  2997. }
  2998. //开启保存处方扣减功能
  2999. if openConfig.IsOpen == 1 {
  3000. creater := c.GetAdminUserInfo().AdminUser.Id
  3001. service.DrugAutoAddCancelInfo(&advice, creater)
  3002. }
  3003. }
  3004. }
  3005. c.ServeSuccessJSON(map[string]interface{}{
  3006. "msg": "删除成功",
  3007. })
  3008. return
  3009. } else {
  3010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3011. return
  3012. }
  3013. }
  3014. func (c *HisApiController) DeleteProject() {
  3015. id, _ := c.GetInt64("id")
  3016. adminInfo := c.GetAdminUserInfo()
  3017. project, _ := service.GetHisProjectByID(id)
  3018. // var consumable models.DialysisBeforePrepare
  3019. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3020. //耗材保存处方出库
  3021. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3022. isCharge := false
  3023. isMedicine := false
  3024. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3025. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3026. for _, item := range new_prescriptions {
  3027. if item.IsMedicine == 1 {
  3028. isMedicine = true
  3029. }
  3030. }
  3031. for _, item := range new_prescriptions {
  3032. if item.OrderStatus == 4 {
  3033. isCharge = true
  3034. }
  3035. }
  3036. if isMedicine {
  3037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3038. return
  3039. }
  3040. if isCharge {
  3041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3042. return
  3043. }
  3044. if new_prescription.ID > 0 {
  3045. if new_prescription.OrderStatus == 2 {
  3046. isCharge = true
  3047. }
  3048. }
  3049. if isCharge {
  3050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3051. return
  3052. }
  3053. service.DeletePrintInfo(id)
  3054. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3055. label.Status = 0
  3056. service.CreateHisLabelRecord(&label)
  3057. if goodOutConfig.IsOpen != 1 {
  3058. if stockConfig.IsOpen == 1 {
  3059. if project.Type == 2 {
  3060. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3061. fmt.Println(err)
  3062. }
  3063. if project.Type == 3 && project.IsOut == 1 {
  3064. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3065. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3066. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3067. operation_time := time.Now().Unix()
  3068. creater := adminInfo.AdminUser.Id
  3069. //创建退库单
  3070. timeStr := time.Now().Format("2006-01-02")
  3071. timeArr := strings.Split(timeStr, "-")
  3072. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3073. total = total + 1
  3074. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3075. cancelStock := models.CancelStock{
  3076. OrderNumber: orderNumber,
  3077. OperaTime: operation_time,
  3078. OrgId: adminInfo.CurrentOrgId,
  3079. Creater: creater,
  3080. Ctime: time.Now().Unix(),
  3081. Status: 1,
  3082. ReturnTime: project.RecordDate,
  3083. Type: 1,
  3084. StorehouseId: houseConfig.StorehouseOutInfo,
  3085. IsCheck: 1,
  3086. }
  3087. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3088. if msgerrkonde == gorm.ErrRecordNotFound {
  3089. service.AddSigleCancelStock(&cancelStock)
  3090. }
  3091. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3092. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3093. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3094. //获取出库数据
  3095. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3096. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3097. deaerler, _ := service.GetDealerById(info.Dealer)
  3098. if info.ID > 0 {
  3099. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3100. if info.Count >= prescribingNumber {
  3101. cancelStockInfo := models.CancelStockInfo{
  3102. GoodId: project.ProjectId,
  3103. CancelStockId: cancel.ID,
  3104. GoodTypeId: good.GoodTypeId,
  3105. Count: prescribingNumber,
  3106. Price: info.Price,
  3107. Total: 0,
  3108. ProductDate: info.ProductDate,
  3109. ExpiryDate: info.ExpiryDate,
  3110. Ctime: time.Now().Unix(),
  3111. Status: 1,
  3112. OrgId: adminInfo.CurrentOrgId,
  3113. OrderNumber: cancel.OrderNumber,
  3114. Type: 0,
  3115. Dealer: deaerler.DealerName,
  3116. Manufacturer: manufacturer.ManufacturerName,
  3117. Number: info.Number,
  3118. RegisterAccount: "",
  3119. Remark: "",
  3120. WarehouseInfoId: info.WarehouseInfotId,
  3121. PatientId: info.PatientId,
  3122. RecordDate: info.SysRecordTime,
  3123. StorehouseId: houseConfig.StorehouseOutInfo,
  3124. IsCheck: 1,
  3125. }
  3126. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3127. //回退库存
  3128. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3129. //退库数量增加
  3130. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3131. //出库数量减少
  3132. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3133. }
  3134. if info.Count < prescribingNumber {
  3135. cancelStockInfo := models.CancelStockInfo{
  3136. GoodId: project.ProjectId,
  3137. CancelStockId: cancel.ID,
  3138. GoodTypeId: good.GoodTypeId,
  3139. Count: info.Count,
  3140. Price: info.Price,
  3141. Total: 0,
  3142. ProductDate: info.ProductDate,
  3143. ExpiryDate: info.ExpiryDate,
  3144. Ctime: time.Now().Unix(),
  3145. Status: 1,
  3146. OrgId: adminInfo.CurrentOrgId,
  3147. OrderNumber: cancel.OrderNumber,
  3148. Type: 0,
  3149. Dealer: deaerler.DealerName,
  3150. Manufacturer: manufacturer.ManufacturerName,
  3151. Number: info.Number,
  3152. RegisterAccount: "",
  3153. Remark: "",
  3154. WarehouseInfoId: info.WarehouseInfotId,
  3155. PatientId: info.PatientId,
  3156. RecordDate: info.SysRecordTime,
  3157. StorehouseId: houseConfig.StorehouseOutInfo,
  3158. IsCheck: 1,
  3159. }
  3160. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3161. //回退库存
  3162. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3163. //退库数量增加
  3164. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3165. //出库数量减少
  3166. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3167. }
  3168. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3169. var over_count int64
  3170. for _, it := range goodList {
  3171. over_count += it.StockCount
  3172. }
  3173. if info.Count >= prescribingNumber {
  3174. flow := models.VmStockFlow{
  3175. WarehousingId: info.WarehouseInfotId,
  3176. GoodId: project.ProjectId,
  3177. Number: info.Number,
  3178. LicenseNumber: info.LicenseNumber,
  3179. Count: prescribingNumber,
  3180. UserOrgId: adminInfo.CurrentOrgId,
  3181. PatientId: project.PatientId,
  3182. SystemTime: info.SysRecordTime,
  3183. ConsumableType: 7,
  3184. IsSys: 0,
  3185. WarehousingOrder: "",
  3186. WarehouseOutId: info.WarehouseOutId,
  3187. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3188. IsEdit: 0,
  3189. CancelStockId: cancel.ID,
  3190. CancelOrderNumber: cancel.OrderNumber,
  3191. Manufacturer: manufacturer.ID,
  3192. Dealer: 0,
  3193. Creator: adminInfo.AdminUser.Id,
  3194. UpdateCreator: 0,
  3195. Status: 1,
  3196. Ctime: time.Now().Unix(),
  3197. Mtime: 0,
  3198. Price: info.Price,
  3199. WarehousingDetailId: info.WarehouseInfotId,
  3200. WarehouseOutDetailId: info.ID,
  3201. CancelOutDetailId: cancelInfo.ID,
  3202. ProductDate: info.ProductDate,
  3203. ExpireDate: info.ExpiryDate,
  3204. StorehouseId: houseConfig.StorehouseOutInfo,
  3205. OverCount: over_count,
  3206. }
  3207. service.CreateStockFlowOne(flow)
  3208. }
  3209. if info.Count < prescribingNumber {
  3210. flow := models.VmStockFlow{
  3211. WarehousingId: info.WarehouseInfotId,
  3212. GoodId: project.ProjectId,
  3213. Number: info.Number,
  3214. LicenseNumber: info.LicenseNumber,
  3215. Count: info.Count,
  3216. UserOrgId: adminInfo.CurrentOrgId,
  3217. PatientId: project.PatientId,
  3218. SystemTime: info.SysRecordTime,
  3219. ConsumableType: 7,
  3220. IsSys: 0,
  3221. WarehousingOrder: "",
  3222. WarehouseOutId: info.WarehouseOutId,
  3223. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3224. IsEdit: 0,
  3225. CancelStockId: cancel.ID,
  3226. CancelOrderNumber: cancel.OrderNumber,
  3227. Manufacturer: manufacturer.ID,
  3228. Dealer: 0,
  3229. Creator: adminInfo.AdminUser.Id,
  3230. UpdateCreator: 0,
  3231. Status: 1,
  3232. Ctime: time.Now().Unix(),
  3233. Mtime: 0,
  3234. Price: info.Price,
  3235. WarehousingDetailId: info.WarehouseInfotId,
  3236. WarehouseOutDetailId: info.ID,
  3237. CancelOutDetailId: cancelInfo.ID,
  3238. ProductDate: info.ProductDate,
  3239. ExpireDate: info.ExpiryDate,
  3240. StorehouseId: houseConfig.StorehouseOutInfo,
  3241. OverCount: over_count,
  3242. }
  3243. service.CreateStockFlowOne(flow)
  3244. }
  3245. //查询已出库数量
  3246. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3247. if prescribingNumber < dialysisInfo.Count {
  3248. //改变数量
  3249. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3250. }
  3251. if prescribingNumber >= dialysisInfo.Count {
  3252. //删除出库表
  3253. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3254. }
  3255. //更新剩余库存
  3256. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3257. //查询今日该患者开了多少耗材
  3258. //projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  3259. //
  3260. //var total_count int64
  3261. //var cha_count int64
  3262. //for _, item := range projectList {
  3263. // count, _ := strconv.ParseInt(item.Count, 10, 64)
  3264. // total_count += count
  3265. //}
  3266. //
  3267. ////查询今日该耗材退库数量
  3268. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  3269. //var cancel_count int64
  3270. //for _, items := range cancelInfoOne {
  3271. // cancel_count += items.Count
  3272. //}
  3273. //
  3274. //cha_count = total_count - cancel_count
  3275. //
  3276. //if total_count > cancel_count {
  3277. //
  3278. // out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  3279. // if err == gorm.ErrRecordNotFound {
  3280. // //没有记录,则创建出库单
  3281. // timeStr := time.Now().Format("2006-01-02")
  3282. // timeArr := strings.Split(timeStr, "-")
  3283. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3284. // total = total + 1
  3285. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3286. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3287. // number = number + total
  3288. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3289. // warehouseOut := models.WarehouseOut{
  3290. // WarehouseOutOrderNumber: warehousing_out_order,
  3291. // OperationTime: time.Now().Unix(),
  3292. // OrgId: adminInfo.CurrentOrgId,
  3293. // Creater: creater,
  3294. // Ctime: time.Now().Unix(),
  3295. // Status: 1,
  3296. // WarehouseOutTime: info.SysRecordTime,
  3297. // Dealer: 0,
  3298. // Manufacturer: 0,
  3299. // Type: 1,
  3300. // IsSys: 1,
  3301. // StorehouseId: houseConfig.StorehouseOutInfo,
  3302. // }
  3303. // err := service.AddSigleWarehouseOut(&warehouseOut)
  3304. // if err != nil {
  3305. // utils.TraceLog("创建出库单失败 err = %v", err)
  3306. // return
  3307. // }
  3308. // prepare := &models.DialysisBeforePrepare{
  3309. // UserOrgId: adminInfo.CurrentOrgId,
  3310. // PatientId: info.PatientId,
  3311. // RecordDate: info.SysRecordTime,
  3312. // GoodId: project.ProjectId,
  3313. // GoodTypeId: info.GoodTypeId,
  3314. // Count: cha_count,
  3315. // StorehouseId: houseConfig.StorehouseOutInfo,
  3316. // }
  3317. // //出库
  3318. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  3319. // } else if err == nil {
  3320. // prepare := &models.DialysisBeforePrepare{
  3321. // UserOrgId: adminInfo.CurrentOrgId,
  3322. // PatientId: info.PatientId,
  3323. // RecordDate: info.SysRecordTime,
  3324. // GoodId: project.ProjectId,
  3325. // GoodTypeId: info.GoodTypeId,
  3326. // Count: cha_count,
  3327. // StorehouseId: houseConfig.StorehouseOutInfo,
  3328. // }
  3329. // //出库
  3330. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  3331. // }
  3332. //
  3333. //}
  3334. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3335. var total_count_one int64
  3336. for _, it := range stockList {
  3337. total_count_one += it.StockCount
  3338. }
  3339. //基础库插入数据
  3340. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3341. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3342. var flush_count int64
  3343. for _, it := range goodListOne {
  3344. flush_count += it.StockCount
  3345. }
  3346. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3347. if errs != nil {
  3348. goodErrcode := models.XtGoodErrcode{
  3349. UserOrgId: project.UserOrgId,
  3350. Errcode: "手动出库更新剩余出库失败",
  3351. GoodId: project.ProjectId,
  3352. Status: 1,
  3353. Ctime: time.Now().Unix(),
  3354. Mtime: 0,
  3355. Count: 0,
  3356. StockCount: 0,
  3357. Creater: creater,
  3358. BatchNumberId: 0,
  3359. WarehouseOutId: 0,
  3360. }
  3361. service.CreateGoodErrcode(goodErrcode)
  3362. }
  3363. }
  3364. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3365. fmt.Println(err)
  3366. } else {
  3367. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3368. fmt.Println(err)
  3369. }
  3370. }
  3371. }
  3372. if goodOutConfig.IsOpen == 1 {
  3373. if project.Type == 3 {
  3374. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3375. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3376. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3377. operation_time := time.Now().Unix()
  3378. creater := adminInfo.AdminUser.Id
  3379. //创建退库单
  3380. timeStr := time.Now().Format("2006-01-02")
  3381. timeArr := strings.Split(timeStr, "-")
  3382. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3383. total = total + 1
  3384. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3385. cancelStock := models.CancelStock{
  3386. OrderNumber: orderNumber,
  3387. OperaTime: operation_time,
  3388. OrgId: adminInfo.CurrentOrgId,
  3389. Creater: creater,
  3390. Ctime: time.Now().Unix(),
  3391. Status: 1,
  3392. ReturnTime: project.RecordDate,
  3393. Type: 1,
  3394. StorehouseId: houseConfig.StorehouseOutInfo,
  3395. IsCheck: 1,
  3396. }
  3397. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3398. if msgerrkonde == gorm.ErrRecordNotFound {
  3399. service.AddSigleCancelStock(&cancelStock)
  3400. }
  3401. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3402. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3403. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3404. //获取出库数据
  3405. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3406. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3407. deaerler, _ := service.GetDealerById(info.Dealer)
  3408. if info.ID > 0 {
  3409. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3410. if info.Count >= prescribingNumber {
  3411. cancelStockInfo := models.CancelStockInfo{
  3412. GoodId: project.ProjectId,
  3413. CancelStockId: cancel.ID,
  3414. GoodTypeId: good.GoodTypeId,
  3415. Count: prescribingNumber,
  3416. Price: info.Price,
  3417. Total: 0,
  3418. ProductDate: info.ProductDate,
  3419. ExpiryDate: info.ExpiryDate,
  3420. Ctime: time.Now().Unix(),
  3421. Status: 1,
  3422. OrgId: adminInfo.CurrentOrgId,
  3423. OrderNumber: cancel.OrderNumber,
  3424. Type: 0,
  3425. Dealer: deaerler.DealerName,
  3426. Manufacturer: manufacturer.ManufacturerName,
  3427. Number: info.Number,
  3428. RegisterAccount: "",
  3429. Remark: "",
  3430. WarehouseInfoId: info.WarehouseInfotId,
  3431. PatientId: info.PatientId,
  3432. RecordDate: info.SysRecordTime,
  3433. StorehouseId: houseConfig.StorehouseOutInfo,
  3434. IsCheck: 1,
  3435. }
  3436. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3437. //回退库存
  3438. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3439. //退库数量增加
  3440. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3441. //出库数量减少
  3442. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3443. }
  3444. if info.Count < prescribingNumber {
  3445. cancelStockInfo := models.CancelStockInfo{
  3446. GoodId: project.ProjectId,
  3447. CancelStockId: cancel.ID,
  3448. GoodTypeId: good.GoodTypeId,
  3449. Count: info.Count,
  3450. Price: info.Price,
  3451. Total: 0,
  3452. ProductDate: info.ProductDate,
  3453. ExpiryDate: info.ExpiryDate,
  3454. Ctime: time.Now().Unix(),
  3455. Status: 1,
  3456. OrgId: adminInfo.CurrentOrgId,
  3457. OrderNumber: cancel.OrderNumber,
  3458. Type: 0,
  3459. Dealer: deaerler.DealerName,
  3460. Manufacturer: manufacturer.ManufacturerName,
  3461. Number: info.Number,
  3462. RegisterAccount: "",
  3463. Remark: "",
  3464. WarehouseInfoId: info.WarehouseInfotId,
  3465. PatientId: info.PatientId,
  3466. RecordDate: info.SysRecordTime,
  3467. StorehouseId: houseConfig.StorehouseOutInfo,
  3468. IsCheck: 1,
  3469. }
  3470. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3471. //回退库存
  3472. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3473. //退库数量增加
  3474. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3475. //出库数量减少
  3476. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3477. }
  3478. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3479. var over_count int64
  3480. for _, it := range goodList {
  3481. over_count += it.StockCount
  3482. }
  3483. if info.Count >= prescribingNumber {
  3484. flow := models.VmStockFlow{
  3485. WarehousingId: info.WarehouseInfotId,
  3486. GoodId: project.ProjectId,
  3487. Number: info.Number,
  3488. LicenseNumber: info.LicenseNumber,
  3489. Count: prescribingNumber,
  3490. UserOrgId: adminInfo.CurrentOrgId,
  3491. PatientId: project.PatientId,
  3492. SystemTime: info.SysRecordTime,
  3493. ConsumableType: 7,
  3494. IsSys: 0,
  3495. WarehousingOrder: "",
  3496. WarehouseOutId: info.WarehouseOutId,
  3497. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3498. IsEdit: 0,
  3499. CancelStockId: cancel.ID,
  3500. CancelOrderNumber: cancel.OrderNumber,
  3501. Manufacturer: manufacturer.ID,
  3502. Dealer: 0,
  3503. Creator: adminInfo.AdminUser.Id,
  3504. UpdateCreator: 0,
  3505. Status: 1,
  3506. Ctime: time.Now().Unix(),
  3507. Mtime: 0,
  3508. Price: info.Price,
  3509. WarehousingDetailId: info.WarehouseInfotId,
  3510. WarehouseOutDetailId: info.ID,
  3511. CancelOutDetailId: cancelInfo.ID,
  3512. ProductDate: info.ProductDate,
  3513. ExpireDate: info.ExpiryDate,
  3514. StorehouseId: houseConfig.StorehouseOutInfo,
  3515. OverCount: over_count,
  3516. }
  3517. service.CreateStockFlowOne(flow)
  3518. }
  3519. if info.Count < prescribingNumber {
  3520. flow := models.VmStockFlow{
  3521. WarehousingId: info.WarehouseInfotId,
  3522. GoodId: project.ProjectId,
  3523. Number: info.Number,
  3524. LicenseNumber: info.LicenseNumber,
  3525. Count: info.Count,
  3526. UserOrgId: adminInfo.CurrentOrgId,
  3527. PatientId: project.PatientId,
  3528. SystemTime: info.SysRecordTime,
  3529. ConsumableType: 7,
  3530. IsSys: 0,
  3531. WarehousingOrder: "",
  3532. WarehouseOutId: info.WarehouseOutId,
  3533. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3534. IsEdit: 0,
  3535. CancelStockId: cancel.ID,
  3536. CancelOrderNumber: cancel.OrderNumber,
  3537. Manufacturer: manufacturer.ID,
  3538. Dealer: 0,
  3539. Creator: adminInfo.AdminUser.Id,
  3540. UpdateCreator: 0,
  3541. Status: 1,
  3542. Ctime: time.Now().Unix(),
  3543. Mtime: 0,
  3544. Price: info.Price,
  3545. WarehousingDetailId: info.WarehouseInfotId,
  3546. WarehouseOutDetailId: info.ID,
  3547. CancelOutDetailId: cancelInfo.ID,
  3548. ProductDate: info.ProductDate,
  3549. ExpireDate: info.ExpiryDate,
  3550. StorehouseId: houseConfig.StorehouseOutInfo,
  3551. OverCount: over_count,
  3552. }
  3553. service.CreateStockFlowOne(flow)
  3554. }
  3555. //查询已出库数量
  3556. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3557. if prescribingNumber < dialysisInfo.Count {
  3558. //改变数量
  3559. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3560. }
  3561. if prescribingNumber >= dialysisInfo.Count {
  3562. //删除出库表
  3563. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3564. }
  3565. //更新剩余库存
  3566. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3567. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3568. var total_count_one int64
  3569. for _, it := range stockList {
  3570. total_count_one += it.StockCount
  3571. }
  3572. //基础库插入数据
  3573. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3574. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3575. var flush_count int64
  3576. for _, it := range goodListOne {
  3577. flush_count += it.StockCount
  3578. }
  3579. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3580. if errs != nil {
  3581. goodErrcode := models.XtGoodErrcode{
  3582. UserOrgId: project.UserOrgId,
  3583. Errcode: "手动出库更新剩余出库失败",
  3584. GoodId: project.ProjectId,
  3585. Status: 1,
  3586. Ctime: time.Now().Unix(),
  3587. Mtime: 0,
  3588. Count: 0,
  3589. StockCount: 0,
  3590. Creater: creater,
  3591. BatchNumberId: 0,
  3592. WarehouseOutId: 0,
  3593. }
  3594. service.CreateGoodErrcode(goodErrcode)
  3595. }
  3596. }
  3597. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3598. fmt.Println(err)
  3599. } else {
  3600. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3601. fmt.Println(err)
  3602. }
  3603. }
  3604. c.ServeSuccessJSON(map[string]interface{}{
  3605. "msg": "删除成功",
  3606. })
  3607. return
  3608. }
  3609. func (c *HisApiController) CreateHisAdditionalCharge() {
  3610. his_patient_id, _ := c.GetInt64("his_patient_id")
  3611. patient_id, _ := c.GetInt64("patient_id")
  3612. record_date := c.GetString("record_date")
  3613. timeLayout := "2006-01-02"
  3614. loc, _ := time.LoadLocation("Local")
  3615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3616. if err != nil {
  3617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3618. return
  3619. }
  3620. adminInfo := c.GetAdminUserInfo()
  3621. recordDateTime := theTime.Unix()
  3622. dataBody := make(map[string]interface{}, 0)
  3623. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3624. if err != nil {
  3625. utils.ErrorLog(err.Error())
  3626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3627. return
  3628. }
  3629. var additions []*models.HisAdditionalCharge
  3630. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  3631. additions, _ := dataBody["addition"].([]interface{})
  3632. if len(additions) > 0 {
  3633. for _, item := range additions {
  3634. items := item.(map[string]interface{})
  3635. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  3636. utils.ErrorLog("item_id")
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3638. return
  3639. }
  3640. item_id := int64(items["item_id"].(float64))
  3641. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  3642. utils.ErrorLog("item_name")
  3643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3644. return
  3645. }
  3646. item_name := items["item_name"].(string)
  3647. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  3648. utils.ErrorLog("price")
  3649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3650. return
  3651. }
  3652. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3653. ctime := time.Now().Unix()
  3654. additional := &models.HisAdditionalCharge{
  3655. PatientId: patient_id,
  3656. HisPatientId: his_patient_id,
  3657. UserOrgId: adminInfo.CurrentOrgId,
  3658. RecordDate: recordDateTime,
  3659. CreatedTime: ctime,
  3660. UpdatedTime: ctime,
  3661. Modifier: adminInfo.AdminUser.Id,
  3662. Creator: adminInfo.AdminUser.Id,
  3663. Price: price,
  3664. ItemName: item_name,
  3665. ItemId: item_id,
  3666. Status: 1,
  3667. }
  3668. additions = append(additions, additional)
  3669. }
  3670. }
  3671. }
  3672. for _, item := range additions {
  3673. service.CreateAddtionalCharge(item)
  3674. }
  3675. c.ServeSuccessJSON(map[string]interface{}{
  3676. "msg": "创建成功",
  3677. })
  3678. }
  3679. func (c *HisApiController) CreateHisPatientCaseHistory() {
  3680. blood_fat := c.GetString("blood_fat")
  3681. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  3682. blood_sugar := c.GetString("blood_sugar")
  3683. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  3684. chief_conplaint := c.GetString("chief_conplaint")
  3685. dbp := c.GetString("dbp")
  3686. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  3687. delivery_way, _ := c.GetInt64("delivery_way")
  3688. diagnostic := c.GetString("diagnostic")
  3689. family_history := c.GetString("family_history")
  3690. height := c.GetString("height")
  3691. history_of_present_illness := c.GetString("history_of_present_illness")
  3692. is_infect, _ := c.GetInt64("is_infect")
  3693. past_history := c.GetString("past_history")
  3694. patient_id, _ := c.GetInt64("patient_id")
  3695. his_patient_id, _ := c.GetInt64("his_patient_id")
  3696. personal_history := c.GetString("personal_history")
  3697. pulse := c.GetString("pulse")
  3698. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  3699. sbp := c.GetString("sbp")
  3700. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  3701. heightfloat, _ := strconv.ParseFloat(height, 64)
  3702. sicktype := c.GetString("sick_type")
  3703. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  3704. symptom := c.GetString("symptom")
  3705. sick_date := c.GetString("sick_date")
  3706. temperatures := c.GetString("temperature")
  3707. temperature, _ := strconv.ParseFloat(temperatures, 64)
  3708. record_date := c.GetString("record_date")
  3709. breathing := c.GetString("breathing")
  3710. doctor_advice := c.GetString("doctor_advice")
  3711. remark := c.GetString("remark")
  3712. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  3713. sick, _ := c.GetInt64("sick")
  3714. diagnose, _ := c.GetInt64("diagnose")
  3715. //id, _ := c.GetInt64("id")
  3716. timeLayout := "2006-01-02"
  3717. loc, _ := time.LoadLocation("Local")
  3718. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3719. allergic_history := c.GetString("allergic_history")
  3720. if err != nil {
  3721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3722. return
  3723. }
  3724. recordDateTime := theTime.Unix()
  3725. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  3726. if err != nil {
  3727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3728. return
  3729. }
  3730. sickTimes := sickTime.Unix()
  3731. ctime := time.Now().Unix()
  3732. primary_disease := c.GetString("primary_disease")
  3733. confirm_failure_date := c.GetString("confirm_failure_date")
  3734. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  3735. drug_allergy_history := c.GetString("drug_allergy_history")
  3736. physical_examination := c.GetString("physical_examination")
  3737. special_inspection := c.GetString("special_inspection")
  3738. lab_apparatus := c.GetString("lab_apparatus")
  3739. caseHistory := models.HisPatientCaseHistory{
  3740. HisPatientId: his_patient_id,
  3741. PatientId: patient_id,
  3742. Temperature: temperature,
  3743. BloodSugar: bloodsugarfloat,
  3744. Pulse: pulsefloat,
  3745. Sbp: sbpfloat,
  3746. Dbp: dbpfloat,
  3747. Height: heightfloat,
  3748. BloodFat: bloodfatfloat,
  3749. SickType: sick_type,
  3750. Symptom: symptom,
  3751. SickDate: sickTimes,
  3752. IsInfect: is_infect,
  3753. HistoryOfPresentIllness: history_of_present_illness,
  3754. PastHistory: past_history,
  3755. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  3756. ChiefConplaint: chief_conplaint,
  3757. PersonalHistory: personal_history,
  3758. FamilyHistory: family_history,
  3759. Diagnostic: diagnostic,
  3760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3761. Status: 1,
  3762. Ctime: ctime,
  3763. Mtime: ctime,
  3764. RecordDate: recordDateTime,
  3765. DeliveryWay: delivery_way,
  3766. Breathing: breathingfloat,
  3767. DoctorAdvice: doctor_advice,
  3768. Remark: remark,
  3769. Sick: sick,
  3770. Diagnose: diagnose,
  3771. AllergicHistory: allergic_history,
  3772. PrimaryDisease: primary_disease,
  3773. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  3774. DrugAllergyHistory: drug_allergy_history,
  3775. PhysicalExamination: physical_examination,
  3776. SpecialInspection: special_inspection,
  3777. LabApparatus: lab_apparatus,
  3778. }
  3779. //查询该患者是否有病历
  3780. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  3781. if errcodes == gorm.ErrRecordNotFound {
  3782. err = service.SaveHisPatientCaseHistory(&caseHistory)
  3783. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3784. if err != nil {
  3785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3786. return
  3787. }
  3788. c.ServeSuccessJSON(map[string]interface{}{
  3789. "caseHistory": caseHistory,
  3790. "historyInfo": historyInfo,
  3791. })
  3792. return
  3793. } else if errcodes == nil {
  3794. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  3795. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3796. if err != nil {
  3797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3798. return
  3799. }
  3800. c.ServeSuccessJSON(map[string]interface{}{
  3801. "caseHistory": caseHistory,
  3802. "historyInfo": historyInfo,
  3803. })
  3804. }
  3805. //查询该患者是否有病历
  3806. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  3807. //if errcode == gorm.ErrRecordNotFound {
  3808. // err = service.SaveHisPatientCaseHistory(caseHistory)
  3809. // if err != nil {
  3810. // c.ServeSuccessJSON(map[string]interface{}{
  3811. // "msg": "保存成功",
  3812. // })
  3813. // }
  3814. //} else if errcode == nil {
  3815. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3816. // return
  3817. //}
  3818. }
  3819. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  3820. patient_id, _ := c.GetInt64("patient_id", 0)
  3821. adminUser := c.GetAdminUserInfo()
  3822. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  3823. c.ServeSuccessJSON(map[string]interface{}{
  3824. "list": caseHistorys,
  3825. })
  3826. }
  3827. func (c *HisApiController) GetHisPatientCaseHistory() {
  3828. record_date, _ := c.GetInt64("record_date", 0)
  3829. patient_id, _ := c.GetInt64("patient_id", 0)
  3830. admin := c.GetAdminUserInfo()
  3831. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  3832. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  3833. c.ServeSuccessJSON(map[string]interface{}{
  3834. "info": info,
  3835. "case_history": case_history,
  3836. })
  3837. }
  3838. func (c *HisApiController) CreateCaseHistoryTemplate() {
  3839. template_name := c.GetString("template_name")
  3840. template_remark := c.GetString("template_remark")
  3841. doctor := c.GetAdminUserInfo().AdminUser.Id
  3842. diagnostic := c.GetString("diagnostic")
  3843. chief_conplaint := c.GetString("chief_conplain")
  3844. history_of_present_illness := c.GetString("history_of_present_illness")
  3845. past_history := c.GetString("past_history")
  3846. personal_history := c.GetString("personal_history")
  3847. family_history := c.GetString("family_history")
  3848. user_name := c.GetString("user_name")
  3849. doctor_advice := c.GetString("doctor_advice")
  3850. remark := c.GetString("remark")
  3851. //record_date := c.GetString("record_date")
  3852. //fmt.Println("record_date--------",record_date)
  3853. //timeLayout := "2006-01-02"
  3854. //loc, _ := time.LoadLocation("Local")
  3855. //
  3856. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3857. //if err != nil {
  3858. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3859. // return
  3860. //}
  3861. //recordDateTime := theTime.Unix()
  3862. ctime := time.Now().Unix()
  3863. template := models.HisCaseHistoryTemplate{
  3864. HistoryOfPresentIllness: history_of_present_illness,
  3865. PastHistory: past_history,
  3866. ChiefConplaint: chief_conplaint,
  3867. PersonalHistory: personal_history,
  3868. FamilyHistory: family_history,
  3869. Diagnostic: diagnostic,
  3870. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3871. Status: 1,
  3872. Ctime: ctime,
  3873. Mtime: ctime,
  3874. RecordDate: time.Now().Unix(),
  3875. TemplateName: template_name,
  3876. TemplateRemark: template_remark,
  3877. Creator: doctor,
  3878. Modifier: doctor,
  3879. UserName: user_name,
  3880. DoctorAdvice: doctor_advice,
  3881. Remark: remark,
  3882. }
  3883. err := service.SaveHisPatientCaseHistoryTemplate(template)
  3884. if err == nil {
  3885. c.ServeSuccessJSON(map[string]interface{}{
  3886. "msg": "保存成功",
  3887. })
  3888. } else {
  3889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3890. return
  3891. }
  3892. }
  3893. func (c *HisApiController) GetCaseHistoryTemplate() {
  3894. timeLayout := "2006-01-02"
  3895. loc, _ := time.LoadLocation("Local")
  3896. keyword := c.GetString("keyword")
  3897. start_time := c.GetString("start_time")
  3898. end_time := c.GetString("end_time")
  3899. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3900. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3901. admin := c.GetAdminUserInfo()
  3902. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  3903. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  3904. c.ServeSuccessJSON(map[string]interface{}{
  3905. "template": template,
  3906. //"history": history,
  3907. })
  3908. }
  3909. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3910. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3911. utils.ErrorLog("drug_name")
  3912. return enums.ErrorCodeParamWrong
  3913. }
  3914. adviceName, _ := json["drug_name"].(string)
  3915. if len(adviceName) == 0 {
  3916. utils.ErrorLog("len(advice_name) == 0")
  3917. return enums.ErrorCodeParamWrong
  3918. }
  3919. advice.AdviceName = adviceName
  3920. adviceDesc, _ := json["advice_desc"].(string)
  3921. advice.AdviceDesc = adviceDesc
  3922. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3923. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3924. advice.DrugSpec = drugSpec
  3925. }
  3926. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3927. remark, _ := json["remark"].(string)
  3928. advice.Remark = remark
  3929. }
  3930. if json["id"] == nil {
  3931. advice.DrugId = 0
  3932. } else {
  3933. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3934. drug_id := int64(json["id"].(float64))
  3935. advice.DrugId = drug_id
  3936. }
  3937. }
  3938. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3939. advice_id := int64(json["advice_id"].(float64))
  3940. advice.ID = advice_id
  3941. if advice.ID > 0 {
  3942. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3943. if err == nil {
  3944. if hisAdvice.ID > 0 {
  3945. advice.ExecutionTime = hisAdvice.ExecutionTime
  3946. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3947. advice.ExecutionState = hisAdvice.ExecutionState
  3948. advice.CheckTime = hisAdvice.CheckTime
  3949. advice.Checker = hisAdvice.Checker
  3950. advice.CheckState = hisAdvice.CheckState
  3951. advice.StartTime = hisAdvice.StartTime
  3952. advice.FeedetlSn = hisAdvice.FeedetlSn
  3953. }
  3954. }
  3955. }
  3956. }
  3957. //
  3958. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3959. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3960. // advice.ExecutionTime = execution_time
  3961. //}
  3962. //
  3963. //
  3964. //
  3965. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3966. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3967. // advice.ExecutionStaff = execution_staff
  3968. //}
  3969. //
  3970. //
  3971. //
  3972. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3973. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3974. // advice.ExecutionState = execution_state
  3975. //}
  3976. //
  3977. //
  3978. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3979. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3980. // advice.CheckTime = check_time
  3981. //}
  3982. //
  3983. //
  3984. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3985. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3986. // advice.CheckState = check_state
  3987. //}
  3988. //
  3989. //
  3990. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3991. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3992. // advice.Checker = checker
  3993. //}
  3994. //
  3995. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3996. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3997. // advice.StartTime = start_time
  3998. //}
  3999. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4000. drugSpecUnit, _ := json["min_unit"].(string)
  4001. advice.DrugSpecUnit = drugSpecUnit
  4002. }
  4003. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4004. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4005. advice.SingleDose = singleDose
  4006. }
  4007. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4008. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4009. advice.SingleDoseUnit = singleDoseUnit
  4010. }
  4011. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4012. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4013. advice.PrescribingNumber = prescribingNumber
  4014. }
  4015. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4016. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4017. advice.PrescribingNumberUnit = prescribingNumberUnit
  4018. }
  4019. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4020. deliveryWay, _ := json["delivery_way"].(string)
  4021. advice.DeliveryWay = deliveryWay
  4022. }
  4023. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4024. executionFrequency, _ := json["execution_frequency"].(string)
  4025. advice.ExecutionFrequency = executionFrequency
  4026. }
  4027. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4028. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4029. advice.Price = price
  4030. }
  4031. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4032. med_list_codg, _ := json["medical_insurance_number"].(string)
  4033. advice.MedListCodg = med_list_codg
  4034. }
  4035. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4036. day := int64(json["day"].(float64))
  4037. advice.Day = day
  4038. }
  4039. return 0
  4040. }
  4041. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4042. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4043. id := int64(json["id"].(float64))
  4044. project.ID = id
  4045. historyProject, _ := service.GetHisProjectByID(id)
  4046. project.FeedetlSn = historyProject.FeedetlSn
  4047. }
  4048. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4049. project_id := int64(json["project_id"].(float64))
  4050. project.ProjectId = project_id
  4051. }
  4052. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4053. // price := int64(json["price"].(float64))
  4054. // formatInt_price := strconv.FormatInt(price, 10)
  4055. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4056. // project.Price = float_price
  4057. // }
  4058. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4059. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4060. project.Price = price
  4061. }
  4062. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4063. total, _ := json["total"].(string)
  4064. project.Count = total
  4065. }
  4066. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4067. medical_code, _ := json["medical_code"].(string)
  4068. project.MedListCodg = medical_code
  4069. }
  4070. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4071. single_dose, _ := json["single_dose"].(string)
  4072. project.SingleDose = single_dose
  4073. }
  4074. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4075. delivery_way, _ := json["delivery_way"].(string)
  4076. project.DeliveryWay = delivery_way
  4077. }
  4078. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4079. execution_frequency, _ := json["execution_frequency"].(string)
  4080. project.ExecutionFrequency = execution_frequency
  4081. }
  4082. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4083. remark, _ := json["remark"].(string)
  4084. project.Remark = remark
  4085. }
  4086. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4087. day, _ := json["number_days"].(string)
  4088. project.Day = day
  4089. }
  4090. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4091. unit, _ := json["unit"].(string)
  4092. project.Unit = unit
  4093. }
  4094. return 0
  4095. }
  4096. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4097. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4098. id := int64(json["id"].(float64))
  4099. historyAddtions, _ := service.GetHisAdditionByID(id)
  4100. additionalCharge.ID = id
  4101. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4102. }
  4103. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4104. item_id := int64(json["item_id"].(float64))
  4105. additionalCharge.ItemId = item_id
  4106. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4107. if config.ID > 0 {
  4108. if len(config.Code) > 0 {
  4109. additionalCharge.MedListCodg = config.Code
  4110. }
  4111. }
  4112. }
  4113. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4114. // price := int64(json["price"].(float64))
  4115. // formatInt_price := strconv.FormatInt(price, 10)
  4116. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4117. // additionalCharge.Price = float_price
  4118. // }
  4119. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4120. // price := int64(json["price"].(float64))
  4121. // formatInt_price := strconv.FormatInt(price, 10)
  4122. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4123. // additionalCharge.Price = float_price
  4124. //}
  4125. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4126. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4127. additionalCharge.Price = price
  4128. }
  4129. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4130. count, _ := json["count"].(string)
  4131. counts, _ := strconv.ParseInt(count, 10, 64)
  4132. additionalCharge.Count = counts
  4133. }
  4134. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4135. item_name, _ := json["item_name"].(string)
  4136. additionalCharge.ItemName = item_name
  4137. }
  4138. return 0
  4139. }
  4140. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4141. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4142. utils.ErrorLog("drug_name")
  4143. return enums.ErrorCodeParamWrong
  4144. }
  4145. adviceName, _ := json["drug_name"].(string)
  4146. if len(adviceName) == 0 {
  4147. utils.ErrorLog("len(advice_name) == 0")
  4148. return enums.ErrorCodeParamWrong
  4149. }
  4150. advice.AdviceName = adviceName
  4151. adviceDesc, _ := json["advice_desc"].(string)
  4152. advice.AdviceDesc = adviceDesc
  4153. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4154. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4155. advice.DrugSpec = drugSpec
  4156. }
  4157. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4158. remark, _ := json["remark"].(string)
  4159. advice.Remark = remark
  4160. }
  4161. if json["id"] == nil {
  4162. advice.DrugId = 0
  4163. } else {
  4164. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4165. drug_id := int64(json["id"].(float64))
  4166. advice.DrugId = drug_id
  4167. }
  4168. }
  4169. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4170. groupno := int64(json["groupno"].(float64))
  4171. advice.Groupno = groupno
  4172. }
  4173. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4174. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4175. advice.HospApprFlag = hosp_appr_flag
  4176. }
  4177. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4178. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4179. advice.PrescribingNumber = prescribingNumber
  4180. }
  4181. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4182. // frequency_type := int64(json["frequency_type"].(float64))
  4183. // advice.FrequencyType = frequency_type
  4184. //}
  4185. //
  4186. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4187. // day_count := int64(json["day_count"].(float64))
  4188. // advice.DayCount = day_count
  4189. //}
  4190. //
  4191. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4192. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4193. // week_day, _ := json["week_day"].(string)
  4194. // advice.WeekDay = week_day
  4195. //}
  4196. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4197. drugSpecUnit, _ := json["min_unit"].(string)
  4198. advice.DrugSpecUnit = drugSpecUnit
  4199. }
  4200. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4201. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4202. advice.SingleDose = singleDose
  4203. }
  4204. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4205. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4206. advice.SingleDoseUnit = singleDoseUnit
  4207. }
  4208. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4209. deliveryWay, _ := json["delivery_way"].(string)
  4210. advice.DeliveryWay = deliveryWay
  4211. }
  4212. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4213. executionFrequency, _ := json["execution_frequency"].(string)
  4214. advice.ExecutionFrequency = executionFrequency
  4215. }
  4216. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4217. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4218. advice.Price = price
  4219. }
  4220. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4221. med_list_codg, _ := json["medical_insurance_number"].(string)
  4222. advice.MedListCodg = med_list_codg
  4223. }
  4224. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4225. day := int64(json["day"].(float64))
  4226. advice.Day = day
  4227. }
  4228. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4229. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4230. advice.PrescribingNumberUnit = prescribingNumberUnit
  4231. }
  4232. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4233. advice_id := int64(json["advice_id"].(float64))
  4234. advice.ID = advice_id
  4235. if advice.ID > 0 {
  4236. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4237. if err == nil {
  4238. if hisAdvice.ID > 0 {
  4239. advice.ExecutionTime = hisAdvice.ExecutionTime
  4240. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4241. advice.ExecutionState = hisAdvice.ExecutionState
  4242. advice.CheckTime = hisAdvice.CheckTime
  4243. advice.Checker = hisAdvice.Checker
  4244. advice.CheckState = hisAdvice.CheckState
  4245. advice.StartTime = hisAdvice.StartTime
  4246. advice.HospApprFlag = hisAdvice.HospApprFlag
  4247. advice.IsMedicine = hisAdvice.IsMedicine
  4248. if hisAdvice.UserOrgId == 10028 {
  4249. 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 {
  4250. advice.ExecutionTime = 0
  4251. advice.ExecutionStaff = 0
  4252. advice.ExecutionState = 2
  4253. advice.CheckTime = 0
  4254. advice.Checker = 0
  4255. advice.CheckState = 2
  4256. }
  4257. } else {
  4258. 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 {
  4259. advice.ExecutionTime = 0
  4260. advice.ExecutionStaff = 0
  4261. advice.ExecutionState = 2
  4262. advice.CheckTime = 0
  4263. advice.Checker = 0
  4264. advice.CheckState = 2
  4265. }
  4266. }
  4267. //advice.Groupno = hisAdvice.Groupno
  4268. }
  4269. }
  4270. }
  4271. }
  4272. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4273. //
  4274. //if drugStockConfig.IsOpen == 1 {
  4275. //
  4276. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4277. // if advice.ID == 0 { //医嘱不存在
  4278. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4279. // drug.Total = drug.Total - advice.PrescribingNumber
  4280. // service.UpdateBaseDrugLib(&drug)
  4281. //
  4282. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4283. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4284. // drug.Total = drug.Total - num
  4285. // service.UpdateBaseDrugLib(&drug)
  4286. // }
  4287. //
  4288. // } else if advice.ID > 0 { //医嘱存在
  4289. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4290. // var num float64
  4291. //
  4292. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4293. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4294. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4295. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4296. // drug.Total = drug.Total + num
  4297. // service.UpdateBaseDrugLib(&drug)
  4298. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4299. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4300. // drug.Total = drug.Total - num
  4301. // service.UpdateBaseDrugLib(&drug)
  4302. // }
  4303. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4304. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4305. // if num2 > advice.PrescribingNumber {
  4306. // num = num2 - advice.PrescribingNumber
  4307. // drug.Total = drug.Total + num
  4308. // service.UpdateBaseDrugLib(&drug)
  4309. // } else if num2 < advice.PrescribingNumber {
  4310. // num = advice.PrescribingNumber - num2
  4311. // drug.Total = drug.Total - num
  4312. // service.UpdateBaseDrugLib(&drug)
  4313. // }
  4314. //
  4315. // }
  4316. //
  4317. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4318. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4319. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4320. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4321. // if num1 > num2 {
  4322. // num = num1 - num2
  4323. // drug.Total = drug.Total + num
  4324. // service.UpdateBaseDrugLib(&drug)
  4325. // } else if num1 < num2 {
  4326. // num = num2 - num1
  4327. // drug.Total = drug.Total - num
  4328. // service.UpdateBaseDrugLib(&drug)
  4329. // }
  4330. //
  4331. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4332. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4333. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4334. // if hisAdvice.PrescribingNumber > num2 {
  4335. // num = hisAdvice.PrescribingNumber - num2
  4336. // drug.Total = drug.Total + num
  4337. // service.UpdateBaseDrugLib(&drug)
  4338. // } else if num2 < advice.PrescribingNumber {
  4339. // num = num2 - hisAdvice.PrescribingNumber
  4340. // drug.Total = drug.Total - num
  4341. // service.UpdateBaseDrugLib(&drug)
  4342. // }
  4343. //
  4344. // }
  4345. // }
  4346. // }
  4347. //}
  4348. //
  4349. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4350. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4351. // advice.ExecutionTime = execution_time
  4352. //}
  4353. //
  4354. //
  4355. //
  4356. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4357. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4358. // advice.ExecutionStaff = execution_staff
  4359. //}
  4360. //
  4361. //
  4362. //
  4363. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4364. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4365. // advice.ExecutionState = execution_state
  4366. //}
  4367. //
  4368. //
  4369. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4370. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4371. // advice.CheckTime = check_time
  4372. //}
  4373. //
  4374. //
  4375. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4376. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4377. // advice.CheckState = check_state
  4378. //}
  4379. //
  4380. //
  4381. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4382. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4383. // advice.Checker = checker
  4384. //}
  4385. //
  4386. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4387. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4388. // advice.StartTime = start_time
  4389. //}
  4390. return 0
  4391. }
  4392. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4393. project.ExecutionStaff = 0
  4394. project.ExecutionState = 2
  4395. project.ExecutionTime = 0
  4396. project.Checker = 0
  4397. project.CheckState = 2
  4398. project.CheckTime = 0
  4399. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4400. id := int64(json["id"].(float64))
  4401. project.ID = id
  4402. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4403. project.ExecutionStaff = temp_project.ExecutionStaff
  4404. project.ExecutionState = temp_project.ExecutionState
  4405. project.ExecutionTime = temp_project.ExecutionTime
  4406. project.Checker = temp_project.Checker
  4407. project.CheckState = temp_project.CheckState
  4408. project.CheckTime = temp_project.CheckTime
  4409. project.TeamId = temp_project.TeamId
  4410. }
  4411. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4412. types := int64(json["type"].(float64))
  4413. project.Type = types
  4414. }
  4415. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4416. project_id := int64(json["project_id"].(float64))
  4417. project.ProjectId = project_id
  4418. }
  4419. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4420. team_id := int64(json["team_id"].(float64))
  4421. project.TeamId = team_id
  4422. }
  4423. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4424. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4425. project.Price = price
  4426. }
  4427. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4428. total, _ := json["total"].(string)
  4429. //totals, _ := strconv.ParseInt(total, 10, 64)
  4430. project.Count = total
  4431. }
  4432. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4433. medical_code, _ := json["medical_code"].(string)
  4434. project.MedListCodg = medical_code
  4435. }
  4436. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4437. single_dose, _ := json["single_dose"].(string)
  4438. project.SingleDose = single_dose
  4439. }
  4440. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4441. delivery_way, _ := json["delivery_way"].(string)
  4442. project.DeliveryWay = delivery_way
  4443. }
  4444. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4445. execution_frequency, _ := json["execution_frequency"].(string)
  4446. project.ExecutionFrequency = execution_frequency
  4447. }
  4448. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4449. remark, _ := json["remark"].(string)
  4450. project.Remark = remark
  4451. }
  4452. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4453. day, _ := json["number_days"].(string)
  4454. project.Day = day
  4455. }
  4456. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4457. unit, _ := json["unit"].(string)
  4458. project.Unit = unit
  4459. }
  4460. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4461. // frequency_type := int64(json["frequency_type"].(float64))
  4462. // project.FrequencyType = frequency_type
  4463. //}
  4464. //
  4465. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4466. // day_count := int64(json["day_count"].(float64))
  4467. // project.DayCount = day_count
  4468. //}
  4469. //
  4470. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4471. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4472. // week_day, _ := json["week_day"].(string)
  4473. // project.WeekDay = week_day
  4474. //}
  4475. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  4476. //
  4477. //if project.ID == 0 {
  4478. // if stockConfig.IsOpen == 1 {
  4479. // if project.Type == 3 {
  4480. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4481. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  4482. // good.Total = good.Total - f_count
  4483. // service.UpdateGoodInfo(&good)
  4484. // }
  4485. // }
  4486. //
  4487. //} else {
  4488. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  4489. //
  4490. // if stockConfig.IsOpen == 1 {
  4491. // if project.Type == 3 {
  4492. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4493. // if project.Count < temp_project.Count {
  4494. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4495. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4496. //
  4497. // other_count := f_count_two - f_count_one
  4498. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4499. // good.Total = good.Total + other_count_two
  4500. // service.UpdateGoodInfo(&good)
  4501. // } else if project.Count > temp_project.Count {
  4502. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4503. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4504. //
  4505. // other_count := f_count_one - f_count_two
  4506. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4507. // good.Total = good.Total - other_count_two
  4508. // service.UpdateGoodInfo(&good)
  4509. // }
  4510. //
  4511. // }
  4512. // }
  4513. //
  4514. //}
  4515. return 0
  4516. }
  4517. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4518. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4519. id := int64(json["id"].(float64))
  4520. additionalCharge.ID = id
  4521. }
  4522. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4523. item_id := int64(json["item_id"].(float64))
  4524. additionalCharge.ItemId = item_id
  4525. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4526. if config.ID > 0 {
  4527. if len(config.Code) > 0 {
  4528. additionalCharge.MedListCodg = config.Code
  4529. }
  4530. }
  4531. }
  4532. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4533. // price := int64(json["price"].(float64))
  4534. // formatInt_price := strconv.FormatInt(price, 10)
  4535. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4536. // additionalCharge.Price = float_price
  4537. // }
  4538. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4539. // price := int64(json["price"].(float64))
  4540. // formatInt_price := strconv.FormatInt(price, 10)
  4541. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4542. // additionalCharge.Price = float_price
  4543. //}
  4544. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4545. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4546. additionalCharge.Price = price
  4547. }
  4548. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4549. count, _ := json["count"].(string)
  4550. counts, _ := strconv.ParseInt(count, 10, 64)
  4551. additionalCharge.Count = counts
  4552. }
  4553. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4554. item_name, _ := json["item_name"].(string)
  4555. additionalCharge.ItemName = item_name
  4556. }
  4557. return 0
  4558. }
  4559. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  4560. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4561. utils.ErrorLog("drug_name")
  4562. return enums.ErrorCodeParamWrong
  4563. }
  4564. adviceName, _ := json["drug_name"].(string)
  4565. if len(adviceName) == 0 {
  4566. utils.ErrorLog("len(advice_name) == 0")
  4567. return enums.ErrorCodeParamWrong
  4568. }
  4569. advice.AdviceName = adviceName
  4570. adviceDesc, _ := json["advice_desc"].(string)
  4571. advice.AdviceDesc = adviceDesc
  4572. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4573. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4574. advice.DrugSpec = drugSpec
  4575. }
  4576. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4577. remark, _ := json["remark"].(string)
  4578. advice.Remark = remark
  4579. }
  4580. if json["id"] == nil {
  4581. advice.DrugId = 0
  4582. } else {
  4583. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4584. drug_id := int64(json["id"].(float64))
  4585. advice.DrugId = drug_id
  4586. }
  4587. }
  4588. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4589. drugSpecUnit, _ := json["min_unit"].(string)
  4590. advice.DrugSpecUnit = drugSpecUnit
  4591. }
  4592. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4593. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4594. advice.SingleDose = singleDose
  4595. }
  4596. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4597. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4598. advice.SingleDoseUnit = singleDoseUnit
  4599. }
  4600. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4601. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4602. advice.PrescribingNumber = prescribingNumber
  4603. }
  4604. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4605. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4606. advice.PrescribingNumberUnit = prescribingNumberUnit
  4607. }
  4608. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4609. deliveryWay, _ := json["delivery_way"].(string)
  4610. advice.DeliveryWay = deliveryWay
  4611. }
  4612. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4613. executionFrequency, _ := json["execution_frequency"].(string)
  4614. advice.ExecutionFrequency = executionFrequency
  4615. }
  4616. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4617. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4618. advice.Price = price
  4619. }
  4620. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4621. med_list_codg, _ := json["medical_insurance_number"].(string)
  4622. advice.MedListCodg = med_list_codg
  4623. }
  4624. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4625. day := int64(json["day"].(float64))
  4626. advice.Day = day
  4627. }
  4628. return 0
  4629. }
  4630. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  4631. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4632. types := int64(json["type"].(float64))
  4633. project.Type = types
  4634. }
  4635. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4636. project_id := int64(json["project_id"].(float64))
  4637. project.ProjectId = project_id
  4638. }
  4639. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4640. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4641. project.Price = price
  4642. }
  4643. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4644. total, _ := json["total"].(string)
  4645. //totals, _ := strconv.ParseInt(total, 10, 64)
  4646. project.Count = total
  4647. }
  4648. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4649. medical_code, _ := json["medical_code"].(string)
  4650. project.MedListCodg = medical_code
  4651. }
  4652. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4653. single_dose, _ := json["single_dose"].(string)
  4654. project.SingleDose = single_dose
  4655. }
  4656. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4657. delivery_way, _ := json["delivery_way"].(string)
  4658. project.DeliveryWay = delivery_way
  4659. }
  4660. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4661. execution_frequency, _ := json["execution_frequency"].(string)
  4662. project.ExecutionFrequency = execution_frequency
  4663. }
  4664. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4665. remark, _ := json["remark"].(string)
  4666. project.Remark = remark
  4667. }
  4668. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4669. day, _ := json["number_days"].(string)
  4670. project.Day = day
  4671. }
  4672. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4673. unit, _ := json["unit"].(string)
  4674. project.Unit = unit
  4675. }
  4676. return 0
  4677. }
  4678. func (c *HisApiController) GetHisOrderList() {
  4679. page, _ := c.GetInt64("page", -1)
  4680. limit, _ := c.GetInt64("limit", -1)
  4681. start_time := c.GetString("start_time")
  4682. end_time := c.GetString("end_time")
  4683. types, _ := c.GetInt64("type", 0)
  4684. keywords := c.GetString("keywords")
  4685. p_type, _ := c.GetInt64("p_type", 0)
  4686. sort_type, _ := c.GetInt64("sort_type", 0)
  4687. charge_type, _ := c.GetInt64("charge_type", 0)
  4688. timeLayout := "2006-01-02"
  4689. loc, _ := time.LoadLocation("Local")
  4690. var startTime int64
  4691. if len(start_time) > 0 {
  4692. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4693. if err != nil {
  4694. //fmt.Println(err)
  4695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4696. return
  4697. }
  4698. startTime = theTime.Unix()
  4699. }
  4700. var endTime int64
  4701. if len(end_time) > 0 {
  4702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4703. if err != nil {
  4704. utils.ErrorLog(err.Error())
  4705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4706. return
  4707. }
  4708. endTime = theTime.Unix()
  4709. }
  4710. adminUser := c.GetAdminUserInfo()
  4711. org_id := adminUser.CurrentOrgId
  4712. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  4713. for _, item := range order {
  4714. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  4715. item.DoctorName = info.Doctor
  4716. item.DepartmentName = info.XtHisDepartment.Name
  4717. }
  4718. if err == nil {
  4719. c.ServeSuccessJSON(map[string]interface{}{
  4720. "order": order,
  4721. "total": total,
  4722. })
  4723. } else {
  4724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4725. return
  4726. }
  4727. }
  4728. func (c *HisApiController) GetHisOrder() {
  4729. patient_id, _ := c.GetInt64("patient_id", 0)
  4730. number := c.GetString("number")
  4731. adminInfo := c.GetAdminUserInfo()
  4732. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  4733. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  4734. if err == nil {
  4735. c.ServeSuccessJSON(map[string]interface{}{
  4736. "order": order,
  4737. "prescription": prescriptions,
  4738. })
  4739. } else {
  4740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4741. return
  4742. }
  4743. }
  4744. func (c *HisApiController) GetHisPrescriptionList() {
  4745. record_date := c.GetString("record_date")
  4746. keywords := c.GetString("keywords")
  4747. page, _ := c.GetInt64("page")
  4748. limit, _ := c.GetInt64("limit")
  4749. timeLayout := "2006-01-02"
  4750. loc, _ := time.LoadLocation("Local")
  4751. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4752. if err != nil {
  4753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4754. return
  4755. }
  4756. recordDateTime := theTime.Unix()
  4757. adminInfo := c.GetAdminUserInfo()
  4758. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  4759. //adminInfo := c.GetAdminUserInfo()
  4760. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  4761. //fmt.Println(prescriptionOrder)
  4762. if err == nil {
  4763. c.ServeSuccessJSON(map[string]interface{}{
  4764. "order": prescriptionOrder,
  4765. "total": total,
  4766. })
  4767. } else {
  4768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4769. return
  4770. }
  4771. }
  4772. func (c *HisApiController) GetHisPrescriptionInfo() {
  4773. id, _ := c.GetInt64("id")
  4774. adminInfo := c.GetAdminUserInfo()
  4775. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  4776. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  4777. if err == nil {
  4778. c.ServeSuccessJSON(map[string]interface{}{
  4779. "order": prescriptionOrder,
  4780. "prescription": prescription,
  4781. })
  4782. } else {
  4783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4784. return
  4785. }
  4786. }
  4787. func (c *HisApiController) GetMedicalInsuranceConfig() {
  4788. adminUser := c.GetAdminUserInfo()
  4789. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4790. c.ServeSuccessJSON(map[string]interface{}{
  4791. "config": config,
  4792. })
  4793. }
  4794. type ResultTwo struct {
  4795. ErrMsg interface{} `json:"err_msg"`
  4796. InfRefmsgid string `json:"inf_refmsgid"`
  4797. Infcode int64 `json:"infcode"`
  4798. Output struct {
  4799. Baseinfo struct {
  4800. Age float64 `json:"age"`
  4801. Brdy string `json:"brdy"`
  4802. Certno string `json:"certno"`
  4803. Gend string `json:"gend"`
  4804. Naty string `json:"naty"`
  4805. PsnCertType string `json:"psn_cert_type"`
  4806. PsnName string `json:"psn_name"`
  4807. PsnNo string `json:"psn_no"`
  4808. } `json:"baseinfo"`
  4809. Idetinfo []interface{} `json:"idetinfo"`
  4810. Iinfo []struct {
  4811. Balc float64 `json:"balc"`
  4812. CvlservFlag string `json:"cvlserv_flag"`
  4813. EmpName string `json:"emp_name"`
  4814. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  4815. Insutype string `json:"insutype"`
  4816. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  4817. PausInsuDate interface{} `json:"paus_insu_date"`
  4818. PsnInsuDate string `json:"psn_insu_date"`
  4819. PsnInsuStas string `json:"psn_insu_stas"`
  4820. PsnType string `json:"psn_type"`
  4821. } `json:"insuinfo"`
  4822. } `json:"output"`
  4823. RefmsgTime string `json:"refmsg_time"`
  4824. RespondTime string `json:"respond_time"`
  4825. Signtype interface{} `json:"signtype"`
  4826. WarnInfo interface{} `json:"warn_info"`
  4827. }
  4828. type ResultThree struct {
  4829. Cainfo interface{} `json:"cainfo"`
  4830. ErrMsg interface{} `json:"err_msg"`
  4831. InfRefmsgid string `json:"inf_refmsgid"`
  4832. Infcode int64 `json:"infcode"`
  4833. Output struct {
  4834. Data struct {
  4835. IptOtpNo string `json:"ipt_otp_no"`
  4836. MdtrtID string `json:"mdtrt_id"`
  4837. PsnNo string `json:"psn_no"`
  4838. } `json:"data"`
  4839. } `json:"output"`
  4840. RefmsgTime string `json:"refmsg_time"`
  4841. RespondTime string `json:"respond_time"`
  4842. Signtype interface{} `json:"signtype"`
  4843. WarnMsg interface{} `json:"warn_msg"`
  4844. }
  4845. type ResultFour struct {
  4846. Cainfo string `json:"cainfo"`
  4847. ErrMsg string `json:"err_msg"`
  4848. InfRefmsgid string `json:"inf_refmsgid"`
  4849. Infcode int64 `json:"infcode"`
  4850. Output struct {
  4851. Result []struct {
  4852. BasMednFlag string `json:"bas_medn_flag"`
  4853. ChldMedcFlag string `json:"chld_medc_flag"`
  4854. ChrgitmLv string `json:"chrgitm_lv"`
  4855. Cnt float64 `json:"cnt"`
  4856. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  4857. DrtReimFlag string `json:"drt_reim_flag"`
  4858. FeedetlSn string `json:"feedetl_sn"`
  4859. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4860. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  4861. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4862. ListSpItemFlag string `json:"list_sp_item_flag"`
  4863. LmtUsedFlag string `json:"lmt_used_flag"`
  4864. MedChrgitmType string `json:"med_chrgitm_type"`
  4865. Memo string `json:"memo"`
  4866. OverlmtAmt float64 `json:"overlmt_amt"`
  4867. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4868. Pric float64 `json:"pric"`
  4869. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  4870. SelfpayProp float64 `json:"selfpay_prop"`
  4871. } `json:"result"`
  4872. } `json:"output"`
  4873. RefmsgTime string `json:"refmsg_time"`
  4874. RespondTime string `json:"respond_time"`
  4875. Signtype string `json:"signtype"`
  4876. WarnMsg string `json:"warn_msg"`
  4877. }
  4878. type ResultFive struct {
  4879. Insutype string `json:"insutype"`
  4880. }
  4881. type ResultSix struct {
  4882. Cainfo interface{} `json:"cainfo"`
  4883. ErrMsg interface{} `json:"err_msg"`
  4884. InfRefmsgid string `json:"inf_refmsgid"`
  4885. Infcode int64 `json:"infcode"`
  4886. Output struct {
  4887. } `json:"output"`
  4888. RefmsgTime string `json:"refmsg_time"`
  4889. RespondTime string `json:"respond_time"`
  4890. Signtype interface{} `json:"signtype"`
  4891. WarnMsg interface{} `json:"warn_msg"`
  4892. }
  4893. type ResultSeven struct {
  4894. Cainfo string `json:"cainfo"`
  4895. ErrMsg string `json:"err_msg"`
  4896. InfRefmsgid string `json:"inf_refmsgid"`
  4897. Infcode int64 `json:"infcode"`
  4898. Output struct {
  4899. Setldetail []interface{} `json:"setldetail"`
  4900. Setlinfo struct {
  4901. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4902. AcctPay float64 `json:"acct_pay"`
  4903. ActPayDedc float64 `json:"act_pay_dedc"`
  4904. Age float64 `json:"age"`
  4905. Balc float64 `json:"balc"`
  4906. Brdy string `json:"brdy"`
  4907. Certno string `json:"certno"`
  4908. ClrOptins string `json:"clr_optins"`
  4909. ClrType string `json:"clr_type"`
  4910. ClrWay string `json:"clr_way"`
  4911. CvlservFlag string `json:"cvlserv_flag"`
  4912. CvlservPay float64 `json:"cvlserv_pay"`
  4913. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4914. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4915. Gend string `json:"gend"`
  4916. HifesPay float64 `json:"hifes_pay"`
  4917. HifmiPay float64 `json:"hifmi_pay"`
  4918. HifobPay float64 `json:"hifob_pay"`
  4919. HifpPay float64 `json:"hifp_pay"`
  4920. HospPartAmt float64 `json:"hosp_part_amt"`
  4921. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4922. Insutype string `json:"insutype"`
  4923. MafPay float64 `json:"maf_pay"`
  4924. MdtrtCertType string `json:"mdtrt_cert_type"`
  4925. MdtrtID string `json:"mdtrt_id"`
  4926. MedType string `json:"med_type"`
  4927. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4928. MedinsSetlID string `json:"medins_setl_id"`
  4929. Naty string `json:"naty"`
  4930. OthPay float64 `json:"oth_pay"`
  4931. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4932. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4933. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4934. PsnCashPay float64 `json:"psn_cash_pay"`
  4935. PsnCertType string `json:"psn_cert_type"`
  4936. PsnName string `json:"psn_name"`
  4937. PsnNo string `json:"psn_no"`
  4938. PsnPartAmt float64 `json:"psn_part_amt"`
  4939. PsnType string `json:"psn_type"`
  4940. SetlID string `json:"setl_id"`
  4941. SetlTime string `json:"setl_time"`
  4942. } `json:"setlinfo"`
  4943. } `json:"output"`
  4944. RefmsgTime string `json:"refmsg_time"`
  4945. RespondTime string `json:"respond_time"`
  4946. Signtype interface{} `json:"signtype"`
  4947. WarnMsg interface{} `json:"warn_msg"`
  4948. }
  4949. type ResultEight struct {
  4950. Cainfo string `json:"cainfo"`
  4951. ErrMsg string `json:"err_msg"`
  4952. InfRefmsgid string `json:"inf_refmsgid"`
  4953. Infcode int64 `json:"infcode"`
  4954. Output struct {
  4955. Stmtinfo struct {
  4956. SetlOptins string `json:"setl_optins"`
  4957. StmtRslt string `json:"stmt_rslt"`
  4958. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4959. } `json:"stmtinfo"`
  4960. } `json:"output"`
  4961. RefmsgTime string `json:"refmsg_time"`
  4962. RespondTime string `json:"respond_time"`
  4963. Signtype interface{} `json:"signtype"`
  4964. WarnMsg interface{} `json:"warn_msg"`
  4965. }
  4966. type ResultNine struct {
  4967. Cainfo string `json:"cainfo"`
  4968. ErrMsg string `json:"err_msg"`
  4969. InfRefmsgid string `json:"inf_refmsgid"`
  4970. Infcode int64 `json:"infcode"`
  4971. Output struct {
  4972. FileQuryNo string `json:"file_qury_no"`
  4973. } `json:"output"`
  4974. RefmsgTime string `json:"refmsg_time"`
  4975. RespondTime string `json:"respond_time"`
  4976. Signtype interface{} `json:"signtype"`
  4977. WarnMsg interface{} `json:"warn_msg"`
  4978. }
  4979. type ResultTen struct {
  4980. Cainfo string `json:"cainfo"`
  4981. ErrMsg string `json:"err_msg"`
  4982. InfRefmsgid string `json:"inf_refmsgid"`
  4983. Infcode int64 `json:"infcode"`
  4984. Output struct {
  4985. DldEndtime string `json:"dld_endtime"`
  4986. FileQuryNo string `json:"file_qury_no"`
  4987. Filename string `json:"filename"`
  4988. } `json:"output"`
  4989. RefmsgTime string `json:"refmsg_time"`
  4990. RespondTime string `json:"respond_time"`
  4991. Signtype interface{} `json:"signtype"`
  4992. WarnMsg interface{} `json:"warn_msg"`
  4993. }
  4994. type ResultEleven struct {
  4995. Cainfo string `json:"cainfo"`
  4996. ErrMsg string `json:"err_msg"`
  4997. InfRefmsgid string `json:"inf_refmsgid"`
  4998. Infcode int64 `json:"infcode"`
  4999. Output struct {
  5000. Setlinfo struct {
  5001. FixmedinsName string `json:"fixmedins_name"`
  5002. FixmedinsCode string `json:"fixmedins_code"`
  5003. PsnNo string `json:"psn_no"`
  5004. PsnName string `json:"psn_name"`
  5005. HifobPay float64 `json:"hifob_pay"`
  5006. Gend string `json:"gend"`
  5007. Brdy string `json:"brdy"`
  5008. PsnCertType string `json:"psn_cert_type"`
  5009. PsnType string `json:"psn_type"`
  5010. EmpName string `json:"emp_name"`
  5011. Certno string `json:"certno"`
  5012. Insutype string `json:"insutype"`
  5013. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5014. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5015. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5016. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5017. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5018. ActPayDedc float64 `json:"act_pay_dedc"`
  5019. HifpPay float64 `json:"hifp_pay"`
  5020. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5021. CvlservPay float64 `json:"cvlserv_pay"`
  5022. HifesPay float64 `json:"hifes_pay"`
  5023. HifmiPay float64 `json:"hifmi_pay"`
  5024. MafPay float64 `json:"maf_pay"`
  5025. OthPay float64 `json:"oth_pay"`
  5026. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5027. PsnPay float64 `json:"psn_pay"`
  5028. AcctPay float64 `json:"acct_pay"`
  5029. CashPayamt float64 `json:"cash_payamt"`
  5030. Balc float64 `json:"balc"`
  5031. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5032. MedinsSetlId string `json:"medins_setl_id"`
  5033. RefdSetlFlag string `json:"refd_setl_flag"`
  5034. SetlTime string `json:"setl_time"`
  5035. MedType string `json:"med_type"`
  5036. } `json:"setlinfo"`
  5037. } `json:"output"`
  5038. RefmsgTime string `json:"refmsg_time"`
  5039. RespondTime string `json:"respond_time"`
  5040. Signtype interface{} `json:"signtype"`
  5041. WarnMsg interface{} `json:"warn_msg"`
  5042. }
  5043. type Custom struct {
  5044. DetItemFeeSumamt string
  5045. Cut string
  5046. FeedetlSn string
  5047. Price string
  5048. MedListCodg string
  5049. Type int64
  5050. AdviceId int64
  5051. ProjectId int64
  5052. ItemId int64
  5053. }
  5054. //获取个人信息----挂号-----上传就诊信息
  5055. func (c *HisApiController) GetRegisterInfo() {
  5056. id, _ := c.GetInt64("id")
  5057. record_time := c.GetString("record_time")
  5058. settlementValue, _ := c.GetInt64("settlement_value")
  5059. medical_insurance_card := c.GetString("medical_insurance_card")
  5060. name := c.GetString("name")
  5061. id_card_type, _ := c.GetInt64("id_card_type")
  5062. certificates, _ := c.GetInt64("certificates")
  5063. medical_care, _ := c.GetInt64("medical_care")
  5064. birthday := c.GetString("birthday")
  5065. age, _ := c.GetInt64("age")
  5066. id_card := c.GetString("id_card")
  5067. register_type, _ := c.GetInt64("register")
  5068. doctor, _ := c.GetInt64("doctor")
  5069. department, _ := c.GetInt64("department")
  5070. gender, _ := c.GetInt64("sex")
  5071. phone := c.GetString("phone")
  5072. registration_fee, _ := c.GetFloat("registration_fee")
  5073. medical_expenses, _ := c.GetFloat("medical_expenses")
  5074. social_type, _ := c.GetInt64("social_type")
  5075. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5076. diagnosis_ids := c.GetString("diagnosis")
  5077. sick_type, _ := c.GetInt64("sick_type")
  5078. reg_type := c.GetString("p_type")
  5079. timeLayout := "2006-01-02"
  5080. loc, _ := time.LoadLocation("Local")
  5081. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5082. birthUnix := birthdays.Unix()
  5083. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5084. if err != nil {
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5086. return
  5087. }
  5088. recordDateTime := theTime.Unix()
  5089. adminInfo := c.GetAdminUserInfo()
  5090. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5091. if tempPatient.ID == 0 {
  5092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5093. return
  5094. }
  5095. var patient service.Patients
  5096. if id == 0 {
  5097. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5098. } else {
  5099. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5100. }
  5101. if patient.ID == 0 {
  5102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5103. return
  5104. }
  5105. if len(patient.IdCardNo) == 0 {
  5106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5107. return
  5108. }
  5109. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5110. if len(his) >= 1 {
  5111. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5112. if len(his) >= 1 && order.ID == 0 {
  5113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5114. return
  5115. }
  5116. }
  5117. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5118. fmt.Println(timeStr)
  5119. timeArr := strings.Split(timeStr, " ")
  5120. fmt.Println(timeArr)
  5121. timeArrTwo := strings.Split(timeArr[0], "-")
  5122. timeArrThree := strings.Split(timeArr[1], ":")
  5123. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5124. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5125. if len(lists) == 0 {
  5126. var hisPatient models.XtHisPatient
  5127. hisPatient = models.XtHisPatient{
  5128. Name: name,
  5129. Age: age,
  5130. Gender: gender,
  5131. Birthday: birthUnix,
  5132. Phone: phone,
  5133. MedicalTreatmentType: medical_care,
  5134. IdType: certificates,
  5135. IdCardNo: id_card,
  5136. BalanceAccountsType: settlementValue,
  5137. SocialType: social_type,
  5138. MedicalInsuranceNumber: medical_insurance_card,
  5139. RegisterType: register_type,
  5140. RegisterCost: registration_fee,
  5141. TreatmentCost: medical_expenses,
  5142. AdminUserId: adminInfo.AdminUser.Id,
  5143. UserOrgId: adminInfo.CurrentOrgId,
  5144. Status: 1,
  5145. RecordDate: recordDateTime,
  5146. IsReturn: 1,
  5147. PatientId: patient.ID,
  5148. Ctime: time.Now().Unix(),
  5149. Mtime: time.Now().Unix(),
  5150. Number: str,
  5151. IdCardType: id_card_type,
  5152. Departments: department,
  5153. Doctor: doctor,
  5154. PType: reg_type,
  5155. Diagnosis: diagnosis_ids,
  5156. SickType: sick_type,
  5157. }
  5158. service.CreateHisPatient(&hisPatient)
  5159. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5160. c.ServeSuccessJSON(map[string]interface{}{
  5161. "his_info": hisPatient,
  5162. })
  5163. } else {
  5164. //chrgBchno := rand.Intn(1000000) + 10000
  5165. var hisPatient models.XtHisPatient
  5166. hisPatient = models.XtHisPatient{
  5167. Name: name,
  5168. Age: age,
  5169. Gender: gender,
  5170. Birthday: birthUnix,
  5171. Phone: phone,
  5172. MedicalTreatmentType: medical_care,
  5173. IdType: certificates,
  5174. IdCardNo: id_card,
  5175. BalanceAccountsType: settlementValue,
  5176. SocialType: social_type,
  5177. MedicalInsuranceNumber: medical_insurance_card,
  5178. RegisterType: register_type,
  5179. RegisterCost: registration_fee,
  5180. TreatmentCost: medical_expenses,
  5181. AdminUserId: adminInfo.AdminUser.Id,
  5182. UserOrgId: adminInfo.CurrentOrgId,
  5183. Status: 1,
  5184. RecordDate: recordDateTime,
  5185. IsReturn: 1,
  5186. PatientId: patient.ID,
  5187. Ctime: time.Now().Unix(),
  5188. Mtime: time.Now().Unix(),
  5189. Number: str,
  5190. IdCardType: id_card_type,
  5191. Departments: department,
  5192. Doctor: doctor,
  5193. PType: reg_type,
  5194. Diagnosis: diagnosis_ids,
  5195. SickType: sick_type,
  5196. }
  5197. service.CreateHisPatient(&hisPatient)
  5198. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5199. c.ServeSuccessJSON(map[string]interface{}{
  5200. "his_info": hisPatient,
  5201. })
  5202. }
  5203. }
  5204. //上传明细----结算
  5205. func (c *HisApiController) GetUploadInfo() {
  5206. id, _ := c.GetInt64("id")
  5207. record_time := c.GetString("record_time")
  5208. his_patient_id, _ := c.GetInt64("his_patient_id")
  5209. pay_way, _ := c.GetInt64("pay_way")
  5210. pay_price, _ := c.GetFloat("pay_price")
  5211. pay_card_no := c.GetString("pay_card_no")
  5212. discount_price, _ := c.GetFloat("discount_price")
  5213. preferential_price, _ := c.GetFloat("preferential_price")
  5214. reality_price, _ := c.GetFloat("reality_price")
  5215. found_price, _ := c.GetFloat("found_price")
  5216. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5217. private_price, _ := c.GetFloat("private_price")
  5218. timeLayout := "2006-01-02"
  5219. loc, _ := time.LoadLocation("Local")
  5220. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5221. fapiao_code := c.GetString("fapiao_code")
  5222. fapiao_number := c.GetString("fapiao_number")
  5223. diagnosis_id := c.GetString("diagnosis")
  5224. sick_type, _ := c.GetInt64("sick_type")
  5225. reg_type, _ := c.GetInt64("p_type")
  5226. order_id, _ := c.GetInt64("order_id")
  5227. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5228. tmp_decimal := c.GetString("tmp_decimal")
  5229. var decimal float64 //本次使用的押金
  5230. var errmsg error
  5231. tx := service.XTWriteDB().Begin() //开了事务
  5232. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5233. defer func() {
  5234. if errmsg != nil {
  5235. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5236. tx.Rollback()
  5237. } else {
  5238. tx.Commit()
  5239. }
  5240. }()
  5241. fmt.Println("dec_way", dec_way)
  5242. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5243. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5244. return
  5245. }
  5246. if len(tmp_decimal) > 0 {
  5247. if tmp_decimal[0] == 45 {
  5248. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5249. return
  5250. }
  5251. }
  5252. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5253. fmt.Println(errs)
  5254. //if errs != nil {
  5255. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5256. // return
  5257. //}
  5258. decimal = tt
  5259. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5260. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5261. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5262. if err != nil {
  5263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5264. return
  5265. }
  5266. recordDateTime := theTime.Unix()
  5267. adminUser := c.GetAdminUserInfo()
  5268. var prescriptions []*models.HisPrescription
  5269. var prescriptionsOne []*models.HisPrescription
  5270. var start_time int64
  5271. var end_time int64
  5272. ids_str := c.GetString("ids")
  5273. ids_arr := strings.Split(ids_str, ",")
  5274. if tempOrder.ID == 0 {
  5275. if settle_accounts_type == 1 { //日结
  5276. fmt.Println(reg_type)
  5277. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5278. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5279. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5280. } else {
  5281. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5282. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5283. }
  5284. } else { //月结
  5285. start_time_str := c.GetString("start_time")
  5286. end_time_str := c.GetString("end_time")
  5287. timeLayout := "2006-01-02"
  5288. loc, _ := time.LoadLocation("Local")
  5289. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5290. if err != nil {
  5291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5292. return
  5293. }
  5294. recordStartTime := theStartTime.Unix()
  5295. start_time = recordStartTime
  5296. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5297. if err != nil {
  5298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5299. return
  5300. }
  5301. recordEndTime := theEndTime.Unix()
  5302. end_time = recordEndTime
  5303. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5304. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5305. }
  5306. var goods []*models.DialysisBeforePrepareGoods
  5307. var newGoods []*models.NewDialysisBeforePrepareGoods
  5308. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5309. var infos []*models.HisDoctorAdviceInfo
  5310. var infoList []*models.HisDoctorAdviceInfo
  5311. var hisAdvice []*models.HisDoctorAdviceInfo
  5312. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5313. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5314. //判断库存不足
  5315. //结算出库开关
  5316. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5317. if settConfig.IsOpen == 1 {
  5318. //判断库存的地方
  5319. for _, info := range prescriptions {
  5320. if info.Type == 1 {
  5321. infos = append(infos, info.HisDoctorAdviceInfo...)
  5322. }
  5323. if info.Type == 2 {
  5324. for _, sumItem := range info.HisPrescriptionProject {
  5325. if sumItem.Type == 3 {
  5326. var good models.DialysisBeforePrepareGoods
  5327. var newGood models.NewDialysisBeforePrepareGoods
  5328. good.GoodId = sumItem.GoodInfo.ID
  5329. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5330. count, _ := strconv.Atoi(sumItem.Count)
  5331. good.Count = int64(count)
  5332. good.StorehouseId = houseConfig.StorehouseOutInfo
  5333. good.ProjectId = sumItem.ID
  5334. goods = append(goods, &good)
  5335. newGood.GoodId = sumItem.GoodInfo.ID
  5336. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5337. count2, _ := strconv.Atoi(sumItem.Count)
  5338. newGood.Count = int64(count2)
  5339. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5340. newGood.ProjectId = sumItem.ID
  5341. newGoods = append(newGoods, &newGood)
  5342. }
  5343. }
  5344. }
  5345. }
  5346. for _, info := range prescriptionsOne {
  5347. if info.Type == 1 {
  5348. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5349. }
  5350. if info.Type == 2 {
  5351. for _, sumItem := range info.HisPrescriptionProject {
  5352. if sumItem.Type == 3 {
  5353. var newGood models.NewDialysisBeforePrepareGoods
  5354. newGood.GoodId = sumItem.GoodInfo.ID
  5355. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5356. count2, _ := strconv.Atoi(sumItem.Count)
  5357. newGood.Count = int64(count2)
  5358. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5359. newGood.ProjectId = sumItem.ID
  5360. newGoodOne = append(newGoodOne, &newGood)
  5361. }
  5362. }
  5363. }
  5364. }
  5365. //判断
  5366. for _, itemOne := range infos {
  5367. for _, itemTwo := range hisAdvice {
  5368. if itemOne.DrugId == itemTwo.DrugId {
  5369. itemTwo.Child = append(itemTwo.Child, itemOne)
  5370. }
  5371. }
  5372. }
  5373. for _, itemTwo := range hisAdvice {
  5374. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5375. var sum_out_count int64
  5376. for _, itemThree := range itemTwo.Child {
  5377. var prescribing_number int64
  5378. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5379. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5380. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5381. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5382. }
  5383. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5384. prescribing_number = parseIntPrescribingNumber
  5385. }
  5386. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5387. prescribing_number = parseIntPrescribingNumber
  5388. }
  5389. sum_out_count += prescribing_number
  5390. }
  5391. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5392. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5393. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5394. if sum_out_count > drugStockOut.FlushCount {
  5395. c.ServeSuccessJSON(map[string]interface{}{
  5396. "msg": "2",
  5397. "drug": medical,
  5398. })
  5399. return
  5400. }
  5401. }
  5402. fmt.Println("newGoods99999988882os", newGoods)
  5403. for _, itemOne := range newGoods {
  5404. for _, item := range newGoodOne {
  5405. if itemOne.GoodId == item.GoodId {
  5406. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5407. }
  5408. }
  5409. }
  5410. for _, item := range newGoodOne {
  5411. var sum_out_count_one int64
  5412. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5413. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5414. sum_out_count_one += itemOne.Count
  5415. }
  5416. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5417. fmt.Println("sum_out_count_one", sum_out_count_one)
  5418. fmt.Println("list.FlushCount", list.FlushCount)
  5419. if sum_out_count_one > list.FlushCount {
  5420. c.ServeSuccessJSON(map[string]interface{}{
  5421. "msg": "3",
  5422. "good": good,
  5423. })
  5424. return
  5425. }
  5426. }
  5427. }
  5428. timestamp := time.Now().Unix()
  5429. tempTime := time.Unix(timestamp, 0)
  5430. timeFormat := tempTime.Format("20060102150405")
  5431. chrgBchno := rand.Intn(100000) + 10000
  5432. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5433. strconv.FormatInt(his.PatientId, 10)
  5434. var ids []int64
  5435. for _, item := range prescriptions {
  5436. ids = append(ids, item.ID)
  5437. }
  5438. var total float64
  5439. for _, item := range prescriptions {
  5440. fmt.Println(item)
  5441. if item.Type == 1 { //药品
  5442. for _, subItem := range item.HisDoctorAdviceInfo {
  5443. total = total + (subItem.Price * subItem.PrescribingNumber)
  5444. }
  5445. }
  5446. if item.Type == 2 { //项目
  5447. for _, subItem := range item.HisPrescriptionProject {
  5448. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5449. total = total + (subItem.Price * cnt)
  5450. }
  5451. }
  5452. for _, subItem := range item.HisAdditionalCharge {
  5453. total = total + (subItem.Price * float64(subItem.Count))
  5454. }
  5455. }
  5456. if reg_type == 1111 || reg_type == 1112 {
  5457. reg_type = 11
  5458. }
  5459. tm := time.Unix(time.Now().Unix(), 0)
  5460. allTotal := fmt.Sprintf("%.4f", total)
  5461. totals, _ := strconv.ParseFloat(allTotal, 64)
  5462. order := &models.HisOrder{
  5463. UserOrgId: adminUser.CurrentOrgId,
  5464. HisPatientId: his.ID,
  5465. PatientId: id,
  5466. SettleAccountsDate: recordDateTime,
  5467. Ctime: time.Now().Unix(),
  5468. Mtime: time.Now().Unix(),
  5469. Status: 1,
  5470. OrderStatus: 2,
  5471. MdtrtId: his.Number,
  5472. Number: chrg_bchno,
  5473. MedfeeSumamt: totals,
  5474. PayWay: pay_way,
  5475. PayPrice: pay_price,
  5476. MedType: strconv.Itoa(int(reg_type)),
  5477. PayCardNo: pay_card_no,
  5478. DiscountPrice: discount_price,
  5479. PreferentialPrice: preferential_price,
  5480. RealityPrice: reality_price,
  5481. FoundPrice: found_price,
  5482. MedicalInsurancePrice: medical_insurance_price,
  5483. PrivatePrice: private_price,
  5484. SettleEndTime: end_time,
  5485. SettleStartTime: start_time,
  5486. PsnPartAmt: totals,
  5487. PsnCashPay: totals,
  5488. SettleType: settle_accounts_type,
  5489. FaPiaoCode: fapiao_code,
  5490. FaPiaoNumber: fapiao_number,
  5491. Diagnosis: diagnosis_id,
  5492. PType: 2,
  5493. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5494. Decimal: decimal,
  5495. }
  5496. err = service.CreateOrderTX(order, tx)
  5497. if err != nil {
  5498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5499. return
  5500. }
  5501. var customs []*Custom
  5502. for _, item := range prescriptions {
  5503. if item.Type == 1 { //药品a
  5504. for _, subItem := range item.HisDoctorAdviceInfo {
  5505. cus := &Custom{
  5506. AdviceId: subItem.ID,
  5507. ProjectId: 0,
  5508. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5509. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5510. FeedetlSn: subItem.FeedetlSn,
  5511. Price: fmt.Sprintf("%.4f", subItem.Price),
  5512. MedListCodg: subItem.MedListCodg,
  5513. Type: 1,
  5514. }
  5515. customs = append(customs, cus)
  5516. }
  5517. }
  5518. if item.Type == 2 { //项目
  5519. for _, subItem := range item.HisPrescriptionProject {
  5520. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5521. cus := &Custom{
  5522. AdviceId: 0,
  5523. ProjectId: subItem.ID,
  5524. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5525. Cut: fmt.Sprintf("%.4f", cnt),
  5526. FeedetlSn: subItem.FeedetlSn,
  5527. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5528. MedListCodg: subItem.MedListCodg,
  5529. Type: 2,
  5530. }
  5531. customs = append(customs, cus)
  5532. }
  5533. }
  5534. for _, item := range item.HisAdditionalCharge {
  5535. cus := &Custom{
  5536. ItemId: item.ID,
  5537. AdviceId: 0,
  5538. ProjectId: 0,
  5539. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5540. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5541. FeedetlSn: item.FeedetlSn,
  5542. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5543. MedListCodg: item.XtHisAddtionConfig.Code,
  5544. Type: 3,
  5545. }
  5546. customs = append(customs, cus)
  5547. }
  5548. }
  5549. for _, item := range customs {
  5550. var advice_id int64 = 0
  5551. var project_id int64 = 0
  5552. var item_id int64 = 0
  5553. var types int64 = 0
  5554. if item.Type == 1 {
  5555. advice_id = item.AdviceId
  5556. project_id = 0
  5557. item_id = 0
  5558. } else if item.Type == 2 {
  5559. advice_id = 0
  5560. item_id = 0
  5561. project_id = item.ProjectId
  5562. } else if item.Type == 3 {
  5563. advice_id = 0
  5564. item_id = item.ItemId
  5565. project_id = 0
  5566. }
  5567. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5568. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5569. pric, _ := strconv.ParseFloat(item.Price, 32)
  5570. info := &models.HisOrderInfo{
  5571. OrderNumber: order.Number,
  5572. UploadDate: time.Now().Unix(),
  5573. AdviceId: advice_id,
  5574. DetItemFeeSumamt: detItemFeeSumamt,
  5575. Cnt: cut,
  5576. Pric: pric,
  5577. PatientId: id,
  5578. Status: 1,
  5579. Mtime: time.Now().Unix(),
  5580. Ctime: time.Now().Unix(),
  5581. UserOrgId: adminUser.CurrentOrgId,
  5582. HisPatientId: his.ID,
  5583. OrderId: order.ID,
  5584. ProjectId: project_id,
  5585. Type: types,
  5586. ItemId: item_id,
  5587. }
  5588. service.CreateOrderInfoTX(info, tx)
  5589. }
  5590. his.Diagnosis = diagnosis_id
  5591. his.SickType = sick_type
  5592. his.RegisterType = reg_type
  5593. his.MedicalTreatmentType = reg_type
  5594. service.UpdataHisPateintTX(&his, tx)
  5595. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5596. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5597. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5598. //判断是否使用了押金
  5599. if dec_way == "true" {
  5600. tmpstring := strconv.FormatInt(order.ID, 10)
  5601. //扣押金
  5602. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5603. order.Decimal = decimal
  5604. service.UpDateOrderTwo(order)
  5605. if errmsg != nil {
  5606. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5607. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5608. return
  5609. }
  5610. }
  5611. if err == nil {
  5612. for _, info := range prescriptions {
  5613. if info.Type == 1 {
  5614. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5615. }
  5616. if info.Type == 2 {
  5617. for _, sumItem := range info.HisPrescriptionProject {
  5618. if sumItem.Type == 3 {
  5619. var good models.DialysisBeforePrepareGoods
  5620. var newGood models.NewDialysisBeforePrepareGoods
  5621. var oldGood models.OldDialysisBeforePrepareGoods
  5622. good.GoodId = sumItem.GoodInfo.ID
  5623. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5624. count, _ := strconv.Atoi(sumItem.Count)
  5625. good.Count = int64(count)
  5626. good.StorehouseId = houseConfig.StorehouseOutInfo
  5627. good.ProjectId = sumItem.ID
  5628. good.PatientId = sumItem.PatientId
  5629. goods = append(goods, &good)
  5630. newGood.GoodId = sumItem.GoodInfo.ID
  5631. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5632. count2, _ := strconv.Atoi(sumItem.Count)
  5633. newGood.Count = int64(count2)
  5634. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5635. newGood.ProjectId = sumItem.ID
  5636. newGood.PatientId = sumItem.HisPatientId
  5637. newGoods = append(newGoods, &newGood)
  5638. oldGood.GoodId = sumItem.GoodInfo.ID
  5639. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5640. count3, _ := strconv.Atoi(sumItem.Count)
  5641. oldGood.Count = int64(count3)
  5642. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5643. oldGood.ProjectId = sumItem.ID
  5644. oldGood.RecordDate = sumItem.RecordDate
  5645. oldGood.PatientId = sumItem.HisPatientId
  5646. oldGoods = append(oldGoods, &oldGood)
  5647. }
  5648. }
  5649. }
  5650. }
  5651. if settConfig.IsOpen == 1 {
  5652. for _, item := range infoList {
  5653. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5654. if medical.IsUse == 2 {
  5655. //药品出库
  5656. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5657. //查询默认仓库
  5658. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5659. //查询默认仓库剩余多少库存
  5660. var sum_count int64
  5661. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5662. for _, its := range stockInfo {
  5663. if its.MaxUnit == medical.MaxUnit {
  5664. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5665. }
  5666. sum_count += its.StockMaxNumber + its.StockMinNumber
  5667. }
  5668. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5669. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5670. }
  5671. }
  5672. orgId := c.GetAdminUserInfo().CurrentOrgId
  5673. if len(oldGoods) > 0 {
  5674. timeStr := time.Now().Format("2006-01-02")
  5675. timeArr := strings.Split(timeStr, "-")
  5676. total, _ := service.FindAllWarehouseOut(orgId)
  5677. total = total + 1
  5678. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5679. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5680. number = number + total
  5681. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5682. operation_time := time.Now().Unix()
  5683. creater := c.GetAdminUserInfo().AdminUser.Id
  5684. //查询默认出库仓库库存
  5685. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5686. recordDateStr := time.Now().Format("2006-01-02")
  5687. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5688. nowtime := recordDate.Unix()
  5689. warehouseOut := models.WarehouseOut{
  5690. WarehouseOutOrderNumber: warehousing_out_order,
  5691. OperationTime: operation_time,
  5692. OrgId: orgId,
  5693. Creater: creater,
  5694. Ctime: time.Now().Unix(),
  5695. Status: 1,
  5696. WarehouseOutTime: nowtime,
  5697. Type: 1,
  5698. StorehouseId: storeConfig.StorehouseOutInfo,
  5699. IsCheck: 1,
  5700. OrderId: order.ID,
  5701. IsSys: 5,
  5702. }
  5703. //查询是否生成出库单
  5704. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5705. if out.ID == 0 {
  5706. service.AddSigleWarehouseOut(&warehouseOut)
  5707. }
  5708. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5709. for _, item := range oldGoods {
  5710. dialyPrepareOne := models.DialysisBeforePrepare{
  5711. GoodTypeId: item.GoodTypeId,
  5712. GoodId: item.GoodId,
  5713. PatientId: his.PatientId,
  5714. RecordDate: item.RecordDate,
  5715. UserOrgId: adminUser.CurrentOrgId,
  5716. Count: item.Count,
  5717. Ctime: time.Now().Unix(),
  5718. Creater: adminUser.AdminUser.Id,
  5719. CommdityCode: item.CommdityCode,
  5720. Status: 1,
  5721. StorehouseId: houseConfig.StorehouseOutInfo,
  5722. }
  5723. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  5724. //非零用
  5725. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  5726. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  5727. //查询剩余库存
  5728. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5729. var sum_count int64
  5730. for _, item := range goodList {
  5731. sum_count += item.StockCount
  5732. }
  5733. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  5734. //耗材
  5735. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  5736. }
  5737. }
  5738. }
  5739. }
  5740. c.ServeSuccessJSON(map[string]interface{}{
  5741. "msg": "结算成功",
  5742. })
  5743. }
  5744. } else {
  5745. if tempOrder.IsPre > 0 {
  5746. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  5747. totals, _ := strconv.ParseFloat(allTotal, 64)
  5748. tempOrder.OrderStatus = 2
  5749. tempOrder.PayWay = pay_way
  5750. tempOrder.PayPrice = pay_price
  5751. tempOrder.PayCardNo = pay_card_no
  5752. tempOrder.DiscountPrice = discount_price
  5753. tempOrder.PreferentialPrice = preferential_price
  5754. tempOrder.RealityPrice = reality_price
  5755. tempOrder.FoundPrice = found_price
  5756. tempOrder.MedicalInsurancePrice = medical_insurance_price
  5757. tempOrder.PrivatePrice = private_price
  5758. tempOrder.FaPiaoCode = fapiao_code
  5759. tempOrder.FaPiaoNumber = fapiao_number
  5760. tempOrder.PType = 2
  5761. tempOrder.MedfeeSumamt = totals
  5762. tempOrder.Diagnosis = diagnosis_id
  5763. err = service.SaveHisOrder(&tempOrder)
  5764. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  5765. if err != nil {
  5766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5767. return
  5768. }
  5769. if err == nil {
  5770. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5771. var goods []*models.DialysisBeforePrepareGoods
  5772. var newGoods []*models.NewDialysisBeforePrepareGoods
  5773. var infos []*models.HisDoctorAdviceInfo
  5774. var hisAdvice []*models.HisDoctorAdviceInfo
  5775. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5776. var infolist []*models.HisDoctorAdviceInfo
  5777. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5778. for _, info := range prescriptions {
  5779. if info.Type == 1 {
  5780. infos = append(infos, info.HisDoctorAdviceInfo...)
  5781. }
  5782. if info.Type == 2 {
  5783. for _, sumItem := range info.HisPrescriptionProject {
  5784. if sumItem.Type == 3 {
  5785. var good models.DialysisBeforePrepareGoods
  5786. var newGood models.NewDialysisBeforePrepareGoods
  5787. good.GoodId = sumItem.GoodInfo.ID
  5788. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5789. count, _ := strconv.Atoi(sumItem.Count)
  5790. good.Count = int64(count)
  5791. good.StorehouseId = houseConfig.StorehouseOutInfo
  5792. good.ProjectId = sumItem.ID
  5793. goods = append(goods, &good)
  5794. newGood.GoodId = sumItem.GoodInfo.ID
  5795. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5796. count2, _ := strconv.Atoi(sumItem.Count)
  5797. newGood.Count = int64(count2)
  5798. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5799. newGood.ProjectId = sumItem.ID
  5800. newGoods = append(newGoods, &newGood)
  5801. }
  5802. }
  5803. }
  5804. }
  5805. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5806. if settConfig.IsOpen == 1 {
  5807. //判断库存的地方
  5808. for _, info := range prescriptions {
  5809. if info.Type == 1 {
  5810. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  5811. }
  5812. if info.Type == 2 {
  5813. for _, sumItem := range info.HisPrescriptionProject {
  5814. if sumItem.Type == 3 {
  5815. var good models.DialysisBeforePrepareGoods
  5816. var newGood models.NewDialysisBeforePrepareGoods
  5817. var oldGood models.OldDialysisBeforePrepareGoods
  5818. good.GoodId = sumItem.GoodInfo.ID
  5819. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5820. count, _ := strconv.Atoi(sumItem.Count)
  5821. good.Count = int64(count)
  5822. good.StorehouseId = houseConfig.StorehouseOutInfo
  5823. good.ProjectId = sumItem.ID
  5824. goods = append(goods, &good)
  5825. newGood.GoodId = sumItem.GoodInfo.ID
  5826. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5827. count2, _ := strconv.Atoi(sumItem.Count)
  5828. newGood.Count = int64(count2)
  5829. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5830. newGood.ProjectId = sumItem.ID
  5831. newGoods = append(newGoods, &newGood)
  5832. oldGood.GoodId = sumItem.GoodInfo.ID
  5833. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5834. count3, _ := strconv.Atoi(sumItem.Count)
  5835. oldGood.Count = int64(count3)
  5836. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5837. oldGood.ProjectId = sumItem.ID
  5838. oldGood.RecordDate = sumItem.RecordDate
  5839. oldGoods = append(oldGoods, &oldGood)
  5840. }
  5841. }
  5842. }
  5843. }
  5844. for _, info := range prescriptionsOne {
  5845. if info.Type == 1 {
  5846. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5847. }
  5848. if info.Type == 2 {
  5849. for _, sumItem := range info.HisPrescriptionProject {
  5850. if sumItem.Type == 3 {
  5851. var newGood models.NewDialysisBeforePrepareGoods
  5852. newGood.GoodId = sumItem.GoodInfo.ID
  5853. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5854. count2, _ := strconv.Atoi(sumItem.Count)
  5855. newGood.Count = int64(count2)
  5856. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5857. newGood.ProjectId = sumItem.ID
  5858. newGoodOne = append(newGoodOne, &newGood)
  5859. }
  5860. }
  5861. }
  5862. }
  5863. //判断
  5864. for _, itemOne := range infos {
  5865. for _, itemTwo := range hisAdvice {
  5866. if itemOne.DrugId == itemTwo.DrugId {
  5867. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  5868. }
  5869. }
  5870. }
  5871. for _, itemTwo := range hisAdvice {
  5872. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5873. var sum_out_count int64
  5874. for _, itemThree := range itemTwo.Child {
  5875. var prescribing_number int64
  5876. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5877. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5878. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5879. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5880. }
  5881. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5882. prescribing_number = parseIntPrescribingNumber
  5883. }
  5884. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5885. prescribing_number = parseIntPrescribingNumber
  5886. }
  5887. sum_out_count += prescribing_number
  5888. }
  5889. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5890. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5891. if sum_out_count > drugStockOut.FlushCount {
  5892. c.ServeSuccessJSON(map[string]interface{}{
  5893. "msg": "2",
  5894. "drug": medical,
  5895. })
  5896. return
  5897. }
  5898. }
  5899. for _, itemOne := range newGoods {
  5900. for _, item := range newGoodOne {
  5901. if itemOne.ProjectId == item.ProjectId {
  5902. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  5903. }
  5904. }
  5905. }
  5906. for _, item := range newGoodOne {
  5907. var sum_out_count_one int64
  5908. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5909. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5910. sum_out_count_one += itemOne.Count
  5911. }
  5912. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5913. fmt.Println("sum_out_count_one", sum_out_count_one)
  5914. fmt.Println("list.FlushCount", list.FlushCount)
  5915. if sum_out_count_one > list.FlushCount {
  5916. c.ServeSuccessJSON(map[string]interface{}{
  5917. "msg": "3",
  5918. "good": good,
  5919. })
  5920. return
  5921. }
  5922. }
  5923. for _, item := range infolist {
  5924. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  5925. }
  5926. for _, item := range oldGoods {
  5927. dialyPrepareOne := models.DialysisBeforePrepare{
  5928. GoodTypeId: item.GoodTypeId,
  5929. GoodId: item.GoodId,
  5930. PatientId: item.PatientId,
  5931. RecordDate: item.RecordDate,
  5932. UserOrgId: item.UserOrgId,
  5933. Count: item.Count,
  5934. Ctime: time.Now().Unix(),
  5935. Creater: adminUser.AdminUser.Id,
  5936. CommdityCode: item.CommdityCode,
  5937. Status: 1,
  5938. StorehouseId: houseConfig.StorehouseOutInfo,
  5939. }
  5940. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5941. }
  5942. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  5943. }
  5944. c.ServeSuccessJSON(map[string]interface{}{
  5945. "msg": "结算成功",
  5946. })
  5947. }
  5948. }
  5949. }
  5950. }
  5951. //退款
  5952. func (c *HisApiController) Refund() {
  5953. order_id, _ := c.GetInt64("order_id")
  5954. order, _ := service.GetHisOrderByID(order_id)
  5955. adminUser := c.GetAdminUserInfo()
  5956. orgid := c.GetAdminUserInfo().CurrentOrgId
  5957. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  5958. if err != nil {
  5959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5960. return
  5961. }
  5962. tmp := strconv.FormatInt(order.ID, 10)
  5963. //当押金不为零时产生退费记录
  5964. if order.Decimal != 0 {
  5965. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  5966. if err != nil {
  5967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5968. return
  5969. }
  5970. }
  5971. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  5972. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  5973. var goods []*models.DialysisBeforePrepareGoods
  5974. var newGoods []*models.NewDialysisBeforePrepareGoods
  5975. var infos []*models.HisDoctorAdviceInfo
  5976. for _, info := range orders {
  5977. if info.AdviceId > 0 && info.ProjectId == 0 {
  5978. infos = append(infos, &info.HisDoctorAdviceInfo)
  5979. }
  5980. if info.ProjectId > 0 && info.AdviceId == 0 {
  5981. if info.HisPrescriptionProject.Type == 3 {
  5982. var good models.DialysisBeforePrepareGoods
  5983. var newGood models.NewDialysisBeforePrepareGoods
  5984. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5985. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5986. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5987. good.Count = int64(count)
  5988. good.StorehouseId = houseConfig.StorehouseOutInfo
  5989. good.ProjectId = info.HisPrescriptionProject.ID
  5990. good.PatientId = info.PatientId
  5991. good.OrderId = order_id
  5992. goods = append(goods, &good)
  5993. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5994. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5995. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5996. newGood.Count = int64(count2)
  5997. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5998. newGood.ProjectId = info.HisPrescriptionProject.ID
  5999. newGood.RecordDate = order.SettleAccountsDate
  6000. newGood.UserOrgId = order.UserOrgId
  6001. newGood.PatientId = info.PatientId
  6002. newGood.OrderId = order_id
  6003. newGoods = append(newGoods, &newGood)
  6004. }
  6005. }
  6006. }
  6007. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6008. if settConfig.IsOpen == 1 {
  6009. for _, item := range infos {
  6010. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6011. }
  6012. for _, item := range newGoods {
  6013. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6014. }
  6015. }
  6016. c.ServeSuccessJSON(map[string]interface{}{
  6017. "msg": "退费成功",
  6018. })
  6019. }
  6020. func (c *HisApiController) RefundNumber() {
  6021. his_patient_id, _ := c.GetInt64("id")
  6022. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6023. info.Status = 0
  6024. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6025. if count > 0 {
  6026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6027. return
  6028. }
  6029. err := service.SaveHisPatient(info)
  6030. if err == nil {
  6031. c.ServeSuccessJSON(map[string]interface{}{
  6032. "msg": "退号成功",
  6033. })
  6034. } else {
  6035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6036. return
  6037. }
  6038. }
  6039. func (this *HisApiController) AdditionalCharge() {
  6040. dataBody := make(map[string]interface{}, 0)
  6041. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6042. fmt.Println(err)
  6043. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6044. patient_id := int64(dataBody["patient_id"].(float64))
  6045. medicineData, _ := dataBody["medicineData"].([]interface{})
  6046. adminUserInfo := this.GetAdminUserInfo()
  6047. orgId := adminUserInfo.CurrentOrgId
  6048. admin_user_id := adminUserInfo.AdminUser.Id
  6049. timeStr := time.Now().Format("2006-01-02")
  6050. timeLayout := "2006-01-02 15:04:05"
  6051. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6052. timenow := timeStringToTime.Unix()
  6053. var additionalCharges []*models.HisAdditionalCharge
  6054. for _, item := range medicineData {
  6055. var randNum int
  6056. randNum = rand.Intn(10000) + 1000
  6057. timestamp := time.Now().Unix()
  6058. tempTime := time.Unix(timestamp, 0)
  6059. timeFormat := tempTime.Format("20060102150405")
  6060. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6061. items := item.(map[string]interface{})
  6062. money := items["price"].(string)
  6063. item_id_str := items["item_id"].(string)
  6064. name := items["name"].(string)
  6065. id_str := items["id"].(string)
  6066. moneys, _ := strconv.ParseInt(money, 10, 64)
  6067. monStr := strconv.FormatInt(moneys, 10)
  6068. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6069. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6070. id, _ := strconv.ParseInt(id_str, 10, 64)
  6071. additionalCharge := &models.HisAdditionalCharge{
  6072. ID: id,
  6073. HisPatientId: his_patient_id,
  6074. UserOrgId: orgId,
  6075. PatientId: patient_id,
  6076. RecordDate: timenow,
  6077. Price: monneyStr,
  6078. Status: 1,
  6079. ItemName: name,
  6080. ItemId: item_id,
  6081. AdminUserId: admin_user_id,
  6082. CreatedTime: time.Now().Unix(),
  6083. OrderStatus: 0,
  6084. PrescriptionNumber: "",
  6085. BatchNumber: "",
  6086. FeedetlSn: p_number,
  6087. }
  6088. service.CreateAdditionalCharge(additionalCharge)
  6089. additionalCharges = append(additionalCharges, additionalCharge)
  6090. }
  6091. this.ServeSuccessJSON(map[string]interface{}{
  6092. "msg": "添加成功",
  6093. "additional_charges": additionalCharges,
  6094. })
  6095. }
  6096. func (this *HisApiController) DeleteAddition() {
  6097. id, _ := this.GetInt64("id")
  6098. //TODO 需要判断是否已经结算
  6099. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6100. if err == nil {
  6101. this.ServeSuccessJSON(map[string]interface{}{
  6102. "msg": "删除成功",
  6103. })
  6104. return
  6105. } else {
  6106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6107. return
  6108. }
  6109. }
  6110. func (this *HisApiController) GetAdminUsers() {
  6111. adminUser := this.GetAdminUserInfo()
  6112. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6113. this.ServeSuccessJSON(map[string]interface{}{
  6114. "doctors": doctors,
  6115. })
  6116. }
  6117. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6118. change_type, _ := this.GetInt64("type", 0)
  6119. record_date := this.GetString("record_time")
  6120. patient_id, _ := this.GetInt64("patient_id", 0)
  6121. p_type, _ := this.GetInt64("p_type", 0)
  6122. timeLayout := "2006-01-02"
  6123. loc, _ := time.LoadLocation("Local")
  6124. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6125. record_time := theAdviceRecordTime.Unix()
  6126. adminUserInfo := this.GetAdminUserInfo()
  6127. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6128. if err == nil {
  6129. if len(prescriptions) == 0 {
  6130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6131. return
  6132. } else {
  6133. this.ServeSuccessJSON(map[string]interface{}{
  6134. "prescriptions": prescriptions,
  6135. })
  6136. return
  6137. }
  6138. } else {
  6139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6140. return
  6141. }
  6142. }
  6143. func (this *HisApiController) GetCallHisPrescription() {
  6144. patient_id, _ := this.GetInt64("patient_id", 0)
  6145. timeLayout := "2006-01-02"
  6146. loc, _ := time.LoadLocation("Local")
  6147. start_time := this.GetString("start_time")
  6148. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6149. end_time := this.GetString("end_time")
  6150. p_type, _ := this.GetInt64("p_type")
  6151. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6152. adminUserInfo := this.GetAdminUserInfo()
  6153. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6154. if err == nil {
  6155. this.ServeSuccessJSON(map[string]interface{}{
  6156. "prescriptions": prescriptions,
  6157. })
  6158. return
  6159. } else {
  6160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6161. return
  6162. }
  6163. }
  6164. func (this *HisApiController) GetHisDayPrescription() {
  6165. timeLayout := "2006-01-02"
  6166. loc, _ := time.LoadLocation("Local")
  6167. start_time := this.GetString("start_time")
  6168. patient_id, _ := this.GetInt64("patient_id", 0)
  6169. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6170. end_time := this.GetString("end_time")
  6171. p_type, _ := this.GetInt64("p_type")
  6172. order_status, _ := this.GetInt64("type")
  6173. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6174. adminUserInfo := this.GetAdminUserInfo()
  6175. var dayHisPrescription []*models.HisPrescription
  6176. var err error
  6177. if order_status == 1 || order_status == 0 {
  6178. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6179. } else if order_status == 2 {
  6180. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6181. }
  6182. var settle_total float64
  6183. for _, item := range dayHisPrescription {
  6184. if len(item.HisPrescriptionProject) > 0 {
  6185. for _, subItem := range item.HisPrescriptionProject {
  6186. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6187. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6188. settle_total = settle_total + total
  6189. }
  6190. }
  6191. if len(item.HisDoctorAdviceInfo) > 0 {
  6192. for _, subItem := range item.HisDoctorAdviceInfo {
  6193. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6194. settle_total = settle_total + total
  6195. }
  6196. }
  6197. }
  6198. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6199. if err == nil {
  6200. this.ServeSuccessJSON(map[string]interface{}{
  6201. "day_prescription": dayHisPrescription,
  6202. "settle_total": settle_total,
  6203. })
  6204. return
  6205. } else {
  6206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6207. return
  6208. }
  6209. }
  6210. func (c *HisApiController) GetHisChargePatientList() {
  6211. record_date := c.GetString("record_date")
  6212. order_status, _ := c.GetInt64("type")
  6213. timeLayout := "2006-01-02"
  6214. loc, _ := time.LoadLocation("Local")
  6215. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6216. if err != nil {
  6217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6218. return
  6219. }
  6220. recordDateTime := theTime.Unix()
  6221. adminInfo := c.GetAdminUserInfo()
  6222. var tempPatients []*service.NewTempPatients
  6223. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6224. if order_status != 2 {
  6225. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6226. } else {
  6227. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6228. }
  6229. var patients []*service.NewTempPatients
  6230. var patients_two []*service.NewTempPatients
  6231. for _, item := range tempPatients {
  6232. //过滤掉没挂号的和没开处方的
  6233. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6234. patients = append(patients, item)
  6235. }
  6236. //过滤掉没挂号的
  6237. if len(item.HisPatient) > 0 {
  6238. patients_two = append(patients_two, item)
  6239. }
  6240. }
  6241. c.ServeSuccessJSON(map[string]interface{}{
  6242. "list": patients,
  6243. "list_two": patients_two,
  6244. })
  6245. }
  6246. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6247. record_date := c.GetString("record_date")
  6248. timeLayout := "2006-01-02"
  6249. loc, _ := time.LoadLocation("Local")
  6250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6251. if err != nil {
  6252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6253. return
  6254. }
  6255. recordDateTime := theTime.Unix()
  6256. adminUser := c.GetAdminUserInfo()
  6257. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6258. var patients []*service.Patients
  6259. for _, item := range tempPatients {
  6260. if item.HisPatient.ID == 0 {
  6261. patients = append(patients, item)
  6262. }
  6263. }
  6264. c.ServeSuccessJSON(map[string]interface{}{
  6265. "list": patients,
  6266. //"list_two": patients_two,
  6267. })
  6268. }
  6269. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6270. newArr = make([]*service.Patients, 0)
  6271. for i := 0; i < len(patient); i++ {
  6272. repeat := false
  6273. for j := i + 1; j < len(patient); j++ {
  6274. if patient[i].ID == patient[j].ID {
  6275. repeat = true
  6276. break
  6277. }
  6278. }
  6279. if !repeat {
  6280. newArr = append(newArr, patient[i])
  6281. }
  6282. }
  6283. return
  6284. }
  6285. func (c *HisApiController) GetHisChargePatientInfo() {
  6286. patient_id, _ := c.GetInt64("patient_id")
  6287. his_patient_id, _ := c.GetInt64("his_patient_id")
  6288. record_date := c.GetString("record_date")
  6289. //start_time := c.GetString("start_time")
  6290. //end_time := c.GetString("end_time")
  6291. order_status, _ := c.GetInt64("type", 0)
  6292. p_type, _ := c.GetInt64("p_type", 0)
  6293. order_id, _ := c.GetInt64("order_id", 0)
  6294. timeLayout := "2006-01-02"
  6295. loc, _ := time.LoadLocation("Local")
  6296. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6297. if err != nil {
  6298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6299. return
  6300. }
  6301. recordDateTime := theTime.Unix()
  6302. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6303. //if err != nil {
  6304. //
  6305. //}
  6306. //startRecordDateTime := startTime.Unix()
  6307. //
  6308. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6309. //if err != nil {
  6310. //
  6311. //}
  6312. //endRecordDateTime := endTime.Unix()
  6313. admin := c.GetAdminUserInfo()
  6314. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6315. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6316. var prescriptions []*models.HisPrescription
  6317. //var unChargeMonthPrescriptions []*models.HisPrescription
  6318. order, _ := service.GetHisOrderByID(order_id)
  6319. if order_status == 1 || order_status == 0 {
  6320. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6321. } else if order_status == 2 {
  6322. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6323. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6324. }
  6325. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6326. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6327. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6328. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6329. //获取所有科室信息
  6330. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6331. c.ServeSuccessJSON(map[string]interface{}{
  6332. "his_info": his_patient_info,
  6333. "xt_info": xt_patient_info,
  6334. "prescription": prescriptions,
  6335. "case_history": case_history,
  6336. "info": patientPrescriptionInfo,
  6337. "last_info": lastPatientPrescriptionInfo,
  6338. "order": order,
  6339. "doctors": doctors,
  6340. "department": department,
  6341. })
  6342. return
  6343. }
  6344. func (c *HisApiController) GetAllOrderDetail() {
  6345. order_id, _ := c.GetInt64("id", 0)
  6346. order, _ := service.GetHisOrderByID(order_id)
  6347. if order.ID == 0 {
  6348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6349. return
  6350. }
  6351. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6352. org_id := c.GetAdminUserInfo().CurrentOrgId
  6353. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6354. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6355. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6356. c.ServeSuccessJSON(map[string]interface{}{
  6357. "order": order,
  6358. "order_info": order_info,
  6359. "patient": patient,
  6360. "admin_info": adminInfo,
  6361. "hospital_record": record,
  6362. })
  6363. return
  6364. }
  6365. func (c *HisApiController) GetAllOrderDetailCollect() {
  6366. order_id, _ := c.GetInt64("id", 0)
  6367. order, _ := service.GetHisOrderByID(order_id)
  6368. if order.ID == 0 {
  6369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6370. return
  6371. }
  6372. org_id := c.GetAdminUserInfo().CurrentOrgId
  6373. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6374. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6375. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6376. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6377. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6378. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6379. var bedCostTotal float64 = 0 //床位总费
  6380. //var bedCostSelfTotal float64 = 0 //床位自费
  6381. var operationCostTotal float64 = 0 //手术费
  6382. //var operationCostSelfTotal float64 = 0 //手术费
  6383. var otherCostTotal float64 = 0 //其他费用
  6384. //var otherCostSelfTotal float64 = 0 //其他费用
  6385. var materialCostTotal float64 = 0 //材料费
  6386. //var materialCostSelfTotal float64 = 0 //材料费
  6387. var westernMedicineCostTotal float64 = 0 //西药费
  6388. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6389. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6390. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6391. var checkCostTotal float64 = 0 //检查费
  6392. //var checkCostSelfTotal float64 = 0 //检查费
  6393. var laboratoryCostTotal float64 = 0 //化验费
  6394. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6395. var treatCostTotal float64 = 0 //治疗费用
  6396. //var treatCostSelfTotal float64 = 0 //治疗费用
  6397. var zhenChaCostTotal float64 = 0 //其他费用
  6398. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6399. decimal.DivisionPrecision = 2
  6400. var BalanceAccountsType int64
  6401. if his.ID > 0 {
  6402. BalanceAccountsType = his.BalanceAccountsType
  6403. } else {
  6404. BalanceAccountsType = record.BalanceAccountsType
  6405. }
  6406. if BalanceAccountsType != 2 {
  6407. for _, item := range order_info {
  6408. if org_id == 10215 {
  6409. if item.MedChrgitmType == "01" { //床位费
  6410. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6411. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6412. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6413. }
  6414. if item.MedChrgitmType == "02" { //诊察费
  6415. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6416. //zhenChaCostSelfTotal = zhenChaCostTotal
  6417. }
  6418. if item.MedChrgitmType == "03" { //检查费
  6419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6420. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6421. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6422. }
  6423. //if item.MedChrgitmType == "02" { //检查费
  6424. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6425. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6426. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6427. //}
  6428. if item.MedChrgitmType == "04" { //化验费
  6429. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6430. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6431. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6432. }
  6433. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6435. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6436. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6437. }
  6438. if item.MedChrgitmType == "06" { //手术费
  6439. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6440. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6441. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6442. }
  6443. if item.MedChrgitmType == "08" { //材料费
  6444. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6445. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6446. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6447. }
  6448. if item.MedChrgitmType == "09" { //西药费
  6449. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6450. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6451. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6452. }
  6453. if item.MedChrgitmType == "11" { //中成费
  6454. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6455. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6456. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6457. }
  6458. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6459. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6460. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6461. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6462. }
  6463. } else if org_id == 10188 || org_id == 10217 {
  6464. if item.MedChrgitmType == "01" { //床位费
  6465. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6466. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6467. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6468. }
  6469. if item.MedChrgitmType == "02" { //诊察费
  6470. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6471. //zhenChaCostSelfTotal = zhenChaCostTotal
  6472. }
  6473. if item.MedChrgitmType == "03" { //检查费
  6474. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6475. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6476. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6477. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6478. }
  6479. //if item.MedChrgitmType == "02" { //检查费
  6480. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6481. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6482. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6483. //}
  6484. if item.MedChrgitmType == "04" { //化验费
  6485. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6486. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6487. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6488. }
  6489. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6490. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6491. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6492. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6493. }
  6494. if item.MedChrgitmType == "06" { //手术费
  6495. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6496. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6497. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6498. }
  6499. if item.MedChrgitmType == "08" { //材料费
  6500. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6501. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6502. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6503. }
  6504. if item.MedChrgitmType == "09" { //西药费
  6505. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6506. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6507. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6508. }
  6509. if item.MedChrgitmType == "11" { //中成费
  6510. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6511. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6512. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6513. }
  6514. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6515. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6516. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6517. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6518. }
  6519. } else {
  6520. if item.MedChrgitmType == "01" { //床位费
  6521. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6522. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6523. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6524. }
  6525. //if item.MedChrgitmType == "02" { //诊察费
  6526. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6527. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6528. //}
  6529. if item.MedChrgitmType == "03" { //检查费
  6530. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6531. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6532. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6533. }
  6534. //if item.MedChrgitmType == "02" { //检查费
  6535. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6536. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6537. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6538. //}
  6539. if item.MedChrgitmType == "04" { //化验费
  6540. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6541. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6542. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6543. }
  6544. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6545. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6546. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6547. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6548. }
  6549. if item.MedChrgitmType == "06" { //手术费
  6550. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6551. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6552. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6553. }
  6554. if item.MedChrgitmType == "08" { //材料费
  6555. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6556. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6557. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6558. }
  6559. if item.MedChrgitmType == "09" { //西药费
  6560. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6561. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6562. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6563. }
  6564. if item.MedChrgitmType == "11" { //中成费
  6565. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6566. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6567. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6568. }
  6569. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6570. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6571. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6572. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6573. }
  6574. }
  6575. }
  6576. c.ServeSuccessJSON(map[string]interface{}{
  6577. "order": order,
  6578. "order_info": order_info,
  6579. "patient": patient,
  6580. "admin_info": adminInfo,
  6581. "his_hospital": record,
  6582. "bedCostTotal": bedCostTotal,
  6583. "operationCostTotal": operationCostTotal,
  6584. "otherCostTotal": otherCostTotal,
  6585. "materialCostTotal": materialCostTotal,
  6586. "westernMedicineCostTotal": westernMedicineCostTotal,
  6587. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6588. "checkCostTotal": checkCostTotal,
  6589. "zhenChaCostTotal": zhenChaCostTotal,
  6590. "laboratoryCostTotal": laboratoryCostTotal,
  6591. "treatCostTotal": treatCostTotal,
  6592. })
  6593. } else {
  6594. for _, item := range order_info {
  6595. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6596. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6597. item.MedChrgitmType = "09"
  6598. }
  6599. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6600. if item.HisPrescriptionProject.Type == 2 {
  6601. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6602. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6603. case 0:
  6604. item.MedChrgitmType = "0"
  6605. break
  6606. case 1:
  6607. item.MedChrgitmType = "14"
  6608. break
  6609. case 2:
  6610. item.MedChrgitmType = "05"
  6611. break
  6612. case 3:
  6613. item.MedChrgitmType = "03"
  6614. break
  6615. case 4:
  6616. item.MedChrgitmType = "03"
  6617. break
  6618. case 5:
  6619. item.MedChrgitmType = "08"
  6620. break
  6621. case 6:
  6622. item.MedChrgitmType = "14"
  6623. break
  6624. case 7:
  6625. item.MedChrgitmType = "14"
  6626. break
  6627. case 8:
  6628. item.MedChrgitmType = "03"
  6629. break
  6630. case 9:
  6631. item.MedChrgitmType = "14"
  6632. break
  6633. case 10:
  6634. item.MedChrgitmType = "14"
  6635. break
  6636. case 11:
  6637. item.MedChrgitmType = "06"
  6638. break
  6639. case 12:
  6640. item.MedChrgitmType = "12"
  6641. break
  6642. case 13:
  6643. item.MedChrgitmType = "01"
  6644. break
  6645. case 14:
  6646. item.MedChrgitmType = "04"
  6647. break
  6648. case 15:
  6649. item.MedChrgitmType = "14"
  6650. break
  6651. }
  6652. } else {
  6653. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6654. case 1:
  6655. item.MedChrgitmType = "14"
  6656. break
  6657. case 2:
  6658. item.MedChrgitmType = "05"
  6659. break
  6660. case 3:
  6661. item.MedChrgitmType = "04"
  6662. break
  6663. case 4:
  6664. item.MedChrgitmType = "14"
  6665. break
  6666. case 5:
  6667. item.MedChrgitmType = "08"
  6668. break
  6669. case 6:
  6670. item.MedChrgitmType = "14"
  6671. break
  6672. case 7:
  6673. item.MedChrgitmType = "14"
  6674. break
  6675. case 8:
  6676. item.MedChrgitmType = "03"
  6677. break
  6678. case 9:
  6679. item.MedChrgitmType = "14"
  6680. break
  6681. }
  6682. }
  6683. } else if item.HisPrescriptionProject.Type == 3 {
  6684. item.MedChrgitmType = "08"
  6685. }
  6686. }
  6687. }
  6688. for _, item := range order_info {
  6689. if org_id == 10215 {
  6690. if item.MedChrgitmType == "01" { //床位费
  6691. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6692. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6693. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6694. }
  6695. if item.MedChrgitmType == "02" { //诊察费
  6696. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6697. //zhenChaCostSelfTotal = zhenChaCostTotal
  6698. }
  6699. if item.MedChrgitmType == "03" { //检查费
  6700. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6701. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6702. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6703. }
  6704. //if item.MedChrgitmType == "02" { //检查费
  6705. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6706. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6707. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6708. //}
  6709. if item.MedChrgitmType == "04" { //化验费
  6710. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6711. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6712. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6713. }
  6714. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6715. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6716. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6717. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6718. }
  6719. if item.MedChrgitmType == "06" { //手术费
  6720. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6721. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6722. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6723. }
  6724. if item.MedChrgitmType == "08" { //材料费
  6725. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6726. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6727. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6728. }
  6729. if item.MedChrgitmType == "09" { //西药费
  6730. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6731. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6732. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6733. }
  6734. if item.MedChrgitmType == "11" { //中成费
  6735. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6736. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6737. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6738. }
  6739. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6740. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6741. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6742. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6743. }
  6744. } else {
  6745. if item.MedChrgitmType == "01" { //床位费
  6746. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6747. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6748. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6749. }
  6750. //if item.MedChrgitmType == "02" { //诊察费
  6751. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6752. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6753. //}
  6754. if item.MedChrgitmType == "03" { //检查费
  6755. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6756. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6757. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6758. }
  6759. //if item.MedChrgitmType == "02" { //检查费
  6760. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6761. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6762. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6763. //}
  6764. if item.MedChrgitmType == "04" { //化验费
  6765. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6766. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6767. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6768. }
  6769. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6770. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6771. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6772. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6773. }
  6774. if item.MedChrgitmType == "06" { //手术费
  6775. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6776. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6777. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6778. }
  6779. if item.MedChrgitmType == "08" { //材料费
  6780. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6781. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6782. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6783. }
  6784. if item.MedChrgitmType == "09" { //西药费
  6785. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6786. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6787. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6788. }
  6789. if item.MedChrgitmType == "11" { //中成费
  6790. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6791. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6792. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6793. }
  6794. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6795. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6796. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6797. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6798. }
  6799. }
  6800. }
  6801. c.ServeSuccessJSON(map[string]interface{}{
  6802. "order": order,
  6803. "order_info": order_info,
  6804. "patient": patient,
  6805. "admin_info": adminInfo,
  6806. "his_hospital": record,
  6807. "bedCostTotal": bedCostTotal,
  6808. "operationCostTotal": operationCostTotal,
  6809. "otherCostTotal": otherCostTotal,
  6810. "materialCostTotal": materialCostTotal,
  6811. "westernMedicineCostTotal": westernMedicineCostTotal,
  6812. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6813. "checkCostTotal": checkCostTotal,
  6814. "zhenChaCostTotal": zhenChaCostTotal,
  6815. "laboratoryCostTotal": laboratoryCostTotal,
  6816. "treatCostTotal": treatCostTotal,
  6817. })
  6818. }
  6819. }
  6820. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  6821. page, _ := c.GetInt64("page")
  6822. limit, _ := c.GetInt64("limit")
  6823. keywords := c.GetString("keywords")
  6824. start_time := c.GetString("start_time")
  6825. end_time := c.GetString("end_time")
  6826. //clr_type := c.GetString("clr_type")
  6827. insutype := c.GetString("insutype")
  6828. timeLayout := "2006-01-02"
  6829. loc, _ := time.LoadLocation("Local")
  6830. var theStartTIme int64
  6831. if len(start_time) > 0 {
  6832. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6833. theStartTIme = theTime.Unix()
  6834. }
  6835. var theEndtTIme int64
  6836. if len(end_time) > 0 {
  6837. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6838. theEndtTIme = theTime.Unix()
  6839. }
  6840. if page <= 0 {
  6841. page = 1
  6842. }
  6843. if limit <= 0 {
  6844. limit = 10
  6845. }
  6846. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  6847. c.ServeSuccessJSON(map[string]interface{}{
  6848. "total": total,
  6849. "list": list,
  6850. })
  6851. return
  6852. }
  6853. func (c *HisApiController) GetPutOnRecordList() {
  6854. page, _ := c.GetInt64("page")
  6855. limit, _ := c.GetInt64("limit")
  6856. keywords := c.GetString("keywords")
  6857. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  6858. if page <= 0 {
  6859. page = 1
  6860. }
  6861. if limit <= 0 {
  6862. limit = 10
  6863. }
  6864. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  6865. c.ServeSuccessJSON(map[string]interface{}{
  6866. "total": total,
  6867. "list": list,
  6868. })
  6869. return
  6870. }
  6871. func (c *HisApiController) GetCompareData() {
  6872. start_time := c.GetString("start_time")
  6873. end_time := c.GetString("end_time")
  6874. insutype := c.GetString("insutype")
  6875. clr_type := c.GetString("clr_type")
  6876. timeLayout := "2006-01-02"
  6877. loc, _ := time.LoadLocation("Local")
  6878. var theStartTIme int64
  6879. if len(start_time) > 0 {
  6880. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6881. if err != nil {
  6882. theStartTIme = 0
  6883. }
  6884. theStartTIme = theTime.Unix()
  6885. }
  6886. var theEndtTIme int64
  6887. if len(end_time) > 0 {
  6888. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6889. if err != nil {
  6890. theEndtTIme = 0
  6891. }
  6892. theEndtTIme = theTime.Unix()
  6893. }
  6894. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  6895. fmt.Println(err)
  6896. if err == nil {
  6897. c.ServeSuccessJSON(map[string]interface{}{
  6898. "list": formData,
  6899. })
  6900. } else {
  6901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6902. return
  6903. }
  6904. }
  6905. func (c *HisApiController) GetFaPiaoData() {
  6906. order_id, _ := c.GetInt64("order_id")
  6907. patient_id, _ := c.GetInt64("patient_id")
  6908. number := c.GetString("number")
  6909. adminUser := c.GetAdminUserInfo()
  6910. order, _ := service.GetHisOrderByID(order_id)
  6911. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  6912. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  6913. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6914. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  6915. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6916. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  6917. var bedCostTotal float64 = 0 //床位总费
  6918. var bedCostSelfTotal float64 = 0 //床位自费
  6919. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  6920. var operationCostTotal float64 = 0 //手术费
  6921. var operationCostSelfTotal float64 = 0 //手术费
  6922. var operationCostPartSelfTotal float64 = 0 //手术费
  6923. var otherCostTotal float64 = 0 //其他费用
  6924. var otherCostSelfTotal float64 = 0 //其他费用
  6925. var otherCostPartSelfTotal float64 = 0 //其他费用
  6926. var materialCostTotal float64 = 0 //材料费
  6927. var materialCostSelfTotal float64 = 0 //材料费
  6928. var materialCostPartSelfTotal float64 = 0 //材料费
  6929. var westernMedicineCostTotal float64 = 0 //西药费
  6930. var westernMedicineCostSelfTotal float64 = 0 //西药费
  6931. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  6932. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6933. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6934. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  6935. var checkCostTotal float64 = 0 //检查费
  6936. var checkCostSelfTotal float64 = 0 //检查费
  6937. var checkCostPartSelfTotal float64 = 0 //检查费
  6938. var laboratoryCostTotal float64 = 0 //化验费
  6939. var laboratoryCostSelfTotal float64 = 0 //化验费
  6940. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  6941. var treatCostTotal float64 = 0 //治疗费用
  6942. var treatCostSelfTotal float64 = 0 //治疗费用
  6943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  6944. var zhenChaCostTotal float64 = 0 //其他费用
  6945. var zhenChaCostSelfTotal float64 = 0 //其他费用
  6946. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6947. decimal.DivisionPrecision = 2
  6948. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6949. var balanceAccountsType int64
  6950. if his.ID > 0 {
  6951. balanceAccountsType = his.BalanceAccountsType
  6952. } else {
  6953. balanceAccountsType = his_hospital_record.BalanceAccountsType
  6954. }
  6955. if balanceAccountsType == 2 {
  6956. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6957. for _, item := range orderInfos_two {
  6958. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6959. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6960. item.MedChrgitmType = "09"
  6961. }
  6962. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6963. if item.HisPrescriptionProject.Type == 2 {
  6964. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6965. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6966. case 0:
  6967. item.MedChrgitmType = "0"
  6968. break
  6969. case 1:
  6970. item.MedChrgitmType = "14"
  6971. break
  6972. case 2:
  6973. item.MedChrgitmType = "05"
  6974. break
  6975. case 3:
  6976. item.MedChrgitmType = "03"
  6977. break
  6978. case 4:
  6979. item.MedChrgitmType = "03"
  6980. break
  6981. case 5:
  6982. item.MedChrgitmType = "08"
  6983. break
  6984. case 6:
  6985. item.MedChrgitmType = "14"
  6986. break
  6987. case 7:
  6988. item.MedChrgitmType = "14"
  6989. break
  6990. case 8:
  6991. item.MedChrgitmType = "03"
  6992. break
  6993. case 9:
  6994. item.MedChrgitmType = "14"
  6995. break
  6996. case 10:
  6997. item.MedChrgitmType = "14"
  6998. break
  6999. case 11:
  7000. item.MedChrgitmType = "06"
  7001. break
  7002. case 12:
  7003. item.MedChrgitmType = "12"
  7004. break
  7005. case 13:
  7006. item.MedChrgitmType = "01"
  7007. break
  7008. case 14:
  7009. item.MedChrgitmType = "04"
  7010. break
  7011. case 15:
  7012. item.MedChrgitmType = "02"
  7013. break
  7014. }
  7015. } else {
  7016. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7017. case 1:
  7018. item.MedChrgitmType = "14"
  7019. break
  7020. case 2:
  7021. item.MedChrgitmType = "05"
  7022. break
  7023. case 3:
  7024. item.MedChrgitmType = "03"
  7025. break
  7026. case 4:
  7027. item.MedChrgitmType = "03"
  7028. break
  7029. case 5:
  7030. item.MedChrgitmType = "08"
  7031. break
  7032. case 6:
  7033. item.MedChrgitmType = "14"
  7034. break
  7035. case 7:
  7036. item.MedChrgitmType = "14"
  7037. break
  7038. case 8:
  7039. item.MedChrgitmType = "03"
  7040. break
  7041. case 9:
  7042. item.MedChrgitmType = "14"
  7043. break
  7044. }
  7045. }
  7046. } else if item.HisPrescriptionProject.Type == 3 {
  7047. item.MedChrgitmType = "08"
  7048. }
  7049. }
  7050. }
  7051. for _, item := range orderInfos_two {
  7052. fmt.Println(item.MedChrgitmType)
  7053. if item.MedChrgitmType == "01" { //床位费
  7054. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7055. bedCostSelfTotal = bedCostTotal
  7056. }
  7057. if item.MedChrgitmType == "02" { //诊察费
  7058. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7059. zhenChaCostSelfTotal = zhenChaCostTotal
  7060. }
  7061. if item.MedChrgitmType == "03" { //检查费
  7062. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7063. checkCostSelfTotal = checkCostTotal
  7064. }
  7065. if item.MedChrgitmType == "04" { //化验费
  7066. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7067. laboratoryCostSelfTotal = laboratoryCostTotal
  7068. }
  7069. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7070. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7071. treatCostSelfTotal = treatCostTotal
  7072. }
  7073. if item.MedChrgitmType == "06" { //手术费
  7074. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7075. operationCostSelfTotal = treatCostTotal
  7076. }
  7077. if item.MedChrgitmType == "08" { //材料费
  7078. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7079. materialCostSelfTotal = materialCostTotal
  7080. }
  7081. if item.MedChrgitmType == "09" { //西药费
  7082. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7083. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7084. }
  7085. if item.MedChrgitmType == "11" { //中成费
  7086. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7087. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7088. }
  7089. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7090. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7091. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7092. otherCostSelfTotal = otherCostTotal
  7093. }
  7094. } else {
  7095. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7096. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7097. otherCostSelfTotal = otherCostTotal
  7098. }
  7099. }
  7100. }
  7101. } else {
  7102. for _, item := range orderInfos {
  7103. if item.MedChrgitmType == "01" { //床位费
  7104. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7105. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7106. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7107. }
  7108. if item.MedChrgitmType == "02" { //诊察费
  7109. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7110. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7111. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7112. }
  7113. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7114. if item.MedChrgitmType == "03" { //检查费
  7115. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7116. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7117. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7118. }
  7119. } else {
  7120. if item.MedChrgitmType == "03" { //检查费
  7121. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7122. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7123. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7124. }
  7125. }
  7126. if item.MedChrgitmType == "04" { //化验费
  7127. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7128. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7129. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7130. }
  7131. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7132. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7133. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7134. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7135. }
  7136. if item.MedChrgitmType == "06" { //手术费
  7137. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7138. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7139. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7140. }
  7141. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7142. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7143. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7144. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7145. }
  7146. if item.MedChrgitmType == "09" { //西药费
  7147. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7148. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7149. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7150. }
  7151. if item.MedChrgitmType == "11" { //中成费
  7152. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7153. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7154. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7155. }
  7156. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7157. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7158. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7159. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7160. }
  7161. }
  7162. }
  7163. timeLayout := "2006-01-02"
  7164. loc, _ := time.LoadLocation("Local")
  7165. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7166. if err != nil {
  7167. }
  7168. startRecordDateTime := startTime.Unix()
  7169. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7170. if err != nil {
  7171. }
  7172. endRecordDateTime := endTime.Unix()
  7173. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7174. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7175. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7176. c.ServeSuccessJSON(map[string]interface{}{
  7177. "order_number": order.Number, //业务流水号
  7178. "id_card_no": his.IdCardNo, //社会保障号
  7179. "department_name": department.Name, //科室
  7180. "number": his.Number, //门诊号
  7181. "date": order.SettleAccountsDate, //结算日期
  7182. "name": order.PsnName, //姓名
  7183. "gender": patient.Gender, //性别
  7184. "psn_cash_money": order.PsnCashPay, //个人支付
  7185. "pay_way": "门诊", //结算方式
  7186. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7187. "admin_user_name": admin.UserName, //收款员
  7188. "order": order,
  7189. "order_info": orderInfos_two,
  7190. "his": his,
  7191. "bedCostTotal": bedCostTotal,
  7192. "bedCostSelfTotal": bedCostSelfTotal,
  7193. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7194. "operationCostTotal": operationCostTotal,
  7195. "operationCostSelfTotal": operationCostSelfTotal,
  7196. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7197. "otherCostTotal": otherCostTotal,
  7198. "otherCostSelfTotal": otherCostSelfTotal,
  7199. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7200. "materialCostTotal": materialCostTotal,
  7201. "materialCostSelfTotal": materialCostSelfTotal,
  7202. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7203. "westernMedicineCostTotal": westernMedicineCostTotal,
  7204. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7205. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7206. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7207. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7208. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7209. "checkCostTotal": checkCostTotal,
  7210. "checkCostSelfTotal": checkCostSelfTotal,
  7211. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7212. "laboratoryCostTotal": laboratoryCostTotal,
  7213. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7214. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7215. "treatCostTotal": treatCostTotal,
  7216. "treatCostSelfTotal": treatCostSelfTotal,
  7217. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7218. "zhenChaCostTotal": zhenChaCostTotal,
  7219. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7220. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7221. "his_hospital_record": his_hospital_record,
  7222. "pre_pay_money": pre_pay_money,
  7223. "refund_sum": sum,
  7224. })
  7225. }
  7226. func (this *HisApiController) GetIncomeStatisticsData() {
  7227. start_time := this.GetString("start_time")
  7228. end_time := this.GetString("end_time")
  7229. key_words := this.GetString("key_words")
  7230. limit, _ := this.GetInt64("limit")
  7231. page, _ := this.GetInt64("page")
  7232. if page <= 0 {
  7233. page = 1
  7234. }
  7235. if limit <= 0 {
  7236. limit = 10
  7237. }
  7238. statistics_type, _ := this.GetInt64("statistics_type")
  7239. admin := this.GetAdminUserInfo()
  7240. timeLayout := "2006-01-02"
  7241. loc, _ := time.LoadLocation("Local")
  7242. var theStartTIme int64
  7243. if len(start_time) > 0 {
  7244. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7245. if err != nil {
  7246. theStartTIme = 0
  7247. }
  7248. theStartTIme = theTime.Unix()
  7249. }
  7250. var theEndtTIme int64
  7251. if len(end_time) > 0 {
  7252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7253. if err != nil {
  7254. theEndtTIme = 0
  7255. }
  7256. theEndtTIme = theTime.Unix()
  7257. }
  7258. if statistics_type == 1 {
  7259. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7260. this.ServeSuccessJSON(map[string]interface{}{
  7261. "list": list,
  7262. "total": total,
  7263. })
  7264. } else {
  7265. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7266. this.ServeSuccessJSON(map[string]interface{}{
  7267. "list": list,
  7268. "total": total,
  7269. })
  7270. }
  7271. }
  7272. func (c *HisApiController) PostProjectInformation() {
  7273. adminUser := c.GetAdminUserInfo()
  7274. orgId := adminUser.CurrentOrgId
  7275. dataBody := make(map[string]interface{}, 0)
  7276. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7277. if err != nil {
  7278. utils.ErrorLog(err.Error())
  7279. return
  7280. }
  7281. utils.ErrorLog("%v", dataBody)
  7282. var projectList []*models.HisProject
  7283. var total_goods []interface{}
  7284. tempProjects := dataBody["projects"].([]interface{})
  7285. total_goods = tempProjects
  7286. for index, projectMap := range tempProjects {
  7287. projectM := projectMap.(map[string]interface{})
  7288. var project models.HisProject
  7289. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7290. utils.ErrorLog("project_name")
  7291. return
  7292. }
  7293. project_name, _ := projectM["project_name"].(string)
  7294. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7295. err_log := models.ExportErrLog{
  7296. LogType: 6,
  7297. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7298. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7299. Status: 1,
  7300. CreateTime: time.Now().Unix(),
  7301. UpdateTime: time.Now().Unix(),
  7302. ExportTime: time.Now().Unix(),
  7303. }
  7304. service.CreateExportErrLog(&err_log)
  7305. continue
  7306. }
  7307. project.ProjectName = project_name
  7308. prices := projectM["price"].(string)
  7309. price, _ := strconv.ParseFloat(prices, 64)
  7310. if price <= 0 { //名字为空则生成一条导入错误日志
  7311. err_log := models.ExportErrLog{
  7312. LogType: 6,
  7313. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7314. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7315. Status: 1,
  7316. CreateTime: time.Now().Unix(),
  7317. UpdateTime: time.Now().Unix(),
  7318. ExportTime: time.Now().Unix(),
  7319. }
  7320. service.CreateExportErrLog(&err_log)
  7321. continue
  7322. }
  7323. project.Price = price
  7324. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7325. utils.ErrorLog("unit_id")
  7326. return
  7327. }
  7328. unit := projectM["unit"].(string)
  7329. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7330. err_log := models.ExportErrLog{
  7331. LogType: 6,
  7332. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7333. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7334. Status: 1,
  7335. CreateTime: time.Now().Unix(),
  7336. UpdateTime: time.Now().Unix(),
  7337. ExportTime: time.Now().Unix(),
  7338. }
  7339. service.CreateExportErrLog(&err_log)
  7340. continue
  7341. }
  7342. project.Unit = unit
  7343. cost_classify := projectM["cost_classify"].(string)
  7344. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7345. err_log := models.ExportErrLog{
  7346. LogType: 6,
  7347. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7348. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7349. Status: 1,
  7350. CreateTime: time.Now().Unix(),
  7351. UpdateTime: time.Now().Unix(),
  7352. ExportTime: time.Now().Unix(),
  7353. }
  7354. service.CreateExportErrLog(&err_log)
  7355. continue
  7356. }
  7357. var costClassify = "费用类别"
  7358. var cost_classify_id int64
  7359. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7360. if len(cost_classify) != 0 {
  7361. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7362. if errcode == gorm.ErrRecordNotFound {
  7363. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7364. dataconfig := models.DictDataconfig{
  7365. ParentId: costClassifyConfig.ID,
  7366. Module: "system",
  7367. OrgId: orgId,
  7368. Name: cost_classify,
  7369. FieldName: "",
  7370. Value: costConfig.Value + 1,
  7371. CreatedTime: "",
  7372. UpdatedTime: "",
  7373. CreateUserId: adminUser.AdminUser.Id,
  7374. Status: 1,
  7375. Remark: "",
  7376. DeleteIdSystem: 0,
  7377. Title: "",
  7378. Content: "",
  7379. Order: 0,
  7380. Code: "",
  7381. }
  7382. service.CreatedDicConfig(&dataconfig)
  7383. }
  7384. }
  7385. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7386. for _, it := range costClassList {
  7387. if cost_classify == it.Name {
  7388. cost_classify_id = int64(it.Value)
  7389. }
  7390. }
  7391. project.CostClassify = cost_classify_id
  7392. executive_section := projectM["executive_section"].(string)
  7393. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7394. err_log := models.ExportErrLog{
  7395. LogType: 6,
  7396. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7397. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7398. Status: 1,
  7399. CreateTime: time.Now().Unix(),
  7400. UpdateTime: time.Now().Unix(),
  7401. ExportTime: time.Now().Unix(),
  7402. }
  7403. service.CreateExportErrLog(&err_log)
  7404. continue
  7405. }
  7406. if len(executive_section) != 0 {
  7407. //查找科室是否有内容
  7408. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7409. if errcodedepart == gorm.ErrRecordNotFound {
  7410. department := models.XtHisDepartment{
  7411. Name: executive_section,
  7412. Status: 1,
  7413. UserOrgId: adminUser.CurrentOrgId,
  7414. CreatedTime: time.Now().Unix(),
  7415. }
  7416. service.CreateDePartment(&department)
  7417. }
  7418. }
  7419. var executive_section_id int64
  7420. departMentList, _ := service.GetAllDepartMent(orgId)
  7421. for _, it := range departMentList {
  7422. if executive_section == it.Name {
  7423. executive_section_id = it.ID
  7424. }
  7425. }
  7426. project.ExecutiveSection = executive_section_id
  7427. medical_coverage := projectM["medical_coverage"].(string)
  7428. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7429. err_log := models.ExportErrLog{
  7430. LogType: 6,
  7431. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7432. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7433. Status: 1,
  7434. CreateTime: time.Now().Unix(),
  7435. UpdateTime: time.Now().Unix(),
  7436. ExportTime: time.Now().Unix(),
  7437. }
  7438. service.CreateExportErrLog(&err_log)
  7439. continue
  7440. }
  7441. var medicalCoverage = "医保等级"
  7442. var medical_coverage_id int64
  7443. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7444. if len(medical_coverage) != 0 {
  7445. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7446. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7447. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7448. dataconfig := models.DictDataconfig{
  7449. ParentId: medicalCoverageConfig.ID,
  7450. Module: "system",
  7451. OrgId: orgId,
  7452. Name: medical_coverage,
  7453. FieldName: "",
  7454. Value: medicalCoverageConfig.Value + 1,
  7455. CreatedTime: "",
  7456. UpdatedTime: "",
  7457. CreateUserId: adminUser.AdminUser.Id,
  7458. Status: 1,
  7459. Remark: "",
  7460. DeleteIdSystem: 0,
  7461. Title: "",
  7462. Content: "",
  7463. Order: 0,
  7464. Code: "",
  7465. }
  7466. service.CreatedDicConfig(&dataconfig)
  7467. }
  7468. }
  7469. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7470. for _, it := range medicalCoverageList {
  7471. if medical_coverage == it.Name {
  7472. medical_coverage_id = int64(it.Value)
  7473. }
  7474. }
  7475. project.MedicalCoverage = medical_coverage_id
  7476. pinyin := projectM["pinyin"].(string)
  7477. project.Pinyin = pinyin
  7478. wubi := projectM["wubi"].(string)
  7479. project.Wubi = wubi
  7480. statistical_classification := projectM["statistical_classification"].(string)
  7481. var statisticalClassification = "统计分类"
  7482. var statistical_classification_id int64
  7483. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7484. if len(statistical_classification) != 0 {
  7485. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7486. if classificationerrcodes == gorm.ErrRecordNotFound {
  7487. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7488. dataconfig := models.DictDataconfig{
  7489. ParentId: classiFication.ID,
  7490. Module: "system",
  7491. OrgId: orgId,
  7492. Name: statistical_classification,
  7493. FieldName: "",
  7494. Value: classiFicationConfig.Value + 1,
  7495. CreatedTime: "",
  7496. UpdatedTime: "",
  7497. CreateUserId: adminUser.AdminUser.Id,
  7498. Status: 1,
  7499. Remark: "",
  7500. DeleteIdSystem: 0,
  7501. Title: "",
  7502. Content: "",
  7503. Order: 0,
  7504. Code: "",
  7505. }
  7506. service.CreatedDicConfig(&dataconfig)
  7507. }
  7508. }
  7509. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7510. for _, it := range classiFicationList {
  7511. if statistical_classification == it.Name {
  7512. statistical_classification_id = int64(it.Value)
  7513. }
  7514. }
  7515. project.StatisticalClassification = statistical_classification_id
  7516. disease_directory := int64(projectM["disease_directory"].(float64))
  7517. project.DiseaseDirectory = disease_directory
  7518. is_record := int64(projectM["is_record"].(float64))
  7519. project.IsRecord = is_record
  7520. medical_code := projectM["medical_code"].(string)
  7521. project.MedicalCode = medical_code
  7522. tube_color := projectM["tube_color"].(string)
  7523. var tubeColor = "试管颜色"
  7524. var tube_color_id int64
  7525. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7526. if len(tube_color) != 0 {
  7527. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7528. if errcodetube == gorm.ErrRecordNotFound {
  7529. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7530. dataconfig := models.DictDataconfig{
  7531. ParentId: tubeColorConfig.ID,
  7532. Module: "system",
  7533. OrgId: orgId,
  7534. Name: tube_color,
  7535. FieldName: "",
  7536. Value: tubeConfig.Value + 1,
  7537. CreatedTime: "",
  7538. UpdatedTime: "",
  7539. CreateUserId: adminUser.AdminUser.Id,
  7540. Status: 1,
  7541. Remark: "",
  7542. DeleteIdSystem: 0,
  7543. Title: "",
  7544. Content: "",
  7545. Order: 0,
  7546. Code: "",
  7547. }
  7548. service.CreatedDicConfig(&dataconfig)
  7549. }
  7550. }
  7551. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7552. for _, it := range tubeColorList {
  7553. if tube_color == it.Name {
  7554. tube_color_id = int64(it.Value)
  7555. }
  7556. }
  7557. project.TubeColor = tube_color_id
  7558. single_dose := projectM["single_dose"].(string)
  7559. project.SingleDose = single_dose
  7560. execution_frequency := projectM["execution_frequency"].(string)
  7561. project.ExecutionFrequency = execution_frequency
  7562. delivery_way := projectM["delivery_way"].(string)
  7563. project.DeliveryWay = delivery_way
  7564. number_days := projectM["number_days"].(string)
  7565. project.NumberDays = number_days
  7566. total := projectM["total"].(string)
  7567. project.Total = total
  7568. medical_status := int64(projectM["medical_status"].(float64))
  7569. project.MedicalStatus = medical_status
  7570. category := int64(projectM["category"].(float64))
  7571. project.Category = category
  7572. specail_project := int64(projectM["specail_project"].(float64))
  7573. project.SpecailProject = specail_project
  7574. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7575. project.SocialSecurityDirectoryCode = social_security_directory_code
  7576. remark := projectM["remark"].(string)
  7577. project.Remark = remark
  7578. record_date := projectM["record_date"].(string)
  7579. timeLayout := "2006-01-02"
  7580. loc, _ := time.LoadLocation("Local")
  7581. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7582. project.RecordDate = theTime.Unix()
  7583. projectList = append(projectList, &project)
  7584. }
  7585. export_time := time.Now().Unix()
  7586. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7587. if len(projectList) > 0 {
  7588. for _, item := range projectList {
  7589. project := models.HisProject{
  7590. ProjectName: item.ProjectName,
  7591. Price: item.Price,
  7592. Unit: item.Unit,
  7593. CostClassify: item.CostClassify,
  7594. ExecutiveSection: item.ExecutiveSection,
  7595. MedicalCoverage: item.MedicalCoverage,
  7596. UserOrgId: orgId,
  7597. Status: 1,
  7598. CreatedTime: time.Now().Unix(),
  7599. Pinyin: item.Pinyin,
  7600. Wubi: item.Wubi,
  7601. StatisticalClassification: item.StatisticalClassification,
  7602. DiseaseDirectory: item.DiseaseDirectory,
  7603. IsRecord: item.IsRecord,
  7604. MedicalCode: item.MedicalCode,
  7605. TubeColor: item.TubeColor,
  7606. SingleDose: item.SingleDose,
  7607. DeliveryWay: item.DeliveryWay,
  7608. NumberDays: item.NumberDays,
  7609. Total: item.Total,
  7610. Category: item.Category,
  7611. MedicalStatus: item.MedicalStatus,
  7612. SpecailProject: item.SpecailProject,
  7613. RecordDate: item.RecordDate,
  7614. Remark: item.Remark,
  7615. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7616. ExecutionFrequency: item.ExecutionFrequency,
  7617. }
  7618. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7619. if errcodeproject == gorm.ErrRecordNotFound {
  7620. service.CreateProjectInfomation(&project)
  7621. } else if errcodeproject == nil {
  7622. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7623. }
  7624. log := models.ExportLog{
  7625. LogType: 6,
  7626. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7627. TotalNum: int64(len(total_goods)),
  7628. FailNum: int64(len(errLogs)),
  7629. SuccessNum: int64(len(projectList)),
  7630. CreateTime: time.Now().Unix(),
  7631. UpdateTime: time.Now().Unix(),
  7632. ExportTime: export_time,
  7633. Status: 1,
  7634. }
  7635. service.CreateExportLog(&log)
  7636. c.ServeSuccessJSON(map[string]interface{}{
  7637. "msg": "导入成功",
  7638. "total_num": len(total_goods),
  7639. "success_num": len(projectList),
  7640. "fail_num": int64(len(errLogs)),
  7641. })
  7642. }
  7643. } else {
  7644. log := models.ExportLog{
  7645. LogType: 6,
  7646. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7647. TotalNum: int64(len(total_goods)),
  7648. FailNum: int64(len(errLogs)),
  7649. SuccessNum: int64(len(projectList)),
  7650. CreateTime: time.Now().Unix(),
  7651. UpdateTime: time.Now().Unix(),
  7652. ExportTime: export_time,
  7653. Status: 1,
  7654. }
  7655. service.CreateExportLog(&log)
  7656. c.ServeSuccessJSON(map[string]interface{}{
  7657. "msg": "导入成功",
  7658. "total_num": len(total_goods),
  7659. "success_num": len(projectList),
  7660. "fail_num": int64(len(errLogs)),
  7661. })
  7662. }
  7663. }
  7664. //func (this *HisApiController) EditProjectInformation(){
  7665. //
  7666. // id, _ := this.GetInt64("id")
  7667. // project_team := this.GetString("project_team")
  7668. // price := this.GetString("price")
  7669. // price_float, _ := strconv.ParseFloat(price, 64)
  7670. // pinyin := this.GetString("pinyin")
  7671. // wubi := this.GetString("wubi")
  7672. // tube_color, _ := this.GetInt64("tube_color")
  7673. // team_type, _ := this.GetInt64("team_type")
  7674. // remark := this.GetString("remark")
  7675. // ids := this.GetString("ids")
  7676. // item_id := this.GetString("item_id")
  7677. // projectTeam := models.XtHisProjectTeam{
  7678. // ProjectTeam: project_team,
  7679. // Price: price_float,
  7680. // Pinyin: pinyin,
  7681. // Wubi: wubi,
  7682. // TubeColor: tube_color,
  7683. // TeamType: team_type,
  7684. // Remark: remark,
  7685. // ProjectId: ids,
  7686. // ItemId: item_id,
  7687. // }
  7688. //
  7689. //
  7690. // dataBody := make(map[string]interface{}, 0)
  7691. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7692. // if err != nil {
  7693. // utils.ErrorLog(err.Error())
  7694. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7695. // return
  7696. // }
  7697. //
  7698. // err = service.UpdatedProjectTeam(id, &projectTeam)
  7699. //
  7700. //
  7701. // if err != nil {
  7702. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7703. // return
  7704. // }
  7705. //
  7706. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  7707. // infos, _ := dataBody["info"].([]interface{})
  7708. // if len(infos) > 0 {
  7709. // var ids []string
  7710. //
  7711. // for _, item := range infos {
  7712. // items := item.(map[string]interface{})
  7713. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  7714. // utils.ErrorLog("id")
  7715. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7716. // return
  7717. // }
  7718. // id := int64(items["id"].(float64))
  7719. //
  7720. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7721. // utils.ErrorLog("type")
  7722. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7723. // return
  7724. // }
  7725. // types := int64(items["type"].(float64))
  7726. //
  7727. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  7728. // utils.ErrorLog("number")
  7729. // }
  7730. //
  7731. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  7732. //
  7733. // projectList := models.XtHisProjectList{
  7734. // Number: number,
  7735. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  7736. // ProjectId: id,
  7737. // Status: 1,
  7738. // CreatedTime: time.Now().Unix(),
  7739. // UpdatedTime: time.Now().Unix(),
  7740. // TeamId: projectTeam.ID,
  7741. // Type: types,
  7742. // }
  7743. // list := projectList
  7744. //
  7745. // service.CreateProjectList(&list)
  7746. //
  7747. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  7748. //
  7749. // }
  7750. // ids_str := strings.Join(ids, ",")
  7751. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  7752. // service.SaveProjectTeam(&projectTeam)
  7753. // this.ServeSuccessJSON(map[string]interface{}{
  7754. // "projectTeam": projectTeam,
  7755. // })
  7756. // }
  7757. // }
  7758. //}
  7759. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  7760. name := c.GetString("name")
  7761. mode_id, _ := c.GetInt64("mode", 0)
  7762. types, _ := c.GetInt64("type", 0)
  7763. patient_id, _ := c.GetInt64("patient_id", 0)
  7764. types = 1
  7765. adminInfo := c.GetAdminUserInfo()
  7766. template := &models.HisPrescriptionTemplate{
  7767. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7768. PatientId: patient_id,
  7769. Type: types,
  7770. Status: 1,
  7771. Ctime: time.Now().Unix(),
  7772. Mtime: time.Now().Unix(),
  7773. Name: name,
  7774. Mode: mode_id,
  7775. }
  7776. dataBody := make(map[string]interface{}, 0)
  7777. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7778. if err != nil {
  7779. utils.ErrorLog(err.Error())
  7780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7781. return
  7782. }
  7783. err = service.CreateHisPrescriptionTemplate(template)
  7784. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  7785. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  7786. if len(prescriptions) > 0 {
  7787. for _, item := range prescriptions {
  7788. items := item.(map[string]interface{})
  7789. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7790. utils.ErrorLog("type")
  7791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7792. return
  7793. }
  7794. types := int64(items["type"].(float64))
  7795. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  7796. utils.ErrorLog("med_type")
  7797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7798. return
  7799. }
  7800. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  7801. ctime := time.Now().Unix()
  7802. prescription := &models.HisPrescriptionInfoTemplate{
  7803. PatientId: patient_id,
  7804. UserOrgId: adminInfo.CurrentOrgId,
  7805. Ctime: ctime,
  7806. Mtime: ctime,
  7807. Type: types,
  7808. Modifier: adminInfo.AdminUser.Id,
  7809. Creator: adminInfo.AdminUser.Id,
  7810. Status: 1,
  7811. PTemplateId: template.ID,
  7812. MedType: med_type,
  7813. }
  7814. service.CreateHisPrescriptionInfoTemplate(prescription)
  7815. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  7816. advices := items["advices"].([]interface{})
  7817. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  7818. ctime := time.Now().Unix()
  7819. mtime := ctime
  7820. if len(advices) > 0 {
  7821. for _, advice := range advices {
  7822. var s models.HisPrescriptionAdviceTemplate
  7823. s.PrescriptionId = prescription.ID
  7824. s.AdviceType = 2
  7825. s.StopState = 2
  7826. s.ExecutionState = 2
  7827. s.Status = 1
  7828. s.UserOrgId = adminInfo.CurrentOrgId
  7829. s.CreatedTime = ctime
  7830. s.UpdatedTime = mtime
  7831. s.PatientId = patient_id
  7832. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  7833. if errcode > 0 {
  7834. c.ServeFailJSONWithSGJErrorCode(errcode)
  7835. return
  7836. }
  7837. service.CreateHisPrescriptionAdviceTemplate(&s)
  7838. }
  7839. }
  7840. }
  7841. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  7842. projects := items["project"].([]interface{})
  7843. if len(projects) > 0 {
  7844. for _, project := range projects {
  7845. var p models.HisPrescriptionProjectTemplate
  7846. p.PrescriptionId = prescription.ID
  7847. p.Ctime = time.Now().Unix()
  7848. p.Mtime = time.Now().Unix()
  7849. p.PatientId = patient_id
  7850. p.UserOrgId = adminInfo.CurrentOrgId
  7851. p.Status = 1
  7852. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  7853. if errcode > 0 {
  7854. c.ServeFailJSONWithSGJErrorCode(errcode)
  7855. return
  7856. }
  7857. service.CreateHisPrescriptionProjectTemplate(&p)
  7858. }
  7859. }
  7860. }
  7861. }
  7862. c.ServeSuccessJSON(map[string]interface{}{
  7863. "msg": "创建成功",
  7864. })
  7865. }
  7866. }
  7867. }
  7868. func (c *HisApiController) PreSettle() {
  7869. id, _ := c.GetInt64("id")
  7870. record_time := c.GetString("record_time")
  7871. his_patient_id, _ := c.GetInt64("his_patient_id")
  7872. timeLayout := "2006-01-02"
  7873. loc, _ := time.LoadLocation("Local")
  7874. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7875. diagnosis_id := c.GetString("diagnosis")
  7876. sick_type, _ := c.GetInt64("sick_type")
  7877. reg_type, _ := c.GetInt64("p_type")
  7878. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  7879. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7880. if err != nil {
  7881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7882. return
  7883. }
  7884. recordDateTime := theTime.Unix()
  7885. adminUser := c.GetAdminUserInfo()
  7886. var prescriptions []*models.HisPrescription
  7887. var start_time int64
  7888. var end_time int64
  7889. ids_str := c.GetString("ids")
  7890. ids_arr := strings.Split(ids_str, ",")
  7891. fmt.Println(reg_type)
  7892. if settle_accounts_type == 1 { //日结
  7893. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7894. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  7895. } else {
  7896. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  7897. }
  7898. fmt.Println(prescriptions)
  7899. } else { //月结
  7900. start_time_str := c.GetString("start_time")
  7901. end_time_str := c.GetString("end_time")
  7902. timeLayout := "2006-01-02"
  7903. loc, _ := time.LoadLocation("Local")
  7904. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7905. if err != nil {
  7906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7907. return
  7908. }
  7909. recordStartTime := theStartTime.Unix()
  7910. start_time = recordStartTime
  7911. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7912. if err != nil {
  7913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7914. return
  7915. }
  7916. recordEndTime := theEndTime.Unix()
  7917. end_time = recordEndTime
  7918. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  7919. }
  7920. if reg_type == 1111 || reg_type == 1112 {
  7921. reg_type = 11
  7922. }
  7923. timestamp := time.Now().Unix()
  7924. tempTime := time.Unix(timestamp, 0)
  7925. timeFormat := tempTime.Format("20060102150405")
  7926. chrgBchno := rand.Intn(100000) + 10000
  7927. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7928. strconv.FormatInt(his.PatientId, 10)
  7929. var ids []int64
  7930. for _, item := range prescriptions {
  7931. ids = append(ids, item.ID)
  7932. }
  7933. fmt.Println(ids)
  7934. var total float64
  7935. for _, item := range prescriptions {
  7936. fmt.Println(item)
  7937. if item.Type == 1 { //药品
  7938. for _, subItem := range item.HisDoctorAdviceInfo {
  7939. total = total + (subItem.Price * subItem.PrescribingNumber)
  7940. }
  7941. }
  7942. if item.Type == 2 { //项目
  7943. for _, subItem := range item.HisPrescriptionProject {
  7944. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7945. total = total + (subItem.Price * cnt)
  7946. }
  7947. }
  7948. for _, subItem := range item.HisAdditionalCharge {
  7949. total = total + (subItem.Price * float64(subItem.Count))
  7950. }
  7951. }
  7952. allTotal := fmt.Sprintf("%.2f", total)
  7953. totals, _ := strconv.ParseFloat(allTotal, 64)
  7954. order := &models.HisOrder{
  7955. UserOrgId: adminUser.CurrentOrgId,
  7956. HisPatientId: his.ID,
  7957. PatientId: id,
  7958. SettleAccountsDate: recordDateTime,
  7959. Ctime: time.Now().Unix(),
  7960. Mtime: time.Now().Unix(),
  7961. Status: 1,
  7962. OrderStatus: 1,
  7963. MdtrtId: his.Number,
  7964. Number: chrg_bchno,
  7965. MedfeeSumamt: totals,
  7966. SettleEndTime: end_time,
  7967. SettleStartTime: start_time,
  7968. SettleType: settle_accounts_type,
  7969. PsnPartAmt: totals,
  7970. PsnCashPay: totals,
  7971. PType: 2,
  7972. IsPre: 1,
  7973. MedType: strconv.Itoa(int(reg_type)),
  7974. Diagnosis: diagnosis_id,
  7975. }
  7976. err = service.CreateOrder(order)
  7977. if err != nil {
  7978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7979. return
  7980. }
  7981. var customs []*Custom
  7982. for _, item := range prescriptions {
  7983. fmt.Println(item.Type)
  7984. if item.Type == 1 { //药品
  7985. for _, subItem := range item.HisDoctorAdviceInfo {
  7986. cus := &Custom{
  7987. AdviceId: subItem.ID,
  7988. ProjectId: 0,
  7989. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  7990. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  7991. FeedetlSn: subItem.FeedetlSn,
  7992. Price: fmt.Sprintf("%.2f", subItem.Price),
  7993. MedListCodg: subItem.MedListCodg,
  7994. Type: 1,
  7995. }
  7996. customs = append(customs, cus)
  7997. }
  7998. }
  7999. if item.Type == 2 { //项目
  8000. for _, subItem := range item.HisPrescriptionProject {
  8001. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8002. cus := &Custom{
  8003. AdviceId: 0,
  8004. ProjectId: subItem.ID,
  8005. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8006. Cut: fmt.Sprintf("%.2f", cnt),
  8007. FeedetlSn: subItem.FeedetlSn,
  8008. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8009. MedListCodg: subItem.MedListCodg,
  8010. Type: 2,
  8011. }
  8012. customs = append(customs, cus)
  8013. }
  8014. }
  8015. for _, item := range item.HisAdditionalCharge {
  8016. cus := &Custom{
  8017. ItemId: item.ID,
  8018. AdviceId: 0,
  8019. ProjectId: 0,
  8020. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8021. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8022. FeedetlSn: item.FeedetlSn,
  8023. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8024. MedListCodg: item.XtHisAddtionConfig.Code,
  8025. Type: 3,
  8026. }
  8027. customs = append(customs, cus)
  8028. }
  8029. }
  8030. fmt.Println(customs)
  8031. for _, item := range customs {
  8032. var advice_id int64 = 0
  8033. var project_id int64 = 0
  8034. var item_id int64 = 0
  8035. var types int64 = 0
  8036. if item.Type == 1 {
  8037. advice_id = item.AdviceId
  8038. project_id = 0
  8039. item_id = 0
  8040. } else if item.Type == 2 {
  8041. advice_id = 0
  8042. item_id = 0
  8043. project_id = item.ProjectId
  8044. } else if item.Type == 3 {
  8045. advice_id = 0
  8046. item_id = item.ItemId
  8047. project_id = 0
  8048. }
  8049. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8050. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8051. pric, _ := strconv.ParseFloat(item.Price, 32)
  8052. info := &models.HisOrderInfo{
  8053. OrderNumber: order.Number,
  8054. UploadDate: time.Now().Unix(),
  8055. AdviceId: advice_id,
  8056. DetItemFeeSumamt: detItemFeeSumamt,
  8057. Cnt: cut,
  8058. Pric: pric,
  8059. PatientId: id,
  8060. Status: 1,
  8061. Mtime: time.Now().Unix(),
  8062. Ctime: time.Now().Unix(),
  8063. UserOrgId: adminUser.CurrentOrgId,
  8064. HisPatientId: his.ID,
  8065. OrderId: order.ID,
  8066. ProjectId: project_id,
  8067. Type: types,
  8068. ItemId: item_id,
  8069. }
  8070. service.CreateOrderInfo(info)
  8071. }
  8072. his.SickType = sick_type
  8073. service.UpdataHisPateint(&his)
  8074. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8075. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8076. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8077. if err == nil {
  8078. c.ServeSuccessJSON(map[string]interface{}{
  8079. "msg": "结算成功",
  8080. })
  8081. }
  8082. }
  8083. type CustomOrderInfo struct {
  8084. Name string
  8085. Spec string
  8086. Unit string
  8087. Count float64
  8088. Price float64
  8089. Total float64
  8090. }
  8091. func (c *HisApiController) GetPrivateExpensesInfo() {
  8092. order_id, _ := c.GetInt64("id", 0)
  8093. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8094. order, _ := service.GetHisOrderByID(order_id)
  8095. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8096. if order.ID == 0 {
  8097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8098. return
  8099. }
  8100. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8101. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8102. org_id := c.GetAdminUserInfo().CurrentOrgId
  8103. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8104. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8105. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8106. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8107. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8108. var orderInfos_four []*models.HisOrderInfoTwo
  8109. for _, item := range orderInfos_three {
  8110. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8111. item.HisPrescriptionProject.IsCheckTeam = 1
  8112. orderInfos_four = append(orderInfos_four, item)
  8113. }
  8114. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8115. item.HisPrescriptionProject.IsCheckTeam = 2
  8116. orderInfos_two = append(orderInfos_two, item)
  8117. }
  8118. }
  8119. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8120. var cus_slice []CustomOrderInfo
  8121. for _, item := range new_order_info {
  8122. var cus CustomOrderInfo
  8123. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8124. cus.Unit = ""
  8125. cus.Spec = ""
  8126. var total float64
  8127. for _, subItem := range orderInfos_four {
  8128. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8129. total = total + subItem.DetItemFeeSumamt
  8130. fmt.Println(subItem.DetItemFeeSumamt)
  8131. }
  8132. }
  8133. cus.Count = 1
  8134. cus.Total = total
  8135. cus_slice = append(cus_slice, cus)
  8136. }
  8137. orderInfos = append(orderInfos, orderInfos_two...)
  8138. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8139. orderInfos = append(orderInfos, orderInfos_three...)
  8140. }
  8141. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8142. c.ServeSuccessJSON(map[string]interface{}{
  8143. "order": order,
  8144. "order_info": orderInfos,
  8145. "patient": patient,
  8146. "admin_info": adminInfo,
  8147. "his": his,
  8148. "current_admin": role,
  8149. "org_config": miConfig,
  8150. "new_order_info": cus_slice,
  8151. })
  8152. }
  8153. func (this *HisApiController) ChangeMedType() {
  8154. med_type := this.GetString("med_type")
  8155. old_med_type := this.GetString("old_med_type")
  8156. ids := this.GetString("ids")
  8157. settle_type, _ := this.GetInt64("settle_type")
  8158. start_time := this.GetString("start_time")
  8159. end_time := this.GetString("end_time")
  8160. ids_arr := strings.Split(ids, ",")
  8161. if settle_type == 1 { //日结
  8162. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8163. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8164. prescription.MedType = med_type
  8165. err := service.SaveHisPrescription(&prescription)
  8166. if err == nil {
  8167. this.ServeSuccessJSON(map[string]interface{}{
  8168. "msg": "修改成功",
  8169. })
  8170. } else {
  8171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8172. return
  8173. }
  8174. } else if settle_type == 2 {
  8175. timeLayout := "2006-01-02"
  8176. loc, _ := time.LoadLocation("Local")
  8177. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8178. if err != nil {
  8179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8180. return
  8181. }
  8182. recordStartTime := theStartTime.Unix()
  8183. start_time_timestamp := recordStartTime
  8184. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8185. if err != nil {
  8186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8187. return
  8188. }
  8189. recordEndTime := theEndTime.Unix()
  8190. end_time_timestamp := recordEndTime
  8191. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8192. if updateErr == nil {
  8193. this.ServeSuccessJSON(map[string]interface{}{
  8194. "msg": "修改成功",
  8195. })
  8196. } else {
  8197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8198. return
  8199. }
  8200. }
  8201. }
  8202. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8203. patient_id, _ := c.GetInt64("patient_id")
  8204. his_patient_id, _ := c.GetInt64("his_patient_id")
  8205. record_date := c.GetString("record_date")
  8206. start_time := c.GetString("start_time")
  8207. end_time := c.GetString("end_time")
  8208. order_status, _ := c.GetInt64("type", 0)
  8209. p_type, _ := c.GetInt64("p_type", 0)
  8210. order_id, _ := c.GetInt64("order_id", 0)
  8211. timeLayout := "2006-01-02"
  8212. loc, _ := time.LoadLocation("Local")
  8213. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8214. if err != nil {
  8215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8216. return
  8217. }
  8218. recordDateTime := theTime.Unix()
  8219. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8220. if err != nil {
  8221. }
  8222. startRecordDateTime := startTime.Unix()
  8223. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8224. if err != nil {
  8225. }
  8226. endRecordDateTime := endTime.Unix()
  8227. admin := c.GetAdminUserInfo()
  8228. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8229. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8230. order, _ := service.GetHisOrderByID(order_id)
  8231. var monthPrescriptions []*models.HisPrescription
  8232. if order_status == 1 || order_status == 0 {
  8233. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8234. } else if order_status == 2 {
  8235. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8236. }
  8237. var settle_total float64
  8238. for _, item := range monthPrescriptions {
  8239. if len(item.HisPrescriptionProject) > 0 {
  8240. for _, subItem := range item.HisPrescriptionProject {
  8241. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8242. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8243. settle_total = settle_total + total
  8244. }
  8245. }
  8246. if len(item.HisDoctorAdviceInfo) > 0 {
  8247. for _, subItem := range item.HisDoctorAdviceInfo {
  8248. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8249. settle_total = settle_total + total
  8250. }
  8251. }
  8252. }
  8253. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8254. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8255. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8256. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8257. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8258. //获取所有科室信息
  8259. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8260. c.ServeSuccessJSON(map[string]interface{}{
  8261. "his_info": his_patient_info,
  8262. "xt_info": xt_patient_info,
  8263. "case_history": case_history,
  8264. "info": patientPrescriptionInfo,
  8265. "last_info": lastPatientPrescriptionInfo,
  8266. "month_prescriptions": monthPrescriptions,
  8267. "order": order,
  8268. "doctors": doctors,
  8269. "department": department,
  8270. "settle_total": settle_total,
  8271. })
  8272. return
  8273. }
  8274. func (c *HisApiController) GetHisMonthPatientInfo() {
  8275. patient_id, _ := c.GetInt64("patient_id")
  8276. his_patient_id, _ := c.GetInt64("his_patient_id")
  8277. record_date := c.GetString("record_date")
  8278. number := c.GetString("number")
  8279. start_time := c.GetString("start_time")
  8280. end_time := c.GetString("end_time")
  8281. p_type, _ := c.GetInt64("p_type")
  8282. timeLayout := "2006-01-02"
  8283. loc, _ := time.LoadLocation("Local")
  8284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8285. if err != nil {
  8286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8287. return
  8288. }
  8289. recordDateTime := theTime.Unix()
  8290. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8291. if err != nil {
  8292. }
  8293. startRecordDateTime := startTime.Unix()
  8294. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8295. if err != nil {
  8296. }
  8297. endRecordDateTime := endTime.Unix()
  8298. admin := c.GetAdminUserInfo()
  8299. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8300. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8301. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8302. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8303. var settle_total float64
  8304. for _, item := range monthPrescriptions {
  8305. if len(item.HisPrescriptionProject) > 0 {
  8306. for _, subItem := range item.HisPrescriptionProject {
  8307. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8308. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8309. settle_total = settle_total + total
  8310. }
  8311. }
  8312. if len(item.HisDoctorAdviceInfo) > 0 {
  8313. for _, subItem := range item.HisDoctorAdviceInfo {
  8314. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8315. settle_total = settle_total + total
  8316. }
  8317. }
  8318. }
  8319. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8320. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8321. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8322. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8323. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8324. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8325. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8326. //获取所有科室信息
  8327. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8328. c.ServeSuccessJSON(map[string]interface{}{
  8329. "his_info": his_patient_info,
  8330. "xt_info": xt_patient_info,
  8331. "case_history": case_history,
  8332. "info": patientPrescriptionInfo,
  8333. "month_prescriptions": monthPrescriptions,
  8334. "order": order,
  8335. "doctors": doctors,
  8336. "department": department,
  8337. "count": count,
  8338. "drugStockConfig": drugStockConfig,
  8339. "last_info": lastPatientPrescriptionInfo,
  8340. "settle_total": settle_total,
  8341. })
  8342. return
  8343. }
  8344. func (c *HisApiController) GetAllOrder() {
  8345. org_id := c.GetAdminUserInfo().CurrentOrgId
  8346. orders, _ := service.GetNewHisOrderList(org_id)
  8347. c.ServeSuccessJSON(map[string]interface{}{
  8348. "order": orders,
  8349. })
  8350. return
  8351. }
  8352. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8353. newArr = make([]*models.HisOrderInfoTwo, 0)
  8354. for i := 0; i < len(arr); i++ {
  8355. repeat := false
  8356. for j := i + 1; j < len(arr); j++ {
  8357. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8358. repeat = true
  8359. break
  8360. }
  8361. }
  8362. if !repeat {
  8363. newArr = append(newArr, arr[i])
  8364. }
  8365. }
  8366. return
  8367. }
  8368. //修改处方退库操作 参数传修改之前的处方数据
  8369. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8370. if advice.ExecutionState == 1 {
  8371. //查询该病人该药品是否有库存记录
  8372. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8373. if errcode == gorm.ErrRecordNotFound {
  8374. } else {
  8375. //退库
  8376. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8377. if advice.PrescribingNumberUnit == drug.MinUnit {
  8378. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8379. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8380. //退库
  8381. warehouseInfo := models.DrugWarehouseInfo{
  8382. StockMinNumber: prescribingNumber,
  8383. }
  8384. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8385. operation_time := time.Now().Unix()
  8386. creater := advice.AdviceDoctor
  8387. ctime := time.Now().Unix()
  8388. timeStr := time.Now().Format("2006-01-02")
  8389. timeArr := strings.Split(timeStr, "-")
  8390. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8391. total = total + 1
  8392. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8393. cancelStock := models.DrugCancelStock{
  8394. OrderNumber: orderNumber,
  8395. OperaTime: operation_time,
  8396. OrgId: advice.UserOrgId,
  8397. Creater: creater,
  8398. Ctime: ctime,
  8399. Status: 1,
  8400. ReturnTime: advice.AdviceDate,
  8401. Dealer: info.Dealer,
  8402. Manufacturer: info.Manufacturer,
  8403. Type: 1,
  8404. }
  8405. service.AddSigleDrugCancelStock(&cancelStock)
  8406. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8407. dealer, _ := service.GetDealerById(info.Dealer)
  8408. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8409. cancelStockInfo := models.DrugCancelStockInfo{
  8410. OrderNumber: cancelInfo.OrderNumber,
  8411. CancelStockId: cancelInfo.ID,
  8412. DrugId: info.DrugId,
  8413. Count: info.Count,
  8414. Status: 1,
  8415. Ctime: ctime,
  8416. OrgId: advice.UserOrgId,
  8417. Type: 1,
  8418. Manufacturer: manufactureName.ManufacturerName,
  8419. Dealer: dealer.DealerName,
  8420. Total: 0,
  8421. RetailPrice: info.RetailPrice,
  8422. RetailTotalPrice: info.RetailTotalPrice,
  8423. Price: info.Price,
  8424. RegisterAccount: "",
  8425. Remark: info.Remark,
  8426. BatchNumber: info.BatchNumber,
  8427. MaxUnit: info.CountUnit,
  8428. ProductDate: info.ProductDate,
  8429. ExpiryDate: info.ExpiryDate,
  8430. BatchNumberId: info.WarehouseInfoId,
  8431. }
  8432. flow := models.DrugFlow{
  8433. WarehousingId: 0,
  8434. DrugId: info.DrugId,
  8435. Number: "",
  8436. BatchNumber: info.BatchNumber,
  8437. Count: info.Count,
  8438. UserOrgId: advice.UserOrgId,
  8439. PatientId: 0,
  8440. SystemTime: ctime,
  8441. ConsumableType: 4,
  8442. IsSys: 0,
  8443. WarehousingOrder: "",
  8444. WarehouseOutId: 0,
  8445. WarehouseOutOrderNumber: "",
  8446. IsEdit: 0,
  8447. CancelStockId: cancelStock.ID,
  8448. CancelOrderNumber: cancelStock.OrderNumber,
  8449. Manufacturer: info.Manufacturer,
  8450. Dealer: info.Dealer,
  8451. Creator: advice.UserOrgId,
  8452. UpdateCreator: 0,
  8453. Status: 1,
  8454. Ctime: time.Now().Unix(),
  8455. Mtime: 0,
  8456. Price: info.Price,
  8457. WarehousingDetailId: 0,
  8458. WarehouseOutDetailId: 0,
  8459. CancelOutDetailId: 0,
  8460. ExpireDate: info.ExpiryDate,
  8461. ProductDate: info.ProductDate,
  8462. MaxUnit: info.CountUnit,
  8463. MinUnit: "",
  8464. }
  8465. service.CreatedCancelStock(cancelStockInfo)
  8466. service.CreateDrugFlowOne(flow)
  8467. } else {
  8468. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8469. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8470. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8471. warehouseInfo := models.DrugWarehouseInfo{
  8472. StockMinNumber: prescribingNumber,
  8473. }
  8474. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8475. }
  8476. operation_time := time.Now().Unix()
  8477. creater := advice.AdviceDoctor
  8478. ctime := time.Now().Unix()
  8479. timeStr := time.Now().Format("2006-01-02")
  8480. timeArr := strings.Split(timeStr, "-")
  8481. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8482. total = total + 1
  8483. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8484. cancelStock := models.DrugCancelStock{
  8485. OrderNumber: orderNumber,
  8486. OperaTime: operation_time,
  8487. OrgId: advice.UserOrgId,
  8488. Creater: creater,
  8489. Ctime: ctime,
  8490. Status: 1,
  8491. ReturnTime: advice.AdviceDate,
  8492. Dealer: info.Dealer,
  8493. Manufacturer: info.Manufacturer,
  8494. Type: 1,
  8495. }
  8496. service.AddSigleDrugCancelStock(&cancelStock)
  8497. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8498. dealer, _ := service.GetDealerById(info.Dealer)
  8499. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8500. cancelStockInfo := models.DrugCancelStockInfo{
  8501. OrderNumber: cancelInfo.OrderNumber,
  8502. CancelStockId: cancelInfo.ID,
  8503. DrugId: info.DrugId,
  8504. Count: info.Count,
  8505. Status: 1,
  8506. Ctime: ctime,
  8507. OrgId: advice.UserOrgId,
  8508. Type: 1,
  8509. Manufacturer: manufactureName.ManufacturerName,
  8510. Dealer: dealer.DealerName,
  8511. Total: 0,
  8512. RetailPrice: info.RetailPrice,
  8513. RetailTotalPrice: info.RetailTotalPrice,
  8514. Price: info.Price,
  8515. RegisterAccount: "",
  8516. Remark: info.Remark,
  8517. BatchNumber: info.BatchNumber,
  8518. MaxUnit: info.CountUnit,
  8519. ProductDate: info.ProductDate,
  8520. ExpiryDate: info.ExpiryDate,
  8521. BatchNumberId: info.WarehouseInfoId,
  8522. }
  8523. flow := models.DrugFlow{
  8524. WarehousingId: 0,
  8525. DrugId: info.DrugId,
  8526. Number: "",
  8527. BatchNumber: info.BatchNumber,
  8528. Count: info.Count,
  8529. UserOrgId: advice.UserOrgId,
  8530. PatientId: 0,
  8531. SystemTime: ctime,
  8532. ConsumableType: 4,
  8533. IsSys: 0,
  8534. WarehousingOrder: "",
  8535. WarehouseOutId: 0,
  8536. WarehouseOutOrderNumber: "",
  8537. IsEdit: 0,
  8538. CancelStockId: cancelStock.ID,
  8539. CancelOrderNumber: cancelStock.OrderNumber,
  8540. Manufacturer: info.Manufacturer,
  8541. Dealer: info.Dealer,
  8542. Creator: advice.AdviceDoctor,
  8543. UpdateCreator: 0,
  8544. Status: 1,
  8545. Ctime: time.Now().Unix(),
  8546. Mtime: 0,
  8547. Price: info.Price,
  8548. WarehousingDetailId: 0,
  8549. WarehouseOutDetailId: 0,
  8550. CancelOutDetailId: 0,
  8551. ExpireDate: info.ExpiryDate,
  8552. ProductDate: info.ProductDate,
  8553. MaxUnit: info.CountUnit,
  8554. MinUnit: "",
  8555. }
  8556. service.CreatedCancelStock(cancelStockInfo)
  8557. service.CreateDrugFlowOne(flow)
  8558. }
  8559. }
  8560. }
  8561. return err
  8562. }
  8563. func (this *HisApiController) DeleteNCDS() {
  8564. id, _ := this.GetInt64("id", 0)
  8565. if id > 0 {
  8566. service.DeletePsnNCDSRecordById(id)
  8567. this.ServeSuccessJSON(map[string]interface{}{
  8568. "msg": "删除成功",
  8569. })
  8570. } else {
  8571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8572. return
  8573. }
  8574. }
  8575. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8576. id, _ := c.GetInt64("id")
  8577. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8578. c.ServeSuccessJSON(map[string]interface{}{
  8579. "advice": advice,
  8580. })
  8581. return
  8582. }
  8583. func (c *HisApiController) GetHisMonthChargePatientList() {
  8584. record_date := c.GetString("record_date")
  8585. start_time := c.GetString("start_time")
  8586. end_time := c.GetString("end_time")
  8587. timeLayout := "2006-01-02"
  8588. loc, _ := time.LoadLocation("Local")
  8589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8590. if err != nil {
  8591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8592. return
  8593. }
  8594. if err != nil {
  8595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8596. return
  8597. }
  8598. recordDateTime := theTime.Unix()
  8599. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8600. if err != nil {
  8601. }
  8602. startRecordDateTime := startTime.Unix()
  8603. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8604. if err != nil {
  8605. }
  8606. endRecordDateTime := endTime.Unix()
  8607. adminInfo := c.GetAdminUserInfo()
  8608. var tempMonthChargePatients []*service.MonthChargePatients
  8609. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8610. for _, item := range tempPatients {
  8611. //过滤没有处方的
  8612. if len(item.HisPrescription) == 0 {
  8613. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8614. }
  8615. }
  8616. c.ServeSuccessJSON(map[string]interface{}{
  8617. "list": tempMonthChargePatients,
  8618. })
  8619. }