his_api_controller.go 441KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. }
  90. func (c *HisApiController) CheckHisPatient() {
  91. record_date := c.GetString("record_date")
  92. patient_id, _ := c.GetInt64("patient_id")
  93. timeLayout := "2006-01-02"
  94. loc, _ := time.LoadLocation("Local")
  95. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  96. if err != nil {
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. recordDateTime := theTime.Unix()
  101. adminInfo := c.GetAdminUserInfo()
  102. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  103. if len(patients) > 1 {
  104. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  105. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  106. c.ServeSuccessJSON(map[string]interface{}{
  107. "status": 1,
  108. "msg": "关联",
  109. "ps": ps,
  110. "his_patient_id": patients[len(patients)-1].ID,
  111. "patient_id": patients[len(patients)-1].PatientId,
  112. })
  113. } else {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 0,
  116. "msg": "无需关联",
  117. })
  118. }
  119. } else {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 0,
  122. "msg": "无需关联",
  123. })
  124. return
  125. }
  126. }
  127. func (c *HisApiController) AssociationHisPrescription() {
  128. record_date := c.GetString("record_date")
  129. his_patient_id, _ := c.GetInt64("his_patient_id")
  130. patient_id, _ := c.GetInt64("patient_id")
  131. p_ids := c.GetString("p_ids")
  132. p_ids_arr := strings.Split(p_ids, ",")
  133. timeLayout := "2006-01-02"
  134. loc, _ := time.LoadLocation("Local")
  135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  136. if err != nil {
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. recordDateTime := theTime.Unix()
  141. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  142. if his_patient_id == 0 || his_patient.ID == 0 {
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  147. if err == nil {
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "msg": "关联处方成功",
  150. })
  151. return
  152. } else {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  154. return
  155. }
  156. }
  157. //func (c *HisApiController) AssociationHisPrescription() {
  158. // record_date, _ := c.GetInt64("record_date")
  159. // his_patient_id, _ := c.GetInt64("his_patient_id")
  160. // patient_id, _ := c.GetInt64("patient_id")
  161. // p_ids := c.GetString("p_ids")
  162. // p_ids_arr := strings.Split(p_ids, ",")
  163. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  164. // if his_patient_id == 0 || his_patient.ID == 0 {
  165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  166. // return
  167. // }
  168. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  169. // if err == nil {
  170. // c.ServeSuccessJSON(map[string]interface{}{
  171. // "msg": "关联处方成功",
  172. // })
  173. // return
  174. // } else {
  175. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  176. // return
  177. // }
  178. //}
  179. func (c *HisApiController) GetFaPiaoNumber() {
  180. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  181. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  182. fmt.Println(count)
  183. var zero string
  184. number := count + 1
  185. if number >= 1000 {
  186. zero = "0000" + strconv.FormatInt(number, 10)
  187. } else if number >= 10000 {
  188. zero = "000" + strconv.FormatInt(number, 10)
  189. } else if number >= 100000 {
  190. zero = "00" + strconv.FormatInt(number, 10)
  191. } else if number >= 1000000 {
  192. zero = "0" + strconv.FormatInt(number, 10)
  193. } else {
  194. zero = strconv.FormatInt(number, 10)
  195. }
  196. c.ServeSuccessJSON(map[string]interface{}{
  197. "fapiao_number": zero,
  198. })
  199. return
  200. }
  201. func (c *HisApiController) ChangeOrderDesc() {
  202. id, _ := c.GetInt64("id")
  203. desc := c.GetString("desc")
  204. change_type := c.GetString("change_type")
  205. order, _ := service.GetHisOrderByID(id)
  206. if order.ID == 0 {
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  208. return
  209. }
  210. switch change_type {
  211. case "oth_desc":
  212. order.OthDesc = desc
  213. break
  214. case "cash_pay":
  215. order.CashPay = desc
  216. break
  217. case "jifen_pay":
  218. order.JifenPay = desc
  219. break
  220. case "band_card_pay":
  221. order.BandCardPay = desc
  222. break
  223. case "ali_pay":
  224. order.AliPay = desc
  225. break
  226. case "wechat_pay":
  227. order.WechatPay = desc
  228. break
  229. case "fa_piao_number":
  230. order.FaPiaoNumber = desc
  231. break
  232. case "fa_piao_code":
  233. order.FaPiaoCode = desc
  234. break
  235. }
  236. err := service.SaveHisOrder(&order)
  237. if err == nil {
  238. c.ServeSuccessJSON(map[string]interface{}{
  239. "msg": "修改成功",
  240. })
  241. return
  242. } else {
  243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  244. return
  245. }
  246. }
  247. func (c *HisApiController) GetMonthHisPatient() {
  248. record_date := c.GetString("record_date")
  249. //order_status, _ := c.GetInt64("type")
  250. timeLayout := "2006-01-02"
  251. loc, _ := time.LoadLocation("Local")
  252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  253. if err != nil {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. recordDateTime := theTime.Unix()
  258. adminInfo := c.GetAdminUserInfo()
  259. var tempPatients []service.NewTempPatients
  260. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  261. // 获取当前时间
  262. now := time.Now()
  263. // 获取本月的第一天
  264. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  265. // 获取下个月的第一天
  266. nextMonth := firstDay.AddDate(0, 1, 0)
  267. // 获取本月的最后一天
  268. lastDay := nextMonth.Add(-time.Nanosecond)
  269. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  270. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  271. var patients []service.NewTempPatients
  272. var patients_two []service.NewTempPatients
  273. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  274. for _, item := range tempPatients {
  275. //过滤掉没挂号的和没开处方的
  276. if len(item.HisPrescription) > 0 {
  277. patients = append(patients, item)
  278. patients_two = append(patients_two, item)
  279. }
  280. ////过滤掉没挂号的
  281. //if len(item.HisPatient) > 0 {
  282. //}
  283. }
  284. } else {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. }
  290. ////过滤掉没挂号的
  291. //if len(item.HisPatient) > 0 {
  292. // patients_two = append(patients_two, item)
  293. //}
  294. }
  295. }
  296. c.ServeSuccessJSON(map[string]interface{}{
  297. "list": patients,
  298. "list_two": patients_two,
  299. "chargePatients": chargePatients,
  300. })
  301. }
  302. func (c *HisApiController) GetBatchSettleAccounts() {
  303. order_ids := c.GetString("order_ids")
  304. admin_user_id, _ := c.GetInt64("admin_user_id")
  305. adminUser := c.GetAdminUserInfo()
  306. orders := strings.Split(order_ids, ",")
  307. var newOrders []models.Orders
  308. for _, item := range orders {
  309. order, _ := service.GetHisOrderByIDTenOne(item)
  310. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  311. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  312. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  313. orderInfos = append(orderInfos, orderInfos_two...)
  314. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  315. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  316. var diagnosis_ids []string
  317. if his.ID > 0 {
  318. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  319. } else {
  320. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  321. }
  322. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  323. var dia_config []*models.HisXtDiagnoseConfig
  324. var name string
  325. for _, item := range diagnosis_ids {
  326. id, _ := strconv.ParseInt(item, 10, 64)
  327. diagnosisConfig, _ := service.FindDiagnoseById(id)
  328. dia_config = append(dia_config, diagnosisConfig)
  329. if len(name) == 0 {
  330. name = diagnosisConfig.ClassName
  331. } else {
  332. name = name + "," + diagnosisConfig.ClassName
  333. }
  334. }
  335. var bedCostTotal float64 = 0 //床位总费
  336. var bedCostSelfTotal float64 = 0 //床位自费
  337. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  338. var bedSelfTotal float64 = 0 //床位部分项目自费
  339. var bedInscpTotal float64 = 0 //床位部分项目自费
  340. var operationCostTotal float64 = 0 //手术费
  341. var operationCostSelfTotal float64 = 0 //手术费
  342. var operationCostPartSelfTotal float64 = 0 //手术费
  343. var operationSelfTotal float64 = 0 //床位部分项目自费
  344. var operationInscpTotal float64 = 0 //床位部分项目自费
  345. var otherCostTotal float64 = 0 //其他费用
  346. var otherCostSelfTotal float64 = 0 //其他费用
  347. var otherCostPartSelfTotal float64 = 0 //其他费用
  348. var otherSelfTotal float64 = 0 //床位部分项目自费
  349. var otherInscpTotal float64 = 0 //床位部分项目自费
  350. var materialCostTotal float64 = 0 //材料费
  351. var materialCostSelfTotal float64 = 0 //材料费
  352. var materialCostPartSelfTotal float64 = 0 //材料费
  353. var materialSelfTotal float64 = 0 //床位部分项目自费
  354. var materialInscpTotal float64 = 0 //床位部分项目自费
  355. var westernMedicineCostTotal float64 = 0 //西药费
  356. var westernMedicineCostSelfTotal float64 = 0 //西药费
  357. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  358. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  359. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  360. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  361. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  364. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  365. var checkCostTotal float64 = 0 //检查费
  366. var checkCostSelfTotal float64 = 0 //检查费
  367. var checkCostPartSelfTotal float64 = 0 //检查费
  368. var checkSelfTotal float64 = 0 //床位部分项目自费
  369. var checkInscpTotal float64 = 0 //床位部分项目自费
  370. var laboratoryCostTotal float64 = 0 //化验费
  371. var laboratoryCostSelfTotal float64 = 0 //化验费
  372. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  373. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  374. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  375. var treatCostTotal float64 = 0 //治疗费用
  376. var treatCostSelfTotal float64 = 0 //治疗费用
  377. var treatCostPartSelfTotal float64 = 0 //治疗费用
  378. var treatSelfTotal float64 = 0 //床位部分项目自费
  379. var treatInscpTotal float64 = 0 //床位部分项目自费
  380. decimal.DivisionPrecision = 2
  381. for _, item := range orderInfos {
  382. if item.MedChrgitmType == "01" { //床位费
  383. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  384. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  385. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  386. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  387. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  388. }
  389. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  390. if item.MedChrgitmType == "03" { //检查费
  391. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. } else {
  398. if item.MedChrgitmType == "03" { //检查费
  399. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. }
  406. if item.MedChrgitmType == "04" { //化验费
  407. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. if item.MedChrgitmType == "05" { //治疗费
  414. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  415. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  416. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  417. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  418. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  419. }
  420. if item.MedChrgitmType == "06" { //手术费
  421. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  422. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  423. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  424. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  425. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  426. }
  427. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  428. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  429. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  430. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  431. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  432. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  433. }
  434. if item.MedChrgitmType == "09" { //西药费
  435. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  436. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  437. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  438. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  439. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  440. }
  441. if item.MedChrgitmType == "11" { //中成费
  442. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  443. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  444. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  445. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  446. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  447. }
  448. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  449. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  450. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  451. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  452. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  453. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  454. }
  455. }
  456. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  457. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  458. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  459. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  460. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  461. var doctor_name string
  462. if roles.ID == 0 {
  463. doctor_name = "管理员"
  464. } else {
  465. doctor_name = roles.UserName
  466. }
  467. yiliao_leibie := ""
  468. switch order.MedType {
  469. case "11":
  470. yiliao_leibie = "普通门诊"
  471. break
  472. case "12":
  473. yiliao_leibie = "门诊挂号"
  474. break
  475. case "13":
  476. yiliao_leibie = "急诊"
  477. break
  478. case "14":
  479. yiliao_leibie = "门诊特殊病"
  480. break
  481. case "15":
  482. yiliao_leibie = "门诊统筹"
  483. break
  484. case "16":
  485. yiliao_leibie = "门诊慢性病"
  486. break
  487. case "21":
  488. yiliao_leibie = "普通住院"
  489. break
  490. }
  491. var newOrder models.Orders
  492. newOrder.Diagnosis = name
  493. newOrder.OrderInfos = orderInfos
  494. newOrder.Number = order.MdtrtId
  495. newOrder.Date = order.SettleAccountsDate
  496. newOrder.ChargeAdmin = charge_admin
  497. newOrder.PrintorAdmin = printor_admin
  498. newOrder.Order = order
  499. newOrder.BedCostTotal = bedCostTotal
  500. newOrder.BedCostSelfTotal = bedCostSelfTotal
  501. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  502. newOrder.BedSelfTotal = bedSelfTotal
  503. newOrder.BedInscpTotal = bedInscpTotal
  504. newOrder.OperationCostTotal = operationCostTotal
  505. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  506. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  507. newOrder.OperationSelfTotal = operationSelfTotal
  508. newOrder.OperationInscpTotal = operationInscpTotal
  509. newOrder.OtherCostTotal = otherCostTotal
  510. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  511. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  512. newOrder.OtherSelfTotal = otherSelfTotal
  513. newOrder.OtherInscpTotal = otherInscpTotal
  514. newOrder.MaterialCostTotal = materialCostTotal
  515. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  516. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  517. newOrder.MaterialSelfTotal = materialSelfTotal
  518. newOrder.MaterialInscpTotal = materialInscpTotal
  519. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  520. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  521. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  522. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  523. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  524. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  525. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  526. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  527. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  528. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  529. newOrder.CheckCostTotal = checkCostTotal
  530. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  531. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  532. newOrder.CheckSelfTotal = checkSelfTotal
  533. newOrder.CheckInscpTotal = checkInscpTotal
  534. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  535. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  536. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  537. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  538. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  539. newOrder.TreatCostTotal = treatCostTotal
  540. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  541. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  542. newOrder.TreatSelfTotal = treatSelfTotal
  543. newOrder.TreatInscpTotal = treatInscpTotal
  544. newOrder.DoctorInfo = doctor_info
  545. newOrder.DoctorName = doctor_name
  546. newOrder.HealthCardNo = order.PsnNo
  547. newOrder.YiliaoLeibie = yiliao_leibie
  548. newOrder.Patient = patient
  549. newOrder.OrgName = miConfig.OrgName
  550. newOrder.OrgCode = miConfig.Code
  551. newOrder.OrderNumber = order.Number
  552. newOrder.HisPatient = his
  553. newOrder.DiaConfig = dia_config
  554. newOrders = append(newOrders, newOrder)
  555. }
  556. c.ServeSuccessJSON(map[string]interface{}{
  557. "orders": newOrders,
  558. })
  559. }
  560. func (c *HisApiController) GetTestOrder() {
  561. order_id, _ := c.GetInt64("order_id")
  562. admin_user_id, _ := c.GetInt64("admin_user_id")
  563. adminUser := c.GetAdminUserInfo()
  564. order, _ := service.GetHisOrderByID(order_id)
  565. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  566. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  567. orderInfos = append(orderInfos, orderInfos_two...)
  568. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  569. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  570. var dia_config []*models.HisXtDiagnoseConfig
  571. var name string
  572. var bedCostTotal float64 = 0 //床位总费
  573. var bedCostSelfTotal float64 = 0 //床位自费
  574. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  575. var bedSelfTotal float64 = 0 //床位部分项目自费
  576. var bedInscpTotal float64 = 0 //床位部分项目自费
  577. var operationCostTotal float64 = 0 //手术费
  578. var operationCostSelfTotal float64 = 0 //手术费
  579. var operationCostPartSelfTotal float64 = 0 //手术费
  580. var operationSelfTotal float64 = 0 //床位部分项目自费
  581. var operationInscpTotal float64 = 0 //床位部分项目自费
  582. var otherCostTotal float64 = 0 //其他费用
  583. var otherCostSelfTotal float64 = 0 //其他费用
  584. var otherCostPartSelfTotal float64 = 0 //其他费用
  585. var otherSelfTotal float64 = 0 //床位部分项目自费
  586. var otherInscpTotal float64 = 0 //床位部分项目自费
  587. var materialCostTotal float64 = 0 //材料费
  588. var materialCostSelfTotal float64 = 0 //材料费
  589. var materialCostPartSelfTotal float64 = 0 //材料费
  590. var materialSelfTotal float64 = 0 //床位部分项目自费
  591. var materialInscpTotal float64 = 0 //床位部分项目自费
  592. var westernMedicineCostTotal float64 = 0 //西药费
  593. var westernMedicineCostSelfTotal float64 = 0 //西药费
  594. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  595. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  596. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  597. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  598. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  601. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  602. var checkCostTotal float64 = 0 //检查费
  603. var checkCostSelfTotal float64 = 0 //检查费
  604. var checkCostPartSelfTotal float64 = 0 //检查费
  605. var checkSelfTotal float64 = 0 //床位部分项目自费
  606. var checkInscpTotal float64 = 0 //床位部分项目自费
  607. var laboratoryCostTotal float64 = 0 //化验费
  608. var laboratoryCostSelfTotal float64 = 0 //化验费
  609. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  610. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  611. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  612. var treatCostTotal float64 = 0 //治疗费用
  613. var treatCostSelfTotal float64 = 0 //治疗费用
  614. var treatCostPartSelfTotal float64 = 0 //治疗费用
  615. var treatSelfTotal float64 = 0 //床位部分项目自费
  616. var treatInscpTotal float64 = 0 //床位部分项目自费
  617. decimal.DivisionPrecision = 2
  618. for _, item := range orderInfos {
  619. if item.MedChrgitmType == "01" { //床位费
  620. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  621. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  622. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  623. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  624. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  625. }
  626. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  627. if item.MedChrgitmType == "03" { //检查费
  628. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. } else {
  635. if item.MedChrgitmType == "03" { //检查费
  636. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. }
  643. if item.MedChrgitmType == "04" { //化验费
  644. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. if item.MedChrgitmType == "05" { //治疗费
  651. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  652. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  653. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  654. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  655. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  656. }
  657. if item.MedChrgitmType == "06" { //手术费
  658. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  659. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  660. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  661. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  662. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  663. }
  664. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  665. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  666. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  667. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  668. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  669. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  670. }
  671. if item.MedChrgitmType == "09" { //西药费
  672. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  673. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  674. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  675. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  676. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  677. }
  678. if item.MedChrgitmType == "11" { //中成费
  679. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  680. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  681. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  682. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  683. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  684. }
  685. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  686. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  687. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  688. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  689. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  690. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  691. }
  692. }
  693. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  694. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  695. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  696. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  697. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  698. var doctor_name string
  699. if roles.ID == 0 {
  700. doctor_name = "管理员"
  701. } else {
  702. doctor_name = roles.UserName
  703. }
  704. yiliao_leibie := ""
  705. switch order.MedType {
  706. case "11":
  707. yiliao_leibie = "普通门诊"
  708. break
  709. case "12":
  710. yiliao_leibie = "门诊挂号"
  711. break
  712. case "13":
  713. yiliao_leibie = "急诊"
  714. break
  715. case "14":
  716. yiliao_leibie = "门诊特殊病"
  717. break
  718. case "15":
  719. yiliao_leibie = "门诊统筹"
  720. break
  721. case "16":
  722. yiliao_leibie = "门诊慢性病"
  723. break
  724. case "21":
  725. yiliao_leibie = "普通住院"
  726. break
  727. }
  728. c.ServeSuccessJSON(map[string]interface{}{
  729. "diagnosis": name,
  730. "order_infos": orderInfos,
  731. "number": order.MdtrtId,
  732. "date": order.SettleAccountsDate,
  733. "charge_admin": charge_admin,
  734. "printor_admin": printor_admin,
  735. "info": order,
  736. "order": order,
  737. "bedCostTotal": bedCostTotal,
  738. "bedCostSelfTotal": bedCostSelfTotal,
  739. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  740. "bedSelfTotal": bedSelfTotal,
  741. "bedInscpTotal": bedInscpTotal,
  742. "operationCostTotal": operationCostTotal,
  743. "operationCostSelfTotal": operationCostSelfTotal,
  744. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  745. "operationSelfTotal": operationSelfTotal,
  746. "operationInscpTotal": operationInscpTotal,
  747. "otherCostTotal": otherCostTotal,
  748. "otherCostSelfTotal": otherCostSelfTotal,
  749. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  750. "otherSelfTotal": otherSelfTotal,
  751. "otherInscpTotal": otherInscpTotal,
  752. "materialCostTotal": materialCostTotal,
  753. "materialCostSelfTotal": materialCostSelfTotal,
  754. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  755. "materialSelfTotal": materialSelfTotal,
  756. "materialInscpTotal": materialInscpTotal,
  757. "westernMedicineCostTotal": westernMedicineCostTotal,
  758. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  759. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  760. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  761. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  762. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  763. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  764. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  765. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  766. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  767. "checkCostTotal": checkCostTotal,
  768. "checkCostSelfTotal": checkCostSelfTotal,
  769. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  770. "checkSelfTotal": checkSelfTotal,
  771. "checkInscpTotal": checkInscpTotal,
  772. "laboratoryCostTotal": laboratoryCostTotal,
  773. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  774. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  775. "laboratorySelfTotal": laboratorySelfTotal,
  776. "laboratoryInscpTotal": laboratoryInscpTotal,
  777. "treatCostTotal": treatCostTotal,
  778. "treatCostSelfTotal": treatCostSelfTotal,
  779. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  780. "treatSelfTotal": treatSelfTotal,
  781. "treatInscpTotal": treatInscpTotal,
  782. "doctor_info": doctor_info,
  783. "doctor_name": doctor_name,
  784. "health_card_no": order.PsnNo,
  785. "yiliao_leibie": yiliao_leibie,
  786. "patient": patient,
  787. "org_name": miConfig.OrgName,
  788. "org_code": miConfig.Code,
  789. "order_number": order.Number,
  790. "his_hospital": his_hospital,
  791. "dia_config": dia_config,
  792. })
  793. }
  794. type CustomFundPay struct {
  795. FundPayType string `json:"fund_pay_type"`
  796. FundPayamt float64 `json:"fund_payamt"`
  797. InscpScpAmt float64 `json:"inscp_scp_amt"`
  798. }
  799. func (c *PublicApiController) GetBaiLinExportData() {
  800. data := service.GetBaiLinOrderData()
  801. fmt.Println(len(data))
  802. var new_data []*models.NewCustomHisOrder
  803. for _, item := range data {
  804. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  805. new_data = append(new_data, item)
  806. }
  807. }
  808. fmt.Println(len(new_data))
  809. c.ServeSuccessJSON(map[string]interface{}{
  810. "list": new_data,
  811. })
  812. }
  813. func (c *HisApiController) GetHisUnChargePatientList() {
  814. record_date := c.GetString("record_date")
  815. sch_type, _ := c.GetInt64("sch_type")
  816. timeLayout := "2006-01-02"
  817. loc, _ := time.LoadLocation("Local")
  818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  819. if err != nil {
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  821. return
  822. }
  823. recordDateTime := theTime.Unix()
  824. adminInfo := c.GetAdminUserInfo()
  825. var tempPatients []*service.NewTempPatients
  826. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  827. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  828. var patients []*service.NewTempPatients
  829. var patients_two []*service.NewTempPatients
  830. for _, item := range tempPatients {
  831. //过滤掉没挂号的和没开处方的
  832. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  833. patients = append(patients, item)
  834. }
  835. //过滤掉没挂号的
  836. if len(item.HisPatient) > 0 {
  837. patients_two = append(patients_two, item)
  838. }
  839. }
  840. c.ServeSuccessJSON(map[string]interface{}{
  841. "list": patients,
  842. "list_two": patients_two,
  843. })
  844. }
  845. func (c *HisApiController) GetPrivateExpensesOrder() {
  846. //id, _ := c.GetInt64("id")
  847. //record_time := c.GetString("record_time")
  848. order_id, _ := c.GetInt64("order_id")
  849. admin_user_id, _ := c.GetInt64("admin_user_id")
  850. //timeLayout := "2006-01-02"
  851. //loc, _ := time.LoadLocation("Local")
  852. //
  853. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  854. //if err != nil {
  855. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. // return
  857. //}
  858. //recordDateTime := theTime.Unix()
  859. adminUser := c.GetAdminUserInfo()
  860. order, _ := service.GetHisOrderByID(order_id)
  861. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  862. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  863. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  864. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  865. //var config []*models.HisXtDiagnoseConfig
  866. var name string
  867. if order.PType == 1 {
  868. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  869. for _, item := range diagnosis_ids {
  870. id, _ := strconv.ParseInt(item, 10, 64)
  871. diagnosisConfig, _ := service.FindDiagnoseById(id)
  872. if len(name) == 0 {
  873. name = diagnosisConfig.ClassName
  874. } else {
  875. name = name + "," + diagnosisConfig.ClassName
  876. }
  877. }
  878. } else {
  879. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. }
  890. var bedCostTotal float64 = 0 //床位总费
  891. //var bedCostSelfTotal float64 = 0 //床位自费
  892. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  893. var operationCostTotal float64 = 0 //手术费
  894. //var operationCostSelfTotal float64 = 0 //手术费
  895. var operationCostPartSelfTotal float64 = 0 //手术费
  896. var otherCostTotal float64 = 0 //其他费用
  897. //var otherCostSelfTotal float64 = 0 //其他费用
  898. var otherCostPartSelfTotal float64 = 0 //其他费用
  899. var materialCostTotal float64 = 0 //材料费
  900. //var materialCostSelfTotal float64 = 0 //材料费
  901. var materialCostPartSelfTotal float64 = 0 //材料费
  902. var westernMedicineCostTotal float64 = 0 //西药费
  903. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  904. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  905. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  906. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  907. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  908. var checkCostTotal float64 = 0 //检查费
  909. //var checkCostSelfTotal float64 = 0 //检查费
  910. var checkCostPartSelfTotal float64 = 0 //检查费
  911. var laboratoryCostTotal float64 = 0 //化验费
  912. //var laboratoryCostSelfTotal float64 = 0 //化验费
  913. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  914. var treatCostTotal float64 = 0 //治疗费用
  915. //var treatCostSelfTotal float64 = 0 //治疗费用
  916. var treatCostPartSelfTotal float64 = 0 //治疗费用
  917. var zhenChaCostTotal float64 = 0 //其他费用
  918. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  919. decimal.DivisionPrecision = 2
  920. for _, item := range orderInfos {
  921. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  922. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  923. item.MedChrgitmType = "09"
  924. }
  925. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  926. if item.HisPrescriptionProject.Type == 2 {
  927. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  928. fmt.Println("CostClassify")
  929. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  930. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  931. case 0:
  932. item.MedChrgitmType = "0"
  933. break
  934. case 1:
  935. item.MedChrgitmType = "14"
  936. break
  937. case 2:
  938. item.MedChrgitmType = "05"
  939. break
  940. case 3:
  941. item.MedChrgitmType = "03"
  942. break
  943. case 4:
  944. item.MedChrgitmType = "03"
  945. break
  946. case 5:
  947. item.MedChrgitmType = "08"
  948. break
  949. case 6:
  950. item.MedChrgitmType = "14"
  951. break
  952. case 7:
  953. item.MedChrgitmType = "14"
  954. break
  955. case 8:
  956. item.MedChrgitmType = "03"
  957. break
  958. case 9:
  959. item.MedChrgitmType = "14"
  960. break
  961. case 10:
  962. item.MedChrgitmType = "14"
  963. break
  964. case 11:
  965. item.MedChrgitmType = "06"
  966. break
  967. case 12:
  968. item.MedChrgitmType = "12"
  969. break
  970. case 13:
  971. item.MedChrgitmType = "01"
  972. break
  973. case 14:
  974. item.MedChrgitmType = "04"
  975. break
  976. case 15:
  977. item.MedChrgitmType = "14"
  978. break
  979. }
  980. } else {
  981. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  982. case 1:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 2:
  986. item.MedChrgitmType = "05"
  987. break
  988. case 3:
  989. item.MedChrgitmType = "04"
  990. break
  991. case 4:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 5:
  995. item.MedChrgitmType = "08"
  996. break
  997. case 6:
  998. item.MedChrgitmType = "14"
  999. break
  1000. case 7:
  1001. item.MedChrgitmType = "14"
  1002. break
  1003. case 8:
  1004. item.MedChrgitmType = "03"
  1005. break
  1006. case 9:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. default:
  1010. item.MedChrgitmType = "14"
  1011. break
  1012. }
  1013. }
  1014. } else if item.HisPrescriptionProject.Type == 3 {
  1015. item.MedChrgitmType = "08"
  1016. }
  1017. }
  1018. }
  1019. order.PsnCashPay = order.MedfeeSumamt
  1020. for _, item := range orderInfos {
  1021. if item.MedChrgitmType == "01" { //床位费
  1022. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1023. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1024. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1025. }
  1026. if item.MedChrgitmType == "02" { //诊察费
  1027. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1028. //zhenChaCostSelfTotal = zhenChaCostTotal
  1029. }
  1030. if item.MedChrgitmType == "03" { //检查费
  1031. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1033. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1034. }
  1035. if item.MedChrgitmType == "02" { //检查费
  1036. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1037. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1038. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1039. }
  1040. if item.MedChrgitmType == "04" { //化验费
  1041. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "05" { //治疗费
  1046. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "06" { //手术费
  1051. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1056. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "09" { //西药费
  1061. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "11" { //中成费
  1066. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1071. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1072. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1073. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1074. }
  1075. }
  1076. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1077. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1078. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1079. var dia_config []*models.HisXtDiagnoseConfig
  1080. var diagnosis_ids []string
  1081. if his.ID > 0 {
  1082. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1083. } else {
  1084. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1085. }
  1086. for _, item := range diagnosis_ids {
  1087. id, _ := strconv.ParseInt(item, 10, 64)
  1088. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1089. dia_config = append(dia_config, diagnosisConfig)
  1090. }
  1091. var rf []CustomFundPay
  1092. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1093. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1094. c.ServeSuccessJSON(map[string]interface{}{
  1095. "patient": patient,
  1096. "order_infos": orderInfos,
  1097. "diagnosis": name,
  1098. "bedCostTotal": bedCostTotal,
  1099. "bedCostSelfTotal": bedCostTotal,
  1100. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1101. "operationCostTotal": operationCostTotal,
  1102. "operationCostSelfTotal": operationCostTotal,
  1103. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1104. "otherCostTotal": otherCostTotal,
  1105. "otherCostSelfTotal": otherCostTotal,
  1106. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1107. "materialCostTotal": materialCostTotal,
  1108. "materialCostSelfTotal": materialCostTotal,
  1109. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1110. "westernMedicineCostTotal": westernMedicineCostTotal,
  1111. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1113. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1114. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1116. "checkCostTotal": checkCostTotal,
  1117. "checkCostSelfTotal": checkCostTotal,
  1118. "zhenChaCostTotal": zhenChaCostTotal,
  1119. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1120. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1121. "laboratoryCostTotal": laboratoryCostTotal,
  1122. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1123. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1124. "treatCostTotal": treatCostTotal,
  1125. "treatCostSelfTotal": treatCostTotal,
  1126. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1127. "charge_admin": charge_admin,
  1128. "printor_admin": printor_admin,
  1129. "org_name": org.OrgName,
  1130. "org_code": miConfig.Code,
  1131. "name": patient.Name,
  1132. "number": order.MdtrtId,
  1133. "date": order.SettleAccountsDate,
  1134. "info": order,
  1135. "new_order": order,
  1136. "his_hospital": his_hospital,
  1137. "his": his,
  1138. "funds": rf,
  1139. "dia_config": dia_config,
  1140. })
  1141. }
  1142. func (c *HisApiController) RefudDetail() {
  1143. order_id, _ := c.GetInt64("order_id")
  1144. order, _ := service.GetHisOrderByID(order_id)
  1145. adminUser := c.GetAdminUserInfo()
  1146. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "msg": "撤销成功",
  1149. })
  1150. }
  1151. func (c *HisApiController) Sscard() {
  1152. //r := CardInit()
  1153. //if r == 0 {
  1154. // GetBaseInfo()
  1155. //}
  1156. //c.ServeSuccessJSON(map[string]interface{}{
  1157. // "list": "11",
  1158. //})
  1159. }
  1160. func GetBaseInfo() error {
  1161. //handle := syscall.MustLoadDLL("SSCard.dll")
  1162. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1163. //
  1164. //str := make([]byte, 256)
  1165. //str1 := make([]byte, 256)
  1166. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1167. //if ferr != nil {
  1168. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1169. // return ferr
  1170. //}
  1171. //
  1172. //fmt.Println(string(str))
  1173. //
  1174. //fmt.Println(r)
  1175. return nil
  1176. }
  1177. func CardInit() int {
  1178. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1179. //add := DllTestDef.MustFindProc("Init")
  1180. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1181. //if err != nil {
  1182. // fmt.Println("SSCard的运算结果为:", ret)
  1183. //}
  1184. //result := int(ret)
  1185. return 0
  1186. }
  1187. func IntPtr(n int) uintptr {
  1188. return uintptr(n)
  1189. }
  1190. func StrPtr(s string) uintptr {
  1191. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1192. }
  1193. func (c *HisApiController) GetHisPatientList() {
  1194. //types, _ := c.GetInt64("type", 0)
  1195. record_date := c.GetString("record_date")
  1196. sch_type, _ := c.GetInt64("sch_type")
  1197. timeLayout := "2006-01-02"
  1198. loc, _ := time.LoadLocation("Local")
  1199. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1200. if err != nil {
  1201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1202. return
  1203. }
  1204. recordDateTime := theTime.Unix()
  1205. adminInfo := c.GetAdminUserInfo()
  1206. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1207. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1208. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1209. //获取当前用户的信息
  1210. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1211. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1212. //获取所有科室信息
  1213. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1214. c.ServeSuccessJSON(map[string]interface{}{
  1215. "list": patients,
  1216. "list_two": patients_two,
  1217. "info": adminUserInfo,
  1218. "doctors": doctors,
  1219. "department": department,
  1220. })
  1221. }
  1222. type CustomTemplate struct {
  1223. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1224. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1225. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1226. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1227. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1228. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1229. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1230. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1231. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1232. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1233. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1234. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1235. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1236. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1237. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1238. }
  1239. func (c *HisApiController) GetHisPatientInfo() {
  1240. patient_id, _ := c.GetInt64("patient_id")
  1241. his_patient_id, _ := c.GetInt64("his_patient_id")
  1242. record_date := c.GetString("record_date")
  1243. number := c.GetString("number")
  1244. //start_time := c.GetString("start_time")
  1245. //end_time := c.GetString("end_time")
  1246. p_type, _ := c.GetInt64("p_type")
  1247. timeLayout := "2006-01-02"
  1248. loc, _ := time.LoadLocation("Local")
  1249. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1250. if err != nil {
  1251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1252. return
  1253. }
  1254. recordDateTime := theTime.Unix()
  1255. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1256. //if err != nil {
  1257. //
  1258. //}
  1259. //startRecordDateTime := startTime.Unix()
  1260. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1261. //if err != nil {
  1262. //
  1263. //}
  1264. //endRecordDateTime := endTime.Unix()
  1265. admin := c.GetAdminUserInfo()
  1266. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1267. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1269. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1270. var prescriptions []*models.HisPrescription
  1271. var last_prescriptions []*models.HisPrescription
  1272. var sch_prescriptions []CustomTemplate
  1273. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. if p_type == 1 { //住院
  1275. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1276. for _, item := range prescriptions {
  1277. for _, subItem := range item.HisDoctorAdviceInfo {
  1278. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1279. if info.RetailPrice > 0 {
  1280. subItem.Drug.MinPrice = info.RetailPrice
  1281. }
  1282. }
  1283. }
  1284. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1285. } else { //门诊
  1286. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1287. for _, item := range prescriptions {
  1288. for _, subItem := range item.HisDoctorAdviceInfo {
  1289. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1290. if info.RetailPrice > 0 {
  1291. subItem.Drug.MinPrice = info.RetailPrice
  1292. }
  1293. }
  1294. }
  1295. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1296. }
  1297. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1298. if sch.ID > 0 {
  1299. var week string
  1300. t := time.Now()
  1301. switch t.Weekday().String() {
  1302. case "Monday":
  1303. week = "周一"
  1304. break
  1305. case "Tuesday":
  1306. week = "周二"
  1307. break
  1308. case "Wednesday":
  1309. week = "周三"
  1310. break
  1311. case "Thursday":
  1312. week = "周四"
  1313. break
  1314. case "Friday":
  1315. week = "周五"
  1316. break
  1317. case "Saturday":
  1318. week = "周六"
  1319. break
  1320. case "Sunday":
  1321. week = "周日"
  1322. break
  1323. }
  1324. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1325. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1326. //根据推送频率组装新的数组
  1327. for _, item := range temp_sch_prescriptions {
  1328. var cus CustomTemplate
  1329. cus.ID = item.ID
  1330. cus.UserOrgId = item.UserOrgId
  1331. cus.PatientId = item.PatientId
  1332. cus.MedType = item.MedType
  1333. cus.RecordDate = item.RecordDate
  1334. cus.Type = item.Type
  1335. cus.PType = item.PType
  1336. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1337. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1338. if subItem.FrequencyType == 1 { //每次必推
  1339. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1340. }
  1341. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1342. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1343. }
  1344. if subItem.FrequencyType == 2 { //按照天数频率
  1345. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1346. now := p.Unix()
  1347. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1348. dayStr2 := "-" + dayStr
  1349. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1350. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1351. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1352. if len(advices) == 0 {
  1353. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1354. }
  1355. }
  1356. }
  1357. }
  1358. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1359. if subItem.Type == 2 {
  1360. if subItem.XtHisProject.MedicalStatus != 1 {
  1361. if subItem.FrequencyType == 1 {
  1362. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1363. }
  1364. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1365. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1366. }
  1367. if subItem.FrequencyType == 2 {
  1368. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1369. now := p.Unix()
  1370. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1371. dayStr2 := "-" + dayStr
  1372. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1373. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1374. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1375. if len(projects) == 0 {
  1376. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1377. }
  1378. }
  1379. }
  1380. } else if subItem.Type == 3 {
  1381. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1382. if subItem.FrequencyType == 1 {
  1383. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1384. }
  1385. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1386. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1387. }
  1388. if subItem.FrequencyType == 2 {
  1389. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1390. now := p.Unix()
  1391. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1392. dayStr2 := "-" + dayStr
  1393. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1394. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1395. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1396. if len(projects) == 0 {
  1397. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. sch_prescriptions = append(sch_prescriptions, cus)
  1404. }
  1405. for _, item := range sch_prescriptions {
  1406. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1407. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1408. }
  1409. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1410. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1411. }
  1412. }
  1413. }
  1414. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1415. if config.ID > 0 && config.IsOpen == 1 {
  1416. for _, item := range sch_prescriptions {
  1417. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1418. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1419. if info.RetailPrice > 0 {
  1420. subItem.Drug.MinPrice = info.RetailPrice
  1421. }
  1422. }
  1423. }
  1424. }
  1425. if config.ID > 0 && config.IsOpen == 1 {
  1426. for _, item := range sch_prescriptions {
  1427. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1428. if subItem.Type == 3 {
  1429. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1430. if info.Price > 0 {
  1431. subItem.GoodInfo.PackingPrice = info.Price
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1438. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1439. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1440. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1441. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1442. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1443. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1444. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1445. //获取所有科室信息
  1446. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1447. c.ServeSuccessJSON(map[string]interface{}{
  1448. "his_info": his_patient_info,
  1449. "xt_info": xt_patient_info,
  1450. "prescription": prescriptions,
  1451. "case_history": case_history,
  1452. "info": patientPrescriptionInfo,
  1453. //"month_prescriptions": monthPrescriptions,
  1454. "order": order,
  1455. "doctors": doctors,
  1456. "department": department,
  1457. "sch_prescriptions": sch_prescriptions,
  1458. "last_prescriptions": last_prescriptions,
  1459. "schedule": sch,
  1460. "count": count,
  1461. "drugStockConfig": drugStockConfig,
  1462. "last_info": lastPatientPrescriptionInfo,
  1463. })
  1464. return
  1465. }
  1466. func (c *HisApiController) GetHisPrescriptionConfig() {
  1467. adminInfo := c.GetAdminUserInfo()
  1468. //获取医嘱模版
  1469. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1470. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1471. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1472. //获取所有基础药
  1473. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1474. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1475. if config.ID > 0 && config.IsOpen == 1 {
  1476. for _, item := range drugs {
  1477. var index = 0
  1478. for _, subItem := range item.OtherDrugWarehouseInfo {
  1479. if index == 0 {
  1480. index = index + 1
  1481. if subItem.RetailPrice > 0 {
  1482. item.MinPrice = subItem.RetailPrice
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1489. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1490. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1491. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1492. //获取所有科室信息
  1493. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1494. //获取诊断信息
  1495. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1496. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1497. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1498. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1499. //获取是否开启保存耗材出库的开关
  1500. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1501. c.ServeSuccessJSON(map[string]interface{}{
  1502. "drugs": drugs,
  1503. "advices_template": advices,
  1504. "drugways": drugways,
  1505. "efs": efs,
  1506. "doctors": doctors,
  1507. "department": department,
  1508. "sick": sick,
  1509. "additions": additions,
  1510. "diagnose": diagnose,
  1511. "manufacturers": manufacturers,
  1512. "goodOutOpen": goodOutOpen,
  1513. "patientDiagnose": patientDiagnose,
  1514. })
  1515. }
  1516. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1517. //获取所有基础药
  1518. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1519. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1520. if config.ID > 0 && config.IsOpen == 1 {
  1521. for _, item := range drugs {
  1522. var index = 0
  1523. for _, subItem := range item.OtherDrugWarehouseInfo {
  1524. if index == 0 {
  1525. index = index + 1
  1526. if subItem.RetailPrice > 0 {
  1527. item.MinPrice = subItem.RetailPrice
  1528. }
  1529. }
  1530. }
  1531. }
  1532. }
  1533. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1534. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1535. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1536. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1537. //获取所有科室信息
  1538. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1539. //获取诊断信息
  1540. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1541. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1542. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1543. //获取是否开启保存耗材出库的开关
  1544. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1545. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1546. c.ServeSuccessJSON(map[string]interface{}{
  1547. "drugs": drugs,
  1548. "advices_template": advices,
  1549. "drugways": drugways,
  1550. "efs": efs,
  1551. "doctors": doctors,
  1552. "department": department,
  1553. "sick": sick,
  1554. "additions": additions,
  1555. "diagnose": diagnose,
  1556. "manufacturers": manufacturers,
  1557. "goodOutOpen": goodOutOpen,
  1558. "patientDiagnose": patientDiagnose,
  1559. })
  1560. }
  1561. }
  1562. func (c *HisApiController) CreateHisPrescription() {
  1563. record_date := c.GetString("record_date")
  1564. patient_id, _ := c.GetInt64("patient_id")
  1565. reg_type, _ := c.GetInt64("reg_type")
  1566. diagnose := c.GetString("diagnose")
  1567. sick_type, _ := c.GetInt64("sick_type")
  1568. sick_history := c.GetString("sick_history")
  1569. doctor_id, _ := c.GetInt64("doctor", 0)
  1570. department, _ := c.GetInt64("department", 0)
  1571. his_patient_id, _ := c.GetInt64("his_patient_id")
  1572. p_type, _ := c.GetInt64("p_type")
  1573. patient_diagnose := c.GetString("patient_diagnose")
  1574. dataBody := make(map[string]interface{}, 0)
  1575. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1576. if err != nil {
  1577. utils.ErrorLog(err.Error())
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1579. return
  1580. }
  1581. timeLayout := "2006-01-02"
  1582. loc, _ := time.LoadLocation("Local")
  1583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1584. if err != nil {
  1585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1586. return
  1587. }
  1588. adminInfo := c.GetAdminUserInfo()
  1589. recordDateTime := theTime.Unix()
  1590. //查询默认出库仓库库存
  1591. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1592. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1593. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1594. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1595. if len(lists) == 1 {
  1596. his_patient_id = lists[0].ID
  1597. }
  1598. }
  1599. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1600. //保存处方出库
  1601. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1602. //自动出库
  1603. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1604. //耗材保存处方出库
  1605. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1606. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1607. //已发药和已收费限制逻辑
  1608. isMidicine := false
  1609. isCharge := false
  1610. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1611. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1612. if len(prescriptions) > 0 {
  1613. for _, item := range prescriptions {
  1614. items := item.(map[string]interface{})
  1615. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1616. utils.ErrorLog("id")
  1617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1618. return
  1619. }
  1620. id := int64(items["id"].(float64))
  1621. if id > 0 {
  1622. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1623. if err != nil {
  1624. if new_prescription.OrderStatus == 4 {
  1625. isCharge = true
  1626. }
  1627. }
  1628. }
  1629. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1630. advices := items["advices"].([]interface{})
  1631. if len(advices) > 0 {
  1632. for _, advice := range advices {
  1633. var adviceId int64
  1634. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1635. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1636. }
  1637. if adviceId > 0 {
  1638. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1639. if err == nil {
  1640. if his_advice_info.IsMedicine == 1 {
  1641. isMidicine = true
  1642. }
  1643. }
  1644. }
  1645. }
  1646. }
  1647. }
  1648. }
  1649. }
  1650. }
  1651. if isMidicine == true {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1653. return
  1654. }
  1655. if isCharge == true {
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1657. return
  1658. }
  1659. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1660. //药品发药出库
  1661. if pharmacyConfig.IsOpen == 1 {
  1662. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1663. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1664. if len(prescriptions) > 0 {
  1665. for _, item := range prescriptions {
  1666. items := item.(map[string]interface{})
  1667. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1668. advices := items["advices"].([]interface{})
  1669. if len(advices) > 0 {
  1670. for _, advice := range advices {
  1671. var drug_id int64
  1672. var prescribing_number float64
  1673. var prescribingNumberUnit string
  1674. var adviceId int64
  1675. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1676. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1677. }
  1678. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1679. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1680. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1681. }
  1682. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1683. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1684. }
  1685. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1686. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1687. }
  1688. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1689. if drug.ID == 0 {
  1690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1691. return
  1692. }
  1693. //查询药品的所有库存
  1694. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1695. var total_count int64
  1696. for _, it := range list {
  1697. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1698. }
  1699. totals := strconv.FormatInt(total_count, 10)
  1700. //查询该药品是否存在开药记录
  1701. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1702. fmt.Println("wooooooooooooo", advicelist.ID)
  1703. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1704. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1705. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1706. //新增处方
  1707. if advicelist.ID == 0 {
  1708. all_count, _ := strconv.ParseFloat(totals, 64)
  1709. if prescribingNumberUnit == drug.MinUnit {
  1710. fmt.Println("prescribing_number", prescribing_number)
  1711. fmt.Println("all_count", all_count)
  1712. if drug.IsUse != 1 {
  1713. if drug.IsProject == 0 || drug.IsProject == 2 {
  1714. if all_count == 0 {
  1715. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1716. return
  1717. }
  1718. if prescribing_number > all_count {
  1719. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1720. return
  1721. }
  1722. }
  1723. }
  1724. }
  1725. if prescribingNumberUnit == drug.MaxUnit {
  1726. num := prescribing_number * float64(drug.MinNumber)
  1727. if drug.IsUse != 1 {
  1728. if drug.IsProject == 0 || drug.IsProject == 2 {
  1729. if all_count == 0 {
  1730. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1731. return
  1732. }
  1733. if num > all_count {
  1734. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1735. return
  1736. }
  1737. }
  1738. }
  1739. }
  1740. }
  1741. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1742. if drugOutConfig.IsOpen != 1 {
  1743. //修改处方
  1744. for _, advice := range advices {
  1745. var drug_id int64
  1746. var prescribing_number float64
  1747. var prescribingNumberUnit string
  1748. var prescribingNumber string
  1749. var adviceId int64
  1750. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1751. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1752. }
  1753. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1754. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1755. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1756. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1757. }
  1758. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1759. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1760. }
  1761. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1762. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1763. }
  1764. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1765. if drug.ID == 0 {
  1766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1767. return
  1768. }
  1769. //查询药品的所有库存
  1770. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1771. var total_count int64
  1772. for _, it := range list {
  1773. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1774. }
  1775. totals := strconv.FormatInt(total_count, 10)
  1776. //查询该药品是否存在开药记录
  1777. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1778. //新增处方
  1779. if advicelist.ID == 0 {
  1780. all_count, _ := strconv.ParseFloat(totals, 64)
  1781. if prescribingNumberUnit == drug.MinUnit {
  1782. if drug.IsUse != 1 {
  1783. if drug.IsProject == 0 || drug.IsProject == 2 {
  1784. if all_count == 0 {
  1785. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1786. return
  1787. }
  1788. if prescribing_number > all_count {
  1789. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1790. return
  1791. }
  1792. }
  1793. }
  1794. } else {
  1795. if prescribingNumberUnit == drug.MaxUnit {
  1796. num := prescribing_number * float64(drug.MinNumber)
  1797. if drug.IsUse != 1 {
  1798. if drug.IsProject == 0 || drug.IsProject == 2 {
  1799. if all_count == 0 {
  1800. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1801. return
  1802. }
  1803. if num > all_count {
  1804. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1805. return
  1806. }
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. //修改处方
  1813. if advicelist.ID > 0 {
  1814. var device_number int64
  1815. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1816. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1817. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1818. device_number = prescribingNumberInt * drug.MinNumber
  1819. }
  1820. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1821. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1822. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1823. device_number = prescribingNumberInt
  1824. }
  1825. var number_count int64
  1826. if prescribingNumberUnit == drug.MaxUnit {
  1827. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1828. number_count = prescribingNumberInt * drug.MinNumber
  1829. }
  1830. if prescribingNumberUnit == drug.MinUnit {
  1831. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1832. number_count = prescribingNumberInt
  1833. }
  1834. //如果修改的数量大于之前修改的数量
  1835. if (number_count - device_number) > 0 {
  1836. //如果修改的差数量 大于库存数量
  1837. if drug.IsUse != 1 {
  1838. if (number_count - device_number) > total_count {
  1839. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1840. return
  1841. }
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. //已发药和已收费限制逻辑
  1855. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1856. //校验库存总量
  1857. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1858. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1859. if len(prescriptions) > 0 {
  1860. for _, item := range prescriptions {
  1861. items := item.(map[string]interface{})
  1862. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1863. advices := items["advices"].([]interface{})
  1864. if len(advices) > 0 {
  1865. for _, advice := range advices {
  1866. var drug_id int64
  1867. var prescribing_number float64
  1868. var prescribingNumberUnit string
  1869. var adviceId int64
  1870. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1871. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1872. }
  1873. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1874. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1875. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1876. }
  1877. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1878. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1879. }
  1880. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1881. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1882. }
  1883. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1884. if drug.ID == 0 {
  1885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1886. return
  1887. }
  1888. //查询药品的所有库存
  1889. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1890. var total_count int64
  1891. for _, it := range list {
  1892. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1893. }
  1894. totals := strconv.FormatInt(total_count, 10)
  1895. //查询该药品是否存在开药记录
  1896. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1897. //查询最新批次库存
  1898. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1899. var batch_number_count int64
  1900. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1901. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1902. //新增处方
  1903. if advicelist.ID == 0 {
  1904. all_count, _ := strconv.ParseFloat(totals, 64)
  1905. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1906. if prescribingNumberUnit == drug.MinUnit {
  1907. if drug.IsUse != 1 {
  1908. if drug.IsProject == 0 || drug.IsProject == 2 {
  1909. if all_count == 0 {
  1910. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1911. return
  1912. }
  1913. if prescribing_number > all_count {
  1914. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1915. return
  1916. }
  1917. }
  1918. if adminInfo.CurrentOrgId == 10215 {
  1919. if prescribing_number > batch_number_all_count {
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1921. return
  1922. }
  1923. }
  1924. }
  1925. }
  1926. if prescribingNumberUnit == drug.MaxUnit {
  1927. num := prescribing_number * float64(drug.MinNumber)
  1928. if drug.IsUse != 1 {
  1929. if drug.IsProject == 0 || drug.IsProject == 2 {
  1930. if all_count == 0 {
  1931. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1932. return
  1933. }
  1934. if num > all_count {
  1935. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1936. return
  1937. }
  1938. }
  1939. if adminInfo.CurrentOrgId == 10215 {
  1940. if num > batch_number_all_count {
  1941. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1942. return
  1943. }
  1944. }
  1945. }
  1946. }
  1947. }
  1948. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1949. if drugOutConfig.IsOpen != 1 {
  1950. //修改处方
  1951. for _, advice := range advices {
  1952. var drug_id int64
  1953. var prescribing_number float64
  1954. var prescribingNumberUnit string
  1955. var prescribingNumber string
  1956. var adviceId int64
  1957. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1958. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1959. }
  1960. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1961. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1962. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1963. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1964. }
  1965. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1966. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1967. }
  1968. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1969. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1970. }
  1971. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1972. if drug.ID == 0 {
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1974. return
  1975. }
  1976. //查询药品的所有库存
  1977. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1978. var total_count int64
  1979. for _, it := range list {
  1980. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1981. }
  1982. totals := strconv.FormatInt(total_count, 10)
  1983. //查询该药品是否存在开药记录
  1984. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1985. //新增处方
  1986. if advicelist.ID == 0 {
  1987. //查询最新批次库存
  1988. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1989. var batch_number_count int64
  1990. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1991. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1992. all_count, _ := strconv.ParseFloat(totals, 64)
  1993. if prescribingNumberUnit == drug.MinUnit {
  1994. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1995. if drug.IsUse != 1 {
  1996. if drug.IsProject == 0 || drug.IsProject == 2 {
  1997. if all_count == 0 {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1999. return
  2000. }
  2001. if prescribing_number > all_count {
  2002. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2003. return
  2004. }
  2005. }
  2006. if adminInfo.CurrentOrgId == 10215 {
  2007. if prescribing_number > batch_number_all_count {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2009. return
  2010. }
  2011. }
  2012. }
  2013. } else {
  2014. if prescribingNumberUnit == drug.MaxUnit {
  2015. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2016. num := prescribing_number * float64(drug.MinNumber)
  2017. if drug.IsUse != 1 {
  2018. if drug.IsProject == 0 || drug.IsProject == 2 {
  2019. if all_count == 0 {
  2020. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2021. return
  2022. }
  2023. if num > all_count {
  2024. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2025. return
  2026. }
  2027. }
  2028. if adminInfo.CurrentOrgId == 10215 {
  2029. if prescribing_number > batch_number_all_count {
  2030. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2031. return
  2032. }
  2033. }
  2034. }
  2035. }
  2036. }
  2037. }
  2038. //修改处方
  2039. if advicelist.ID > 0 {
  2040. //查询最新批次库存
  2041. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2042. var batch_number_count int64
  2043. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2044. var device_number int64
  2045. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2046. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2047. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2048. device_number = prescribingNumberInt * drug.MinNumber
  2049. }
  2050. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2051. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2052. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2053. device_number = prescribingNumberInt
  2054. }
  2055. var number_count int64
  2056. if prescribingNumberUnit == drug.MaxUnit {
  2057. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2058. number_count = prescribingNumberInt * drug.MinNumber
  2059. }
  2060. if prescribingNumberUnit == drug.MinUnit {
  2061. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2062. number_count = prescribingNumberInt
  2063. }
  2064. //如果修改的数量大于之前修改的数量
  2065. if (number_count - device_number) > 0 {
  2066. //如果修改的差数量 大于库存数量
  2067. if drug.IsUse != 1 {
  2068. if drug.IsProject == 0 || drug.IsProject == 2 {
  2069. if total_count == 0 {
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if (number_count - device_number) > total_count {
  2074. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2075. return
  2076. }
  2077. if (number_count - device_number) > batch_number_count {
  2078. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2079. return
  2080. }
  2081. }
  2082. if adminInfo.CurrentOrgId == 10215 {
  2083. // 查询该药品最后一次出库记录
  2084. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2085. var out_count int64
  2086. var in_count int64
  2087. var stock_max_number int64
  2088. var stock_min_number int64
  2089. for _, it := range outInfo {
  2090. if it.CountUnit == drug.MaxUnit {
  2091. it.Count = it.Count * drug.MinNumber
  2092. }
  2093. out_count += it.Count
  2094. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2095. stock_max_number = warehouseInfoList.StockMaxNumber
  2096. stock_min_number = warehouseInfoList.StockMinNumber
  2097. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2098. }
  2099. if out_count > 0 {
  2100. if (number_count - device_number) > in_count {
  2101. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2102. return
  2103. }
  2104. }
  2105. // 未出库
  2106. if out_count == 0 {
  2107. var sum_in_count int64
  2108. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2109. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2110. fmt.Println("sum_in_count", sum_in_count)
  2111. //如果修改的数量大于有库存的第一个批次
  2112. if number_count > sum_in_count {
  2113. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2114. return
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2121. if pharmacyConfig.IsOpen != 1 {
  2122. if device_number != number_count {
  2123. // 查询该药品最后一次出库记录
  2124. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2125. //回退库存
  2126. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2127. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2128. }
  2129. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2130. var stock_max_number int64
  2131. var stock_min_number int64
  2132. if number_count >= drug.MinNumber {
  2133. stock_max_number = device_number / drug.MinNumber
  2134. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2135. stock_min_number = device_number % drug.MinNumber
  2136. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2137. } else {
  2138. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2139. }
  2140. }
  2141. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2142. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2143. }
  2144. //删除记录
  2145. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2146. //查询默认仓库剩余多少库存
  2147. var sum_count int64
  2148. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2149. for _, its := range stockInfo {
  2150. if its.MaxUnit == drug.MaxUnit {
  2151. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2152. }
  2153. sum_count += its.StockMaxNumber + its.StockMinNumber
  2154. }
  2155. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2156. }
  2157. }
  2158. }
  2159. }
  2160. }
  2161. //保存处方开药
  2162. if drugOutConfig.IsOpen == 1 {
  2163. //修改处方
  2164. for _, advice := range advices {
  2165. var drug_id int64
  2166. var prescribing_number float64
  2167. var prescribingNumberUnit string
  2168. var prescribingNumber string
  2169. var adviceId int64
  2170. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2171. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2172. }
  2173. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2174. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2175. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2176. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2177. }
  2178. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2179. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2180. }
  2181. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2182. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2183. }
  2184. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2185. if drug.ID == 0 {
  2186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2187. return
  2188. }
  2189. //查询药品的所有库存
  2190. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2191. var total_count int64
  2192. for _, it := range list {
  2193. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2194. }
  2195. totals := strconv.FormatInt(total_count, 10)
  2196. //查询该药品是否存在开药记录
  2197. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2198. //新增处方
  2199. if advicelist.ID == 0 {
  2200. //查询最新批次库存
  2201. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2202. var batch_number_count int64
  2203. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2204. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2205. all_count, _ := strconv.ParseFloat(totals, 64)
  2206. if prescribingNumberUnit == drug.MinUnit {
  2207. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2208. if drug.IsUse != 1 {
  2209. if drug.IsProject == 0 || drug.IsProject == 2 {
  2210. if all_count == 0 {
  2211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2212. return
  2213. }
  2214. if prescribing_number > all_count {
  2215. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2216. return
  2217. }
  2218. }
  2219. if adminInfo.CurrentOrgId == 10215 {
  2220. if prescribing_number > batch_number_all_count {
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. } else {
  2227. if prescribingNumberUnit == drug.MaxUnit {
  2228. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2229. num := prescribing_number * float64(drug.MinNumber)
  2230. if drug.IsUse != 1 {
  2231. if drug.IsProject == 0 || drug.IsProject == 2 {
  2232. if all_count == 0 {
  2233. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2234. return
  2235. }
  2236. if num > all_count {
  2237. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2238. return
  2239. }
  2240. }
  2241. if adminInfo.CurrentOrgId == 10215 {
  2242. if prescribing_number > batch_number_all_count {
  2243. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2244. return
  2245. }
  2246. }
  2247. }
  2248. }
  2249. }
  2250. }
  2251. //修改处方
  2252. if advicelist.ID > 0 {
  2253. //查询最新批次库存
  2254. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2255. var batch_number_count int64
  2256. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2257. var device_number int64
  2258. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2259. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2260. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2261. device_number = prescribingNumberInt * drug.MinNumber
  2262. }
  2263. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2264. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2265. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2266. device_number = prescribingNumberInt
  2267. }
  2268. var number_count int64
  2269. if prescribingNumberUnit == drug.MaxUnit {
  2270. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2271. number_count = prescribingNumberInt * drug.MinNumber
  2272. }
  2273. if prescribingNumberUnit == drug.MinUnit {
  2274. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2275. number_count = prescribingNumberInt
  2276. }
  2277. //如果修改的数量大于之前修改的数量
  2278. if (number_count - device_number) > 0 {
  2279. //如果修改的差数量 大于库存数量
  2280. if drug.IsUse != 1 {
  2281. if drug.IsProject == 0 || drug.IsProject == 2 {
  2282. if total_count == 0 {
  2283. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2284. return
  2285. }
  2286. if (number_count - device_number) > total_count {
  2287. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2288. return
  2289. }
  2290. }
  2291. if adminInfo.CurrentOrgId == 10215 {
  2292. if (number_count - device_number) > batch_number_count {
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2294. return
  2295. }
  2296. }
  2297. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2298. //查询历史出库数据总批次
  2299. // 查询该药品最后一次出库记录
  2300. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2301. var out_count int64
  2302. var in_count int64
  2303. var stock_max_number int64
  2304. var stock_min_number int64
  2305. for _, it := range outInfo {
  2306. if it.CountUnit == drug.MaxUnit {
  2307. it.Count = it.Count * drug.MinNumber
  2308. }
  2309. out_count += it.Count
  2310. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2311. stock_max_number = warehouseInfoList.StockMaxNumber
  2312. stock_min_number = warehouseInfoList.StockMinNumber
  2313. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2314. }
  2315. if out_count > 0 {
  2316. if (number_count - device_number) > in_count {
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2318. return
  2319. }
  2320. }
  2321. // 未出库
  2322. if out_count == 0 {
  2323. var sum_in_count int64
  2324. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2325. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2326. if sum_in_count == 0 {
  2327. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2328. return
  2329. }
  2330. //如果修改的数量大于有库存的第一个批次
  2331. if number_count > sum_in_count {
  2332. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2333. return
  2334. }
  2335. }
  2336. }
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. //校验耗材库存
  2350. if goodOutConfig.IsOpen == 1 {
  2351. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2352. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2353. if len(prescriptions) > 0 {
  2354. for _, item := range prescriptions {
  2355. items := item.(map[string]interface{})
  2356. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2357. projects := items["project"].([]interface{})
  2358. if len(projects) > 0 {
  2359. for _, project := range projects {
  2360. var project_id int64
  2361. var project_type int64
  2362. var totals float64
  2363. var project_name string
  2364. var parsetotal int64
  2365. var id int64
  2366. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2367. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2368. }
  2369. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2370. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2371. }
  2372. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2373. total, _ := project.(map[string]interface{})["total"].(string)
  2374. totals, _ = strconv.ParseFloat(total, 64)
  2375. }
  2376. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2377. project_name = project.(map[string]interface{})["project_name"].(string)
  2378. }
  2379. if project_type == 3 {
  2380. //查找该耗材的出库记录
  2381. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2382. if len(goodWarehouseInfo) == 0 {
  2383. //查询耗材库存
  2384. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2385. var stock_count int64
  2386. for _, it := range list {
  2387. stock_count += it.StockCount
  2388. }
  2389. stock_counts := strconv.FormatInt(stock_count, 10)
  2390. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2391. if stock_total_count == 0 {
  2392. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2393. return
  2394. }
  2395. if totals > stock_total_count {
  2396. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2397. return
  2398. }
  2399. }
  2400. if len(goodWarehouseInfo) > 0 {
  2401. //查询该患者耗材的历史数据
  2402. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2403. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2404. //数量发生改变
  2405. if parsetotal != count {
  2406. //如果现在的数量大于历史数量,就要看库存是否足够
  2407. if parsetotal > count {
  2408. //查询耗材所有库存
  2409. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2410. var stock_count int64
  2411. for _, it := range list {
  2412. stock_count += it.StockCount
  2413. }
  2414. //库存不足
  2415. if stock_count == 0 {
  2416. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2417. return
  2418. }
  2419. if (parsetotal - count) > stock_count {
  2420. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2421. return
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. //不使用耗材保存处方出库
  2435. if goodOutConfig.IsOpen != 1 {
  2436. if stockConfig.IsOpen == 1 {
  2437. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2438. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2439. if len(prescriptions) > 0 {
  2440. for _, item := range prescriptions {
  2441. items := item.(map[string]interface{})
  2442. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2443. projects := items["project"].([]interface{})
  2444. if len(projects) > 0 {
  2445. for _, project := range projects {
  2446. var project_id int64
  2447. var project_type int64
  2448. var totals float64
  2449. var project_name string
  2450. var parsetotal int64
  2451. var id int64
  2452. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2453. id = int64(project.(map[string]interface{})["id"].(float64))
  2454. }
  2455. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2456. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2457. }
  2458. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2459. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2460. }
  2461. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2462. total, _ := project.(map[string]interface{})["total"].(string)
  2463. totals, _ = strconv.ParseFloat(total, 64)
  2464. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2465. }
  2466. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2467. project_name = project.(map[string]interface{})["project_name"].(string)
  2468. }
  2469. if project_type == 3 {
  2470. //查找该耗材的出库记录
  2471. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2472. //没有出库记录
  2473. if len(goodWarehouseInfo) == 0 {
  2474. //查询耗材库存
  2475. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2476. var stock_count int64
  2477. for _, it := range list {
  2478. stock_count += it.StockCount
  2479. }
  2480. stock_counts := strconv.FormatInt(stock_count, 10)
  2481. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2482. if stock_total_count == 0 {
  2483. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2484. return
  2485. }
  2486. if totals > stock_total_count {
  2487. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2488. return
  2489. }
  2490. //查找今日该患者已经出库的所有耗材
  2491. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2492. for _, item := range goodList {
  2493. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2494. var flush_count int64
  2495. for _, it := range goodListSix {
  2496. flush_count += it.StockCount
  2497. }
  2498. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2499. creater := adminInfo.AdminUser.Id
  2500. if errs != nil {
  2501. goodErrcode := models.XtGoodErrcode{
  2502. UserOrgId: item.OrgId,
  2503. Errcode: "手动出库更新剩余出库失败",
  2504. GoodId: item.GoodId,
  2505. Status: 1,
  2506. Ctime: time.Now().Unix(),
  2507. Mtime: 0,
  2508. Count: 0,
  2509. StockCount: 0,
  2510. Creater: creater,
  2511. BatchNumberId: 0,
  2512. WarehouseOutId: 0,
  2513. }
  2514. service.CreateGoodErrcode(goodErrcode)
  2515. }
  2516. }
  2517. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2518. }
  2519. //有出库记录
  2520. if len(goodWarehouseInfo) > 0 {
  2521. //查询该患者耗材的历史数据
  2522. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2523. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2524. //数量发生改变
  2525. if parsetotal != count {
  2526. //查找今日该患者已经出库的所有耗材
  2527. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2528. for _, item := range goodList {
  2529. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2530. var flush_count int64
  2531. for _, it := range goodListSix {
  2532. flush_count += it.StockCount
  2533. }
  2534. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2535. //减少出库数量
  2536. creater := adminInfo.AdminUser.Id
  2537. if errs != nil {
  2538. goodErrcode := models.XtGoodErrcode{
  2539. UserOrgId: item.OrgId,
  2540. Errcode: "手动出库更新剩余出库失败",
  2541. GoodId: item.GoodId,
  2542. Status: 1,
  2543. Ctime: time.Now().Unix(),
  2544. Mtime: 0,
  2545. Count: 0,
  2546. StockCount: 0,
  2547. Creater: creater,
  2548. BatchNumberId: 0,
  2549. WarehouseOutId: 0,
  2550. }
  2551. service.CreateGoodErrcode(goodErrcode)
  2552. }
  2553. //查询默认仓库
  2554. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2555. var total_count int64
  2556. for _, it := range stockList {
  2557. total_count += it.StockCount
  2558. }
  2559. //基础库插入数据
  2560. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2561. }
  2562. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2563. }
  2564. }
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. }
  2572. }
  2573. }
  2574. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2575. var hpInfo models.HisPrescriptionInfo
  2576. if info.ID == 0 {
  2577. var randNum int
  2578. randNum = rand.Intn(10000) + 1000
  2579. timestamp := time.Now().Unix()
  2580. tempTime := time.Unix(timestamp, 0)
  2581. timeFormat := tempTime.Format("20060102150405")
  2582. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2583. hpInfo = models.HisPrescriptionInfo{
  2584. HisPatientId: his_patient_id,
  2585. UserOrgId: adminInfo.CurrentOrgId,
  2586. RecordDate: theTime.Unix(),
  2587. PatientId: patient_id,
  2588. Status: 1,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: time.Now().Unix(),
  2591. Creator: adminInfo.AdminUser.Id,
  2592. Modifier: adminInfo.AdminUser.Id,
  2593. Diagnosis: diagnose,
  2594. SickHistory: sick_history,
  2595. Departments: department,
  2596. RegisterType: reg_type,
  2597. PrescriptionNumber: p_number,
  2598. PrescriptionStatus: 1,
  2599. Doctor: role.UserName,
  2600. DoctorId: doctor_id,
  2601. SickType: sick_type,
  2602. PType: p_type,
  2603. PatientDiagnosis: patient_diagnose,
  2604. }
  2605. service.SavePatientPrescriptionInfo(hpInfo)
  2606. //创建步骤表
  2607. finish := models.XtDialysisFinish{
  2608. IsFinish: 1,
  2609. UserOrgId: adminInfo.CurrentOrgId,
  2610. Status: 1,
  2611. Ctime: time.Now().Unix(),
  2612. Mtime: 0,
  2613. Module: 4,
  2614. RecordDate: theTime.Unix(),
  2615. Sourse: 1,
  2616. PatientId: patient_id,
  2617. }
  2618. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2619. if dialysisFinish.ID == 0 {
  2620. service.CreateDialysisFinish(finish)
  2621. }
  2622. redis := service.RedisClient()
  2623. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2624. redis.Set(key, "", time.Second)
  2625. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2626. redis.Set(keyOne, "", time.Second)
  2627. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2628. redis.Set(keySeven, "", time.Second)
  2629. defer redis.Close()
  2630. } else {
  2631. hpInfo = models.HisPrescriptionInfo{
  2632. ID: info.ID,
  2633. UserOrgId: adminInfo.CurrentOrgId,
  2634. RecordDate: info.RecordDate,
  2635. PatientId: info.PatientId,
  2636. Status: 1,
  2637. Ctime: info.Ctime,
  2638. Mtime: time.Now().Unix(),
  2639. Creator: info.Creator,
  2640. Modifier: adminInfo.AdminUser.Id,
  2641. Diagnosis: diagnose,
  2642. SickHistory: sick_history,
  2643. Departments: department,
  2644. RegisterType: reg_type,
  2645. PrescriptionNumber: info.PrescriptionNumber,
  2646. Doctor: role.UserName,
  2647. PrescriptionStatus: info.PrescriptionStatus,
  2648. DoctorId: doctor_id,
  2649. SickType: sick_type,
  2650. PType: info.PType,
  2651. HisPatientId: info.HisPatientId,
  2652. PatientDiagnosis: patient_diagnose,
  2653. }
  2654. service.SavePatientPrescriptionInfo(hpInfo)
  2655. //创建步骤表
  2656. finish := models.XtDialysisFinish{
  2657. IsFinish: 1,
  2658. UserOrgId: adminInfo.CurrentOrgId,
  2659. Status: 1,
  2660. Ctime: time.Now().Unix(),
  2661. Mtime: 0,
  2662. Module: 4,
  2663. RecordDate: info.RecordDate,
  2664. Sourse: 1,
  2665. PatientId: info.PatientId,
  2666. }
  2667. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2668. if dialysisFinish.ID == 0 {
  2669. service.CreateDialysisFinish(finish)
  2670. }
  2671. redis := service.RedisClient()
  2672. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2673. redis.Set(key, "", time.Second)
  2674. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2675. redis.Set(keyOne, "", time.Second)
  2676. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2677. redis.Set(keySeven, "", time.Second)
  2678. defer redis.Close()
  2679. }
  2680. //定义切片
  2681. var adviceList []models.HisDoctorAdviceInfo
  2682. var projectList []models.HisPrescriptionProject
  2683. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2684. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2685. var tempPrescription *models.HisPrescription
  2686. if len(prescriptions) > 0 {
  2687. for _, item := range prescriptions {
  2688. items := item.(map[string]interface{})
  2689. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2690. utils.ErrorLog("id")
  2691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2692. return
  2693. }
  2694. id := int64(items["id"].(float64))
  2695. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2696. tempPrescription = &new_prescription
  2697. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2698. utils.ErrorLog("type")
  2699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2700. return
  2701. }
  2702. types := int64(items["type"].(float64))
  2703. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2704. utils.ErrorLog("med_type")
  2705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2706. return
  2707. }
  2708. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2709. if med_type == "0" {
  2710. med_type = "14"
  2711. }
  2712. //if order_status == 0 {
  2713. // order_status = 1
  2714. //}
  2715. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2716. utils.ErrorLog("pre_time")
  2717. }
  2718. preTime, _ := items["pre_time"].(string)
  2719. timeLayout := "2006-01-02"
  2720. loc, _ := time.LoadLocation("Local")
  2721. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2722. if err != nil {
  2723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2724. return
  2725. }
  2726. pTime := theTime2.Unix()
  2727. ctime := time.Now().Unix()
  2728. if tempPrescription.ID == 0 {
  2729. prescription := &models.HisPrescription{
  2730. ID: 0,
  2731. PatientId: patient_id,
  2732. UserOrgId: adminInfo.CurrentOrgId,
  2733. RecordDate: recordDateTime,
  2734. Ctime: ctime,
  2735. Mtime: ctime,
  2736. Type: types,
  2737. Modifier: adminInfo.AdminUser.Id,
  2738. Creator: adminInfo.AdminUser.Id,
  2739. Status: 1,
  2740. Doctor: role.UserName,
  2741. HisPatientId: his_patient_id,
  2742. OrderStatus: 1,
  2743. BatchNumber: "",
  2744. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2745. PreTime: pTime,
  2746. PType: p_type,
  2747. MedType: med_type,
  2748. }
  2749. tempPrescription = prescription
  2750. service.SaveHisPrescription(tempPrescription)
  2751. redis := service.RedisClient()
  2752. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2753. redis.Set(key, "", time.Second)
  2754. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2755. redis.Set(keyOne, "", time.Second)
  2756. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2757. redis.Set(keySeven, "", time.Second)
  2758. defer redis.Close()
  2759. } else {
  2760. tempPrescription.ID = id
  2761. tempPrescription.Type = types
  2762. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2763. tempPrescription.Mtime = time.Now().Unix()
  2764. tempPrescription.Doctor = role.UserName
  2765. //tempPrescription.OrderStatus = order_status
  2766. tempPrescription.PreTime = pTime
  2767. tempPrescription.MedType = med_type
  2768. service.SaveHisPrescription(tempPrescription)
  2769. redis := service.RedisClient()
  2770. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2771. redis.Set(key, "", time.Second)
  2772. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2773. redis.Set(keyOne, "", time.Second)
  2774. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2775. redis.Set(keySeven, "", time.Second)
  2776. defer redis.Close()
  2777. }
  2778. //service.SaveHisPrescription(prescription)
  2779. //更改患者挂号状态
  2780. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2781. fmt.Println("更改失败", err2)
  2782. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2783. advices := items["advices"].([]interface{})
  2784. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2785. groupNo := int64(0)
  2786. ctime := time.Now().Unix()
  2787. mtime := ctime
  2788. if len(advices) > 0 {
  2789. for _, advice := range advices {
  2790. var s models.HisDoctorAdviceInfo
  2791. s.PrescriptionId = tempPrescription.ID
  2792. s.AdviceType = 2
  2793. s.AdviceDoctor = doctor_id
  2794. s.StopState = 2
  2795. s.ExecutionState = 2
  2796. s.AdviceDate = recordDateTime
  2797. s.Status = 1
  2798. s.UserOrgId = adminInfo.CurrentOrgId
  2799. s.RecordDate = recordDateTime
  2800. s.StartTime = tempPrescription.PreTime
  2801. s.Groupno = groupNo
  2802. s.CreatedTime = ctime
  2803. s.UpdatedTime = mtime
  2804. s.PatientId = patient_id
  2805. s.HisPatientId = his_patient_id
  2806. s.StartTime = pTime
  2807. s.IsSettle = 2
  2808. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2809. if errcode > 0 {
  2810. c.ServeFailJSONWithSGJErrorCode(errcode)
  2811. return
  2812. }
  2813. s.StartTime = pTime
  2814. var total_count int64 //处方总库存
  2815. //查询改药品信息
  2816. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2817. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2818. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2819. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2820. total_count += prescribingNumberSeven * medical.MinNumber
  2821. }
  2822. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2823. total_count += prescribingNumberSeven
  2824. }
  2825. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2826. total_count += prescribingNumberSeven
  2827. }
  2828. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2829. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2830. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2831. if s.Price != lastWarehouse.RetailPrice {
  2832. s.Price = lastWarehouse.RetailPrice
  2833. }
  2834. if s.Price == 0 {
  2835. s.Price = lastWarehouse.RetailPrice
  2836. }
  2837. }
  2838. service.CreateHisDoctorAdvice(&s)
  2839. //记录日志
  2840. byterequest, _ := json.Marshal(s)
  2841. adviceLog := models.XtDoctorAdviceLog{
  2842. UserOrgId: s.UserOrgId,
  2843. PatientId: s.PatientId,
  2844. AdminUserId: adminInfo.AdminUser.Id,
  2845. Module: 1,
  2846. ErrLog: string(byterequest),
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Source: "电脑端新建his医嘱",
  2851. RecordDate: s.AdviceDate,
  2852. }
  2853. service.CreateDoctorAdviceLog(adviceLog)
  2854. //存储切片中
  2855. adviceList = append(adviceList, s)
  2856. redis := service.RedisClient()
  2857. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2858. redis.Set(key, "", time.Second)
  2859. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2860. redis.Set(keyOne, "", time.Second)
  2861. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2862. redis.Set(keySeven, "", time.Second)
  2863. var randNum int
  2864. randNum = rand.Intn(10000) + 1000
  2865. timestamp := time.Now().Unix()
  2866. tempTime := time.Unix(timestamp, 0)
  2867. timeFormat := tempTime.Format("20060102150405")
  2868. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2869. service.CreateHisDoctorAdvice(&s)
  2870. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2871. redis.Set(keySix, "", time.Second)
  2872. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2873. redis.Set(keyFive, "", time.Second)
  2874. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2875. redis.Set(keyEight, "", time.Second)
  2876. defer redis.Close()
  2877. }
  2878. }
  2879. }
  2880. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2881. projects := items["project"].([]interface{})
  2882. if len(projects) > 0 {
  2883. for _, project := range projects {
  2884. var p models.HisPrescriptionProject
  2885. p.PrescriptionId = tempPrescription.ID
  2886. p.Ctime = time.Now().Unix()
  2887. p.Mtime = time.Now().Unix()
  2888. p.PatientId = patient_id
  2889. p.RecordDate = recordDateTime
  2890. p.Doctor = doctor_id
  2891. p.UserOrgId = adminInfo.CurrentOrgId
  2892. p.HisPatientId = his_patient_id
  2893. p.Status = 1
  2894. p.StartTime = pTime
  2895. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2896. if errcode > 0 {
  2897. c.ServeFailJSONWithSGJErrorCode(errcode)
  2898. return
  2899. }
  2900. if p.ID == 0 {
  2901. p.IsOut = 2
  2902. }
  2903. if p.ID > 0 {
  2904. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2905. p.IsOut = projectDetail.IsOut
  2906. }
  2907. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2908. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2909. if p.Type == 3 {
  2910. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2911. if p.Price != lastWarehouse.PackingPrice {
  2912. p.Price = lastWarehouse.PackingPrice
  2913. }
  2914. if p.Unit == "" {
  2915. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2916. p.Unit = goodInfoOne.PackingUnit
  2917. }
  2918. }
  2919. }
  2920. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2921. //
  2922. // if p.Type == 3 {
  2923. // //查询该耗材是否停用
  2924. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2925. // //表示该耗材已经停用,不能保存
  2926. // if goodInfoSeven.ID == 0 {
  2927. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2928. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2929. // return
  2930. // }
  2931. // }
  2932. //
  2933. //}
  2934. service.CreateHisProjectTwo(&p)
  2935. //记录日志
  2936. byterequest, _ := json.Marshal(p)
  2937. adviceLog := models.XtDoctorAdviceLog{
  2938. UserOrgId: p.UserOrgId,
  2939. PatientId: p.PatientId,
  2940. AdminUserId: adminInfo.AdminUser.Id,
  2941. Module: 1,
  2942. ErrLog: string(byterequest),
  2943. Status: 1,
  2944. Ctime: time.Now().Unix(),
  2945. Mtime: 0,
  2946. Source: "电脑端新建his项目",
  2947. RecordDate: p.RecordDate,
  2948. }
  2949. service.CreateDoctorAdviceLog(adviceLog)
  2950. projectList = append(projectList, p)
  2951. var randNum int
  2952. randNum = rand.Intn(10000) + 1000
  2953. timestamp := time.Now().Unix()
  2954. tempTime := time.Unix(timestamp, 0)
  2955. timeFormat := tempTime.Format("20060102150405")
  2956. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2957. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2958. //新增或者编辑项目,修改对应的标签数据
  2959. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2960. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2961. var label models.HisLabelPrintInfo
  2962. project, _ := service.GetProjectDetail(p.ProjectId)
  2963. if project.CostClassify == 3 { //类别为检验检查
  2964. if p.TeamId > 0 { //检验检查组套
  2965. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2966. if tempLabel.ID == 0 {
  2967. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2968. label.Number = tempPrescription.PrescriptionNumber
  2969. label.ProjectId = project.ID
  2970. label.Status = 1
  2971. label.IsPrint = 2
  2972. label.DoctorId = info.DoctorId
  2973. label.UserOrgId = p.UserOrgId
  2974. label.PatientId = patient_id
  2975. label.RecordDate = recordDateTime
  2976. label.Ctime = time.Now().Unix()
  2977. label.Mtime = time.Now().Unix()
  2978. label.ItemId = p.TeamId
  2979. label.FeedetlSn = p.FeedetlSn
  2980. label.PProjectId = p.ID
  2981. label.ProjectName = team.ProjectTeam
  2982. label.PatientName = patient.Name
  2983. service.CreateHisLabelRecord(&label)
  2984. }
  2985. } else { //单条检验检查项目
  2986. label.Number = tempPrescription.PrescriptionNumber
  2987. label.ProjectId = project.ID
  2988. label.Status = 1
  2989. label.DoctorId = info.DoctorId
  2990. label.UserOrgId = p.UserOrgId
  2991. label.PatientId = patient_id
  2992. label.RecordDate = recordDateTime
  2993. label.IsPrint = 2
  2994. label.Ctime = time.Now().Unix()
  2995. label.Mtime = time.Now().Unix()
  2996. label.FeedetlSn = p.FeedetlSn
  2997. label.PProjectId = p.ID
  2998. label.ItemId = p.TeamId
  2999. label.ProjectName = project.ProjectName
  3000. label.PatientName = patient.Name
  3001. service.CreateHisLabelRecord(&label)
  3002. }
  3003. }
  3004. }
  3005. }
  3006. service.SaveHisProjectTwo(&p)
  3007. }
  3008. }
  3009. }
  3010. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3011. // addition := items["addition"].([]interface{})
  3012. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3013. // ctime := time.Now().Unix()
  3014. // mtime := ctime
  3015. // if len(addition) > 0 {
  3016. // for _, item := range addition {
  3017. // var s models.HisAdditionalCharge
  3018. // s.PrescriptionId = tempPrescription.ID
  3019. // s.Status = 1
  3020. // s.UserOrgId = adminInfo.CurrentOrgId
  3021. // s.RecordDate = recordDateTime
  3022. // s.CreatedTime = ctime
  3023. // s.UpdatedTime = mtime
  3024. // s.PatientId = patient_id
  3025. // s.HisPatientId = his_patient_id
  3026. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3027. // if errcode > 0 {
  3028. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3029. // return
  3030. // }
  3031. // service.CreateAdditionalCharge(&s)
  3032. // var randNum int
  3033. // randNum = rand.Intn(10000) + 1000
  3034. // timestamp := time.Now().Unix()
  3035. // tempTime := time.Unix(timestamp, 0)
  3036. // timeFormat := tempTime.Format("20060102150405")
  3037. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3038. // service.CreateAdditionalCharge(&s)
  3039. //
  3040. // }
  3041. // }
  3042. //}
  3043. }
  3044. }
  3045. //查询今日该患者开的药品处方
  3046. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3047. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3048. //药品出库
  3049. if drugOutConfig.IsOpen == 1 {
  3050. for _, item := range hisdoctorlist {
  3051. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3052. // 查询该药品最后一次出库记录
  3053. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3054. if len(druginfo) > 0 {
  3055. //回退库存
  3056. for _, it := range druginfo {
  3057. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3058. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3059. }
  3060. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3061. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3062. }
  3063. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3064. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3065. }
  3066. }
  3067. }
  3068. //删除记录
  3069. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3070. //查询最后一次数据
  3071. if drugOutConfig.IsOpen == 1 {
  3072. //出库
  3073. if drug.IsUse == 2 {
  3074. creater := adminInfo.AdminUser.Id
  3075. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3076. }
  3077. //更新字典里面的库存
  3078. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3079. var sum_count int64
  3080. for _, its := range stockInfo {
  3081. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3082. if its.MaxUnit == baseDrug.MaxUnit {
  3083. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3084. }
  3085. sum_count += its.StockMaxNumber + its.StockMinNumber
  3086. }
  3087. //更新基础库存
  3088. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3089. //剩余库存
  3090. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3091. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3092. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3093. }
  3094. }
  3095. }
  3096. //耗材保存处方出库
  3097. if goodOutConfig.IsOpen == 1 {
  3098. //查询今日耗材出库数量
  3099. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3100. for _, item := range hisgoodlist {
  3101. //查询历史出库数据
  3102. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3103. var out_count_five int64
  3104. for _, item := range flowGood {
  3105. out_count_five += item.Count
  3106. }
  3107. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3108. if out_count_five != parseIntCount {
  3109. //查询耗材最后一次出库记录
  3110. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3111. //查询默认出库仓库库存
  3112. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3113. if len(wareOut) > 0 {
  3114. for _, it := range wareOut {
  3115. //回退库存
  3116. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3117. //删除出库记录
  3118. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3119. }
  3120. }
  3121. timeStr := time.Now().Format("2006-01-02")
  3122. timeArr := strings.Split(timeStr, "-")
  3123. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3124. total = total + 1
  3125. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3126. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3127. number = number + total
  3128. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3129. operation_time := time.Now().Unix()
  3130. creater := c.GetAdminUserInfo().AdminUser.Id
  3131. recordDateStr := time.Now().Format("2006-01-02")
  3132. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3133. nowtime := recordDate.Unix()
  3134. warehouseOut := models.WarehouseOut{
  3135. WarehouseOutOrderNumber: warehousing_out_order,
  3136. OperationTime: operation_time,
  3137. OrgId: adminInfo.CurrentOrgId,
  3138. Creater: creater,
  3139. Ctime: time.Now().Unix(),
  3140. Status: 1,
  3141. WarehouseOutTime: nowtime,
  3142. Type: 1,
  3143. StorehouseId: storeConfig.StorehouseOutInfo,
  3144. IsCheck: 1,
  3145. IsSys: 1,
  3146. }
  3147. //查询是否生成出库单
  3148. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3149. if out.ID == 0 {
  3150. service.AddSigleWarehouseOut(&warehouseOut)
  3151. }
  3152. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3153. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3154. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3155. dialyPrepareOne := models.DialysisBeforePrepare{
  3156. GoodTypeId: goodObj.GoodTypeId,
  3157. GoodId: item.ProjectId,
  3158. PatientId: item.PatientId,
  3159. RecordDate: item.RecordDate,
  3160. UserOrgId: adminInfo.CurrentOrgId,
  3161. Count: parseIntCount,
  3162. Ctime: time.Now().Unix(),
  3163. Creater: creater,
  3164. Status: 1,
  3165. StorehouseId: houseConfig.StorehouseOutInfo,
  3166. ProjectId: item.ID,
  3167. }
  3168. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3169. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3170. //查询历史出库数据
  3171. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3172. var out_count int64
  3173. for _, item := range flowGood {
  3174. out_count += item.Count
  3175. }
  3176. //如果历史数和当前数据不想等才进行退库出库
  3177. if out_count != parseIntCount {
  3178. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3179. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3180. detail := models.AutomaticReduceDetail{
  3181. WarehouseOutId: 0,
  3182. WarehouseOutOrderNumber: "",
  3183. PatientId: item.PatientId,
  3184. Ctime: time.Now().Unix(),
  3185. Mtime: 0,
  3186. Status: 1,
  3187. RecordTime: item.RecordDate,
  3188. OrgId: item.UserOrgId,
  3189. GoodId: item.ProjectId,
  3190. GoodTypeId: 0,
  3191. Count: parseIntCount,
  3192. Type: 0,
  3193. ProjectId: item.ID,
  3194. StorehouseId: 0,
  3195. }
  3196. service.CreateAutoDetail(detail)
  3197. //查询剩余库存
  3198. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3199. var sum_count int64
  3200. for _, item := range goodList {
  3201. sum_count += item.StockCount
  3202. }
  3203. //更新剩余库存
  3204. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3205. //耗材
  3206. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3207. }
  3208. }
  3209. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3210. //查询历史出库数据
  3211. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3212. var out_count int64
  3213. for _, item := range flowGood {
  3214. out_count += item.Count
  3215. }
  3216. //如果历史数和当前数据不想等才进行退库出库
  3217. if out_count != parseIntCount {
  3218. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3219. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3220. detail := models.AutomaticReduceDetail{
  3221. WarehouseOutId: 0,
  3222. WarehouseOutOrderNumber: "",
  3223. PatientId: item.PatientId,
  3224. Ctime: time.Now().Unix(),
  3225. Mtime: 0,
  3226. Status: 1,
  3227. RecordTime: item.RecordDate,
  3228. OrgId: item.UserOrgId,
  3229. GoodId: item.ProjectId,
  3230. GoodTypeId: 0,
  3231. Count: parseIntCount,
  3232. Type: 0,
  3233. ProjectId: item.ID,
  3234. StorehouseId: 0,
  3235. }
  3236. service.CreateAutoDetail(detail)
  3237. //查询剩余库存
  3238. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3239. var sum_count int64
  3240. for _, item := range goodList {
  3241. sum_count += item.StockCount
  3242. }
  3243. //更新剩余库存
  3244. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3245. //耗材
  3246. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3247. }
  3248. }
  3249. }
  3250. }
  3251. }
  3252. }
  3253. //redisClient := service.RedisClient()
  3254. //defer redisClient.Close()
  3255. //
  3256. //list := models.HisList{
  3257. // Patient_id: patient_id,
  3258. // Advice_id:0,
  3259. // Record_date: 0,
  3260. // Advice: adviceList,
  3261. // Project: nil,
  3262. //}
  3263. //hisLis = append(hisLis, list)
  3264. //
  3265. //advice_json, _ := json.Marshal(&hisLis)
  3266. //redisClient.RPush("111", advice_json).Result()
  3267. //result, _ := redisClient.RPop("111").Result()
  3268. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3269. //
  3270. //var dat []map[string]interface{}
  3271. //json.Unmarshal([]byte(result), &dat)
  3272. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3273. //
  3274. //for k,v:=range dat{
  3275. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3276. //}
  3277. //project_json, _ := json.Marshal(&projectList)
  3278. //redisClient.LPush("222", project_json).Result()
  3279. if err == nil {
  3280. c.ServeSuccessJSON(map[string]interface{}{
  3281. "msg": "保存成功",
  3282. })
  3283. return
  3284. } else {
  3285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3286. return
  3287. }
  3288. }
  3289. func (c *HisApiController) EditHisPrescription() {
  3290. record_date := c.GetString("record_date")
  3291. patient_id, _ := c.GetInt64("patient_id")
  3292. reg_type, _ := c.GetInt64("reg_type")
  3293. //diagnose, _ := c.GetInt64("diagnose", 0)
  3294. diagnose := c.GetString("diagnose")
  3295. sick_type, _ := c.GetInt64("sick_type")
  3296. sick_history := c.GetString("sick_history")
  3297. doctor_id, _ := c.GetInt64("doctor", 0)
  3298. department, _ := c.GetInt64("department", 0)
  3299. his_patient_id, _ := c.GetInt64("his_patient_id")
  3300. p_type, _ := c.GetInt64("p_type")
  3301. dataBody := make(map[string]interface{}, 0)
  3302. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3303. if err != nil {
  3304. utils.ErrorLog(err.Error())
  3305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3306. return
  3307. }
  3308. timeLayout := "2006-01-02"
  3309. loc, _ := time.LoadLocation("Local")
  3310. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3311. if err != nil {
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3313. return
  3314. }
  3315. adminInfo := c.GetAdminUserInfo()
  3316. recordDateTime := theTime.Unix()
  3317. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3318. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3319. var hpInfo models.HisPrescriptionInfo
  3320. if info.ID == 0 {
  3321. var randNum int
  3322. randNum = rand.Intn(10000) + 1000
  3323. timestamp := time.Now().Unix()
  3324. tempTime := time.Unix(timestamp, 0)
  3325. timeFormat := tempTime.Format("20060102150405")
  3326. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3327. hpInfo = models.HisPrescriptionInfo{
  3328. UserOrgId: adminInfo.CurrentOrgId,
  3329. RecordDate: theTime.Unix(),
  3330. PatientId: patient_id,
  3331. Status: 1,
  3332. Ctime: time.Now().Unix(),
  3333. Mtime: time.Now().Unix(),
  3334. Creator: adminInfo.AdminUser.Id,
  3335. Modifier: adminInfo.AdminUser.Id,
  3336. Diagnosis: diagnose,
  3337. SickHistory: sick_history,
  3338. Departments: department,
  3339. RegisterType: reg_type,
  3340. PrescriptionNumber: p_number,
  3341. PrescriptionStatus: 1,
  3342. Doctor: role.UserName,
  3343. DoctorId: doctor_id,
  3344. SickType: sick_type,
  3345. PType: p_type,
  3346. }
  3347. service.SavePatientPrescriptionInfo(hpInfo)
  3348. } else {
  3349. hpInfo = models.HisPrescriptionInfo{
  3350. ID: info.ID,
  3351. UserOrgId: adminInfo.CurrentOrgId,
  3352. RecordDate: info.RecordDate,
  3353. PatientId: info.PatientId,
  3354. Status: 1,
  3355. Ctime: info.Ctime,
  3356. Mtime: time.Now().Unix(),
  3357. Creator: info.Creator,
  3358. Modifier: adminInfo.AdminUser.Id,
  3359. Diagnosis: diagnose,
  3360. SickHistory: sick_history,
  3361. Departments: department,
  3362. RegisterType: reg_type,
  3363. PrescriptionNumber: info.PrescriptionNumber,
  3364. Doctor: role.UserName,
  3365. PrescriptionStatus: info.PrescriptionStatus,
  3366. DoctorId: doctor_id,
  3367. SickType: sick_type,
  3368. PType: info.PType,
  3369. }
  3370. service.SavePatientPrescriptionInfo(hpInfo)
  3371. }
  3372. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3373. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3374. if len(prescriptions) > 0 {
  3375. for _, item := range prescriptions {
  3376. items := item.(map[string]interface{})
  3377. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3378. utils.ErrorLog("id")
  3379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3380. return
  3381. }
  3382. id := int64(items["id"].(float64))
  3383. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3384. utils.ErrorLog("type")
  3385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3386. return
  3387. }
  3388. types := int64(items["type"].(float64))
  3389. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3390. utils.ErrorLog("med_type")
  3391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3392. return
  3393. }
  3394. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3395. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3396. ctime := time.Now().Unix()
  3397. prescription := &models.HisPrescription{
  3398. ID: id,
  3399. PatientId: patient_id,
  3400. UserOrgId: adminInfo.CurrentOrgId,
  3401. RecordDate: recordDateTime,
  3402. Ctime: ctime,
  3403. Mtime: ctime,
  3404. Type: types,
  3405. Modifier: adminInfo.AdminUser.Id,
  3406. Creator: adminInfo.AdminUser.Id,
  3407. Status: 1,
  3408. Doctor: role.UserName,
  3409. HisPatientId: his_patient_id,
  3410. OrderStatus: 1,
  3411. BatchNumber: "",
  3412. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3413. PType: hpInfo.PType,
  3414. MedType: med_type,
  3415. }
  3416. if historyPrescription.ID > 0 {
  3417. prescription.PreTime = historyPrescription.PreTime
  3418. }
  3419. service.SaveHisPrescription(prescription)
  3420. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3421. advices := items["advices"].([]interface{})
  3422. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3423. groupNo := int64(0)
  3424. ctime := time.Now().Unix()
  3425. mtime := ctime
  3426. if len(advices) > 0 {
  3427. for _, advice := range advices {
  3428. var s models.HisDoctorAdviceInfo
  3429. s.PrescriptionId = prescription.ID
  3430. s.AdviceType = 2
  3431. s.AdviceDoctor = adminInfo.AdminUser.Id
  3432. s.StopState = 2
  3433. s.ExecutionState = 2
  3434. s.AdviceDate = recordDateTime
  3435. s.Status = 1
  3436. s.UserOrgId = adminInfo.CurrentOrgId
  3437. s.RecordDate = recordDateTime
  3438. s.StartTime = prescription.PreTime
  3439. s.Groupno = groupNo
  3440. s.CreatedTime = ctime
  3441. s.UpdatedTime = mtime
  3442. s.PatientId = patient_id
  3443. s.HisPatientId = his_patient_id
  3444. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3445. if errcode > 0 {
  3446. c.ServeFailJSONWithSGJErrorCode(errcode)
  3447. return
  3448. }
  3449. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3450. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3451. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3452. if s.Price == 0 {
  3453. s.Price = lastWarehouse.RetailPrice
  3454. }
  3455. }
  3456. service.CreateHisDoctorAdvice(&s)
  3457. //记录日志
  3458. byterequest, _ := json.Marshal(s)
  3459. adviceLog := models.XtDoctorAdviceLog{
  3460. UserOrgId: s.UserOrgId,
  3461. PatientId: s.PatientId,
  3462. AdminUserId: adminInfo.AdminUser.Id,
  3463. Module: 1,
  3464. ErrLog: string(byterequest),
  3465. Status: 1,
  3466. Ctime: time.Now().Unix(),
  3467. Mtime: 0,
  3468. Source: "电脑端his医嘱修改",
  3469. RecordDate: s.AdviceDate,
  3470. }
  3471. service.CreateDoctorAdviceLog(adviceLog)
  3472. redis := service.RedisClient()
  3473. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3474. redis.Set(key, "", time.Second)
  3475. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3476. fmt.Println("keyOne", keyOne)
  3477. redis.Set(keyOne, "", time.Second)
  3478. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3479. redis.Set(keySeven, "", time.Second)
  3480. redis.Close()
  3481. }
  3482. }
  3483. }
  3484. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3485. projects := items["project"].([]interface{})
  3486. if len(projects) > 0 {
  3487. for _, project := range projects {
  3488. var p models.HisPrescriptionProject
  3489. p.PrescriptionId = prescription.ID
  3490. p.Ctime = time.Now().Unix()
  3491. p.Mtime = time.Now().Unix()
  3492. p.PatientId = patient_id
  3493. p.RecordDate = recordDateTime
  3494. p.UserOrgId = adminInfo.CurrentOrgId
  3495. p.HisPatientId = his_patient_id
  3496. p.Status = 1
  3497. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3498. if errcode > 0 {
  3499. c.ServeFailJSONWithSGJErrorCode(errcode)
  3500. return
  3501. }
  3502. service.CreateHisProjectTwo(&p)
  3503. //记录日志
  3504. byterequest, _ := json.Marshal(p)
  3505. adviceLog := models.XtDoctorAdviceLog{
  3506. UserOrgId: p.UserOrgId,
  3507. PatientId: p.PatientId,
  3508. AdminUserId: adminInfo.AdminUser.Id,
  3509. Module: 1,
  3510. ErrLog: string(byterequest),
  3511. Status: 1,
  3512. Ctime: time.Now().Unix(),
  3513. Mtime: 0,
  3514. Source: "电脑端his项目修改",
  3515. RecordDate: p.RecordDate,
  3516. }
  3517. service.CreateDoctorAdviceLog(adviceLog)
  3518. }
  3519. }
  3520. }
  3521. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3522. addition := items["addition"].([]interface{})
  3523. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3524. ctime := time.Now().Unix()
  3525. mtime := ctime
  3526. if len(addition) > 0 {
  3527. for _, item := range addition {
  3528. var s models.HisAdditionalCharge
  3529. s.PrescriptionId = prescription.ID
  3530. s.Status = 1
  3531. s.UserOrgId = adminInfo.CurrentOrgId
  3532. s.RecordDate = recordDateTime
  3533. s.CreatedTime = ctime
  3534. s.UpdatedTime = mtime
  3535. s.PatientId = patient_id
  3536. s.HisPatientId = his_patient_id
  3537. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3538. if errcode > 0 {
  3539. c.ServeFailJSONWithSGJErrorCode(errcode)
  3540. return
  3541. }
  3542. service.CreateAdditionalCharge(&s)
  3543. }
  3544. }
  3545. }
  3546. }
  3547. }
  3548. }
  3549. if err == nil {
  3550. c.ServeSuccessJSON(map[string]interface{}{
  3551. "msg": "保存成功",
  3552. })
  3553. return
  3554. } else {
  3555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3556. return
  3557. }
  3558. }
  3559. func (c *HisApiController) DeletePrescription() {
  3560. prescription_id, _ := c.GetInt64("id")
  3561. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3562. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3563. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3564. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3565. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3566. //耗材保存处方出库
  3567. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3568. //已收费和已发药限制逻辑
  3569. isCharge := false
  3570. isMedicine := false
  3571. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3572. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3573. for _, item := range new_prescriptions {
  3574. if item.IsMedicine == 1 {
  3575. isMedicine = true
  3576. }
  3577. }
  3578. for _, item := range new_prescriptions {
  3579. if item.OrderStatus == 4 {
  3580. isCharge = true
  3581. }
  3582. }
  3583. if p_err != nil {
  3584. if new_prescription.ID > 0 {
  3585. if new_prescription.OrderStatus == 2 {
  3586. isCharge = true
  3587. }
  3588. }
  3589. }
  3590. for _, item := range advices {
  3591. if item.IsMedicine == 1 {
  3592. isMedicine = true
  3593. }
  3594. }
  3595. if isCharge {
  3596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3597. return
  3598. }
  3599. if isMedicine {
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3601. return
  3602. }
  3603. //已收费和已发药限制逻辑
  3604. if len(projects) > 0 {
  3605. for _, item := range projects {
  3606. service.DeletePrintInfo(item.ID) //删除打印信息
  3607. if goodOutConfig.IsOpen != 1 {
  3608. if stockConfig.IsOpen == 1 {
  3609. if item.Type == 3 && item.IsOut == 1 {
  3610. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3611. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3612. good.Total = good.Total + f_count
  3613. service.UpdateGoodInfo(&good)
  3614. operation_time := time.Now().Unix()
  3615. creater := c.GetAdminUserInfo().AdminUser.Id
  3616. //创建退库单
  3617. timeStr := time.Now().Format("2006-01-02")
  3618. timeArr := strings.Split(timeStr, "-")
  3619. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3620. total = total + 1
  3621. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3622. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3623. cancelStock := models.CancelStock{
  3624. OrderNumber: orderNumber,
  3625. OperaTime: operation_time,
  3626. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3627. Creater: creater,
  3628. Ctime: time.Now().Unix(),
  3629. Status: 1,
  3630. ReturnTime: item.RecordDate,
  3631. Type: 1,
  3632. StorehouseId: houseConfig.StorehouseOutInfo,
  3633. IsCheck: 1,
  3634. }
  3635. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3636. if msgerrkonde == gorm.ErrRecordNotFound {
  3637. service.AddSigleCancelStock(&cancelStock)
  3638. }
  3639. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3640. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3641. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3642. //查询该耗材是否出库
  3643. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3644. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3645. deaerler, _ := service.GetDealerById(info.Dealer)
  3646. var total_count int64
  3647. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3648. total_count += count
  3649. if info.ID > 0 {
  3650. if info.Count >= total_count {
  3651. //回退库存
  3652. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3653. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3654. var flush_count int64
  3655. for _, it := range goodList {
  3656. flush_count += it.StockCount
  3657. }
  3658. cancelStockInfo := models.CancelStockInfo{
  3659. GoodId: item.ProjectId,
  3660. CancelStockId: cancel.ID,
  3661. GoodTypeId: good.GoodTypeId,
  3662. Count: prescribingNumber,
  3663. Price: info.Price,
  3664. Total: 0,
  3665. ProductDate: info.ProductDate,
  3666. ExpiryDate: info.ExpiryDate,
  3667. Ctime: time.Now().Unix(),
  3668. Status: 1,
  3669. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3670. OrderNumber: cancel.OrderNumber,
  3671. Type: 0,
  3672. Dealer: deaerler.DealerName,
  3673. Manufacturer: manufacturer.ManufacturerName,
  3674. Number: info.Number,
  3675. RegisterAccount: "",
  3676. Remark: "",
  3677. WarehouseInfoId: info.WarehouseInfotId,
  3678. PatientId: info.PatientId,
  3679. RecordDate: info.SysRecordTime,
  3680. StorehouseId: houseConfig.StorehouseOutInfo,
  3681. IsCheck: 1,
  3682. }
  3683. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3684. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3685. flow := models.VmStockFlow{
  3686. WarehousingId: info.WarehouseInfotId,
  3687. GoodId: item.ProjectId,
  3688. Number: info.Number,
  3689. LicenseNumber: info.LicenseNumber,
  3690. Count: prescribingNumber,
  3691. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3692. PatientId: item.PatientId,
  3693. SystemTime: info.SysRecordTime,
  3694. ConsumableType: 7,
  3695. IsSys: 0,
  3696. WarehousingOrder: "",
  3697. WarehouseOutId: info.WarehouseOutId,
  3698. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3699. IsEdit: 0,
  3700. CancelStockId: cancel.ID,
  3701. CancelOrderNumber: cancel.OrderNumber,
  3702. Manufacturer: manufacturer.ID,
  3703. Dealer: 0,
  3704. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3705. UpdateCreator: 0,
  3706. Status: 1,
  3707. Ctime: time.Now().Unix(),
  3708. Mtime: 0,
  3709. Price: info.Price,
  3710. WarehousingDetailId: info.WarehouseInfotId,
  3711. WarehouseOutDetailId: info.ID,
  3712. CancelOutDetailId: cancelInfo.ID,
  3713. ProductDate: info.ProductDate,
  3714. ExpireDate: info.ExpiryDate,
  3715. StorehouseId: houseConfig.StorehouseOutInfo,
  3716. OverCount: flush_count,
  3717. }
  3718. service.CreateStockFlowOne(flow)
  3719. //退库数量增加
  3720. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3721. //出库数量减少
  3722. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3723. }
  3724. if info.Count < total_count {
  3725. //回退库存
  3726. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3727. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3728. var flush_count int64
  3729. for _, it := range goodList {
  3730. flush_count += it.StockCount
  3731. }
  3732. cancelStockInfo := models.CancelStockInfo{
  3733. GoodId: item.ProjectId,
  3734. CancelStockId: cancel.ID,
  3735. GoodTypeId: good.GoodTypeId,
  3736. Count: info.Count,
  3737. Price: info.Price,
  3738. Total: 0,
  3739. ProductDate: info.ProductDate,
  3740. ExpiryDate: info.ExpiryDate,
  3741. Ctime: time.Now().Unix(),
  3742. Status: 1,
  3743. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3744. OrderNumber: cancel.OrderNumber,
  3745. Type: 0,
  3746. Dealer: deaerler.DealerName,
  3747. Manufacturer: manufacturer.ManufacturerName,
  3748. Number: info.Number,
  3749. RegisterAccount: "",
  3750. Remark: "",
  3751. WarehouseInfoId: info.WarehouseInfotId,
  3752. PatientId: info.PatientId,
  3753. RecordDate: info.SysRecordTime,
  3754. StorehouseId: houseConfig.StorehouseOutInfo,
  3755. IsCheck: 1,
  3756. }
  3757. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3758. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3759. flow := models.VmStockFlow{
  3760. WarehousingId: info.WarehouseInfotId,
  3761. GoodId: item.ProjectId,
  3762. Number: info.Number,
  3763. LicenseNumber: info.LicenseNumber,
  3764. Count: info.Count,
  3765. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3766. PatientId: item.PatientId,
  3767. SystemTime: info.SysRecordTime,
  3768. ConsumableType: 7,
  3769. IsSys: 0,
  3770. WarehousingOrder: "",
  3771. WarehouseOutId: info.WarehouseOutId,
  3772. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3773. IsEdit: 0,
  3774. CancelStockId: cancel.ID,
  3775. CancelOrderNumber: cancel.OrderNumber,
  3776. Manufacturer: manufacturer.ID,
  3777. Dealer: 0,
  3778. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3779. UpdateCreator: 0,
  3780. Status: 1,
  3781. Ctime: time.Now().Unix(),
  3782. Mtime: 0,
  3783. Price: info.Price,
  3784. WarehousingDetailId: info.WarehouseInfotId,
  3785. WarehouseOutDetailId: info.ID,
  3786. CancelOutDetailId: cancelInfo.ID,
  3787. ProductDate: info.ProductDate,
  3788. ExpireDate: info.ExpiryDate,
  3789. StorehouseId: houseConfig.StorehouseOutInfo,
  3790. OverCount: flush_count,
  3791. }
  3792. service.CreateStockFlowOne(flow)
  3793. //退库数量增加
  3794. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3795. //出库数量减少
  3796. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3797. }
  3798. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3799. var flush_count int64
  3800. for _, it := range goodList {
  3801. flush_count += it.StockCount
  3802. }
  3803. //查询已出库数量
  3804. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3805. if prescribingNumber < dialysisInfo.Count {
  3806. //改变数量
  3807. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3808. }
  3809. if prescribingNumber >= dialysisInfo.Count {
  3810. //删除出库表
  3811. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3812. }
  3813. //更新库存
  3814. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3815. //更新基础库库存
  3816. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3817. }
  3818. }
  3819. }
  3820. }
  3821. //保存耗材出库
  3822. if goodOutConfig.IsOpen == 1 {
  3823. if item.Type == 3 {
  3824. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3825. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3826. good.Total = good.Total + f_count
  3827. service.UpdateGoodInfo(&good)
  3828. operation_time := time.Now().Unix()
  3829. creater := c.GetAdminUserInfo().AdminUser.Id
  3830. //创建退库单
  3831. timeStr := time.Now().Format("2006-01-02")
  3832. timeArr := strings.Split(timeStr, "-")
  3833. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3834. total = total + 1
  3835. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3836. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3837. cancelStock := models.CancelStock{
  3838. OrderNumber: orderNumber,
  3839. OperaTime: operation_time,
  3840. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3841. Creater: creater,
  3842. Ctime: time.Now().Unix(),
  3843. Status: 1,
  3844. ReturnTime: item.RecordDate,
  3845. Type: 1,
  3846. StorehouseId: houseConfig.StorehouseOutInfo,
  3847. IsCheck: 1,
  3848. }
  3849. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3850. if msgerrkonde == gorm.ErrRecordNotFound {
  3851. service.AddSigleCancelStock(&cancelStock)
  3852. }
  3853. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3854. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3855. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3856. //查询该耗材是否出库
  3857. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3858. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3859. deaerler, _ := service.GetDealerById(info.Dealer)
  3860. var total_count int64
  3861. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3862. total_count += count
  3863. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3864. var flush_count int64
  3865. for _, it := range goodList {
  3866. flush_count += it.StockCount
  3867. }
  3868. fmt.Println("历史出库数据", info.Count)
  3869. fmt.Println("出库数量", total_count)
  3870. if info.ID > 0 {
  3871. cancelStockInfo := models.CancelStockInfo{
  3872. GoodId: item.ProjectId,
  3873. CancelStockId: cancel.ID,
  3874. GoodTypeId: good.GoodTypeId,
  3875. Count: prescribingNumber,
  3876. Price: info.Price,
  3877. Total: 0,
  3878. ProductDate: info.ProductDate,
  3879. ExpiryDate: info.ExpiryDate,
  3880. Ctime: time.Now().Unix(),
  3881. Status: 1,
  3882. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3883. OrderNumber: cancel.OrderNumber,
  3884. Type: 0,
  3885. Dealer: deaerler.DealerName,
  3886. Manufacturer: manufacturer.ManufacturerName,
  3887. Number: info.Number,
  3888. RegisterAccount: "",
  3889. Remark: "",
  3890. WarehouseInfoId: info.WarehouseInfotId,
  3891. PatientId: info.PatientId,
  3892. RecordDate: info.SysRecordTime,
  3893. StorehouseId: houseConfig.StorehouseOutInfo,
  3894. IsCheck: 1,
  3895. }
  3896. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3897. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3898. //查询出库数量
  3899. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3900. //出库数据 大于 退库数量
  3901. if len(list) > 0 {
  3902. for _, it := range list {
  3903. //回退库存
  3904. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3905. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3906. var flush_count_one int64
  3907. for _, it := range goodList {
  3908. flush_count_one += it.StockCount
  3909. }
  3910. //查询该批次是否有退库数据
  3911. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3912. creater := c.GetAdminUserInfo().AdminUser.Id
  3913. flow := models.VmStockFlow{
  3914. WarehousingId: it.WarehouseInfotId,
  3915. GoodId: it.GoodId,
  3916. Number: it.Number,
  3917. LicenseNumber: it.LicenseNumber,
  3918. Count: it.Count,
  3919. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3920. PatientId: it.PatientId,
  3921. SystemTime: it.SysRecordTime,
  3922. ConsumableType: 7,
  3923. IsSys: 0,
  3924. WarehousingOrder: "",
  3925. WarehouseOutId: it.WarehouseOutId,
  3926. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3927. IsEdit: 0,
  3928. CancelStockId: cancel.ID,
  3929. CancelOrderNumber: cancel.OrderNumber,
  3930. Manufacturer: manufacturer.ID,
  3931. Dealer: 0,
  3932. Creator: creater,
  3933. UpdateCreator: 0,
  3934. Status: 1,
  3935. Ctime: time.Now().Unix(),
  3936. Mtime: 0,
  3937. Price: it.Price,
  3938. WarehousingDetailId: it.WarehouseInfotId,
  3939. WarehouseOutDetailId: it.ID,
  3940. CancelOutDetailId: cancelInfo.ID,
  3941. ProductDate: it.ProductDate,
  3942. ExpireDate: it.ExpiryDate,
  3943. StorehouseId: houseConfig.StorehouseOutInfo,
  3944. OverCount: flush_count_one,
  3945. }
  3946. service.CreateStockFlowOne(flow)
  3947. //if flow.ID > 0 {
  3948. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3949. //}
  3950. }
  3951. }
  3952. //flow := models.VmStockFlow{
  3953. // WarehousingId: info.WarehouseInfotId,
  3954. // GoodId: item.ProjectId,
  3955. // Number: info.Number,
  3956. // LicenseNumber: info.LicenseNumber,
  3957. // Count: prescribingNumber,
  3958. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3959. // PatientId: item.PatientId,
  3960. // SystemTime: info.SysRecordTime,
  3961. // ConsumableType: 7,
  3962. // IsSys: 0,
  3963. // WarehousingOrder: "",
  3964. // WarehouseOutId: info.WarehouseOutId,
  3965. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3966. // IsEdit: 0,
  3967. // CancelStockId: cancel.ID,
  3968. // CancelOrderNumber: cancel.OrderNumber,
  3969. // Manufacturer: manufacturer.ID,
  3970. // Dealer: 0,
  3971. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3972. // UpdateCreator: 0,
  3973. // Status: 1,
  3974. // Ctime: time.Now().Unix(),
  3975. // Mtime: 0,
  3976. // Price: info.Price,
  3977. // WarehousingDetailId: info.WarehouseInfotId,
  3978. // WarehouseOutDetailId: info.ID,
  3979. // CancelOutDetailId: cancelInfo.ID,
  3980. // ProductDate: info.ProductDate,
  3981. // ExpireDate: info.ExpiryDate,
  3982. // StorehouseId: houseConfig.StorehouseOutInfo,
  3983. // OverCount: flush_count,
  3984. //}
  3985. //service.CreateStockFlowOne(flow)
  3986. //退库数量增加
  3987. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3988. //出库数量减少
  3989. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3990. //查询已出库数量
  3991. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3992. if prescribingNumber < dialysisInfo.Count {
  3993. //改变数量
  3994. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3995. }
  3996. if prescribingNumber >= dialysisInfo.Count {
  3997. //删除出库表
  3998. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3999. }
  4000. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4001. var flush_count_one int64
  4002. for _, it := range goodList {
  4003. flush_count_one += it.StockCount
  4004. }
  4005. //更新库存
  4006. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4007. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4008. //更新基础库库存
  4009. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4010. }
  4011. }
  4012. }
  4013. }
  4014. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4015. fmt.Println(err)
  4016. }
  4017. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4018. fmt.Println(err)
  4019. if len(advices) > 0 {
  4020. for _, item := range advices {
  4021. redis := service.RedisClient()
  4022. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4023. redis.Set(keyFive, "", time.Second)
  4024. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4025. redis.Set(keyOne, "", time.Second)
  4026. redis.Close()
  4027. }
  4028. }
  4029. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4030. if len(advices) > 0 {
  4031. for _, item := range advices {
  4032. creater := c.GetAdminUserInfo().AdminUser.Id
  4033. service.DrugAutoAddCancelInfo(item, creater)
  4034. }
  4035. }
  4036. } else {
  4037. if drugOutConfig.IsOpen == 1 {
  4038. if len(advices) > 0 {
  4039. for _, item := range advices {
  4040. creater := c.GetAdminUserInfo().AdminUser.Id
  4041. service.DrugAutoAddCancelInfo(item, creater)
  4042. }
  4043. }
  4044. } else {
  4045. if len(advices) > 0 {
  4046. for _, item := range advices {
  4047. creater := c.GetAdminUserInfo().AdminUser.Id
  4048. service.DrugAutoAddCancelInfo(item, creater)
  4049. }
  4050. }
  4051. }
  4052. }
  4053. c.ServeSuccessJSON(map[string]interface{}{
  4054. "msg": "删除成功",
  4055. })
  4056. return
  4057. }
  4058. func (c *HisApiController) DeleteDoctorAdvice() {
  4059. id, _ := c.GetInt64("id")
  4060. advice, _ := service.GetHisDoctorAdvicesById(id)
  4061. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4062. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4063. //已收费和已发药的限制逻辑
  4064. isCharge := false
  4065. isMedicine := false
  4066. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4067. //获取今天该患者所有处方,判断是否发药或者收费
  4068. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4069. for _, item := range new_prescriptions {
  4070. if item.IsMedicine == 1 {
  4071. isMedicine = true
  4072. }
  4073. }
  4074. for _, item := range new_prescriptions {
  4075. if item.OrderStatus == 4 {
  4076. isCharge = true
  4077. }
  4078. }
  4079. if isMedicine {
  4080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4081. return
  4082. }
  4083. if isCharge {
  4084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4085. return
  4086. }
  4087. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4088. for _, item := range advices {
  4089. if item.IsMedicine == 1 {
  4090. isMedicine = true
  4091. }
  4092. }
  4093. if isMedicine {
  4094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4095. return
  4096. }
  4097. if new_prescription.ID > 0 {
  4098. if new_prescription.OrderStatus == 2 {
  4099. isCharge = true
  4100. }
  4101. }
  4102. if isCharge {
  4103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4104. return
  4105. }
  4106. //已收费和已发药的限制逻辑
  4107. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4108. redis := service.RedisClient()
  4109. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4110. redis.Set(keyFive, "", time.Second)
  4111. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4112. redis.Set(keyOne, "", time.Second)
  4113. defer redis.Close()
  4114. if err == nil {
  4115. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4116. //查询是否在处方中出库
  4117. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4118. if openConfig.IsOpen != 1 {
  4119. //判断该医嘱是否执行了
  4120. if advice.ExecutionState == 1 {
  4121. creater := c.GetAdminUserInfo().AdminUser.Id
  4122. service.DrugAutoAddCancelInfo(&advice, creater)
  4123. }
  4124. }
  4125. //开启保存处方扣减功能
  4126. if openConfig.IsOpen == 1 {
  4127. creater := c.GetAdminUserInfo().AdminUser.Id
  4128. service.DrugAutoAddCancelInfo(&advice, creater)
  4129. }
  4130. } else {
  4131. if drugOutConfig.IsOpen == 1 {
  4132. //查询是否在处方中出库
  4133. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4134. if openConfig.IsOpen != 1 {
  4135. //判断该医嘱是否执行了
  4136. if advice.ExecutionState == 1 {
  4137. creater := c.GetAdminUserInfo().AdminUser.Id
  4138. service.DrugAutoAddCancelInfo(&advice, creater)
  4139. }
  4140. }
  4141. //开启保存处方扣减功能
  4142. if openConfig.IsOpen == 1 {
  4143. creater := c.GetAdminUserInfo().AdminUser.Id
  4144. service.DrugAutoAddCancelInfo(&advice, creater)
  4145. }
  4146. } else {
  4147. //判断该医嘱是否执行了
  4148. if advice.ExecutionState == 1 {
  4149. creater := c.GetAdminUserInfo().AdminUser.Id
  4150. service.DrugAutoAddCancelInfo(&advice, creater)
  4151. }
  4152. }
  4153. }
  4154. c.ServeSuccessJSON(map[string]interface{}{
  4155. "msg": "删除成功",
  4156. })
  4157. return
  4158. } else {
  4159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4160. return
  4161. }
  4162. }
  4163. func (c *HisApiController) DeleteProject() {
  4164. id, _ := c.GetInt64("id")
  4165. adminInfo := c.GetAdminUserInfo()
  4166. project, _ := service.GetHisProjectByID(id)
  4167. // var consumable models.DialysisBeforePrepare
  4168. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4169. //耗材保存处方出库
  4170. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4171. isCharge := false
  4172. isMedicine := false
  4173. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4174. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4175. for _, item := range new_prescriptions {
  4176. if item.IsMedicine == 1 {
  4177. isMedicine = true
  4178. }
  4179. }
  4180. for _, item := range new_prescriptions {
  4181. if item.OrderStatus == 4 {
  4182. isCharge = true
  4183. }
  4184. }
  4185. if isMedicine {
  4186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4187. return
  4188. }
  4189. if isCharge {
  4190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4191. return
  4192. }
  4193. if new_prescription.ID > 0 {
  4194. if new_prescription.OrderStatus == 2 {
  4195. isCharge = true
  4196. }
  4197. }
  4198. if isCharge {
  4199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4200. return
  4201. }
  4202. service.DeletePrintInfo(id)
  4203. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4204. label.Status = 0
  4205. service.CreateHisLabelRecord(&label)
  4206. fmt.Println(goodOutConfig.IsOpen)
  4207. if goodOutConfig.IsOpen != 1 {
  4208. if stockConfig.IsOpen == 1 {
  4209. if project.Type == 2 {
  4210. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4211. fmt.Println(err)
  4212. }
  4213. if project.Type == 3 && project.IsOut == 1 {
  4214. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4215. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4216. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4217. operation_time := time.Now().Unix()
  4218. creater := adminInfo.AdminUser.Id
  4219. //创建退库单
  4220. timeStr := time.Now().Format("2006-01-02")
  4221. timeArr := strings.Split(timeStr, "-")
  4222. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4223. total = total + 1
  4224. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4225. cancelStock := models.CancelStock{
  4226. OrderNumber: orderNumber,
  4227. OperaTime: operation_time,
  4228. OrgId: adminInfo.CurrentOrgId,
  4229. Creater: creater,
  4230. Ctime: time.Now().Unix(),
  4231. Status: 1,
  4232. ReturnTime: project.RecordDate,
  4233. Type: 1,
  4234. StorehouseId: houseConfig.StorehouseOutInfo,
  4235. IsCheck: 1,
  4236. }
  4237. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4238. if msgerrkonde == gorm.ErrRecordNotFound {
  4239. service.AddSigleCancelStock(&cancelStock)
  4240. }
  4241. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4242. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4243. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4244. //查询是否有出库
  4245. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4246. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4247. deaerler, _ := service.GetDealerById(info.Dealer)
  4248. if info.ID > 0 {
  4249. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4250. if info.Count >= prescribingNumber {
  4251. cancelStockInfo := models.CancelStockInfo{
  4252. GoodId: project.ProjectId,
  4253. CancelStockId: cancel.ID,
  4254. GoodTypeId: good.GoodTypeId,
  4255. Count: prescribingNumber,
  4256. Price: info.Price,
  4257. Total: 0,
  4258. ProductDate: info.ProductDate,
  4259. ExpiryDate: info.ExpiryDate,
  4260. Ctime: time.Now().Unix(),
  4261. Status: 1,
  4262. OrgId: adminInfo.CurrentOrgId,
  4263. OrderNumber: cancel.OrderNumber,
  4264. Type: 0,
  4265. Dealer: deaerler.DealerName,
  4266. Manufacturer: manufacturer.ManufacturerName,
  4267. Number: info.Number,
  4268. RegisterAccount: "",
  4269. Remark: "",
  4270. WarehouseInfoId: info.WarehouseInfotId,
  4271. PatientId: info.PatientId,
  4272. RecordDate: info.SysRecordTime,
  4273. StorehouseId: houseConfig.StorehouseOutInfo,
  4274. IsCheck: 1,
  4275. }
  4276. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4277. //回退库存
  4278. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4279. //退库数量增加
  4280. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4281. //出库数量减少
  4282. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4283. }
  4284. if info.Count < prescribingNumber {
  4285. cancelStockInfo := models.CancelStockInfo{
  4286. GoodId: project.ProjectId,
  4287. CancelStockId: cancel.ID,
  4288. GoodTypeId: good.GoodTypeId,
  4289. Count: info.Count,
  4290. Price: info.Price,
  4291. Total: 0,
  4292. ProductDate: info.ProductDate,
  4293. ExpiryDate: info.ExpiryDate,
  4294. Ctime: time.Now().Unix(),
  4295. Status: 1,
  4296. OrgId: adminInfo.CurrentOrgId,
  4297. OrderNumber: cancel.OrderNumber,
  4298. Type: 0,
  4299. Dealer: deaerler.DealerName,
  4300. Manufacturer: manufacturer.ManufacturerName,
  4301. Number: info.Number,
  4302. RegisterAccount: "",
  4303. Remark: "",
  4304. WarehouseInfoId: info.WarehouseInfotId,
  4305. PatientId: info.PatientId,
  4306. RecordDate: info.SysRecordTime,
  4307. StorehouseId: houseConfig.StorehouseOutInfo,
  4308. IsCheck: 1,
  4309. }
  4310. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4311. //回退库存
  4312. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4313. //退库数量增加
  4314. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4315. //出库数量减少
  4316. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4317. }
  4318. //查询剩余库存
  4319. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4320. var over_count int64
  4321. for _, it := range goodList {
  4322. over_count += it.StockCount
  4323. }
  4324. //出库数据 大于 退库数量
  4325. if info.Count >= prescribingNumber {
  4326. flow := models.VmStockFlow{
  4327. WarehousingId: info.WarehouseInfotId,
  4328. GoodId: project.ProjectId,
  4329. Number: info.Number,
  4330. LicenseNumber: info.LicenseNumber,
  4331. Count: prescribingNumber,
  4332. UserOrgId: adminInfo.CurrentOrgId,
  4333. PatientId: project.PatientId,
  4334. SystemTime: info.SysRecordTime,
  4335. ConsumableType: 7,
  4336. IsSys: 0,
  4337. WarehousingOrder: "",
  4338. WarehouseOutId: info.WarehouseOutId,
  4339. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4340. IsEdit: 0,
  4341. CancelStockId: cancel.ID,
  4342. CancelOrderNumber: cancel.OrderNumber,
  4343. Manufacturer: manufacturer.ID,
  4344. Dealer: 0,
  4345. Creator: adminInfo.AdminUser.Id,
  4346. UpdateCreator: 0,
  4347. Status: 1,
  4348. Ctime: time.Now().Unix(),
  4349. Mtime: 0,
  4350. Price: info.Price,
  4351. WarehousingDetailId: info.WarehouseInfotId,
  4352. WarehouseOutDetailId: info.ID,
  4353. CancelOutDetailId: cancelInfo.ID,
  4354. ProductDate: info.ProductDate,
  4355. ExpireDate: info.ExpiryDate,
  4356. StorehouseId: houseConfig.StorehouseOutInfo,
  4357. OverCount: over_count,
  4358. }
  4359. service.CreateStockFlowOne(flow)
  4360. }
  4361. //出库数据小于退库数据
  4362. if info.Count < prescribingNumber {
  4363. flow := models.VmStockFlow{
  4364. WarehousingId: info.WarehouseInfotId,
  4365. GoodId: project.ProjectId,
  4366. Number: info.Number,
  4367. LicenseNumber: info.LicenseNumber,
  4368. Count: info.Count,
  4369. UserOrgId: adminInfo.CurrentOrgId,
  4370. PatientId: project.PatientId,
  4371. SystemTime: info.SysRecordTime,
  4372. ConsumableType: 7,
  4373. IsSys: 0,
  4374. WarehousingOrder: "",
  4375. WarehouseOutId: info.WarehouseOutId,
  4376. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4377. IsEdit: 0,
  4378. CancelStockId: cancel.ID,
  4379. CancelOrderNumber: cancel.OrderNumber,
  4380. Manufacturer: manufacturer.ID,
  4381. Dealer: 0,
  4382. Creator: adminInfo.AdminUser.Id,
  4383. UpdateCreator: 0,
  4384. Status: 1,
  4385. Ctime: time.Now().Unix(),
  4386. Mtime: 0,
  4387. Price: info.Price,
  4388. WarehousingDetailId: info.WarehouseInfotId,
  4389. WarehouseOutDetailId: info.ID,
  4390. CancelOutDetailId: cancelInfo.ID,
  4391. ProductDate: info.ProductDate,
  4392. ExpireDate: info.ExpiryDate,
  4393. StorehouseId: houseConfig.StorehouseOutInfo,
  4394. OverCount: over_count,
  4395. }
  4396. service.CreateStockFlowOne(flow)
  4397. }
  4398. //查询已出库数量
  4399. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4400. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4401. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4402. if prescribingNumber < dialysisInfo.Count {
  4403. //改变数量
  4404. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4405. }
  4406. if prescribingNumber >= dialysisInfo.Count {
  4407. //删除出库表
  4408. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4409. }
  4410. //更新剩余库存
  4411. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4412. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4413. var total_count_one int64
  4414. for _, it := range stockList {
  4415. total_count_one += it.StockCount
  4416. }
  4417. //基础库插入数据
  4418. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4419. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4420. var flush_count int64
  4421. for _, it := range goodListOne {
  4422. flush_count += it.StockCount
  4423. }
  4424. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4425. if errs != nil {
  4426. goodErrcode := models.XtGoodErrcode{
  4427. UserOrgId: project.UserOrgId,
  4428. Errcode: "手动出库更新剩余出库失败",
  4429. GoodId: project.ProjectId,
  4430. Status: 1,
  4431. Ctime: time.Now().Unix(),
  4432. Mtime: 0,
  4433. Count: 0,
  4434. StockCount: 0,
  4435. Creater: creater,
  4436. BatchNumberId: 0,
  4437. WarehouseOutId: 0,
  4438. }
  4439. service.CreateGoodErrcode(goodErrcode)
  4440. }
  4441. }
  4442. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4443. fmt.Println(err)
  4444. } else {
  4445. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4446. fmt.Println(err)
  4447. }
  4448. } else {
  4449. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4450. fmt.Println(err)
  4451. }
  4452. }
  4453. //保存处方出库
  4454. if goodOutConfig.IsOpen == 1 {
  4455. if project.Type == 3 {
  4456. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4457. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4458. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4459. operation_time := time.Now().Unix()
  4460. creater := adminInfo.AdminUser.Id
  4461. //创建退库单
  4462. timeStr := time.Now().Format("2006-01-02")
  4463. timeArr := strings.Split(timeStr, "-")
  4464. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4465. total = total + 1
  4466. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4467. cancelStock := models.CancelStock{
  4468. OrderNumber: orderNumber,
  4469. OperaTime: operation_time,
  4470. OrgId: adminInfo.CurrentOrgId,
  4471. Creater: creater,
  4472. Ctime: time.Now().Unix(),
  4473. Status: 1,
  4474. ReturnTime: project.RecordDate,
  4475. Type: 1,
  4476. StorehouseId: houseConfig.StorehouseOutInfo,
  4477. IsCheck: 1,
  4478. }
  4479. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4480. if msgerrkonde == gorm.ErrRecordNotFound {
  4481. service.AddSigleCancelStock(&cancelStock)
  4482. }
  4483. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4484. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4485. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4486. //获取出库数据
  4487. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4488. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4489. deaerler, _ := service.GetDealerById(info.Dealer)
  4490. if info.ID > 0 {
  4491. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4492. if info.Count >= prescribingNumber {
  4493. cancelStockInfo := models.CancelStockInfo{
  4494. GoodId: project.ProjectId,
  4495. CancelStockId: cancel.ID,
  4496. GoodTypeId: good.GoodTypeId,
  4497. Count: prescribingNumber,
  4498. Price: info.Price,
  4499. Total: 0,
  4500. ProductDate: info.ProductDate,
  4501. ExpiryDate: info.ExpiryDate,
  4502. Ctime: time.Now().Unix(),
  4503. Status: 1,
  4504. OrgId: adminInfo.CurrentOrgId,
  4505. OrderNumber: cancel.OrderNumber,
  4506. Type: 0,
  4507. Dealer: deaerler.DealerName,
  4508. Manufacturer: manufacturer.ManufacturerName,
  4509. Number: info.Number,
  4510. RegisterAccount: "",
  4511. Remark: "",
  4512. WarehouseInfoId: info.WarehouseInfotId,
  4513. PatientId: info.PatientId,
  4514. RecordDate: info.SysRecordTime,
  4515. StorehouseId: houseConfig.StorehouseOutInfo,
  4516. IsCheck: 1,
  4517. }
  4518. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4519. //退库数量增加
  4520. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4521. //出库数量减少
  4522. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4523. }
  4524. if info.Count < prescribingNumber {
  4525. cancelStockInfo := models.CancelStockInfo{
  4526. GoodId: project.ProjectId,
  4527. CancelStockId: cancel.ID,
  4528. GoodTypeId: good.GoodTypeId,
  4529. Count: prescribingNumber,
  4530. Price: info.Price,
  4531. Total: 0,
  4532. ProductDate: info.ProductDate,
  4533. ExpiryDate: info.ExpiryDate,
  4534. Ctime: time.Now().Unix(),
  4535. Status: 1,
  4536. OrgId: adminInfo.CurrentOrgId,
  4537. OrderNumber: cancel.OrderNumber,
  4538. Type: 0,
  4539. Dealer: deaerler.DealerName,
  4540. Manufacturer: manufacturer.ManufacturerName,
  4541. Number: info.Number,
  4542. RegisterAccount: "",
  4543. Remark: "",
  4544. WarehouseInfoId: info.WarehouseInfotId,
  4545. PatientId: info.PatientId,
  4546. RecordDate: info.SysRecordTime,
  4547. StorehouseId: houseConfig.StorehouseOutInfo,
  4548. IsCheck: 1,
  4549. }
  4550. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4551. //回退库存
  4552. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4553. }
  4554. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4555. var over_count int64
  4556. for _, it := range goodList {
  4557. over_count += it.StockCount
  4558. }
  4559. //查询出库数量
  4560. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4561. //出库数据 大于 退库数量
  4562. if len(list) > 0 {
  4563. for _, it := range list {
  4564. //回退库存
  4565. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4566. //退库数量增加
  4567. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4568. //出库数量减少
  4569. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4570. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4571. var over_count_one int64
  4572. for _, it := range goodList {
  4573. over_count_one += it.StockCount
  4574. }
  4575. //查询该批次是否有退库数据
  4576. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4577. flow := models.VmStockFlow{
  4578. WarehousingId: it.WarehouseInfotId,
  4579. GoodId: it.GoodId,
  4580. Number: it.Number,
  4581. LicenseNumber: it.LicenseNumber,
  4582. Count: it.Count,
  4583. UserOrgId: adminInfo.CurrentOrgId,
  4584. PatientId: it.PatientId,
  4585. SystemTime: it.SysRecordTime,
  4586. ConsumableType: 7,
  4587. IsSys: 0,
  4588. WarehousingOrder: "",
  4589. WarehouseOutId: it.WarehouseOutId,
  4590. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4591. IsEdit: 0,
  4592. CancelStockId: cancel.ID,
  4593. CancelOrderNumber: cancel.OrderNumber,
  4594. Manufacturer: manufacturer.ID,
  4595. Dealer: 0,
  4596. Creator: adminInfo.AdminUser.Id,
  4597. UpdateCreator: 0,
  4598. Status: 1,
  4599. Ctime: time.Now().Unix(),
  4600. Mtime: 0,
  4601. Price: it.Price,
  4602. WarehousingDetailId: it.WarehouseInfotId,
  4603. WarehouseOutDetailId: it.ID,
  4604. CancelOutDetailId: cancelInfo.ID,
  4605. ProductDate: it.ProductDate,
  4606. ExpireDate: it.ExpiryDate,
  4607. StorehouseId: houseConfig.StorehouseOutInfo,
  4608. OverCount: over_count_one,
  4609. }
  4610. service.CreateStockFlowOne(flow)
  4611. }
  4612. }
  4613. //查询已出库数量
  4614. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4615. if prescribingNumber < dialysisInfo.Count {
  4616. //改变数量
  4617. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4618. }
  4619. if prescribingNumber >= dialysisInfo.Count {
  4620. //删除出库表
  4621. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4622. }
  4623. //更新剩余库存
  4624. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4625. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4626. var total_count_one int64
  4627. for _, it := range stockList {
  4628. total_count_one += it.StockCount
  4629. }
  4630. //基础库插入数据
  4631. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4632. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4633. var flush_count int64
  4634. for _, it := range goodListOne {
  4635. flush_count += it.StockCount
  4636. }
  4637. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4638. if errs != nil {
  4639. goodErrcode := models.XtGoodErrcode{
  4640. UserOrgId: project.UserOrgId,
  4641. Errcode: "手动出库更新剩余出库失败",
  4642. GoodId: project.ProjectId,
  4643. Status: 1,
  4644. Ctime: time.Now().Unix(),
  4645. Mtime: 0,
  4646. Count: 0,
  4647. StockCount: 0,
  4648. Creater: creater,
  4649. BatchNumberId: 0,
  4650. WarehouseOutId: 0,
  4651. }
  4652. service.CreateGoodErrcode(goodErrcode)
  4653. }
  4654. }
  4655. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4656. fmt.Println(err)
  4657. } else {
  4658. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4659. fmt.Println(err)
  4660. }
  4661. }
  4662. c.ServeSuccessJSON(map[string]interface{}{
  4663. "msg": "删除成功",
  4664. })
  4665. return
  4666. }
  4667. func (c *HisApiController) CreateHisAdditionalCharge() {
  4668. his_patient_id, _ := c.GetInt64("his_patient_id")
  4669. patient_id, _ := c.GetInt64("patient_id")
  4670. record_date := c.GetString("record_date")
  4671. timeLayout := "2006-01-02"
  4672. loc, _ := time.LoadLocation("Local")
  4673. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4674. if err != nil {
  4675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4676. return
  4677. }
  4678. adminInfo := c.GetAdminUserInfo()
  4679. recordDateTime := theTime.Unix()
  4680. dataBody := make(map[string]interface{}, 0)
  4681. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4682. if err != nil {
  4683. utils.ErrorLog(err.Error())
  4684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4685. return
  4686. }
  4687. var additions []*models.HisAdditionalCharge
  4688. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4689. additions, _ := dataBody["addition"].([]interface{})
  4690. if len(additions) > 0 {
  4691. for _, item := range additions {
  4692. items := item.(map[string]interface{})
  4693. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4694. utils.ErrorLog("item_id")
  4695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4696. return
  4697. }
  4698. item_id := int64(items["item_id"].(float64))
  4699. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4700. utils.ErrorLog("item_name")
  4701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4702. return
  4703. }
  4704. item_name := items["item_name"].(string)
  4705. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4706. utils.ErrorLog("price")
  4707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4708. return
  4709. }
  4710. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4711. ctime := time.Now().Unix()
  4712. additional := &models.HisAdditionalCharge{
  4713. PatientId: patient_id,
  4714. HisPatientId: his_patient_id,
  4715. UserOrgId: adminInfo.CurrentOrgId,
  4716. RecordDate: recordDateTime,
  4717. CreatedTime: ctime,
  4718. UpdatedTime: ctime,
  4719. Modifier: adminInfo.AdminUser.Id,
  4720. Creator: adminInfo.AdminUser.Id,
  4721. Price: price,
  4722. ItemName: item_name,
  4723. ItemId: item_id,
  4724. Status: 1,
  4725. }
  4726. additions = append(additions, additional)
  4727. }
  4728. }
  4729. }
  4730. for _, item := range additions {
  4731. service.CreateAddtionalCharge(item)
  4732. }
  4733. c.ServeSuccessJSON(map[string]interface{}{
  4734. "msg": "创建成功",
  4735. })
  4736. }
  4737. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4738. blood_fat := c.GetString("blood_fat")
  4739. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4740. blood_sugar := c.GetString("blood_sugar")
  4741. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4742. chief_conplaint := c.GetString("chief_conplaint")
  4743. dbp := c.GetString("dbp")
  4744. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4745. delivery_way, _ := c.GetInt64("delivery_way")
  4746. diagnostic := c.GetString("diagnostic")
  4747. family_history := c.GetString("family_history")
  4748. height := c.GetString("height")
  4749. history_of_present_illness := c.GetString("history_of_present_illness")
  4750. is_infect, _ := c.GetInt64("is_infect")
  4751. past_history := c.GetString("past_history")
  4752. patient_id, _ := c.GetInt64("patient_id")
  4753. his_patient_id, _ := c.GetInt64("his_patient_id")
  4754. personal_history := c.GetString("personal_history")
  4755. pulse := c.GetString("pulse")
  4756. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4757. sbp := c.GetString("sbp")
  4758. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4759. heightfloat, _ := strconv.ParseFloat(height, 64)
  4760. sicktype := c.GetString("sick_type")
  4761. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4762. symptom := c.GetString("symptom")
  4763. sick_date := c.GetString("sick_date")
  4764. temperatures := c.GetString("temperature")
  4765. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4766. record_date := c.GetString("record_date")
  4767. breathing := c.GetString("breathing")
  4768. doctor_advice := c.GetString("doctor_advice")
  4769. remark := c.GetString("remark")
  4770. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4771. sick, _ := c.GetInt64("sick")
  4772. diagnose, _ := c.GetInt64("diagnose")
  4773. //id, _ := c.GetInt64("id")
  4774. timeLayout := "2006-01-02"
  4775. loc, _ := time.LoadLocation("Local")
  4776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4777. allergic_history := c.GetString("allergic_history")
  4778. if err != nil {
  4779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4780. return
  4781. }
  4782. recordDateTime := theTime.Unix()
  4783. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4784. if err != nil {
  4785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4786. return
  4787. }
  4788. sickTimes := sickTime.Unix()
  4789. ctime := time.Now().Unix()
  4790. primary_disease := c.GetString("primary_disease")
  4791. confirm_failure_date := c.GetString("confirm_failure_date")
  4792. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4793. drug_allergy_history := c.GetString("drug_allergy_history")
  4794. physical_examination := c.GetString("physical_examination")
  4795. special_inspection := c.GetString("special_inspection")
  4796. lab_apparatus := c.GetString("lab_apparatus")
  4797. caseHistory := models.HisPatientCaseHistory{
  4798. HisPatientId: his_patient_id,
  4799. PatientId: patient_id,
  4800. Temperature: temperature,
  4801. BloodSugar: bloodsugarfloat,
  4802. Pulse: pulsefloat,
  4803. Sbp: sbpfloat,
  4804. Dbp: dbpfloat,
  4805. Height: heightfloat,
  4806. BloodFat: bloodfatfloat,
  4807. SickType: sick_type,
  4808. Symptom: symptom,
  4809. SickDate: sickTimes,
  4810. IsInfect: is_infect,
  4811. HistoryOfPresentIllness: history_of_present_illness,
  4812. PastHistory: past_history,
  4813. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4814. ChiefConplaint: chief_conplaint,
  4815. PersonalHistory: personal_history,
  4816. FamilyHistory: family_history,
  4817. Diagnostic: diagnostic,
  4818. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4819. Status: 1,
  4820. Ctime: ctime,
  4821. Mtime: ctime,
  4822. RecordDate: recordDateTime,
  4823. DeliveryWay: delivery_way,
  4824. Breathing: breathingfloat,
  4825. DoctorAdvice: doctor_advice,
  4826. Remark: remark,
  4827. Sick: sick,
  4828. Diagnose: diagnose,
  4829. AllergicHistory: allergic_history,
  4830. PrimaryDisease: primary_disease,
  4831. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4832. DrugAllergyHistory: drug_allergy_history,
  4833. PhysicalExamination: physical_examination,
  4834. SpecialInspection: special_inspection,
  4835. LabApparatus: lab_apparatus,
  4836. }
  4837. //查询该患者是否有病历
  4838. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4839. if errcodes == gorm.ErrRecordNotFound {
  4840. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4841. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4842. if err != nil {
  4843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4844. return
  4845. }
  4846. c.ServeSuccessJSON(map[string]interface{}{
  4847. "caseHistory": caseHistory,
  4848. "historyInfo": historyInfo,
  4849. })
  4850. return
  4851. } else if errcodes == nil {
  4852. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4853. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4854. if err != nil {
  4855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4856. return
  4857. }
  4858. c.ServeSuccessJSON(map[string]interface{}{
  4859. "caseHistory": caseHistory,
  4860. "historyInfo": historyInfo,
  4861. })
  4862. }
  4863. //查询该患者是否有病历
  4864. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4865. //if errcode == gorm.ErrRecordNotFound {
  4866. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4867. // if err != nil {
  4868. // c.ServeSuccessJSON(map[string]interface{}{
  4869. // "msg": "保存成功",
  4870. // })
  4871. // }
  4872. //} else if errcode == nil {
  4873. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4874. // return
  4875. //}
  4876. }
  4877. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4878. patient_id, _ := c.GetInt64("patient_id", 0)
  4879. adminUser := c.GetAdminUserInfo()
  4880. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4881. c.ServeSuccessJSON(map[string]interface{}{
  4882. "list": caseHistorys,
  4883. })
  4884. }
  4885. func (c *HisApiController) GetHisPatientCaseHistory() {
  4886. record_date, _ := c.GetInt64("record_date", 0)
  4887. patient_id, _ := c.GetInt64("patient_id", 0)
  4888. admin := c.GetAdminUserInfo()
  4889. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4890. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4891. c.ServeSuccessJSON(map[string]interface{}{
  4892. "info": info,
  4893. "case_history": case_history,
  4894. })
  4895. }
  4896. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4897. template_name := c.GetString("template_name")
  4898. template_remark := c.GetString("template_remark")
  4899. doctor := c.GetAdminUserInfo().AdminUser.Id
  4900. diagnostic := c.GetString("diagnostic")
  4901. chief_conplaint := c.GetString("chief_conplain")
  4902. history_of_present_illness := c.GetString("history_of_present_illness")
  4903. past_history := c.GetString("past_history")
  4904. personal_history := c.GetString("personal_history")
  4905. family_history := c.GetString("family_history")
  4906. user_name := c.GetString("user_name")
  4907. doctor_advice := c.GetString("doctor_advice")
  4908. remark := c.GetString("remark")
  4909. //record_date := c.GetString("record_date")
  4910. //fmt.Println("record_date--------",record_date)
  4911. //timeLayout := "2006-01-02"
  4912. //loc, _ := time.LoadLocation("Local")
  4913. //
  4914. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4915. //if err != nil {
  4916. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4917. // return
  4918. //}
  4919. //recordDateTime := theTime.Unix()
  4920. ctime := time.Now().Unix()
  4921. template := models.HisCaseHistoryTemplate{
  4922. HistoryOfPresentIllness: history_of_present_illness,
  4923. PastHistory: past_history,
  4924. ChiefConplaint: chief_conplaint,
  4925. PersonalHistory: personal_history,
  4926. FamilyHistory: family_history,
  4927. Diagnostic: diagnostic,
  4928. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4929. Status: 1,
  4930. Ctime: ctime,
  4931. Mtime: ctime,
  4932. RecordDate: time.Now().Unix(),
  4933. TemplateName: template_name,
  4934. TemplateRemark: template_remark,
  4935. Creator: doctor,
  4936. Modifier: doctor,
  4937. UserName: user_name,
  4938. DoctorAdvice: doctor_advice,
  4939. Remark: remark,
  4940. }
  4941. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4942. if err == nil {
  4943. c.ServeSuccessJSON(map[string]interface{}{
  4944. "msg": "保存成功",
  4945. })
  4946. } else {
  4947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4948. return
  4949. }
  4950. }
  4951. func (c *HisApiController) GetCaseHistoryTemplate() {
  4952. timeLayout := "2006-01-02"
  4953. loc, _ := time.LoadLocation("Local")
  4954. keyword := c.GetString("keyword")
  4955. start_time := c.GetString("start_time")
  4956. end_time := c.GetString("end_time")
  4957. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4958. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4959. admin := c.GetAdminUserInfo()
  4960. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4961. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4962. c.ServeSuccessJSON(map[string]interface{}{
  4963. "template": template,
  4964. //"history": history,
  4965. })
  4966. }
  4967. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4968. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4969. utils.ErrorLog("drug_name")
  4970. return enums.ErrorCodeParamWrong
  4971. }
  4972. adviceName, _ := json["drug_name"].(string)
  4973. if len(adviceName) == 0 {
  4974. utils.ErrorLog("len(advice_name) == 0")
  4975. return enums.ErrorCodeParamWrong
  4976. }
  4977. advice.AdviceName = adviceName
  4978. adviceDesc, _ := json["advice_desc"].(string)
  4979. advice.AdviceDesc = adviceDesc
  4980. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4981. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4982. advice.DrugSpec = drugSpec
  4983. }
  4984. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4985. remark, _ := json["remark"].(string)
  4986. advice.Remark = remark
  4987. }
  4988. if json["id"] == nil {
  4989. advice.DrugId = 0
  4990. } else {
  4991. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4992. drug_id := int64(json["id"].(float64))
  4993. advice.DrugId = drug_id
  4994. }
  4995. }
  4996. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4997. advice_id := int64(json["advice_id"].(float64))
  4998. advice.ID = advice_id
  4999. if advice.ID > 0 {
  5000. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5001. if err == nil {
  5002. if hisAdvice.ID > 0 {
  5003. advice.ExecutionTime = hisAdvice.ExecutionTime
  5004. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5005. advice.ExecutionState = hisAdvice.ExecutionState
  5006. advice.CheckTime = hisAdvice.CheckTime
  5007. advice.Checker = hisAdvice.Checker
  5008. advice.CheckState = hisAdvice.CheckState
  5009. advice.StartTime = hisAdvice.StartTime
  5010. advice.FeedetlSn = hisAdvice.FeedetlSn
  5011. }
  5012. }
  5013. }
  5014. }
  5015. //
  5016. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5017. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5018. // advice.ExecutionTime = execution_time
  5019. //}
  5020. //
  5021. //
  5022. //
  5023. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5024. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5025. // advice.ExecutionStaff = execution_staff
  5026. //}
  5027. //
  5028. //
  5029. //
  5030. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5031. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5032. // advice.ExecutionState = execution_state
  5033. //}
  5034. //
  5035. //
  5036. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5037. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5038. // advice.CheckTime = check_time
  5039. //}
  5040. //
  5041. //
  5042. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5043. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5044. // advice.CheckState = check_state
  5045. //}
  5046. //
  5047. //
  5048. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5049. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5050. // advice.Checker = checker
  5051. //}
  5052. //
  5053. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5054. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5055. // advice.StartTime = start_time
  5056. //}
  5057. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5058. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5059. advice.IsSelfDrug = is_self_drug
  5060. }
  5061. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5062. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5063. drug_way_count, _ := json["drug_way_count"].(string)
  5064. advice.DrugWayCount = drug_way_count
  5065. }
  5066. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5067. drugSpecUnit, _ := json["min_unit"].(string)
  5068. advice.DrugSpecUnit = drugSpecUnit
  5069. }
  5070. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5071. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5072. advice.SingleDose = singleDose
  5073. }
  5074. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5075. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5076. advice.SingleDoseUnit = singleDoseUnit
  5077. }
  5078. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5079. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5080. advice.PrescribingNumber = prescribingNumber
  5081. }
  5082. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5083. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5084. advice.PrescribingNumberUnit = prescribingNumberUnit
  5085. }
  5086. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5087. deliveryWay, _ := json["delivery_way"].(string)
  5088. advice.DeliveryWay = deliveryWay
  5089. }
  5090. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5091. executionFrequency, _ := json["execution_frequency"].(string)
  5092. advice.ExecutionFrequency = executionFrequency
  5093. }
  5094. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5095. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5096. advice.Price = price
  5097. }
  5098. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5099. med_list_codg, _ := json["medical_insurance_number"].(string)
  5100. advice.MedListCodg = med_list_codg
  5101. }
  5102. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5103. day := int64(json["day"].(float64))
  5104. advice.Day = day
  5105. }
  5106. return 0
  5107. }
  5108. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5109. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5110. id := int64(json["id"].(float64))
  5111. project.ID = id
  5112. historyProject, _ := service.GetHisProjectByID(id)
  5113. project.FeedetlSn = historyProject.FeedetlSn
  5114. }
  5115. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5116. project_id := int64(json["project_id"].(float64))
  5117. project.ProjectId = project_id
  5118. }
  5119. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5120. // price := int64(json["price"].(float64))
  5121. // formatInt_price := strconv.FormatInt(price, 10)
  5122. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5123. // project.Price = float_price
  5124. // }
  5125. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5126. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5127. project.Price = price
  5128. }
  5129. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5130. total, _ := json["total"].(string)
  5131. project.Count = total
  5132. }
  5133. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5134. medical_code, _ := json["medical_code"].(string)
  5135. project.MedListCodg = medical_code
  5136. }
  5137. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5138. single_dose, _ := json["single_dose"].(string)
  5139. project.SingleDose = single_dose
  5140. }
  5141. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5142. delivery_way, _ := json["delivery_way"].(string)
  5143. project.DeliveryWay = delivery_way
  5144. }
  5145. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5146. execution_frequency, _ := json["execution_frequency"].(string)
  5147. project.ExecutionFrequency = execution_frequency
  5148. }
  5149. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5150. remark, _ := json["remark"].(string)
  5151. project.Remark = remark
  5152. }
  5153. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5154. day, _ := json["number_days"].(string)
  5155. project.Day = day
  5156. }
  5157. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5158. unit, _ := json["unit"].(string)
  5159. project.Unit = unit
  5160. }
  5161. return 0
  5162. }
  5163. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5164. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5165. id := int64(json["id"].(float64))
  5166. historyAddtions, _ := service.GetHisAdditionByID(id)
  5167. additionalCharge.ID = id
  5168. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5169. }
  5170. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5171. item_id := int64(json["item_id"].(float64))
  5172. additionalCharge.ItemId = item_id
  5173. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5174. if config.ID > 0 {
  5175. if len(config.Code) > 0 {
  5176. additionalCharge.MedListCodg = config.Code
  5177. }
  5178. }
  5179. }
  5180. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5181. // price := int64(json["price"].(float64))
  5182. // formatInt_price := strconv.FormatInt(price, 10)
  5183. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5184. // additionalCharge.Price = float_price
  5185. // }
  5186. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5187. // price := int64(json["price"].(float64))
  5188. // formatInt_price := strconv.FormatInt(price, 10)
  5189. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5190. // additionalCharge.Price = float_price
  5191. //}
  5192. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5193. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5194. additionalCharge.Price = price
  5195. }
  5196. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5197. count, _ := json["count"].(string)
  5198. counts, _ := strconv.ParseInt(count, 10, 64)
  5199. additionalCharge.Count = counts
  5200. }
  5201. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5202. item_name, _ := json["item_name"].(string)
  5203. additionalCharge.ItemName = item_name
  5204. }
  5205. return 0
  5206. }
  5207. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5208. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5209. utils.ErrorLog("drug_name")
  5210. return enums.ErrorCodeParamWrong
  5211. }
  5212. adviceName, _ := json["drug_name"].(string)
  5213. if len(adviceName) == 0 {
  5214. utils.ErrorLog("len(advice_name) == 0")
  5215. return enums.ErrorCodeParamWrong
  5216. }
  5217. advice.AdviceName = adviceName
  5218. adviceDesc, _ := json["advice_desc"].(string)
  5219. advice.AdviceDesc = adviceDesc
  5220. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5221. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5222. advice.DrugSpec = drugSpec
  5223. }
  5224. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5225. remark, _ := json["remark"].(string)
  5226. advice.Remark = remark
  5227. }
  5228. if json["id"] == nil {
  5229. advice.DrugId = 0
  5230. } else {
  5231. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5232. drug_id := int64(json["id"].(float64))
  5233. advice.DrugId = drug_id
  5234. }
  5235. }
  5236. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5237. groupno := int64(json["groupno"].(float64))
  5238. advice.Groupno = groupno
  5239. }
  5240. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5241. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5242. advice.IsSelfDrug = is_self_drug
  5243. }
  5244. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5245. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5246. drug_way_count, _ := json["drug_way_count"].(string)
  5247. advice.DrugWayCount = drug_way_count
  5248. }
  5249. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5250. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5251. advice.HospApprFlag = hosp_appr_flag
  5252. }
  5253. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5254. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5255. advice.PrescribingNumber = prescribingNumber
  5256. }
  5257. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5258. // frequency_type := int64(json["frequency_type"].(float64))
  5259. // advice.FrequencyType = frequency_type
  5260. //}
  5261. //
  5262. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5263. // day_count := int64(json["day_count"].(float64))
  5264. // advice.DayCount = day_count
  5265. //}
  5266. //
  5267. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5268. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5269. // week_day, _ := json["week_day"].(string)
  5270. // advice.WeekDay = week_day
  5271. //}
  5272. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5273. drugSpecUnit, _ := json["min_unit"].(string)
  5274. advice.DrugSpecUnit = drugSpecUnit
  5275. }
  5276. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5277. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5278. advice.SingleDose = singleDose
  5279. }
  5280. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5281. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5282. advice.SingleDoseUnit = singleDoseUnit
  5283. }
  5284. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5285. deliveryWay, _ := json["delivery_way"].(string)
  5286. advice.DeliveryWay = deliveryWay
  5287. }
  5288. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5289. executionFrequency, _ := json["execution_frequency"].(string)
  5290. advice.ExecutionFrequency = executionFrequency
  5291. }
  5292. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5293. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5294. advice.Price = price
  5295. }
  5296. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5297. med_list_codg, _ := json["medical_insurance_number"].(string)
  5298. advice.MedListCodg = med_list_codg
  5299. }
  5300. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5301. day := int64(json["day"].(float64))
  5302. advice.Day = day
  5303. }
  5304. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5305. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5306. advice.PrescribingNumberUnit = prescribingNumberUnit
  5307. }
  5308. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5309. advice_id := int64(json["advice_id"].(float64))
  5310. advice.ID = advice_id
  5311. if advice.ID > 0 {
  5312. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5313. if err == nil {
  5314. if hisAdvice.ID > 0 {
  5315. advice.ExecutionTime = hisAdvice.ExecutionTime
  5316. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5317. advice.ExecutionState = hisAdvice.ExecutionState
  5318. advice.CheckTime = hisAdvice.CheckTime
  5319. advice.Checker = hisAdvice.Checker
  5320. advice.CheckState = hisAdvice.CheckState
  5321. advice.StartTime = hisAdvice.StartTime
  5322. advice.HospApprFlag = hisAdvice.HospApprFlag
  5323. advice.IsMedicine = hisAdvice.IsMedicine
  5324. if hisAdvice.UserOrgId == 10028 {
  5325. 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 {
  5326. advice.ExecutionTime = 0
  5327. advice.ExecutionStaff = 0
  5328. advice.ExecutionState = 2
  5329. advice.CheckTime = 0
  5330. advice.Checker = 0
  5331. advice.CheckState = 2
  5332. }
  5333. } else {
  5334. 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 {
  5335. advice.ExecutionTime = 0
  5336. advice.ExecutionStaff = 0
  5337. advice.ExecutionState = 2
  5338. advice.CheckTime = 0
  5339. advice.Checker = 0
  5340. advice.CheckState = 2
  5341. }
  5342. }
  5343. //advice.Groupno = hisAdvice.Groupno
  5344. }
  5345. }
  5346. }
  5347. }
  5348. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5349. //
  5350. //if drugStockConfig.IsOpen == 1 {
  5351. //
  5352. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5353. // if advice.ID == 0 { //医嘱不存在
  5354. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5355. // drug.Total = drug.Total - advice.PrescribingNumber
  5356. // service.UpdateBaseDrugLib(&drug)
  5357. //
  5358. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5359. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5360. // drug.Total = drug.Total - num
  5361. // service.UpdateBaseDrugLib(&drug)
  5362. // }
  5363. //
  5364. // } else if advice.ID > 0 { //医嘱存在
  5365. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5366. // var num float64
  5367. //
  5368. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5369. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5370. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5371. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5372. // drug.Total = drug.Total + num
  5373. // service.UpdateBaseDrugLib(&drug)
  5374. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5375. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5376. // drug.Total = drug.Total - num
  5377. // service.UpdateBaseDrugLib(&drug)
  5378. // }
  5379. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5380. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5381. // if num2 > advice.PrescribingNumber {
  5382. // num = num2 - advice.PrescribingNumber
  5383. // drug.Total = drug.Total + num
  5384. // service.UpdateBaseDrugLib(&drug)
  5385. // } else if num2 < advice.PrescribingNumber {
  5386. // num = advice.PrescribingNumber - num2
  5387. // drug.Total = drug.Total - num
  5388. // service.UpdateBaseDrugLib(&drug)
  5389. // }
  5390. //
  5391. // }
  5392. //
  5393. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5394. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5395. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5396. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5397. // if num1 > num2 {
  5398. // num = num1 - num2
  5399. // drug.Total = drug.Total + num
  5400. // service.UpdateBaseDrugLib(&drug)
  5401. // } else if num1 < num2 {
  5402. // num = num2 - num1
  5403. // drug.Total = drug.Total - num
  5404. // service.UpdateBaseDrugLib(&drug)
  5405. // }
  5406. //
  5407. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5408. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5409. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5410. // if hisAdvice.PrescribingNumber > num2 {
  5411. // num = hisAdvice.PrescribingNumber - num2
  5412. // drug.Total = drug.Total + num
  5413. // service.UpdateBaseDrugLib(&drug)
  5414. // } else if num2 < advice.PrescribingNumber {
  5415. // num = num2 - hisAdvice.PrescribingNumber
  5416. // drug.Total = drug.Total - num
  5417. // service.UpdateBaseDrugLib(&drug)
  5418. // }
  5419. //
  5420. // }
  5421. // }
  5422. // }
  5423. //}
  5424. //
  5425. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5426. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5427. // advice.ExecutionTime = execution_time
  5428. //}
  5429. //
  5430. //
  5431. //
  5432. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5433. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5434. // advice.ExecutionStaff = execution_staff
  5435. //}
  5436. //
  5437. //
  5438. //
  5439. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5440. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5441. // advice.ExecutionState = execution_state
  5442. //}
  5443. //
  5444. //
  5445. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5446. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5447. // advice.CheckTime = check_time
  5448. //}
  5449. //
  5450. //
  5451. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5452. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5453. // advice.CheckState = check_state
  5454. //}
  5455. //
  5456. //
  5457. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5458. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5459. // advice.Checker = checker
  5460. //}
  5461. //
  5462. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5463. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5464. // advice.StartTime = start_time
  5465. //}
  5466. return 0
  5467. }
  5468. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5469. project.ExecutionStaff = 0
  5470. project.ExecutionState = 2
  5471. project.ExecutionTime = 0
  5472. project.Checker = 0
  5473. project.CheckState = 2
  5474. project.CheckTime = 0
  5475. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5476. id := int64(json["id"].(float64))
  5477. project.ID = id
  5478. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5479. project.ExecutionStaff = temp_project.ExecutionStaff
  5480. project.ExecutionState = temp_project.ExecutionState
  5481. project.ExecutionTime = temp_project.ExecutionTime
  5482. project.Checker = temp_project.Checker
  5483. project.CheckState = temp_project.CheckState
  5484. project.CheckTime = temp_project.CheckTime
  5485. project.TeamId = temp_project.TeamId
  5486. }
  5487. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5488. types := int64(json["type"].(float64))
  5489. project.Type = types
  5490. }
  5491. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5492. project_id := int64(json["project_id"].(float64))
  5493. project.ProjectId = project_id
  5494. }
  5495. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5496. team_id := int64(json["team_id"].(float64))
  5497. project.TeamId = team_id
  5498. }
  5499. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5500. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5501. project.Price = price
  5502. }
  5503. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5504. total, _ := json["total"].(string)
  5505. //totals, _ := strconv.ParseInt(total, 10, 64)
  5506. project.Count = total
  5507. }
  5508. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5509. medical_code, _ := json["medical_code"].(string)
  5510. project.MedListCodg = medical_code
  5511. }
  5512. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5513. single_dose, _ := json["single_dose"].(string)
  5514. project.SingleDose = single_dose
  5515. }
  5516. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5517. delivery_way, _ := json["delivery_way"].(string)
  5518. project.DeliveryWay = delivery_way
  5519. }
  5520. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5521. execution_frequency, _ := json["execution_frequency"].(string)
  5522. project.ExecutionFrequency = execution_frequency
  5523. }
  5524. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5525. remark, _ := json["remark"].(string)
  5526. project.Remark = remark
  5527. }
  5528. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5529. day, _ := json["number_days"].(string)
  5530. project.Day = day
  5531. }
  5532. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5533. unit, _ := json["unit"].(string)
  5534. project.Unit = unit
  5535. }
  5536. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5537. // frequency_type := int64(json["frequency_type"].(float64))
  5538. // project.FrequencyType = frequency_type
  5539. //}
  5540. //
  5541. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5542. // day_count := int64(json["day_count"].(float64))
  5543. // project.DayCount = day_count
  5544. //}
  5545. //
  5546. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5547. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5548. // week_day, _ := json["week_day"].(string)
  5549. // project.WeekDay = week_day
  5550. //}
  5551. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5552. //
  5553. //if project.ID == 0 {
  5554. // if stockConfig.IsOpen == 1 {
  5555. // if project.Type == 3 {
  5556. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5557. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5558. // good.Total = good.Total - f_count
  5559. // service.UpdateGoodInfo(&good)
  5560. // }
  5561. // }
  5562. //
  5563. //} else {
  5564. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5565. //
  5566. // if stockConfig.IsOpen == 1 {
  5567. // if project.Type == 3 {
  5568. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5569. // if project.Count < temp_project.Count {
  5570. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5571. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5572. //
  5573. // other_count := f_count_two - f_count_one
  5574. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5575. // good.Total = good.Total + other_count_two
  5576. // service.UpdateGoodInfo(&good)
  5577. // } else if project.Count > temp_project.Count {
  5578. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5579. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5580. //
  5581. // other_count := f_count_one - f_count_two
  5582. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5583. // good.Total = good.Total - other_count_two
  5584. // service.UpdateGoodInfo(&good)
  5585. // }
  5586. //
  5587. // }
  5588. // }
  5589. //
  5590. //}
  5591. return 0
  5592. }
  5593. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5594. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5595. id := int64(json["id"].(float64))
  5596. additionalCharge.ID = id
  5597. }
  5598. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5599. item_id := int64(json["item_id"].(float64))
  5600. additionalCharge.ItemId = item_id
  5601. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5602. if config.ID > 0 {
  5603. if len(config.Code) > 0 {
  5604. additionalCharge.MedListCodg = config.Code
  5605. }
  5606. }
  5607. }
  5608. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5609. // price := int64(json["price"].(float64))
  5610. // formatInt_price := strconv.FormatInt(price, 10)
  5611. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5612. // additionalCharge.Price = float_price
  5613. // }
  5614. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5615. // price := int64(json["price"].(float64))
  5616. // formatInt_price := strconv.FormatInt(price, 10)
  5617. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5618. // additionalCharge.Price = float_price
  5619. //}
  5620. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5621. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5622. additionalCharge.Price = price
  5623. }
  5624. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5625. count, _ := json["count"].(string)
  5626. counts, _ := strconv.ParseInt(count, 10, 64)
  5627. additionalCharge.Count = counts
  5628. }
  5629. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5630. item_name, _ := json["item_name"].(string)
  5631. additionalCharge.ItemName = item_name
  5632. }
  5633. return 0
  5634. }
  5635. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5636. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5637. utils.ErrorLog("drug_name")
  5638. return enums.ErrorCodeParamWrong
  5639. }
  5640. adviceName, _ := json["drug_name"].(string)
  5641. if len(adviceName) == 0 {
  5642. utils.ErrorLog("len(advice_name) == 0")
  5643. return enums.ErrorCodeParamWrong
  5644. }
  5645. advice.AdviceName = adviceName
  5646. adviceDesc, _ := json["advice_desc"].(string)
  5647. advice.AdviceDesc = adviceDesc
  5648. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5649. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5650. advice.DrugSpec = drugSpec
  5651. }
  5652. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5653. remark, _ := json["remark"].(string)
  5654. advice.Remark = remark
  5655. }
  5656. if json["id"] == nil {
  5657. advice.DrugId = 0
  5658. } else {
  5659. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5660. drug_id := int64(json["id"].(float64))
  5661. advice.DrugId = drug_id
  5662. }
  5663. }
  5664. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5665. groupno := int64(json["groupno"].(float64))
  5666. advice.Groupno = groupno
  5667. }
  5668. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5669. drugSpecUnit, _ := json["min_unit"].(string)
  5670. advice.DrugSpecUnit = drugSpecUnit
  5671. }
  5672. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5673. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5674. advice.SingleDose = singleDose
  5675. }
  5676. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5677. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5678. advice.SingleDoseUnit = singleDoseUnit
  5679. }
  5680. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5681. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5682. advice.PrescribingNumber = prescribingNumber
  5683. }
  5684. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5685. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5686. advice.PrescribingNumberUnit = prescribingNumberUnit
  5687. }
  5688. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5689. deliveryWay, _ := json["delivery_way"].(string)
  5690. advice.DeliveryWay = deliveryWay
  5691. }
  5692. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5693. executionFrequency, _ := json["execution_frequency"].(string)
  5694. advice.ExecutionFrequency = executionFrequency
  5695. }
  5696. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5697. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5698. advice.Price = price
  5699. }
  5700. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5701. med_list_codg, _ := json["medical_insurance_number"].(string)
  5702. advice.MedListCodg = med_list_codg
  5703. }
  5704. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5705. day := int64(json["day"].(float64))
  5706. advice.Day = day
  5707. }
  5708. advice.FrequencyType = 1
  5709. return 0
  5710. }
  5711. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5712. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5713. types := int64(json["type"].(float64))
  5714. project.Type = types
  5715. }
  5716. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5717. project_id := int64(json["project_id"].(float64))
  5718. project.ProjectId = project_id
  5719. }
  5720. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5721. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5722. project.Price = price
  5723. }
  5724. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5725. total, _ := json["total"].(string)
  5726. //totals, _ := strconv.ParseInt(total, 10, 64)
  5727. project.Count = total
  5728. }
  5729. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5730. medical_code, _ := json["medical_code"].(string)
  5731. project.MedListCodg = medical_code
  5732. }
  5733. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5734. single_dose, _ := json["single_dose"].(string)
  5735. project.SingleDose = single_dose
  5736. }
  5737. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5738. delivery_way, _ := json["delivery_way"].(string)
  5739. project.DeliveryWay = delivery_way
  5740. }
  5741. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5742. execution_frequency, _ := json["execution_frequency"].(string)
  5743. project.ExecutionFrequency = execution_frequency
  5744. }
  5745. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5746. remark, _ := json["remark"].(string)
  5747. project.Remark = remark
  5748. }
  5749. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5750. day, _ := json["number_days"].(string)
  5751. project.Day = day
  5752. }
  5753. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5754. unit, _ := json["unit"].(string)
  5755. project.Unit = unit
  5756. }
  5757. project.FrequencyType = 1
  5758. return 0
  5759. }
  5760. func (c *HisApiController) GetHisOrderList() {
  5761. page, _ := c.GetInt64("page", -1)
  5762. limit, _ := c.GetInt64("limit", -1)
  5763. start_time := c.GetString("start_time")
  5764. end_time := c.GetString("end_time")
  5765. types, _ := c.GetInt64("type", 0)
  5766. keywords := c.GetString("keywords")
  5767. p_type, _ := c.GetInt64("p_type", 0)
  5768. sort_type, _ := c.GetInt64("sort_type", 0)
  5769. charge_type, _ := c.GetInt64("charge_type", 0)
  5770. sch_type, _ := c.GetInt64("sch_type", 0)
  5771. zone_type, _ := c.GetInt64("zone_type", 0)
  5772. med_type, _ := c.GetInt64("med_type", 0)
  5773. timeLayout := "2006-01-02"
  5774. loc, _ := time.LoadLocation("Local")
  5775. var startTime int64
  5776. if len(start_time) > 0 {
  5777. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5778. if err != nil {
  5779. //fmt.Println(err)
  5780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5781. return
  5782. }
  5783. startTime = theTime.Unix()
  5784. }
  5785. var endTime int64
  5786. if len(end_time) > 0 {
  5787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5788. if err != nil {
  5789. utils.ErrorLog(err.Error())
  5790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5791. return
  5792. }
  5793. endTime = theTime.Unix()
  5794. }
  5795. adminUser := c.GetAdminUserInfo()
  5796. org_id := adminUser.CurrentOrgId
  5797. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  5798. order2, _ := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  5799. for _, item := range order {
  5800. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5801. item.DoctorName = info.Doctor
  5802. item.DepartmentName = info.XtHisDepartment.Name
  5803. }
  5804. if err == nil {
  5805. c.ServeSuccessJSON(map[string]interface{}{
  5806. "order": order,
  5807. "order2": order2,
  5808. "total": total,
  5809. })
  5810. } else {
  5811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5812. return
  5813. }
  5814. }
  5815. func (c *HisApiController) GetHisOrder() {
  5816. patient_id, _ := c.GetInt64("patient_id", 0)
  5817. number := c.GetString("number")
  5818. adminInfo := c.GetAdminUserInfo()
  5819. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5820. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5821. if err == nil {
  5822. c.ServeSuccessJSON(map[string]interface{}{
  5823. "order": order,
  5824. "prescription": prescriptions,
  5825. })
  5826. } else {
  5827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5828. return
  5829. }
  5830. }
  5831. func (c *HisApiController) GetHisPrescriptionList() {
  5832. record_date := c.GetString("record_date")
  5833. keywords := c.GetString("keywords")
  5834. page, _ := c.GetInt64("page")
  5835. limit, _ := c.GetInt64("limit")
  5836. sch_type, _ := c.GetInt64("sch_type")
  5837. timeLayout := "2006-01-02"
  5838. loc, _ := time.LoadLocation("Local")
  5839. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5840. if err != nil {
  5841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5842. return
  5843. }
  5844. recordDateTime := theTime.Unix()
  5845. adminInfo := c.GetAdminUserInfo()
  5846. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5847. //adminInfo := c.GetAdminUserInfo()
  5848. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5849. //fmt.Println(prescriptionOrder)
  5850. if err == nil {
  5851. c.ServeSuccessJSON(map[string]interface{}{
  5852. "order": prescriptionOrder,
  5853. "total": total,
  5854. })
  5855. } else {
  5856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5857. return
  5858. }
  5859. }
  5860. func (c *HisApiController) GetHisPrescriptionInfo() {
  5861. id, _ := c.GetInt64("id")
  5862. adminInfo := c.GetAdminUserInfo()
  5863. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5864. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5865. if err == nil {
  5866. c.ServeSuccessJSON(map[string]interface{}{
  5867. "order": prescriptionOrder,
  5868. "prescription": prescription,
  5869. })
  5870. } else {
  5871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5872. return
  5873. }
  5874. }
  5875. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5876. adminUser := c.GetAdminUserInfo()
  5877. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5878. c.ServeSuccessJSON(map[string]interface{}{
  5879. "config": config,
  5880. })
  5881. }
  5882. type ResultTwo struct {
  5883. ErrMsg interface{} `json:"err_msg"`
  5884. InfRefmsgid string `json:"inf_refmsgid"`
  5885. Infcode int64 `json:"infcode"`
  5886. Output struct {
  5887. Baseinfo struct {
  5888. Age float64 `json:"age"`
  5889. Brdy string `json:"brdy"`
  5890. Certno string `json:"certno"`
  5891. Gend string `json:"gend"`
  5892. Naty string `json:"naty"`
  5893. PsnCertType string `json:"psn_cert_type"`
  5894. PsnName string `json:"psn_name"`
  5895. PsnNo string `json:"psn_no"`
  5896. } `json:"baseinfo"`
  5897. Idetinfo []interface{} `json:"idetinfo"`
  5898. Iinfo []struct {
  5899. Balc float64 `json:"balc"`
  5900. CvlservFlag string `json:"cvlserv_flag"`
  5901. EmpName string `json:"emp_name"`
  5902. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5903. Insutype string `json:"insutype"`
  5904. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5905. PausInsuDate interface{} `json:"paus_insu_date"`
  5906. PsnInsuDate string `json:"psn_insu_date"`
  5907. PsnInsuStas string `json:"psn_insu_stas"`
  5908. PsnType string `json:"psn_type"`
  5909. } `json:"insuinfo"`
  5910. } `json:"output"`
  5911. RefmsgTime string `json:"refmsg_time"`
  5912. RespondTime string `json:"respond_time"`
  5913. Signtype interface{} `json:"signtype"`
  5914. WarnInfo interface{} `json:"warn_info"`
  5915. }
  5916. type ResultThree struct {
  5917. Cainfo interface{} `json:"cainfo"`
  5918. ErrMsg interface{} `json:"err_msg"`
  5919. InfRefmsgid string `json:"inf_refmsgid"`
  5920. Infcode int64 `json:"infcode"`
  5921. Output struct {
  5922. Data struct {
  5923. IptOtpNo string `json:"ipt_otp_no"`
  5924. MdtrtID string `json:"mdtrt_id"`
  5925. PsnNo string `json:"psn_no"`
  5926. } `json:"data"`
  5927. } `json:"output"`
  5928. RefmsgTime string `json:"refmsg_time"`
  5929. RespondTime string `json:"respond_time"`
  5930. Signtype interface{} `json:"signtype"`
  5931. WarnMsg interface{} `json:"warn_msg"`
  5932. }
  5933. type ResultFour struct {
  5934. Cainfo string `json:"cainfo"`
  5935. ErrMsg string `json:"err_msg"`
  5936. InfRefmsgid string `json:"inf_refmsgid"`
  5937. Infcode int64 `json:"infcode"`
  5938. Output struct {
  5939. Result []struct {
  5940. BasMednFlag string `json:"bas_medn_flag"`
  5941. ChldMedcFlag string `json:"chld_medc_flag"`
  5942. ChrgitmLv string `json:"chrgitm_lv"`
  5943. Cnt float64 `json:"cnt"`
  5944. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5945. DrtReimFlag string `json:"drt_reim_flag"`
  5946. FeedetlSn string `json:"feedetl_sn"`
  5947. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5948. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5949. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5950. ListSpItemFlag string `json:"list_sp_item_flag"`
  5951. LmtUsedFlag string `json:"lmt_used_flag"`
  5952. MedChrgitmType string `json:"med_chrgitm_type"`
  5953. Memo string `json:"memo"`
  5954. OverlmtAmt float64 `json:"overlmt_amt"`
  5955. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5956. Pric float64 `json:"pric"`
  5957. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5958. SelfpayProp float64 `json:"selfpay_prop"`
  5959. } `json:"result"`
  5960. } `json:"output"`
  5961. RefmsgTime string `json:"refmsg_time"`
  5962. RespondTime string `json:"respond_time"`
  5963. Signtype string `json:"signtype"`
  5964. WarnMsg string `json:"warn_msg"`
  5965. }
  5966. type ResultFive struct {
  5967. Insutype string `json:"insutype"`
  5968. }
  5969. type ResultSix struct {
  5970. Cainfo interface{} `json:"cainfo"`
  5971. ErrMsg interface{} `json:"err_msg"`
  5972. InfRefmsgid string `json:"inf_refmsgid"`
  5973. Infcode int64 `json:"infcode"`
  5974. Output struct {
  5975. } `json:"output"`
  5976. RefmsgTime string `json:"refmsg_time"`
  5977. RespondTime string `json:"respond_time"`
  5978. Signtype interface{} `json:"signtype"`
  5979. WarnMsg interface{} `json:"warn_msg"`
  5980. }
  5981. type ResultSeven struct {
  5982. Cainfo string `json:"cainfo"`
  5983. ErrMsg string `json:"err_msg"`
  5984. InfRefmsgid string `json:"inf_refmsgid"`
  5985. Infcode int64 `json:"infcode"`
  5986. Output struct {
  5987. Setldetail []interface{} `json:"setldetail"`
  5988. Setlinfo struct {
  5989. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5990. AcctPay float64 `json:"acct_pay"`
  5991. ActPayDedc float64 `json:"act_pay_dedc"`
  5992. Age float64 `json:"age"`
  5993. Balc float64 `json:"balc"`
  5994. Brdy string `json:"brdy"`
  5995. Certno string `json:"certno"`
  5996. ClrOptins string `json:"clr_optins"`
  5997. ClrType string `json:"clr_type"`
  5998. ClrWay string `json:"clr_way"`
  5999. CvlservFlag string `json:"cvlserv_flag"`
  6000. CvlservPay float64 `json:"cvlserv_pay"`
  6001. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6002. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6003. Gend string `json:"gend"`
  6004. HifesPay float64 `json:"hifes_pay"`
  6005. HifmiPay float64 `json:"hifmi_pay"`
  6006. HifobPay float64 `json:"hifob_pay"`
  6007. HifpPay float64 `json:"hifp_pay"`
  6008. HospPartAmt float64 `json:"hosp_part_amt"`
  6009. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6010. Insutype string `json:"insutype"`
  6011. MafPay float64 `json:"maf_pay"`
  6012. MdtrtCertType string `json:"mdtrt_cert_type"`
  6013. MdtrtID string `json:"mdtrt_id"`
  6014. MedType string `json:"med_type"`
  6015. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6016. MedinsSetlID string `json:"medins_setl_id"`
  6017. Naty string `json:"naty"`
  6018. OthPay float64 `json:"oth_pay"`
  6019. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6020. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6021. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6022. PsnCashPay float64 `json:"psn_cash_pay"`
  6023. PsnCertType string `json:"psn_cert_type"`
  6024. PsnName string `json:"psn_name"`
  6025. PsnNo string `json:"psn_no"`
  6026. PsnPartAmt float64 `json:"psn_part_amt"`
  6027. PsnType string `json:"psn_type"`
  6028. SetlID string `json:"setl_id"`
  6029. SetlTime string `json:"setl_time"`
  6030. } `json:"setlinfo"`
  6031. } `json:"output"`
  6032. RefmsgTime string `json:"refmsg_time"`
  6033. RespondTime string `json:"respond_time"`
  6034. Signtype interface{} `json:"signtype"`
  6035. WarnMsg interface{} `json:"warn_msg"`
  6036. }
  6037. type ResultEight struct {
  6038. Cainfo string `json:"cainfo"`
  6039. ErrMsg string `json:"err_msg"`
  6040. InfRefmsgid string `json:"inf_refmsgid"`
  6041. Infcode int64 `json:"infcode"`
  6042. Output struct {
  6043. Stmtinfo struct {
  6044. SetlOptins string `json:"setl_optins"`
  6045. StmtRslt string `json:"stmt_rslt"`
  6046. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6047. } `json:"stmtinfo"`
  6048. } `json:"output"`
  6049. RefmsgTime string `json:"refmsg_time"`
  6050. RespondTime string `json:"respond_time"`
  6051. Signtype interface{} `json:"signtype"`
  6052. WarnMsg interface{} `json:"warn_msg"`
  6053. }
  6054. type ResultNine struct {
  6055. Cainfo string `json:"cainfo"`
  6056. ErrMsg string `json:"err_msg"`
  6057. InfRefmsgid string `json:"inf_refmsgid"`
  6058. Infcode int64 `json:"infcode"`
  6059. Output struct {
  6060. FileQuryNo string `json:"file_qury_no"`
  6061. } `json:"output"`
  6062. RefmsgTime string `json:"refmsg_time"`
  6063. RespondTime string `json:"respond_time"`
  6064. Signtype interface{} `json:"signtype"`
  6065. WarnMsg interface{} `json:"warn_msg"`
  6066. }
  6067. type ResultTen struct {
  6068. Cainfo string `json:"cainfo"`
  6069. ErrMsg string `json:"err_msg"`
  6070. InfRefmsgid string `json:"inf_refmsgid"`
  6071. Infcode int64 `json:"infcode"`
  6072. Output struct {
  6073. DldEndtime string `json:"dld_endtime"`
  6074. FileQuryNo string `json:"file_qury_no"`
  6075. Filename string `json:"filename"`
  6076. } `json:"output"`
  6077. RefmsgTime string `json:"refmsg_time"`
  6078. RespondTime string `json:"respond_time"`
  6079. Signtype interface{} `json:"signtype"`
  6080. WarnMsg interface{} `json:"warn_msg"`
  6081. }
  6082. type ResultEleven struct {
  6083. Cainfo string `json:"cainfo"`
  6084. ErrMsg string `json:"err_msg"`
  6085. InfRefmsgid string `json:"inf_refmsgid"`
  6086. Infcode int64 `json:"infcode"`
  6087. Output struct {
  6088. Setlinfo struct {
  6089. FixmedinsName string `json:"fixmedins_name"`
  6090. FixmedinsCode string `json:"fixmedins_code"`
  6091. PsnNo string `json:"psn_no"`
  6092. PsnName string `json:"psn_name"`
  6093. HifobPay float64 `json:"hifob_pay"`
  6094. Gend string `json:"gend"`
  6095. Brdy string `json:"brdy"`
  6096. PsnCertType string `json:"psn_cert_type"`
  6097. PsnType string `json:"psn_type"`
  6098. EmpName string `json:"emp_name"`
  6099. Certno string `json:"certno"`
  6100. Insutype string `json:"insutype"`
  6101. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6102. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6103. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6104. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6105. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6106. ActPayDedc float64 `json:"act_pay_dedc"`
  6107. HifpPay float64 `json:"hifp_pay"`
  6108. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6109. CvlservPay float64 `json:"cvlserv_pay"`
  6110. HifesPay float64 `json:"hifes_pay"`
  6111. HifmiPay float64 `json:"hifmi_pay"`
  6112. MafPay float64 `json:"maf_pay"`
  6113. OthPay float64 `json:"oth_pay"`
  6114. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6115. PsnPay float64 `json:"psn_pay"`
  6116. AcctPay float64 `json:"acct_pay"`
  6117. CashPayamt float64 `json:"cash_payamt"`
  6118. Balc float64 `json:"balc"`
  6119. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6120. MedinsSetlId string `json:"medins_setl_id"`
  6121. RefdSetlFlag string `json:"refd_setl_flag"`
  6122. SetlTime string `json:"setl_time"`
  6123. MedType string `json:"med_type"`
  6124. } `json:"setlinfo"`
  6125. } `json:"output"`
  6126. RefmsgTime string `json:"refmsg_time"`
  6127. RespondTime string `json:"respond_time"`
  6128. Signtype interface{} `json:"signtype"`
  6129. WarnMsg interface{} `json:"warn_msg"`
  6130. }
  6131. type Custom struct {
  6132. DetItemFeeSumamt string
  6133. Cut string
  6134. FeedetlSn string
  6135. Price string
  6136. MedListCodg string
  6137. Type int64
  6138. AdviceId int64
  6139. ProjectId int64
  6140. ItemId int64
  6141. }
  6142. // 获取个人信息----挂号-----上传就诊信息
  6143. func (c *HisApiController) GetRegisterInfo() {
  6144. id, _ := c.GetInt64("id")
  6145. record_time := c.GetString("record_time")
  6146. settlementValue, _ := c.GetInt64("settlement_value")
  6147. medical_insurance_card := c.GetString("medical_insurance_card")
  6148. name := c.GetString("name")
  6149. id_card_type, _ := c.GetInt64("id_card_type")
  6150. certificates, _ := c.GetInt64("certificates")
  6151. medical_care, _ := c.GetInt64("medical_care")
  6152. birthday := c.GetString("birthday")
  6153. age, _ := c.GetInt64("age")
  6154. id_card := c.GetString("id_card")
  6155. register_type, _ := c.GetInt64("register")
  6156. doctor, _ := c.GetInt64("doctor")
  6157. department, _ := c.GetInt64("department")
  6158. gender, _ := c.GetInt64("sex")
  6159. phone := c.GetString("phone")
  6160. registration_fee, _ := c.GetFloat("registration_fee")
  6161. medical_expenses, _ := c.GetFloat("medical_expenses")
  6162. social_type, _ := c.GetInt64("social_type")
  6163. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6164. diagnosis_ids := c.GetString("diagnosis")
  6165. sick_type, _ := c.GetInt64("sick_type")
  6166. reg_type := c.GetString("p_type")
  6167. timeLayout := "2006-01-02"
  6168. loc, _ := time.LoadLocation("Local")
  6169. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6170. birthUnix := birthdays.Unix()
  6171. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6172. if err != nil {
  6173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6174. return
  6175. }
  6176. recordDateTime := theTime.Unix()
  6177. adminInfo := c.GetAdminUserInfo()
  6178. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6179. if tempPatient.ID == 0 {
  6180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6181. return
  6182. }
  6183. var patient service.Patients
  6184. if id == 0 {
  6185. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6186. } else {
  6187. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6188. }
  6189. if patient.ID == 0 {
  6190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6191. return
  6192. }
  6193. if len(patient.IdCardNo) == 0 {
  6194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6195. return
  6196. }
  6197. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6198. if len(his) >= 1 {
  6199. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6200. if len(his) >= 1 && order.ID == 0 {
  6201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6202. return
  6203. }
  6204. }
  6205. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6206. fmt.Println(timeStr)
  6207. timeArr := strings.Split(timeStr, " ")
  6208. fmt.Println(timeArr)
  6209. timeArrTwo := strings.Split(timeArr[0], "-")
  6210. timeArrThree := strings.Split(timeArr[1], ":")
  6211. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6212. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6213. if len(lists) == 0 {
  6214. var hisPatient models.XtHisPatient
  6215. hisPatient = models.XtHisPatient{
  6216. Name: name,
  6217. Age: age,
  6218. Gender: gender,
  6219. Birthday: birthUnix,
  6220. Phone: phone,
  6221. MedicalTreatmentType: medical_care,
  6222. IdType: certificates,
  6223. IdCardNo: id_card,
  6224. BalanceAccountsType: settlementValue,
  6225. SocialType: social_type,
  6226. MedicalInsuranceNumber: medical_insurance_card,
  6227. RegisterType: register_type,
  6228. RegisterCost: registration_fee,
  6229. TreatmentCost: medical_expenses,
  6230. AdminUserId: adminInfo.AdminUser.Id,
  6231. UserOrgId: adminInfo.CurrentOrgId,
  6232. Status: 1,
  6233. RecordDate: recordDateTime,
  6234. IsReturn: 1,
  6235. PatientId: patient.ID,
  6236. Ctime: time.Now().Unix(),
  6237. Mtime: time.Now().Unix(),
  6238. Number: str,
  6239. IdCardType: id_card_type,
  6240. Departments: department,
  6241. Doctor: doctor,
  6242. PType: reg_type,
  6243. Diagnosis: diagnosis_ids,
  6244. SickType: sick_type,
  6245. }
  6246. service.CreateHisPatient(&hisPatient)
  6247. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6248. c.ServeSuccessJSON(map[string]interface{}{
  6249. "his_info": hisPatient,
  6250. })
  6251. } else {
  6252. //chrgBchno := rand.Intn(1000000) + 10000
  6253. var hisPatient models.XtHisPatient
  6254. hisPatient = models.XtHisPatient{
  6255. Name: name,
  6256. Age: age,
  6257. Gender: gender,
  6258. Birthday: birthUnix,
  6259. Phone: phone,
  6260. MedicalTreatmentType: medical_care,
  6261. IdType: certificates,
  6262. IdCardNo: id_card,
  6263. BalanceAccountsType: settlementValue,
  6264. SocialType: social_type,
  6265. MedicalInsuranceNumber: medical_insurance_card,
  6266. RegisterType: register_type,
  6267. RegisterCost: registration_fee,
  6268. TreatmentCost: medical_expenses,
  6269. AdminUserId: adminInfo.AdminUser.Id,
  6270. UserOrgId: adminInfo.CurrentOrgId,
  6271. Status: 1,
  6272. RecordDate: recordDateTime,
  6273. IsReturn: 1,
  6274. PatientId: patient.ID,
  6275. Ctime: time.Now().Unix(),
  6276. Mtime: time.Now().Unix(),
  6277. Number: str,
  6278. IdCardType: id_card_type,
  6279. Departments: department,
  6280. Doctor: doctor,
  6281. PType: reg_type,
  6282. Diagnosis: diagnosis_ids,
  6283. SickType: sick_type,
  6284. }
  6285. service.CreateHisPatient(&hisPatient)
  6286. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6287. c.ServeSuccessJSON(map[string]interface{}{
  6288. "his_info": hisPatient,
  6289. })
  6290. }
  6291. }
  6292. // 上传明细----结算
  6293. func (c *HisApiController) GetUploadInfo() {
  6294. id, _ := c.GetInt64("id")
  6295. record_time := c.GetString("record_time")
  6296. his_patient_id, _ := c.GetInt64("his_patient_id")
  6297. oth_desc := c.GetString("oth_desc")
  6298. pay_way, _ := c.GetInt64("pay_way")
  6299. pay_ways := c.GetString("pay_ways")
  6300. pay_price, _ := c.GetFloat("pay_price")
  6301. pay_card_no := c.GetString("pay_card_no")
  6302. discount_price, _ := c.GetFloat("discount_price")
  6303. preferential_price, _ := c.GetFloat("preferential_price")
  6304. reality_price, _ := c.GetFloat("reality_price")
  6305. found_price, _ := c.GetFloat("found_price")
  6306. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6307. private_price, _ := c.GetFloat("private_price")
  6308. timeLayout := "2006-01-02"
  6309. loc, _ := time.LoadLocation("Local")
  6310. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6311. fapiao_code := c.GetString("fapiao_code")
  6312. fapiao_number := c.GetString("fapiao_number")
  6313. diagnosis_id := c.GetString("diagnosis")
  6314. sick_type, _ := c.GetInt64("sick_type")
  6315. reg_type, _ := c.GetInt64("p_type")
  6316. order_id, _ := c.GetInt64("order_id")
  6317. cash_pay := c.GetString("cash_pay")
  6318. wechat_pay := c.GetString("wechat_pay")
  6319. ali_pay := c.GetString("ali_pay")
  6320. jifen_pay := c.GetString("jifen_pay")
  6321. band_card_pay := c.GetString("band_card_pay")
  6322. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6323. tmp_decimal := c.GetString("tmp_decimal")
  6324. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6325. var decimal float64 //本次使用的押金
  6326. var errmsg error
  6327. tx := service.XTWriteDB().Begin() //开了事务
  6328. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6329. defer func() {
  6330. if errmsg != nil {
  6331. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6332. tx.Rollback()
  6333. } else {
  6334. tx.Commit()
  6335. }
  6336. }()
  6337. fmt.Println("dec_way", dec_way)
  6338. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6339. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6340. return
  6341. }
  6342. if len(tmp_decimal) > 0 {
  6343. if tmp_decimal[0] == 45 {
  6344. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6345. return
  6346. }
  6347. }
  6348. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6349. fmt.Println(errs)
  6350. decimal = tt
  6351. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6352. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6353. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6354. if err != nil {
  6355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6356. return
  6357. }
  6358. recordDateTime := theTime.Unix()
  6359. adminUser := c.GetAdminUserInfo()
  6360. var prescriptions []*models.HisPrescription
  6361. var prescriptionsOne []*models.HisPrescription
  6362. var start_time int64
  6363. var end_time int64
  6364. ids_str := c.GetString("ids")
  6365. ids_arr := strings.Split(ids_str, ",")
  6366. if tempOrder.ID == 0 {
  6367. if settle_accounts_type == 1 { //日结
  6368. fmt.Println(reg_type)
  6369. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6370. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6371. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6372. } else {
  6373. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6374. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6375. }
  6376. } else { //月结
  6377. start_time_str := c.GetString("start_time")
  6378. end_time_str := c.GetString("end_time")
  6379. timeLayout := "2006-01-02"
  6380. loc, _ := time.LoadLocation("Local")
  6381. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6382. if err != nil {
  6383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6384. return
  6385. }
  6386. recordStartTime := theStartTime.Unix()
  6387. start_time = recordStartTime
  6388. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6389. if err != nil {
  6390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6391. return
  6392. }
  6393. recordEndTime := theEndTime.Unix()
  6394. end_time = recordEndTime
  6395. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6396. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6397. }
  6398. var goods []*models.DialysisBeforePrepareGoods
  6399. var newGoods []*models.NewDialysisBeforePrepareGoods
  6400. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6401. var infos []*models.HisDoctorAdviceInfo
  6402. var infoList []*models.HisDoctorAdviceInfo
  6403. var hisAdvice []*models.HisDoctorAdviceInfo
  6404. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6405. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6406. //判断库存不足
  6407. //结算出库开关
  6408. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6409. if settConfig.IsOpen == 1 {
  6410. //判断库存的地方
  6411. for _, info := range prescriptions {
  6412. if info.Type == 1 {
  6413. infos = append(infos, info.HisDoctorAdviceInfo...)
  6414. }
  6415. if info.Type == 2 {
  6416. for _, sumItem := range info.HisPrescriptionProject {
  6417. if sumItem.Type == 3 {
  6418. var good models.DialysisBeforePrepareGoods
  6419. var newGood models.NewDialysisBeforePrepareGoods
  6420. good.GoodId = sumItem.GoodInfo.ID
  6421. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6422. count, _ := strconv.Atoi(sumItem.Count)
  6423. good.Count = int64(count)
  6424. good.StorehouseId = houseConfig.StorehouseOutInfo
  6425. good.ProjectId = sumItem.ID
  6426. goods = append(goods, &good)
  6427. newGood.GoodId = sumItem.GoodInfo.ID
  6428. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6429. count2, _ := strconv.Atoi(sumItem.Count)
  6430. newGood.Count = int64(count2)
  6431. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6432. newGood.ProjectId = sumItem.ID
  6433. newGoods = append(newGoods, &newGood)
  6434. }
  6435. }
  6436. }
  6437. }
  6438. for _, info := range prescriptionsOne {
  6439. if info.Type == 1 {
  6440. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6441. }
  6442. if info.Type == 2 {
  6443. for _, sumItem := range info.HisPrescriptionProject {
  6444. if sumItem.Type == 3 {
  6445. var newGood models.NewDialysisBeforePrepareGoods
  6446. newGood.GoodId = sumItem.GoodInfo.ID
  6447. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6448. count2, _ := strconv.Atoi(sumItem.Count)
  6449. newGood.Count = int64(count2)
  6450. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6451. newGood.ProjectId = sumItem.ID
  6452. newGoodOne = append(newGoodOne, &newGood)
  6453. }
  6454. }
  6455. }
  6456. }
  6457. //判断
  6458. for _, itemOne := range infos {
  6459. for _, itemTwo := range hisAdvice {
  6460. if itemOne.DrugId == itemTwo.DrugId {
  6461. itemTwo.Child = append(itemTwo.Child, itemOne)
  6462. }
  6463. }
  6464. }
  6465. for _, itemTwo := range hisAdvice {
  6466. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6467. var sum_out_count int64
  6468. for _, itemThree := range itemTwo.Child {
  6469. var prescribing_number int64
  6470. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6471. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6472. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6473. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6474. }
  6475. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6476. prescribing_number = parseIntPrescribingNumber
  6477. }
  6478. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6479. prescribing_number = parseIntPrescribingNumber
  6480. }
  6481. sum_out_count += prescribing_number
  6482. }
  6483. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6484. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6485. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6486. if sum_out_count > drugStockOut.FlushCount {
  6487. c.ServeSuccessJSON(map[string]interface{}{
  6488. "msg": "2",
  6489. "drug": medical,
  6490. })
  6491. return
  6492. }
  6493. }
  6494. fmt.Println("newGoods99999988882os", newGoods)
  6495. for _, itemOne := range newGoods {
  6496. for _, item := range newGoodOne {
  6497. if itemOne.GoodId == item.GoodId {
  6498. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6499. }
  6500. }
  6501. }
  6502. for _, item := range newGoodOne {
  6503. var sum_out_count_one int64
  6504. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6505. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6506. sum_out_count_one += itemOne.Count
  6507. }
  6508. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6509. fmt.Println("sum_out_count_one", sum_out_count_one)
  6510. fmt.Println("list.FlushCount", list.FlushCount)
  6511. if sum_out_count_one > list.FlushCount {
  6512. c.ServeSuccessJSON(map[string]interface{}{
  6513. "msg": "3",
  6514. "good": good,
  6515. })
  6516. return
  6517. }
  6518. }
  6519. }
  6520. timestamp := time.Now().Unix()
  6521. tempTime := time.Unix(timestamp, 0)
  6522. timeFormat := tempTime.Format("20060102150405")
  6523. chrgBchno := rand.Intn(100000) + 10000
  6524. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6525. strconv.FormatInt(his.PatientId, 10)
  6526. var ids []int64
  6527. for _, item := range prescriptions {
  6528. ids = append(ids, item.ID)
  6529. }
  6530. var total float64
  6531. for _, item := range prescriptions {
  6532. fmt.Println(item)
  6533. if item.Type == 1 { //药品
  6534. for _, subItem := range item.HisDoctorAdviceInfo {
  6535. total = total + (subItem.Price * subItem.PrescribingNumber)
  6536. }
  6537. }
  6538. if item.Type == 2 { //项目
  6539. for _, subItem := range item.HisPrescriptionProject {
  6540. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6541. total = total + (subItem.Price * cnt)
  6542. }
  6543. }
  6544. for _, subItem := range item.HisAdditionalCharge {
  6545. total = total + (subItem.Price * float64(subItem.Count))
  6546. }
  6547. }
  6548. if reg_type == 1111 || reg_type == 1112 {
  6549. reg_type = 11
  6550. }
  6551. tm := time.Unix(time.Now().Unix(), 0)
  6552. allTotal := fmt.Sprintf("%.4f", total)
  6553. totals, _ := strconv.ParseFloat(allTotal, 64)
  6554. order := &models.HisOrder{
  6555. UserOrgId: adminUser.CurrentOrgId,
  6556. HisPatientId: his.ID,
  6557. PatientId: id,
  6558. SettleAccountsDate: recordDateTime,
  6559. Ctime: time.Now().Unix(),
  6560. Mtime: time.Now().Unix(),
  6561. Status: 1,
  6562. OrderStatus: 2,
  6563. MdtrtId: his.Number,
  6564. Number: chrg_bchno,
  6565. MedfeeSumamt: totals,
  6566. PayWay: pay_way,
  6567. PayWays: pay_ways,
  6568. PayPrice: pay_price,
  6569. MedType: strconv.Itoa(int(reg_type)),
  6570. PayCardNo: pay_card_no,
  6571. DiscountPrice: discount_price,
  6572. PreferentialPrice: preferential_price,
  6573. RealityPrice: reality_price,
  6574. FoundPrice: found_price,
  6575. MedicalInsurancePrice: medical_insurance_price,
  6576. PrivatePrice: private_price,
  6577. SettleEndTime: end_time,
  6578. SettleStartTime: start_time,
  6579. PsnPartAmt: totals,
  6580. PsnCashPay: totals,
  6581. SettleType: settle_accounts_type,
  6582. FaPiaoCode: fapiao_code,
  6583. FaPiaoNumber: fapiao_number,
  6584. Diagnosis: diagnosis_id,
  6585. PType: 2,
  6586. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6587. Decimal: decimal,
  6588. OthDesc: oth_desc,
  6589. CashPay: cash_pay,
  6590. WechatPay: wechat_pay,
  6591. AliPay: ali_pay,
  6592. JifenPay: jifen_pay,
  6593. BandCardPay: band_card_pay,
  6594. Creator: adminUser.AdminUser.Id,
  6595. }
  6596. err = service.CreateOrderTX(order, tx)
  6597. if err != nil {
  6598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6599. return
  6600. }
  6601. var customs []*Custom
  6602. for _, item := range prescriptions {
  6603. if item.Type == 1 { //药品a
  6604. for _, subItem := range item.HisDoctorAdviceInfo {
  6605. cus := &Custom{
  6606. AdviceId: subItem.ID,
  6607. ProjectId: 0,
  6608. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6609. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6610. FeedetlSn: subItem.FeedetlSn,
  6611. Price: fmt.Sprintf("%.4f", subItem.Price),
  6612. MedListCodg: subItem.MedListCodg,
  6613. Type: 1,
  6614. }
  6615. customs = append(customs, cus)
  6616. }
  6617. }
  6618. if item.Type == 2 { //项目
  6619. for _, subItem := range item.HisPrescriptionProject {
  6620. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6621. cus := &Custom{
  6622. AdviceId: 0,
  6623. ProjectId: subItem.ID,
  6624. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6625. Cut: fmt.Sprintf("%.4f", cnt),
  6626. FeedetlSn: subItem.FeedetlSn,
  6627. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6628. MedListCodg: subItem.MedListCodg,
  6629. Type: 2,
  6630. }
  6631. customs = append(customs, cus)
  6632. }
  6633. }
  6634. for _, item := range item.HisAdditionalCharge {
  6635. cus := &Custom{
  6636. ItemId: item.ID,
  6637. AdviceId: 0,
  6638. ProjectId: 0,
  6639. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6640. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6641. FeedetlSn: item.FeedetlSn,
  6642. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6643. MedListCodg: item.XtHisAddtionConfig.Code,
  6644. Type: 3,
  6645. }
  6646. customs = append(customs, cus)
  6647. }
  6648. }
  6649. for _, item := range customs {
  6650. var advice_id int64 = 0
  6651. var project_id int64 = 0
  6652. var item_id int64 = 0
  6653. var types int64 = 0
  6654. if item.Type == 1 {
  6655. advice_id = item.AdviceId
  6656. project_id = 0
  6657. item_id = 0
  6658. } else if item.Type == 2 {
  6659. advice_id = 0
  6660. item_id = 0
  6661. project_id = item.ProjectId
  6662. } else if item.Type == 3 {
  6663. advice_id = 0
  6664. item_id = item.ItemId
  6665. project_id = 0
  6666. }
  6667. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6668. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6669. pric, _ := strconv.ParseFloat(item.Price, 32)
  6670. info := &models.HisOrderInfo{
  6671. OrderNumber: order.Number,
  6672. UploadDate: time.Now().Unix(),
  6673. AdviceId: advice_id,
  6674. DetItemFeeSumamt: detItemFeeSumamt,
  6675. Cnt: cut,
  6676. Pric: pric,
  6677. PatientId: id,
  6678. Status: 1,
  6679. Mtime: time.Now().Unix(),
  6680. Ctime: time.Now().Unix(),
  6681. UserOrgId: adminUser.CurrentOrgId,
  6682. HisPatientId: his.ID,
  6683. OrderId: order.ID,
  6684. ProjectId: project_id,
  6685. Type: types,
  6686. ItemId: item_id,
  6687. }
  6688. service.CreateOrderInfoTX(info, tx)
  6689. }
  6690. his.Diagnosis = diagnosis_id
  6691. his.SickType = sick_type
  6692. his.RegisterType = reg_type
  6693. his.MedicalTreatmentType = reg_type
  6694. service.UpdataHisPateintTX(&his, tx)
  6695. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6696. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6697. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6698. //判断是否使用了押金
  6699. if dec_way == "true" {
  6700. tmpstring := strconv.FormatInt(order.ID, 10)
  6701. //扣押金
  6702. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6703. order.Decimal = decimal
  6704. service.UpDateOrderTwo(order, tx)
  6705. if errmsg != nil {
  6706. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6707. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6708. return
  6709. }
  6710. }
  6711. if err == nil {
  6712. for _, info := range prescriptions {
  6713. if info.Type == 1 {
  6714. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6715. }
  6716. if info.Type == 2 {
  6717. for _, sumItem := range info.HisPrescriptionProject {
  6718. if sumItem.Type == 3 {
  6719. var good models.DialysisBeforePrepareGoods
  6720. var newGood models.NewDialysisBeforePrepareGoods
  6721. var oldGood models.OldDialysisBeforePrepareGoods
  6722. good.GoodId = sumItem.GoodInfo.ID
  6723. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6724. count, _ := strconv.Atoi(sumItem.Count)
  6725. good.Count = int64(count)
  6726. good.StorehouseId = houseConfig.StorehouseOutInfo
  6727. good.ProjectId = sumItem.ID
  6728. good.PatientId = sumItem.PatientId
  6729. goods = append(goods, &good)
  6730. newGood.GoodId = sumItem.GoodInfo.ID
  6731. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6732. count2, _ := strconv.Atoi(sumItem.Count)
  6733. newGood.Count = int64(count2)
  6734. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6735. newGood.ProjectId = sumItem.ID
  6736. newGood.PatientId = sumItem.HisPatientId
  6737. newGoods = append(newGoods, &newGood)
  6738. oldGood.GoodId = sumItem.GoodInfo.ID
  6739. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6740. count3, _ := strconv.Atoi(sumItem.Count)
  6741. oldGood.Count = int64(count3)
  6742. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6743. oldGood.ProjectId = sumItem.ID
  6744. oldGood.RecordDate = sumItem.RecordDate
  6745. oldGood.PatientId = sumItem.HisPatientId
  6746. oldGoods = append(oldGoods, &oldGood)
  6747. }
  6748. }
  6749. }
  6750. }
  6751. if settConfig.IsOpen == 1 {
  6752. for _, item := range infoList {
  6753. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6754. if medical.IsUse == 2 {
  6755. //药品出库
  6756. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6757. //查询默认仓库
  6758. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6759. //查询默认仓库剩余多少库存
  6760. var sum_count int64
  6761. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6762. for _, its := range stockInfo {
  6763. if its.MaxUnit == medical.MaxUnit {
  6764. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6765. }
  6766. sum_count += its.StockMaxNumber + its.StockMinNumber
  6767. }
  6768. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6769. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6770. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6771. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6772. }
  6773. }
  6774. orgId := c.GetAdminUserInfo().CurrentOrgId
  6775. if len(oldGoods) > 0 {
  6776. timeStr := time.Now().Format("2006-01-02")
  6777. timeArr := strings.Split(timeStr, "-")
  6778. total, _ := service.FindAllWarehouseOut(orgId)
  6779. total = total + 1
  6780. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6781. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6782. number = number + total
  6783. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6784. operation_time := time.Now().Unix()
  6785. creater := c.GetAdminUserInfo().AdminUser.Id
  6786. //查询默认出库仓库库存
  6787. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6788. recordDateStr := time.Now().Format("2006-01-02")
  6789. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6790. nowtime := recordDate.Unix()
  6791. warehouseOut := models.WarehouseOut{
  6792. WarehouseOutOrderNumber: warehousing_out_order,
  6793. OperationTime: operation_time,
  6794. OrgId: orgId,
  6795. Creater: creater,
  6796. Ctime: time.Now().Unix(),
  6797. Status: 1,
  6798. WarehouseOutTime: nowtime,
  6799. Type: 1,
  6800. StorehouseId: storeConfig.StorehouseOutInfo,
  6801. IsCheck: 1,
  6802. OrderId: order.ID,
  6803. IsSys: 5,
  6804. }
  6805. //查询是否生成出库单
  6806. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6807. if out.ID == 0 {
  6808. service.AddSigleWarehouseOut(&warehouseOut)
  6809. }
  6810. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6811. for _, item := range oldGoods {
  6812. dialyPrepareOne := models.DialysisBeforePrepare{
  6813. GoodTypeId: item.GoodTypeId,
  6814. GoodId: item.GoodId,
  6815. PatientId: his.PatientId,
  6816. RecordDate: item.RecordDate,
  6817. UserOrgId: adminUser.CurrentOrgId,
  6818. Count: item.Count,
  6819. Ctime: time.Now().Unix(),
  6820. Creater: adminUser.AdminUser.Id,
  6821. CommdityCode: item.CommdityCode,
  6822. Status: 1,
  6823. StorehouseId: houseConfig.StorehouseOutInfo,
  6824. }
  6825. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6826. //非零用
  6827. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6828. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6829. //查询剩余库存
  6830. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6831. var sum_count int64
  6832. for _, item := range goodList {
  6833. sum_count += item.StockCount
  6834. }
  6835. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6836. //耗材
  6837. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6838. }
  6839. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6840. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6841. //查询剩余库存
  6842. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6843. var sum_count int64
  6844. for _, item := range goodList {
  6845. sum_count += item.StockCount
  6846. }
  6847. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6848. //耗材
  6849. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6850. }
  6851. }
  6852. }
  6853. }
  6854. c.ServeSuccessJSON(map[string]interface{}{
  6855. "msg": "结算成功",
  6856. })
  6857. }
  6858. }
  6859. }
  6860. // 退款
  6861. func (c *HisApiController) Refund() {
  6862. order_id, _ := c.GetInt64("order_id")
  6863. order, _ := service.GetHisOrderByID(order_id)
  6864. adminUser := c.GetAdminUserInfo()
  6865. orgid := c.GetAdminUserInfo().CurrentOrgId
  6866. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6867. if err != nil {
  6868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6869. return
  6870. }
  6871. tmp := strconv.FormatInt(order.ID, 10)
  6872. //当押金不为零时产生退费记录
  6873. if order.Decimal != 0 {
  6874. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6875. if err != nil {
  6876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6877. return
  6878. }
  6879. }
  6880. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6881. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6882. var goods []*models.DialysisBeforePrepareGoods
  6883. var newGoods []*models.NewDialysisBeforePrepareGoods
  6884. var infos []*models.HisDoctorAdviceInfo
  6885. for _, info := range orders {
  6886. if info.AdviceId > 0 && info.ProjectId == 0 {
  6887. infos = append(infos, &info.HisDoctorAdviceInfo)
  6888. }
  6889. if info.ProjectId > 0 && info.AdviceId == 0 {
  6890. if info.HisPrescriptionProject.Type == 3 {
  6891. var good models.DialysisBeforePrepareGoods
  6892. var newGood models.NewDialysisBeforePrepareGoods
  6893. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6894. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6895. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6896. good.Count = int64(count)
  6897. good.StorehouseId = houseConfig.StorehouseOutInfo
  6898. good.ProjectId = info.HisPrescriptionProject.ID
  6899. good.PatientId = info.PatientId
  6900. good.OrderId = order_id
  6901. goods = append(goods, &good)
  6902. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6903. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6904. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6905. newGood.Count = int64(count2)
  6906. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6907. newGood.ProjectId = info.HisPrescriptionProject.ID
  6908. newGood.RecordDate = order.SettleAccountsDate
  6909. newGood.UserOrgId = order.UserOrgId
  6910. newGood.PatientId = info.PatientId
  6911. newGood.OrderId = order_id
  6912. newGoods = append(newGoods, &newGood)
  6913. }
  6914. }
  6915. }
  6916. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6917. if settConfig.IsOpen == 1 {
  6918. for _, item := range infos {
  6919. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6920. }
  6921. for _, item := range newGoods {
  6922. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6923. }
  6924. }
  6925. c.ServeSuccessJSON(map[string]interface{}{
  6926. "msg": "退费成功",
  6927. })
  6928. }
  6929. func (c *HisApiController) RefundNumber() {
  6930. his_patient_id, _ := c.GetInt64("id")
  6931. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6932. info.Status = 0
  6933. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6934. if count > 0 {
  6935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6936. return
  6937. }
  6938. err := service.SaveHisPatient(info)
  6939. if err == nil {
  6940. c.ServeSuccessJSON(map[string]interface{}{
  6941. "msg": "退号成功",
  6942. })
  6943. } else {
  6944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6945. return
  6946. }
  6947. }
  6948. func (this *HisApiController) AdditionalCharge() {
  6949. dataBody := make(map[string]interface{}, 0)
  6950. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6951. fmt.Println(err)
  6952. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6953. patient_id := int64(dataBody["patient_id"].(float64))
  6954. medicineData, _ := dataBody["medicineData"].([]interface{})
  6955. adminUserInfo := this.GetAdminUserInfo()
  6956. orgId := adminUserInfo.CurrentOrgId
  6957. admin_user_id := adminUserInfo.AdminUser.Id
  6958. timeStr := time.Now().Format("2006-01-02")
  6959. timeLayout := "2006-01-02 15:04:05"
  6960. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6961. timenow := timeStringToTime.Unix()
  6962. var additionalCharges []*models.HisAdditionalCharge
  6963. for _, item := range medicineData {
  6964. var randNum int
  6965. randNum = rand.Intn(10000) + 1000
  6966. timestamp := time.Now().Unix()
  6967. tempTime := time.Unix(timestamp, 0)
  6968. timeFormat := tempTime.Format("20060102150405")
  6969. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6970. items := item.(map[string]interface{})
  6971. money := items["price"].(string)
  6972. item_id_str := items["item_id"].(string)
  6973. name := items["name"].(string)
  6974. id_str := items["id"].(string)
  6975. moneys, _ := strconv.ParseInt(money, 10, 64)
  6976. monStr := strconv.FormatInt(moneys, 10)
  6977. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6978. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6979. id, _ := strconv.ParseInt(id_str, 10, 64)
  6980. additionalCharge := &models.HisAdditionalCharge{
  6981. ID: id,
  6982. HisPatientId: his_patient_id,
  6983. UserOrgId: orgId,
  6984. PatientId: patient_id,
  6985. RecordDate: timenow,
  6986. Price: monneyStr,
  6987. Status: 1,
  6988. ItemName: name,
  6989. ItemId: item_id,
  6990. AdminUserId: admin_user_id,
  6991. CreatedTime: time.Now().Unix(),
  6992. OrderStatus: 0,
  6993. PrescriptionNumber: "",
  6994. BatchNumber: "",
  6995. FeedetlSn: p_number,
  6996. }
  6997. service.CreateAdditionalCharge(additionalCharge)
  6998. additionalCharges = append(additionalCharges, additionalCharge)
  6999. }
  7000. this.ServeSuccessJSON(map[string]interface{}{
  7001. "msg": "添加成功",
  7002. "additional_charges": additionalCharges,
  7003. })
  7004. }
  7005. func (this *HisApiController) DeleteAddition() {
  7006. id, _ := this.GetInt64("id")
  7007. //TODO 需要判断是否已经结算
  7008. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  7009. if err == nil {
  7010. this.ServeSuccessJSON(map[string]interface{}{
  7011. "msg": "删除成功",
  7012. })
  7013. return
  7014. } else {
  7015. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7016. return
  7017. }
  7018. }
  7019. func (this *HisApiController) GetAdminUsers() {
  7020. adminUser := this.GetAdminUserInfo()
  7021. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  7022. this.ServeSuccessJSON(map[string]interface{}{
  7023. "doctors": doctors,
  7024. })
  7025. }
  7026. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7027. change_type, _ := this.GetInt64("type", 0)
  7028. record_date := this.GetString("record_time")
  7029. patient_id, _ := this.GetInt64("patient_id", 0)
  7030. p_type, _ := this.GetInt64("p_type", 0)
  7031. timeLayout := "2006-01-02"
  7032. loc, _ := time.LoadLocation("Local")
  7033. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7034. record_time := theAdviceRecordTime.Unix()
  7035. adminUserInfo := this.GetAdminUserInfo()
  7036. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7037. if err == nil {
  7038. if len(prescriptions) == 0 {
  7039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7040. return
  7041. } else {
  7042. this.ServeSuccessJSON(map[string]interface{}{
  7043. "prescriptions": prescriptions,
  7044. })
  7045. return
  7046. }
  7047. } else {
  7048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7049. return
  7050. }
  7051. }
  7052. func (this *HisApiController) GetCallHisPrescription() {
  7053. patient_id, _ := this.GetInt64("patient_id", 0)
  7054. timeLayout := "2006-01-02"
  7055. loc, _ := time.LoadLocation("Local")
  7056. start_time := this.GetString("start_time")
  7057. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7058. end_time := this.GetString("end_time")
  7059. p_type, _ := this.GetInt64("p_type")
  7060. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7061. adminUserInfo := this.GetAdminUserInfo()
  7062. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7063. if err == nil {
  7064. this.ServeSuccessJSON(map[string]interface{}{
  7065. "prescriptions": prescriptions,
  7066. })
  7067. return
  7068. } else {
  7069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7070. return
  7071. }
  7072. }
  7073. func (this *HisApiController) GetHisDayPrescription() {
  7074. timeLayout := "2006-01-02"
  7075. loc, _ := time.LoadLocation("Local")
  7076. start_time := this.GetString("start_time")
  7077. patient_id, _ := this.GetInt64("patient_id", 0)
  7078. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7079. end_time := this.GetString("end_time")
  7080. p_type, _ := this.GetInt64("p_type")
  7081. order_status, _ := this.GetInt64("type")
  7082. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7083. adminUserInfo := this.GetAdminUserInfo()
  7084. var dayHisPrescription []*models.HisPrescription
  7085. var err error
  7086. if order_status == 1 || order_status == 0 {
  7087. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7088. } else if order_status == 2 {
  7089. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7090. }
  7091. var settle_total float64
  7092. for _, item := range dayHisPrescription {
  7093. if len(item.HisPrescriptionProject) > 0 {
  7094. for _, subItem := range item.HisPrescriptionProject {
  7095. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7096. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7097. settle_total = settle_total + total
  7098. }
  7099. }
  7100. if len(item.HisDoctorAdviceInfo) > 0 {
  7101. for _, subItem := range item.HisDoctorAdviceInfo {
  7102. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7103. settle_total = settle_total + total
  7104. }
  7105. }
  7106. }
  7107. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7108. if err == nil {
  7109. this.ServeSuccessJSON(map[string]interface{}{
  7110. "day_prescription": dayHisPrescription,
  7111. "settle_total": settle_total,
  7112. })
  7113. return
  7114. } else {
  7115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7116. return
  7117. }
  7118. }
  7119. func (c *HisApiController) GetHisChargePatientList() {
  7120. record_date := c.GetString("record_date")
  7121. order_status, _ := c.GetInt64("type")
  7122. sch_type, _ := c.GetInt64("sch_type")
  7123. timeLayout := "2006-01-02"
  7124. loc, _ := time.LoadLocation("Local")
  7125. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7126. if err != nil {
  7127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7128. return
  7129. }
  7130. recordDateTime := theTime.Unix()
  7131. adminInfo := c.GetAdminUserInfo()
  7132. var tempPatients []*service.NewTempPatients
  7133. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7134. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7135. if order_status != 2 {
  7136. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7137. } else {
  7138. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7139. }
  7140. } else {
  7141. if order_status != 2 {
  7142. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7143. } else {
  7144. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7145. }
  7146. }
  7147. var patients []*service.NewTempPatients
  7148. var patients_two []*service.NewTempPatients
  7149. for _, item := range tempPatients {
  7150. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7151. //过滤掉没挂号的和没开处方的
  7152. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7153. patients = append(patients, item)
  7154. }
  7155. //过滤掉没挂号的
  7156. if len(item.HisPatient) > 0 {
  7157. patients_two = append(patients_two, item)
  7158. }
  7159. } else {
  7160. if len(item.HisPrescription) > 0 {
  7161. patients = append(patients, item)
  7162. }
  7163. }
  7164. }
  7165. c.ServeSuccessJSON(map[string]interface{}{
  7166. "list": patients,
  7167. "list_two": patients_two,
  7168. })
  7169. }
  7170. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7171. record_date := c.GetString("record_date")
  7172. timeLayout := "2006-01-02"
  7173. loc, _ := time.LoadLocation("Local")
  7174. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7175. if err != nil {
  7176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7177. return
  7178. }
  7179. recordDateTime := theTime.Unix()
  7180. adminUser := c.GetAdminUserInfo()
  7181. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7182. var patients []*service.Patients
  7183. for _, item := range tempPatients {
  7184. if item.HisPatient.ID == 0 {
  7185. patients = append(patients, item)
  7186. }
  7187. }
  7188. c.ServeSuccessJSON(map[string]interface{}{
  7189. "list": patients,
  7190. //"list_two": patients_two,
  7191. })
  7192. }
  7193. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7194. newArr = make([]*service.Patients, 0)
  7195. for i := 0; i < len(patient); i++ {
  7196. repeat := false
  7197. for j := i + 1; j < len(patient); j++ {
  7198. if patient[i].ID == patient[j].ID {
  7199. repeat = true
  7200. break
  7201. }
  7202. }
  7203. if !repeat {
  7204. newArr = append(newArr, patient[i])
  7205. }
  7206. }
  7207. return
  7208. }
  7209. func (c *HisApiController) GetHisChargePatientInfo() {
  7210. patient_id, _ := c.GetInt64("patient_id")
  7211. his_patient_id, _ := c.GetInt64("his_patient_id")
  7212. record_date := c.GetString("record_date")
  7213. //start_time := c.GetString("start_time")
  7214. //end_time := c.GetString("end_time")
  7215. order_status, _ := c.GetInt64("type", 0)
  7216. p_type, _ := c.GetInt64("p_type", 0)
  7217. order_id, _ := c.GetInt64("order_id", 0)
  7218. timeLayout := "2006-01-02"
  7219. loc, _ := time.LoadLocation("Local")
  7220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7221. if err != nil {
  7222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7223. return
  7224. }
  7225. recordDateTime := theTime.Unix()
  7226. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7227. //if err != nil {
  7228. //
  7229. //}
  7230. //startRecordDateTime := startTime.Unix()
  7231. //
  7232. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7233. //if err != nil {
  7234. //
  7235. //}
  7236. //endRecordDateTime := endTime.Unix()
  7237. admin := c.GetAdminUserInfo()
  7238. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7239. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7240. var prescriptions []*models.HisPrescription
  7241. //var unChargeMonthPrescriptions []*models.HisPrescription
  7242. order, _ := service.GetHisOrderByID(order_id)
  7243. if order_status == 1 || order_status == 0 {
  7244. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7245. } else if order_status == 2 {
  7246. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7247. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7248. }
  7249. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7250. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7251. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7252. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7253. //获取所有科室信息
  7254. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7255. c.ServeSuccessJSON(map[string]interface{}{
  7256. "his_info": his_patient_info,
  7257. "xt_info": xt_patient_info,
  7258. "prescription": prescriptions,
  7259. "case_history": case_history,
  7260. "info": patientPrescriptionInfo,
  7261. "last_info": lastPatientPrescriptionInfo,
  7262. "order": order,
  7263. "doctors": doctors,
  7264. "department": department,
  7265. })
  7266. return
  7267. }
  7268. func (c *HisApiController) GetAllOrderDetail() {
  7269. order_id, _ := c.GetInt64("id", 0)
  7270. order, _ := service.GetHisOrderByID(order_id)
  7271. if order.ID == 0 {
  7272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7273. return
  7274. }
  7275. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7276. org_id := c.GetAdminUserInfo().CurrentOrgId
  7277. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7278. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7279. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7280. c.ServeSuccessJSON(map[string]interface{}{
  7281. "order": order,
  7282. "order_info": order_info,
  7283. "patient": patient,
  7284. "admin_info": adminInfo,
  7285. "hospital_record": record,
  7286. })
  7287. return
  7288. }
  7289. func (c *HisApiController) GetAllOrderDetailCollect() {
  7290. order_id, _ := c.GetInt64("id", 0)
  7291. order, _ := service.GetHisOrderByID(order_id)
  7292. if order.ID == 0 {
  7293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7294. return
  7295. }
  7296. org_id := c.GetAdminUserInfo().CurrentOrgId
  7297. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7298. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7299. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7300. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7301. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7302. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7303. var bedCostTotal float64 = 0 //床位总费
  7304. //var bedCostSelfTotal float64 = 0 //床位自费
  7305. var operationCostTotal float64 = 0 //手术费
  7306. //var operationCostSelfTotal float64 = 0 //手术费
  7307. var otherCostTotal float64 = 0 //其他费用
  7308. //var otherCostSelfTotal float64 = 0 //其他费用
  7309. var materialCostTotal float64 = 0 //材料费
  7310. //var materialCostSelfTotal float64 = 0 //材料费
  7311. var westernMedicineCostTotal float64 = 0 //西药费
  7312. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7313. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7314. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7315. var checkCostTotal float64 = 0 //检查费
  7316. //var checkCostSelfTotal float64 = 0 //检查费
  7317. var laboratoryCostTotal float64 = 0 //化验费
  7318. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7319. var treatCostTotal float64 = 0 //治疗费用
  7320. //var treatCostSelfTotal float64 = 0 //治疗费用
  7321. var zhenChaCostTotal float64 = 0 //其他费用
  7322. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7323. decimal.DivisionPrecision = 2
  7324. var BalanceAccountsType int64
  7325. if his.ID > 0 {
  7326. BalanceAccountsType = his.BalanceAccountsType
  7327. } else {
  7328. BalanceAccountsType = record.BalanceAccountsType
  7329. }
  7330. if BalanceAccountsType != 2 {
  7331. for _, item := range order_info {
  7332. if org_id == 10215 {
  7333. if item.MedChrgitmType == "01" { //床位费
  7334. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7336. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7337. }
  7338. if item.MedChrgitmType == "02" { //诊察费
  7339. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7340. //zhenChaCostSelfTotal = zhenChaCostTotal
  7341. }
  7342. if item.MedChrgitmType == "03" { //检查费
  7343. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7344. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7345. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7346. }
  7347. //if item.MedChrgitmType == "02" { //检查费
  7348. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7349. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7350. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7351. //}
  7352. if item.MedChrgitmType == "04" { //化验费
  7353. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7354. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7355. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7356. }
  7357. if item.MedChrgitmType == "05" { //治疗费
  7358. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7359. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7360. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7361. }
  7362. if item.MedChrgitmType == "06" { //手术费
  7363. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7364. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7365. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7366. }
  7367. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7368. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7369. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7370. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7371. }
  7372. if item.MedChrgitmType == "09" { //西药费
  7373. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7374. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7375. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7376. }
  7377. if item.MedChrgitmType == "11" { //中成费
  7378. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7379. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7380. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7381. }
  7382. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7383. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7384. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7385. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7386. }
  7387. } else if org_id == 10188 || org_id == 10217 {
  7388. if item.MedChrgitmType == "01" { //床位费
  7389. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7390. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7391. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7392. }
  7393. if item.MedChrgitmType == "02" { //诊察费
  7394. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7395. //zhenChaCostSelfTotal = zhenChaCostTotal
  7396. }
  7397. if item.MedChrgitmType == "03" { //检查费
  7398. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7399. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7400. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7401. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7402. }
  7403. //if item.MedChrgitmType == "02" { //检查费
  7404. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7405. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7406. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7407. //}
  7408. if item.MedChrgitmType == "04" { //化验费
  7409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7410. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7411. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7412. }
  7413. if item.MedChrgitmType == "05" { //治疗费
  7414. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7415. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7416. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7417. }
  7418. if item.MedChrgitmType == "06" { //手术费
  7419. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7420. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7421. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7422. }
  7423. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7424. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7425. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7426. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7427. }
  7428. if item.MedChrgitmType == "09" { //西药费
  7429. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7430. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7431. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7432. }
  7433. if item.MedChrgitmType == "11" { //中成费
  7434. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7435. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7436. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7437. }
  7438. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7439. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7440. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7441. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7442. }
  7443. } else {
  7444. if item.MedChrgitmType == "01" { //床位费
  7445. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7446. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7447. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7448. }
  7449. //if item.MedChrgitmType == "02" { //诊察费
  7450. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7451. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7452. //}
  7453. if item.MedChrgitmType == "03" { //检查费
  7454. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7455. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7456. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7457. }
  7458. //if item.MedChrgitmType == "02" { //检查费
  7459. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7460. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7461. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7462. //}
  7463. if item.MedChrgitmType == "04" { //化验费
  7464. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7465. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7466. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7467. }
  7468. if item.MedChrgitmType == "05" { //治疗费
  7469. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7470. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7471. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7472. }
  7473. if item.MedChrgitmType == "06" { //手术费
  7474. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7475. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7476. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7477. }
  7478. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7479. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7480. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7481. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7482. }
  7483. if item.MedChrgitmType == "09" { //西药费
  7484. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7485. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7486. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7487. }
  7488. if item.MedChrgitmType == "11" { //中成费
  7489. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7490. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7491. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7492. }
  7493. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7494. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7495. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7496. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7497. }
  7498. }
  7499. }
  7500. c.ServeSuccessJSON(map[string]interface{}{
  7501. "order": order,
  7502. "order_info": order_info,
  7503. "patient": patient,
  7504. "admin_info": adminInfo,
  7505. "his_hospital": record,
  7506. "bedCostTotal": bedCostTotal,
  7507. "operationCostTotal": operationCostTotal,
  7508. "otherCostTotal": otherCostTotal,
  7509. "materialCostTotal": materialCostTotal,
  7510. "westernMedicineCostTotal": westernMedicineCostTotal,
  7511. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7512. "checkCostTotal": checkCostTotal,
  7513. "zhenChaCostTotal": zhenChaCostTotal,
  7514. "laboratoryCostTotal": laboratoryCostTotal,
  7515. "treatCostTotal": treatCostTotal,
  7516. })
  7517. } else {
  7518. for _, item := range order_info {
  7519. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7520. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7521. item.MedChrgitmType = "09"
  7522. }
  7523. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7524. if item.HisPrescriptionProject.Type == 2 {
  7525. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7526. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7527. case 0:
  7528. item.MedChrgitmType = "0"
  7529. break
  7530. case 1:
  7531. item.MedChrgitmType = "14"
  7532. break
  7533. case 2:
  7534. item.MedChrgitmType = "05"
  7535. break
  7536. case 3:
  7537. item.MedChrgitmType = "03"
  7538. break
  7539. case 4:
  7540. item.MedChrgitmType = "03"
  7541. break
  7542. case 5:
  7543. item.MedChrgitmType = "08"
  7544. break
  7545. case 6:
  7546. item.MedChrgitmType = "14"
  7547. break
  7548. case 7:
  7549. item.MedChrgitmType = "14"
  7550. break
  7551. case 8:
  7552. item.MedChrgitmType = "03"
  7553. break
  7554. case 9:
  7555. item.MedChrgitmType = "14"
  7556. break
  7557. case 10:
  7558. item.MedChrgitmType = "14"
  7559. break
  7560. case 11:
  7561. item.MedChrgitmType = "06"
  7562. break
  7563. case 12:
  7564. item.MedChrgitmType = "12"
  7565. break
  7566. case 13:
  7567. item.MedChrgitmType = "01"
  7568. break
  7569. case 14:
  7570. item.MedChrgitmType = "04"
  7571. break
  7572. case 15:
  7573. item.MedChrgitmType = "14"
  7574. break
  7575. }
  7576. } else {
  7577. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7578. case 1:
  7579. item.MedChrgitmType = "14"
  7580. break
  7581. case 2:
  7582. item.MedChrgitmType = "05"
  7583. break
  7584. case 3:
  7585. item.MedChrgitmType = "04"
  7586. break
  7587. case 4:
  7588. item.MedChrgitmType = "14"
  7589. break
  7590. case 5:
  7591. item.MedChrgitmType = "08"
  7592. break
  7593. case 6:
  7594. item.MedChrgitmType = "14"
  7595. break
  7596. case 7:
  7597. item.MedChrgitmType = "14"
  7598. break
  7599. case 8:
  7600. item.MedChrgitmType = "03"
  7601. break
  7602. case 9:
  7603. item.MedChrgitmType = "14"
  7604. break
  7605. }
  7606. }
  7607. } else if item.HisPrescriptionProject.Type == 3 {
  7608. item.MedChrgitmType = "08"
  7609. }
  7610. }
  7611. }
  7612. for _, item := range order_info {
  7613. if org_id == 10215 {
  7614. if item.MedChrgitmType == "01" { //床位费
  7615. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7616. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7617. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7618. }
  7619. if item.MedChrgitmType == "02" { //诊察费
  7620. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7621. //zhenChaCostSelfTotal = zhenChaCostTotal
  7622. }
  7623. if item.MedChrgitmType == "03" { //检查费
  7624. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7625. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7626. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7627. }
  7628. //if item.MedChrgitmType == "02" { //检查费
  7629. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7630. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7631. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7632. //}
  7633. if item.MedChrgitmType == "04" { //化验费
  7634. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7635. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7636. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7637. }
  7638. if item.MedChrgitmType == "05" { //治疗费
  7639. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7640. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7641. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7642. }
  7643. if item.MedChrgitmType == "06" { //手术费
  7644. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7645. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7646. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7647. }
  7648. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7649. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7650. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7651. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7652. }
  7653. if item.MedChrgitmType == "09" { //西药费
  7654. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7655. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7656. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7657. }
  7658. if item.MedChrgitmType == "11" { //中成费
  7659. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7660. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7661. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7662. }
  7663. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7664. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7665. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7666. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7667. }
  7668. } else {
  7669. if item.MedChrgitmType == "01" { //床位费
  7670. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7671. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7672. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7673. }
  7674. //if item.MedChrgitmType == "02" { //诊察费
  7675. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7676. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7677. //}
  7678. if item.MedChrgitmType == "03" { //检查费
  7679. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7680. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7681. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7682. }
  7683. //if item.MedChrgitmType == "02" { //检查费
  7684. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7685. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7686. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7687. //}
  7688. if item.MedChrgitmType == "04" { //化验费
  7689. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7690. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7691. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7692. }
  7693. if item.MedChrgitmType == "05" { //治疗费
  7694. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7695. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7696. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7697. }
  7698. if item.MedChrgitmType == "06" { //手术费
  7699. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7700. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7701. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7702. }
  7703. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7704. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7705. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7706. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7707. }
  7708. if item.MedChrgitmType == "09" { //西药费
  7709. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7710. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7711. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7712. }
  7713. if item.MedChrgitmType == "11" { //中成费
  7714. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7715. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7716. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7717. }
  7718. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7719. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7720. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7721. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7722. }
  7723. }
  7724. }
  7725. c.ServeSuccessJSON(map[string]interface{}{
  7726. "order": order,
  7727. "order_info": order_info,
  7728. "patient": patient,
  7729. "admin_info": adminInfo,
  7730. "his_hospital": record,
  7731. "bedCostTotal": bedCostTotal,
  7732. "operationCostTotal": operationCostTotal,
  7733. "otherCostTotal": otherCostTotal,
  7734. "materialCostTotal": materialCostTotal,
  7735. "westernMedicineCostTotal": westernMedicineCostTotal,
  7736. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7737. "checkCostTotal": checkCostTotal,
  7738. "zhenChaCostTotal": zhenChaCostTotal,
  7739. "laboratoryCostTotal": laboratoryCostTotal,
  7740. "treatCostTotal": treatCostTotal,
  7741. })
  7742. }
  7743. }
  7744. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7745. page, _ := c.GetInt64("page")
  7746. limit, _ := c.GetInt64("limit")
  7747. keywords := c.GetString("keywords")
  7748. start_time := c.GetString("start_time")
  7749. end_time := c.GetString("end_time")
  7750. //clr_type := c.GetString("clr_type")
  7751. insutype := c.GetString("insutype")
  7752. timeLayout := "2006-01-02"
  7753. loc, _ := time.LoadLocation("Local")
  7754. var theStartTIme int64
  7755. if len(start_time) > 0 {
  7756. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7757. theStartTIme = theTime.Unix()
  7758. }
  7759. var theEndtTIme int64
  7760. if len(end_time) > 0 {
  7761. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7762. theEndtTIme = theTime.Unix()
  7763. }
  7764. if page <= 0 {
  7765. page = 1
  7766. }
  7767. if limit <= 0 {
  7768. limit = 10
  7769. }
  7770. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7771. c.ServeSuccessJSON(map[string]interface{}{
  7772. "total": total,
  7773. "list": list,
  7774. })
  7775. return
  7776. }
  7777. func (c *HisApiController) GetPutOnRecordList() {
  7778. page, _ := c.GetInt64("page")
  7779. limit, _ := c.GetInt64("limit")
  7780. keywords := c.GetString("keywords")
  7781. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7782. if page <= 0 {
  7783. page = 1
  7784. }
  7785. if limit <= 0 {
  7786. limit = 10
  7787. }
  7788. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7789. c.ServeSuccessJSON(map[string]interface{}{
  7790. "total": total,
  7791. "list": list,
  7792. })
  7793. return
  7794. }
  7795. func (c *HisApiController) GetCompareData() {
  7796. start_time := c.GetString("start_time")
  7797. end_time := c.GetString("end_time")
  7798. insutype := c.GetString("insutype")
  7799. clr_type := c.GetString("clr_type")
  7800. timeLayout := "2006-01-02"
  7801. loc, _ := time.LoadLocation("Local")
  7802. var theStartTIme int64
  7803. if len(start_time) > 0 {
  7804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7805. if err != nil {
  7806. theStartTIme = 0
  7807. }
  7808. theStartTIme = theTime.Unix()
  7809. }
  7810. var theEndtTIme int64
  7811. if len(end_time) > 0 {
  7812. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7813. if err != nil {
  7814. theEndtTIme = 0
  7815. }
  7816. theEndtTIme = theTime.Unix()
  7817. }
  7818. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7819. fmt.Println(err)
  7820. if err == nil {
  7821. c.ServeSuccessJSON(map[string]interface{}{
  7822. "list": formData,
  7823. })
  7824. } else {
  7825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7826. return
  7827. }
  7828. }
  7829. func (c *HisApiController) GetFaPiaoData() {
  7830. order_id, _ := c.GetInt64("order_id")
  7831. patient_id, _ := c.GetInt64("patient_id")
  7832. //number := c.GetString("number")
  7833. adminUser := c.GetAdminUserInfo()
  7834. order, _ := service.GetHisOrderByID(order_id)
  7835. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7836. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7837. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7838. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7839. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7840. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7841. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7842. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7843. var bedCostTotal float64 = 0 //床位总费
  7844. var bedCostSelfTotal float64 = 0 //床位自费
  7845. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7846. var operationCostTotal float64 = 0 //手术费
  7847. var operationCostSelfTotal float64 = 0 //手术费
  7848. var operationCostPartSelfTotal float64 = 0 //手术费
  7849. var otherCostTotal float64 = 0 //其他费用
  7850. var otherCostSelfTotal float64 = 0 //其他费用
  7851. var otherCostPartSelfTotal float64 = 0 //其他费用
  7852. var materialCostTotal float64 = 0 //材料费
  7853. var materialCostSelfTotal float64 = 0 //材料费
  7854. var materialCostPartSelfTotal float64 = 0 //材料费
  7855. var westernMedicineCostTotal float64 = 0 //西药费
  7856. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7857. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7858. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7859. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7860. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7861. var checkCostTotal float64 = 0 //检查费
  7862. var checkCostSelfTotal float64 = 0 //检查费
  7863. var checkCostPartSelfTotal float64 = 0 //检查费
  7864. var hiliCostTotal float64 = 0 //护理费
  7865. var hiliCostSelfTotal float64 = 0 //护理费
  7866. var hiliCostPartSelfTotal float64 = 0 //护理费
  7867. var laboratoryCostTotal float64 = 0 //化验费
  7868. var laboratoryCostSelfTotal float64 = 0 //化验费
  7869. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7870. var treatCostTotal float64 = 0 //治疗费用
  7871. var treatCostSelfTotal float64 = 0 //治疗费用
  7872. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7873. var zhenChaCostTotal float64 = 0 //其他费用
  7874. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7875. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7876. decimal.DivisionPrecision = 2
  7877. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7878. var balanceAccountsType int64
  7879. if his.ID > 0 {
  7880. balanceAccountsType = his.BalanceAccountsType
  7881. } else {
  7882. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7883. }
  7884. if balanceAccountsType == 2 {
  7885. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7886. for _, item := range orderInfos_two {
  7887. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7888. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7889. item.MedChrgitmType = "09"
  7890. }
  7891. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7892. if item.HisPrescriptionProject.Type == 2 {
  7893. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7894. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7895. case 0:
  7896. item.MedChrgitmType = "0"
  7897. break
  7898. case 1:
  7899. item.MedChrgitmType = "14"
  7900. break
  7901. case 2:
  7902. item.MedChrgitmType = "05"
  7903. break
  7904. case 3:
  7905. item.MedChrgitmType = "03"
  7906. break
  7907. case 4:
  7908. item.MedChrgitmType = "03"
  7909. break
  7910. case 5:
  7911. item.MedChrgitmType = "08"
  7912. break
  7913. case 6:
  7914. item.MedChrgitmType = "14"
  7915. break
  7916. case 7:
  7917. item.MedChrgitmType = "14"
  7918. break
  7919. case 8:
  7920. item.MedChrgitmType = "03"
  7921. break
  7922. case 9:
  7923. item.MedChrgitmType = "14"
  7924. break
  7925. case 10:
  7926. item.MedChrgitmType = "14"
  7927. break
  7928. case 11:
  7929. item.MedChrgitmType = "06"
  7930. break
  7931. case 12:
  7932. item.MedChrgitmType = "12"
  7933. break
  7934. case 13:
  7935. item.MedChrgitmType = "01"
  7936. break
  7937. case 14:
  7938. item.MedChrgitmType = "04"
  7939. break
  7940. case 15:
  7941. item.MedChrgitmType = "02"
  7942. break
  7943. }
  7944. } else {
  7945. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7946. case 1:
  7947. item.MedChrgitmType = "14"
  7948. break
  7949. case 2:
  7950. item.MedChrgitmType = "05"
  7951. break
  7952. case 3:
  7953. item.MedChrgitmType = "03"
  7954. break
  7955. case 4:
  7956. item.MedChrgitmType = "03"
  7957. break
  7958. case 5:
  7959. item.MedChrgitmType = "08"
  7960. break
  7961. case 6:
  7962. item.MedChrgitmType = "14"
  7963. break
  7964. case 7:
  7965. item.MedChrgitmType = "14"
  7966. break
  7967. case 8:
  7968. item.MedChrgitmType = "03"
  7969. break
  7970. case 9:
  7971. item.MedChrgitmType = "14"
  7972. break
  7973. }
  7974. }
  7975. } else if item.HisPrescriptionProject.Type == 3 {
  7976. item.MedChrgitmType = "08"
  7977. }
  7978. }
  7979. }
  7980. for _, item := range orderInfos_two {
  7981. fmt.Println(item.MedChrgitmType)
  7982. if item.MedChrgitmType == "07" { //床位费
  7983. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7984. hiliCostSelfTotal = hiliCostTotal
  7985. }
  7986. if item.MedChrgitmType == "01" { //床位费
  7987. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7988. bedCostSelfTotal = bedCostTotal
  7989. }
  7990. if item.MedChrgitmType == "02" { //诊察费
  7991. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7992. zhenChaCostSelfTotal = zhenChaCostTotal
  7993. }
  7994. if item.MedChrgitmType == "03" { //检查费
  7995. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7996. checkCostSelfTotal = checkCostTotal
  7997. }
  7998. if item.MedChrgitmType == "04" { //化验费
  7999. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8000. laboratoryCostSelfTotal = laboratoryCostTotal
  8001. }
  8002. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8003. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8004. treatCostSelfTotal = treatCostTotal
  8005. }
  8006. if item.MedChrgitmType == "06" { //手术费
  8007. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8008. operationCostSelfTotal = treatCostTotal
  8009. }
  8010. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8011. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8012. materialCostSelfTotal = materialCostTotal
  8013. }
  8014. if item.MedChrgitmType == "09" { //西药费
  8015. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8016. westernMedicineCostSelfTotal = westernMedicineCostTotal
  8017. }
  8018. if item.MedChrgitmType == "11" { //中成费
  8019. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8020. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8021. }
  8022. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8023. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8024. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8025. otherCostSelfTotal = otherCostTotal
  8026. }
  8027. } else {
  8028. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8029. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8030. otherCostSelfTotal = otherCostTotal
  8031. }
  8032. }
  8033. }
  8034. } else {
  8035. for _, item := range orderInfos {
  8036. if item.MedChrgitmType == "01" { //床位费
  8037. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8038. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8039. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8040. }
  8041. if item.MedChrgitmType == "02" { //诊察费
  8042. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8043. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8044. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8045. }
  8046. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8047. if item.MedChrgitmType == "03" { //检查费
  8048. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8049. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8050. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8051. }
  8052. } else {
  8053. if item.MedChrgitmType == "03" { //检查费
  8054. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8055. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8056. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8057. }
  8058. }
  8059. if item.MedChrgitmType == "04" { //化验费
  8060. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8061. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8062. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8063. }
  8064. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8065. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8066. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8067. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8068. }
  8069. if item.MedChrgitmType == "06" { //手术费
  8070. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8071. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8072. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8073. }
  8074. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8075. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8076. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8077. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8078. }
  8079. if item.MedChrgitmType == "07" { //西药费
  8080. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8081. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8082. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8083. }
  8084. if item.MedChrgitmType == "09" { //西药费
  8085. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8086. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8087. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8088. }
  8089. if item.MedChrgitmType == "11" { //中成费
  8090. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8091. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8092. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8093. }
  8094. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8095. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8096. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8097. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8098. }
  8099. }
  8100. }
  8101. timeLayout := "2006-01-02"
  8102. loc, _ := time.LoadLocation("Local")
  8103. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8104. if err != nil {
  8105. }
  8106. startRecordDateTime := startTime.Unix()
  8107. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8108. if err != nil {
  8109. }
  8110. endRecordDateTime := endTime.Unix()
  8111. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8112. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8113. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8114. c.ServeSuccessJSON(map[string]interface{}{
  8115. "order_number": order.Number, //业务流水号
  8116. "id_card_no": his.IdCardNo, //社会保障号
  8117. "patient": patient,
  8118. "department_name": department.Name, //科室
  8119. "number": his.Number, //门诊号
  8120. "date": order.SettleAccountsDate, //结算日期
  8121. "name": order.PsnName, //姓名
  8122. "gender": patient.Gender, //性别
  8123. "psn_cash_money": order.PsnCashPay, //个人支付
  8124. "pay_way": "门诊", //结算方式
  8125. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8126. "admin_user_name": admin.UserName, //收款员
  8127. "order": order,
  8128. "order_info": orderInfos_two,
  8129. "his": his,
  8130. "bedCostTotal": bedCostTotal,
  8131. "bedCostSelfTotal": bedCostSelfTotal,
  8132. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8133. "operationCostTotal": operationCostTotal,
  8134. "operationCostSelfTotal": operationCostSelfTotal,
  8135. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8136. "otherCostTotal": otherCostTotal,
  8137. "otherCostSelfTotal": otherCostSelfTotal,
  8138. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8139. "materialCostTotal": materialCostTotal,
  8140. "materialCostSelfTotal": materialCostSelfTotal,
  8141. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8142. "westernMedicineCostTotal": westernMedicineCostTotal,
  8143. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8144. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8145. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8146. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8147. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8148. "checkCostTotal": checkCostTotal,
  8149. "checkCostSelfTotal": checkCostSelfTotal,
  8150. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8151. "laboratoryCostTotal": laboratoryCostTotal,
  8152. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8153. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8154. "treatCostTotal": treatCostTotal,
  8155. "treatCostSelfTotal": treatCostSelfTotal,
  8156. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8157. "zhenChaCostTotal": zhenChaCostTotal,
  8158. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8159. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8160. "his_hospital_record": his_hospital_record,
  8161. "pre_pay_money": pre_pay_money,
  8162. "refund_sum": sum,
  8163. "doctor_info": doctor_info,
  8164. "hiliCostTotal": hiliCostTotal,
  8165. "hiliCostSelfTotal": hiliCostSelfTotal,
  8166. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8167. })
  8168. }
  8169. //func (c *HisApiController) GetFaPiaoDatas() {
  8170. // order_ids := c.GetString("order_ids")
  8171. // patient_id, _ := c.GetInt64("patient_id")
  8172. // adminUser := c.GetAdminUserInfo()
  8173. //
  8174. // orders := strings.Split(order_ids, ",")
  8175. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8176. //
  8177. // for _, item := range orders {
  8178. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8179. // order, _ := service.GetHisOrderByID(order_id)
  8180. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8181. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8182. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8183. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8184. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8185. //
  8186. // }
  8187. //
  8188. // var bedCostTotal float64 = 0 //床位总费
  8189. // var bedCostSelfTotal float64 = 0 //床位自费
  8190. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8191. //
  8192. // var operationCostTotal float64 = 0 //手术费
  8193. // var operationCostSelfTotal float64 = 0 //手术费
  8194. // var operationCostPartSelfTotal float64 = 0 //手术费
  8195. //
  8196. // var otherCostTotal float64 = 0 //其他费用
  8197. // var otherCostSelfTotal float64 = 0 //其他费用
  8198. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8199. //
  8200. // var materialCostTotal float64 = 0 //材料费
  8201. // var materialCostSelfTotal float64 = 0 //材料费
  8202. // var materialCostPartSelfTotal float64 = 0 //材料费
  8203. //
  8204. // var westernMedicineCostTotal float64 = 0 //西药费
  8205. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8206. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8207. //
  8208. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8209. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8210. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8211. //
  8212. // var checkCostTotal float64 = 0 //检查费
  8213. // var checkCostSelfTotal float64 = 0 //检查费
  8214. // var checkCostPartSelfTotal float64 = 0 //检查费
  8215. //
  8216. // var laboratoryCostTotal float64 = 0 //化验费
  8217. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8218. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8219. //
  8220. // var treatCostTotal float64 = 0 //治疗费用
  8221. // var treatCostSelfTotal float64 = 0 //治疗费用
  8222. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8223. //
  8224. // var zhenChaCostTotal float64 = 0 //其他费用
  8225. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8226. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8227. //
  8228. // decimal.DivisionPrecision = 2
  8229. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8230. //
  8231. // var balanceAccountsType int64
  8232. // if his.ID > 0 {
  8233. // balanceAccountsType = his.BalanceAccountsType
  8234. // } else {
  8235. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8236. // }
  8237. // if balanceAccountsType == 2 {
  8238. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8239. // for _, item := range orderInfos_two {
  8240. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8241. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8242. // item.MedChrgitmType = "09"
  8243. // }
  8244. //
  8245. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8246. // if item.HisPrescriptionProject.Type == 2 {
  8247. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8248. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8249. // case 0:
  8250. // item.MedChrgitmType = "0"
  8251. // break
  8252. // case 1:
  8253. // item.MedChrgitmType = "14"
  8254. // break
  8255. // case 2:
  8256. // item.MedChrgitmType = "05"
  8257. //
  8258. // break
  8259. // case 3:
  8260. // item.MedChrgitmType = "03"
  8261. //
  8262. // break
  8263. // case 4:
  8264. // item.MedChrgitmType = "03"
  8265. //
  8266. // break
  8267. // case 5:
  8268. // item.MedChrgitmType = "08"
  8269. //
  8270. // break
  8271. // case 6:
  8272. // item.MedChrgitmType = "14"
  8273. //
  8274. // break
  8275. // case 7:
  8276. // item.MedChrgitmType = "14"
  8277. //
  8278. // break
  8279. // case 8:
  8280. // item.MedChrgitmType = "03"
  8281. // break
  8282. // case 9:
  8283. // item.MedChrgitmType = "14"
  8284. // break
  8285. // case 10:
  8286. // item.MedChrgitmType = "14"
  8287. // break
  8288. // case 11:
  8289. // item.MedChrgitmType = "06"
  8290. // break
  8291. // case 12:
  8292. // item.MedChrgitmType = "12"
  8293. // break
  8294. // case 13:
  8295. // item.MedChrgitmType = "01"
  8296. // break
  8297. // case 14:
  8298. // item.MedChrgitmType = "04"
  8299. // break
  8300. // case 15:
  8301. // item.MedChrgitmType = "02"
  8302. // break
  8303. //
  8304. // }
  8305. //
  8306. // } else {
  8307. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8308. //
  8309. // case 1:
  8310. // item.MedChrgitmType = "14"
  8311. // break
  8312. // case 2:
  8313. // item.MedChrgitmType = "05"
  8314. //
  8315. // break
  8316. // case 3:
  8317. // item.MedChrgitmType = "03"
  8318. //
  8319. // break
  8320. // case 4:
  8321. // item.MedChrgitmType = "03"
  8322. //
  8323. // break
  8324. // case 5:
  8325. // item.MedChrgitmType = "08"
  8326. //
  8327. // break
  8328. // case 6:
  8329. // item.MedChrgitmType = "14"
  8330. //
  8331. // break
  8332. // case 7:
  8333. // item.MedChrgitmType = "14"
  8334. //
  8335. // break
  8336. // case 8:
  8337. // item.MedChrgitmType = "03"
  8338. // break
  8339. // case 9:
  8340. // item.MedChrgitmType = "14"
  8341. // break
  8342. //
  8343. // }
  8344. //
  8345. // }
  8346. //
  8347. // } else if item.HisPrescriptionProject.Type == 3 {
  8348. // item.MedChrgitmType = "08"
  8349. // }
  8350. // }
  8351. // }
  8352. //
  8353. // for _, item := range orderInfos_two {
  8354. // fmt.Println(item.MedChrgitmType)
  8355. // if item.MedChrgitmType == "01" { //床位费
  8356. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8357. // bedCostSelfTotal = bedCostTotal
  8358. // }
  8359. //
  8360. // if item.MedChrgitmType == "02" { //诊察费
  8361. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8362. // zhenChaCostSelfTotal = zhenChaCostTotal
  8363. // }
  8364. //
  8365. // if item.MedChrgitmType == "03" { //检查费
  8366. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8367. // checkCostSelfTotal = checkCostTotal
  8368. // }
  8369. //
  8370. // if item.MedChrgitmType == "04" { //化验费
  8371. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8372. // laboratoryCostSelfTotal = laboratoryCostTotal
  8373. // }
  8374. //
  8375. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8376. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8377. // treatCostSelfTotal = treatCostTotal
  8378. // }
  8379. //
  8380. // if item.MedChrgitmType == "06" { //手术费
  8381. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8382. // operationCostSelfTotal = treatCostTotal
  8383. // }
  8384. //
  8385. // if item.MedChrgitmType == "08" { //材料费
  8386. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8387. // materialCostSelfTotal = materialCostTotal
  8388. // }
  8389. //
  8390. // if item.MedChrgitmType == "09" { //西药费
  8391. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8392. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8393. // }
  8394. //
  8395. // if item.MedChrgitmType == "11" { //中成费
  8396. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8397. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8398. // }
  8399. //
  8400. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8401. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8402. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8403. // otherCostSelfTotal = otherCostTotal
  8404. // }
  8405. // } else {
  8406. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8407. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8408. // otherCostSelfTotal = otherCostTotal
  8409. // }
  8410. //
  8411. // }
  8412. //
  8413. // }
  8414. //
  8415. // } else {
  8416. // for _, item := range orderInfos {
  8417. // if item.MedChrgitmType == "01" { //床位费
  8418. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8419. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8420. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8421. // }
  8422. //
  8423. // if item.MedChrgitmType == "02" { //诊察费
  8424. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8425. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8426. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8427. // }
  8428. //
  8429. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8430. // if item.MedChrgitmType == "03" { //检查费
  8431. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8432. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8433. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8434. //
  8435. // }
  8436. // } else {
  8437. // if item.MedChrgitmType == "03" { //检查费
  8438. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8439. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8440. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8441. // }
  8442. //
  8443. // }
  8444. //
  8445. // if item.MedChrgitmType == "04" { //化验费
  8446. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8447. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8448. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8449. //
  8450. // }
  8451. //
  8452. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8453. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8454. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8455. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8456. //
  8457. // }
  8458. //
  8459. // if item.MedChrgitmType == "06" { //手术费
  8460. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8461. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8462. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8463. // }
  8464. //
  8465. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8466. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8467. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8468. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8469. // }
  8470. //
  8471. // if item.MedChrgitmType == "09" { //西药费
  8472. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8473. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8474. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8475. // }
  8476. //
  8477. // if item.MedChrgitmType == "11" { //中成费
  8478. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8479. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8480. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8481. // }
  8482. //
  8483. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8484. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8485. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8486. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8487. // }
  8488. //
  8489. // }
  8490. // }
  8491. // timeLayout := "2006-01-02"
  8492. // loc, _ := time.LoadLocation("Local")
  8493. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8494. // if err != nil {
  8495. // }
  8496. // startRecordDateTime := startTime.Unix()
  8497. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8498. // if err != nil {
  8499. // }
  8500. // endRecordDateTime := endTime.Unix()
  8501. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8502. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8503. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8504. //
  8505. // c.ServeSuccessJSON(map[string]interface{}{
  8506. // "order_number": order.Number, //业务流水号
  8507. // "id_card_no": his.IdCardNo, //社会保障号
  8508. // "department_name": department.Name, //科室
  8509. // "number": his.Number, //门诊号
  8510. // "date": order.SettleAccountsDate, //结算日期
  8511. // "name": order.PsnName, //姓名
  8512. // "gender": patient.Gender, //性别
  8513. // "psn_cash_money": order.PsnCashPay, //个人支付
  8514. // "pay_way": "门诊", //结算方式
  8515. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8516. // "admin_user_name": admin.UserName, //收款员
  8517. // "order": order,
  8518. // "order_info": orderInfos_two,
  8519. // "his": his,
  8520. // "bedCostTotal": bedCostTotal,
  8521. // "bedCostSelfTotal": bedCostSelfTotal,
  8522. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8523. // "operationCostTotal": operationCostTotal,
  8524. // "operationCostSelfTotal": operationCostSelfTotal,
  8525. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8526. // "otherCostTotal": otherCostTotal,
  8527. // "otherCostSelfTotal": otherCostSelfTotal,
  8528. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8529. // "materialCostTotal": materialCostTotal,
  8530. // "materialCostSelfTotal": materialCostSelfTotal,
  8531. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8532. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8533. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8534. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8535. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8536. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8537. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8538. // "checkCostTotal": checkCostTotal,
  8539. // "checkCostSelfTotal": checkCostSelfTotal,
  8540. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8541. // "laboratoryCostTotal": laboratoryCostTotal,
  8542. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8543. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8544. // "treatCostTotal": treatCostTotal,
  8545. // "treatCostSelfTotal": treatCostSelfTotal,
  8546. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8547. // "zhenChaCostTotal": zhenChaCostTotal,
  8548. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8549. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8550. // "his_hospital_record": his_hospital_record,
  8551. // "pre_pay_money": pre_pay_money,
  8552. // "refund_sum": sum,
  8553. // })
  8554. //
  8555. //}
  8556. func (this *HisApiController) GetIncomeStatisticsData() {
  8557. start_time := this.GetString("start_time")
  8558. end_time := this.GetString("end_time")
  8559. key_words := this.GetString("key_words")
  8560. limit, _ := this.GetInt64("limit")
  8561. page, _ := this.GetInt64("page")
  8562. if page <= 0 {
  8563. page = 1
  8564. }
  8565. if limit <= 0 {
  8566. limit = 10
  8567. }
  8568. statistics_type, _ := this.GetInt64("statistics_type")
  8569. admin := this.GetAdminUserInfo()
  8570. timeLayout := "2006-01-02"
  8571. loc, _ := time.LoadLocation("Local")
  8572. var theStartTIme int64
  8573. if len(start_time) > 0 {
  8574. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8575. if err != nil {
  8576. theStartTIme = 0
  8577. }
  8578. theStartTIme = theTime.Unix()
  8579. }
  8580. var theEndtTIme int64
  8581. if len(end_time) > 0 {
  8582. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8583. if err != nil {
  8584. theEndtTIme = 0
  8585. }
  8586. theEndtTIme = theTime.Unix()
  8587. }
  8588. if statistics_type == 1 {
  8589. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8590. this.ServeSuccessJSON(map[string]interface{}{
  8591. "list": list,
  8592. "total": total,
  8593. })
  8594. } else {
  8595. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8596. this.ServeSuccessJSON(map[string]interface{}{
  8597. "list": list,
  8598. "total": total,
  8599. })
  8600. }
  8601. }
  8602. func (c *HisApiController) PostProjectInformation() {
  8603. adminUser := c.GetAdminUserInfo()
  8604. orgId := adminUser.CurrentOrgId
  8605. dataBody := make(map[string]interface{}, 0)
  8606. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8607. if err != nil {
  8608. utils.ErrorLog(err.Error())
  8609. return
  8610. }
  8611. utils.ErrorLog("%v", dataBody)
  8612. var projectList []*models.HisProject
  8613. var total_goods []interface{}
  8614. tempProjects := dataBody["projects"].([]interface{})
  8615. total_goods = tempProjects
  8616. for index, projectMap := range tempProjects {
  8617. projectM := projectMap.(map[string]interface{})
  8618. var project models.HisProject
  8619. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8620. utils.ErrorLog("project_name")
  8621. return
  8622. }
  8623. project_name, _ := projectM["project_name"].(string)
  8624. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8625. err_log := models.ExportErrLog{
  8626. LogType: 6,
  8627. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8628. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8629. Status: 1,
  8630. CreateTime: time.Now().Unix(),
  8631. UpdateTime: time.Now().Unix(),
  8632. ExportTime: time.Now().Unix(),
  8633. }
  8634. service.CreateExportErrLog(&err_log)
  8635. continue
  8636. }
  8637. project.ProjectName = project_name
  8638. prices := projectM["price"].(string)
  8639. price, _ := strconv.ParseFloat(prices, 64)
  8640. if price <= 0 { //名字为空则生成一条导入错误日志
  8641. err_log := models.ExportErrLog{
  8642. LogType: 6,
  8643. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8644. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8645. Status: 1,
  8646. CreateTime: time.Now().Unix(),
  8647. UpdateTime: time.Now().Unix(),
  8648. ExportTime: time.Now().Unix(),
  8649. }
  8650. service.CreateExportErrLog(&err_log)
  8651. continue
  8652. }
  8653. project.Price = price
  8654. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8655. utils.ErrorLog("unit_id")
  8656. return
  8657. }
  8658. unit := projectM["unit"].(string)
  8659. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8660. err_log := models.ExportErrLog{
  8661. LogType: 6,
  8662. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8663. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8664. Status: 1,
  8665. CreateTime: time.Now().Unix(),
  8666. UpdateTime: time.Now().Unix(),
  8667. ExportTime: time.Now().Unix(),
  8668. }
  8669. service.CreateExportErrLog(&err_log)
  8670. continue
  8671. }
  8672. project.Unit = unit
  8673. cost_classify := projectM["cost_classify"].(string)
  8674. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8675. err_log := models.ExportErrLog{
  8676. LogType: 6,
  8677. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8678. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8679. Status: 1,
  8680. CreateTime: time.Now().Unix(),
  8681. UpdateTime: time.Now().Unix(),
  8682. ExportTime: time.Now().Unix(),
  8683. }
  8684. service.CreateExportErrLog(&err_log)
  8685. continue
  8686. }
  8687. var costClassify = "费用类别"
  8688. var cost_classify_id int64
  8689. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8690. if len(cost_classify) != 0 {
  8691. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8692. if errcode == gorm.ErrRecordNotFound {
  8693. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8694. dataconfig := models.DictDataconfig{
  8695. ParentId: costClassifyConfig.ID,
  8696. Module: "system",
  8697. OrgId: orgId,
  8698. Name: cost_classify,
  8699. FieldName: "",
  8700. Value: costConfig.Value + 1,
  8701. CreatedTime: "",
  8702. UpdatedTime: "",
  8703. CreateUserId: adminUser.AdminUser.Id,
  8704. Status: 1,
  8705. Remark: "",
  8706. DeleteIdSystem: 0,
  8707. Title: "",
  8708. Content: "",
  8709. Order: 0,
  8710. Code: "",
  8711. }
  8712. service.CreatedDicConfig(&dataconfig)
  8713. }
  8714. }
  8715. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8716. for _, it := range costClassList {
  8717. if cost_classify == it.Name {
  8718. cost_classify_id = int64(it.Value)
  8719. }
  8720. }
  8721. project.CostClassify = cost_classify_id
  8722. executive_section := projectM["executive_section"].(string)
  8723. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8724. err_log := models.ExportErrLog{
  8725. LogType: 6,
  8726. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8727. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8728. Status: 1,
  8729. CreateTime: time.Now().Unix(),
  8730. UpdateTime: time.Now().Unix(),
  8731. ExportTime: time.Now().Unix(),
  8732. }
  8733. service.CreateExportErrLog(&err_log)
  8734. continue
  8735. }
  8736. if len(executive_section) != 0 {
  8737. //查找科室是否有内容
  8738. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8739. if errcodedepart == gorm.ErrRecordNotFound {
  8740. department := models.XtHisDepartment{
  8741. Name: executive_section,
  8742. Status: 1,
  8743. UserOrgId: adminUser.CurrentOrgId,
  8744. CreatedTime: time.Now().Unix(),
  8745. }
  8746. service.CreateDePartment(&department)
  8747. }
  8748. }
  8749. var executive_section_id int64
  8750. departMentList, _ := service.GetAllDepartMent(orgId)
  8751. for _, it := range departMentList {
  8752. if executive_section == it.Name {
  8753. executive_section_id = it.ID
  8754. }
  8755. }
  8756. project.ExecutiveSection = executive_section_id
  8757. medical_coverage := projectM["medical_coverage"].(string)
  8758. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8759. err_log := models.ExportErrLog{
  8760. LogType: 6,
  8761. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8762. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8763. Status: 1,
  8764. CreateTime: time.Now().Unix(),
  8765. UpdateTime: time.Now().Unix(),
  8766. ExportTime: time.Now().Unix(),
  8767. }
  8768. service.CreateExportErrLog(&err_log)
  8769. continue
  8770. }
  8771. var medicalCoverage = "医保等级"
  8772. var medical_coverage_id int64
  8773. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8774. if len(medical_coverage) != 0 {
  8775. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8776. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8777. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8778. dataconfig := models.DictDataconfig{
  8779. ParentId: medicalCoverageConfig.ID,
  8780. Module: "system",
  8781. OrgId: orgId,
  8782. Name: medical_coverage,
  8783. FieldName: "",
  8784. Value: medicalCoverageConfig.Value + 1,
  8785. CreatedTime: "",
  8786. UpdatedTime: "",
  8787. CreateUserId: adminUser.AdminUser.Id,
  8788. Status: 1,
  8789. Remark: "",
  8790. DeleteIdSystem: 0,
  8791. Title: "",
  8792. Content: "",
  8793. Order: 0,
  8794. Code: "",
  8795. }
  8796. service.CreatedDicConfig(&dataconfig)
  8797. }
  8798. }
  8799. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8800. for _, it := range medicalCoverageList {
  8801. if medical_coverage == it.Name {
  8802. medical_coverage_id = int64(it.Value)
  8803. }
  8804. }
  8805. project.MedicalCoverage = medical_coverage_id
  8806. pinyin := projectM["pinyin"].(string)
  8807. project.Pinyin = pinyin
  8808. wubi := projectM["wubi"].(string)
  8809. project.Wubi = wubi
  8810. statistical_classification := projectM["statistical_classification"].(string)
  8811. var statisticalClassification = "统计分类"
  8812. var statistical_classification_id int64
  8813. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8814. if len(statistical_classification) != 0 {
  8815. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8816. if classificationerrcodes == gorm.ErrRecordNotFound {
  8817. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8818. dataconfig := models.DictDataconfig{
  8819. ParentId: classiFication.ID,
  8820. Module: "system",
  8821. OrgId: orgId,
  8822. Name: statistical_classification,
  8823. FieldName: "",
  8824. Value: classiFicationConfig.Value + 1,
  8825. CreatedTime: "",
  8826. UpdatedTime: "",
  8827. CreateUserId: adminUser.AdminUser.Id,
  8828. Status: 1,
  8829. Remark: "",
  8830. DeleteIdSystem: 0,
  8831. Title: "",
  8832. Content: "",
  8833. Order: 0,
  8834. Code: "",
  8835. }
  8836. service.CreatedDicConfig(&dataconfig)
  8837. }
  8838. }
  8839. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8840. for _, it := range classiFicationList {
  8841. if statistical_classification == it.Name {
  8842. statistical_classification_id = int64(it.Value)
  8843. }
  8844. }
  8845. project.StatisticalClassification = statistical_classification_id
  8846. disease_directory := int64(projectM["disease_directory"].(float64))
  8847. project.DiseaseDirectory = disease_directory
  8848. is_record := int64(projectM["is_record"].(float64))
  8849. project.IsRecord = is_record
  8850. medical_code := projectM["medical_code"].(string)
  8851. project.MedicalCode = medical_code
  8852. tube_color := projectM["tube_color"].(string)
  8853. var tubeColor = "试管颜色"
  8854. var tube_color_id int64
  8855. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8856. if len(tube_color) != 0 {
  8857. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8858. if errcodetube == gorm.ErrRecordNotFound {
  8859. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8860. dataconfig := models.DictDataconfig{
  8861. ParentId: tubeColorConfig.ID,
  8862. Module: "system",
  8863. OrgId: orgId,
  8864. Name: tube_color,
  8865. FieldName: "",
  8866. Value: tubeConfig.Value + 1,
  8867. CreatedTime: "",
  8868. UpdatedTime: "",
  8869. CreateUserId: adminUser.AdminUser.Id,
  8870. Status: 1,
  8871. Remark: "",
  8872. DeleteIdSystem: 0,
  8873. Title: "",
  8874. Content: "",
  8875. Order: 0,
  8876. Code: "",
  8877. }
  8878. service.CreatedDicConfig(&dataconfig)
  8879. }
  8880. }
  8881. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8882. for _, it := range tubeColorList {
  8883. if tube_color == it.Name {
  8884. tube_color_id = int64(it.Value)
  8885. }
  8886. }
  8887. project.TubeColor = tube_color_id
  8888. single_dose := projectM["single_dose"].(string)
  8889. project.SingleDose = single_dose
  8890. execution_frequency := projectM["execution_frequency"].(string)
  8891. project.ExecutionFrequency = execution_frequency
  8892. delivery_way := projectM["delivery_way"].(string)
  8893. project.DeliveryWay = delivery_way
  8894. number_days := projectM["number_days"].(string)
  8895. project.NumberDays = number_days
  8896. total := projectM["total"].(string)
  8897. project.Total = total
  8898. medical_status := int64(projectM["medical_status"].(float64))
  8899. project.MedicalStatus = medical_status
  8900. category := int64(projectM["category"].(float64))
  8901. project.Category = category
  8902. specail_project := int64(projectM["specail_project"].(float64))
  8903. project.SpecailProject = specail_project
  8904. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8905. project.SocialSecurityDirectoryCode = social_security_directory_code
  8906. remark := projectM["remark"].(string)
  8907. project.Remark = remark
  8908. record_date := projectM["record_date"].(string)
  8909. timeLayout := "2006-01-02"
  8910. loc, _ := time.LoadLocation("Local")
  8911. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8912. project.RecordDate = theTime.Unix()
  8913. projectList = append(projectList, &project)
  8914. }
  8915. export_time := time.Now().Unix()
  8916. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8917. if len(projectList) > 0 {
  8918. for _, item := range projectList {
  8919. project := models.HisProject{
  8920. ProjectName: item.ProjectName,
  8921. Price: item.Price,
  8922. Unit: item.Unit,
  8923. CostClassify: item.CostClassify,
  8924. ExecutiveSection: item.ExecutiveSection,
  8925. MedicalCoverage: item.MedicalCoverage,
  8926. UserOrgId: orgId,
  8927. Status: 1,
  8928. CreatedTime: time.Now().Unix(),
  8929. Pinyin: item.Pinyin,
  8930. Wubi: item.Wubi,
  8931. StatisticalClassification: item.StatisticalClassification,
  8932. DiseaseDirectory: item.DiseaseDirectory,
  8933. IsRecord: item.IsRecord,
  8934. MedicalCode: item.MedicalCode,
  8935. TubeColor: item.TubeColor,
  8936. SingleDose: item.SingleDose,
  8937. DeliveryWay: item.DeliveryWay,
  8938. NumberDays: item.NumberDays,
  8939. Total: item.Total,
  8940. Category: item.Category,
  8941. MedicalStatus: item.MedicalStatus,
  8942. SpecailProject: item.SpecailProject,
  8943. RecordDate: item.RecordDate,
  8944. Remark: item.Remark,
  8945. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8946. ExecutionFrequency: item.ExecutionFrequency,
  8947. }
  8948. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8949. if errcodeproject == gorm.ErrRecordNotFound {
  8950. service.CreateProjectInfomation(&project)
  8951. } else if errcodeproject == nil {
  8952. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8953. }
  8954. log := models.ExportLog{
  8955. LogType: 6,
  8956. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8957. TotalNum: int64(len(total_goods)),
  8958. FailNum: int64(len(errLogs)),
  8959. SuccessNum: int64(len(projectList)),
  8960. CreateTime: time.Now().Unix(),
  8961. UpdateTime: time.Now().Unix(),
  8962. ExportTime: export_time,
  8963. Status: 1,
  8964. }
  8965. service.CreateExportLog(&log)
  8966. c.ServeSuccessJSON(map[string]interface{}{
  8967. "msg": "导入成功",
  8968. "total_num": len(total_goods),
  8969. "success_num": len(projectList),
  8970. "fail_num": int64(len(errLogs)),
  8971. })
  8972. }
  8973. } else {
  8974. log := models.ExportLog{
  8975. LogType: 6,
  8976. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8977. TotalNum: int64(len(total_goods)),
  8978. FailNum: int64(len(errLogs)),
  8979. SuccessNum: int64(len(projectList)),
  8980. CreateTime: time.Now().Unix(),
  8981. UpdateTime: time.Now().Unix(),
  8982. ExportTime: export_time,
  8983. Status: 1,
  8984. }
  8985. service.CreateExportLog(&log)
  8986. c.ServeSuccessJSON(map[string]interface{}{
  8987. "msg": "导入成功",
  8988. "total_num": len(total_goods),
  8989. "success_num": len(projectList),
  8990. "fail_num": int64(len(errLogs)),
  8991. })
  8992. }
  8993. }
  8994. //func (this *HisApiController) EditProjectInformation(){
  8995. //
  8996. // id, _ := this.GetInt64("id")
  8997. // project_team := this.GetString("project_team")
  8998. // price := this.GetString("price")
  8999. // price_float, _ := strconv.ParseFloat(price, 64)
  9000. // pinyin := this.GetString("pinyin")
  9001. // wubi := this.GetString("wubi")
  9002. // tube_color, _ := this.GetInt64("tube_color")
  9003. // team_type, _ := this.GetInt64("team_type")
  9004. // remark := this.GetString("remark")
  9005. // ids := this.GetString("ids")
  9006. // item_id := this.GetString("item_id")
  9007. // projectTeam := models.XtHisProjectTeam{
  9008. // ProjectTeam: project_team,
  9009. // Price: price_float,
  9010. // Pinyin: pinyin,
  9011. // Wubi: wubi,
  9012. // TubeColor: tube_color,
  9013. // TeamType: team_type,
  9014. // Remark: remark,
  9015. // ProjectId: ids,
  9016. // ItemId: item_id,
  9017. // }
  9018. //
  9019. //
  9020. // dataBody := make(map[string]interface{}, 0)
  9021. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9022. // if err != nil {
  9023. // utils.ErrorLog(err.Error())
  9024. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9025. // return
  9026. // }
  9027. //
  9028. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9029. //
  9030. //
  9031. // if err != nil {
  9032. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9033. // return
  9034. // }
  9035. //
  9036. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9037. // infos, _ := dataBody["info"].([]interface{})
  9038. // if len(infos) > 0 {
  9039. // var ids []string
  9040. //
  9041. // for _, item := range infos {
  9042. // items := item.(map[string]interface{})
  9043. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9044. // utils.ErrorLog("id")
  9045. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9046. // return
  9047. // }
  9048. // id := int64(items["id"].(float64))
  9049. //
  9050. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9051. // utils.ErrorLog("type")
  9052. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9053. // return
  9054. // }
  9055. // types := int64(items["type"].(float64))
  9056. //
  9057. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9058. // utils.ErrorLog("number")
  9059. // }
  9060. //
  9061. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9062. //
  9063. // projectList := models.XtHisProjectList{
  9064. // Number: number,
  9065. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9066. // ProjectId: id,
  9067. // Status: 1,
  9068. // CreatedTime: time.Now().Unix(),
  9069. // UpdatedTime: time.Now().Unix(),
  9070. // TeamId: projectTeam.ID,
  9071. // Type: types,
  9072. // }
  9073. // list := projectList
  9074. //
  9075. // service.CreateProjectList(&list)
  9076. //
  9077. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9078. //
  9079. // }
  9080. // ids_str := strings.Join(ids, ",")
  9081. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9082. // service.SaveProjectTeam(&projectTeam)
  9083. // this.ServeSuccessJSON(map[string]interface{}{
  9084. // "projectTeam": projectTeam,
  9085. // })
  9086. // }
  9087. // }
  9088. //}
  9089. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9090. name := c.GetString("name")
  9091. mode_id, _ := c.GetInt64("mode", 0)
  9092. types, _ := c.GetInt64("type", 0)
  9093. patient_id, _ := c.GetInt64("patient_id", 0)
  9094. types = 1
  9095. adminInfo := c.GetAdminUserInfo()
  9096. template := &models.HisPrescriptionTemplate{
  9097. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9098. PatientId: patient_id,
  9099. Type: types,
  9100. Status: 1,
  9101. Ctime: time.Now().Unix(),
  9102. Mtime: time.Now().Unix(),
  9103. Name: name,
  9104. Mode: mode_id,
  9105. }
  9106. dataBody := make(map[string]interface{}, 0)
  9107. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9108. if err != nil {
  9109. utils.ErrorLog(err.Error())
  9110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9111. return
  9112. }
  9113. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9114. //如果已经存在记录则删除处方
  9115. if template_one.ID > 0 {
  9116. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9117. var ids []int64
  9118. var org_id int64
  9119. for _, item := range ps {
  9120. org_id = c.GetAdminUserInfo().CurrentOrgId
  9121. ids = append(ids, item.ID)
  9122. }
  9123. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  9124. if err2 == nil {
  9125. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9126. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9127. if len(prescriptions) > 0 {
  9128. for _, item := range prescriptions {
  9129. items := item.(map[string]interface{})
  9130. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9131. utils.ErrorLog("type")
  9132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9133. return
  9134. }
  9135. types := int64(items["type"].(float64))
  9136. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9137. utils.ErrorLog("med_type")
  9138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9139. return
  9140. }
  9141. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9142. ctime := time.Now().Unix()
  9143. prescription := &models.HisPrescriptionInfoTemplate{
  9144. PatientId: patient_id,
  9145. UserOrgId: adminInfo.CurrentOrgId,
  9146. Ctime: ctime,
  9147. Mtime: ctime,
  9148. Type: types,
  9149. Modifier: adminInfo.AdminUser.Id,
  9150. Creator: adminInfo.AdminUser.Id,
  9151. Status: 1,
  9152. PTemplateId: template_one.ID,
  9153. MedType: med_type,
  9154. }
  9155. service.CreateHisPrescriptionInfoTemplate(prescription)
  9156. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9157. advices := items["advices"].([]interface{})
  9158. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9159. ctime := time.Now().Unix()
  9160. mtime := ctime
  9161. if len(advices) > 0 {
  9162. for _, advice := range advices {
  9163. var s models.HisPrescriptionAdviceTemplate
  9164. s.PrescriptionId = prescription.ID
  9165. s.AdviceType = 2
  9166. s.StopState = 2
  9167. s.ExecutionState = 2
  9168. s.Status = 1
  9169. s.UserOrgId = adminInfo.CurrentOrgId
  9170. s.CreatedTime = ctime
  9171. s.UpdatedTime = mtime
  9172. s.PatientId = patient_id
  9173. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9174. if errcode > 0 {
  9175. c.ServeFailJSONWithSGJErrorCode(errcode)
  9176. return
  9177. }
  9178. service.CreateHisPrescriptionAdviceTemplate(&s)
  9179. }
  9180. }
  9181. }
  9182. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9183. projects := items["project"].([]interface{})
  9184. if len(projects) > 0 {
  9185. for _, project := range projects {
  9186. var p models.HisPrescriptionProjectTemplate
  9187. p.PrescriptionId = prescription.ID
  9188. p.Ctime = time.Now().Unix()
  9189. p.Mtime = time.Now().Unix()
  9190. p.PatientId = patient_id
  9191. p.UserOrgId = adminInfo.CurrentOrgId
  9192. p.Status = 1
  9193. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9194. if errcode > 0 {
  9195. c.ServeFailJSONWithSGJErrorCode(errcode)
  9196. return
  9197. }
  9198. service.CreateHisPrescriptionProjectTemplate(&p)
  9199. }
  9200. }
  9201. }
  9202. }
  9203. c.ServeSuccessJSON(map[string]interface{}{
  9204. "msg": "创建成功",
  9205. })
  9206. }
  9207. }
  9208. } else {
  9209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9210. return
  9211. }
  9212. } else {
  9213. err3 := service.CreateHisPrescriptionTemplate(template)
  9214. if err3 == nil {
  9215. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9216. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9217. if len(prescriptions) > 0 {
  9218. for _, item := range prescriptions {
  9219. items := item.(map[string]interface{})
  9220. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9221. utils.ErrorLog("type")
  9222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9223. return
  9224. }
  9225. types := int64(items["type"].(float64))
  9226. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9227. utils.ErrorLog("med_type")
  9228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9229. return
  9230. }
  9231. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9232. ctime := time.Now().Unix()
  9233. prescription := &models.HisPrescriptionInfoTemplate{
  9234. PatientId: patient_id,
  9235. UserOrgId: adminInfo.CurrentOrgId,
  9236. Ctime: ctime,
  9237. Mtime: ctime,
  9238. Type: types,
  9239. Modifier: adminInfo.AdminUser.Id,
  9240. Creator: adminInfo.AdminUser.Id,
  9241. Status: 1,
  9242. PTemplateId: template.ID,
  9243. MedType: med_type,
  9244. }
  9245. service.CreateHisPrescriptionInfoTemplate(prescription)
  9246. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9247. advices := items["advices"].([]interface{})
  9248. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9249. ctime := time.Now().Unix()
  9250. mtime := ctime
  9251. if len(advices) > 0 {
  9252. for _, advice := range advices {
  9253. var s models.HisPrescriptionAdviceTemplate
  9254. s.PrescriptionId = prescription.ID
  9255. s.AdviceType = 2
  9256. s.StopState = 2
  9257. s.ExecutionState = 2
  9258. s.Status = 1
  9259. s.UserOrgId = adminInfo.CurrentOrgId
  9260. s.CreatedTime = ctime
  9261. s.UpdatedTime = mtime
  9262. s.PatientId = patient_id
  9263. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9264. if errcode > 0 {
  9265. c.ServeFailJSONWithSGJErrorCode(errcode)
  9266. return
  9267. }
  9268. service.CreateHisPrescriptionAdviceTemplate(&s)
  9269. }
  9270. }
  9271. }
  9272. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9273. projects := items["project"].([]interface{})
  9274. if len(projects) > 0 {
  9275. for _, project := range projects {
  9276. var p models.HisPrescriptionProjectTemplate
  9277. p.PrescriptionId = prescription.ID
  9278. p.Ctime = time.Now().Unix()
  9279. p.Mtime = time.Now().Unix()
  9280. p.PatientId = patient_id
  9281. p.UserOrgId = adminInfo.CurrentOrgId
  9282. p.Status = 1
  9283. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9284. if errcode > 0 {
  9285. c.ServeFailJSONWithSGJErrorCode(errcode)
  9286. return
  9287. }
  9288. service.CreateHisPrescriptionProjectTemplate(&p)
  9289. }
  9290. }
  9291. }
  9292. }
  9293. c.ServeSuccessJSON(map[string]interface{}{
  9294. "msg": "创建成功",
  9295. })
  9296. }
  9297. }
  9298. } else {
  9299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9300. return
  9301. }
  9302. }
  9303. }
  9304. func (c *HisApiController) PreSettle() {
  9305. id, _ := c.GetInt64("id")
  9306. record_time := c.GetString("record_time")
  9307. his_patient_id, _ := c.GetInt64("his_patient_id")
  9308. timeLayout := "2006-01-02"
  9309. loc, _ := time.LoadLocation("Local")
  9310. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9311. diagnosis_id := c.GetString("diagnosis")
  9312. sick_type, _ := c.GetInt64("sick_type")
  9313. reg_type, _ := c.GetInt64("p_type")
  9314. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9315. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9316. if err != nil {
  9317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9318. return
  9319. }
  9320. recordDateTime := theTime.Unix()
  9321. adminUser := c.GetAdminUserInfo()
  9322. var prescriptions []*models.HisPrescription
  9323. var start_time int64
  9324. var end_time int64
  9325. ids_str := c.GetString("ids")
  9326. ids_arr := strings.Split(ids_str, ",")
  9327. fmt.Println(reg_type)
  9328. if settle_accounts_type == 1 { //日结
  9329. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9330. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9331. } else {
  9332. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9333. }
  9334. fmt.Println(prescriptions)
  9335. } else { //月结
  9336. start_time_str := c.GetString("start_time")
  9337. end_time_str := c.GetString("end_time")
  9338. timeLayout := "2006-01-02"
  9339. loc, _ := time.LoadLocation("Local")
  9340. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9341. if err != nil {
  9342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9343. return
  9344. }
  9345. recordStartTime := theStartTime.Unix()
  9346. start_time = recordStartTime
  9347. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9348. if err != nil {
  9349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9350. return
  9351. }
  9352. recordEndTime := theEndTime.Unix()
  9353. end_time = recordEndTime
  9354. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9355. }
  9356. if reg_type == 1111 || reg_type == 1112 {
  9357. reg_type = 11
  9358. }
  9359. timestamp := time.Now().Unix()
  9360. tempTime := time.Unix(timestamp, 0)
  9361. timeFormat := tempTime.Format("20060102150405")
  9362. chrgBchno := rand.Intn(100000) + 10000
  9363. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9364. strconv.FormatInt(his.PatientId, 10)
  9365. var ids []int64
  9366. for _, item := range prescriptions {
  9367. ids = append(ids, item.ID)
  9368. }
  9369. fmt.Println(ids)
  9370. var total float64
  9371. for _, item := range prescriptions {
  9372. fmt.Println(item)
  9373. if item.Type == 1 { //药品
  9374. for _, subItem := range item.HisDoctorAdviceInfo {
  9375. total = total + (subItem.Price * subItem.PrescribingNumber)
  9376. }
  9377. }
  9378. if item.Type == 2 { //项目
  9379. for _, subItem := range item.HisPrescriptionProject {
  9380. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9381. total = total + (subItem.Price * cnt)
  9382. }
  9383. }
  9384. for _, subItem := range item.HisAdditionalCharge {
  9385. total = total + (subItem.Price * float64(subItem.Count))
  9386. }
  9387. }
  9388. allTotal := fmt.Sprintf("%.2f", total)
  9389. totals, _ := strconv.ParseFloat(allTotal, 64)
  9390. order := &models.HisOrder{
  9391. UserOrgId: adminUser.CurrentOrgId,
  9392. HisPatientId: his.ID,
  9393. PatientId: id,
  9394. SettleAccountsDate: recordDateTime,
  9395. Ctime: time.Now().Unix(),
  9396. Mtime: time.Now().Unix(),
  9397. Status: 1,
  9398. OrderStatus: 1,
  9399. MdtrtId: his.Number,
  9400. Number: chrg_bchno,
  9401. MedfeeSumamt: totals,
  9402. SettleEndTime: end_time,
  9403. SettleStartTime: start_time,
  9404. SettleType: settle_accounts_type,
  9405. PsnPartAmt: totals,
  9406. PsnCashPay: totals,
  9407. PType: 2,
  9408. IsPre: 1,
  9409. MedType: strconv.Itoa(int(reg_type)),
  9410. Diagnosis: diagnosis_id,
  9411. }
  9412. err = service.CreateOrder(order)
  9413. if err != nil {
  9414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9415. return
  9416. }
  9417. var customs []*Custom
  9418. for _, item := range prescriptions {
  9419. fmt.Println(item.Type)
  9420. if item.Type == 1 { //药品
  9421. for _, subItem := range item.HisDoctorAdviceInfo {
  9422. cus := &Custom{
  9423. AdviceId: subItem.ID,
  9424. ProjectId: 0,
  9425. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9426. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9427. FeedetlSn: subItem.FeedetlSn,
  9428. Price: fmt.Sprintf("%.2f", subItem.Price),
  9429. MedListCodg: subItem.MedListCodg,
  9430. Type: 1,
  9431. }
  9432. customs = append(customs, cus)
  9433. }
  9434. }
  9435. if item.Type == 2 { //项目
  9436. for _, subItem := range item.HisPrescriptionProject {
  9437. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9438. cus := &Custom{
  9439. AdviceId: 0,
  9440. ProjectId: subItem.ID,
  9441. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9442. Cut: fmt.Sprintf("%.2f", cnt),
  9443. FeedetlSn: subItem.FeedetlSn,
  9444. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9445. MedListCodg: subItem.MedListCodg,
  9446. Type: 2,
  9447. }
  9448. customs = append(customs, cus)
  9449. }
  9450. }
  9451. for _, item := range item.HisAdditionalCharge {
  9452. cus := &Custom{
  9453. ItemId: item.ID,
  9454. AdviceId: 0,
  9455. ProjectId: 0,
  9456. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9457. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9458. FeedetlSn: item.FeedetlSn,
  9459. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9460. MedListCodg: item.XtHisAddtionConfig.Code,
  9461. Type: 3,
  9462. }
  9463. customs = append(customs, cus)
  9464. }
  9465. }
  9466. fmt.Println(customs)
  9467. for _, item := range customs {
  9468. var advice_id int64 = 0
  9469. var project_id int64 = 0
  9470. var item_id int64 = 0
  9471. var types int64 = 0
  9472. if item.Type == 1 {
  9473. advice_id = item.AdviceId
  9474. project_id = 0
  9475. item_id = 0
  9476. } else if item.Type == 2 {
  9477. advice_id = 0
  9478. item_id = 0
  9479. project_id = item.ProjectId
  9480. } else if item.Type == 3 {
  9481. advice_id = 0
  9482. item_id = item.ItemId
  9483. project_id = 0
  9484. }
  9485. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9486. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9487. pric, _ := strconv.ParseFloat(item.Price, 32)
  9488. info := &models.HisOrderInfo{
  9489. OrderNumber: order.Number,
  9490. UploadDate: time.Now().Unix(),
  9491. AdviceId: advice_id,
  9492. DetItemFeeSumamt: detItemFeeSumamt,
  9493. Cnt: cut,
  9494. Pric: pric,
  9495. PatientId: id,
  9496. Status: 1,
  9497. Mtime: time.Now().Unix(),
  9498. Ctime: time.Now().Unix(),
  9499. UserOrgId: adminUser.CurrentOrgId,
  9500. HisPatientId: his.ID,
  9501. OrderId: order.ID,
  9502. ProjectId: project_id,
  9503. Type: types,
  9504. ItemId: item_id,
  9505. }
  9506. service.CreateOrderInfo(info)
  9507. }
  9508. his.SickType = sick_type
  9509. service.UpdataHisPateint(&his)
  9510. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9511. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9512. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9513. if err == nil {
  9514. c.ServeSuccessJSON(map[string]interface{}{
  9515. "msg": "结算成功",
  9516. })
  9517. }
  9518. }
  9519. type CustomOrderInfo struct {
  9520. Name string
  9521. Spec string
  9522. Unit string
  9523. Count float64
  9524. Price float64
  9525. Total float64
  9526. }
  9527. func (c *HisApiController) GetPrivateExpensesInfo() {
  9528. order_id, _ := c.GetInt64("id", 0)
  9529. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9530. order, _ := service.GetHisOrderByID(order_id)
  9531. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9532. if order.ID == 0 {
  9533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9534. return
  9535. }
  9536. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9537. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9538. org_id := c.GetAdminUserInfo().CurrentOrgId
  9539. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9540. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9541. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9542. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9543. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9544. //var orderInfos_four []*models.HisOrderInfoTwo
  9545. //for _, item := range orderInfos_three {
  9546. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9547. // item.HisPrescriptionProject.IsCheckTeam = 1
  9548. // orderInfos_four = append(orderInfos_four, item)
  9549. //
  9550. // }
  9551. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9552. // item.HisPrescriptionProject.IsCheckTeam = 2
  9553. // orderInfos_two = append(orderInfos_two, item)
  9554. // }
  9555. //}
  9556. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9557. //var cus_slice []CustomOrderInfo
  9558. //for _, item := range new_order_info {
  9559. // var cus CustomOrderInfo
  9560. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9561. // cus.Unit = ""
  9562. // cus.Spec = ""
  9563. // var total float64
  9564. // for _, subItem := range orderInfos_four {
  9565. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9566. // total = total + subItem.DetItemFeeSumamt
  9567. // fmt.Println(subItem.DetItemFeeSumamt)
  9568. // }
  9569. // }
  9570. // cus.Count = 1
  9571. // cus.Total = total
  9572. // cus_slice = append(cus_slice, cus)
  9573. //}
  9574. orderInfos = append(orderInfos, orderInfos_two...)
  9575. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9576. //orderInfos = append(orderInfos, orderInfos_three...)
  9577. //}/**/
  9578. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9579. c.ServeSuccessJSON(map[string]interface{}{
  9580. "order": order,
  9581. "order_info": orderInfos,
  9582. "patient": patient,
  9583. "admin_info": adminInfo,
  9584. "his": his,
  9585. "current_admin": role,
  9586. "org_config": miConfig,
  9587. //"new_order_info": cus_slice,
  9588. })
  9589. }
  9590. func (this *HisApiController) ChangeMedType() {
  9591. med_type := this.GetString("med_type")
  9592. old_med_type := this.GetString("old_med_type")
  9593. ids := this.GetString("ids")
  9594. settle_type, _ := this.GetInt64("settle_type")
  9595. start_time := this.GetString("start_time")
  9596. end_time := this.GetString("end_time")
  9597. ids_arr := strings.Split(ids, ",")
  9598. if settle_type == 1 { //日结
  9599. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9600. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9601. prescription.MedType = med_type
  9602. err := service.SaveHisPrescription(&prescription)
  9603. if err == nil {
  9604. this.ServeSuccessJSON(map[string]interface{}{
  9605. "msg": "修改成功",
  9606. })
  9607. } else {
  9608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9609. return
  9610. }
  9611. } else if settle_type == 2 {
  9612. timeLayout := "2006-01-02"
  9613. loc, _ := time.LoadLocation("Local")
  9614. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9615. if err != nil {
  9616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9617. return
  9618. }
  9619. recordStartTime := theStartTime.Unix()
  9620. start_time_timestamp := recordStartTime
  9621. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9622. if err != nil {
  9623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9624. return
  9625. }
  9626. recordEndTime := theEndTime.Unix()
  9627. end_time_timestamp := recordEndTime
  9628. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9629. if updateErr == nil {
  9630. this.ServeSuccessJSON(map[string]interface{}{
  9631. "msg": "修改成功",
  9632. })
  9633. } else {
  9634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9635. return
  9636. }
  9637. }
  9638. }
  9639. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9640. patient_id, _ := c.GetInt64("patient_id")
  9641. his_patient_id, _ := c.GetInt64("his_patient_id")
  9642. record_date := c.GetString("record_date")
  9643. start_time := c.GetString("start_time")
  9644. end_time := c.GetString("end_time")
  9645. order_status, _ := c.GetInt64("type", 0)
  9646. p_type, _ := c.GetInt64("p_type", 0)
  9647. order_id, _ := c.GetInt64("order_id", 0)
  9648. timeLayout := "2006-01-02"
  9649. loc, _ := time.LoadLocation("Local")
  9650. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9651. if err != nil {
  9652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9653. return
  9654. }
  9655. recordDateTime := theTime.Unix()
  9656. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9657. if err != nil {
  9658. }
  9659. startRecordDateTime := startTime.Unix()
  9660. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9661. if err != nil {
  9662. }
  9663. endRecordDateTime := endTime.Unix()
  9664. admin := c.GetAdminUserInfo()
  9665. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9666. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9667. order, _ := service.GetHisOrderByID(order_id)
  9668. var monthPrescriptions []*models.HisPrescription
  9669. if order_status == 1 || order_status == 0 {
  9670. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9671. } else if order_status == 2 {
  9672. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9673. }
  9674. var settle_total float64
  9675. for _, item := range monthPrescriptions {
  9676. if len(item.HisPrescriptionProject) > 0 {
  9677. for _, subItem := range item.HisPrescriptionProject {
  9678. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9679. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9680. settle_total = settle_total + total
  9681. }
  9682. }
  9683. if len(item.HisDoctorAdviceInfo) > 0 {
  9684. for _, subItem := range item.HisDoctorAdviceInfo {
  9685. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9686. settle_total = settle_total + total
  9687. }
  9688. }
  9689. }
  9690. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9691. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9692. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9693. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9694. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9695. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9696. //获取所有科室信息
  9697. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9698. var dia string
  9699. for _, item := range month_p_info {
  9700. if len(dia) == 0 {
  9701. dia = item.Diagnosis
  9702. } else {
  9703. dia = dia + "," + item.Diagnosis
  9704. }
  9705. }
  9706. dia_arr := removeDuplicates(strings.Split(dia, ","))
  9707. dia_arr = removeEmptyStrings(dia_arr)
  9708. c.ServeSuccessJSON(map[string]interface{}{
  9709. "his_info": his_patient_info,
  9710. "xt_info": xt_patient_info,
  9711. "case_history": case_history,
  9712. "info": patientPrescriptionInfo,
  9713. "last_info": lastPatientPrescriptionInfo,
  9714. "month_prescriptions": monthPrescriptions,
  9715. "order": order,
  9716. "doctors": doctors,
  9717. "department": department,
  9718. "settle_total": settle_total,
  9719. "dia_arr": dia_arr,
  9720. })
  9721. return
  9722. }
  9723. func removeEmptyStrings(input []string) []string {
  9724. var output []string
  9725. for _, s := range input {
  9726. if s != "" {
  9727. output = append(output, s)
  9728. }
  9729. }
  9730. return output
  9731. }
  9732. func removeDuplicates(input []string) []string {
  9733. seen := make(map[string]bool)
  9734. output := []string{}
  9735. for _, s := range input {
  9736. if _, exists := seen[s]; !exists {
  9737. seen[s] = true
  9738. output = append(output, s)
  9739. }
  9740. }
  9741. return output
  9742. }
  9743. func (c *HisApiController) GetHisMonthPatientInfo() {
  9744. patient_id, _ := c.GetInt64("patient_id")
  9745. his_patient_id, _ := c.GetInt64("his_patient_id")
  9746. record_date := c.GetString("record_date")
  9747. number := c.GetString("number")
  9748. start_time := c.GetString("start_time")
  9749. end_time := c.GetString("end_time")
  9750. p_type, _ := c.GetInt64("p_type")
  9751. timeLayout := "2006-01-02"
  9752. loc, _ := time.LoadLocation("Local")
  9753. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9754. if err != nil {
  9755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9756. return
  9757. }
  9758. recordDateTime := theTime.Unix()
  9759. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9760. if err != nil {
  9761. }
  9762. startRecordDateTime := startTime.Unix()
  9763. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9764. if err != nil {
  9765. }
  9766. endRecordDateTime := endTime.Unix()
  9767. admin := c.GetAdminUserInfo()
  9768. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9769. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9770. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9771. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9772. var settle_total float64
  9773. for _, item := range monthPrescriptions {
  9774. if len(item.HisPrescriptionProject) > 0 {
  9775. for _, subItem := range item.HisPrescriptionProject {
  9776. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9777. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9778. settle_total = settle_total + total
  9779. }
  9780. }
  9781. if len(item.HisDoctorAdviceInfo) > 0 {
  9782. for _, subItem := range item.HisDoctorAdviceInfo {
  9783. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9784. settle_total = settle_total + total
  9785. }
  9786. }
  9787. }
  9788. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9789. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9790. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9791. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9792. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9793. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9794. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9795. //获取所有科室信息
  9796. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9797. c.ServeSuccessJSON(map[string]interface{}{
  9798. "his_info": his_patient_info,
  9799. "xt_info": xt_patient_info,
  9800. "case_history": case_history,
  9801. "info": patientPrescriptionInfo,
  9802. "month_prescriptions": monthPrescriptions,
  9803. "order": order,
  9804. "doctors": doctors,
  9805. "department": department,
  9806. "count": count,
  9807. "drugStockConfig": drugStockConfig,
  9808. "last_info": lastPatientPrescriptionInfo,
  9809. "settle_total": settle_total,
  9810. })
  9811. return
  9812. }
  9813. func (c *HisApiController) GetAllOrder() {
  9814. org_id := c.GetAdminUserInfo().CurrentOrgId
  9815. orders, _ := service.GetNewHisOrderList(org_id)
  9816. c.ServeSuccessJSON(map[string]interface{}{
  9817. "order": orders,
  9818. })
  9819. return
  9820. }
  9821. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9822. newArr = make([]*models.HisOrderInfoTwo, 0)
  9823. for i := 0; i < len(arr); i++ {
  9824. repeat := false
  9825. for j := i + 1; j < len(arr); j++ {
  9826. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9827. repeat = true
  9828. break
  9829. }
  9830. }
  9831. if !repeat {
  9832. newArr = append(newArr, arr[i])
  9833. }
  9834. }
  9835. return
  9836. }
  9837. // 修改处方退库操作 参数传修改之前的处方数据
  9838. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9839. if advice.ExecutionState == 1 {
  9840. //查询该病人该药品是否有库存记录
  9841. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9842. if errcode == gorm.ErrRecordNotFound {
  9843. } else {
  9844. //退库
  9845. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9846. if advice.PrescribingNumberUnit == drug.MinUnit {
  9847. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9848. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9849. //退库
  9850. warehouseInfo := models.DrugWarehouseInfo{
  9851. StockMinNumber: prescribingNumber,
  9852. }
  9853. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9854. operation_time := time.Now().Unix()
  9855. creater := advice.AdviceDoctor
  9856. ctime := time.Now().Unix()
  9857. timeStr := time.Now().Format("2006-01-02")
  9858. timeArr := strings.Split(timeStr, "-")
  9859. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9860. total = total + 1
  9861. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9862. cancelStock := models.DrugCancelStock{
  9863. OrderNumber: orderNumber,
  9864. OperaTime: operation_time,
  9865. OrgId: advice.UserOrgId,
  9866. Creater: creater,
  9867. Ctime: ctime,
  9868. Status: 1,
  9869. ReturnTime: advice.AdviceDate,
  9870. Dealer: info.Dealer,
  9871. Manufacturer: info.Manufacturer,
  9872. Type: 1,
  9873. }
  9874. service.AddSigleDrugCancelStock(&cancelStock)
  9875. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9876. dealer, _ := service.GetDealerById(info.Dealer)
  9877. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9878. cancelStockInfo := models.DrugCancelStockInfo{
  9879. OrderNumber: cancelInfo.OrderNumber,
  9880. CancelStockId: cancelInfo.ID,
  9881. DrugId: info.DrugId,
  9882. Count: info.Count,
  9883. Status: 1,
  9884. Ctime: ctime,
  9885. OrgId: advice.UserOrgId,
  9886. Type: 1,
  9887. Manufacturer: manufactureName.ManufacturerName,
  9888. Dealer: dealer.DealerName,
  9889. Total: 0,
  9890. RetailPrice: info.RetailPrice,
  9891. RetailTotalPrice: info.RetailTotalPrice,
  9892. Price: info.Price,
  9893. RegisterAccount: "",
  9894. Remark: info.Remark,
  9895. BatchNumber: info.BatchNumber,
  9896. MaxUnit: info.CountUnit,
  9897. ProductDate: info.ProductDate,
  9898. ExpiryDate: info.ExpiryDate,
  9899. BatchNumberId: info.WarehouseInfoId,
  9900. }
  9901. flow := models.DrugFlow{
  9902. WarehousingId: 0,
  9903. DrugId: info.DrugId,
  9904. Number: "",
  9905. BatchNumber: info.BatchNumber,
  9906. Count: info.Count,
  9907. UserOrgId: advice.UserOrgId,
  9908. PatientId: 0,
  9909. SystemTime: ctime,
  9910. ConsumableType: 4,
  9911. IsSys: 0,
  9912. WarehousingOrder: "",
  9913. WarehouseOutId: 0,
  9914. WarehouseOutOrderNumber: "",
  9915. IsEdit: 0,
  9916. CancelStockId: cancelStock.ID,
  9917. CancelOrderNumber: cancelStock.OrderNumber,
  9918. Manufacturer: info.Manufacturer,
  9919. Dealer: info.Dealer,
  9920. Creator: advice.UserOrgId,
  9921. UpdateCreator: 0,
  9922. Status: 1,
  9923. Ctime: time.Now().Unix(),
  9924. Mtime: 0,
  9925. Price: info.Price,
  9926. WarehousingDetailId: 0,
  9927. WarehouseOutDetailId: 0,
  9928. CancelOutDetailId: 0,
  9929. ExpireDate: info.ExpiryDate,
  9930. ProductDate: info.ProductDate,
  9931. MaxUnit: info.CountUnit,
  9932. MinUnit: "",
  9933. }
  9934. service.CreatedCancelStock(cancelStockInfo)
  9935. service.CreateDrugFlowOne(flow)
  9936. } else {
  9937. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9938. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9939. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9940. warehouseInfo := models.DrugWarehouseInfo{
  9941. StockMinNumber: prescribingNumber,
  9942. }
  9943. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9944. }
  9945. operation_time := time.Now().Unix()
  9946. creater := advice.AdviceDoctor
  9947. ctime := time.Now().Unix()
  9948. timeStr := time.Now().Format("2006-01-02")
  9949. timeArr := strings.Split(timeStr, "-")
  9950. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9951. total = total + 1
  9952. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9953. cancelStock := models.DrugCancelStock{
  9954. OrderNumber: orderNumber,
  9955. OperaTime: operation_time,
  9956. OrgId: advice.UserOrgId,
  9957. Creater: creater,
  9958. Ctime: ctime,
  9959. Status: 1,
  9960. ReturnTime: advice.AdviceDate,
  9961. Dealer: info.Dealer,
  9962. Manufacturer: info.Manufacturer,
  9963. Type: 1,
  9964. }
  9965. service.AddSigleDrugCancelStock(&cancelStock)
  9966. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9967. dealer, _ := service.GetDealerById(info.Dealer)
  9968. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9969. cancelStockInfo := models.DrugCancelStockInfo{
  9970. OrderNumber: cancelInfo.OrderNumber,
  9971. CancelStockId: cancelInfo.ID,
  9972. DrugId: info.DrugId,
  9973. Count: info.Count,
  9974. Status: 1,
  9975. Ctime: ctime,
  9976. OrgId: advice.UserOrgId,
  9977. Type: 1,
  9978. Manufacturer: manufactureName.ManufacturerName,
  9979. Dealer: dealer.DealerName,
  9980. Total: 0,
  9981. RetailPrice: info.RetailPrice,
  9982. RetailTotalPrice: info.RetailTotalPrice,
  9983. Price: info.Price,
  9984. RegisterAccount: "",
  9985. Remark: info.Remark,
  9986. BatchNumber: info.BatchNumber,
  9987. MaxUnit: info.CountUnit,
  9988. ProductDate: info.ProductDate,
  9989. ExpiryDate: info.ExpiryDate,
  9990. BatchNumberId: info.WarehouseInfoId,
  9991. }
  9992. flow := models.DrugFlow{
  9993. WarehousingId: 0,
  9994. DrugId: info.DrugId,
  9995. Number: "",
  9996. BatchNumber: info.BatchNumber,
  9997. Count: info.Count,
  9998. UserOrgId: advice.UserOrgId,
  9999. PatientId: 0,
  10000. SystemTime: ctime,
  10001. ConsumableType: 4,
  10002. IsSys: 0,
  10003. WarehousingOrder: "",
  10004. WarehouseOutId: 0,
  10005. WarehouseOutOrderNumber: "",
  10006. IsEdit: 0,
  10007. CancelStockId: cancelStock.ID,
  10008. CancelOrderNumber: cancelStock.OrderNumber,
  10009. Manufacturer: info.Manufacturer,
  10010. Dealer: info.Dealer,
  10011. Creator: advice.AdviceDoctor,
  10012. UpdateCreator: 0,
  10013. Status: 1,
  10014. Ctime: time.Now().Unix(),
  10015. Mtime: 0,
  10016. Price: info.Price,
  10017. WarehousingDetailId: 0,
  10018. WarehouseOutDetailId: 0,
  10019. CancelOutDetailId: 0,
  10020. ExpireDate: info.ExpiryDate,
  10021. ProductDate: info.ProductDate,
  10022. MaxUnit: info.CountUnit,
  10023. MinUnit: "",
  10024. }
  10025. service.CreatedCancelStock(cancelStockInfo)
  10026. service.CreateDrugFlowOne(flow)
  10027. }
  10028. }
  10029. }
  10030. return err
  10031. }
  10032. func (this *HisApiController) DeleteNCDS() {
  10033. id, _ := this.GetInt64("id", 0)
  10034. if id > 0 {
  10035. service.DeletePsnNCDSRecordById(id)
  10036. this.ServeSuccessJSON(map[string]interface{}{
  10037. "msg": "删除成功",
  10038. })
  10039. } else {
  10040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10041. return
  10042. }
  10043. }
  10044. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10045. id, _ := c.GetInt64("id")
  10046. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10047. c.ServeSuccessJSON(map[string]interface{}{
  10048. "advice": advice,
  10049. })
  10050. return
  10051. }
  10052. func (c *HisApiController) GetHisMonthChargePatientList() {
  10053. record_date := c.GetString("record_date")
  10054. start_time := c.GetString("start_time")
  10055. end_time := c.GetString("end_time")
  10056. timeLayout := "2006-01-02"
  10057. loc, _ := time.LoadLocation("Local")
  10058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10059. if err != nil {
  10060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10061. return
  10062. }
  10063. if err != nil {
  10064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10065. return
  10066. }
  10067. recordDateTime := theTime.Unix()
  10068. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10069. if err != nil {
  10070. }
  10071. startRecordDateTime := startTime.Unix()
  10072. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10073. if err != nil {
  10074. }
  10075. endRecordDateTime := endTime.Unix()
  10076. adminInfo := c.GetAdminUserInfo()
  10077. var tempMonthChargePatients []*service.MonthChargePatients
  10078. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10079. for _, item := range tempPatients {
  10080. //过滤没有处方的
  10081. if len(item.HisPrescription) == 0 {
  10082. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10083. }
  10084. }
  10085. c.ServeSuccessJSON(map[string]interface{}{
  10086. "list": tempMonthChargePatients,
  10087. })
  10088. }