his_api_controller.go 435KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. }
  88. func (c *HisApiController) GetFaPiaoNumber() {
  89. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  90. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  91. fmt.Println(count)
  92. var zero string
  93. number := count + 1
  94. if number >= 1000 {
  95. zero = "0000" + strconv.FormatInt(number, 10)
  96. } else if number >= 10000 {
  97. zero = "000" + strconv.FormatInt(number, 10)
  98. } else if number >= 100000 {
  99. zero = "00" + strconv.FormatInt(number, 10)
  100. } else if number >= 1000000 {
  101. zero = "0" + strconv.FormatInt(number, 10)
  102. } else {
  103. zero = strconv.FormatInt(number, 10)
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "fapiao_number": zero,
  107. })
  108. return
  109. }
  110. func (c *HisApiController) ChangeOrderDesc() {
  111. id, _ := c.GetInt64("id")
  112. desc := c.GetString("desc")
  113. change_type := c.GetString("change_type")
  114. order, _ := service.GetHisOrderByID(id)
  115. if order.ID == 0 {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. switch change_type {
  120. case "oth_desc":
  121. order.OthDesc = desc
  122. break
  123. case "cash_pay":
  124. order.CashPay = desc
  125. break
  126. case "jifen_pay":
  127. order.JifenPay = desc
  128. break
  129. case "band_card_pay":
  130. order.BandCardPay = desc
  131. break
  132. case "ali_pay":
  133. order.AliPay = desc
  134. break
  135. case "wechat_pay":
  136. order.WechatPay = desc
  137. break
  138. }
  139. err := service.SaveHisOrder(&order)
  140. if err == nil {
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "msg": "修改成功",
  143. })
  144. return
  145. } else {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  147. return
  148. }
  149. }
  150. func (c *HisApiController) GetMonthHisPatient() {
  151. record_date := c.GetString("record_date")
  152. //order_status, _ := c.GetInt64("type")
  153. timeLayout := "2006-01-02"
  154. loc, _ := time.LoadLocation("Local")
  155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  156. if err != nil {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. recordDateTime := theTime.Unix()
  161. adminInfo := c.GetAdminUserInfo()
  162. var tempPatients []service.NewTempPatients
  163. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  164. // 获取当前时间
  165. now := time.Now()
  166. // 获取本月的第一天
  167. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  168. // 获取下个月的第一天
  169. nextMonth := firstDay.AddDate(0, 1, 0)
  170. // 获取本月的最后一天
  171. lastDay := nextMonth.Add(-time.Nanosecond)
  172. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  173. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  174. var patients []service.NewTempPatients
  175. var patients_two []service.NewTempPatients
  176. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  177. for _, item := range tempPatients {
  178. //过滤掉没挂号的和没开处方的
  179. if len(item.HisPrescription) > 0 {
  180. patients = append(patients, item)
  181. patients_two = append(patients_two, item)
  182. }
  183. ////过滤掉没挂号的
  184. //if len(item.HisPatient) > 0 {
  185. //}
  186. }
  187. } else {
  188. for _, item := range tempPatients {
  189. //过滤掉没挂号的和没开处方的
  190. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  191. patients = append(patients, item)
  192. }
  193. ////过滤掉没挂号的
  194. //if len(item.HisPatient) > 0 {
  195. // patients_two = append(patients_two, item)
  196. //}
  197. }
  198. }
  199. c.ServeSuccessJSON(map[string]interface{}{
  200. "list": patients,
  201. "list_two": patients_two,
  202. "chargePatients": chargePatients,
  203. })
  204. }
  205. func (c *HisApiController) GetBatchSettleAccounts() {
  206. order_ids := c.GetString("order_ids")
  207. admin_user_id, _ := c.GetInt64("admin_user_id")
  208. adminUser := c.GetAdminUserInfo()
  209. orders := strings.Split(order_ids, ",")
  210. var newOrders []models.Orders
  211. for _, item := range orders {
  212. order, _ := service.GetHisOrderByIDTenOne(item)
  213. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  214. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  215. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  216. orderInfos = append(orderInfos, orderInfos_two...)
  217. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  218. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  219. var diagnosis_ids []string
  220. if his.ID > 0 {
  221. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  222. } else {
  223. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  224. }
  225. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  226. var dia_config []*models.HisXtDiagnoseConfig
  227. var name string
  228. for _, item := range diagnosis_ids {
  229. id, _ := strconv.ParseInt(item, 10, 64)
  230. diagnosisConfig, _ := service.FindDiagnoseById(id)
  231. dia_config = append(dia_config, diagnosisConfig)
  232. if len(name) == 0 {
  233. name = diagnosisConfig.ClassName
  234. } else {
  235. name = name + "," + diagnosisConfig.ClassName
  236. }
  237. }
  238. var bedCostTotal float64 = 0 //床位总费
  239. var bedCostSelfTotal float64 = 0 //床位自费
  240. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  241. var bedSelfTotal float64 = 0 //床位部分项目自费
  242. var bedInscpTotal float64 = 0 //床位部分项目自费
  243. var operationCostTotal float64 = 0 //手术费
  244. var operationCostSelfTotal float64 = 0 //手术费
  245. var operationCostPartSelfTotal float64 = 0 //手术费
  246. var operationSelfTotal float64 = 0 //床位部分项目自费
  247. var operationInscpTotal float64 = 0 //床位部分项目自费
  248. var otherCostTotal float64 = 0 //其他费用
  249. var otherCostSelfTotal float64 = 0 //其他费用
  250. var otherCostPartSelfTotal float64 = 0 //其他费用
  251. var otherSelfTotal float64 = 0 //床位部分项目自费
  252. var otherInscpTotal float64 = 0 //床位部分项目自费
  253. var materialCostTotal float64 = 0 //材料费
  254. var materialCostSelfTotal float64 = 0 //材料费
  255. var materialCostPartSelfTotal float64 = 0 //材料费
  256. var materialSelfTotal float64 = 0 //床位部分项目自费
  257. var materialInscpTotal float64 = 0 //床位部分项目自费
  258. var westernMedicineCostTotal float64 = 0 //西药费
  259. var westernMedicineCostSelfTotal float64 = 0 //西药费
  260. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  261. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  262. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  263. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  264. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  265. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  266. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  267. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  268. var checkCostTotal float64 = 0 //检查费
  269. var checkCostSelfTotal float64 = 0 //检查费
  270. var checkCostPartSelfTotal float64 = 0 //检查费
  271. var checkSelfTotal float64 = 0 //床位部分项目自费
  272. var checkInscpTotal float64 = 0 //床位部分项目自费
  273. var laboratoryCostTotal float64 = 0 //化验费
  274. var laboratoryCostSelfTotal float64 = 0 //化验费
  275. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  276. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  277. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  278. var treatCostTotal float64 = 0 //治疗费用
  279. var treatCostSelfTotal float64 = 0 //治疗费用
  280. var treatCostPartSelfTotal float64 = 0 //治疗费用
  281. var treatSelfTotal float64 = 0 //床位部分项目自费
  282. var treatInscpTotal float64 = 0 //床位部分项目自费
  283. decimal.DivisionPrecision = 2
  284. for _, item := range orderInfos {
  285. if item.MedChrgitmType == "01" { //床位费
  286. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  287. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  288. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  289. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  290. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  291. }
  292. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  293. if item.MedChrgitmType == "03" { //检查费
  294. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  295. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  296. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  297. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  298. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  299. }
  300. } else {
  301. if item.MedChrgitmType == "03" { //检查费
  302. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  306. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  307. }
  308. }
  309. if item.MedChrgitmType == "04" { //化验费
  310. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  311. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  312. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  313. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  314. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  315. }
  316. if item.MedChrgitmType == "05" { //治疗费
  317. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  318. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  319. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  320. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  321. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  322. }
  323. if item.MedChrgitmType == "06" { //手术费
  324. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  325. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  326. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  327. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  328. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  331. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  335. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  336. }
  337. if item.MedChrgitmType == "09" { //西药费
  338. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  339. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  340. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  341. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  342. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  343. }
  344. if item.MedChrgitmType == "11" { //中成费
  345. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  346. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  347. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  348. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  349. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  350. }
  351. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  352. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  353. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  354. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  355. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  356. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  357. }
  358. }
  359. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  360. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  361. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  362. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  363. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  364. var doctor_name string
  365. if roles.ID == 0 {
  366. doctor_name = "管理员"
  367. } else {
  368. doctor_name = roles.UserName
  369. }
  370. yiliao_leibie := ""
  371. switch order.MedType {
  372. case "11":
  373. yiliao_leibie = "普通门诊"
  374. break
  375. case "12":
  376. yiliao_leibie = "门诊挂号"
  377. break
  378. case "13":
  379. yiliao_leibie = "急诊"
  380. break
  381. case "14":
  382. yiliao_leibie = "门诊特殊病"
  383. break
  384. case "15":
  385. yiliao_leibie = "门诊统筹"
  386. break
  387. case "16":
  388. yiliao_leibie = "门诊慢性病"
  389. break
  390. case "21":
  391. yiliao_leibie = "普通住院"
  392. break
  393. }
  394. var newOrder models.Orders
  395. newOrder.Diagnosis = name
  396. newOrder.OrderInfos = orderInfos
  397. newOrder.Number = order.MdtrtId
  398. newOrder.Date = order.SettleAccountsDate
  399. newOrder.ChargeAdmin = charge_admin
  400. newOrder.PrintorAdmin = printor_admin
  401. newOrder.Order = order
  402. newOrder.BedCostTotal = bedCostTotal
  403. newOrder.BedCostSelfTotal = bedCostSelfTotal
  404. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  405. newOrder.BedSelfTotal = bedSelfTotal
  406. newOrder.BedInscpTotal = bedInscpTotal
  407. newOrder.OperationCostTotal = operationCostTotal
  408. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  409. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  410. newOrder.OperationSelfTotal = operationSelfTotal
  411. newOrder.OperationInscpTotal = operationInscpTotal
  412. newOrder.OtherCostTotal = otherCostTotal
  413. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  414. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  415. newOrder.OtherSelfTotal = otherSelfTotal
  416. newOrder.OtherInscpTotal = otherInscpTotal
  417. newOrder.MaterialCostTotal = materialCostTotal
  418. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  419. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  420. newOrder.MaterialSelfTotal = materialSelfTotal
  421. newOrder.MaterialInscpTotal = materialInscpTotal
  422. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  423. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  424. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  425. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  426. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  427. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  428. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  429. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  430. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  431. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  432. newOrder.CheckCostTotal = checkCostTotal
  433. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  434. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  435. newOrder.CheckSelfTotal = checkSelfTotal
  436. newOrder.CheckInscpTotal = checkInscpTotal
  437. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  438. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  439. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  440. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  441. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  442. newOrder.TreatCostTotal = treatCostTotal
  443. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  444. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  445. newOrder.TreatSelfTotal = treatSelfTotal
  446. newOrder.TreatInscpTotal = treatInscpTotal
  447. newOrder.DoctorInfo = doctor_info
  448. newOrder.DoctorName = doctor_name
  449. newOrder.HealthCardNo = order.PsnNo
  450. newOrder.YiliaoLeibie = yiliao_leibie
  451. newOrder.Patient = patient
  452. newOrder.OrgName = miConfig.OrgName
  453. newOrder.OrgCode = miConfig.Code
  454. newOrder.OrderNumber = order.Number
  455. newOrder.HisPatient = his
  456. newOrder.DiaConfig = dia_config
  457. newOrders = append(newOrders, newOrder)
  458. }
  459. c.ServeSuccessJSON(map[string]interface{}{
  460. "orders": newOrders,
  461. })
  462. }
  463. func (c *HisApiController) GetTestOrder() {
  464. order_id, _ := c.GetInt64("order_id")
  465. admin_user_id, _ := c.GetInt64("admin_user_id")
  466. adminUser := c.GetAdminUserInfo()
  467. order, _ := service.GetHisOrderByID(order_id)
  468. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  469. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  470. orderInfos = append(orderInfos, orderInfos_two...)
  471. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  472. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  473. var dia_config []*models.HisXtDiagnoseConfig
  474. var name string
  475. var bedCostTotal float64 = 0 //床位总费
  476. var bedCostSelfTotal float64 = 0 //床位自费
  477. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  478. var bedSelfTotal float64 = 0 //床位部分项目自费
  479. var bedInscpTotal float64 = 0 //床位部分项目自费
  480. var operationCostTotal float64 = 0 //手术费
  481. var operationCostSelfTotal float64 = 0 //手术费
  482. var operationCostPartSelfTotal float64 = 0 //手术费
  483. var operationSelfTotal float64 = 0 //床位部分项目自费
  484. var operationInscpTotal float64 = 0 //床位部分项目自费
  485. var otherCostTotal float64 = 0 //其他费用
  486. var otherCostSelfTotal float64 = 0 //其他费用
  487. var otherCostPartSelfTotal float64 = 0 //其他费用
  488. var otherSelfTotal float64 = 0 //床位部分项目自费
  489. var otherInscpTotal float64 = 0 //床位部分项目自费
  490. var materialCostTotal float64 = 0 //材料费
  491. var materialCostSelfTotal float64 = 0 //材料费
  492. var materialCostPartSelfTotal float64 = 0 //材料费
  493. var materialSelfTotal float64 = 0 //床位部分项目自费
  494. var materialInscpTotal float64 = 0 //床位部分项目自费
  495. var westernMedicineCostTotal float64 = 0 //西药费
  496. var westernMedicineCostSelfTotal float64 = 0 //西药费
  497. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  498. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  499. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  500. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  501. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  502. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  503. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  504. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  505. var checkCostTotal float64 = 0 //检查费
  506. var checkCostSelfTotal float64 = 0 //检查费
  507. var checkCostPartSelfTotal float64 = 0 //检查费
  508. var checkSelfTotal float64 = 0 //床位部分项目自费
  509. var checkInscpTotal float64 = 0 //床位部分项目自费
  510. var laboratoryCostTotal float64 = 0 //化验费
  511. var laboratoryCostSelfTotal float64 = 0 //化验费
  512. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  513. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  514. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  515. var treatCostTotal float64 = 0 //治疗费用
  516. var treatCostSelfTotal float64 = 0 //治疗费用
  517. var treatCostPartSelfTotal float64 = 0 //治疗费用
  518. var treatSelfTotal float64 = 0 //床位部分项目自费
  519. var treatInscpTotal float64 = 0 //床位部分项目自费
  520. decimal.DivisionPrecision = 2
  521. for _, item := range orderInfos {
  522. if item.MedChrgitmType == "01" { //床位费
  523. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  524. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  525. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  526. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  527. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  528. }
  529. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  530. if item.MedChrgitmType == "03" { //检查费
  531. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  532. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  533. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  534. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  535. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  536. }
  537. } else {
  538. if item.MedChrgitmType == "03" { //检查费
  539. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  540. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  541. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  543. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  544. }
  545. }
  546. if item.MedChrgitmType == "04" { //化验费
  547. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  548. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  549. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  550. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  551. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  552. }
  553. if item.MedChrgitmType == "05" { //治疗费
  554. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  555. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  556. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  557. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  558. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  559. }
  560. if item.MedChrgitmType == "06" { //手术费
  561. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  562. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  563. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  564. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  565. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  566. }
  567. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  568. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  569. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  570. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  571. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  572. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  573. }
  574. if item.MedChrgitmType == "09" { //西药费
  575. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  576. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  577. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  578. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  579. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  580. }
  581. if item.MedChrgitmType == "11" { //中成费
  582. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  583. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  584. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  585. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  586. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  587. }
  588. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  589. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  590. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  591. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  592. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  593. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  594. }
  595. }
  596. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  597. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  598. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  599. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  600. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  601. var doctor_name string
  602. if roles.ID == 0 {
  603. doctor_name = "管理员"
  604. } else {
  605. doctor_name = roles.UserName
  606. }
  607. yiliao_leibie := ""
  608. switch order.MedType {
  609. case "11":
  610. yiliao_leibie = "普通门诊"
  611. break
  612. case "12":
  613. yiliao_leibie = "门诊挂号"
  614. break
  615. case "13":
  616. yiliao_leibie = "急诊"
  617. break
  618. case "14":
  619. yiliao_leibie = "门诊特殊病"
  620. break
  621. case "15":
  622. yiliao_leibie = "门诊统筹"
  623. break
  624. case "16":
  625. yiliao_leibie = "门诊慢性病"
  626. break
  627. case "21":
  628. yiliao_leibie = "普通住院"
  629. break
  630. }
  631. c.ServeSuccessJSON(map[string]interface{}{
  632. "diagnosis": name,
  633. "order_infos": orderInfos,
  634. "number": order.MdtrtId,
  635. "date": order.SettleAccountsDate,
  636. "charge_admin": charge_admin,
  637. "printor_admin": printor_admin,
  638. "info": order,
  639. "order": order,
  640. "bedCostTotal": bedCostTotal,
  641. "bedCostSelfTotal": bedCostSelfTotal,
  642. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  643. "bedSelfTotal": bedSelfTotal,
  644. "bedInscpTotal": bedInscpTotal,
  645. "operationCostTotal": operationCostTotal,
  646. "operationCostSelfTotal": operationCostSelfTotal,
  647. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  648. "operationSelfTotal": operationSelfTotal,
  649. "operationInscpTotal": operationInscpTotal,
  650. "otherCostTotal": otherCostTotal,
  651. "otherCostSelfTotal": otherCostSelfTotal,
  652. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  653. "otherSelfTotal": otherSelfTotal,
  654. "otherInscpTotal": otherInscpTotal,
  655. "materialCostTotal": materialCostTotal,
  656. "materialCostSelfTotal": materialCostSelfTotal,
  657. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  658. "materialSelfTotal": materialSelfTotal,
  659. "materialInscpTotal": materialInscpTotal,
  660. "westernMedicineCostTotal": westernMedicineCostTotal,
  661. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  662. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  663. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  664. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  665. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  666. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  667. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  668. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  669. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  670. "checkCostTotal": checkCostTotal,
  671. "checkCostSelfTotal": checkCostSelfTotal,
  672. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  673. "checkSelfTotal": checkSelfTotal,
  674. "checkInscpTotal": checkInscpTotal,
  675. "laboratoryCostTotal": laboratoryCostTotal,
  676. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  677. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  678. "laboratorySelfTotal": laboratorySelfTotal,
  679. "laboratoryInscpTotal": laboratoryInscpTotal,
  680. "treatCostTotal": treatCostTotal,
  681. "treatCostSelfTotal": treatCostSelfTotal,
  682. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  683. "treatSelfTotal": treatSelfTotal,
  684. "treatInscpTotal": treatInscpTotal,
  685. "doctor_info": doctor_info,
  686. "doctor_name": doctor_name,
  687. "health_card_no": order.PsnNo,
  688. "yiliao_leibie": yiliao_leibie,
  689. "patient": patient,
  690. "org_name": miConfig.OrgName,
  691. "org_code": miConfig.Code,
  692. "order_number": order.Number,
  693. "his_hospital": his_hospital,
  694. "dia_config": dia_config,
  695. })
  696. }
  697. func (c *PublicApiController) GetBaiLinExportData() {
  698. data := service.GetBaiLinOrderData()
  699. fmt.Println(len(data))
  700. var new_data []*models.NewCustomHisOrder
  701. for _, item := range data {
  702. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  703. new_data = append(new_data, item)
  704. }
  705. }
  706. fmt.Println(len(new_data))
  707. c.ServeSuccessJSON(map[string]interface{}{
  708. "list": new_data,
  709. })
  710. }
  711. func (c *HisApiController) GetHisUnChargePatientList() {
  712. record_date := c.GetString("record_date")
  713. sch_type, _ := c.GetInt64("sch_type")
  714. timeLayout := "2006-01-02"
  715. loc, _ := time.LoadLocation("Local")
  716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  717. if err != nil {
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  719. return
  720. }
  721. recordDateTime := theTime.Unix()
  722. adminInfo := c.GetAdminUserInfo()
  723. var tempPatients []*service.NewTempPatients
  724. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  725. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  726. var patients []*service.NewTempPatients
  727. var patients_two []*service.NewTempPatients
  728. for _, item := range tempPatients {
  729. //过滤掉没挂号的和没开处方的
  730. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  731. patients = append(patients, item)
  732. }
  733. //过滤掉没挂号的
  734. if len(item.HisPatient) > 0 {
  735. patients_two = append(patients_two, item)
  736. }
  737. }
  738. c.ServeSuccessJSON(map[string]interface{}{
  739. "list": patients,
  740. "list_two": patients_two,
  741. })
  742. }
  743. func (c *HisApiController) GetPrivateExpensesOrder() {
  744. //id, _ := c.GetInt64("id")
  745. //record_time := c.GetString("record_time")
  746. order_id, _ := c.GetInt64("order_id")
  747. admin_user_id, _ := c.GetInt64("admin_user_id")
  748. //timeLayout := "2006-01-02"
  749. //loc, _ := time.LoadLocation("Local")
  750. //
  751. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  752. //if err != nil {
  753. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  754. // return
  755. //}
  756. //recordDateTime := theTime.Unix()
  757. adminUser := c.GetAdminUserInfo()
  758. order, _ := service.GetHisOrderByID(order_id)
  759. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  760. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  761. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  762. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  763. //var config []*models.HisXtDiagnoseConfig
  764. var name string
  765. if order.PType == 1 {
  766. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  767. for _, item := range diagnosis_ids {
  768. id, _ := strconv.ParseInt(item, 10, 64)
  769. diagnosisConfig, _ := service.FindDiagnoseById(id)
  770. if len(name) == 0 {
  771. name = diagnosisConfig.ClassName
  772. } else {
  773. name = name + "," + diagnosisConfig.ClassName
  774. }
  775. }
  776. } else {
  777. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  778. for _, item := range diagnosis_ids {
  779. id, _ := strconv.ParseInt(item, 10, 64)
  780. diagnosisConfig, _ := service.FindDiagnoseById(id)
  781. if len(name) == 0 {
  782. name = diagnosisConfig.ClassName
  783. } else {
  784. name = name + "," + diagnosisConfig.ClassName
  785. }
  786. }
  787. }
  788. var bedCostTotal float64 = 0 //床位总费
  789. //var bedCostSelfTotal float64 = 0 //床位自费
  790. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  791. var operationCostTotal float64 = 0 //手术费
  792. //var operationCostSelfTotal float64 = 0 //手术费
  793. var operationCostPartSelfTotal float64 = 0 //手术费
  794. var otherCostTotal float64 = 0 //其他费用
  795. //var otherCostSelfTotal float64 = 0 //其他费用
  796. var otherCostPartSelfTotal float64 = 0 //其他费用
  797. var materialCostTotal float64 = 0 //材料费
  798. //var materialCostSelfTotal float64 = 0 //材料费
  799. var materialCostPartSelfTotal float64 = 0 //材料费
  800. var westernMedicineCostTotal float64 = 0 //西药费
  801. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  802. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  803. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  804. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  805. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  806. var checkCostTotal float64 = 0 //检查费
  807. //var checkCostSelfTotal float64 = 0 //检查费
  808. var checkCostPartSelfTotal float64 = 0 //检查费
  809. var laboratoryCostTotal float64 = 0 //化验费
  810. //var laboratoryCostSelfTotal float64 = 0 //化验费
  811. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  812. var treatCostTotal float64 = 0 //治疗费用
  813. //var treatCostSelfTotal float64 = 0 //治疗费用
  814. var treatCostPartSelfTotal float64 = 0 //治疗费用
  815. var zhenChaCostTotal float64 = 0 //其他费用
  816. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  817. decimal.DivisionPrecision = 2
  818. for _, item := range orderInfos {
  819. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  820. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  821. item.MedChrgitmType = "09"
  822. }
  823. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  824. if item.HisPrescriptionProject.Type == 2 {
  825. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  826. fmt.Println("CostClassify")
  827. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  828. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  829. case 0:
  830. item.MedChrgitmType = "0"
  831. break
  832. case 1:
  833. item.MedChrgitmType = "14"
  834. break
  835. case 2:
  836. item.MedChrgitmType = "05"
  837. break
  838. case 3:
  839. item.MedChrgitmType = "03"
  840. break
  841. case 4:
  842. item.MedChrgitmType = "03"
  843. break
  844. case 5:
  845. item.MedChrgitmType = "08"
  846. break
  847. case 6:
  848. item.MedChrgitmType = "14"
  849. break
  850. case 7:
  851. item.MedChrgitmType = "14"
  852. break
  853. case 8:
  854. item.MedChrgitmType = "03"
  855. break
  856. case 9:
  857. item.MedChrgitmType = "14"
  858. break
  859. case 10:
  860. item.MedChrgitmType = "14"
  861. break
  862. case 11:
  863. item.MedChrgitmType = "06"
  864. break
  865. case 12:
  866. item.MedChrgitmType = "12"
  867. break
  868. case 13:
  869. item.MedChrgitmType = "01"
  870. break
  871. case 14:
  872. item.MedChrgitmType = "04"
  873. break
  874. case 15:
  875. item.MedChrgitmType = "14"
  876. break
  877. }
  878. } else {
  879. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  880. case 1:
  881. item.MedChrgitmType = "14"
  882. break
  883. case 2:
  884. item.MedChrgitmType = "05"
  885. break
  886. case 3:
  887. item.MedChrgitmType = "04"
  888. break
  889. case 4:
  890. item.MedChrgitmType = "14"
  891. break
  892. case 5:
  893. item.MedChrgitmType = "08"
  894. break
  895. case 6:
  896. item.MedChrgitmType = "14"
  897. break
  898. case 7:
  899. item.MedChrgitmType = "14"
  900. break
  901. case 8:
  902. item.MedChrgitmType = "03"
  903. break
  904. case 9:
  905. item.MedChrgitmType = "14"
  906. break
  907. }
  908. }
  909. } else if item.HisPrescriptionProject.Type == 3 {
  910. item.MedChrgitmType = "08"
  911. }
  912. }
  913. }
  914. order.PsnCashPay = order.MedfeeSumamt
  915. for _, item := range orderInfos {
  916. if item.MedChrgitmType == "01" { //床位费
  917. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  918. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  919. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  920. }
  921. if item.MedChrgitmType == "02" { //诊察费
  922. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  923. //zhenChaCostSelfTotal = zhenChaCostTotal
  924. }
  925. if item.MedChrgitmType == "03" { //检查费
  926. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  927. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  928. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  929. }
  930. if item.MedChrgitmType == "02" { //检查费
  931. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  932. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  933. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  934. }
  935. if item.MedChrgitmType == "04" { //化验费
  936. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  937. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  938. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  939. }
  940. if item.MedChrgitmType == "05" { //治疗费
  941. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  942. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  943. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  944. }
  945. if item.MedChrgitmType == "06" { //手术费
  946. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  947. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  948. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  949. }
  950. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  951. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  952. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  953. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  954. }
  955. if item.MedChrgitmType == "09" { //西药费
  956. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  957. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  958. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  959. }
  960. if item.MedChrgitmType == "11" { //中成费
  961. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  962. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  963. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  964. }
  965. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  966. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  967. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  968. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  969. }
  970. }
  971. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  972. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  973. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  974. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "patient": patient,
  977. "order_infos": orderInfos,
  978. "diagnosis": name,
  979. "bedCostTotal": bedCostTotal,
  980. "bedCostSelfTotal": bedCostTotal,
  981. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  982. "operationCostTotal": operationCostTotal,
  983. "operationCostSelfTotal": operationCostTotal,
  984. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  985. "otherCostTotal": otherCostTotal,
  986. "otherCostSelfTotal": otherCostTotal,
  987. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  988. "materialCostTotal": materialCostTotal,
  989. "materialCostSelfTotal": materialCostTotal,
  990. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  991. "westernMedicineCostTotal": westernMedicineCostTotal,
  992. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  993. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  994. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  995. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  996. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  997. "checkCostTotal": checkCostTotal,
  998. "checkCostSelfTotal": checkCostTotal,
  999. "zhenChaCostTotal": zhenChaCostTotal,
  1000. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1001. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1002. "laboratoryCostTotal": laboratoryCostTotal,
  1003. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1004. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1005. "treatCostTotal": treatCostTotal,
  1006. "treatCostSelfTotal": treatCostTotal,
  1007. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1008. "charge_admin": charge_admin,
  1009. "printor_admin": printor_admin,
  1010. "org_name": org.OrgName,
  1011. "org_code": miConfig.Code,
  1012. "name": patient.Name,
  1013. "number": order.MdtrtId,
  1014. "date": order.SettleAccountsDate,
  1015. "info": order,
  1016. "his_hospital": his_hospital,
  1017. "his": his,
  1018. })
  1019. }
  1020. func (c *HisApiController) RefudDetail() {
  1021. order_id, _ := c.GetInt64("order_id")
  1022. order, _ := service.GetHisOrderByID(order_id)
  1023. adminUser := c.GetAdminUserInfo()
  1024. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1025. c.ServeSuccessJSON(map[string]interface{}{
  1026. "msg": "撤销成功",
  1027. })
  1028. }
  1029. func (c *HisApiController) Sscard() {
  1030. //r := CardInit()
  1031. //if r == 0 {
  1032. // GetBaseInfo()
  1033. //}
  1034. //c.ServeSuccessJSON(map[string]interface{}{
  1035. // "list": "11",
  1036. //})
  1037. }
  1038. func GetBaseInfo() error {
  1039. //handle := syscall.MustLoadDLL("SSCard.dll")
  1040. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1041. //
  1042. //str := make([]byte, 256)
  1043. //str1 := make([]byte, 256)
  1044. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1045. //if ferr != nil {
  1046. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1047. // return ferr
  1048. //}
  1049. //
  1050. //fmt.Println(string(str))
  1051. //
  1052. //fmt.Println(r)
  1053. return nil
  1054. }
  1055. func CardInit() int {
  1056. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1057. //add := DllTestDef.MustFindProc("Init")
  1058. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1059. //if err != nil {
  1060. // fmt.Println("SSCard的运算结果为:", ret)
  1061. //}
  1062. //result := int(ret)
  1063. return 0
  1064. }
  1065. func IntPtr(n int) uintptr {
  1066. return uintptr(n)
  1067. }
  1068. func StrPtr(s string) uintptr {
  1069. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1070. }
  1071. func (c *HisApiController) GetHisPatientList() {
  1072. //types, _ := c.GetInt64("type", 0)
  1073. record_date := c.GetString("record_date")
  1074. sch_type, _ := c.GetInt64("sch_type")
  1075. timeLayout := "2006-01-02"
  1076. loc, _ := time.LoadLocation("Local")
  1077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1078. if err != nil {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1080. return
  1081. }
  1082. recordDateTime := theTime.Unix()
  1083. adminInfo := c.GetAdminUserInfo()
  1084. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1085. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1086. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1087. //获取当前用户的信息
  1088. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1089. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1090. //获取所有科室信息
  1091. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1092. c.ServeSuccessJSON(map[string]interface{}{
  1093. "list": patients,
  1094. "list_two": patients_two,
  1095. "info": adminUserInfo,
  1096. "doctors": doctors,
  1097. "department": department,
  1098. })
  1099. }
  1100. type CustomTemplate struct {
  1101. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1102. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1103. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1104. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1105. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1106. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1107. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1108. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1109. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1110. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1111. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1112. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1113. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1114. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1115. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1116. }
  1117. func (c *HisApiController) GetHisPatientInfo() {
  1118. patient_id, _ := c.GetInt64("patient_id")
  1119. his_patient_id, _ := c.GetInt64("his_patient_id")
  1120. record_date := c.GetString("record_date")
  1121. number := c.GetString("number")
  1122. //start_time := c.GetString("start_time")
  1123. //end_time := c.GetString("end_time")
  1124. p_type, _ := c.GetInt64("p_type")
  1125. timeLayout := "2006-01-02"
  1126. loc, _ := time.LoadLocation("Local")
  1127. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1128. if err != nil {
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1130. return
  1131. }
  1132. recordDateTime := theTime.Unix()
  1133. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1134. //if err != nil {
  1135. //
  1136. //}
  1137. //startRecordDateTime := startTime.Unix()
  1138. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1139. //if err != nil {
  1140. //
  1141. //}
  1142. //endRecordDateTime := endTime.Unix()
  1143. admin := c.GetAdminUserInfo()
  1144. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1145. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1146. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1147. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1148. var prescriptions []*models.HisPrescription
  1149. var last_prescriptions []*models.HisPrescription
  1150. var sch_prescriptions []CustomTemplate
  1151. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1152. if p_type == 1 { //住院
  1153. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1154. for _, item := range prescriptions {
  1155. for _, subItem := range item.HisDoctorAdviceInfo {
  1156. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1157. if info.RetailPrice > 0 {
  1158. subItem.Drug.MinPrice = info.RetailPrice
  1159. }
  1160. }
  1161. }
  1162. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1163. } else { //门诊
  1164. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1165. for _, item := range prescriptions {
  1166. for _, subItem := range item.HisDoctorAdviceInfo {
  1167. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1168. if info.RetailPrice > 0 {
  1169. subItem.Drug.MinPrice = info.RetailPrice
  1170. }
  1171. }
  1172. }
  1173. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1174. }
  1175. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1176. if sch.ID > 0 {
  1177. var week string
  1178. t := time.Now()
  1179. switch t.Weekday().String() {
  1180. case "Monday":
  1181. week = "周一"
  1182. break
  1183. case "Tuesday":
  1184. week = "周二"
  1185. break
  1186. case "Wednesday":
  1187. week = "周三"
  1188. break
  1189. case "Thursday":
  1190. week = "周四"
  1191. break
  1192. case "Friday":
  1193. week = "周五"
  1194. break
  1195. case "Saturday":
  1196. week = "周六"
  1197. break
  1198. case "Sunday":
  1199. week = "周日"
  1200. break
  1201. }
  1202. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1203. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1204. //根据推送频率组装新的数组
  1205. for _, item := range temp_sch_prescriptions {
  1206. var cus CustomTemplate
  1207. cus.ID = item.ID
  1208. cus.UserOrgId = item.UserOrgId
  1209. cus.PatientId = item.PatientId
  1210. cus.MedType = item.MedType
  1211. cus.RecordDate = item.RecordDate
  1212. cus.Type = item.Type
  1213. cus.PType = item.PType
  1214. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1215. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1216. if subItem.FrequencyType == 1 { //每次必推
  1217. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1218. }
  1219. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1220. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1221. }
  1222. if subItem.FrequencyType == 2 { //按照天数频率
  1223. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1224. now := p.Unix()
  1225. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1226. dayStr2 := "-" + dayStr
  1227. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1228. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1229. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1230. if len(advices) == 0 {
  1231. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1232. }
  1233. }
  1234. }
  1235. }
  1236. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1237. if subItem.Type == 2 {
  1238. if subItem.XtHisProject.MedicalStatus != 1 {
  1239. if subItem.FrequencyType == 1 {
  1240. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1241. }
  1242. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1243. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1244. }
  1245. if subItem.FrequencyType == 2 {
  1246. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1247. now := p.Unix()
  1248. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1249. dayStr2 := "-" + dayStr
  1250. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1251. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1252. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1253. if len(projects) == 0 {
  1254. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1255. }
  1256. }
  1257. }
  1258. } else if subItem.Type == 3 {
  1259. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1260. if subItem.FrequencyType == 1 {
  1261. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1262. }
  1263. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1264. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1265. }
  1266. if subItem.FrequencyType == 2 {
  1267. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1268. now := p.Unix()
  1269. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1270. dayStr2 := "-" + dayStr
  1271. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1272. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1273. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1274. if len(projects) == 0 {
  1275. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1276. }
  1277. }
  1278. }
  1279. }
  1280. }
  1281. sch_prescriptions = append(sch_prescriptions, cus)
  1282. }
  1283. for _, item := range sch_prescriptions {
  1284. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1285. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1286. }
  1287. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1288. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1289. }
  1290. }
  1291. }
  1292. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1293. if config.ID > 0 && config.IsOpen == 1 {
  1294. for _, item := range sch_prescriptions {
  1295. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1296. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1297. if info.RetailPrice > 0 {
  1298. subItem.Drug.MinPrice = info.RetailPrice
  1299. }
  1300. }
  1301. }
  1302. }
  1303. if config.ID > 0 && config.IsOpen == 1 {
  1304. for _, item := range sch_prescriptions {
  1305. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1306. if subItem.Type == 3 {
  1307. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1308. if info.Price > 0 {
  1309. subItem.GoodInfo.PackingPrice = info.Price
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1316. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1317. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1318. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1319. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1320. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1321. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1322. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1323. //获取所有科室信息
  1324. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1325. c.ServeSuccessJSON(map[string]interface{}{
  1326. "his_info": his_patient_info,
  1327. "xt_info": xt_patient_info,
  1328. "prescription": prescriptions,
  1329. "case_history": case_history,
  1330. "info": patientPrescriptionInfo,
  1331. //"month_prescriptions": monthPrescriptions,
  1332. "order": order,
  1333. "doctors": doctors,
  1334. "department": department,
  1335. "sch_prescriptions": sch_prescriptions,
  1336. "last_prescriptions": last_prescriptions,
  1337. "schedule": sch,
  1338. "count": count,
  1339. "drugStockConfig": drugStockConfig,
  1340. "last_info": lastPatientPrescriptionInfo,
  1341. })
  1342. return
  1343. }
  1344. func (c *HisApiController) GetHisPrescriptionConfig() {
  1345. adminInfo := c.GetAdminUserInfo()
  1346. //获取医嘱模版
  1347. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1348. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1349. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1350. //获取所有基础药
  1351. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1352. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1353. if config.ID > 0 && config.IsOpen == 1 {
  1354. for _, item := range drugs {
  1355. var index = 0
  1356. for _, subItem := range item.OtherDrugWarehouseInfo {
  1357. if index == 0 {
  1358. index = index + 1
  1359. if subItem.RetailPrice > 0 {
  1360. item.MinPrice = subItem.RetailPrice
  1361. }
  1362. }
  1363. }
  1364. }
  1365. }
  1366. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1367. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1368. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1369. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1370. //获取所有科室信息
  1371. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1372. //获取诊断信息
  1373. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1374. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1375. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1376. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1377. //获取是否开启保存耗材出库的开关
  1378. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1379. c.ServeSuccessJSON(map[string]interface{}{
  1380. "drugs": drugs,
  1381. "advices_template": advices,
  1382. "drugways": drugways,
  1383. "efs": efs,
  1384. "doctors": doctors,
  1385. "department": department,
  1386. "sick": sick,
  1387. "additions": additions,
  1388. "diagnose": diagnose,
  1389. "manufacturers": manufacturers,
  1390. "goodOutOpen": goodOutOpen,
  1391. "patientDiagnose": patientDiagnose,
  1392. })
  1393. }
  1394. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1395. //获取所有基础药
  1396. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1397. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1398. if config.ID > 0 && config.IsOpen == 1 {
  1399. for _, item := range drugs {
  1400. var index = 0
  1401. for _, subItem := range item.OtherDrugWarehouseInfo {
  1402. if index == 0 {
  1403. index = index + 1
  1404. if subItem.RetailPrice > 0 {
  1405. item.MinPrice = subItem.RetailPrice
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1412. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1413. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1414. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1415. //获取所有科室信息
  1416. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1417. //获取诊断信息
  1418. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1419. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1420. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1421. //获取是否开启保存耗材出库的开关
  1422. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1423. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1424. c.ServeSuccessJSON(map[string]interface{}{
  1425. "drugs": drugs,
  1426. "advices_template": advices,
  1427. "drugways": drugways,
  1428. "efs": efs,
  1429. "doctors": doctors,
  1430. "department": department,
  1431. "sick": sick,
  1432. "additions": additions,
  1433. "diagnose": diagnose,
  1434. "manufacturers": manufacturers,
  1435. "goodOutOpen": goodOutOpen,
  1436. "patientDiagnose": patientDiagnose,
  1437. })
  1438. }
  1439. }
  1440. func (c *HisApiController) CreateHisPrescription() {
  1441. record_date := c.GetString("record_date")
  1442. patient_id, _ := c.GetInt64("patient_id")
  1443. reg_type, _ := c.GetInt64("reg_type")
  1444. diagnose := c.GetString("diagnose")
  1445. sick_type, _ := c.GetInt64("sick_type")
  1446. sick_history := c.GetString("sick_history")
  1447. doctor_id, _ := c.GetInt64("doctor", 0)
  1448. department, _ := c.GetInt64("department", 0)
  1449. his_patient_id, _ := c.GetInt64("his_patient_id")
  1450. p_type, _ := c.GetInt64("p_type")
  1451. patient_diagnose := c.GetString("patient_diagnose")
  1452. dataBody := make(map[string]interface{}, 0)
  1453. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1454. if err != nil {
  1455. utils.ErrorLog(err.Error())
  1456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1457. return
  1458. }
  1459. timeLayout := "2006-01-02"
  1460. loc, _ := time.LoadLocation("Local")
  1461. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1462. if err != nil {
  1463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1464. return
  1465. }
  1466. adminInfo := c.GetAdminUserInfo()
  1467. recordDateTime := theTime.Unix()
  1468. //查询默认出库仓库库存
  1469. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1470. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1471. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1472. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1473. if len(lists) == 1 {
  1474. his_patient_id = lists[0].ID
  1475. }
  1476. }
  1477. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1478. //保存处方出库
  1479. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1480. //自动出库
  1481. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1482. //耗材保存处方出库
  1483. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1484. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1485. //已发药和已收费限制逻辑
  1486. isMidicine := false
  1487. isCharge := false
  1488. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1489. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1490. if len(prescriptions) > 0 {
  1491. for _, item := range prescriptions {
  1492. items := item.(map[string]interface{})
  1493. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1494. utils.ErrorLog("id")
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1496. return
  1497. }
  1498. id := int64(items["id"].(float64))
  1499. if id > 0 {
  1500. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1501. if err != nil {
  1502. if new_prescription.OrderStatus == 4 {
  1503. isCharge = true
  1504. }
  1505. }
  1506. }
  1507. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1508. advices := items["advices"].([]interface{})
  1509. if len(advices) > 0 {
  1510. for _, advice := range advices {
  1511. var adviceId int64
  1512. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1513. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1514. }
  1515. if adviceId > 0 {
  1516. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1517. if err == nil {
  1518. if his_advice_info.IsMedicine == 1 {
  1519. isMidicine = true
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. if isMidicine == true {
  1530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1531. return
  1532. }
  1533. if isCharge == true {
  1534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1535. return
  1536. }
  1537. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1538. //药品发药出库
  1539. if pharmacyConfig.IsOpen == 1 {
  1540. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1541. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1542. if len(prescriptions) > 0 {
  1543. for _, item := range prescriptions {
  1544. items := item.(map[string]interface{})
  1545. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1546. advices := items["advices"].([]interface{})
  1547. if len(advices) > 0 {
  1548. for _, advice := range advices {
  1549. var drug_id int64
  1550. var prescribing_number float64
  1551. var prescribingNumberUnit string
  1552. var adviceId int64
  1553. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1554. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1555. }
  1556. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1557. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1558. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1559. }
  1560. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1561. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1562. }
  1563. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1564. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1565. }
  1566. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1567. if drug.ID == 0 {
  1568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1569. return
  1570. }
  1571. //查询药品的所有库存
  1572. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1573. var total_count int64
  1574. for _, it := range list {
  1575. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1576. }
  1577. totals := strconv.FormatInt(total_count, 10)
  1578. //查询该药品是否存在开药记录
  1579. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1580. fmt.Println("wooooooooooooo", advicelist.ID)
  1581. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1582. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1583. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1584. //新增处方
  1585. if advicelist.ID == 0 {
  1586. all_count, _ := strconv.ParseFloat(totals, 64)
  1587. if prescribingNumberUnit == drug.MinUnit {
  1588. fmt.Println("prescribing_number", prescribing_number)
  1589. fmt.Println("all_count", all_count)
  1590. if drug.IsUse != 1 {
  1591. if drug.IsProject == 0 || drug.IsProject == 2 {
  1592. if all_count == 0 {
  1593. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1594. return
  1595. }
  1596. if prescribing_number > all_count {
  1597. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1598. return
  1599. }
  1600. }
  1601. }
  1602. }
  1603. if prescribingNumberUnit == drug.MaxUnit {
  1604. num := prescribing_number * float64(drug.MinNumber)
  1605. if drug.IsUse != 1 {
  1606. if drug.IsProject == 0 || drug.IsProject == 2 {
  1607. if all_count == 0 {
  1608. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1609. return
  1610. }
  1611. if num > all_count {
  1612. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1613. return
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1620. if drugOutConfig.IsOpen != 1 {
  1621. //修改处方
  1622. for _, advice := range advices {
  1623. var drug_id int64
  1624. var prescribing_number float64
  1625. var prescribingNumberUnit string
  1626. var prescribingNumber string
  1627. var adviceId int64
  1628. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1629. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1630. }
  1631. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1632. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1633. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1634. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1635. }
  1636. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1637. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1638. }
  1639. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1640. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1641. }
  1642. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1643. if drug.ID == 0 {
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. //查询药品的所有库存
  1648. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1649. var total_count int64
  1650. for _, it := range list {
  1651. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1652. }
  1653. totals := strconv.FormatInt(total_count, 10)
  1654. //查询该药品是否存在开药记录
  1655. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1656. //新增处方
  1657. if advicelist.ID == 0 {
  1658. all_count, _ := strconv.ParseFloat(totals, 64)
  1659. if prescribingNumberUnit == drug.MinUnit {
  1660. if drug.IsUse != 1 {
  1661. if drug.IsProject == 0 || drug.IsProject == 2 {
  1662. if all_count == 0 {
  1663. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1664. return
  1665. }
  1666. if prescribing_number > all_count {
  1667. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1668. return
  1669. }
  1670. }
  1671. }
  1672. } else {
  1673. if prescribingNumberUnit == drug.MaxUnit {
  1674. num := prescribing_number * float64(drug.MinNumber)
  1675. if drug.IsUse != 1 {
  1676. if drug.IsProject == 0 || drug.IsProject == 2 {
  1677. if all_count == 0 {
  1678. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1679. return
  1680. }
  1681. if num > all_count {
  1682. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1683. return
  1684. }
  1685. }
  1686. }
  1687. }
  1688. }
  1689. }
  1690. //修改处方
  1691. if advicelist.ID > 0 {
  1692. var device_number int64
  1693. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1694. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1695. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1696. device_number = prescribingNumberInt * drug.MinNumber
  1697. }
  1698. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1699. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1700. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1701. device_number = prescribingNumberInt
  1702. }
  1703. var number_count int64
  1704. if prescribingNumberUnit == drug.MaxUnit {
  1705. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1706. number_count = prescribingNumberInt * drug.MinNumber
  1707. }
  1708. if prescribingNumberUnit == drug.MinUnit {
  1709. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1710. number_count = prescribingNumberInt
  1711. }
  1712. //如果修改的数量大于之前修改的数量
  1713. if (number_count - device_number) > 0 {
  1714. //如果修改的差数量 大于库存数量
  1715. if drug.IsUse != 1 {
  1716. if (number_count - device_number) > total_count {
  1717. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1718. return
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. }
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. //已发药和已收费限制逻辑
  1733. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1734. //校验库存总量
  1735. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1736. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1737. if len(prescriptions) > 0 {
  1738. for _, item := range prescriptions {
  1739. items := item.(map[string]interface{})
  1740. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1741. advices := items["advices"].([]interface{})
  1742. if len(advices) > 0 {
  1743. for _, advice := range advices {
  1744. var drug_id int64
  1745. var prescribing_number float64
  1746. var prescribingNumberUnit string
  1747. var adviceId int64
  1748. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1749. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1750. }
  1751. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1752. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1753. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1754. }
  1755. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1756. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1757. }
  1758. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1759. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1760. }
  1761. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1762. if drug.ID == 0 {
  1763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1764. return
  1765. }
  1766. //查询药品的所有库存
  1767. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1768. var total_count int64
  1769. for _, it := range list {
  1770. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1771. }
  1772. totals := strconv.FormatInt(total_count, 10)
  1773. //查询该药品是否存在开药记录
  1774. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1775. //查询最新批次库存
  1776. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1777. var batch_number_count int64
  1778. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1779. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1780. //新增处方
  1781. if advicelist.ID == 0 {
  1782. all_count, _ := strconv.ParseFloat(totals, 64)
  1783. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1784. if prescribingNumberUnit == drug.MinUnit {
  1785. if drug.IsUse != 1 {
  1786. if drug.IsProject == 0 || drug.IsProject == 2 {
  1787. if all_count == 0 {
  1788. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1789. return
  1790. }
  1791. if prescribing_number > all_count {
  1792. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1793. return
  1794. }
  1795. }
  1796. if adminInfo.CurrentOrgId == 10215 {
  1797. if prescribing_number > batch_number_all_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1799. return
  1800. }
  1801. }
  1802. }
  1803. }
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. num := prescribing_number * float64(drug.MinNumber)
  1806. if drug.IsUse != 1 {
  1807. if drug.IsProject == 0 || drug.IsProject == 2 {
  1808. if all_count == 0 {
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1810. return
  1811. }
  1812. if num > all_count {
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. }
  1817. if adminInfo.CurrentOrgId == 10215 {
  1818. if num > batch_number_all_count {
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1820. return
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1827. if drugOutConfig.IsOpen != 1 {
  1828. //修改处方
  1829. for _, advice := range advices {
  1830. var drug_id int64
  1831. var prescribing_number float64
  1832. var prescribingNumberUnit string
  1833. var prescribingNumber string
  1834. var adviceId int64
  1835. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1836. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1837. }
  1838. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1839. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1840. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1841. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1842. }
  1843. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1844. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1845. }
  1846. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1847. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1848. }
  1849. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1850. if drug.ID == 0 {
  1851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1852. return
  1853. }
  1854. //查询药品的所有库存
  1855. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1856. var total_count int64
  1857. for _, it := range list {
  1858. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1859. }
  1860. totals := strconv.FormatInt(total_count, 10)
  1861. //查询该药品是否存在开药记录
  1862. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1863. //新增处方
  1864. if advicelist.ID == 0 {
  1865. //查询最新批次库存
  1866. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1867. var batch_number_count int64
  1868. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1869. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1870. all_count, _ := strconv.ParseFloat(totals, 64)
  1871. if prescribingNumberUnit == drug.MinUnit {
  1872. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1873. if drug.IsUse != 1 {
  1874. if drug.IsProject == 0 || drug.IsProject == 2 {
  1875. if all_count == 0 {
  1876. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1877. return
  1878. }
  1879. if prescribing_number > all_count {
  1880. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1881. return
  1882. }
  1883. }
  1884. if adminInfo.CurrentOrgId == 10215 {
  1885. if prescribing_number > batch_number_all_count {
  1886. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1887. return
  1888. }
  1889. }
  1890. }
  1891. } else {
  1892. if prescribingNumberUnit == drug.MaxUnit {
  1893. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1894. num := prescribing_number * float64(drug.MinNumber)
  1895. if drug.IsUse != 1 {
  1896. if drug.IsProject == 0 || drug.IsProject == 2 {
  1897. if all_count == 0 {
  1898. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1899. return
  1900. }
  1901. if num > all_count {
  1902. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1903. return
  1904. }
  1905. }
  1906. if adminInfo.CurrentOrgId == 10215 {
  1907. if prescribing_number > batch_number_all_count {
  1908. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1909. return
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. }
  1916. //修改处方
  1917. if advicelist.ID > 0 {
  1918. //查询最新批次库存
  1919. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1920. var batch_number_count int64
  1921. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1922. var device_number int64
  1923. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1924. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1925. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1926. device_number = prescribingNumberInt * drug.MinNumber
  1927. }
  1928. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1929. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1930. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1931. device_number = prescribingNumberInt
  1932. }
  1933. var number_count int64
  1934. if prescribingNumberUnit == drug.MaxUnit {
  1935. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1936. number_count = prescribingNumberInt * drug.MinNumber
  1937. }
  1938. if prescribingNumberUnit == drug.MinUnit {
  1939. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1940. number_count = prescribingNumberInt
  1941. }
  1942. //如果修改的数量大于之前修改的数量
  1943. if (number_count - device_number) > 0 {
  1944. //如果修改的差数量 大于库存数量
  1945. if drug.IsUse != 1 {
  1946. if drug.IsProject == 0 || drug.IsProject == 2 {
  1947. if total_count == 0 {
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1949. return
  1950. }
  1951. if (number_count - device_number) > total_count {
  1952. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1953. return
  1954. }
  1955. if (number_count - device_number) > batch_number_count {
  1956. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1957. return
  1958. }
  1959. }
  1960. if adminInfo.CurrentOrgId == 10215 {
  1961. // 查询该药品最后一次出库记录
  1962. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1963. var out_count int64
  1964. var in_count int64
  1965. var stock_max_number int64
  1966. var stock_min_number int64
  1967. for _, it := range outInfo {
  1968. if it.CountUnit == drug.MaxUnit {
  1969. it.Count = it.Count * drug.MinNumber
  1970. }
  1971. out_count += it.Count
  1972. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1973. stock_max_number = warehouseInfoList.StockMaxNumber
  1974. stock_min_number = warehouseInfoList.StockMinNumber
  1975. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1976. }
  1977. if out_count > 0 {
  1978. if (number_count - device_number) > in_count {
  1979. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1980. return
  1981. }
  1982. }
  1983. // 未出库
  1984. if out_count == 0 {
  1985. var sum_in_count int64
  1986. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1987. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1988. fmt.Println("sum_in_count", sum_in_count)
  1989. //如果修改的数量大于有库存的第一个批次
  1990. if number_count > sum_in_count {
  1991. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1992. return
  1993. }
  1994. }
  1995. }
  1996. }
  1997. }
  1998. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1999. if pharmacyConfig.IsOpen != 1 {
  2000. if device_number != number_count {
  2001. // 查询该药品最后一次出库记录
  2002. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2003. //回退库存
  2004. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2005. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2006. }
  2007. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2008. var stock_max_number int64
  2009. var stock_min_number int64
  2010. if number_count >= drug.MinNumber {
  2011. stock_max_number = device_number / drug.MinNumber
  2012. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2013. stock_min_number = device_number % drug.MinNumber
  2014. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2015. } else {
  2016. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2017. }
  2018. }
  2019. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2020. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2021. }
  2022. //删除记录
  2023. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2024. //查询默认仓库剩余多少库存
  2025. var sum_count int64
  2026. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2027. for _, its := range stockInfo {
  2028. if its.MaxUnit == drug.MaxUnit {
  2029. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2030. }
  2031. sum_count += its.StockMaxNumber + its.StockMinNumber
  2032. }
  2033. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. //保存处方开药
  2040. if drugOutConfig.IsOpen == 1 {
  2041. //修改处方
  2042. for _, advice := range advices {
  2043. var drug_id int64
  2044. var prescribing_number float64
  2045. var prescribingNumberUnit string
  2046. var prescribingNumber string
  2047. var adviceId int64
  2048. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2049. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2050. }
  2051. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2052. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2053. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2054. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2055. }
  2056. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2057. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2058. }
  2059. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2060. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2061. }
  2062. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2063. if drug.ID == 0 {
  2064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2065. return
  2066. }
  2067. //查询药品的所有库存
  2068. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2069. var total_count int64
  2070. for _, it := range list {
  2071. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2072. }
  2073. totals := strconv.FormatInt(total_count, 10)
  2074. //查询该药品是否存在开药记录
  2075. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2076. //新增处方
  2077. if advicelist.ID == 0 {
  2078. //查询最新批次库存
  2079. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2080. var batch_number_count int64
  2081. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2082. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2083. all_count, _ := strconv.ParseFloat(totals, 64)
  2084. if prescribingNumberUnit == drug.MinUnit {
  2085. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2086. if drug.IsUse != 1 {
  2087. if drug.IsProject == 0 || drug.IsProject == 2 {
  2088. if all_count == 0 {
  2089. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2090. return
  2091. }
  2092. if prescribing_number > all_count {
  2093. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2094. return
  2095. }
  2096. }
  2097. if adminInfo.CurrentOrgId == 10215 {
  2098. if prescribing_number > batch_number_all_count {
  2099. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2100. return
  2101. }
  2102. }
  2103. }
  2104. } else {
  2105. if prescribingNumberUnit == drug.MaxUnit {
  2106. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2107. num := prescribing_number * float64(drug.MinNumber)
  2108. if drug.IsUse != 1 {
  2109. if drug.IsProject == 0 || drug.IsProject == 2 {
  2110. if all_count == 0 {
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. if num > all_count {
  2115. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2116. return
  2117. }
  2118. }
  2119. if adminInfo.CurrentOrgId == 10215 {
  2120. if prescribing_number > batch_number_all_count {
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2122. return
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. //修改处方
  2130. if advicelist.ID > 0 {
  2131. //查询最新批次库存
  2132. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2133. var batch_number_count int64
  2134. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2135. var device_number int64
  2136. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2137. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2138. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2139. device_number = prescribingNumberInt * drug.MinNumber
  2140. }
  2141. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2142. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2143. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2144. device_number = prescribingNumberInt
  2145. }
  2146. var number_count int64
  2147. if prescribingNumberUnit == drug.MaxUnit {
  2148. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2149. number_count = prescribingNumberInt * drug.MinNumber
  2150. }
  2151. if prescribingNumberUnit == drug.MinUnit {
  2152. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2153. number_count = prescribingNumberInt
  2154. }
  2155. //如果修改的数量大于之前修改的数量
  2156. if (number_count - device_number) > 0 {
  2157. //如果修改的差数量 大于库存数量
  2158. if drug.IsUse != 1 {
  2159. if drug.IsProject == 0 || drug.IsProject == 2 {
  2160. if total_count == 0 {
  2161. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2162. return
  2163. }
  2164. if (number_count - device_number) > total_count {
  2165. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2166. return
  2167. }
  2168. }
  2169. if adminInfo.CurrentOrgId == 10215 {
  2170. if (number_count - device_number) > batch_number_count {
  2171. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2172. return
  2173. }
  2174. }
  2175. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2176. //查询历史出库数据总批次
  2177. // 查询该药品最后一次出库记录
  2178. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2179. var out_count int64
  2180. var in_count int64
  2181. var stock_max_number int64
  2182. var stock_min_number int64
  2183. for _, it := range outInfo {
  2184. if it.CountUnit == drug.MaxUnit {
  2185. it.Count = it.Count * drug.MinNumber
  2186. }
  2187. out_count += it.Count
  2188. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2189. stock_max_number = warehouseInfoList.StockMaxNumber
  2190. stock_min_number = warehouseInfoList.StockMinNumber
  2191. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2192. }
  2193. if out_count > 0 {
  2194. if (number_count - device_number) > in_count {
  2195. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2196. return
  2197. }
  2198. }
  2199. // 未出库
  2200. if out_count == 0 {
  2201. var sum_in_count int64
  2202. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2203. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2204. if sum_in_count == 0 {
  2205. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2206. return
  2207. }
  2208. //如果修改的数量大于有库存的第一个批次
  2209. if number_count > sum_in_count {
  2210. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2211. return
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }
  2226. }
  2227. //校验耗材库存
  2228. if goodOutConfig.IsOpen == 1 {
  2229. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2230. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2231. if len(prescriptions) > 0 {
  2232. for _, item := range prescriptions {
  2233. items := item.(map[string]interface{})
  2234. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2235. projects := items["project"].([]interface{})
  2236. if len(projects) > 0 {
  2237. for _, project := range projects {
  2238. var project_id int64
  2239. var project_type int64
  2240. var totals float64
  2241. var project_name string
  2242. var parsetotal int64
  2243. var id int64
  2244. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2245. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2246. }
  2247. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2248. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2249. }
  2250. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2251. total, _ := project.(map[string]interface{})["total"].(string)
  2252. totals, _ = strconv.ParseFloat(total, 64)
  2253. }
  2254. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2255. project_name = project.(map[string]interface{})["project_name"].(string)
  2256. }
  2257. if project_type == 3 {
  2258. //查找该耗材的出库记录
  2259. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2260. if len(goodWarehouseInfo) == 0 {
  2261. //查询耗材库存
  2262. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2263. var stock_count int64
  2264. for _, it := range list {
  2265. stock_count += it.StockCount
  2266. }
  2267. stock_counts := strconv.FormatInt(stock_count, 10)
  2268. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2269. if stock_total_count == 0 {
  2270. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2271. return
  2272. }
  2273. if totals > stock_total_count {
  2274. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2275. return
  2276. }
  2277. }
  2278. if len(goodWarehouseInfo) > 0 {
  2279. //查询该患者耗材的历史数据
  2280. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2281. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2282. //数量发生改变
  2283. if parsetotal != count {
  2284. //如果现在的数量大于历史数量,就要看库存是否足够
  2285. if parsetotal > count {
  2286. //查询耗材所有库存
  2287. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2288. var stock_count int64
  2289. for _, it := range list {
  2290. stock_count += it.StockCount
  2291. }
  2292. //库存不足
  2293. if stock_count == 0 {
  2294. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2295. return
  2296. }
  2297. if (parsetotal - count) > stock_count {
  2298. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2299. return
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. //不使用耗材保存处方出库
  2313. if goodOutConfig.IsOpen != 1 {
  2314. if stockConfig.IsOpen == 1 {
  2315. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2316. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2317. if len(prescriptions) > 0 {
  2318. for _, item := range prescriptions {
  2319. items := item.(map[string]interface{})
  2320. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2321. projects := items["project"].([]interface{})
  2322. if len(projects) > 0 {
  2323. for _, project := range projects {
  2324. var project_id int64
  2325. var project_type int64
  2326. var totals float64
  2327. var project_name string
  2328. var parsetotal int64
  2329. var id int64
  2330. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2331. id = int64(project.(map[string]interface{})["id"].(float64))
  2332. }
  2333. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2334. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2335. }
  2336. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2337. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2338. }
  2339. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2340. total, _ := project.(map[string]interface{})["total"].(string)
  2341. totals, _ = strconv.ParseFloat(total, 64)
  2342. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2343. }
  2344. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2345. project_name = project.(map[string]interface{})["project_name"].(string)
  2346. }
  2347. if project_type == 3 {
  2348. //查找该耗材的出库记录
  2349. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2350. //没有出库记录
  2351. if len(goodWarehouseInfo) == 0 {
  2352. //查询耗材库存
  2353. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2354. var stock_count int64
  2355. for _, it := range list {
  2356. stock_count += it.StockCount
  2357. }
  2358. stock_counts := strconv.FormatInt(stock_count, 10)
  2359. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2360. if stock_total_count == 0 {
  2361. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2362. return
  2363. }
  2364. if totals > stock_total_count {
  2365. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2366. return
  2367. }
  2368. //查找今日该患者已经出库的所有耗材
  2369. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2370. for _, item := range goodList {
  2371. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2372. var flush_count int64
  2373. for _, it := range goodListSix {
  2374. flush_count += it.StockCount
  2375. }
  2376. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2377. creater := adminInfo.AdminUser.Id
  2378. if errs != nil {
  2379. goodErrcode := models.XtGoodErrcode{
  2380. UserOrgId: item.OrgId,
  2381. Errcode: "手动出库更新剩余出库失败",
  2382. GoodId: item.GoodId,
  2383. Status: 1,
  2384. Ctime: time.Now().Unix(),
  2385. Mtime: 0,
  2386. Count: 0,
  2387. StockCount: 0,
  2388. Creater: creater,
  2389. BatchNumberId: 0,
  2390. WarehouseOutId: 0,
  2391. }
  2392. service.CreateGoodErrcode(goodErrcode)
  2393. }
  2394. }
  2395. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2396. }
  2397. //有出库记录
  2398. if len(goodWarehouseInfo) > 0 {
  2399. //查询该患者耗材的历史数据
  2400. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2401. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2402. //数量发生改变
  2403. if parsetotal != count {
  2404. //查找今日该患者已经出库的所有耗材
  2405. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2406. for _, item := range goodList {
  2407. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2408. var flush_count int64
  2409. for _, it := range goodListSix {
  2410. flush_count += it.StockCount
  2411. }
  2412. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2413. //减少出库数量
  2414. creater := adminInfo.AdminUser.Id
  2415. if errs != nil {
  2416. goodErrcode := models.XtGoodErrcode{
  2417. UserOrgId: item.OrgId,
  2418. Errcode: "手动出库更新剩余出库失败",
  2419. GoodId: item.GoodId,
  2420. Status: 1,
  2421. Ctime: time.Now().Unix(),
  2422. Mtime: 0,
  2423. Count: 0,
  2424. StockCount: 0,
  2425. Creater: creater,
  2426. BatchNumberId: 0,
  2427. WarehouseOutId: 0,
  2428. }
  2429. service.CreateGoodErrcode(goodErrcode)
  2430. }
  2431. //查询默认仓库
  2432. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2433. var total_count int64
  2434. for _, it := range stockList {
  2435. total_count += it.StockCount
  2436. }
  2437. //基础库插入数据
  2438. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2439. }
  2440. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2441. }
  2442. }
  2443. }
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2453. var hpInfo models.HisPrescriptionInfo
  2454. if info.ID == 0 {
  2455. var randNum int
  2456. randNum = rand.Intn(10000) + 1000
  2457. timestamp := time.Now().Unix()
  2458. tempTime := time.Unix(timestamp, 0)
  2459. timeFormat := tempTime.Format("20060102150405")
  2460. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2461. hpInfo = models.HisPrescriptionInfo{
  2462. HisPatientId: his_patient_id,
  2463. UserOrgId: adminInfo.CurrentOrgId,
  2464. RecordDate: theTime.Unix(),
  2465. PatientId: patient_id,
  2466. Status: 1,
  2467. Ctime: time.Now().Unix(),
  2468. Mtime: time.Now().Unix(),
  2469. Creator: adminInfo.AdminUser.Id,
  2470. Modifier: adminInfo.AdminUser.Id,
  2471. Diagnosis: diagnose,
  2472. SickHistory: sick_history,
  2473. Departments: department,
  2474. RegisterType: reg_type,
  2475. PrescriptionNumber: p_number,
  2476. PrescriptionStatus: 1,
  2477. Doctor: role.UserName,
  2478. DoctorId: doctor_id,
  2479. SickType: sick_type,
  2480. PType: p_type,
  2481. PatientDiagnosis: patient_diagnose,
  2482. }
  2483. service.SavePatientPrescriptionInfo(hpInfo)
  2484. //创建步骤表
  2485. finish := models.XtDialysisFinish{
  2486. IsFinish: 1,
  2487. UserOrgId: adminInfo.CurrentOrgId,
  2488. Status: 1,
  2489. Ctime: time.Now().Unix(),
  2490. Mtime: 0,
  2491. Module: 4,
  2492. RecordDate: theTime.Unix(),
  2493. Sourse: 1,
  2494. PatientId: patient_id,
  2495. }
  2496. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2497. if dialysisFinish.ID == 0 {
  2498. service.CreateDialysisFinish(finish)
  2499. }
  2500. redis := service.RedisClient()
  2501. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2502. redis.Set(key, "", time.Second)
  2503. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2504. redis.Set(keyOne, "", time.Second)
  2505. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2506. redis.Set(keySeven, "", time.Second)
  2507. defer redis.Close()
  2508. } else {
  2509. hpInfo = models.HisPrescriptionInfo{
  2510. ID: info.ID,
  2511. UserOrgId: adminInfo.CurrentOrgId,
  2512. RecordDate: info.RecordDate,
  2513. PatientId: info.PatientId,
  2514. Status: 1,
  2515. Ctime: info.Ctime,
  2516. Mtime: time.Now().Unix(),
  2517. Creator: info.Creator,
  2518. Modifier: adminInfo.AdminUser.Id,
  2519. Diagnosis: diagnose,
  2520. SickHistory: sick_history,
  2521. Departments: department,
  2522. RegisterType: reg_type,
  2523. PrescriptionNumber: info.PrescriptionNumber,
  2524. Doctor: role.UserName,
  2525. PrescriptionStatus: info.PrescriptionStatus,
  2526. DoctorId: doctor_id,
  2527. SickType: sick_type,
  2528. PType: info.PType,
  2529. HisPatientId: info.HisPatientId,
  2530. PatientDiagnosis: patient_diagnose,
  2531. }
  2532. service.SavePatientPrescriptionInfo(hpInfo)
  2533. //创建步骤表
  2534. finish := models.XtDialysisFinish{
  2535. IsFinish: 1,
  2536. UserOrgId: adminInfo.CurrentOrgId,
  2537. Status: 1,
  2538. Ctime: time.Now().Unix(),
  2539. Mtime: 0,
  2540. Module: 4,
  2541. RecordDate: info.RecordDate,
  2542. Sourse: 1,
  2543. PatientId: info.PatientId,
  2544. }
  2545. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2546. if dialysisFinish.ID == 0 {
  2547. service.CreateDialysisFinish(finish)
  2548. }
  2549. redis := service.RedisClient()
  2550. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2551. redis.Set(key, "", time.Second)
  2552. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2553. redis.Set(keyOne, "", time.Second)
  2554. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2555. redis.Set(keySeven, "", time.Second)
  2556. defer redis.Close()
  2557. }
  2558. //定义切片
  2559. var adviceList []models.HisDoctorAdviceInfo
  2560. var projectList []models.HisPrescriptionProject
  2561. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2562. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2563. var tempPrescription *models.HisPrescription
  2564. if len(prescriptions) > 0 {
  2565. for _, item := range prescriptions {
  2566. items := item.(map[string]interface{})
  2567. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2568. utils.ErrorLog("id")
  2569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. id := int64(items["id"].(float64))
  2573. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2574. tempPrescription = &new_prescription
  2575. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2576. utils.ErrorLog("type")
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2578. return
  2579. }
  2580. types := int64(items["type"].(float64))
  2581. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2582. utils.ErrorLog("med_type")
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2584. return
  2585. }
  2586. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2587. if med_type == "0" {
  2588. med_type = "14"
  2589. }
  2590. //if order_status == 0 {
  2591. // order_status = 1
  2592. //}
  2593. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2594. utils.ErrorLog("pre_time")
  2595. }
  2596. preTime, _ := items["pre_time"].(string)
  2597. timeLayout := "2006-01-02"
  2598. loc, _ := time.LoadLocation("Local")
  2599. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2600. if err != nil {
  2601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. pTime := theTime2.Unix()
  2605. ctime := time.Now().Unix()
  2606. if tempPrescription.ID == 0 {
  2607. prescription := &models.HisPrescription{
  2608. ID: 0,
  2609. PatientId: patient_id,
  2610. UserOrgId: adminInfo.CurrentOrgId,
  2611. RecordDate: recordDateTime,
  2612. Ctime: ctime,
  2613. Mtime: ctime,
  2614. Type: types,
  2615. Modifier: adminInfo.AdminUser.Id,
  2616. Creator: adminInfo.AdminUser.Id,
  2617. Status: 1,
  2618. Doctor: role.UserName,
  2619. HisPatientId: his_patient_id,
  2620. OrderStatus: 1,
  2621. BatchNumber: "",
  2622. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2623. PreTime: pTime,
  2624. PType: p_type,
  2625. MedType: med_type,
  2626. }
  2627. tempPrescription = prescription
  2628. service.SaveHisPrescription(tempPrescription)
  2629. redis := service.RedisClient()
  2630. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2631. redis.Set(key, "", time.Second)
  2632. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2633. redis.Set(keyOne, "", time.Second)
  2634. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2635. redis.Set(keySeven, "", time.Second)
  2636. defer redis.Close()
  2637. } else {
  2638. tempPrescription.ID = id
  2639. tempPrescription.Type = types
  2640. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2641. tempPrescription.Mtime = time.Now().Unix()
  2642. tempPrescription.Doctor = role.UserName
  2643. //tempPrescription.OrderStatus = order_status
  2644. tempPrescription.PreTime = pTime
  2645. tempPrescription.MedType = med_type
  2646. service.SaveHisPrescription(tempPrescription)
  2647. redis := service.RedisClient()
  2648. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2649. redis.Set(key, "", time.Second)
  2650. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2651. redis.Set(keyOne, "", time.Second)
  2652. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2653. redis.Set(keySeven, "", time.Second)
  2654. defer redis.Close()
  2655. }
  2656. //service.SaveHisPrescription(prescription)
  2657. //更改患者挂号状态
  2658. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2659. fmt.Println("更改失败", err2)
  2660. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2661. advices := items["advices"].([]interface{})
  2662. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2663. groupNo := int64(0)
  2664. ctime := time.Now().Unix()
  2665. mtime := ctime
  2666. if len(advices) > 0 {
  2667. for _, advice := range advices {
  2668. var s models.HisDoctorAdviceInfo
  2669. s.PrescriptionId = tempPrescription.ID
  2670. s.AdviceType = 2
  2671. s.AdviceDoctor = doctor_id
  2672. s.StopState = 2
  2673. s.ExecutionState = 2
  2674. s.AdviceDate = recordDateTime
  2675. s.Status = 1
  2676. s.UserOrgId = adminInfo.CurrentOrgId
  2677. s.RecordDate = recordDateTime
  2678. s.StartTime = tempPrescription.PreTime
  2679. s.Groupno = groupNo
  2680. s.CreatedTime = ctime
  2681. s.UpdatedTime = mtime
  2682. s.PatientId = patient_id
  2683. s.HisPatientId = his_patient_id
  2684. s.StartTime = pTime
  2685. s.IsSettle = 2
  2686. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2687. if errcode > 0 {
  2688. c.ServeFailJSONWithSGJErrorCode(errcode)
  2689. return
  2690. }
  2691. s.StartTime = pTime
  2692. var total_count int64 //处方总库存
  2693. //查询改药品信息
  2694. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2695. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2696. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2697. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2698. total_count += prescribingNumberSeven * medical.MinNumber
  2699. }
  2700. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2701. total_count += prescribingNumberSeven
  2702. }
  2703. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2704. total_count += prescribingNumberSeven
  2705. }
  2706. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2707. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2708. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2709. if s.Price != lastWarehouse.RetailPrice {
  2710. s.Price = lastWarehouse.RetailPrice
  2711. }
  2712. if s.Price == 0 {
  2713. s.Price = lastWarehouse.RetailPrice
  2714. }
  2715. }
  2716. service.CreateHisDoctorAdvice(&s)
  2717. //记录日志
  2718. byterequest, _ := json.Marshal(s)
  2719. adviceLog := models.XtDoctorAdviceLog{
  2720. UserOrgId: s.UserOrgId,
  2721. PatientId: s.PatientId,
  2722. AdminUserId: adminInfo.AdminUser.Id,
  2723. Module: 1,
  2724. ErrLog: string(byterequest),
  2725. Status: 1,
  2726. Ctime: time.Now().Unix(),
  2727. Mtime: 0,
  2728. Source: "电脑端新建his医嘱",
  2729. RecordDate: s.AdviceDate,
  2730. }
  2731. service.CreateDoctorAdviceLog(adviceLog)
  2732. //存储切片中
  2733. adviceList = append(adviceList, s)
  2734. redis := service.RedisClient()
  2735. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2736. redis.Set(key, "", time.Second)
  2737. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2738. redis.Set(keyOne, "", time.Second)
  2739. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2740. redis.Set(keySeven, "", time.Second)
  2741. var randNum int
  2742. randNum = rand.Intn(10000) + 1000
  2743. timestamp := time.Now().Unix()
  2744. tempTime := time.Unix(timestamp, 0)
  2745. timeFormat := tempTime.Format("20060102150405")
  2746. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2747. service.CreateHisDoctorAdvice(&s)
  2748. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2749. redis.Set(keySix, "", time.Second)
  2750. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2751. redis.Set(keyFive, "", time.Second)
  2752. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2753. redis.Set(keyEight, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. }
  2757. }
  2758. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2759. projects := items["project"].([]interface{})
  2760. if len(projects) > 0 {
  2761. for _, project := range projects {
  2762. var p models.HisPrescriptionProject
  2763. p.PrescriptionId = tempPrescription.ID
  2764. p.Ctime = time.Now().Unix()
  2765. p.Mtime = time.Now().Unix()
  2766. p.PatientId = patient_id
  2767. p.RecordDate = recordDateTime
  2768. p.Doctor = doctor_id
  2769. p.UserOrgId = adminInfo.CurrentOrgId
  2770. p.HisPatientId = his_patient_id
  2771. p.Status = 1
  2772. p.StartTime = pTime
  2773. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2774. if errcode > 0 {
  2775. c.ServeFailJSONWithSGJErrorCode(errcode)
  2776. return
  2777. }
  2778. if p.ID == 0 {
  2779. p.IsOut = 2
  2780. }
  2781. if p.ID > 0 {
  2782. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2783. p.IsOut = projectDetail.IsOut
  2784. }
  2785. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2786. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2787. if p.Type == 3 {
  2788. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2789. if p.Price != lastWarehouse.PackingPrice {
  2790. p.Price = lastWarehouse.PackingPrice
  2791. }
  2792. if p.Unit == "" {
  2793. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2794. p.Unit = goodInfoOne.PackingUnit
  2795. }
  2796. }
  2797. }
  2798. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2799. //
  2800. // if p.Type == 3 {
  2801. // //查询该耗材是否停用
  2802. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2803. // //表示该耗材已经停用,不能保存
  2804. // if goodInfoSeven.ID == 0 {
  2805. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2806. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2807. // return
  2808. // }
  2809. // }
  2810. //
  2811. //}
  2812. service.CreateHisProjectTwo(&p)
  2813. //记录日志
  2814. byterequest, _ := json.Marshal(p)
  2815. adviceLog := models.XtDoctorAdviceLog{
  2816. UserOrgId: p.UserOrgId,
  2817. PatientId: p.PatientId,
  2818. AdminUserId: adminInfo.AdminUser.Id,
  2819. Module: 1,
  2820. ErrLog: string(byterequest),
  2821. Status: 1,
  2822. Ctime: time.Now().Unix(),
  2823. Mtime: 0,
  2824. Source: "电脑端新建his项目",
  2825. RecordDate: p.RecordDate,
  2826. }
  2827. service.CreateDoctorAdviceLog(adviceLog)
  2828. projectList = append(projectList, p)
  2829. var randNum int
  2830. randNum = rand.Intn(10000) + 1000
  2831. timestamp := time.Now().Unix()
  2832. tempTime := time.Unix(timestamp, 0)
  2833. timeFormat := tempTime.Format("20060102150405")
  2834. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2835. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2836. //新增或者编辑项目,修改对应的标签数据
  2837. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2838. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2839. var label models.HisLabelPrintInfo
  2840. project, _ := service.GetProjectDetail(p.ProjectId)
  2841. if project.CostClassify == 3 { //类别为检验检查
  2842. if p.TeamId > 0 { //检验检查组套
  2843. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2844. if tempLabel.ID == 0 {
  2845. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2846. label.Number = tempPrescription.PrescriptionNumber
  2847. label.ProjectId = project.ID
  2848. label.Status = 1
  2849. label.IsPrint = 2
  2850. label.DoctorId = info.DoctorId
  2851. label.UserOrgId = p.UserOrgId
  2852. label.PatientId = patient_id
  2853. label.RecordDate = recordDateTime
  2854. label.Ctime = time.Now().Unix()
  2855. label.Mtime = time.Now().Unix()
  2856. label.ItemId = p.TeamId
  2857. label.FeedetlSn = p.FeedetlSn
  2858. label.PProjectId = p.ID
  2859. label.ProjectName = team.ProjectTeam
  2860. label.PatientName = patient.Name
  2861. service.CreateHisLabelRecord(&label)
  2862. }
  2863. } else { //单条检验检查项目
  2864. label.Number = tempPrescription.PrescriptionNumber
  2865. label.ProjectId = project.ID
  2866. label.Status = 1
  2867. label.DoctorId = info.DoctorId
  2868. label.UserOrgId = p.UserOrgId
  2869. label.PatientId = patient_id
  2870. label.RecordDate = recordDateTime
  2871. label.IsPrint = 2
  2872. label.Ctime = time.Now().Unix()
  2873. label.Mtime = time.Now().Unix()
  2874. label.FeedetlSn = p.FeedetlSn
  2875. label.PProjectId = p.ID
  2876. label.ItemId = p.TeamId
  2877. label.ProjectName = project.ProjectName
  2878. label.PatientName = patient.Name
  2879. service.CreateHisLabelRecord(&label)
  2880. }
  2881. }
  2882. }
  2883. }
  2884. service.SaveHisProjectTwo(&p)
  2885. }
  2886. }
  2887. }
  2888. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2889. // addition := items["addition"].([]interface{})
  2890. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2891. // ctime := time.Now().Unix()
  2892. // mtime := ctime
  2893. // if len(addition) > 0 {
  2894. // for _, item := range addition {
  2895. // var s models.HisAdditionalCharge
  2896. // s.PrescriptionId = tempPrescription.ID
  2897. // s.Status = 1
  2898. // s.UserOrgId = adminInfo.CurrentOrgId
  2899. // s.RecordDate = recordDateTime
  2900. // s.CreatedTime = ctime
  2901. // s.UpdatedTime = mtime
  2902. // s.PatientId = patient_id
  2903. // s.HisPatientId = his_patient_id
  2904. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2905. // if errcode > 0 {
  2906. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2907. // return
  2908. // }
  2909. // service.CreateAdditionalCharge(&s)
  2910. // var randNum int
  2911. // randNum = rand.Intn(10000) + 1000
  2912. // timestamp := time.Now().Unix()
  2913. // tempTime := time.Unix(timestamp, 0)
  2914. // timeFormat := tempTime.Format("20060102150405")
  2915. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2916. // service.CreateAdditionalCharge(&s)
  2917. //
  2918. // }
  2919. // }
  2920. //}
  2921. }
  2922. }
  2923. //查询今日该患者开的药品处方
  2924. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2925. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2926. //药品出库
  2927. if drugOutConfig.IsOpen == 1 {
  2928. for _, item := range hisdoctorlist {
  2929. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2930. // 查询该药品最后一次出库记录
  2931. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2932. if len(druginfo) > 0 {
  2933. //回退库存
  2934. for _, it := range druginfo {
  2935. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2936. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2937. }
  2938. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2939. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2940. }
  2941. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2942. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2943. }
  2944. }
  2945. }
  2946. //删除记录
  2947. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2948. //查询最后一次数据
  2949. if drugOutConfig.IsOpen == 1 {
  2950. //出库
  2951. if drug.IsUse == 2 {
  2952. creater := adminInfo.AdminUser.Id
  2953. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2954. }
  2955. //更新字典里面的库存
  2956. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2957. var sum_count int64
  2958. for _, its := range stockInfo {
  2959. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2960. if its.MaxUnit == baseDrug.MaxUnit {
  2961. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2962. }
  2963. sum_count += its.StockMaxNumber + its.StockMinNumber
  2964. }
  2965. //更新基础库存
  2966. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2967. //剩余库存
  2968. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2969. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  2970. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2971. }
  2972. }
  2973. }
  2974. //耗材保存处方出库
  2975. if goodOutConfig.IsOpen == 1 {
  2976. //查询今日耗材出库数量
  2977. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2978. for _, item := range hisgoodlist {
  2979. //查询历史出库数据
  2980. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2981. var out_count_five int64
  2982. for _, item := range flowGood {
  2983. out_count_five += item.Count
  2984. }
  2985. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2986. if out_count_five != parseIntCount {
  2987. //查询耗材最后一次出库记录
  2988. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2989. //查询默认出库仓库库存
  2990. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2991. if len(wareOut) > 0 {
  2992. for _, it := range wareOut {
  2993. //回退库存
  2994. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2995. //删除出库记录
  2996. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2997. }
  2998. }
  2999. timeStr := time.Now().Format("2006-01-02")
  3000. timeArr := strings.Split(timeStr, "-")
  3001. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3002. total = total + 1
  3003. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3004. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3005. number = number + total
  3006. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3007. operation_time := time.Now().Unix()
  3008. creater := c.GetAdminUserInfo().AdminUser.Id
  3009. recordDateStr := time.Now().Format("2006-01-02")
  3010. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3011. nowtime := recordDate.Unix()
  3012. warehouseOut := models.WarehouseOut{
  3013. WarehouseOutOrderNumber: warehousing_out_order,
  3014. OperationTime: operation_time,
  3015. OrgId: adminInfo.CurrentOrgId,
  3016. Creater: creater,
  3017. Ctime: time.Now().Unix(),
  3018. Status: 1,
  3019. WarehouseOutTime: nowtime,
  3020. Type: 1,
  3021. StorehouseId: storeConfig.StorehouseOutInfo,
  3022. IsCheck: 1,
  3023. IsSys: 1,
  3024. }
  3025. //查询是否生成出库单
  3026. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3027. if out.ID == 0 {
  3028. service.AddSigleWarehouseOut(&warehouseOut)
  3029. }
  3030. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3031. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3032. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3033. dialyPrepareOne := models.DialysisBeforePrepare{
  3034. GoodTypeId: goodObj.GoodTypeId,
  3035. GoodId: item.ProjectId,
  3036. PatientId: item.PatientId,
  3037. RecordDate: item.RecordDate,
  3038. UserOrgId: adminInfo.CurrentOrgId,
  3039. Count: parseIntCount,
  3040. Ctime: time.Now().Unix(),
  3041. Creater: creater,
  3042. Status: 1,
  3043. StorehouseId: houseConfig.StorehouseOutInfo,
  3044. ProjectId: item.ID,
  3045. }
  3046. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3047. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3048. //查询历史出库数据
  3049. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3050. var out_count int64
  3051. for _, item := range flowGood {
  3052. out_count += item.Count
  3053. }
  3054. //如果历史数和当前数据不想等才进行退库出库
  3055. if out_count != parseIntCount {
  3056. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3057. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3058. detail := models.AutomaticReduceDetail{
  3059. WarehouseOutId: 0,
  3060. WarehouseOutOrderNumber: "",
  3061. PatientId: item.PatientId,
  3062. Ctime: time.Now().Unix(),
  3063. Mtime: 0,
  3064. Status: 1,
  3065. RecordTime: item.RecordDate,
  3066. OrgId: item.UserOrgId,
  3067. GoodId: item.ProjectId,
  3068. GoodTypeId: 0,
  3069. Count: parseIntCount,
  3070. Type: 0,
  3071. ProjectId: item.ID,
  3072. StorehouseId: 0,
  3073. }
  3074. service.CreateAutoDetail(detail)
  3075. //查询剩余库存
  3076. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3077. var sum_count int64
  3078. for _, item := range goodList {
  3079. sum_count += item.StockCount
  3080. }
  3081. //更新剩余库存
  3082. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3083. //耗材
  3084. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3085. }
  3086. }
  3087. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3088. //查询历史出库数据
  3089. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3090. var out_count int64
  3091. for _, item := range flowGood {
  3092. out_count += item.Count
  3093. }
  3094. //如果历史数和当前数据不想等才进行退库出库
  3095. if out_count != parseIntCount {
  3096. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3097. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3098. detail := models.AutomaticReduceDetail{
  3099. WarehouseOutId: 0,
  3100. WarehouseOutOrderNumber: "",
  3101. PatientId: item.PatientId,
  3102. Ctime: time.Now().Unix(),
  3103. Mtime: 0,
  3104. Status: 1,
  3105. RecordTime: item.RecordDate,
  3106. OrgId: item.UserOrgId,
  3107. GoodId: item.ProjectId,
  3108. GoodTypeId: 0,
  3109. Count: parseIntCount,
  3110. Type: 0,
  3111. ProjectId: item.ID,
  3112. StorehouseId: 0,
  3113. }
  3114. service.CreateAutoDetail(detail)
  3115. //查询剩余库存
  3116. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3117. var sum_count int64
  3118. for _, item := range goodList {
  3119. sum_count += item.StockCount
  3120. }
  3121. //更新剩余库存
  3122. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3123. //耗材
  3124. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3125. }
  3126. }
  3127. }
  3128. }
  3129. }
  3130. }
  3131. //redisClient := service.RedisClient()
  3132. //defer redisClient.Close()
  3133. //
  3134. //list := models.HisList{
  3135. // Patient_id: patient_id,
  3136. // Advice_id:0,
  3137. // Record_date: 0,
  3138. // Advice: adviceList,
  3139. // Project: nil,
  3140. //}
  3141. //hisLis = append(hisLis, list)
  3142. //
  3143. //advice_json, _ := json.Marshal(&hisLis)
  3144. //redisClient.RPush("111", advice_json).Result()
  3145. //result, _ := redisClient.RPop("111").Result()
  3146. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3147. //
  3148. //var dat []map[string]interface{}
  3149. //json.Unmarshal([]byte(result), &dat)
  3150. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3151. //
  3152. //for k,v:=range dat{
  3153. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3154. //}
  3155. //project_json, _ := json.Marshal(&projectList)
  3156. //redisClient.LPush("222", project_json).Result()
  3157. if err == nil {
  3158. c.ServeSuccessJSON(map[string]interface{}{
  3159. "msg": "保存成功",
  3160. })
  3161. return
  3162. } else {
  3163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3164. return
  3165. }
  3166. }
  3167. func (c *HisApiController) EditHisPrescription() {
  3168. record_date := c.GetString("record_date")
  3169. patient_id, _ := c.GetInt64("patient_id")
  3170. reg_type, _ := c.GetInt64("reg_type")
  3171. //diagnose, _ := c.GetInt64("diagnose", 0)
  3172. diagnose := c.GetString("diagnose")
  3173. sick_type, _ := c.GetInt64("sick_type")
  3174. sick_history := c.GetString("sick_history")
  3175. doctor_id, _ := c.GetInt64("doctor", 0)
  3176. department, _ := c.GetInt64("department", 0)
  3177. his_patient_id, _ := c.GetInt64("his_patient_id")
  3178. p_type, _ := c.GetInt64("p_type")
  3179. dataBody := make(map[string]interface{}, 0)
  3180. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3181. if err != nil {
  3182. utils.ErrorLog(err.Error())
  3183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3184. return
  3185. }
  3186. timeLayout := "2006-01-02"
  3187. loc, _ := time.LoadLocation("Local")
  3188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3189. if err != nil {
  3190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3191. return
  3192. }
  3193. adminInfo := c.GetAdminUserInfo()
  3194. recordDateTime := theTime.Unix()
  3195. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3196. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3197. var hpInfo models.HisPrescriptionInfo
  3198. if info.ID == 0 {
  3199. var randNum int
  3200. randNum = rand.Intn(10000) + 1000
  3201. timestamp := time.Now().Unix()
  3202. tempTime := time.Unix(timestamp, 0)
  3203. timeFormat := tempTime.Format("20060102150405")
  3204. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3205. hpInfo = models.HisPrescriptionInfo{
  3206. UserOrgId: adminInfo.CurrentOrgId,
  3207. RecordDate: theTime.Unix(),
  3208. PatientId: patient_id,
  3209. Status: 1,
  3210. Ctime: time.Now().Unix(),
  3211. Mtime: time.Now().Unix(),
  3212. Creator: adminInfo.AdminUser.Id,
  3213. Modifier: adminInfo.AdminUser.Id,
  3214. Diagnosis: diagnose,
  3215. SickHistory: sick_history,
  3216. Departments: department,
  3217. RegisterType: reg_type,
  3218. PrescriptionNumber: p_number,
  3219. PrescriptionStatus: 1,
  3220. Doctor: role.UserName,
  3221. DoctorId: doctor_id,
  3222. SickType: sick_type,
  3223. PType: p_type,
  3224. }
  3225. service.SavePatientPrescriptionInfo(hpInfo)
  3226. } else {
  3227. hpInfo = models.HisPrescriptionInfo{
  3228. ID: info.ID,
  3229. UserOrgId: adminInfo.CurrentOrgId,
  3230. RecordDate: info.RecordDate,
  3231. PatientId: info.PatientId,
  3232. Status: 1,
  3233. Ctime: info.Ctime,
  3234. Mtime: time.Now().Unix(),
  3235. Creator: info.Creator,
  3236. Modifier: adminInfo.AdminUser.Id,
  3237. Diagnosis: diagnose,
  3238. SickHistory: sick_history,
  3239. Departments: department,
  3240. RegisterType: reg_type,
  3241. PrescriptionNumber: info.PrescriptionNumber,
  3242. Doctor: role.UserName,
  3243. PrescriptionStatus: info.PrescriptionStatus,
  3244. DoctorId: doctor_id,
  3245. SickType: sick_type,
  3246. PType: info.PType,
  3247. }
  3248. service.SavePatientPrescriptionInfo(hpInfo)
  3249. }
  3250. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3251. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3252. if len(prescriptions) > 0 {
  3253. for _, item := range prescriptions {
  3254. items := item.(map[string]interface{})
  3255. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3256. utils.ErrorLog("id")
  3257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3258. return
  3259. }
  3260. id := int64(items["id"].(float64))
  3261. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3262. utils.ErrorLog("type")
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3264. return
  3265. }
  3266. types := int64(items["type"].(float64))
  3267. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3268. utils.ErrorLog("med_type")
  3269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3270. return
  3271. }
  3272. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3273. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3274. ctime := time.Now().Unix()
  3275. prescription := &models.HisPrescription{
  3276. ID: id,
  3277. PatientId: patient_id,
  3278. UserOrgId: adminInfo.CurrentOrgId,
  3279. RecordDate: recordDateTime,
  3280. Ctime: ctime,
  3281. Mtime: ctime,
  3282. Type: types,
  3283. Modifier: adminInfo.AdminUser.Id,
  3284. Creator: adminInfo.AdminUser.Id,
  3285. Status: 1,
  3286. Doctor: role.UserName,
  3287. HisPatientId: his_patient_id,
  3288. OrderStatus: 1,
  3289. BatchNumber: "",
  3290. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3291. PType: hpInfo.PType,
  3292. MedType: med_type,
  3293. }
  3294. if historyPrescription.ID > 0 {
  3295. prescription.PreTime = historyPrescription.PreTime
  3296. }
  3297. service.SaveHisPrescription(prescription)
  3298. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3299. advices := items["advices"].([]interface{})
  3300. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3301. groupNo := int64(0)
  3302. ctime := time.Now().Unix()
  3303. mtime := ctime
  3304. if len(advices) > 0 {
  3305. for _, advice := range advices {
  3306. var s models.HisDoctorAdviceInfo
  3307. s.PrescriptionId = prescription.ID
  3308. s.AdviceType = 2
  3309. s.AdviceDoctor = adminInfo.AdminUser.Id
  3310. s.StopState = 2
  3311. s.ExecutionState = 2
  3312. s.AdviceDate = recordDateTime
  3313. s.Status = 1
  3314. s.UserOrgId = adminInfo.CurrentOrgId
  3315. s.RecordDate = recordDateTime
  3316. s.StartTime = prescription.PreTime
  3317. s.Groupno = groupNo
  3318. s.CreatedTime = ctime
  3319. s.UpdatedTime = mtime
  3320. s.PatientId = patient_id
  3321. s.HisPatientId = his_patient_id
  3322. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3323. if errcode > 0 {
  3324. c.ServeFailJSONWithSGJErrorCode(errcode)
  3325. return
  3326. }
  3327. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3328. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3329. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3330. if s.Price == 0 {
  3331. s.Price = lastWarehouse.RetailPrice
  3332. }
  3333. }
  3334. service.CreateHisDoctorAdvice(&s)
  3335. //记录日志
  3336. byterequest, _ := json.Marshal(s)
  3337. adviceLog := models.XtDoctorAdviceLog{
  3338. UserOrgId: s.UserOrgId,
  3339. PatientId: s.PatientId,
  3340. AdminUserId: adminInfo.AdminUser.Id,
  3341. Module: 1,
  3342. ErrLog: string(byterequest),
  3343. Status: 1,
  3344. Ctime: time.Now().Unix(),
  3345. Mtime: 0,
  3346. Source: "电脑端his医嘱修改",
  3347. RecordDate: s.AdviceDate,
  3348. }
  3349. service.CreateDoctorAdviceLog(adviceLog)
  3350. redis := service.RedisClient()
  3351. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3352. redis.Set(key, "", time.Second)
  3353. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3354. fmt.Println("keyOne", keyOne)
  3355. redis.Set(keyOne, "", time.Second)
  3356. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3357. redis.Set(keySeven, "", time.Second)
  3358. redis.Close()
  3359. }
  3360. }
  3361. }
  3362. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3363. projects := items["project"].([]interface{})
  3364. if len(projects) > 0 {
  3365. for _, project := range projects {
  3366. var p models.HisPrescriptionProject
  3367. p.PrescriptionId = prescription.ID
  3368. p.Ctime = time.Now().Unix()
  3369. p.Mtime = time.Now().Unix()
  3370. p.PatientId = patient_id
  3371. p.RecordDate = recordDateTime
  3372. p.UserOrgId = adminInfo.CurrentOrgId
  3373. p.HisPatientId = his_patient_id
  3374. p.Status = 1
  3375. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3376. if errcode > 0 {
  3377. c.ServeFailJSONWithSGJErrorCode(errcode)
  3378. return
  3379. }
  3380. service.CreateHisProjectTwo(&p)
  3381. //记录日志
  3382. byterequest, _ := json.Marshal(p)
  3383. adviceLog := models.XtDoctorAdviceLog{
  3384. UserOrgId: p.UserOrgId,
  3385. PatientId: p.PatientId,
  3386. AdminUserId: adminInfo.AdminUser.Id,
  3387. Module: 1,
  3388. ErrLog: string(byterequest),
  3389. Status: 1,
  3390. Ctime: time.Now().Unix(),
  3391. Mtime: 0,
  3392. Source: "电脑端his项目修改",
  3393. RecordDate: p.RecordDate,
  3394. }
  3395. service.CreateDoctorAdviceLog(adviceLog)
  3396. }
  3397. }
  3398. }
  3399. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3400. addition := items["addition"].([]interface{})
  3401. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3402. ctime := time.Now().Unix()
  3403. mtime := ctime
  3404. if len(addition) > 0 {
  3405. for _, item := range addition {
  3406. var s models.HisAdditionalCharge
  3407. s.PrescriptionId = prescription.ID
  3408. s.Status = 1
  3409. s.UserOrgId = adminInfo.CurrentOrgId
  3410. s.RecordDate = recordDateTime
  3411. s.CreatedTime = ctime
  3412. s.UpdatedTime = mtime
  3413. s.PatientId = patient_id
  3414. s.HisPatientId = his_patient_id
  3415. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3416. if errcode > 0 {
  3417. c.ServeFailJSONWithSGJErrorCode(errcode)
  3418. return
  3419. }
  3420. service.CreateAdditionalCharge(&s)
  3421. }
  3422. }
  3423. }
  3424. }
  3425. }
  3426. }
  3427. if err == nil {
  3428. c.ServeSuccessJSON(map[string]interface{}{
  3429. "msg": "保存成功",
  3430. })
  3431. return
  3432. } else {
  3433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3434. return
  3435. }
  3436. }
  3437. func (c *HisApiController) DeletePrescription() {
  3438. prescription_id, _ := c.GetInt64("id")
  3439. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3440. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3441. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3442. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3443. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3444. //耗材保存处方出库
  3445. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3446. //已收费和已发药限制逻辑
  3447. isCharge := false
  3448. isMedicine := false
  3449. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3450. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3451. for _, item := range new_prescriptions {
  3452. if item.IsMedicine == 1 {
  3453. isMedicine = true
  3454. }
  3455. }
  3456. for _, item := range new_prescriptions {
  3457. if item.OrderStatus == 4 {
  3458. isCharge = true
  3459. }
  3460. }
  3461. if p_err != nil {
  3462. if new_prescription.ID > 0 {
  3463. if new_prescription.OrderStatus == 2 {
  3464. isCharge = true
  3465. }
  3466. }
  3467. }
  3468. for _, item := range advices {
  3469. if item.IsMedicine == 1 {
  3470. isMedicine = true
  3471. }
  3472. }
  3473. if isCharge {
  3474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3475. return
  3476. }
  3477. if isMedicine {
  3478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3479. return
  3480. }
  3481. //已收费和已发药限制逻辑
  3482. if len(projects) > 0 {
  3483. for _, item := range projects {
  3484. service.DeletePrintInfo(item.ID) //删除打印信息
  3485. if goodOutConfig.IsOpen != 1 {
  3486. if stockConfig.IsOpen == 1 {
  3487. if item.Type == 3 && item.IsOut == 1 {
  3488. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3489. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3490. good.Total = good.Total + f_count
  3491. service.UpdateGoodInfo(&good)
  3492. operation_time := time.Now().Unix()
  3493. creater := c.GetAdminUserInfo().AdminUser.Id
  3494. //创建退库单
  3495. timeStr := time.Now().Format("2006-01-02")
  3496. timeArr := strings.Split(timeStr, "-")
  3497. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3498. total = total + 1
  3499. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3500. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3501. cancelStock := models.CancelStock{
  3502. OrderNumber: orderNumber,
  3503. OperaTime: operation_time,
  3504. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3505. Creater: creater,
  3506. Ctime: time.Now().Unix(),
  3507. Status: 1,
  3508. ReturnTime: item.RecordDate,
  3509. Type: 1,
  3510. StorehouseId: houseConfig.StorehouseOutInfo,
  3511. IsCheck: 1,
  3512. }
  3513. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3514. if msgerrkonde == gorm.ErrRecordNotFound {
  3515. service.AddSigleCancelStock(&cancelStock)
  3516. }
  3517. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3518. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3519. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3520. //查询该耗材是否出库
  3521. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3522. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3523. deaerler, _ := service.GetDealerById(info.Dealer)
  3524. var total_count int64
  3525. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3526. total_count += count
  3527. if info.ID > 0 {
  3528. if info.Count >= total_count {
  3529. //回退库存
  3530. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3531. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3532. var flush_count int64
  3533. for _, it := range goodList {
  3534. flush_count += it.StockCount
  3535. }
  3536. cancelStockInfo := models.CancelStockInfo{
  3537. GoodId: item.ProjectId,
  3538. CancelStockId: cancel.ID,
  3539. GoodTypeId: good.GoodTypeId,
  3540. Count: prescribingNumber,
  3541. Price: info.Price,
  3542. Total: 0,
  3543. ProductDate: info.ProductDate,
  3544. ExpiryDate: info.ExpiryDate,
  3545. Ctime: time.Now().Unix(),
  3546. Status: 1,
  3547. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3548. OrderNumber: cancel.OrderNumber,
  3549. Type: 0,
  3550. Dealer: deaerler.DealerName,
  3551. Manufacturer: manufacturer.ManufacturerName,
  3552. Number: info.Number,
  3553. RegisterAccount: "",
  3554. Remark: "",
  3555. WarehouseInfoId: info.WarehouseInfotId,
  3556. PatientId: info.PatientId,
  3557. RecordDate: info.SysRecordTime,
  3558. StorehouseId: houseConfig.StorehouseOutInfo,
  3559. IsCheck: 1,
  3560. }
  3561. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3562. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3563. flow := models.VmStockFlow{
  3564. WarehousingId: info.WarehouseInfotId,
  3565. GoodId: item.ProjectId,
  3566. Number: info.Number,
  3567. LicenseNumber: info.LicenseNumber,
  3568. Count: prescribingNumber,
  3569. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3570. PatientId: item.PatientId,
  3571. SystemTime: info.SysRecordTime,
  3572. ConsumableType: 7,
  3573. IsSys: 0,
  3574. WarehousingOrder: "",
  3575. WarehouseOutId: info.WarehouseOutId,
  3576. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3577. IsEdit: 0,
  3578. CancelStockId: cancel.ID,
  3579. CancelOrderNumber: cancel.OrderNumber,
  3580. Manufacturer: manufacturer.ID,
  3581. Dealer: 0,
  3582. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3583. UpdateCreator: 0,
  3584. Status: 1,
  3585. Ctime: time.Now().Unix(),
  3586. Mtime: 0,
  3587. Price: info.Price,
  3588. WarehousingDetailId: info.WarehouseInfotId,
  3589. WarehouseOutDetailId: info.ID,
  3590. CancelOutDetailId: cancelInfo.ID,
  3591. ProductDate: info.ProductDate,
  3592. ExpireDate: info.ExpiryDate,
  3593. StorehouseId: houseConfig.StorehouseOutInfo,
  3594. OverCount: flush_count,
  3595. }
  3596. service.CreateStockFlowOne(flow)
  3597. //退库数量增加
  3598. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3599. //出库数量减少
  3600. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3601. }
  3602. if info.Count < total_count {
  3603. //回退库存
  3604. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3605. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3606. var flush_count int64
  3607. for _, it := range goodList {
  3608. flush_count += it.StockCount
  3609. }
  3610. cancelStockInfo := models.CancelStockInfo{
  3611. GoodId: item.ProjectId,
  3612. CancelStockId: cancel.ID,
  3613. GoodTypeId: good.GoodTypeId,
  3614. Count: info.Count,
  3615. Price: info.Price,
  3616. Total: 0,
  3617. ProductDate: info.ProductDate,
  3618. ExpiryDate: info.ExpiryDate,
  3619. Ctime: time.Now().Unix(),
  3620. Status: 1,
  3621. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3622. OrderNumber: cancel.OrderNumber,
  3623. Type: 0,
  3624. Dealer: deaerler.DealerName,
  3625. Manufacturer: manufacturer.ManufacturerName,
  3626. Number: info.Number,
  3627. RegisterAccount: "",
  3628. Remark: "",
  3629. WarehouseInfoId: info.WarehouseInfotId,
  3630. PatientId: info.PatientId,
  3631. RecordDate: info.SysRecordTime,
  3632. StorehouseId: houseConfig.StorehouseOutInfo,
  3633. IsCheck: 1,
  3634. }
  3635. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3636. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3637. flow := models.VmStockFlow{
  3638. WarehousingId: info.WarehouseInfotId,
  3639. GoodId: item.ProjectId,
  3640. Number: info.Number,
  3641. LicenseNumber: info.LicenseNumber,
  3642. Count: info.Count,
  3643. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3644. PatientId: item.PatientId,
  3645. SystemTime: info.SysRecordTime,
  3646. ConsumableType: 7,
  3647. IsSys: 0,
  3648. WarehousingOrder: "",
  3649. WarehouseOutId: info.WarehouseOutId,
  3650. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3651. IsEdit: 0,
  3652. CancelStockId: cancel.ID,
  3653. CancelOrderNumber: cancel.OrderNumber,
  3654. Manufacturer: manufacturer.ID,
  3655. Dealer: 0,
  3656. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3657. UpdateCreator: 0,
  3658. Status: 1,
  3659. Ctime: time.Now().Unix(),
  3660. Mtime: 0,
  3661. Price: info.Price,
  3662. WarehousingDetailId: info.WarehouseInfotId,
  3663. WarehouseOutDetailId: info.ID,
  3664. CancelOutDetailId: cancelInfo.ID,
  3665. ProductDate: info.ProductDate,
  3666. ExpireDate: info.ExpiryDate,
  3667. StorehouseId: houseConfig.StorehouseOutInfo,
  3668. OverCount: flush_count,
  3669. }
  3670. service.CreateStockFlowOne(flow)
  3671. //退库数量增加
  3672. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3673. //出库数量减少
  3674. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3675. }
  3676. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3677. var flush_count int64
  3678. for _, it := range goodList {
  3679. flush_count += it.StockCount
  3680. }
  3681. //查询已出库数量
  3682. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3683. if prescribingNumber < dialysisInfo.Count {
  3684. //改变数量
  3685. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3686. }
  3687. if prescribingNumber >= dialysisInfo.Count {
  3688. //删除出库表
  3689. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3690. }
  3691. //更新库存
  3692. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3693. //更新基础库库存
  3694. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3695. }
  3696. }
  3697. }
  3698. }
  3699. //保存耗材出库
  3700. if goodOutConfig.IsOpen == 1 {
  3701. if item.Type == 3 {
  3702. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3703. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3704. good.Total = good.Total + f_count
  3705. service.UpdateGoodInfo(&good)
  3706. operation_time := time.Now().Unix()
  3707. creater := c.GetAdminUserInfo().AdminUser.Id
  3708. //创建退库单
  3709. timeStr := time.Now().Format("2006-01-02")
  3710. timeArr := strings.Split(timeStr, "-")
  3711. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3712. total = total + 1
  3713. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3714. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3715. cancelStock := models.CancelStock{
  3716. OrderNumber: orderNumber,
  3717. OperaTime: operation_time,
  3718. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3719. Creater: creater,
  3720. Ctime: time.Now().Unix(),
  3721. Status: 1,
  3722. ReturnTime: item.RecordDate,
  3723. Type: 1,
  3724. StorehouseId: houseConfig.StorehouseOutInfo,
  3725. IsCheck: 1,
  3726. }
  3727. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3728. if msgerrkonde == gorm.ErrRecordNotFound {
  3729. service.AddSigleCancelStock(&cancelStock)
  3730. }
  3731. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3732. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3733. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3734. //查询该耗材是否出库
  3735. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3736. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3737. deaerler, _ := service.GetDealerById(info.Dealer)
  3738. var total_count int64
  3739. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3740. total_count += count
  3741. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3742. var flush_count int64
  3743. for _, it := range goodList {
  3744. flush_count += it.StockCount
  3745. }
  3746. fmt.Println("历史出库数据", info.Count)
  3747. fmt.Println("出库数量", total_count)
  3748. if info.ID > 0 {
  3749. cancelStockInfo := models.CancelStockInfo{
  3750. GoodId: item.ProjectId,
  3751. CancelStockId: cancel.ID,
  3752. GoodTypeId: good.GoodTypeId,
  3753. Count: prescribingNumber,
  3754. Price: info.Price,
  3755. Total: 0,
  3756. ProductDate: info.ProductDate,
  3757. ExpiryDate: info.ExpiryDate,
  3758. Ctime: time.Now().Unix(),
  3759. Status: 1,
  3760. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3761. OrderNumber: cancel.OrderNumber,
  3762. Type: 0,
  3763. Dealer: deaerler.DealerName,
  3764. Manufacturer: manufacturer.ManufacturerName,
  3765. Number: info.Number,
  3766. RegisterAccount: "",
  3767. Remark: "",
  3768. WarehouseInfoId: info.WarehouseInfotId,
  3769. PatientId: info.PatientId,
  3770. RecordDate: info.SysRecordTime,
  3771. StorehouseId: houseConfig.StorehouseOutInfo,
  3772. IsCheck: 1,
  3773. }
  3774. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3775. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3776. //查询出库数量
  3777. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3778. //出库数据 大于 退库数量
  3779. if len(list) > 0 {
  3780. for _, it := range list {
  3781. //回退库存
  3782. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3783. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3784. var flush_count_one int64
  3785. for _, it := range goodList {
  3786. flush_count_one += it.StockCount
  3787. }
  3788. //查询该批次是否有退库数据
  3789. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3790. creater := c.GetAdminUserInfo().AdminUser.Id
  3791. flow := models.VmStockFlow{
  3792. WarehousingId: it.WarehouseInfotId,
  3793. GoodId: it.GoodId,
  3794. Number: it.Number,
  3795. LicenseNumber: it.LicenseNumber,
  3796. Count: it.Count,
  3797. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3798. PatientId: it.PatientId,
  3799. SystemTime: it.SysRecordTime,
  3800. ConsumableType: 7,
  3801. IsSys: 0,
  3802. WarehousingOrder: "",
  3803. WarehouseOutId: it.WarehouseOutId,
  3804. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3805. IsEdit: 0,
  3806. CancelStockId: cancel.ID,
  3807. CancelOrderNumber: cancel.OrderNumber,
  3808. Manufacturer: manufacturer.ID,
  3809. Dealer: 0,
  3810. Creator: creater,
  3811. UpdateCreator: 0,
  3812. Status: 1,
  3813. Ctime: time.Now().Unix(),
  3814. Mtime: 0,
  3815. Price: it.Price,
  3816. WarehousingDetailId: it.WarehouseInfotId,
  3817. WarehouseOutDetailId: it.ID,
  3818. CancelOutDetailId: cancelInfo.ID,
  3819. ProductDate: it.ProductDate,
  3820. ExpireDate: it.ExpiryDate,
  3821. StorehouseId: houseConfig.StorehouseOutInfo,
  3822. OverCount: flush_count_one,
  3823. }
  3824. service.CreateStockFlowOne(flow)
  3825. //if flow.ID > 0 {
  3826. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3827. //}
  3828. }
  3829. }
  3830. //flow := models.VmStockFlow{
  3831. // WarehousingId: info.WarehouseInfotId,
  3832. // GoodId: item.ProjectId,
  3833. // Number: info.Number,
  3834. // LicenseNumber: info.LicenseNumber,
  3835. // Count: prescribingNumber,
  3836. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3837. // PatientId: item.PatientId,
  3838. // SystemTime: info.SysRecordTime,
  3839. // ConsumableType: 7,
  3840. // IsSys: 0,
  3841. // WarehousingOrder: "",
  3842. // WarehouseOutId: info.WarehouseOutId,
  3843. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3844. // IsEdit: 0,
  3845. // CancelStockId: cancel.ID,
  3846. // CancelOrderNumber: cancel.OrderNumber,
  3847. // Manufacturer: manufacturer.ID,
  3848. // Dealer: 0,
  3849. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3850. // UpdateCreator: 0,
  3851. // Status: 1,
  3852. // Ctime: time.Now().Unix(),
  3853. // Mtime: 0,
  3854. // Price: info.Price,
  3855. // WarehousingDetailId: info.WarehouseInfotId,
  3856. // WarehouseOutDetailId: info.ID,
  3857. // CancelOutDetailId: cancelInfo.ID,
  3858. // ProductDate: info.ProductDate,
  3859. // ExpireDate: info.ExpiryDate,
  3860. // StorehouseId: houseConfig.StorehouseOutInfo,
  3861. // OverCount: flush_count,
  3862. //}
  3863. //service.CreateStockFlowOne(flow)
  3864. //退库数量增加
  3865. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3866. //出库数量减少
  3867. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3868. //查询已出库数量
  3869. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3870. if prescribingNumber < dialysisInfo.Count {
  3871. //改变数量
  3872. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3873. }
  3874. if prescribingNumber >= dialysisInfo.Count {
  3875. //删除出库表
  3876. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3877. }
  3878. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3879. var flush_count_one int64
  3880. for _, it := range goodList {
  3881. flush_count_one += it.StockCount
  3882. }
  3883. //更新库存
  3884. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3885. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3886. //更新基础库库存
  3887. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3888. }
  3889. }
  3890. }
  3891. }
  3892. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3893. fmt.Println(err)
  3894. }
  3895. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3896. fmt.Println(err)
  3897. if len(advices) > 0 {
  3898. for _, item := range advices {
  3899. redis := service.RedisClient()
  3900. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3901. redis.Set(keyFive, "", time.Second)
  3902. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3903. redis.Set(keyOne, "", time.Second)
  3904. redis.Close()
  3905. }
  3906. }
  3907. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3908. if len(advices) > 0 {
  3909. for _, item := range advices {
  3910. creater := c.GetAdminUserInfo().AdminUser.Id
  3911. service.DrugAutoAddCancelInfo(item, creater)
  3912. }
  3913. }
  3914. } else {
  3915. if drugOutConfig.IsOpen == 1 {
  3916. if len(advices) > 0 {
  3917. for _, item := range advices {
  3918. creater := c.GetAdminUserInfo().AdminUser.Id
  3919. service.DrugAutoAddCancelInfo(item, creater)
  3920. }
  3921. }
  3922. } else {
  3923. if len(advices) > 0 {
  3924. for _, item := range advices {
  3925. creater := c.GetAdminUserInfo().AdminUser.Id
  3926. service.DrugAutoAddCancelInfo(item, creater)
  3927. }
  3928. }
  3929. }
  3930. }
  3931. c.ServeSuccessJSON(map[string]interface{}{
  3932. "msg": "删除成功",
  3933. })
  3934. return
  3935. }
  3936. func (c *HisApiController) DeleteDoctorAdvice() {
  3937. id, _ := c.GetInt64("id")
  3938. advice, _ := service.GetHisDoctorAdvicesById(id)
  3939. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3940. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3941. //已收费和已发药的限制逻辑
  3942. isCharge := false
  3943. isMedicine := false
  3944. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3945. //获取今天该患者所有处方,判断是否发药或者收费
  3946. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3947. for _, item := range new_prescriptions {
  3948. if item.IsMedicine == 1 {
  3949. isMedicine = true
  3950. }
  3951. }
  3952. for _, item := range new_prescriptions {
  3953. if item.OrderStatus == 4 {
  3954. isCharge = true
  3955. }
  3956. }
  3957. if isMedicine {
  3958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3959. return
  3960. }
  3961. if isCharge {
  3962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3963. return
  3964. }
  3965. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3966. for _, item := range advices {
  3967. if item.IsMedicine == 1 {
  3968. isMedicine = true
  3969. }
  3970. }
  3971. if isMedicine {
  3972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3973. return
  3974. }
  3975. if new_prescription.ID > 0 {
  3976. if new_prescription.OrderStatus == 2 {
  3977. isCharge = true
  3978. }
  3979. }
  3980. if isCharge {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3982. return
  3983. }
  3984. //已收费和已发药的限制逻辑
  3985. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3986. redis := service.RedisClient()
  3987. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3988. redis.Set(keyFive, "", time.Second)
  3989. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3990. redis.Set(keyOne, "", time.Second)
  3991. defer redis.Close()
  3992. if err == nil {
  3993. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3994. //查询是否在处方中出库
  3995. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3996. if openConfig.IsOpen != 1 {
  3997. //判断该医嘱是否执行了
  3998. if advice.ExecutionState == 1 {
  3999. creater := c.GetAdminUserInfo().AdminUser.Id
  4000. service.DrugAutoAddCancelInfo(&advice, creater)
  4001. }
  4002. }
  4003. //开启保存处方扣减功能
  4004. if openConfig.IsOpen == 1 {
  4005. creater := c.GetAdminUserInfo().AdminUser.Id
  4006. service.DrugAutoAddCancelInfo(&advice, creater)
  4007. }
  4008. } else {
  4009. if drugOutConfig.IsOpen == 1 {
  4010. //查询是否在处方中出库
  4011. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4012. if openConfig.IsOpen != 1 {
  4013. //判断该医嘱是否执行了
  4014. if advice.ExecutionState == 1 {
  4015. creater := c.GetAdminUserInfo().AdminUser.Id
  4016. service.DrugAutoAddCancelInfo(&advice, creater)
  4017. }
  4018. }
  4019. //开启保存处方扣减功能
  4020. if openConfig.IsOpen == 1 {
  4021. creater := c.GetAdminUserInfo().AdminUser.Id
  4022. service.DrugAutoAddCancelInfo(&advice, creater)
  4023. }
  4024. } else {
  4025. //判断该医嘱是否执行了
  4026. if advice.ExecutionState == 1 {
  4027. creater := c.GetAdminUserInfo().AdminUser.Id
  4028. service.DrugAutoAddCancelInfo(&advice, creater)
  4029. }
  4030. }
  4031. }
  4032. c.ServeSuccessJSON(map[string]interface{}{
  4033. "msg": "删除成功",
  4034. })
  4035. return
  4036. } else {
  4037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4038. return
  4039. }
  4040. }
  4041. func (c *HisApiController) DeleteProject() {
  4042. id, _ := c.GetInt64("id")
  4043. adminInfo := c.GetAdminUserInfo()
  4044. project, _ := service.GetHisProjectByID(id)
  4045. // var consumable models.DialysisBeforePrepare
  4046. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4047. //耗材保存处方出库
  4048. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4049. isCharge := false
  4050. isMedicine := false
  4051. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4052. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4053. for _, item := range new_prescriptions {
  4054. if item.IsMedicine == 1 {
  4055. isMedicine = true
  4056. }
  4057. }
  4058. for _, item := range new_prescriptions {
  4059. if item.OrderStatus == 4 {
  4060. isCharge = true
  4061. }
  4062. }
  4063. if isMedicine {
  4064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4065. return
  4066. }
  4067. if isCharge {
  4068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4069. return
  4070. }
  4071. if new_prescription.ID > 0 {
  4072. if new_prescription.OrderStatus == 2 {
  4073. isCharge = true
  4074. }
  4075. }
  4076. if isCharge {
  4077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4078. return
  4079. }
  4080. service.DeletePrintInfo(id)
  4081. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4082. label.Status = 0
  4083. service.CreateHisLabelRecord(&label)
  4084. fmt.Println(goodOutConfig.IsOpen)
  4085. if goodOutConfig.IsOpen != 1 {
  4086. if stockConfig.IsOpen == 1 {
  4087. if project.Type == 2 {
  4088. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4089. fmt.Println(err)
  4090. }
  4091. if project.Type == 3 && project.IsOut == 1 {
  4092. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4093. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4094. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4095. operation_time := time.Now().Unix()
  4096. creater := adminInfo.AdminUser.Id
  4097. //创建退库单
  4098. timeStr := time.Now().Format("2006-01-02")
  4099. timeArr := strings.Split(timeStr, "-")
  4100. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4101. total = total + 1
  4102. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4103. cancelStock := models.CancelStock{
  4104. OrderNumber: orderNumber,
  4105. OperaTime: operation_time,
  4106. OrgId: adminInfo.CurrentOrgId,
  4107. Creater: creater,
  4108. Ctime: time.Now().Unix(),
  4109. Status: 1,
  4110. ReturnTime: project.RecordDate,
  4111. Type: 1,
  4112. StorehouseId: houseConfig.StorehouseOutInfo,
  4113. IsCheck: 1,
  4114. }
  4115. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4116. if msgerrkonde == gorm.ErrRecordNotFound {
  4117. service.AddSigleCancelStock(&cancelStock)
  4118. }
  4119. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4120. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4121. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4122. //查询是否有出库
  4123. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4124. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4125. deaerler, _ := service.GetDealerById(info.Dealer)
  4126. if info.ID > 0 {
  4127. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4128. if info.Count >= prescribingNumber {
  4129. cancelStockInfo := models.CancelStockInfo{
  4130. GoodId: project.ProjectId,
  4131. CancelStockId: cancel.ID,
  4132. GoodTypeId: good.GoodTypeId,
  4133. Count: prescribingNumber,
  4134. Price: info.Price,
  4135. Total: 0,
  4136. ProductDate: info.ProductDate,
  4137. ExpiryDate: info.ExpiryDate,
  4138. Ctime: time.Now().Unix(),
  4139. Status: 1,
  4140. OrgId: adminInfo.CurrentOrgId,
  4141. OrderNumber: cancel.OrderNumber,
  4142. Type: 0,
  4143. Dealer: deaerler.DealerName,
  4144. Manufacturer: manufacturer.ManufacturerName,
  4145. Number: info.Number,
  4146. RegisterAccount: "",
  4147. Remark: "",
  4148. WarehouseInfoId: info.WarehouseInfotId,
  4149. PatientId: info.PatientId,
  4150. RecordDate: info.SysRecordTime,
  4151. StorehouseId: houseConfig.StorehouseOutInfo,
  4152. IsCheck: 1,
  4153. }
  4154. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4155. //回退库存
  4156. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4157. //退库数量增加
  4158. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4159. //出库数量减少
  4160. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4161. }
  4162. if info.Count < prescribingNumber {
  4163. cancelStockInfo := models.CancelStockInfo{
  4164. GoodId: project.ProjectId,
  4165. CancelStockId: cancel.ID,
  4166. GoodTypeId: good.GoodTypeId,
  4167. Count: info.Count,
  4168. Price: info.Price,
  4169. Total: 0,
  4170. ProductDate: info.ProductDate,
  4171. ExpiryDate: info.ExpiryDate,
  4172. Ctime: time.Now().Unix(),
  4173. Status: 1,
  4174. OrgId: adminInfo.CurrentOrgId,
  4175. OrderNumber: cancel.OrderNumber,
  4176. Type: 0,
  4177. Dealer: deaerler.DealerName,
  4178. Manufacturer: manufacturer.ManufacturerName,
  4179. Number: info.Number,
  4180. RegisterAccount: "",
  4181. Remark: "",
  4182. WarehouseInfoId: info.WarehouseInfotId,
  4183. PatientId: info.PatientId,
  4184. RecordDate: info.SysRecordTime,
  4185. StorehouseId: houseConfig.StorehouseOutInfo,
  4186. IsCheck: 1,
  4187. }
  4188. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4189. //回退库存
  4190. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4191. //退库数量增加
  4192. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4193. //出库数量减少
  4194. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4195. }
  4196. //查询剩余库存
  4197. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4198. var over_count int64
  4199. for _, it := range goodList {
  4200. over_count += it.StockCount
  4201. }
  4202. //出库数据 大于 退库数量
  4203. if info.Count >= prescribingNumber {
  4204. flow := models.VmStockFlow{
  4205. WarehousingId: info.WarehouseInfotId,
  4206. GoodId: project.ProjectId,
  4207. Number: info.Number,
  4208. LicenseNumber: info.LicenseNumber,
  4209. Count: prescribingNumber,
  4210. UserOrgId: adminInfo.CurrentOrgId,
  4211. PatientId: project.PatientId,
  4212. SystemTime: info.SysRecordTime,
  4213. ConsumableType: 7,
  4214. IsSys: 0,
  4215. WarehousingOrder: "",
  4216. WarehouseOutId: info.WarehouseOutId,
  4217. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4218. IsEdit: 0,
  4219. CancelStockId: cancel.ID,
  4220. CancelOrderNumber: cancel.OrderNumber,
  4221. Manufacturer: manufacturer.ID,
  4222. Dealer: 0,
  4223. Creator: adminInfo.AdminUser.Id,
  4224. UpdateCreator: 0,
  4225. Status: 1,
  4226. Ctime: time.Now().Unix(),
  4227. Mtime: 0,
  4228. Price: info.Price,
  4229. WarehousingDetailId: info.WarehouseInfotId,
  4230. WarehouseOutDetailId: info.ID,
  4231. CancelOutDetailId: cancelInfo.ID,
  4232. ProductDate: info.ProductDate,
  4233. ExpireDate: info.ExpiryDate,
  4234. StorehouseId: houseConfig.StorehouseOutInfo,
  4235. OverCount: over_count,
  4236. }
  4237. service.CreateStockFlowOne(flow)
  4238. }
  4239. //出库数据小于退库数据
  4240. if info.Count < prescribingNumber {
  4241. flow := models.VmStockFlow{
  4242. WarehousingId: info.WarehouseInfotId,
  4243. GoodId: project.ProjectId,
  4244. Number: info.Number,
  4245. LicenseNumber: info.LicenseNumber,
  4246. Count: info.Count,
  4247. UserOrgId: adminInfo.CurrentOrgId,
  4248. PatientId: project.PatientId,
  4249. SystemTime: info.SysRecordTime,
  4250. ConsumableType: 7,
  4251. IsSys: 0,
  4252. WarehousingOrder: "",
  4253. WarehouseOutId: info.WarehouseOutId,
  4254. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4255. IsEdit: 0,
  4256. CancelStockId: cancel.ID,
  4257. CancelOrderNumber: cancel.OrderNumber,
  4258. Manufacturer: manufacturer.ID,
  4259. Dealer: 0,
  4260. Creator: adminInfo.AdminUser.Id,
  4261. UpdateCreator: 0,
  4262. Status: 1,
  4263. Ctime: time.Now().Unix(),
  4264. Mtime: 0,
  4265. Price: info.Price,
  4266. WarehousingDetailId: info.WarehouseInfotId,
  4267. WarehouseOutDetailId: info.ID,
  4268. CancelOutDetailId: cancelInfo.ID,
  4269. ProductDate: info.ProductDate,
  4270. ExpireDate: info.ExpiryDate,
  4271. StorehouseId: houseConfig.StorehouseOutInfo,
  4272. OverCount: over_count,
  4273. }
  4274. service.CreateStockFlowOne(flow)
  4275. }
  4276. //查询已出库数量
  4277. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4278. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4279. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4280. if prescribingNumber < dialysisInfo.Count {
  4281. //改变数量
  4282. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4283. }
  4284. if prescribingNumber >= dialysisInfo.Count {
  4285. //删除出库表
  4286. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4287. }
  4288. //更新剩余库存
  4289. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4290. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4291. var total_count_one int64
  4292. for _, it := range stockList {
  4293. total_count_one += it.StockCount
  4294. }
  4295. //基础库插入数据
  4296. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4297. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4298. var flush_count int64
  4299. for _, it := range goodListOne {
  4300. flush_count += it.StockCount
  4301. }
  4302. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4303. if errs != nil {
  4304. goodErrcode := models.XtGoodErrcode{
  4305. UserOrgId: project.UserOrgId,
  4306. Errcode: "手动出库更新剩余出库失败",
  4307. GoodId: project.ProjectId,
  4308. Status: 1,
  4309. Ctime: time.Now().Unix(),
  4310. Mtime: 0,
  4311. Count: 0,
  4312. StockCount: 0,
  4313. Creater: creater,
  4314. BatchNumberId: 0,
  4315. WarehouseOutId: 0,
  4316. }
  4317. service.CreateGoodErrcode(goodErrcode)
  4318. }
  4319. }
  4320. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4321. fmt.Println(err)
  4322. } else {
  4323. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4324. fmt.Println(err)
  4325. }
  4326. } else {
  4327. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4328. fmt.Println(err)
  4329. }
  4330. }
  4331. //保存处方出库
  4332. if goodOutConfig.IsOpen == 1 {
  4333. if project.Type == 3 {
  4334. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4335. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4336. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4337. operation_time := time.Now().Unix()
  4338. creater := adminInfo.AdminUser.Id
  4339. //创建退库单
  4340. timeStr := time.Now().Format("2006-01-02")
  4341. timeArr := strings.Split(timeStr, "-")
  4342. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4343. total = total + 1
  4344. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4345. cancelStock := models.CancelStock{
  4346. OrderNumber: orderNumber,
  4347. OperaTime: operation_time,
  4348. OrgId: adminInfo.CurrentOrgId,
  4349. Creater: creater,
  4350. Ctime: time.Now().Unix(),
  4351. Status: 1,
  4352. ReturnTime: project.RecordDate,
  4353. Type: 1,
  4354. StorehouseId: houseConfig.StorehouseOutInfo,
  4355. IsCheck: 1,
  4356. }
  4357. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4358. if msgerrkonde == gorm.ErrRecordNotFound {
  4359. service.AddSigleCancelStock(&cancelStock)
  4360. }
  4361. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4362. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4363. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4364. //获取出库数据
  4365. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4366. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4367. deaerler, _ := service.GetDealerById(info.Dealer)
  4368. if info.ID > 0 {
  4369. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4370. if info.Count >= prescribingNumber {
  4371. cancelStockInfo := models.CancelStockInfo{
  4372. GoodId: project.ProjectId,
  4373. CancelStockId: cancel.ID,
  4374. GoodTypeId: good.GoodTypeId,
  4375. Count: prescribingNumber,
  4376. Price: info.Price,
  4377. Total: 0,
  4378. ProductDate: info.ProductDate,
  4379. ExpiryDate: info.ExpiryDate,
  4380. Ctime: time.Now().Unix(),
  4381. Status: 1,
  4382. OrgId: adminInfo.CurrentOrgId,
  4383. OrderNumber: cancel.OrderNumber,
  4384. Type: 0,
  4385. Dealer: deaerler.DealerName,
  4386. Manufacturer: manufacturer.ManufacturerName,
  4387. Number: info.Number,
  4388. RegisterAccount: "",
  4389. Remark: "",
  4390. WarehouseInfoId: info.WarehouseInfotId,
  4391. PatientId: info.PatientId,
  4392. RecordDate: info.SysRecordTime,
  4393. StorehouseId: houseConfig.StorehouseOutInfo,
  4394. IsCheck: 1,
  4395. }
  4396. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4397. //退库数量增加
  4398. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4399. //出库数量减少
  4400. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4401. }
  4402. if info.Count < prescribingNumber {
  4403. cancelStockInfo := models.CancelStockInfo{
  4404. GoodId: project.ProjectId,
  4405. CancelStockId: cancel.ID,
  4406. GoodTypeId: good.GoodTypeId,
  4407. Count: prescribingNumber,
  4408. Price: info.Price,
  4409. Total: 0,
  4410. ProductDate: info.ProductDate,
  4411. ExpiryDate: info.ExpiryDate,
  4412. Ctime: time.Now().Unix(),
  4413. Status: 1,
  4414. OrgId: adminInfo.CurrentOrgId,
  4415. OrderNumber: cancel.OrderNumber,
  4416. Type: 0,
  4417. Dealer: deaerler.DealerName,
  4418. Manufacturer: manufacturer.ManufacturerName,
  4419. Number: info.Number,
  4420. RegisterAccount: "",
  4421. Remark: "",
  4422. WarehouseInfoId: info.WarehouseInfotId,
  4423. PatientId: info.PatientId,
  4424. RecordDate: info.SysRecordTime,
  4425. StorehouseId: houseConfig.StorehouseOutInfo,
  4426. IsCheck: 1,
  4427. }
  4428. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4429. //回退库存
  4430. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4431. }
  4432. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4433. var over_count int64
  4434. for _, it := range goodList {
  4435. over_count += it.StockCount
  4436. }
  4437. //查询出库数量
  4438. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4439. //出库数据 大于 退库数量
  4440. if len(list) > 0 {
  4441. for _, it := range list {
  4442. //回退库存
  4443. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4444. //退库数量增加
  4445. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4446. //出库数量减少
  4447. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4448. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4449. var over_count_one int64
  4450. for _, it := range goodList {
  4451. over_count_one += it.StockCount
  4452. }
  4453. //查询该批次是否有退库数据
  4454. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4455. flow := models.VmStockFlow{
  4456. WarehousingId: it.WarehouseInfotId,
  4457. GoodId: it.GoodId,
  4458. Number: it.Number,
  4459. LicenseNumber: it.LicenseNumber,
  4460. Count: it.Count,
  4461. UserOrgId: adminInfo.CurrentOrgId,
  4462. PatientId: it.PatientId,
  4463. SystemTime: it.SysRecordTime,
  4464. ConsumableType: 7,
  4465. IsSys: 0,
  4466. WarehousingOrder: "",
  4467. WarehouseOutId: it.WarehouseOutId,
  4468. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4469. IsEdit: 0,
  4470. CancelStockId: cancel.ID,
  4471. CancelOrderNumber: cancel.OrderNumber,
  4472. Manufacturer: manufacturer.ID,
  4473. Dealer: 0,
  4474. Creator: adminInfo.AdminUser.Id,
  4475. UpdateCreator: 0,
  4476. Status: 1,
  4477. Ctime: time.Now().Unix(),
  4478. Mtime: 0,
  4479. Price: it.Price,
  4480. WarehousingDetailId: it.WarehouseInfotId,
  4481. WarehouseOutDetailId: it.ID,
  4482. CancelOutDetailId: cancelInfo.ID,
  4483. ProductDate: it.ProductDate,
  4484. ExpireDate: it.ExpiryDate,
  4485. StorehouseId: houseConfig.StorehouseOutInfo,
  4486. OverCount: over_count_one,
  4487. }
  4488. service.CreateStockFlowOne(flow)
  4489. }
  4490. }
  4491. //查询已出库数量
  4492. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4493. if prescribingNumber < dialysisInfo.Count {
  4494. //改变数量
  4495. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4496. }
  4497. if prescribingNumber >= dialysisInfo.Count {
  4498. //删除出库表
  4499. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4500. }
  4501. //更新剩余库存
  4502. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4503. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4504. var total_count_one int64
  4505. for _, it := range stockList {
  4506. total_count_one += it.StockCount
  4507. }
  4508. //基础库插入数据
  4509. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4510. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4511. var flush_count int64
  4512. for _, it := range goodListOne {
  4513. flush_count += it.StockCount
  4514. }
  4515. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4516. if errs != nil {
  4517. goodErrcode := models.XtGoodErrcode{
  4518. UserOrgId: project.UserOrgId,
  4519. Errcode: "手动出库更新剩余出库失败",
  4520. GoodId: project.ProjectId,
  4521. Status: 1,
  4522. Ctime: time.Now().Unix(),
  4523. Mtime: 0,
  4524. Count: 0,
  4525. StockCount: 0,
  4526. Creater: creater,
  4527. BatchNumberId: 0,
  4528. WarehouseOutId: 0,
  4529. }
  4530. service.CreateGoodErrcode(goodErrcode)
  4531. }
  4532. }
  4533. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4534. fmt.Println(err)
  4535. } else {
  4536. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4537. fmt.Println(err)
  4538. }
  4539. }
  4540. c.ServeSuccessJSON(map[string]interface{}{
  4541. "msg": "删除成功",
  4542. })
  4543. return
  4544. }
  4545. func (c *HisApiController) CreateHisAdditionalCharge() {
  4546. his_patient_id, _ := c.GetInt64("his_patient_id")
  4547. patient_id, _ := c.GetInt64("patient_id")
  4548. record_date := c.GetString("record_date")
  4549. timeLayout := "2006-01-02"
  4550. loc, _ := time.LoadLocation("Local")
  4551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4552. if err != nil {
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4554. return
  4555. }
  4556. adminInfo := c.GetAdminUserInfo()
  4557. recordDateTime := theTime.Unix()
  4558. dataBody := make(map[string]interface{}, 0)
  4559. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4560. if err != nil {
  4561. utils.ErrorLog(err.Error())
  4562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. var additions []*models.HisAdditionalCharge
  4566. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4567. additions, _ := dataBody["addition"].([]interface{})
  4568. if len(additions) > 0 {
  4569. for _, item := range additions {
  4570. items := item.(map[string]interface{})
  4571. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4572. utils.ErrorLog("item_id")
  4573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4574. return
  4575. }
  4576. item_id := int64(items["item_id"].(float64))
  4577. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4578. utils.ErrorLog("item_name")
  4579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4580. return
  4581. }
  4582. item_name := items["item_name"].(string)
  4583. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4584. utils.ErrorLog("price")
  4585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4586. return
  4587. }
  4588. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4589. ctime := time.Now().Unix()
  4590. additional := &models.HisAdditionalCharge{
  4591. PatientId: patient_id,
  4592. HisPatientId: his_patient_id,
  4593. UserOrgId: adminInfo.CurrentOrgId,
  4594. RecordDate: recordDateTime,
  4595. CreatedTime: ctime,
  4596. UpdatedTime: ctime,
  4597. Modifier: adminInfo.AdminUser.Id,
  4598. Creator: adminInfo.AdminUser.Id,
  4599. Price: price,
  4600. ItemName: item_name,
  4601. ItemId: item_id,
  4602. Status: 1,
  4603. }
  4604. additions = append(additions, additional)
  4605. }
  4606. }
  4607. }
  4608. for _, item := range additions {
  4609. service.CreateAddtionalCharge(item)
  4610. }
  4611. c.ServeSuccessJSON(map[string]interface{}{
  4612. "msg": "创建成功",
  4613. })
  4614. }
  4615. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4616. blood_fat := c.GetString("blood_fat")
  4617. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4618. blood_sugar := c.GetString("blood_sugar")
  4619. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4620. chief_conplaint := c.GetString("chief_conplaint")
  4621. dbp := c.GetString("dbp")
  4622. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4623. delivery_way, _ := c.GetInt64("delivery_way")
  4624. diagnostic := c.GetString("diagnostic")
  4625. family_history := c.GetString("family_history")
  4626. height := c.GetString("height")
  4627. history_of_present_illness := c.GetString("history_of_present_illness")
  4628. is_infect, _ := c.GetInt64("is_infect")
  4629. past_history := c.GetString("past_history")
  4630. patient_id, _ := c.GetInt64("patient_id")
  4631. his_patient_id, _ := c.GetInt64("his_patient_id")
  4632. personal_history := c.GetString("personal_history")
  4633. pulse := c.GetString("pulse")
  4634. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4635. sbp := c.GetString("sbp")
  4636. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4637. heightfloat, _ := strconv.ParseFloat(height, 64)
  4638. sicktype := c.GetString("sick_type")
  4639. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4640. symptom := c.GetString("symptom")
  4641. sick_date := c.GetString("sick_date")
  4642. temperatures := c.GetString("temperature")
  4643. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4644. record_date := c.GetString("record_date")
  4645. breathing := c.GetString("breathing")
  4646. doctor_advice := c.GetString("doctor_advice")
  4647. remark := c.GetString("remark")
  4648. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4649. sick, _ := c.GetInt64("sick")
  4650. diagnose, _ := c.GetInt64("diagnose")
  4651. //id, _ := c.GetInt64("id")
  4652. timeLayout := "2006-01-02"
  4653. loc, _ := time.LoadLocation("Local")
  4654. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4655. allergic_history := c.GetString("allergic_history")
  4656. if err != nil {
  4657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4658. return
  4659. }
  4660. recordDateTime := theTime.Unix()
  4661. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4662. if err != nil {
  4663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4664. return
  4665. }
  4666. sickTimes := sickTime.Unix()
  4667. ctime := time.Now().Unix()
  4668. primary_disease := c.GetString("primary_disease")
  4669. confirm_failure_date := c.GetString("confirm_failure_date")
  4670. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4671. drug_allergy_history := c.GetString("drug_allergy_history")
  4672. physical_examination := c.GetString("physical_examination")
  4673. special_inspection := c.GetString("special_inspection")
  4674. lab_apparatus := c.GetString("lab_apparatus")
  4675. caseHistory := models.HisPatientCaseHistory{
  4676. HisPatientId: his_patient_id,
  4677. PatientId: patient_id,
  4678. Temperature: temperature,
  4679. BloodSugar: bloodsugarfloat,
  4680. Pulse: pulsefloat,
  4681. Sbp: sbpfloat,
  4682. Dbp: dbpfloat,
  4683. Height: heightfloat,
  4684. BloodFat: bloodfatfloat,
  4685. SickType: sick_type,
  4686. Symptom: symptom,
  4687. SickDate: sickTimes,
  4688. IsInfect: is_infect,
  4689. HistoryOfPresentIllness: history_of_present_illness,
  4690. PastHistory: past_history,
  4691. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4692. ChiefConplaint: chief_conplaint,
  4693. PersonalHistory: personal_history,
  4694. FamilyHistory: family_history,
  4695. Diagnostic: diagnostic,
  4696. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4697. Status: 1,
  4698. Ctime: ctime,
  4699. Mtime: ctime,
  4700. RecordDate: recordDateTime,
  4701. DeliveryWay: delivery_way,
  4702. Breathing: breathingfloat,
  4703. DoctorAdvice: doctor_advice,
  4704. Remark: remark,
  4705. Sick: sick,
  4706. Diagnose: diagnose,
  4707. AllergicHistory: allergic_history,
  4708. PrimaryDisease: primary_disease,
  4709. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4710. DrugAllergyHistory: drug_allergy_history,
  4711. PhysicalExamination: physical_examination,
  4712. SpecialInspection: special_inspection,
  4713. LabApparatus: lab_apparatus,
  4714. }
  4715. //查询该患者是否有病历
  4716. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4717. if errcodes == gorm.ErrRecordNotFound {
  4718. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4719. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4720. if err != nil {
  4721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4722. return
  4723. }
  4724. c.ServeSuccessJSON(map[string]interface{}{
  4725. "caseHistory": caseHistory,
  4726. "historyInfo": historyInfo,
  4727. })
  4728. return
  4729. } else if errcodes == nil {
  4730. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4731. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4732. if err != nil {
  4733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4734. return
  4735. }
  4736. c.ServeSuccessJSON(map[string]interface{}{
  4737. "caseHistory": caseHistory,
  4738. "historyInfo": historyInfo,
  4739. })
  4740. }
  4741. //查询该患者是否有病历
  4742. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4743. //if errcode == gorm.ErrRecordNotFound {
  4744. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4745. // if err != nil {
  4746. // c.ServeSuccessJSON(map[string]interface{}{
  4747. // "msg": "保存成功",
  4748. // })
  4749. // }
  4750. //} else if errcode == nil {
  4751. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4752. // return
  4753. //}
  4754. }
  4755. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4756. patient_id, _ := c.GetInt64("patient_id", 0)
  4757. adminUser := c.GetAdminUserInfo()
  4758. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4759. c.ServeSuccessJSON(map[string]interface{}{
  4760. "list": caseHistorys,
  4761. })
  4762. }
  4763. func (c *HisApiController) GetHisPatientCaseHistory() {
  4764. record_date, _ := c.GetInt64("record_date", 0)
  4765. patient_id, _ := c.GetInt64("patient_id", 0)
  4766. admin := c.GetAdminUserInfo()
  4767. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4768. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4769. c.ServeSuccessJSON(map[string]interface{}{
  4770. "info": info,
  4771. "case_history": case_history,
  4772. })
  4773. }
  4774. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4775. template_name := c.GetString("template_name")
  4776. template_remark := c.GetString("template_remark")
  4777. doctor := c.GetAdminUserInfo().AdminUser.Id
  4778. diagnostic := c.GetString("diagnostic")
  4779. chief_conplaint := c.GetString("chief_conplain")
  4780. history_of_present_illness := c.GetString("history_of_present_illness")
  4781. past_history := c.GetString("past_history")
  4782. personal_history := c.GetString("personal_history")
  4783. family_history := c.GetString("family_history")
  4784. user_name := c.GetString("user_name")
  4785. doctor_advice := c.GetString("doctor_advice")
  4786. remark := c.GetString("remark")
  4787. //record_date := c.GetString("record_date")
  4788. //fmt.Println("record_date--------",record_date)
  4789. //timeLayout := "2006-01-02"
  4790. //loc, _ := time.LoadLocation("Local")
  4791. //
  4792. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4793. //if err != nil {
  4794. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4795. // return
  4796. //}
  4797. //recordDateTime := theTime.Unix()
  4798. ctime := time.Now().Unix()
  4799. template := models.HisCaseHistoryTemplate{
  4800. HistoryOfPresentIllness: history_of_present_illness,
  4801. PastHistory: past_history,
  4802. ChiefConplaint: chief_conplaint,
  4803. PersonalHistory: personal_history,
  4804. FamilyHistory: family_history,
  4805. Diagnostic: diagnostic,
  4806. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4807. Status: 1,
  4808. Ctime: ctime,
  4809. Mtime: ctime,
  4810. RecordDate: time.Now().Unix(),
  4811. TemplateName: template_name,
  4812. TemplateRemark: template_remark,
  4813. Creator: doctor,
  4814. Modifier: doctor,
  4815. UserName: user_name,
  4816. DoctorAdvice: doctor_advice,
  4817. Remark: remark,
  4818. }
  4819. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4820. if err == nil {
  4821. c.ServeSuccessJSON(map[string]interface{}{
  4822. "msg": "保存成功",
  4823. })
  4824. } else {
  4825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4826. return
  4827. }
  4828. }
  4829. func (c *HisApiController) GetCaseHistoryTemplate() {
  4830. timeLayout := "2006-01-02"
  4831. loc, _ := time.LoadLocation("Local")
  4832. keyword := c.GetString("keyword")
  4833. start_time := c.GetString("start_time")
  4834. end_time := c.GetString("end_time")
  4835. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4836. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4837. admin := c.GetAdminUserInfo()
  4838. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4839. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4840. c.ServeSuccessJSON(map[string]interface{}{
  4841. "template": template,
  4842. //"history": history,
  4843. })
  4844. }
  4845. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4846. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4847. utils.ErrorLog("drug_name")
  4848. return enums.ErrorCodeParamWrong
  4849. }
  4850. adviceName, _ := json["drug_name"].(string)
  4851. if len(adviceName) == 0 {
  4852. utils.ErrorLog("len(advice_name) == 0")
  4853. return enums.ErrorCodeParamWrong
  4854. }
  4855. advice.AdviceName = adviceName
  4856. adviceDesc, _ := json["advice_desc"].(string)
  4857. advice.AdviceDesc = adviceDesc
  4858. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4859. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4860. advice.DrugSpec = drugSpec
  4861. }
  4862. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4863. remark, _ := json["remark"].(string)
  4864. advice.Remark = remark
  4865. }
  4866. if json["id"] == nil {
  4867. advice.DrugId = 0
  4868. } else {
  4869. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4870. drug_id := int64(json["id"].(float64))
  4871. advice.DrugId = drug_id
  4872. }
  4873. }
  4874. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4875. advice_id := int64(json["advice_id"].(float64))
  4876. advice.ID = advice_id
  4877. if advice.ID > 0 {
  4878. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4879. if err == nil {
  4880. if hisAdvice.ID > 0 {
  4881. advice.ExecutionTime = hisAdvice.ExecutionTime
  4882. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4883. advice.ExecutionState = hisAdvice.ExecutionState
  4884. advice.CheckTime = hisAdvice.CheckTime
  4885. advice.Checker = hisAdvice.Checker
  4886. advice.CheckState = hisAdvice.CheckState
  4887. advice.StartTime = hisAdvice.StartTime
  4888. advice.FeedetlSn = hisAdvice.FeedetlSn
  4889. }
  4890. }
  4891. }
  4892. }
  4893. //
  4894. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4895. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4896. // advice.ExecutionTime = execution_time
  4897. //}
  4898. //
  4899. //
  4900. //
  4901. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4902. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4903. // advice.ExecutionStaff = execution_staff
  4904. //}
  4905. //
  4906. //
  4907. //
  4908. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4909. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4910. // advice.ExecutionState = execution_state
  4911. //}
  4912. //
  4913. //
  4914. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4915. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4916. // advice.CheckTime = check_time
  4917. //}
  4918. //
  4919. //
  4920. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4921. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4922. // advice.CheckState = check_state
  4923. //}
  4924. //
  4925. //
  4926. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4927. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4928. // advice.Checker = checker
  4929. //}
  4930. //
  4931. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4932. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4933. // advice.StartTime = start_time
  4934. //}
  4935. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4936. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4937. advice.IsSelfDrug = is_self_drug
  4938. }
  4939. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4940. drugSpecUnit, _ := json["min_unit"].(string)
  4941. advice.DrugSpecUnit = drugSpecUnit
  4942. }
  4943. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4944. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4945. advice.SingleDose = singleDose
  4946. }
  4947. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4948. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4949. advice.SingleDoseUnit = singleDoseUnit
  4950. }
  4951. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4952. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4953. advice.PrescribingNumber = prescribingNumber
  4954. }
  4955. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4956. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4957. advice.PrescribingNumberUnit = prescribingNumberUnit
  4958. }
  4959. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4960. deliveryWay, _ := json["delivery_way"].(string)
  4961. advice.DeliveryWay = deliveryWay
  4962. }
  4963. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4964. executionFrequency, _ := json["execution_frequency"].(string)
  4965. advice.ExecutionFrequency = executionFrequency
  4966. }
  4967. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4968. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4969. advice.Price = price
  4970. }
  4971. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4972. med_list_codg, _ := json["medical_insurance_number"].(string)
  4973. advice.MedListCodg = med_list_codg
  4974. }
  4975. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4976. day := int64(json["day"].(float64))
  4977. advice.Day = day
  4978. }
  4979. return 0
  4980. }
  4981. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4982. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4983. id := int64(json["id"].(float64))
  4984. project.ID = id
  4985. historyProject, _ := service.GetHisProjectByID(id)
  4986. project.FeedetlSn = historyProject.FeedetlSn
  4987. }
  4988. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4989. project_id := int64(json["project_id"].(float64))
  4990. project.ProjectId = project_id
  4991. }
  4992. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4993. // price := int64(json["price"].(float64))
  4994. // formatInt_price := strconv.FormatInt(price, 10)
  4995. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4996. // project.Price = float_price
  4997. // }
  4998. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4999. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5000. project.Price = price
  5001. }
  5002. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5003. total, _ := json["total"].(string)
  5004. project.Count = total
  5005. }
  5006. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5007. medical_code, _ := json["medical_code"].(string)
  5008. project.MedListCodg = medical_code
  5009. }
  5010. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5011. single_dose, _ := json["single_dose"].(string)
  5012. project.SingleDose = single_dose
  5013. }
  5014. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5015. delivery_way, _ := json["delivery_way"].(string)
  5016. project.DeliveryWay = delivery_way
  5017. }
  5018. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5019. execution_frequency, _ := json["execution_frequency"].(string)
  5020. project.ExecutionFrequency = execution_frequency
  5021. }
  5022. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5023. remark, _ := json["remark"].(string)
  5024. project.Remark = remark
  5025. }
  5026. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5027. day, _ := json["number_days"].(string)
  5028. project.Day = day
  5029. }
  5030. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5031. unit, _ := json["unit"].(string)
  5032. project.Unit = unit
  5033. }
  5034. return 0
  5035. }
  5036. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5037. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5038. id := int64(json["id"].(float64))
  5039. historyAddtions, _ := service.GetHisAdditionByID(id)
  5040. additionalCharge.ID = id
  5041. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5042. }
  5043. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5044. item_id := int64(json["item_id"].(float64))
  5045. additionalCharge.ItemId = item_id
  5046. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5047. if config.ID > 0 {
  5048. if len(config.Code) > 0 {
  5049. additionalCharge.MedListCodg = config.Code
  5050. }
  5051. }
  5052. }
  5053. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5054. // price := int64(json["price"].(float64))
  5055. // formatInt_price := strconv.FormatInt(price, 10)
  5056. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5057. // additionalCharge.Price = float_price
  5058. // }
  5059. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5060. // price := int64(json["price"].(float64))
  5061. // formatInt_price := strconv.FormatInt(price, 10)
  5062. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5063. // additionalCharge.Price = float_price
  5064. //}
  5065. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5066. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5067. additionalCharge.Price = price
  5068. }
  5069. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5070. count, _ := json["count"].(string)
  5071. counts, _ := strconv.ParseInt(count, 10, 64)
  5072. additionalCharge.Count = counts
  5073. }
  5074. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5075. item_name, _ := json["item_name"].(string)
  5076. additionalCharge.ItemName = item_name
  5077. }
  5078. return 0
  5079. }
  5080. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5081. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5082. utils.ErrorLog("drug_name")
  5083. return enums.ErrorCodeParamWrong
  5084. }
  5085. adviceName, _ := json["drug_name"].(string)
  5086. if len(adviceName) == 0 {
  5087. utils.ErrorLog("len(advice_name) == 0")
  5088. return enums.ErrorCodeParamWrong
  5089. }
  5090. advice.AdviceName = adviceName
  5091. adviceDesc, _ := json["advice_desc"].(string)
  5092. advice.AdviceDesc = adviceDesc
  5093. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5094. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5095. advice.DrugSpec = drugSpec
  5096. }
  5097. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5098. remark, _ := json["remark"].(string)
  5099. advice.Remark = remark
  5100. }
  5101. if json["id"] == nil {
  5102. advice.DrugId = 0
  5103. } else {
  5104. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5105. drug_id := int64(json["id"].(float64))
  5106. advice.DrugId = drug_id
  5107. }
  5108. }
  5109. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5110. groupno := int64(json["groupno"].(float64))
  5111. advice.Groupno = groupno
  5112. }
  5113. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5114. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5115. advice.IsSelfDrug = is_self_drug
  5116. }
  5117. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5118. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5119. advice.HospApprFlag = hosp_appr_flag
  5120. }
  5121. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5122. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5123. advice.PrescribingNumber = prescribingNumber
  5124. }
  5125. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5126. // frequency_type := int64(json["frequency_type"].(float64))
  5127. // advice.FrequencyType = frequency_type
  5128. //}
  5129. //
  5130. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5131. // day_count := int64(json["day_count"].(float64))
  5132. // advice.DayCount = day_count
  5133. //}
  5134. //
  5135. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5136. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5137. // week_day, _ := json["week_day"].(string)
  5138. // advice.WeekDay = week_day
  5139. //}
  5140. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5141. drugSpecUnit, _ := json["min_unit"].(string)
  5142. advice.DrugSpecUnit = drugSpecUnit
  5143. }
  5144. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5145. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5146. advice.SingleDose = singleDose
  5147. }
  5148. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5149. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5150. advice.SingleDoseUnit = singleDoseUnit
  5151. }
  5152. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5153. deliveryWay, _ := json["delivery_way"].(string)
  5154. advice.DeliveryWay = deliveryWay
  5155. }
  5156. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5157. executionFrequency, _ := json["execution_frequency"].(string)
  5158. advice.ExecutionFrequency = executionFrequency
  5159. }
  5160. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5161. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5162. advice.Price = price
  5163. }
  5164. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5165. med_list_codg, _ := json["medical_insurance_number"].(string)
  5166. advice.MedListCodg = med_list_codg
  5167. }
  5168. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5169. day := int64(json["day"].(float64))
  5170. advice.Day = day
  5171. }
  5172. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5173. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5174. advice.PrescribingNumberUnit = prescribingNumberUnit
  5175. }
  5176. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5177. advice_id := int64(json["advice_id"].(float64))
  5178. advice.ID = advice_id
  5179. if advice.ID > 0 {
  5180. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5181. if err == nil {
  5182. if hisAdvice.ID > 0 {
  5183. advice.ExecutionTime = hisAdvice.ExecutionTime
  5184. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5185. advice.ExecutionState = hisAdvice.ExecutionState
  5186. advice.CheckTime = hisAdvice.CheckTime
  5187. advice.Checker = hisAdvice.Checker
  5188. advice.CheckState = hisAdvice.CheckState
  5189. advice.StartTime = hisAdvice.StartTime
  5190. advice.HospApprFlag = hisAdvice.HospApprFlag
  5191. advice.IsMedicine = hisAdvice.IsMedicine
  5192. if hisAdvice.UserOrgId == 10028 {
  5193. 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 {
  5194. advice.ExecutionTime = 0
  5195. advice.ExecutionStaff = 0
  5196. advice.ExecutionState = 2
  5197. advice.CheckTime = 0
  5198. advice.Checker = 0
  5199. advice.CheckState = 2
  5200. }
  5201. } else {
  5202. 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 {
  5203. advice.ExecutionTime = 0
  5204. advice.ExecutionStaff = 0
  5205. advice.ExecutionState = 2
  5206. advice.CheckTime = 0
  5207. advice.Checker = 0
  5208. advice.CheckState = 2
  5209. }
  5210. }
  5211. //advice.Groupno = hisAdvice.Groupno
  5212. }
  5213. }
  5214. }
  5215. }
  5216. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5217. //
  5218. //if drugStockConfig.IsOpen == 1 {
  5219. //
  5220. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5221. // if advice.ID == 0 { //医嘱不存在
  5222. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5223. // drug.Total = drug.Total - advice.PrescribingNumber
  5224. // service.UpdateBaseDrugLib(&drug)
  5225. //
  5226. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5227. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5228. // drug.Total = drug.Total - num
  5229. // service.UpdateBaseDrugLib(&drug)
  5230. // }
  5231. //
  5232. // } else if advice.ID > 0 { //医嘱存在
  5233. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5234. // var num float64
  5235. //
  5236. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5237. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5238. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5239. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5240. // drug.Total = drug.Total + num
  5241. // service.UpdateBaseDrugLib(&drug)
  5242. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5243. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5244. // drug.Total = drug.Total - num
  5245. // service.UpdateBaseDrugLib(&drug)
  5246. // }
  5247. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5248. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5249. // if num2 > advice.PrescribingNumber {
  5250. // num = num2 - advice.PrescribingNumber
  5251. // drug.Total = drug.Total + num
  5252. // service.UpdateBaseDrugLib(&drug)
  5253. // } else if num2 < advice.PrescribingNumber {
  5254. // num = advice.PrescribingNumber - num2
  5255. // drug.Total = drug.Total - num
  5256. // service.UpdateBaseDrugLib(&drug)
  5257. // }
  5258. //
  5259. // }
  5260. //
  5261. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5262. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5263. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5264. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5265. // if num1 > num2 {
  5266. // num = num1 - num2
  5267. // drug.Total = drug.Total + num
  5268. // service.UpdateBaseDrugLib(&drug)
  5269. // } else if num1 < num2 {
  5270. // num = num2 - num1
  5271. // drug.Total = drug.Total - num
  5272. // service.UpdateBaseDrugLib(&drug)
  5273. // }
  5274. //
  5275. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5276. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5277. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5278. // if hisAdvice.PrescribingNumber > num2 {
  5279. // num = hisAdvice.PrescribingNumber - num2
  5280. // drug.Total = drug.Total + num
  5281. // service.UpdateBaseDrugLib(&drug)
  5282. // } else if num2 < advice.PrescribingNumber {
  5283. // num = num2 - hisAdvice.PrescribingNumber
  5284. // drug.Total = drug.Total - num
  5285. // service.UpdateBaseDrugLib(&drug)
  5286. // }
  5287. //
  5288. // }
  5289. // }
  5290. // }
  5291. //}
  5292. //
  5293. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5294. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5295. // advice.ExecutionTime = execution_time
  5296. //}
  5297. //
  5298. //
  5299. //
  5300. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5301. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5302. // advice.ExecutionStaff = execution_staff
  5303. //}
  5304. //
  5305. //
  5306. //
  5307. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5308. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5309. // advice.ExecutionState = execution_state
  5310. //}
  5311. //
  5312. //
  5313. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5314. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5315. // advice.CheckTime = check_time
  5316. //}
  5317. //
  5318. //
  5319. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5320. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5321. // advice.CheckState = check_state
  5322. //}
  5323. //
  5324. //
  5325. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5326. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5327. // advice.Checker = checker
  5328. //}
  5329. //
  5330. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5331. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5332. // advice.StartTime = start_time
  5333. //}
  5334. return 0
  5335. }
  5336. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5337. project.ExecutionStaff = 0
  5338. project.ExecutionState = 2
  5339. project.ExecutionTime = 0
  5340. project.Checker = 0
  5341. project.CheckState = 2
  5342. project.CheckTime = 0
  5343. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5344. id := int64(json["id"].(float64))
  5345. project.ID = id
  5346. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5347. project.ExecutionStaff = temp_project.ExecutionStaff
  5348. project.ExecutionState = temp_project.ExecutionState
  5349. project.ExecutionTime = temp_project.ExecutionTime
  5350. project.Checker = temp_project.Checker
  5351. project.CheckState = temp_project.CheckState
  5352. project.CheckTime = temp_project.CheckTime
  5353. project.TeamId = temp_project.TeamId
  5354. }
  5355. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5356. types := int64(json["type"].(float64))
  5357. project.Type = types
  5358. }
  5359. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5360. project_id := int64(json["project_id"].(float64))
  5361. project.ProjectId = project_id
  5362. }
  5363. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5364. team_id := int64(json["team_id"].(float64))
  5365. project.TeamId = team_id
  5366. }
  5367. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5368. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5369. project.Price = price
  5370. }
  5371. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5372. total, _ := json["total"].(string)
  5373. //totals, _ := strconv.ParseInt(total, 10, 64)
  5374. project.Count = total
  5375. }
  5376. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5377. medical_code, _ := json["medical_code"].(string)
  5378. project.MedListCodg = medical_code
  5379. }
  5380. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5381. single_dose, _ := json["single_dose"].(string)
  5382. project.SingleDose = single_dose
  5383. }
  5384. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5385. delivery_way, _ := json["delivery_way"].(string)
  5386. project.DeliveryWay = delivery_way
  5387. }
  5388. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5389. execution_frequency, _ := json["execution_frequency"].(string)
  5390. project.ExecutionFrequency = execution_frequency
  5391. }
  5392. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5393. remark, _ := json["remark"].(string)
  5394. project.Remark = remark
  5395. }
  5396. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5397. day, _ := json["number_days"].(string)
  5398. project.Day = day
  5399. }
  5400. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5401. unit, _ := json["unit"].(string)
  5402. project.Unit = unit
  5403. }
  5404. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5405. // frequency_type := int64(json["frequency_type"].(float64))
  5406. // project.FrequencyType = frequency_type
  5407. //}
  5408. //
  5409. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5410. // day_count := int64(json["day_count"].(float64))
  5411. // project.DayCount = day_count
  5412. //}
  5413. //
  5414. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5415. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5416. // week_day, _ := json["week_day"].(string)
  5417. // project.WeekDay = week_day
  5418. //}
  5419. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5420. //
  5421. //if project.ID == 0 {
  5422. // if stockConfig.IsOpen == 1 {
  5423. // if project.Type == 3 {
  5424. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5425. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5426. // good.Total = good.Total - f_count
  5427. // service.UpdateGoodInfo(&good)
  5428. // }
  5429. // }
  5430. //
  5431. //} else {
  5432. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5433. //
  5434. // if stockConfig.IsOpen == 1 {
  5435. // if project.Type == 3 {
  5436. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5437. // if project.Count < temp_project.Count {
  5438. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5439. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5440. //
  5441. // other_count := f_count_two - f_count_one
  5442. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5443. // good.Total = good.Total + other_count_two
  5444. // service.UpdateGoodInfo(&good)
  5445. // } else if project.Count > temp_project.Count {
  5446. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5447. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5448. //
  5449. // other_count := f_count_one - f_count_two
  5450. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5451. // good.Total = good.Total - other_count_two
  5452. // service.UpdateGoodInfo(&good)
  5453. // }
  5454. //
  5455. // }
  5456. // }
  5457. //
  5458. //}
  5459. return 0
  5460. }
  5461. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5462. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5463. id := int64(json["id"].(float64))
  5464. additionalCharge.ID = id
  5465. }
  5466. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5467. item_id := int64(json["item_id"].(float64))
  5468. additionalCharge.ItemId = item_id
  5469. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5470. if config.ID > 0 {
  5471. if len(config.Code) > 0 {
  5472. additionalCharge.MedListCodg = config.Code
  5473. }
  5474. }
  5475. }
  5476. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5477. // price := int64(json["price"].(float64))
  5478. // formatInt_price := strconv.FormatInt(price, 10)
  5479. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5480. // additionalCharge.Price = float_price
  5481. // }
  5482. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5483. // price := int64(json["price"].(float64))
  5484. // formatInt_price := strconv.FormatInt(price, 10)
  5485. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5486. // additionalCharge.Price = float_price
  5487. //}
  5488. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5489. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5490. additionalCharge.Price = price
  5491. }
  5492. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5493. count, _ := json["count"].(string)
  5494. counts, _ := strconv.ParseInt(count, 10, 64)
  5495. additionalCharge.Count = counts
  5496. }
  5497. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5498. item_name, _ := json["item_name"].(string)
  5499. additionalCharge.ItemName = item_name
  5500. }
  5501. return 0
  5502. }
  5503. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5504. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5505. utils.ErrorLog("drug_name")
  5506. return enums.ErrorCodeParamWrong
  5507. }
  5508. adviceName, _ := json["drug_name"].(string)
  5509. if len(adviceName) == 0 {
  5510. utils.ErrorLog("len(advice_name) == 0")
  5511. return enums.ErrorCodeParamWrong
  5512. }
  5513. advice.AdviceName = adviceName
  5514. adviceDesc, _ := json["advice_desc"].(string)
  5515. advice.AdviceDesc = adviceDesc
  5516. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5517. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5518. advice.DrugSpec = drugSpec
  5519. }
  5520. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5521. remark, _ := json["remark"].(string)
  5522. advice.Remark = remark
  5523. }
  5524. if json["id"] == nil {
  5525. advice.DrugId = 0
  5526. } else {
  5527. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5528. drug_id := int64(json["id"].(float64))
  5529. advice.DrugId = drug_id
  5530. }
  5531. }
  5532. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5533. groupno := int64(json["groupno"].(float64))
  5534. advice.Groupno = groupno
  5535. }
  5536. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5537. drugSpecUnit, _ := json["min_unit"].(string)
  5538. advice.DrugSpecUnit = drugSpecUnit
  5539. }
  5540. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5541. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5542. advice.SingleDose = singleDose
  5543. }
  5544. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5545. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5546. advice.SingleDoseUnit = singleDoseUnit
  5547. }
  5548. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5549. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5550. advice.PrescribingNumber = prescribingNumber
  5551. }
  5552. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5553. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5554. advice.PrescribingNumberUnit = prescribingNumberUnit
  5555. }
  5556. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5557. deliveryWay, _ := json["delivery_way"].(string)
  5558. advice.DeliveryWay = deliveryWay
  5559. }
  5560. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5561. executionFrequency, _ := json["execution_frequency"].(string)
  5562. advice.ExecutionFrequency = executionFrequency
  5563. }
  5564. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5565. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5566. advice.Price = price
  5567. }
  5568. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5569. med_list_codg, _ := json["medical_insurance_number"].(string)
  5570. advice.MedListCodg = med_list_codg
  5571. }
  5572. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5573. day := int64(json["day"].(float64))
  5574. advice.Day = day
  5575. }
  5576. advice.FrequencyType = 1
  5577. return 0
  5578. }
  5579. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5580. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5581. types := int64(json["type"].(float64))
  5582. project.Type = types
  5583. }
  5584. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5585. project_id := int64(json["project_id"].(float64))
  5586. project.ProjectId = project_id
  5587. }
  5588. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5589. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5590. project.Price = price
  5591. }
  5592. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5593. total, _ := json["total"].(string)
  5594. //totals, _ := strconv.ParseInt(total, 10, 64)
  5595. project.Count = total
  5596. }
  5597. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5598. medical_code, _ := json["medical_code"].(string)
  5599. project.MedListCodg = medical_code
  5600. }
  5601. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5602. single_dose, _ := json["single_dose"].(string)
  5603. project.SingleDose = single_dose
  5604. }
  5605. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5606. delivery_way, _ := json["delivery_way"].(string)
  5607. project.DeliveryWay = delivery_way
  5608. }
  5609. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5610. execution_frequency, _ := json["execution_frequency"].(string)
  5611. project.ExecutionFrequency = execution_frequency
  5612. }
  5613. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5614. remark, _ := json["remark"].(string)
  5615. project.Remark = remark
  5616. }
  5617. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5618. day, _ := json["number_days"].(string)
  5619. project.Day = day
  5620. }
  5621. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5622. unit, _ := json["unit"].(string)
  5623. project.Unit = unit
  5624. }
  5625. project.FrequencyType = 1
  5626. return 0
  5627. }
  5628. func (c *HisApiController) GetHisOrderList() {
  5629. page, _ := c.GetInt64("page", -1)
  5630. limit, _ := c.GetInt64("limit", -1)
  5631. start_time := c.GetString("start_time")
  5632. end_time := c.GetString("end_time")
  5633. types, _ := c.GetInt64("type", 0)
  5634. keywords := c.GetString("keywords")
  5635. p_type, _ := c.GetInt64("p_type", 0)
  5636. sort_type, _ := c.GetInt64("sort_type", 0)
  5637. charge_type, _ := c.GetInt64("charge_type", 0)
  5638. sch_type, _ := c.GetInt64("sch_type", 0)
  5639. zone_type, _ := c.GetInt64("zone_type", 0)
  5640. med_type, _ := c.GetInt64("med_type", 0)
  5641. timeLayout := "2006-01-02"
  5642. loc, _ := time.LoadLocation("Local")
  5643. var startTime int64
  5644. if len(start_time) > 0 {
  5645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5646. if err != nil {
  5647. //fmt.Println(err)
  5648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5649. return
  5650. }
  5651. startTime = theTime.Unix()
  5652. }
  5653. var endTime int64
  5654. if len(end_time) > 0 {
  5655. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5656. if err != nil {
  5657. utils.ErrorLog(err.Error())
  5658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5659. return
  5660. }
  5661. endTime = theTime.Unix()
  5662. }
  5663. adminUser := c.GetAdminUserInfo()
  5664. org_id := adminUser.CurrentOrgId
  5665. 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)
  5666. for _, item := range order {
  5667. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5668. item.DoctorName = info.Doctor
  5669. item.DepartmentName = info.XtHisDepartment.Name
  5670. }
  5671. if err == nil {
  5672. c.ServeSuccessJSON(map[string]interface{}{
  5673. "order": order,
  5674. "total": total,
  5675. })
  5676. } else {
  5677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5678. return
  5679. }
  5680. }
  5681. func (c *HisApiController) GetHisOrder() {
  5682. patient_id, _ := c.GetInt64("patient_id", 0)
  5683. number := c.GetString("number")
  5684. adminInfo := c.GetAdminUserInfo()
  5685. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5686. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5687. if err == nil {
  5688. c.ServeSuccessJSON(map[string]interface{}{
  5689. "order": order,
  5690. "prescription": prescriptions,
  5691. })
  5692. } else {
  5693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5694. return
  5695. }
  5696. }
  5697. func (c *HisApiController) GetHisPrescriptionList() {
  5698. record_date := c.GetString("record_date")
  5699. keywords := c.GetString("keywords")
  5700. page, _ := c.GetInt64("page")
  5701. limit, _ := c.GetInt64("limit")
  5702. sch_type, _ := c.GetInt64("sch_type")
  5703. timeLayout := "2006-01-02"
  5704. loc, _ := time.LoadLocation("Local")
  5705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5706. if err != nil {
  5707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5708. return
  5709. }
  5710. recordDateTime := theTime.Unix()
  5711. adminInfo := c.GetAdminUserInfo()
  5712. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5713. //adminInfo := c.GetAdminUserInfo()
  5714. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5715. //fmt.Println(prescriptionOrder)
  5716. if err == nil {
  5717. c.ServeSuccessJSON(map[string]interface{}{
  5718. "order": prescriptionOrder,
  5719. "total": total,
  5720. })
  5721. } else {
  5722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5723. return
  5724. }
  5725. }
  5726. func (c *HisApiController) GetHisPrescriptionInfo() {
  5727. id, _ := c.GetInt64("id")
  5728. adminInfo := c.GetAdminUserInfo()
  5729. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5730. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5731. if err == nil {
  5732. c.ServeSuccessJSON(map[string]interface{}{
  5733. "order": prescriptionOrder,
  5734. "prescription": prescription,
  5735. })
  5736. } else {
  5737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5738. return
  5739. }
  5740. }
  5741. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5742. adminUser := c.GetAdminUserInfo()
  5743. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5744. c.ServeSuccessJSON(map[string]interface{}{
  5745. "config": config,
  5746. })
  5747. }
  5748. type ResultTwo struct {
  5749. ErrMsg interface{} `json:"err_msg"`
  5750. InfRefmsgid string `json:"inf_refmsgid"`
  5751. Infcode int64 `json:"infcode"`
  5752. Output struct {
  5753. Baseinfo struct {
  5754. Age float64 `json:"age"`
  5755. Brdy string `json:"brdy"`
  5756. Certno string `json:"certno"`
  5757. Gend string `json:"gend"`
  5758. Naty string `json:"naty"`
  5759. PsnCertType string `json:"psn_cert_type"`
  5760. PsnName string `json:"psn_name"`
  5761. PsnNo string `json:"psn_no"`
  5762. } `json:"baseinfo"`
  5763. Idetinfo []interface{} `json:"idetinfo"`
  5764. Iinfo []struct {
  5765. Balc float64 `json:"balc"`
  5766. CvlservFlag string `json:"cvlserv_flag"`
  5767. EmpName string `json:"emp_name"`
  5768. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5769. Insutype string `json:"insutype"`
  5770. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5771. PausInsuDate interface{} `json:"paus_insu_date"`
  5772. PsnInsuDate string `json:"psn_insu_date"`
  5773. PsnInsuStas string `json:"psn_insu_stas"`
  5774. PsnType string `json:"psn_type"`
  5775. } `json:"insuinfo"`
  5776. } `json:"output"`
  5777. RefmsgTime string `json:"refmsg_time"`
  5778. RespondTime string `json:"respond_time"`
  5779. Signtype interface{} `json:"signtype"`
  5780. WarnInfo interface{} `json:"warn_info"`
  5781. }
  5782. type ResultThree struct {
  5783. Cainfo interface{} `json:"cainfo"`
  5784. ErrMsg interface{} `json:"err_msg"`
  5785. InfRefmsgid string `json:"inf_refmsgid"`
  5786. Infcode int64 `json:"infcode"`
  5787. Output struct {
  5788. Data struct {
  5789. IptOtpNo string `json:"ipt_otp_no"`
  5790. MdtrtID string `json:"mdtrt_id"`
  5791. PsnNo string `json:"psn_no"`
  5792. } `json:"data"`
  5793. } `json:"output"`
  5794. RefmsgTime string `json:"refmsg_time"`
  5795. RespondTime string `json:"respond_time"`
  5796. Signtype interface{} `json:"signtype"`
  5797. WarnMsg interface{} `json:"warn_msg"`
  5798. }
  5799. type ResultFour struct {
  5800. Cainfo string `json:"cainfo"`
  5801. ErrMsg string `json:"err_msg"`
  5802. InfRefmsgid string `json:"inf_refmsgid"`
  5803. Infcode int64 `json:"infcode"`
  5804. Output struct {
  5805. Result []struct {
  5806. BasMednFlag string `json:"bas_medn_flag"`
  5807. ChldMedcFlag string `json:"chld_medc_flag"`
  5808. ChrgitmLv string `json:"chrgitm_lv"`
  5809. Cnt float64 `json:"cnt"`
  5810. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5811. DrtReimFlag string `json:"drt_reim_flag"`
  5812. FeedetlSn string `json:"feedetl_sn"`
  5813. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5814. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5815. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5816. ListSpItemFlag string `json:"list_sp_item_flag"`
  5817. LmtUsedFlag string `json:"lmt_used_flag"`
  5818. MedChrgitmType string `json:"med_chrgitm_type"`
  5819. Memo string `json:"memo"`
  5820. OverlmtAmt float64 `json:"overlmt_amt"`
  5821. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5822. Pric float64 `json:"pric"`
  5823. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5824. SelfpayProp float64 `json:"selfpay_prop"`
  5825. } `json:"result"`
  5826. } `json:"output"`
  5827. RefmsgTime string `json:"refmsg_time"`
  5828. RespondTime string `json:"respond_time"`
  5829. Signtype string `json:"signtype"`
  5830. WarnMsg string `json:"warn_msg"`
  5831. }
  5832. type ResultFive struct {
  5833. Insutype string `json:"insutype"`
  5834. }
  5835. type ResultSix struct {
  5836. Cainfo interface{} `json:"cainfo"`
  5837. ErrMsg interface{} `json:"err_msg"`
  5838. InfRefmsgid string `json:"inf_refmsgid"`
  5839. Infcode int64 `json:"infcode"`
  5840. Output struct {
  5841. } `json:"output"`
  5842. RefmsgTime string `json:"refmsg_time"`
  5843. RespondTime string `json:"respond_time"`
  5844. Signtype interface{} `json:"signtype"`
  5845. WarnMsg interface{} `json:"warn_msg"`
  5846. }
  5847. type ResultSeven struct {
  5848. Cainfo string `json:"cainfo"`
  5849. ErrMsg string `json:"err_msg"`
  5850. InfRefmsgid string `json:"inf_refmsgid"`
  5851. Infcode int64 `json:"infcode"`
  5852. Output struct {
  5853. Setldetail []interface{} `json:"setldetail"`
  5854. Setlinfo struct {
  5855. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5856. AcctPay float64 `json:"acct_pay"`
  5857. ActPayDedc float64 `json:"act_pay_dedc"`
  5858. Age float64 `json:"age"`
  5859. Balc float64 `json:"balc"`
  5860. Brdy string `json:"brdy"`
  5861. Certno string `json:"certno"`
  5862. ClrOptins string `json:"clr_optins"`
  5863. ClrType string `json:"clr_type"`
  5864. ClrWay string `json:"clr_way"`
  5865. CvlservFlag string `json:"cvlserv_flag"`
  5866. CvlservPay float64 `json:"cvlserv_pay"`
  5867. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5868. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5869. Gend string `json:"gend"`
  5870. HifesPay float64 `json:"hifes_pay"`
  5871. HifmiPay float64 `json:"hifmi_pay"`
  5872. HifobPay float64 `json:"hifob_pay"`
  5873. HifpPay float64 `json:"hifp_pay"`
  5874. HospPartAmt float64 `json:"hosp_part_amt"`
  5875. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5876. Insutype string `json:"insutype"`
  5877. MafPay float64 `json:"maf_pay"`
  5878. MdtrtCertType string `json:"mdtrt_cert_type"`
  5879. MdtrtID string `json:"mdtrt_id"`
  5880. MedType string `json:"med_type"`
  5881. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5882. MedinsSetlID string `json:"medins_setl_id"`
  5883. Naty string `json:"naty"`
  5884. OthPay float64 `json:"oth_pay"`
  5885. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5886. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5887. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5888. PsnCashPay float64 `json:"psn_cash_pay"`
  5889. PsnCertType string `json:"psn_cert_type"`
  5890. PsnName string `json:"psn_name"`
  5891. PsnNo string `json:"psn_no"`
  5892. PsnPartAmt float64 `json:"psn_part_amt"`
  5893. PsnType string `json:"psn_type"`
  5894. SetlID string `json:"setl_id"`
  5895. SetlTime string `json:"setl_time"`
  5896. } `json:"setlinfo"`
  5897. } `json:"output"`
  5898. RefmsgTime string `json:"refmsg_time"`
  5899. RespondTime string `json:"respond_time"`
  5900. Signtype interface{} `json:"signtype"`
  5901. WarnMsg interface{} `json:"warn_msg"`
  5902. }
  5903. type ResultEight struct {
  5904. Cainfo string `json:"cainfo"`
  5905. ErrMsg string `json:"err_msg"`
  5906. InfRefmsgid string `json:"inf_refmsgid"`
  5907. Infcode int64 `json:"infcode"`
  5908. Output struct {
  5909. Stmtinfo struct {
  5910. SetlOptins string `json:"setl_optins"`
  5911. StmtRslt string `json:"stmt_rslt"`
  5912. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5913. } `json:"stmtinfo"`
  5914. } `json:"output"`
  5915. RefmsgTime string `json:"refmsg_time"`
  5916. RespondTime string `json:"respond_time"`
  5917. Signtype interface{} `json:"signtype"`
  5918. WarnMsg interface{} `json:"warn_msg"`
  5919. }
  5920. type ResultNine struct {
  5921. Cainfo string `json:"cainfo"`
  5922. ErrMsg string `json:"err_msg"`
  5923. InfRefmsgid string `json:"inf_refmsgid"`
  5924. Infcode int64 `json:"infcode"`
  5925. Output struct {
  5926. FileQuryNo string `json:"file_qury_no"`
  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 ResultTen 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. DldEndtime string `json:"dld_endtime"`
  5940. FileQuryNo string `json:"file_qury_no"`
  5941. Filename string `json:"filename"`
  5942. } `json:"output"`
  5943. RefmsgTime string `json:"refmsg_time"`
  5944. RespondTime string `json:"respond_time"`
  5945. Signtype interface{} `json:"signtype"`
  5946. WarnMsg interface{} `json:"warn_msg"`
  5947. }
  5948. type ResultEleven struct {
  5949. Cainfo string `json:"cainfo"`
  5950. ErrMsg string `json:"err_msg"`
  5951. InfRefmsgid string `json:"inf_refmsgid"`
  5952. Infcode int64 `json:"infcode"`
  5953. Output struct {
  5954. Setlinfo struct {
  5955. FixmedinsName string `json:"fixmedins_name"`
  5956. FixmedinsCode string `json:"fixmedins_code"`
  5957. PsnNo string `json:"psn_no"`
  5958. PsnName string `json:"psn_name"`
  5959. HifobPay float64 `json:"hifob_pay"`
  5960. Gend string `json:"gend"`
  5961. Brdy string `json:"brdy"`
  5962. PsnCertType string `json:"psn_cert_type"`
  5963. PsnType string `json:"psn_type"`
  5964. EmpName string `json:"emp_name"`
  5965. Certno string `json:"certno"`
  5966. Insutype string `json:"insutype"`
  5967. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5968. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5969. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5970. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5971. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5972. ActPayDedc float64 `json:"act_pay_dedc"`
  5973. HifpPay float64 `json:"hifp_pay"`
  5974. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5975. CvlservPay float64 `json:"cvlserv_pay"`
  5976. HifesPay float64 `json:"hifes_pay"`
  5977. HifmiPay float64 `json:"hifmi_pay"`
  5978. MafPay float64 `json:"maf_pay"`
  5979. OthPay float64 `json:"oth_pay"`
  5980. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5981. PsnPay float64 `json:"psn_pay"`
  5982. AcctPay float64 `json:"acct_pay"`
  5983. CashPayamt float64 `json:"cash_payamt"`
  5984. Balc float64 `json:"balc"`
  5985. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5986. MedinsSetlId string `json:"medins_setl_id"`
  5987. RefdSetlFlag string `json:"refd_setl_flag"`
  5988. SetlTime string `json:"setl_time"`
  5989. MedType string `json:"med_type"`
  5990. } `json:"setlinfo"`
  5991. } `json:"output"`
  5992. RefmsgTime string `json:"refmsg_time"`
  5993. RespondTime string `json:"respond_time"`
  5994. Signtype interface{} `json:"signtype"`
  5995. WarnMsg interface{} `json:"warn_msg"`
  5996. }
  5997. type Custom struct {
  5998. DetItemFeeSumamt string
  5999. Cut string
  6000. FeedetlSn string
  6001. Price string
  6002. MedListCodg string
  6003. Type int64
  6004. AdviceId int64
  6005. ProjectId int64
  6006. ItemId int64
  6007. }
  6008. // 获取个人信息----挂号-----上传就诊信息
  6009. func (c *HisApiController) GetRegisterInfo() {
  6010. id, _ := c.GetInt64("id")
  6011. record_time := c.GetString("record_time")
  6012. settlementValue, _ := c.GetInt64("settlement_value")
  6013. medical_insurance_card := c.GetString("medical_insurance_card")
  6014. name := c.GetString("name")
  6015. id_card_type, _ := c.GetInt64("id_card_type")
  6016. certificates, _ := c.GetInt64("certificates")
  6017. medical_care, _ := c.GetInt64("medical_care")
  6018. birthday := c.GetString("birthday")
  6019. age, _ := c.GetInt64("age")
  6020. id_card := c.GetString("id_card")
  6021. register_type, _ := c.GetInt64("register")
  6022. doctor, _ := c.GetInt64("doctor")
  6023. department, _ := c.GetInt64("department")
  6024. gender, _ := c.GetInt64("sex")
  6025. phone := c.GetString("phone")
  6026. registration_fee, _ := c.GetFloat("registration_fee")
  6027. medical_expenses, _ := c.GetFloat("medical_expenses")
  6028. social_type, _ := c.GetInt64("social_type")
  6029. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6030. diagnosis_ids := c.GetString("diagnosis")
  6031. sick_type, _ := c.GetInt64("sick_type")
  6032. reg_type := c.GetString("p_type")
  6033. timeLayout := "2006-01-02"
  6034. loc, _ := time.LoadLocation("Local")
  6035. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6036. birthUnix := birthdays.Unix()
  6037. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6038. if err != nil {
  6039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6040. return
  6041. }
  6042. recordDateTime := theTime.Unix()
  6043. adminInfo := c.GetAdminUserInfo()
  6044. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6045. if tempPatient.ID == 0 {
  6046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6047. return
  6048. }
  6049. var patient service.Patients
  6050. if id == 0 {
  6051. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6052. } else {
  6053. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6054. }
  6055. if patient.ID == 0 {
  6056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6057. return
  6058. }
  6059. if len(patient.IdCardNo) == 0 {
  6060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6061. return
  6062. }
  6063. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6064. if len(his) >= 1 {
  6065. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6066. if len(his) >= 1 && order.ID == 0 {
  6067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6068. return
  6069. }
  6070. }
  6071. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6072. fmt.Println(timeStr)
  6073. timeArr := strings.Split(timeStr, " ")
  6074. fmt.Println(timeArr)
  6075. timeArrTwo := strings.Split(timeArr[0], "-")
  6076. timeArrThree := strings.Split(timeArr[1], ":")
  6077. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6078. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6079. if len(lists) == 0 {
  6080. var hisPatient models.XtHisPatient
  6081. hisPatient = models.XtHisPatient{
  6082. Name: name,
  6083. Age: age,
  6084. Gender: gender,
  6085. Birthday: birthUnix,
  6086. Phone: phone,
  6087. MedicalTreatmentType: medical_care,
  6088. IdType: certificates,
  6089. IdCardNo: id_card,
  6090. BalanceAccountsType: settlementValue,
  6091. SocialType: social_type,
  6092. MedicalInsuranceNumber: medical_insurance_card,
  6093. RegisterType: register_type,
  6094. RegisterCost: registration_fee,
  6095. TreatmentCost: medical_expenses,
  6096. AdminUserId: adminInfo.AdminUser.Id,
  6097. UserOrgId: adminInfo.CurrentOrgId,
  6098. Status: 1,
  6099. RecordDate: recordDateTime,
  6100. IsReturn: 1,
  6101. PatientId: patient.ID,
  6102. Ctime: time.Now().Unix(),
  6103. Mtime: time.Now().Unix(),
  6104. Number: str,
  6105. IdCardType: id_card_type,
  6106. Departments: department,
  6107. Doctor: doctor,
  6108. PType: reg_type,
  6109. Diagnosis: diagnosis_ids,
  6110. SickType: sick_type,
  6111. }
  6112. service.CreateHisPatient(&hisPatient)
  6113. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6114. c.ServeSuccessJSON(map[string]interface{}{
  6115. "his_info": hisPatient,
  6116. })
  6117. } else {
  6118. //chrgBchno := rand.Intn(1000000) + 10000
  6119. var hisPatient models.XtHisPatient
  6120. hisPatient = models.XtHisPatient{
  6121. Name: name,
  6122. Age: age,
  6123. Gender: gender,
  6124. Birthday: birthUnix,
  6125. Phone: phone,
  6126. MedicalTreatmentType: medical_care,
  6127. IdType: certificates,
  6128. IdCardNo: id_card,
  6129. BalanceAccountsType: settlementValue,
  6130. SocialType: social_type,
  6131. MedicalInsuranceNumber: medical_insurance_card,
  6132. RegisterType: register_type,
  6133. RegisterCost: registration_fee,
  6134. TreatmentCost: medical_expenses,
  6135. AdminUserId: adminInfo.AdminUser.Id,
  6136. UserOrgId: adminInfo.CurrentOrgId,
  6137. Status: 1,
  6138. RecordDate: recordDateTime,
  6139. IsReturn: 1,
  6140. PatientId: patient.ID,
  6141. Ctime: time.Now().Unix(),
  6142. Mtime: time.Now().Unix(),
  6143. Number: str,
  6144. IdCardType: id_card_type,
  6145. Departments: department,
  6146. Doctor: doctor,
  6147. PType: reg_type,
  6148. Diagnosis: diagnosis_ids,
  6149. SickType: sick_type,
  6150. }
  6151. service.CreateHisPatient(&hisPatient)
  6152. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6153. c.ServeSuccessJSON(map[string]interface{}{
  6154. "his_info": hisPatient,
  6155. })
  6156. }
  6157. }
  6158. // 上传明细----结算
  6159. func (c *HisApiController) GetUploadInfo() {
  6160. id, _ := c.GetInt64("id")
  6161. record_time := c.GetString("record_time")
  6162. his_patient_id, _ := c.GetInt64("his_patient_id")
  6163. oth_desc := c.GetString("oth_desc")
  6164. pay_way, _ := c.GetInt64("pay_way")
  6165. pay_ways := c.GetString("pay_ways")
  6166. pay_price, _ := c.GetFloat("pay_price")
  6167. pay_card_no := c.GetString("pay_card_no")
  6168. discount_price, _ := c.GetFloat("discount_price")
  6169. preferential_price, _ := c.GetFloat("preferential_price")
  6170. reality_price, _ := c.GetFloat("reality_price")
  6171. found_price, _ := c.GetFloat("found_price")
  6172. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6173. private_price, _ := c.GetFloat("private_price")
  6174. timeLayout := "2006-01-02"
  6175. loc, _ := time.LoadLocation("Local")
  6176. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6177. fapiao_code := c.GetString("fapiao_code")
  6178. fapiao_number := c.GetString("fapiao_number")
  6179. diagnosis_id := c.GetString("diagnosis")
  6180. sick_type, _ := c.GetInt64("sick_type")
  6181. reg_type, _ := c.GetInt64("p_type")
  6182. order_id, _ := c.GetInt64("order_id")
  6183. cash_pay := c.GetString("cash_pay")
  6184. wechat_pay := c.GetString("wechat_pay")
  6185. ali_pay := c.GetString("ali_pay")
  6186. jifen_pay := c.GetString("jifen_pay")
  6187. band_card_pay := c.GetString("band_card_pay")
  6188. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6189. tmp_decimal := c.GetString("tmp_decimal")
  6190. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6191. var decimal float64 //本次使用的押金
  6192. var errmsg error
  6193. tx := service.XTWriteDB().Begin() //开了事务
  6194. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6195. defer func() {
  6196. if errmsg != nil {
  6197. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6198. tx.Rollback()
  6199. } else {
  6200. tx.Commit()
  6201. }
  6202. }()
  6203. fmt.Println("dec_way", dec_way)
  6204. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6205. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6206. return
  6207. }
  6208. if len(tmp_decimal) > 0 {
  6209. if tmp_decimal[0] == 45 {
  6210. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6211. return
  6212. }
  6213. }
  6214. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6215. fmt.Println(errs)
  6216. decimal = tt
  6217. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6218. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6219. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6220. if err != nil {
  6221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6222. return
  6223. }
  6224. recordDateTime := theTime.Unix()
  6225. adminUser := c.GetAdminUserInfo()
  6226. var prescriptions []*models.HisPrescription
  6227. var prescriptionsOne []*models.HisPrescription
  6228. var start_time int64
  6229. var end_time int64
  6230. ids_str := c.GetString("ids")
  6231. ids_arr := strings.Split(ids_str, ",")
  6232. if tempOrder.ID == 0 {
  6233. if settle_accounts_type == 1 { //日结
  6234. fmt.Println(reg_type)
  6235. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6236. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6237. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6238. } else {
  6239. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6240. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6241. }
  6242. } else { //月结
  6243. start_time_str := c.GetString("start_time")
  6244. end_time_str := c.GetString("end_time")
  6245. timeLayout := "2006-01-02"
  6246. loc, _ := time.LoadLocation("Local")
  6247. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6248. if err != nil {
  6249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6250. return
  6251. }
  6252. recordStartTime := theStartTime.Unix()
  6253. start_time = recordStartTime
  6254. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6255. if err != nil {
  6256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6257. return
  6258. }
  6259. recordEndTime := theEndTime.Unix()
  6260. end_time = recordEndTime
  6261. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6262. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6263. }
  6264. var goods []*models.DialysisBeforePrepareGoods
  6265. var newGoods []*models.NewDialysisBeforePrepareGoods
  6266. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6267. var infos []*models.HisDoctorAdviceInfo
  6268. var infoList []*models.HisDoctorAdviceInfo
  6269. var hisAdvice []*models.HisDoctorAdviceInfo
  6270. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6271. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6272. //判断库存不足
  6273. //结算出库开关
  6274. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6275. if settConfig.IsOpen == 1 {
  6276. //判断库存的地方
  6277. for _, info := range prescriptions {
  6278. if info.Type == 1 {
  6279. infos = append(infos, info.HisDoctorAdviceInfo...)
  6280. }
  6281. if info.Type == 2 {
  6282. for _, sumItem := range info.HisPrescriptionProject {
  6283. if sumItem.Type == 3 {
  6284. var good models.DialysisBeforePrepareGoods
  6285. var newGood models.NewDialysisBeforePrepareGoods
  6286. good.GoodId = sumItem.GoodInfo.ID
  6287. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6288. count, _ := strconv.Atoi(sumItem.Count)
  6289. good.Count = int64(count)
  6290. good.StorehouseId = houseConfig.StorehouseOutInfo
  6291. good.ProjectId = sumItem.ID
  6292. goods = append(goods, &good)
  6293. newGood.GoodId = sumItem.GoodInfo.ID
  6294. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6295. count2, _ := strconv.Atoi(sumItem.Count)
  6296. newGood.Count = int64(count2)
  6297. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6298. newGood.ProjectId = sumItem.ID
  6299. newGoods = append(newGoods, &newGood)
  6300. }
  6301. }
  6302. }
  6303. }
  6304. for _, info := range prescriptionsOne {
  6305. if info.Type == 1 {
  6306. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6307. }
  6308. if info.Type == 2 {
  6309. for _, sumItem := range info.HisPrescriptionProject {
  6310. if sumItem.Type == 3 {
  6311. var newGood models.NewDialysisBeforePrepareGoods
  6312. newGood.GoodId = sumItem.GoodInfo.ID
  6313. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6314. count2, _ := strconv.Atoi(sumItem.Count)
  6315. newGood.Count = int64(count2)
  6316. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6317. newGood.ProjectId = sumItem.ID
  6318. newGoodOne = append(newGoodOne, &newGood)
  6319. }
  6320. }
  6321. }
  6322. }
  6323. //判断
  6324. for _, itemOne := range infos {
  6325. for _, itemTwo := range hisAdvice {
  6326. if itemOne.DrugId == itemTwo.DrugId {
  6327. itemTwo.Child = append(itemTwo.Child, itemOne)
  6328. }
  6329. }
  6330. }
  6331. for _, itemTwo := range hisAdvice {
  6332. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6333. var sum_out_count int64
  6334. for _, itemThree := range itemTwo.Child {
  6335. var prescribing_number int64
  6336. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6337. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6338. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6339. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6340. }
  6341. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6342. prescribing_number = parseIntPrescribingNumber
  6343. }
  6344. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6345. prescribing_number = parseIntPrescribingNumber
  6346. }
  6347. sum_out_count += prescribing_number
  6348. }
  6349. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6350. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6351. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6352. if sum_out_count > drugStockOut.FlushCount {
  6353. c.ServeSuccessJSON(map[string]interface{}{
  6354. "msg": "2",
  6355. "drug": medical,
  6356. })
  6357. return
  6358. }
  6359. }
  6360. fmt.Println("newGoods99999988882os", newGoods)
  6361. for _, itemOne := range newGoods {
  6362. for _, item := range newGoodOne {
  6363. if itemOne.GoodId == item.GoodId {
  6364. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6365. }
  6366. }
  6367. }
  6368. for _, item := range newGoodOne {
  6369. var sum_out_count_one int64
  6370. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6371. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6372. sum_out_count_one += itemOne.Count
  6373. }
  6374. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6375. fmt.Println("sum_out_count_one", sum_out_count_one)
  6376. fmt.Println("list.FlushCount", list.FlushCount)
  6377. if sum_out_count_one > list.FlushCount {
  6378. c.ServeSuccessJSON(map[string]interface{}{
  6379. "msg": "3",
  6380. "good": good,
  6381. })
  6382. return
  6383. }
  6384. }
  6385. }
  6386. timestamp := time.Now().Unix()
  6387. tempTime := time.Unix(timestamp, 0)
  6388. timeFormat := tempTime.Format("20060102150405")
  6389. chrgBchno := rand.Intn(100000) + 10000
  6390. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6391. strconv.FormatInt(his.PatientId, 10)
  6392. var ids []int64
  6393. for _, item := range prescriptions {
  6394. ids = append(ids, item.ID)
  6395. }
  6396. var total float64
  6397. for _, item := range prescriptions {
  6398. fmt.Println(item)
  6399. if item.Type == 1 { //药品
  6400. for _, subItem := range item.HisDoctorAdviceInfo {
  6401. total = total + (subItem.Price * subItem.PrescribingNumber)
  6402. }
  6403. }
  6404. if item.Type == 2 { //项目
  6405. for _, subItem := range item.HisPrescriptionProject {
  6406. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6407. total = total + (subItem.Price * cnt)
  6408. }
  6409. }
  6410. for _, subItem := range item.HisAdditionalCharge {
  6411. total = total + (subItem.Price * float64(subItem.Count))
  6412. }
  6413. }
  6414. if reg_type == 1111 || reg_type == 1112 {
  6415. reg_type = 11
  6416. }
  6417. tm := time.Unix(time.Now().Unix(), 0)
  6418. allTotal := fmt.Sprintf("%.4f", total)
  6419. totals, _ := strconv.ParseFloat(allTotal, 64)
  6420. order := &models.HisOrder{
  6421. UserOrgId: adminUser.CurrentOrgId,
  6422. HisPatientId: his.ID,
  6423. PatientId: id,
  6424. SettleAccountsDate: recordDateTime,
  6425. Ctime: time.Now().Unix(),
  6426. Mtime: time.Now().Unix(),
  6427. Status: 1,
  6428. OrderStatus: 2,
  6429. MdtrtId: his.Number,
  6430. Number: chrg_bchno,
  6431. MedfeeSumamt: totals,
  6432. PayWay: pay_way,
  6433. PayWays: pay_ways,
  6434. PayPrice: pay_price,
  6435. MedType: strconv.Itoa(int(reg_type)),
  6436. PayCardNo: pay_card_no,
  6437. DiscountPrice: discount_price,
  6438. PreferentialPrice: preferential_price,
  6439. RealityPrice: reality_price,
  6440. FoundPrice: found_price,
  6441. MedicalInsurancePrice: medical_insurance_price,
  6442. PrivatePrice: private_price,
  6443. SettleEndTime: end_time,
  6444. SettleStartTime: start_time,
  6445. PsnPartAmt: totals,
  6446. PsnCashPay: totals,
  6447. SettleType: settle_accounts_type,
  6448. FaPiaoCode: fapiao_code,
  6449. FaPiaoNumber: fapiao_number,
  6450. Diagnosis: diagnosis_id,
  6451. PType: 2,
  6452. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6453. Decimal: decimal,
  6454. OthDesc: oth_desc,
  6455. CashPay: cash_pay,
  6456. WechatPay: wechat_pay,
  6457. AliPay: ali_pay,
  6458. JifenPay: jifen_pay,
  6459. BandCardPay: band_card_pay,
  6460. }
  6461. err = service.CreateOrderTX(order, tx)
  6462. if err != nil {
  6463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6464. return
  6465. }
  6466. var customs []*Custom
  6467. for _, item := range prescriptions {
  6468. if item.Type == 1 { //药品a
  6469. for _, subItem := range item.HisDoctorAdviceInfo {
  6470. cus := &Custom{
  6471. AdviceId: subItem.ID,
  6472. ProjectId: 0,
  6473. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6474. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6475. FeedetlSn: subItem.FeedetlSn,
  6476. Price: fmt.Sprintf("%.4f", subItem.Price),
  6477. MedListCodg: subItem.MedListCodg,
  6478. Type: 1,
  6479. }
  6480. customs = append(customs, cus)
  6481. }
  6482. }
  6483. if item.Type == 2 { //项目
  6484. for _, subItem := range item.HisPrescriptionProject {
  6485. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6486. cus := &Custom{
  6487. AdviceId: 0,
  6488. ProjectId: subItem.ID,
  6489. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6490. Cut: fmt.Sprintf("%.4f", cnt),
  6491. FeedetlSn: subItem.FeedetlSn,
  6492. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6493. MedListCodg: subItem.MedListCodg,
  6494. Type: 2,
  6495. }
  6496. customs = append(customs, cus)
  6497. }
  6498. }
  6499. for _, item := range item.HisAdditionalCharge {
  6500. cus := &Custom{
  6501. ItemId: item.ID,
  6502. AdviceId: 0,
  6503. ProjectId: 0,
  6504. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6505. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6506. FeedetlSn: item.FeedetlSn,
  6507. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6508. MedListCodg: item.XtHisAddtionConfig.Code,
  6509. Type: 3,
  6510. }
  6511. customs = append(customs, cus)
  6512. }
  6513. }
  6514. for _, item := range customs {
  6515. var advice_id int64 = 0
  6516. var project_id int64 = 0
  6517. var item_id int64 = 0
  6518. var types int64 = 0
  6519. if item.Type == 1 {
  6520. advice_id = item.AdviceId
  6521. project_id = 0
  6522. item_id = 0
  6523. } else if item.Type == 2 {
  6524. advice_id = 0
  6525. item_id = 0
  6526. project_id = item.ProjectId
  6527. } else if item.Type == 3 {
  6528. advice_id = 0
  6529. item_id = item.ItemId
  6530. project_id = 0
  6531. }
  6532. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6533. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6534. pric, _ := strconv.ParseFloat(item.Price, 32)
  6535. info := &models.HisOrderInfo{
  6536. OrderNumber: order.Number,
  6537. UploadDate: time.Now().Unix(),
  6538. AdviceId: advice_id,
  6539. DetItemFeeSumamt: detItemFeeSumamt,
  6540. Cnt: cut,
  6541. Pric: pric,
  6542. PatientId: id,
  6543. Status: 1,
  6544. Mtime: time.Now().Unix(),
  6545. Ctime: time.Now().Unix(),
  6546. UserOrgId: adminUser.CurrentOrgId,
  6547. HisPatientId: his.ID,
  6548. OrderId: order.ID,
  6549. ProjectId: project_id,
  6550. Type: types,
  6551. ItemId: item_id,
  6552. }
  6553. service.CreateOrderInfoTX(info, tx)
  6554. }
  6555. his.Diagnosis = diagnosis_id
  6556. his.SickType = sick_type
  6557. his.RegisterType = reg_type
  6558. his.MedicalTreatmentType = reg_type
  6559. service.UpdataHisPateintTX(&his, tx)
  6560. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6561. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6562. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6563. //判断是否使用了押金
  6564. if dec_way == "true" {
  6565. tmpstring := strconv.FormatInt(order.ID, 10)
  6566. //扣押金
  6567. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6568. order.Decimal = decimal
  6569. service.UpDateOrderTwo(order, tx)
  6570. if errmsg != nil {
  6571. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6572. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6573. return
  6574. }
  6575. }
  6576. if err == nil {
  6577. for _, info := range prescriptions {
  6578. if info.Type == 1 {
  6579. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6580. }
  6581. if info.Type == 2 {
  6582. for _, sumItem := range info.HisPrescriptionProject {
  6583. if sumItem.Type == 3 {
  6584. var good models.DialysisBeforePrepareGoods
  6585. var newGood models.NewDialysisBeforePrepareGoods
  6586. var oldGood models.OldDialysisBeforePrepareGoods
  6587. good.GoodId = sumItem.GoodInfo.ID
  6588. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6589. count, _ := strconv.Atoi(sumItem.Count)
  6590. good.Count = int64(count)
  6591. good.StorehouseId = houseConfig.StorehouseOutInfo
  6592. good.ProjectId = sumItem.ID
  6593. good.PatientId = sumItem.PatientId
  6594. goods = append(goods, &good)
  6595. newGood.GoodId = sumItem.GoodInfo.ID
  6596. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6597. count2, _ := strconv.Atoi(sumItem.Count)
  6598. newGood.Count = int64(count2)
  6599. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6600. newGood.ProjectId = sumItem.ID
  6601. newGood.PatientId = sumItem.HisPatientId
  6602. newGoods = append(newGoods, &newGood)
  6603. oldGood.GoodId = sumItem.GoodInfo.ID
  6604. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6605. count3, _ := strconv.Atoi(sumItem.Count)
  6606. oldGood.Count = int64(count3)
  6607. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6608. oldGood.ProjectId = sumItem.ID
  6609. oldGood.RecordDate = sumItem.RecordDate
  6610. oldGood.PatientId = sumItem.HisPatientId
  6611. oldGoods = append(oldGoods, &oldGood)
  6612. }
  6613. }
  6614. }
  6615. }
  6616. if settConfig.IsOpen == 1 {
  6617. for _, item := range infoList {
  6618. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6619. if medical.IsUse == 2 {
  6620. //药品出库
  6621. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6622. //查询默认仓库
  6623. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6624. //查询默认仓库剩余多少库存
  6625. var sum_count int64
  6626. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6627. for _, its := range stockInfo {
  6628. if its.MaxUnit == medical.MaxUnit {
  6629. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6630. }
  6631. sum_count += its.StockMaxNumber + its.StockMinNumber
  6632. }
  6633. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6634. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6635. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6636. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6637. }
  6638. }
  6639. orgId := c.GetAdminUserInfo().CurrentOrgId
  6640. if len(oldGoods) > 0 {
  6641. timeStr := time.Now().Format("2006-01-02")
  6642. timeArr := strings.Split(timeStr, "-")
  6643. total, _ := service.FindAllWarehouseOut(orgId)
  6644. total = total + 1
  6645. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6646. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6647. number = number + total
  6648. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6649. operation_time := time.Now().Unix()
  6650. creater := c.GetAdminUserInfo().AdminUser.Id
  6651. //查询默认出库仓库库存
  6652. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6653. recordDateStr := time.Now().Format("2006-01-02")
  6654. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6655. nowtime := recordDate.Unix()
  6656. warehouseOut := models.WarehouseOut{
  6657. WarehouseOutOrderNumber: warehousing_out_order,
  6658. OperationTime: operation_time,
  6659. OrgId: orgId,
  6660. Creater: creater,
  6661. Ctime: time.Now().Unix(),
  6662. Status: 1,
  6663. WarehouseOutTime: nowtime,
  6664. Type: 1,
  6665. StorehouseId: storeConfig.StorehouseOutInfo,
  6666. IsCheck: 1,
  6667. OrderId: order.ID,
  6668. IsSys: 5,
  6669. }
  6670. //查询是否生成出库单
  6671. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6672. if out.ID == 0 {
  6673. service.AddSigleWarehouseOut(&warehouseOut)
  6674. }
  6675. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6676. for _, item := range oldGoods {
  6677. dialyPrepareOne := models.DialysisBeforePrepare{
  6678. GoodTypeId: item.GoodTypeId,
  6679. GoodId: item.GoodId,
  6680. PatientId: his.PatientId,
  6681. RecordDate: item.RecordDate,
  6682. UserOrgId: adminUser.CurrentOrgId,
  6683. Count: item.Count,
  6684. Ctime: time.Now().Unix(),
  6685. Creater: adminUser.AdminUser.Id,
  6686. CommdityCode: item.CommdityCode,
  6687. Status: 1,
  6688. StorehouseId: houseConfig.StorehouseOutInfo,
  6689. }
  6690. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6691. //非零用
  6692. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6693. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6694. //查询剩余库存
  6695. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6696. var sum_count int64
  6697. for _, item := range goodList {
  6698. sum_count += item.StockCount
  6699. }
  6700. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6701. //耗材
  6702. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6703. }
  6704. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6705. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6706. //查询剩余库存
  6707. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6708. var sum_count int64
  6709. for _, item := range goodList {
  6710. sum_count += item.StockCount
  6711. }
  6712. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6713. //耗材
  6714. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6715. }
  6716. }
  6717. }
  6718. }
  6719. c.ServeSuccessJSON(map[string]interface{}{
  6720. "msg": "结算成功",
  6721. })
  6722. }
  6723. }
  6724. }
  6725. // 退款
  6726. func (c *HisApiController) Refund() {
  6727. order_id, _ := c.GetInt64("order_id")
  6728. order, _ := service.GetHisOrderByID(order_id)
  6729. adminUser := c.GetAdminUserInfo()
  6730. orgid := c.GetAdminUserInfo().CurrentOrgId
  6731. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6732. if err != nil {
  6733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6734. return
  6735. }
  6736. tmp := strconv.FormatInt(order.ID, 10)
  6737. //当押金不为零时产生退费记录
  6738. if order.Decimal != 0 {
  6739. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6740. if err != nil {
  6741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6742. return
  6743. }
  6744. }
  6745. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6746. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6747. var goods []*models.DialysisBeforePrepareGoods
  6748. var newGoods []*models.NewDialysisBeforePrepareGoods
  6749. var infos []*models.HisDoctorAdviceInfo
  6750. for _, info := range orders {
  6751. if info.AdviceId > 0 && info.ProjectId == 0 {
  6752. infos = append(infos, &info.HisDoctorAdviceInfo)
  6753. }
  6754. if info.ProjectId > 0 && info.AdviceId == 0 {
  6755. if info.HisPrescriptionProject.Type == 3 {
  6756. var good models.DialysisBeforePrepareGoods
  6757. var newGood models.NewDialysisBeforePrepareGoods
  6758. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6759. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6760. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6761. good.Count = int64(count)
  6762. good.StorehouseId = houseConfig.StorehouseOutInfo
  6763. good.ProjectId = info.HisPrescriptionProject.ID
  6764. good.PatientId = info.PatientId
  6765. good.OrderId = order_id
  6766. goods = append(goods, &good)
  6767. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6768. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6769. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6770. newGood.Count = int64(count2)
  6771. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6772. newGood.ProjectId = info.HisPrescriptionProject.ID
  6773. newGood.RecordDate = order.SettleAccountsDate
  6774. newGood.UserOrgId = order.UserOrgId
  6775. newGood.PatientId = info.PatientId
  6776. newGood.OrderId = order_id
  6777. newGoods = append(newGoods, &newGood)
  6778. }
  6779. }
  6780. }
  6781. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6782. if settConfig.IsOpen == 1 {
  6783. for _, item := range infos {
  6784. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6785. }
  6786. for _, item := range newGoods {
  6787. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6788. }
  6789. }
  6790. c.ServeSuccessJSON(map[string]interface{}{
  6791. "msg": "退费成功",
  6792. })
  6793. }
  6794. func (c *HisApiController) RefundNumber() {
  6795. his_patient_id, _ := c.GetInt64("id")
  6796. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6797. info.Status = 0
  6798. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6799. if count > 0 {
  6800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6801. return
  6802. }
  6803. err := service.SaveHisPatient(info)
  6804. if err == nil {
  6805. c.ServeSuccessJSON(map[string]interface{}{
  6806. "msg": "退号成功",
  6807. })
  6808. } else {
  6809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6810. return
  6811. }
  6812. }
  6813. func (this *HisApiController) AdditionalCharge() {
  6814. dataBody := make(map[string]interface{}, 0)
  6815. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6816. fmt.Println(err)
  6817. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6818. patient_id := int64(dataBody["patient_id"].(float64))
  6819. medicineData, _ := dataBody["medicineData"].([]interface{})
  6820. adminUserInfo := this.GetAdminUserInfo()
  6821. orgId := adminUserInfo.CurrentOrgId
  6822. admin_user_id := adminUserInfo.AdminUser.Id
  6823. timeStr := time.Now().Format("2006-01-02")
  6824. timeLayout := "2006-01-02 15:04:05"
  6825. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6826. timenow := timeStringToTime.Unix()
  6827. var additionalCharges []*models.HisAdditionalCharge
  6828. for _, item := range medicineData {
  6829. var randNum int
  6830. randNum = rand.Intn(10000) + 1000
  6831. timestamp := time.Now().Unix()
  6832. tempTime := time.Unix(timestamp, 0)
  6833. timeFormat := tempTime.Format("20060102150405")
  6834. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6835. items := item.(map[string]interface{})
  6836. money := items["price"].(string)
  6837. item_id_str := items["item_id"].(string)
  6838. name := items["name"].(string)
  6839. id_str := items["id"].(string)
  6840. moneys, _ := strconv.ParseInt(money, 10, 64)
  6841. monStr := strconv.FormatInt(moneys, 10)
  6842. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6843. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6844. id, _ := strconv.ParseInt(id_str, 10, 64)
  6845. additionalCharge := &models.HisAdditionalCharge{
  6846. ID: id,
  6847. HisPatientId: his_patient_id,
  6848. UserOrgId: orgId,
  6849. PatientId: patient_id,
  6850. RecordDate: timenow,
  6851. Price: monneyStr,
  6852. Status: 1,
  6853. ItemName: name,
  6854. ItemId: item_id,
  6855. AdminUserId: admin_user_id,
  6856. CreatedTime: time.Now().Unix(),
  6857. OrderStatus: 0,
  6858. PrescriptionNumber: "",
  6859. BatchNumber: "",
  6860. FeedetlSn: p_number,
  6861. }
  6862. service.CreateAdditionalCharge(additionalCharge)
  6863. additionalCharges = append(additionalCharges, additionalCharge)
  6864. }
  6865. this.ServeSuccessJSON(map[string]interface{}{
  6866. "msg": "添加成功",
  6867. "additional_charges": additionalCharges,
  6868. })
  6869. }
  6870. func (this *HisApiController) DeleteAddition() {
  6871. id, _ := this.GetInt64("id")
  6872. //TODO 需要判断是否已经结算
  6873. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6874. if err == nil {
  6875. this.ServeSuccessJSON(map[string]interface{}{
  6876. "msg": "删除成功",
  6877. })
  6878. return
  6879. } else {
  6880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6881. return
  6882. }
  6883. }
  6884. func (this *HisApiController) GetAdminUsers() {
  6885. adminUser := this.GetAdminUserInfo()
  6886. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6887. this.ServeSuccessJSON(map[string]interface{}{
  6888. "doctors": doctors,
  6889. })
  6890. }
  6891. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6892. change_type, _ := this.GetInt64("type", 0)
  6893. record_date := this.GetString("record_time")
  6894. patient_id, _ := this.GetInt64("patient_id", 0)
  6895. p_type, _ := this.GetInt64("p_type", 0)
  6896. timeLayout := "2006-01-02"
  6897. loc, _ := time.LoadLocation("Local")
  6898. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6899. record_time := theAdviceRecordTime.Unix()
  6900. adminUserInfo := this.GetAdminUserInfo()
  6901. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6902. if err == nil {
  6903. if len(prescriptions) == 0 {
  6904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6905. return
  6906. } else {
  6907. this.ServeSuccessJSON(map[string]interface{}{
  6908. "prescriptions": prescriptions,
  6909. })
  6910. return
  6911. }
  6912. } else {
  6913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6914. return
  6915. }
  6916. }
  6917. func (this *HisApiController) GetCallHisPrescription() {
  6918. patient_id, _ := this.GetInt64("patient_id", 0)
  6919. timeLayout := "2006-01-02"
  6920. loc, _ := time.LoadLocation("Local")
  6921. start_time := this.GetString("start_time")
  6922. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6923. end_time := this.GetString("end_time")
  6924. p_type, _ := this.GetInt64("p_type")
  6925. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6926. adminUserInfo := this.GetAdminUserInfo()
  6927. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6928. if err == nil {
  6929. this.ServeSuccessJSON(map[string]interface{}{
  6930. "prescriptions": prescriptions,
  6931. })
  6932. return
  6933. } else {
  6934. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6935. return
  6936. }
  6937. }
  6938. func (this *HisApiController) GetHisDayPrescription() {
  6939. timeLayout := "2006-01-02"
  6940. loc, _ := time.LoadLocation("Local")
  6941. start_time := this.GetString("start_time")
  6942. patient_id, _ := this.GetInt64("patient_id", 0)
  6943. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6944. end_time := this.GetString("end_time")
  6945. p_type, _ := this.GetInt64("p_type")
  6946. order_status, _ := this.GetInt64("type")
  6947. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6948. adminUserInfo := this.GetAdminUserInfo()
  6949. var dayHisPrescription []*models.HisPrescription
  6950. var err error
  6951. if order_status == 1 || order_status == 0 {
  6952. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6953. } else if order_status == 2 {
  6954. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6955. }
  6956. var settle_total float64
  6957. for _, item := range dayHisPrescription {
  6958. if len(item.HisPrescriptionProject) > 0 {
  6959. for _, subItem := range item.HisPrescriptionProject {
  6960. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6961. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6962. settle_total = settle_total + total
  6963. }
  6964. }
  6965. if len(item.HisDoctorAdviceInfo) > 0 {
  6966. for _, subItem := range item.HisDoctorAdviceInfo {
  6967. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6968. settle_total = settle_total + total
  6969. }
  6970. }
  6971. }
  6972. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6973. if err == nil {
  6974. this.ServeSuccessJSON(map[string]interface{}{
  6975. "day_prescription": dayHisPrescription,
  6976. "settle_total": settle_total,
  6977. })
  6978. return
  6979. } else {
  6980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6981. return
  6982. }
  6983. }
  6984. func (c *HisApiController) GetHisChargePatientList() {
  6985. record_date := c.GetString("record_date")
  6986. order_status, _ := c.GetInt64("type")
  6987. sch_type, _ := c.GetInt64("sch_type")
  6988. timeLayout := "2006-01-02"
  6989. loc, _ := time.LoadLocation("Local")
  6990. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6991. if err != nil {
  6992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6993. return
  6994. }
  6995. recordDateTime := theTime.Unix()
  6996. adminInfo := c.GetAdminUserInfo()
  6997. var tempPatients []*service.NewTempPatients
  6998. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6999. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7000. if order_status != 2 {
  7001. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7002. } else {
  7003. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7004. }
  7005. } else {
  7006. if order_status != 2 {
  7007. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7008. } else {
  7009. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7010. }
  7011. }
  7012. var patients []*service.NewTempPatients
  7013. var patients_two []*service.NewTempPatients
  7014. for _, item := range tempPatients {
  7015. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7016. //过滤掉没挂号的和没开处方的
  7017. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7018. patients = append(patients, item)
  7019. }
  7020. //过滤掉没挂号的
  7021. if len(item.HisPatient) > 0 {
  7022. patients_two = append(patients_two, item)
  7023. }
  7024. } else {
  7025. if len(item.HisPrescription) > 0 {
  7026. patients = append(patients, item)
  7027. }
  7028. }
  7029. }
  7030. c.ServeSuccessJSON(map[string]interface{}{
  7031. "list": patients,
  7032. "list_two": patients_two,
  7033. })
  7034. }
  7035. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7036. record_date := c.GetString("record_date")
  7037. timeLayout := "2006-01-02"
  7038. loc, _ := time.LoadLocation("Local")
  7039. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7040. if err != nil {
  7041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7042. return
  7043. }
  7044. recordDateTime := theTime.Unix()
  7045. adminUser := c.GetAdminUserInfo()
  7046. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7047. var patients []*service.Patients
  7048. for _, item := range tempPatients {
  7049. if item.HisPatient.ID == 0 {
  7050. patients = append(patients, item)
  7051. }
  7052. }
  7053. c.ServeSuccessJSON(map[string]interface{}{
  7054. "list": patients,
  7055. //"list_two": patients_two,
  7056. })
  7057. }
  7058. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7059. newArr = make([]*service.Patients, 0)
  7060. for i := 0; i < len(patient); i++ {
  7061. repeat := false
  7062. for j := i + 1; j < len(patient); j++ {
  7063. if patient[i].ID == patient[j].ID {
  7064. repeat = true
  7065. break
  7066. }
  7067. }
  7068. if !repeat {
  7069. newArr = append(newArr, patient[i])
  7070. }
  7071. }
  7072. return
  7073. }
  7074. func (c *HisApiController) GetHisChargePatientInfo() {
  7075. patient_id, _ := c.GetInt64("patient_id")
  7076. his_patient_id, _ := c.GetInt64("his_patient_id")
  7077. record_date := c.GetString("record_date")
  7078. //start_time := c.GetString("start_time")
  7079. //end_time := c.GetString("end_time")
  7080. order_status, _ := c.GetInt64("type", 0)
  7081. p_type, _ := c.GetInt64("p_type", 0)
  7082. order_id, _ := c.GetInt64("order_id", 0)
  7083. timeLayout := "2006-01-02"
  7084. loc, _ := time.LoadLocation("Local")
  7085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7086. if err != nil {
  7087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7088. return
  7089. }
  7090. recordDateTime := theTime.Unix()
  7091. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7092. //if err != nil {
  7093. //
  7094. //}
  7095. //startRecordDateTime := startTime.Unix()
  7096. //
  7097. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7098. //if err != nil {
  7099. //
  7100. //}
  7101. //endRecordDateTime := endTime.Unix()
  7102. admin := c.GetAdminUserInfo()
  7103. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7104. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7105. var prescriptions []*models.HisPrescription
  7106. //var unChargeMonthPrescriptions []*models.HisPrescription
  7107. order, _ := service.GetHisOrderByID(order_id)
  7108. if order_status == 1 || order_status == 0 {
  7109. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7110. } else if order_status == 2 {
  7111. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7112. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7113. }
  7114. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7115. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7116. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7117. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7118. //获取所有科室信息
  7119. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7120. c.ServeSuccessJSON(map[string]interface{}{
  7121. "his_info": his_patient_info,
  7122. "xt_info": xt_patient_info,
  7123. "prescription": prescriptions,
  7124. "case_history": case_history,
  7125. "info": patientPrescriptionInfo,
  7126. "last_info": lastPatientPrescriptionInfo,
  7127. "order": order,
  7128. "doctors": doctors,
  7129. "department": department,
  7130. })
  7131. return
  7132. }
  7133. func (c *HisApiController) GetAllOrderDetail() {
  7134. order_id, _ := c.GetInt64("id", 0)
  7135. order, _ := service.GetHisOrderByID(order_id)
  7136. if order.ID == 0 {
  7137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7138. return
  7139. }
  7140. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7141. org_id := c.GetAdminUserInfo().CurrentOrgId
  7142. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7143. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7144. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7145. c.ServeSuccessJSON(map[string]interface{}{
  7146. "order": order,
  7147. "order_info": order_info,
  7148. "patient": patient,
  7149. "admin_info": adminInfo,
  7150. "hospital_record": record,
  7151. })
  7152. return
  7153. }
  7154. func (c *HisApiController) GetAllOrderDetailCollect() {
  7155. order_id, _ := c.GetInt64("id", 0)
  7156. order, _ := service.GetHisOrderByID(order_id)
  7157. if order.ID == 0 {
  7158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7159. return
  7160. }
  7161. org_id := c.GetAdminUserInfo().CurrentOrgId
  7162. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7163. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7164. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7165. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7166. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7167. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7168. var bedCostTotal float64 = 0 //床位总费
  7169. //var bedCostSelfTotal float64 = 0 //床位自费
  7170. var operationCostTotal float64 = 0 //手术费
  7171. //var operationCostSelfTotal float64 = 0 //手术费
  7172. var otherCostTotal float64 = 0 //其他费用
  7173. //var otherCostSelfTotal float64 = 0 //其他费用
  7174. var materialCostTotal float64 = 0 //材料费
  7175. //var materialCostSelfTotal float64 = 0 //材料费
  7176. var westernMedicineCostTotal float64 = 0 //西药费
  7177. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7178. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7179. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7180. var checkCostTotal float64 = 0 //检查费
  7181. //var checkCostSelfTotal float64 = 0 //检查费
  7182. var laboratoryCostTotal float64 = 0 //化验费
  7183. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7184. var treatCostTotal float64 = 0 //治疗费用
  7185. //var treatCostSelfTotal float64 = 0 //治疗费用
  7186. var zhenChaCostTotal float64 = 0 //其他费用
  7187. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7188. decimal.DivisionPrecision = 2
  7189. var BalanceAccountsType int64
  7190. if his.ID > 0 {
  7191. BalanceAccountsType = his.BalanceAccountsType
  7192. } else {
  7193. BalanceAccountsType = record.BalanceAccountsType
  7194. }
  7195. if BalanceAccountsType != 2 {
  7196. for _, item := range order_info {
  7197. if org_id == 10215 {
  7198. if item.MedChrgitmType == "01" { //床位费
  7199. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7200. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7201. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7202. }
  7203. if item.MedChrgitmType == "02" { //诊察费
  7204. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7205. //zhenChaCostSelfTotal = zhenChaCostTotal
  7206. }
  7207. if item.MedChrgitmType == "03" { //检查费
  7208. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7209. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7210. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7211. }
  7212. //if item.MedChrgitmType == "02" { //检查费
  7213. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7214. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7215. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7216. //}
  7217. if item.MedChrgitmType == "04" { //化验费
  7218. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7219. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7220. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7221. }
  7222. if item.MedChrgitmType == "05" { //治疗费
  7223. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7224. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7225. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7226. }
  7227. if item.MedChrgitmType == "06" { //手术费
  7228. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7229. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7230. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7231. }
  7232. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7233. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7234. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7235. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7236. }
  7237. if item.MedChrgitmType == "09" { //西药费
  7238. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7239. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7240. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7241. }
  7242. if item.MedChrgitmType == "11" { //中成费
  7243. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7244. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7245. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7246. }
  7247. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7248. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7249. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7250. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7251. }
  7252. } else if org_id == 10188 || org_id == 10217 {
  7253. if item.MedChrgitmType == "01" { //床位费
  7254. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7255. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7256. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7257. }
  7258. if item.MedChrgitmType == "02" { //诊察费
  7259. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7260. //zhenChaCostSelfTotal = zhenChaCostTotal
  7261. }
  7262. if item.MedChrgitmType == "03" { //检查费
  7263. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7264. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7265. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7266. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7267. }
  7268. //if item.MedChrgitmType == "02" { //检查费
  7269. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7270. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7271. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7272. //}
  7273. if item.MedChrgitmType == "04" { //化验费
  7274. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7275. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7276. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7277. }
  7278. if item.MedChrgitmType == "05" { //治疗费
  7279. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7280. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7281. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7282. }
  7283. if item.MedChrgitmType == "06" { //手术费
  7284. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7285. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7286. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7287. }
  7288. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7289. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7290. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7291. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7292. }
  7293. if item.MedChrgitmType == "09" { //西药费
  7294. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7295. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7296. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7297. }
  7298. if item.MedChrgitmType == "11" { //中成费
  7299. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7300. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7301. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7302. }
  7303. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7304. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7305. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7306. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7307. }
  7308. } else {
  7309. if item.MedChrgitmType == "01" { //床位费
  7310. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7311. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7312. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7313. }
  7314. //if item.MedChrgitmType == "02" { //诊察费
  7315. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7316. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7317. //}
  7318. if item.MedChrgitmType == "03" { //检查费
  7319. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7320. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7321. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7322. }
  7323. //if item.MedChrgitmType == "02" { //检查费
  7324. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7325. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7326. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7327. //}
  7328. if item.MedChrgitmType == "04" { //化验费
  7329. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7330. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7331. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7332. }
  7333. if item.MedChrgitmType == "05" { //治疗费
  7334. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7336. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7337. }
  7338. if item.MedChrgitmType == "06" { //手术费
  7339. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7340. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7341. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7342. }
  7343. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7344. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7345. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7346. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7347. }
  7348. if item.MedChrgitmType == "09" { //西药费
  7349. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7350. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7351. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7352. }
  7353. if item.MedChrgitmType == "11" { //中成费
  7354. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7355. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7356. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7357. }
  7358. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7359. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7360. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7361. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7362. }
  7363. }
  7364. }
  7365. c.ServeSuccessJSON(map[string]interface{}{
  7366. "order": order,
  7367. "order_info": order_info,
  7368. "patient": patient,
  7369. "admin_info": adminInfo,
  7370. "his_hospital": record,
  7371. "bedCostTotal": bedCostTotal,
  7372. "operationCostTotal": operationCostTotal,
  7373. "otherCostTotal": otherCostTotal,
  7374. "materialCostTotal": materialCostTotal,
  7375. "westernMedicineCostTotal": westernMedicineCostTotal,
  7376. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7377. "checkCostTotal": checkCostTotal,
  7378. "zhenChaCostTotal": zhenChaCostTotal,
  7379. "laboratoryCostTotal": laboratoryCostTotal,
  7380. "treatCostTotal": treatCostTotal,
  7381. })
  7382. } else {
  7383. for _, item := range order_info {
  7384. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7385. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7386. item.MedChrgitmType = "09"
  7387. }
  7388. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7389. if item.HisPrescriptionProject.Type == 2 {
  7390. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7391. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7392. case 0:
  7393. item.MedChrgitmType = "0"
  7394. break
  7395. case 1:
  7396. item.MedChrgitmType = "14"
  7397. break
  7398. case 2:
  7399. item.MedChrgitmType = "05"
  7400. break
  7401. case 3:
  7402. item.MedChrgitmType = "03"
  7403. break
  7404. case 4:
  7405. item.MedChrgitmType = "03"
  7406. break
  7407. case 5:
  7408. item.MedChrgitmType = "08"
  7409. break
  7410. case 6:
  7411. item.MedChrgitmType = "14"
  7412. break
  7413. case 7:
  7414. item.MedChrgitmType = "14"
  7415. break
  7416. case 8:
  7417. item.MedChrgitmType = "03"
  7418. break
  7419. case 9:
  7420. item.MedChrgitmType = "14"
  7421. break
  7422. case 10:
  7423. item.MedChrgitmType = "14"
  7424. break
  7425. case 11:
  7426. item.MedChrgitmType = "06"
  7427. break
  7428. case 12:
  7429. item.MedChrgitmType = "12"
  7430. break
  7431. case 13:
  7432. item.MedChrgitmType = "01"
  7433. break
  7434. case 14:
  7435. item.MedChrgitmType = "04"
  7436. break
  7437. case 15:
  7438. item.MedChrgitmType = "14"
  7439. break
  7440. }
  7441. } else {
  7442. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7443. case 1:
  7444. item.MedChrgitmType = "14"
  7445. break
  7446. case 2:
  7447. item.MedChrgitmType = "05"
  7448. break
  7449. case 3:
  7450. item.MedChrgitmType = "04"
  7451. break
  7452. case 4:
  7453. item.MedChrgitmType = "14"
  7454. break
  7455. case 5:
  7456. item.MedChrgitmType = "08"
  7457. break
  7458. case 6:
  7459. item.MedChrgitmType = "14"
  7460. break
  7461. case 7:
  7462. item.MedChrgitmType = "14"
  7463. break
  7464. case 8:
  7465. item.MedChrgitmType = "03"
  7466. break
  7467. case 9:
  7468. item.MedChrgitmType = "14"
  7469. break
  7470. }
  7471. }
  7472. } else if item.HisPrescriptionProject.Type == 3 {
  7473. item.MedChrgitmType = "08"
  7474. }
  7475. }
  7476. }
  7477. for _, item := range order_info {
  7478. if org_id == 10215 {
  7479. if item.MedChrgitmType == "01" { //床位费
  7480. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7481. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7482. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7483. }
  7484. if item.MedChrgitmType == "02" { //诊察费
  7485. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7486. //zhenChaCostSelfTotal = zhenChaCostTotal
  7487. }
  7488. if item.MedChrgitmType == "03" { //检查费
  7489. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7490. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7491. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7492. }
  7493. //if item.MedChrgitmType == "02" { //检查费
  7494. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7495. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7496. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7497. //}
  7498. if item.MedChrgitmType == "04" { //化验费
  7499. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7500. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7501. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7502. }
  7503. if item.MedChrgitmType == "05" { //治疗费
  7504. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7505. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7506. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7507. }
  7508. if item.MedChrgitmType == "06" { //手术费
  7509. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7510. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7511. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7512. }
  7513. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7514. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7515. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7516. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7517. }
  7518. if item.MedChrgitmType == "09" { //西药费
  7519. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7520. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7521. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7522. }
  7523. if item.MedChrgitmType == "11" { //中成费
  7524. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7525. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7526. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7527. }
  7528. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7529. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7530. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7531. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7532. }
  7533. } else {
  7534. if item.MedChrgitmType == "01" { //床位费
  7535. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7536. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7537. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7538. }
  7539. //if item.MedChrgitmType == "02" { //诊察费
  7540. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7541. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7542. //}
  7543. if item.MedChrgitmType == "03" { //检查费
  7544. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7545. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7546. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7547. }
  7548. //if item.MedChrgitmType == "02" { //检查费
  7549. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7550. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7551. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7552. //}
  7553. if item.MedChrgitmType == "04" { //化验费
  7554. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7555. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7556. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7557. }
  7558. if item.MedChrgitmType == "05" { //治疗费
  7559. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7560. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7561. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7562. }
  7563. if item.MedChrgitmType == "06" { //手术费
  7564. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7565. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7566. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7567. }
  7568. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7569. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7570. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7571. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7572. }
  7573. if item.MedChrgitmType == "09" { //西药费
  7574. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7575. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7576. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7577. }
  7578. if item.MedChrgitmType == "11" { //中成费
  7579. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7580. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7581. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7582. }
  7583. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7584. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7585. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7586. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7587. }
  7588. }
  7589. }
  7590. c.ServeSuccessJSON(map[string]interface{}{
  7591. "order": order,
  7592. "order_info": order_info,
  7593. "patient": patient,
  7594. "admin_info": adminInfo,
  7595. "his_hospital": record,
  7596. "bedCostTotal": bedCostTotal,
  7597. "operationCostTotal": operationCostTotal,
  7598. "otherCostTotal": otherCostTotal,
  7599. "materialCostTotal": materialCostTotal,
  7600. "westernMedicineCostTotal": westernMedicineCostTotal,
  7601. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7602. "checkCostTotal": checkCostTotal,
  7603. "zhenChaCostTotal": zhenChaCostTotal,
  7604. "laboratoryCostTotal": laboratoryCostTotal,
  7605. "treatCostTotal": treatCostTotal,
  7606. })
  7607. }
  7608. }
  7609. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7610. page, _ := c.GetInt64("page")
  7611. limit, _ := c.GetInt64("limit")
  7612. keywords := c.GetString("keywords")
  7613. start_time := c.GetString("start_time")
  7614. end_time := c.GetString("end_time")
  7615. //clr_type := c.GetString("clr_type")
  7616. insutype := c.GetString("insutype")
  7617. timeLayout := "2006-01-02"
  7618. loc, _ := time.LoadLocation("Local")
  7619. var theStartTIme int64
  7620. if len(start_time) > 0 {
  7621. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7622. theStartTIme = theTime.Unix()
  7623. }
  7624. var theEndtTIme int64
  7625. if len(end_time) > 0 {
  7626. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7627. theEndtTIme = theTime.Unix()
  7628. }
  7629. if page <= 0 {
  7630. page = 1
  7631. }
  7632. if limit <= 0 {
  7633. limit = 10
  7634. }
  7635. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7636. c.ServeSuccessJSON(map[string]interface{}{
  7637. "total": total,
  7638. "list": list,
  7639. })
  7640. return
  7641. }
  7642. func (c *HisApiController) GetPutOnRecordList() {
  7643. page, _ := c.GetInt64("page")
  7644. limit, _ := c.GetInt64("limit")
  7645. keywords := c.GetString("keywords")
  7646. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7647. if page <= 0 {
  7648. page = 1
  7649. }
  7650. if limit <= 0 {
  7651. limit = 10
  7652. }
  7653. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7654. c.ServeSuccessJSON(map[string]interface{}{
  7655. "total": total,
  7656. "list": list,
  7657. })
  7658. return
  7659. }
  7660. func (c *HisApiController) GetCompareData() {
  7661. start_time := c.GetString("start_time")
  7662. end_time := c.GetString("end_time")
  7663. insutype := c.GetString("insutype")
  7664. clr_type := c.GetString("clr_type")
  7665. timeLayout := "2006-01-02"
  7666. loc, _ := time.LoadLocation("Local")
  7667. var theStartTIme int64
  7668. if len(start_time) > 0 {
  7669. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7670. if err != nil {
  7671. theStartTIme = 0
  7672. }
  7673. theStartTIme = theTime.Unix()
  7674. }
  7675. var theEndtTIme int64
  7676. if len(end_time) > 0 {
  7677. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7678. if err != nil {
  7679. theEndtTIme = 0
  7680. }
  7681. theEndtTIme = theTime.Unix()
  7682. }
  7683. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7684. fmt.Println(err)
  7685. if err == nil {
  7686. c.ServeSuccessJSON(map[string]interface{}{
  7687. "list": formData,
  7688. })
  7689. } else {
  7690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7691. return
  7692. }
  7693. }
  7694. func (c *HisApiController) GetFaPiaoData() {
  7695. order_id, _ := c.GetInt64("order_id")
  7696. patient_id, _ := c.GetInt64("patient_id")
  7697. //number := c.GetString("number")
  7698. adminUser := c.GetAdminUserInfo()
  7699. order, _ := service.GetHisOrderByID(order_id)
  7700. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7701. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7702. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7703. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7704. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7705. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7706. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7707. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7708. var bedCostTotal float64 = 0 //床位总费
  7709. var bedCostSelfTotal float64 = 0 //床位自费
  7710. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7711. var operationCostTotal float64 = 0 //手术费
  7712. var operationCostSelfTotal float64 = 0 //手术费
  7713. var operationCostPartSelfTotal float64 = 0 //手术费
  7714. var otherCostTotal float64 = 0 //其他费用
  7715. var otherCostSelfTotal float64 = 0 //其他费用
  7716. var otherCostPartSelfTotal float64 = 0 //其他费用
  7717. var materialCostTotal float64 = 0 //材料费
  7718. var materialCostSelfTotal float64 = 0 //材料费
  7719. var materialCostPartSelfTotal float64 = 0 //材料费
  7720. var westernMedicineCostTotal float64 = 0 //西药费
  7721. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7722. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7723. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7724. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7725. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7726. var checkCostTotal float64 = 0 //检查费
  7727. var checkCostSelfTotal float64 = 0 //检查费
  7728. var checkCostPartSelfTotal float64 = 0 //检查费
  7729. var hiliCostTotal float64 = 0 //护理费
  7730. var hiliCostSelfTotal float64 = 0 //护理费
  7731. var hiliCostPartSelfTotal float64 = 0 //护理费
  7732. var laboratoryCostTotal float64 = 0 //化验费
  7733. var laboratoryCostSelfTotal float64 = 0 //化验费
  7734. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7735. var treatCostTotal float64 = 0 //治疗费用
  7736. var treatCostSelfTotal float64 = 0 //治疗费用
  7737. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7738. var zhenChaCostTotal float64 = 0 //其他费用
  7739. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7740. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7741. decimal.DivisionPrecision = 2
  7742. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7743. var balanceAccountsType int64
  7744. if his.ID > 0 {
  7745. balanceAccountsType = his.BalanceAccountsType
  7746. } else {
  7747. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7748. }
  7749. if balanceAccountsType == 2 {
  7750. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7751. for _, item := range orderInfos_two {
  7752. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7753. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7754. item.MedChrgitmType = "09"
  7755. }
  7756. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7757. if item.HisPrescriptionProject.Type == 2 {
  7758. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7759. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7760. case 0:
  7761. item.MedChrgitmType = "0"
  7762. break
  7763. case 1:
  7764. item.MedChrgitmType = "14"
  7765. break
  7766. case 2:
  7767. item.MedChrgitmType = "05"
  7768. break
  7769. case 3:
  7770. item.MedChrgitmType = "03"
  7771. break
  7772. case 4:
  7773. item.MedChrgitmType = "03"
  7774. break
  7775. case 5:
  7776. item.MedChrgitmType = "08"
  7777. break
  7778. case 6:
  7779. item.MedChrgitmType = "14"
  7780. break
  7781. case 7:
  7782. item.MedChrgitmType = "14"
  7783. break
  7784. case 8:
  7785. item.MedChrgitmType = "03"
  7786. break
  7787. case 9:
  7788. item.MedChrgitmType = "14"
  7789. break
  7790. case 10:
  7791. item.MedChrgitmType = "14"
  7792. break
  7793. case 11:
  7794. item.MedChrgitmType = "06"
  7795. break
  7796. case 12:
  7797. item.MedChrgitmType = "12"
  7798. break
  7799. case 13:
  7800. item.MedChrgitmType = "01"
  7801. break
  7802. case 14:
  7803. item.MedChrgitmType = "04"
  7804. break
  7805. case 15:
  7806. item.MedChrgitmType = "02"
  7807. break
  7808. }
  7809. } else {
  7810. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7811. case 1:
  7812. item.MedChrgitmType = "14"
  7813. break
  7814. case 2:
  7815. item.MedChrgitmType = "05"
  7816. break
  7817. case 3:
  7818. item.MedChrgitmType = "03"
  7819. break
  7820. case 4:
  7821. item.MedChrgitmType = "03"
  7822. break
  7823. case 5:
  7824. item.MedChrgitmType = "08"
  7825. break
  7826. case 6:
  7827. item.MedChrgitmType = "14"
  7828. break
  7829. case 7:
  7830. item.MedChrgitmType = "14"
  7831. break
  7832. case 8:
  7833. item.MedChrgitmType = "03"
  7834. break
  7835. case 9:
  7836. item.MedChrgitmType = "14"
  7837. break
  7838. }
  7839. }
  7840. } else if item.HisPrescriptionProject.Type == 3 {
  7841. item.MedChrgitmType = "08"
  7842. }
  7843. }
  7844. }
  7845. for _, item := range orderInfos_two {
  7846. fmt.Println(item.MedChrgitmType)
  7847. if item.MedChrgitmType == "07" { //床位费
  7848. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7849. hiliCostSelfTotal = hiliCostTotal
  7850. }
  7851. if item.MedChrgitmType == "01" { //床位费
  7852. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7853. bedCostSelfTotal = bedCostTotal
  7854. }
  7855. if item.MedChrgitmType == "02" { //诊察费
  7856. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7857. zhenChaCostSelfTotal = zhenChaCostTotal
  7858. }
  7859. if item.MedChrgitmType == "03" { //检查费
  7860. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7861. checkCostSelfTotal = checkCostTotal
  7862. }
  7863. if item.MedChrgitmType == "04" { //化验费
  7864. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7865. laboratoryCostSelfTotal = laboratoryCostTotal
  7866. }
  7867. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7868. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7869. treatCostSelfTotal = treatCostTotal
  7870. }
  7871. if item.MedChrgitmType == "06" { //手术费
  7872. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7873. operationCostSelfTotal = treatCostTotal
  7874. }
  7875. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7876. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7877. materialCostSelfTotal = materialCostTotal
  7878. }
  7879. if item.MedChrgitmType == "09" { //西药费
  7880. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7881. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7882. }
  7883. if item.MedChrgitmType == "11" { //中成费
  7884. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7885. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7886. }
  7887. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7888. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7889. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7890. otherCostSelfTotal = otherCostTotal
  7891. }
  7892. } else {
  7893. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7894. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7895. otherCostSelfTotal = otherCostTotal
  7896. }
  7897. }
  7898. }
  7899. } else {
  7900. for _, item := range orderInfos {
  7901. if item.MedChrgitmType == "01" { //床位费
  7902. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7903. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7904. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7905. }
  7906. if item.MedChrgitmType == "02" { //诊察费
  7907. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7908. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7909. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7910. }
  7911. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7912. if item.MedChrgitmType == "03" { //检查费
  7913. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7914. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7915. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7916. }
  7917. } else {
  7918. if item.MedChrgitmType == "03" { //检查费
  7919. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7920. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7921. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7922. }
  7923. }
  7924. if item.MedChrgitmType == "04" { //化验费
  7925. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7926. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7927. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7928. }
  7929. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7930. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7931. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7932. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7933. }
  7934. if item.MedChrgitmType == "06" { //手术费
  7935. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7936. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7937. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7938. }
  7939. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  7940. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7941. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7942. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7943. }
  7944. if item.MedChrgitmType == "07" { //西药费
  7945. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7946. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7947. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7948. }
  7949. if item.MedChrgitmType == "09" { //西药费
  7950. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7951. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7952. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7953. }
  7954. if item.MedChrgitmType == "11" { //中成费
  7955. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7956. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7957. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7958. }
  7959. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7960. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7961. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7962. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7963. }
  7964. }
  7965. }
  7966. timeLayout := "2006-01-02"
  7967. loc, _ := time.LoadLocation("Local")
  7968. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7969. if err != nil {
  7970. }
  7971. startRecordDateTime := startTime.Unix()
  7972. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7973. if err != nil {
  7974. }
  7975. endRecordDateTime := endTime.Unix()
  7976. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7977. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7978. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7979. c.ServeSuccessJSON(map[string]interface{}{
  7980. "order_number": order.Number, //业务流水号
  7981. "id_card_no": his.IdCardNo, //社会保障号
  7982. "patient": patient,
  7983. "department_name": department.Name, //科室
  7984. "number": his.Number, //门诊号
  7985. "date": order.SettleAccountsDate, //结算日期
  7986. "name": order.PsnName, //姓名
  7987. "gender": patient.Gender, //性别
  7988. "psn_cash_money": order.PsnCashPay, //个人支付
  7989. "pay_way": "门诊", //结算方式
  7990. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7991. "admin_user_name": admin.UserName, //收款员
  7992. "order": order,
  7993. "order_info": orderInfos_two,
  7994. "his": his,
  7995. "bedCostTotal": bedCostTotal,
  7996. "bedCostSelfTotal": bedCostSelfTotal,
  7997. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7998. "operationCostTotal": operationCostTotal,
  7999. "operationCostSelfTotal": operationCostSelfTotal,
  8000. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8001. "otherCostTotal": otherCostTotal,
  8002. "otherCostSelfTotal": otherCostSelfTotal,
  8003. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8004. "materialCostTotal": materialCostTotal,
  8005. "materialCostSelfTotal": materialCostSelfTotal,
  8006. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8007. "westernMedicineCostTotal": westernMedicineCostTotal,
  8008. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8009. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8010. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8011. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8012. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8013. "checkCostTotal": checkCostTotal,
  8014. "checkCostSelfTotal": checkCostSelfTotal,
  8015. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8016. "laboratoryCostTotal": laboratoryCostTotal,
  8017. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8018. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8019. "treatCostTotal": treatCostTotal,
  8020. "treatCostSelfTotal": treatCostSelfTotal,
  8021. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8022. "zhenChaCostTotal": zhenChaCostTotal,
  8023. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8024. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8025. "his_hospital_record": his_hospital_record,
  8026. "pre_pay_money": pre_pay_money,
  8027. "refund_sum": sum,
  8028. "doctor_info": doctor_info,
  8029. "hiliCostTotal": hiliCostTotal,
  8030. "hiliCostSelfTotal": hiliCostSelfTotal,
  8031. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8032. })
  8033. }
  8034. //func (c *HisApiController) GetFaPiaoDatas() {
  8035. // order_ids := c.GetString("order_ids")
  8036. // patient_id, _ := c.GetInt64("patient_id")
  8037. // adminUser := c.GetAdminUserInfo()
  8038. //
  8039. // orders := strings.Split(order_ids, ",")
  8040. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8041. //
  8042. // for _, item := range orders {
  8043. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8044. // order, _ := service.GetHisOrderByID(order_id)
  8045. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8046. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8047. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8048. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8049. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8050. //
  8051. // }
  8052. //
  8053. // var bedCostTotal float64 = 0 //床位总费
  8054. // var bedCostSelfTotal float64 = 0 //床位自费
  8055. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8056. //
  8057. // var operationCostTotal float64 = 0 //手术费
  8058. // var operationCostSelfTotal float64 = 0 //手术费
  8059. // var operationCostPartSelfTotal float64 = 0 //手术费
  8060. //
  8061. // var otherCostTotal float64 = 0 //其他费用
  8062. // var otherCostSelfTotal float64 = 0 //其他费用
  8063. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8064. //
  8065. // var materialCostTotal float64 = 0 //材料费
  8066. // var materialCostSelfTotal float64 = 0 //材料费
  8067. // var materialCostPartSelfTotal float64 = 0 //材料费
  8068. //
  8069. // var westernMedicineCostTotal float64 = 0 //西药费
  8070. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8071. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8072. //
  8073. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8074. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8075. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8076. //
  8077. // var checkCostTotal float64 = 0 //检查费
  8078. // var checkCostSelfTotal float64 = 0 //检查费
  8079. // var checkCostPartSelfTotal float64 = 0 //检查费
  8080. //
  8081. // var laboratoryCostTotal float64 = 0 //化验费
  8082. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8083. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8084. //
  8085. // var treatCostTotal float64 = 0 //治疗费用
  8086. // var treatCostSelfTotal float64 = 0 //治疗费用
  8087. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8088. //
  8089. // var zhenChaCostTotal float64 = 0 //其他费用
  8090. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8091. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8092. //
  8093. // decimal.DivisionPrecision = 2
  8094. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8095. //
  8096. // var balanceAccountsType int64
  8097. // if his.ID > 0 {
  8098. // balanceAccountsType = his.BalanceAccountsType
  8099. // } else {
  8100. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8101. // }
  8102. // if balanceAccountsType == 2 {
  8103. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8104. // for _, item := range orderInfos_two {
  8105. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8106. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8107. // item.MedChrgitmType = "09"
  8108. // }
  8109. //
  8110. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8111. // if item.HisPrescriptionProject.Type == 2 {
  8112. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8113. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8114. // case 0:
  8115. // item.MedChrgitmType = "0"
  8116. // break
  8117. // case 1:
  8118. // item.MedChrgitmType = "14"
  8119. // break
  8120. // case 2:
  8121. // item.MedChrgitmType = "05"
  8122. //
  8123. // break
  8124. // case 3:
  8125. // item.MedChrgitmType = "03"
  8126. //
  8127. // break
  8128. // case 4:
  8129. // item.MedChrgitmType = "03"
  8130. //
  8131. // break
  8132. // case 5:
  8133. // item.MedChrgitmType = "08"
  8134. //
  8135. // break
  8136. // case 6:
  8137. // item.MedChrgitmType = "14"
  8138. //
  8139. // break
  8140. // case 7:
  8141. // item.MedChrgitmType = "14"
  8142. //
  8143. // break
  8144. // case 8:
  8145. // item.MedChrgitmType = "03"
  8146. // break
  8147. // case 9:
  8148. // item.MedChrgitmType = "14"
  8149. // break
  8150. // case 10:
  8151. // item.MedChrgitmType = "14"
  8152. // break
  8153. // case 11:
  8154. // item.MedChrgitmType = "06"
  8155. // break
  8156. // case 12:
  8157. // item.MedChrgitmType = "12"
  8158. // break
  8159. // case 13:
  8160. // item.MedChrgitmType = "01"
  8161. // break
  8162. // case 14:
  8163. // item.MedChrgitmType = "04"
  8164. // break
  8165. // case 15:
  8166. // item.MedChrgitmType = "02"
  8167. // break
  8168. //
  8169. // }
  8170. //
  8171. // } else {
  8172. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8173. //
  8174. // case 1:
  8175. // item.MedChrgitmType = "14"
  8176. // break
  8177. // case 2:
  8178. // item.MedChrgitmType = "05"
  8179. //
  8180. // break
  8181. // case 3:
  8182. // item.MedChrgitmType = "03"
  8183. //
  8184. // break
  8185. // case 4:
  8186. // item.MedChrgitmType = "03"
  8187. //
  8188. // break
  8189. // case 5:
  8190. // item.MedChrgitmType = "08"
  8191. //
  8192. // break
  8193. // case 6:
  8194. // item.MedChrgitmType = "14"
  8195. //
  8196. // break
  8197. // case 7:
  8198. // item.MedChrgitmType = "14"
  8199. //
  8200. // break
  8201. // case 8:
  8202. // item.MedChrgitmType = "03"
  8203. // break
  8204. // case 9:
  8205. // item.MedChrgitmType = "14"
  8206. // break
  8207. //
  8208. // }
  8209. //
  8210. // }
  8211. //
  8212. // } else if item.HisPrescriptionProject.Type == 3 {
  8213. // item.MedChrgitmType = "08"
  8214. // }
  8215. // }
  8216. // }
  8217. //
  8218. // for _, item := range orderInfos_two {
  8219. // fmt.Println(item.MedChrgitmType)
  8220. // if item.MedChrgitmType == "01" { //床位费
  8221. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8222. // bedCostSelfTotal = bedCostTotal
  8223. // }
  8224. //
  8225. // if item.MedChrgitmType == "02" { //诊察费
  8226. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8227. // zhenChaCostSelfTotal = zhenChaCostTotal
  8228. // }
  8229. //
  8230. // if item.MedChrgitmType == "03" { //检查费
  8231. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8232. // checkCostSelfTotal = checkCostTotal
  8233. // }
  8234. //
  8235. // if item.MedChrgitmType == "04" { //化验费
  8236. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8237. // laboratoryCostSelfTotal = laboratoryCostTotal
  8238. // }
  8239. //
  8240. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8241. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8242. // treatCostSelfTotal = treatCostTotal
  8243. // }
  8244. //
  8245. // if item.MedChrgitmType == "06" { //手术费
  8246. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8247. // operationCostSelfTotal = treatCostTotal
  8248. // }
  8249. //
  8250. // if item.MedChrgitmType == "08" { //材料费
  8251. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8252. // materialCostSelfTotal = materialCostTotal
  8253. // }
  8254. //
  8255. // if item.MedChrgitmType == "09" { //西药费
  8256. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8257. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8258. // }
  8259. //
  8260. // if item.MedChrgitmType == "11" { //中成费
  8261. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8262. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8263. // }
  8264. //
  8265. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8266. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8267. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8268. // otherCostSelfTotal = otherCostTotal
  8269. // }
  8270. // } else {
  8271. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8272. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8273. // otherCostSelfTotal = otherCostTotal
  8274. // }
  8275. //
  8276. // }
  8277. //
  8278. // }
  8279. //
  8280. // } else {
  8281. // for _, item := range orderInfos {
  8282. // if item.MedChrgitmType == "01" { //床位费
  8283. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8284. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8285. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8286. // }
  8287. //
  8288. // if item.MedChrgitmType == "02" { //诊察费
  8289. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8290. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8291. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8292. // }
  8293. //
  8294. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8295. // if item.MedChrgitmType == "03" { //检查费
  8296. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8297. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8298. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8299. //
  8300. // }
  8301. // } else {
  8302. // if item.MedChrgitmType == "03" { //检查费
  8303. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8304. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8305. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8306. // }
  8307. //
  8308. // }
  8309. //
  8310. // if item.MedChrgitmType == "04" { //化验费
  8311. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8312. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8313. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8314. //
  8315. // }
  8316. //
  8317. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8318. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8319. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8320. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8321. //
  8322. // }
  8323. //
  8324. // if item.MedChrgitmType == "06" { //手术费
  8325. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8326. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8327. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8328. // }
  8329. //
  8330. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8331. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8332. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8333. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8334. // }
  8335. //
  8336. // if item.MedChrgitmType == "09" { //西药费
  8337. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8338. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8339. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8340. // }
  8341. //
  8342. // if item.MedChrgitmType == "11" { //中成费
  8343. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8344. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8345. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8346. // }
  8347. //
  8348. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8349. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8350. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8351. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8352. // }
  8353. //
  8354. // }
  8355. // }
  8356. // timeLayout := "2006-01-02"
  8357. // loc, _ := time.LoadLocation("Local")
  8358. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8359. // if err != nil {
  8360. // }
  8361. // startRecordDateTime := startTime.Unix()
  8362. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8363. // if err != nil {
  8364. // }
  8365. // endRecordDateTime := endTime.Unix()
  8366. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8367. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8368. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8369. //
  8370. // c.ServeSuccessJSON(map[string]interface{}{
  8371. // "order_number": order.Number, //业务流水号
  8372. // "id_card_no": his.IdCardNo, //社会保障号
  8373. // "department_name": department.Name, //科室
  8374. // "number": his.Number, //门诊号
  8375. // "date": order.SettleAccountsDate, //结算日期
  8376. // "name": order.PsnName, //姓名
  8377. // "gender": patient.Gender, //性别
  8378. // "psn_cash_money": order.PsnCashPay, //个人支付
  8379. // "pay_way": "门诊", //结算方式
  8380. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8381. // "admin_user_name": admin.UserName, //收款员
  8382. // "order": order,
  8383. // "order_info": orderInfos_two,
  8384. // "his": his,
  8385. // "bedCostTotal": bedCostTotal,
  8386. // "bedCostSelfTotal": bedCostSelfTotal,
  8387. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8388. // "operationCostTotal": operationCostTotal,
  8389. // "operationCostSelfTotal": operationCostSelfTotal,
  8390. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8391. // "otherCostTotal": otherCostTotal,
  8392. // "otherCostSelfTotal": otherCostSelfTotal,
  8393. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8394. // "materialCostTotal": materialCostTotal,
  8395. // "materialCostSelfTotal": materialCostSelfTotal,
  8396. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8397. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8398. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8399. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8400. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8401. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8402. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8403. // "checkCostTotal": checkCostTotal,
  8404. // "checkCostSelfTotal": checkCostSelfTotal,
  8405. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8406. // "laboratoryCostTotal": laboratoryCostTotal,
  8407. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8408. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8409. // "treatCostTotal": treatCostTotal,
  8410. // "treatCostSelfTotal": treatCostSelfTotal,
  8411. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8412. // "zhenChaCostTotal": zhenChaCostTotal,
  8413. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8414. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8415. // "his_hospital_record": his_hospital_record,
  8416. // "pre_pay_money": pre_pay_money,
  8417. // "refund_sum": sum,
  8418. // })
  8419. //
  8420. //}
  8421. func (this *HisApiController) GetIncomeStatisticsData() {
  8422. start_time := this.GetString("start_time")
  8423. end_time := this.GetString("end_time")
  8424. key_words := this.GetString("key_words")
  8425. limit, _ := this.GetInt64("limit")
  8426. page, _ := this.GetInt64("page")
  8427. if page <= 0 {
  8428. page = 1
  8429. }
  8430. if limit <= 0 {
  8431. limit = 10
  8432. }
  8433. statistics_type, _ := this.GetInt64("statistics_type")
  8434. admin := this.GetAdminUserInfo()
  8435. timeLayout := "2006-01-02"
  8436. loc, _ := time.LoadLocation("Local")
  8437. var theStartTIme int64
  8438. if len(start_time) > 0 {
  8439. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8440. if err != nil {
  8441. theStartTIme = 0
  8442. }
  8443. theStartTIme = theTime.Unix()
  8444. }
  8445. var theEndtTIme int64
  8446. if len(end_time) > 0 {
  8447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8448. if err != nil {
  8449. theEndtTIme = 0
  8450. }
  8451. theEndtTIme = theTime.Unix()
  8452. }
  8453. if statistics_type == 1 {
  8454. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8455. this.ServeSuccessJSON(map[string]interface{}{
  8456. "list": list,
  8457. "total": total,
  8458. })
  8459. } else {
  8460. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8461. this.ServeSuccessJSON(map[string]interface{}{
  8462. "list": list,
  8463. "total": total,
  8464. })
  8465. }
  8466. }
  8467. func (c *HisApiController) PostProjectInformation() {
  8468. adminUser := c.GetAdminUserInfo()
  8469. orgId := adminUser.CurrentOrgId
  8470. dataBody := make(map[string]interface{}, 0)
  8471. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8472. if err != nil {
  8473. utils.ErrorLog(err.Error())
  8474. return
  8475. }
  8476. utils.ErrorLog("%v", dataBody)
  8477. var projectList []*models.HisProject
  8478. var total_goods []interface{}
  8479. tempProjects := dataBody["projects"].([]interface{})
  8480. total_goods = tempProjects
  8481. for index, projectMap := range tempProjects {
  8482. projectM := projectMap.(map[string]interface{})
  8483. var project models.HisProject
  8484. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8485. utils.ErrorLog("project_name")
  8486. return
  8487. }
  8488. project_name, _ := projectM["project_name"].(string)
  8489. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8490. err_log := models.ExportErrLog{
  8491. LogType: 6,
  8492. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8493. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8494. Status: 1,
  8495. CreateTime: time.Now().Unix(),
  8496. UpdateTime: time.Now().Unix(),
  8497. ExportTime: time.Now().Unix(),
  8498. }
  8499. service.CreateExportErrLog(&err_log)
  8500. continue
  8501. }
  8502. project.ProjectName = project_name
  8503. prices := projectM["price"].(string)
  8504. price, _ := strconv.ParseFloat(prices, 64)
  8505. if price <= 0 { //名字为空则生成一条导入错误日志
  8506. err_log := models.ExportErrLog{
  8507. LogType: 6,
  8508. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8509. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8510. Status: 1,
  8511. CreateTime: time.Now().Unix(),
  8512. UpdateTime: time.Now().Unix(),
  8513. ExportTime: time.Now().Unix(),
  8514. }
  8515. service.CreateExportErrLog(&err_log)
  8516. continue
  8517. }
  8518. project.Price = price
  8519. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8520. utils.ErrorLog("unit_id")
  8521. return
  8522. }
  8523. unit := projectM["unit"].(string)
  8524. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8525. err_log := models.ExportErrLog{
  8526. LogType: 6,
  8527. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8528. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8529. Status: 1,
  8530. CreateTime: time.Now().Unix(),
  8531. UpdateTime: time.Now().Unix(),
  8532. ExportTime: time.Now().Unix(),
  8533. }
  8534. service.CreateExportErrLog(&err_log)
  8535. continue
  8536. }
  8537. project.Unit = unit
  8538. cost_classify := projectM["cost_classify"].(string)
  8539. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8540. err_log := models.ExportErrLog{
  8541. LogType: 6,
  8542. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8543. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8544. Status: 1,
  8545. CreateTime: time.Now().Unix(),
  8546. UpdateTime: time.Now().Unix(),
  8547. ExportTime: time.Now().Unix(),
  8548. }
  8549. service.CreateExportErrLog(&err_log)
  8550. continue
  8551. }
  8552. var costClassify = "费用类别"
  8553. var cost_classify_id int64
  8554. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8555. if len(cost_classify) != 0 {
  8556. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8557. if errcode == gorm.ErrRecordNotFound {
  8558. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8559. dataconfig := models.DictDataconfig{
  8560. ParentId: costClassifyConfig.ID,
  8561. Module: "system",
  8562. OrgId: orgId,
  8563. Name: cost_classify,
  8564. FieldName: "",
  8565. Value: costConfig.Value + 1,
  8566. CreatedTime: "",
  8567. UpdatedTime: "",
  8568. CreateUserId: adminUser.AdminUser.Id,
  8569. Status: 1,
  8570. Remark: "",
  8571. DeleteIdSystem: 0,
  8572. Title: "",
  8573. Content: "",
  8574. Order: 0,
  8575. Code: "",
  8576. }
  8577. service.CreatedDicConfig(&dataconfig)
  8578. }
  8579. }
  8580. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8581. for _, it := range costClassList {
  8582. if cost_classify == it.Name {
  8583. cost_classify_id = int64(it.Value)
  8584. }
  8585. }
  8586. project.CostClassify = cost_classify_id
  8587. executive_section := projectM["executive_section"].(string)
  8588. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8589. err_log := models.ExportErrLog{
  8590. LogType: 6,
  8591. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8592. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8593. Status: 1,
  8594. CreateTime: time.Now().Unix(),
  8595. UpdateTime: time.Now().Unix(),
  8596. ExportTime: time.Now().Unix(),
  8597. }
  8598. service.CreateExportErrLog(&err_log)
  8599. continue
  8600. }
  8601. if len(executive_section) != 0 {
  8602. //查找科室是否有内容
  8603. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8604. if errcodedepart == gorm.ErrRecordNotFound {
  8605. department := models.XtHisDepartment{
  8606. Name: executive_section,
  8607. Status: 1,
  8608. UserOrgId: adminUser.CurrentOrgId,
  8609. CreatedTime: time.Now().Unix(),
  8610. }
  8611. service.CreateDePartment(&department)
  8612. }
  8613. }
  8614. var executive_section_id int64
  8615. departMentList, _ := service.GetAllDepartMent(orgId)
  8616. for _, it := range departMentList {
  8617. if executive_section == it.Name {
  8618. executive_section_id = it.ID
  8619. }
  8620. }
  8621. project.ExecutiveSection = executive_section_id
  8622. medical_coverage := projectM["medical_coverage"].(string)
  8623. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8624. err_log := models.ExportErrLog{
  8625. LogType: 6,
  8626. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8627. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8628. Status: 1,
  8629. CreateTime: time.Now().Unix(),
  8630. UpdateTime: time.Now().Unix(),
  8631. ExportTime: time.Now().Unix(),
  8632. }
  8633. service.CreateExportErrLog(&err_log)
  8634. continue
  8635. }
  8636. var medicalCoverage = "医保等级"
  8637. var medical_coverage_id int64
  8638. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8639. if len(medical_coverage) != 0 {
  8640. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8641. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8642. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8643. dataconfig := models.DictDataconfig{
  8644. ParentId: medicalCoverageConfig.ID,
  8645. Module: "system",
  8646. OrgId: orgId,
  8647. Name: medical_coverage,
  8648. FieldName: "",
  8649. Value: medicalCoverageConfig.Value + 1,
  8650. CreatedTime: "",
  8651. UpdatedTime: "",
  8652. CreateUserId: adminUser.AdminUser.Id,
  8653. Status: 1,
  8654. Remark: "",
  8655. DeleteIdSystem: 0,
  8656. Title: "",
  8657. Content: "",
  8658. Order: 0,
  8659. Code: "",
  8660. }
  8661. service.CreatedDicConfig(&dataconfig)
  8662. }
  8663. }
  8664. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8665. for _, it := range medicalCoverageList {
  8666. if medical_coverage == it.Name {
  8667. medical_coverage_id = int64(it.Value)
  8668. }
  8669. }
  8670. project.MedicalCoverage = medical_coverage_id
  8671. pinyin := projectM["pinyin"].(string)
  8672. project.Pinyin = pinyin
  8673. wubi := projectM["wubi"].(string)
  8674. project.Wubi = wubi
  8675. statistical_classification := projectM["statistical_classification"].(string)
  8676. var statisticalClassification = "统计分类"
  8677. var statistical_classification_id int64
  8678. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8679. if len(statistical_classification) != 0 {
  8680. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8681. if classificationerrcodes == gorm.ErrRecordNotFound {
  8682. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8683. dataconfig := models.DictDataconfig{
  8684. ParentId: classiFication.ID,
  8685. Module: "system",
  8686. OrgId: orgId,
  8687. Name: statistical_classification,
  8688. FieldName: "",
  8689. Value: classiFicationConfig.Value + 1,
  8690. CreatedTime: "",
  8691. UpdatedTime: "",
  8692. CreateUserId: adminUser.AdminUser.Id,
  8693. Status: 1,
  8694. Remark: "",
  8695. DeleteIdSystem: 0,
  8696. Title: "",
  8697. Content: "",
  8698. Order: 0,
  8699. Code: "",
  8700. }
  8701. service.CreatedDicConfig(&dataconfig)
  8702. }
  8703. }
  8704. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8705. for _, it := range classiFicationList {
  8706. if statistical_classification == it.Name {
  8707. statistical_classification_id = int64(it.Value)
  8708. }
  8709. }
  8710. project.StatisticalClassification = statistical_classification_id
  8711. disease_directory := int64(projectM["disease_directory"].(float64))
  8712. project.DiseaseDirectory = disease_directory
  8713. is_record := int64(projectM["is_record"].(float64))
  8714. project.IsRecord = is_record
  8715. medical_code := projectM["medical_code"].(string)
  8716. project.MedicalCode = medical_code
  8717. tube_color := projectM["tube_color"].(string)
  8718. var tubeColor = "试管颜色"
  8719. var tube_color_id int64
  8720. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8721. if len(tube_color) != 0 {
  8722. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8723. if errcodetube == gorm.ErrRecordNotFound {
  8724. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8725. dataconfig := models.DictDataconfig{
  8726. ParentId: tubeColorConfig.ID,
  8727. Module: "system",
  8728. OrgId: orgId,
  8729. Name: tube_color,
  8730. FieldName: "",
  8731. Value: tubeConfig.Value + 1,
  8732. CreatedTime: "",
  8733. UpdatedTime: "",
  8734. CreateUserId: adminUser.AdminUser.Id,
  8735. Status: 1,
  8736. Remark: "",
  8737. DeleteIdSystem: 0,
  8738. Title: "",
  8739. Content: "",
  8740. Order: 0,
  8741. Code: "",
  8742. }
  8743. service.CreatedDicConfig(&dataconfig)
  8744. }
  8745. }
  8746. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8747. for _, it := range tubeColorList {
  8748. if tube_color == it.Name {
  8749. tube_color_id = int64(it.Value)
  8750. }
  8751. }
  8752. project.TubeColor = tube_color_id
  8753. single_dose := projectM["single_dose"].(string)
  8754. project.SingleDose = single_dose
  8755. execution_frequency := projectM["execution_frequency"].(string)
  8756. project.ExecutionFrequency = execution_frequency
  8757. delivery_way := projectM["delivery_way"].(string)
  8758. project.DeliveryWay = delivery_way
  8759. number_days := projectM["number_days"].(string)
  8760. project.NumberDays = number_days
  8761. total := projectM["total"].(string)
  8762. project.Total = total
  8763. medical_status := int64(projectM["medical_status"].(float64))
  8764. project.MedicalStatus = medical_status
  8765. category := int64(projectM["category"].(float64))
  8766. project.Category = category
  8767. specail_project := int64(projectM["specail_project"].(float64))
  8768. project.SpecailProject = specail_project
  8769. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8770. project.SocialSecurityDirectoryCode = social_security_directory_code
  8771. remark := projectM["remark"].(string)
  8772. project.Remark = remark
  8773. record_date := projectM["record_date"].(string)
  8774. timeLayout := "2006-01-02"
  8775. loc, _ := time.LoadLocation("Local")
  8776. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8777. project.RecordDate = theTime.Unix()
  8778. projectList = append(projectList, &project)
  8779. }
  8780. export_time := time.Now().Unix()
  8781. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8782. if len(projectList) > 0 {
  8783. for _, item := range projectList {
  8784. project := models.HisProject{
  8785. ProjectName: item.ProjectName,
  8786. Price: item.Price,
  8787. Unit: item.Unit,
  8788. CostClassify: item.CostClassify,
  8789. ExecutiveSection: item.ExecutiveSection,
  8790. MedicalCoverage: item.MedicalCoverage,
  8791. UserOrgId: orgId,
  8792. Status: 1,
  8793. CreatedTime: time.Now().Unix(),
  8794. Pinyin: item.Pinyin,
  8795. Wubi: item.Wubi,
  8796. StatisticalClassification: item.StatisticalClassification,
  8797. DiseaseDirectory: item.DiseaseDirectory,
  8798. IsRecord: item.IsRecord,
  8799. MedicalCode: item.MedicalCode,
  8800. TubeColor: item.TubeColor,
  8801. SingleDose: item.SingleDose,
  8802. DeliveryWay: item.DeliveryWay,
  8803. NumberDays: item.NumberDays,
  8804. Total: item.Total,
  8805. Category: item.Category,
  8806. MedicalStatus: item.MedicalStatus,
  8807. SpecailProject: item.SpecailProject,
  8808. RecordDate: item.RecordDate,
  8809. Remark: item.Remark,
  8810. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8811. ExecutionFrequency: item.ExecutionFrequency,
  8812. }
  8813. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8814. if errcodeproject == gorm.ErrRecordNotFound {
  8815. service.CreateProjectInfomation(&project)
  8816. } else if errcodeproject == nil {
  8817. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8818. }
  8819. log := models.ExportLog{
  8820. LogType: 6,
  8821. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8822. TotalNum: int64(len(total_goods)),
  8823. FailNum: int64(len(errLogs)),
  8824. SuccessNum: int64(len(projectList)),
  8825. CreateTime: time.Now().Unix(),
  8826. UpdateTime: time.Now().Unix(),
  8827. ExportTime: export_time,
  8828. Status: 1,
  8829. }
  8830. service.CreateExportLog(&log)
  8831. c.ServeSuccessJSON(map[string]interface{}{
  8832. "msg": "导入成功",
  8833. "total_num": len(total_goods),
  8834. "success_num": len(projectList),
  8835. "fail_num": int64(len(errLogs)),
  8836. })
  8837. }
  8838. } else {
  8839. log := models.ExportLog{
  8840. LogType: 6,
  8841. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8842. TotalNum: int64(len(total_goods)),
  8843. FailNum: int64(len(errLogs)),
  8844. SuccessNum: int64(len(projectList)),
  8845. CreateTime: time.Now().Unix(),
  8846. UpdateTime: time.Now().Unix(),
  8847. ExportTime: export_time,
  8848. Status: 1,
  8849. }
  8850. service.CreateExportLog(&log)
  8851. c.ServeSuccessJSON(map[string]interface{}{
  8852. "msg": "导入成功",
  8853. "total_num": len(total_goods),
  8854. "success_num": len(projectList),
  8855. "fail_num": int64(len(errLogs)),
  8856. })
  8857. }
  8858. }
  8859. //func (this *HisApiController) EditProjectInformation(){
  8860. //
  8861. // id, _ := this.GetInt64("id")
  8862. // project_team := this.GetString("project_team")
  8863. // price := this.GetString("price")
  8864. // price_float, _ := strconv.ParseFloat(price, 64)
  8865. // pinyin := this.GetString("pinyin")
  8866. // wubi := this.GetString("wubi")
  8867. // tube_color, _ := this.GetInt64("tube_color")
  8868. // team_type, _ := this.GetInt64("team_type")
  8869. // remark := this.GetString("remark")
  8870. // ids := this.GetString("ids")
  8871. // item_id := this.GetString("item_id")
  8872. // projectTeam := models.XtHisProjectTeam{
  8873. // ProjectTeam: project_team,
  8874. // Price: price_float,
  8875. // Pinyin: pinyin,
  8876. // Wubi: wubi,
  8877. // TubeColor: tube_color,
  8878. // TeamType: team_type,
  8879. // Remark: remark,
  8880. // ProjectId: ids,
  8881. // ItemId: item_id,
  8882. // }
  8883. //
  8884. //
  8885. // dataBody := make(map[string]interface{}, 0)
  8886. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8887. // if err != nil {
  8888. // utils.ErrorLog(err.Error())
  8889. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8890. // return
  8891. // }
  8892. //
  8893. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8894. //
  8895. //
  8896. // if err != nil {
  8897. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8898. // return
  8899. // }
  8900. //
  8901. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8902. // infos, _ := dataBody["info"].([]interface{})
  8903. // if len(infos) > 0 {
  8904. // var ids []string
  8905. //
  8906. // for _, item := range infos {
  8907. // items := item.(map[string]interface{})
  8908. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8909. // utils.ErrorLog("id")
  8910. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8911. // return
  8912. // }
  8913. // id := int64(items["id"].(float64))
  8914. //
  8915. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8916. // utils.ErrorLog("type")
  8917. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8918. // return
  8919. // }
  8920. // types := int64(items["type"].(float64))
  8921. //
  8922. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8923. // utils.ErrorLog("number")
  8924. // }
  8925. //
  8926. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8927. //
  8928. // projectList := models.XtHisProjectList{
  8929. // Number: number,
  8930. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8931. // ProjectId: id,
  8932. // Status: 1,
  8933. // CreatedTime: time.Now().Unix(),
  8934. // UpdatedTime: time.Now().Unix(),
  8935. // TeamId: projectTeam.ID,
  8936. // Type: types,
  8937. // }
  8938. // list := projectList
  8939. //
  8940. // service.CreateProjectList(&list)
  8941. //
  8942. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8943. //
  8944. // }
  8945. // ids_str := strings.Join(ids, ",")
  8946. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8947. // service.SaveProjectTeam(&projectTeam)
  8948. // this.ServeSuccessJSON(map[string]interface{}{
  8949. // "projectTeam": projectTeam,
  8950. // })
  8951. // }
  8952. // }
  8953. //}
  8954. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8955. name := c.GetString("name")
  8956. mode_id, _ := c.GetInt64("mode", 0)
  8957. types, _ := c.GetInt64("type", 0)
  8958. patient_id, _ := c.GetInt64("patient_id", 0)
  8959. types = 1
  8960. adminInfo := c.GetAdminUserInfo()
  8961. template := &models.HisPrescriptionTemplate{
  8962. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8963. PatientId: patient_id,
  8964. Type: types,
  8965. Status: 1,
  8966. Ctime: time.Now().Unix(),
  8967. Mtime: time.Now().Unix(),
  8968. Name: name,
  8969. Mode: mode_id,
  8970. }
  8971. dataBody := make(map[string]interface{}, 0)
  8972. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8973. if err != nil {
  8974. utils.ErrorLog(err.Error())
  8975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8976. return
  8977. }
  8978. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8979. //如果已经存在记录则删除处方
  8980. if template_one.ID > 0 {
  8981. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8982. for _, item := range ps {
  8983. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8984. }
  8985. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8986. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8987. if len(prescriptions) > 0 {
  8988. for _, item := range prescriptions {
  8989. items := item.(map[string]interface{})
  8990. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8991. utils.ErrorLog("type")
  8992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8993. return
  8994. }
  8995. types := int64(items["type"].(float64))
  8996. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8997. utils.ErrorLog("med_type")
  8998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8999. return
  9000. }
  9001. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9002. ctime := time.Now().Unix()
  9003. prescription := &models.HisPrescriptionInfoTemplate{
  9004. PatientId: patient_id,
  9005. UserOrgId: adminInfo.CurrentOrgId,
  9006. Ctime: ctime,
  9007. Mtime: ctime,
  9008. Type: types,
  9009. Modifier: adminInfo.AdminUser.Id,
  9010. Creator: adminInfo.AdminUser.Id,
  9011. Status: 1,
  9012. PTemplateId: template_one.ID,
  9013. MedType: med_type,
  9014. }
  9015. service.CreateHisPrescriptionInfoTemplate(prescription)
  9016. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9017. advices := items["advices"].([]interface{})
  9018. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9019. ctime := time.Now().Unix()
  9020. mtime := ctime
  9021. if len(advices) > 0 {
  9022. for _, advice := range advices {
  9023. var s models.HisPrescriptionAdviceTemplate
  9024. s.PrescriptionId = prescription.ID
  9025. s.AdviceType = 2
  9026. s.StopState = 2
  9027. s.ExecutionState = 2
  9028. s.Status = 1
  9029. s.UserOrgId = adminInfo.CurrentOrgId
  9030. s.CreatedTime = ctime
  9031. s.UpdatedTime = mtime
  9032. s.PatientId = patient_id
  9033. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9034. if errcode > 0 {
  9035. c.ServeFailJSONWithSGJErrorCode(errcode)
  9036. return
  9037. }
  9038. service.CreateHisPrescriptionAdviceTemplate(&s)
  9039. }
  9040. }
  9041. }
  9042. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9043. projects := items["project"].([]interface{})
  9044. if len(projects) > 0 {
  9045. for _, project := range projects {
  9046. var p models.HisPrescriptionProjectTemplate
  9047. p.PrescriptionId = prescription.ID
  9048. p.Ctime = time.Now().Unix()
  9049. p.Mtime = time.Now().Unix()
  9050. p.PatientId = patient_id
  9051. p.UserOrgId = adminInfo.CurrentOrgId
  9052. p.Status = 1
  9053. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9054. if errcode > 0 {
  9055. c.ServeFailJSONWithSGJErrorCode(errcode)
  9056. return
  9057. }
  9058. service.CreateHisPrescriptionProjectTemplate(&p)
  9059. }
  9060. }
  9061. }
  9062. }
  9063. c.ServeSuccessJSON(map[string]interface{}{
  9064. "msg": "创建成功",
  9065. })
  9066. }
  9067. }
  9068. } else {
  9069. err = service.CreateHisPrescriptionTemplate(template)
  9070. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9071. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9072. if len(prescriptions) > 0 {
  9073. for _, item := range prescriptions {
  9074. items := item.(map[string]interface{})
  9075. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9076. utils.ErrorLog("type")
  9077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9078. return
  9079. }
  9080. types := int64(items["type"].(float64))
  9081. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9082. utils.ErrorLog("med_type")
  9083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9084. return
  9085. }
  9086. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9087. ctime := time.Now().Unix()
  9088. prescription := &models.HisPrescriptionInfoTemplate{
  9089. PatientId: patient_id,
  9090. UserOrgId: adminInfo.CurrentOrgId,
  9091. Ctime: ctime,
  9092. Mtime: ctime,
  9093. Type: types,
  9094. Modifier: adminInfo.AdminUser.Id,
  9095. Creator: adminInfo.AdminUser.Id,
  9096. Status: 1,
  9097. PTemplateId: template.ID,
  9098. MedType: med_type,
  9099. }
  9100. service.CreateHisPrescriptionInfoTemplate(prescription)
  9101. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9102. advices := items["advices"].([]interface{})
  9103. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9104. ctime := time.Now().Unix()
  9105. mtime := ctime
  9106. if len(advices) > 0 {
  9107. for _, advice := range advices {
  9108. var s models.HisPrescriptionAdviceTemplate
  9109. s.PrescriptionId = prescription.ID
  9110. s.AdviceType = 2
  9111. s.StopState = 2
  9112. s.ExecutionState = 2
  9113. s.Status = 1
  9114. s.UserOrgId = adminInfo.CurrentOrgId
  9115. s.CreatedTime = ctime
  9116. s.UpdatedTime = mtime
  9117. s.PatientId = patient_id
  9118. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9119. if errcode > 0 {
  9120. c.ServeFailJSONWithSGJErrorCode(errcode)
  9121. return
  9122. }
  9123. service.CreateHisPrescriptionAdviceTemplate(&s)
  9124. }
  9125. }
  9126. }
  9127. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9128. projects := items["project"].([]interface{})
  9129. if len(projects) > 0 {
  9130. for _, project := range projects {
  9131. var p models.HisPrescriptionProjectTemplate
  9132. p.PrescriptionId = prescription.ID
  9133. p.Ctime = time.Now().Unix()
  9134. p.Mtime = time.Now().Unix()
  9135. p.PatientId = patient_id
  9136. p.UserOrgId = adminInfo.CurrentOrgId
  9137. p.Status = 1
  9138. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9139. if errcode > 0 {
  9140. c.ServeFailJSONWithSGJErrorCode(errcode)
  9141. return
  9142. }
  9143. service.CreateHisPrescriptionProjectTemplate(&p)
  9144. }
  9145. }
  9146. }
  9147. }
  9148. c.ServeSuccessJSON(map[string]interface{}{
  9149. "msg": "创建成功",
  9150. })
  9151. }
  9152. }
  9153. }
  9154. }
  9155. func (c *HisApiController) PreSettle() {
  9156. id, _ := c.GetInt64("id")
  9157. record_time := c.GetString("record_time")
  9158. his_patient_id, _ := c.GetInt64("his_patient_id")
  9159. timeLayout := "2006-01-02"
  9160. loc, _ := time.LoadLocation("Local")
  9161. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9162. diagnosis_id := c.GetString("diagnosis")
  9163. sick_type, _ := c.GetInt64("sick_type")
  9164. reg_type, _ := c.GetInt64("p_type")
  9165. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9166. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9167. if err != nil {
  9168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9169. return
  9170. }
  9171. recordDateTime := theTime.Unix()
  9172. adminUser := c.GetAdminUserInfo()
  9173. var prescriptions []*models.HisPrescription
  9174. var start_time int64
  9175. var end_time int64
  9176. ids_str := c.GetString("ids")
  9177. ids_arr := strings.Split(ids_str, ",")
  9178. fmt.Println(reg_type)
  9179. if settle_accounts_type == 1 { //日结
  9180. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9181. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9182. } else {
  9183. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9184. }
  9185. fmt.Println(prescriptions)
  9186. } else { //月结
  9187. start_time_str := c.GetString("start_time")
  9188. end_time_str := c.GetString("end_time")
  9189. timeLayout := "2006-01-02"
  9190. loc, _ := time.LoadLocation("Local")
  9191. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9192. if err != nil {
  9193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9194. return
  9195. }
  9196. recordStartTime := theStartTime.Unix()
  9197. start_time = recordStartTime
  9198. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9199. if err != nil {
  9200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9201. return
  9202. }
  9203. recordEndTime := theEndTime.Unix()
  9204. end_time = recordEndTime
  9205. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9206. }
  9207. if reg_type == 1111 || reg_type == 1112 {
  9208. reg_type = 11
  9209. }
  9210. timestamp := time.Now().Unix()
  9211. tempTime := time.Unix(timestamp, 0)
  9212. timeFormat := tempTime.Format("20060102150405")
  9213. chrgBchno := rand.Intn(100000) + 10000
  9214. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9215. strconv.FormatInt(his.PatientId, 10)
  9216. var ids []int64
  9217. for _, item := range prescriptions {
  9218. ids = append(ids, item.ID)
  9219. }
  9220. fmt.Println(ids)
  9221. var total float64
  9222. for _, item := range prescriptions {
  9223. fmt.Println(item)
  9224. if item.Type == 1 { //药品
  9225. for _, subItem := range item.HisDoctorAdviceInfo {
  9226. total = total + (subItem.Price * subItem.PrescribingNumber)
  9227. }
  9228. }
  9229. if item.Type == 2 { //项目
  9230. for _, subItem := range item.HisPrescriptionProject {
  9231. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9232. total = total + (subItem.Price * cnt)
  9233. }
  9234. }
  9235. for _, subItem := range item.HisAdditionalCharge {
  9236. total = total + (subItem.Price * float64(subItem.Count))
  9237. }
  9238. }
  9239. allTotal := fmt.Sprintf("%.2f", total)
  9240. totals, _ := strconv.ParseFloat(allTotal, 64)
  9241. order := &models.HisOrder{
  9242. UserOrgId: adminUser.CurrentOrgId,
  9243. HisPatientId: his.ID,
  9244. PatientId: id,
  9245. SettleAccountsDate: recordDateTime,
  9246. Ctime: time.Now().Unix(),
  9247. Mtime: time.Now().Unix(),
  9248. Status: 1,
  9249. OrderStatus: 1,
  9250. MdtrtId: his.Number,
  9251. Number: chrg_bchno,
  9252. MedfeeSumamt: totals,
  9253. SettleEndTime: end_time,
  9254. SettleStartTime: start_time,
  9255. SettleType: settle_accounts_type,
  9256. PsnPartAmt: totals,
  9257. PsnCashPay: totals,
  9258. PType: 2,
  9259. IsPre: 1,
  9260. MedType: strconv.Itoa(int(reg_type)),
  9261. Diagnosis: diagnosis_id,
  9262. }
  9263. err = service.CreateOrder(order)
  9264. if err != nil {
  9265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9266. return
  9267. }
  9268. var customs []*Custom
  9269. for _, item := range prescriptions {
  9270. fmt.Println(item.Type)
  9271. if item.Type == 1 { //药品
  9272. for _, subItem := range item.HisDoctorAdviceInfo {
  9273. cus := &Custom{
  9274. AdviceId: subItem.ID,
  9275. ProjectId: 0,
  9276. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9277. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9278. FeedetlSn: subItem.FeedetlSn,
  9279. Price: fmt.Sprintf("%.2f", subItem.Price),
  9280. MedListCodg: subItem.MedListCodg,
  9281. Type: 1,
  9282. }
  9283. customs = append(customs, cus)
  9284. }
  9285. }
  9286. if item.Type == 2 { //项目
  9287. for _, subItem := range item.HisPrescriptionProject {
  9288. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9289. cus := &Custom{
  9290. AdviceId: 0,
  9291. ProjectId: subItem.ID,
  9292. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9293. Cut: fmt.Sprintf("%.2f", cnt),
  9294. FeedetlSn: subItem.FeedetlSn,
  9295. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9296. MedListCodg: subItem.MedListCodg,
  9297. Type: 2,
  9298. }
  9299. customs = append(customs, cus)
  9300. }
  9301. }
  9302. for _, item := range item.HisAdditionalCharge {
  9303. cus := &Custom{
  9304. ItemId: item.ID,
  9305. AdviceId: 0,
  9306. ProjectId: 0,
  9307. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9308. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9309. FeedetlSn: item.FeedetlSn,
  9310. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9311. MedListCodg: item.XtHisAddtionConfig.Code,
  9312. Type: 3,
  9313. }
  9314. customs = append(customs, cus)
  9315. }
  9316. }
  9317. fmt.Println(customs)
  9318. for _, item := range customs {
  9319. var advice_id int64 = 0
  9320. var project_id int64 = 0
  9321. var item_id int64 = 0
  9322. var types int64 = 0
  9323. if item.Type == 1 {
  9324. advice_id = item.AdviceId
  9325. project_id = 0
  9326. item_id = 0
  9327. } else if item.Type == 2 {
  9328. advice_id = 0
  9329. item_id = 0
  9330. project_id = item.ProjectId
  9331. } else if item.Type == 3 {
  9332. advice_id = 0
  9333. item_id = item.ItemId
  9334. project_id = 0
  9335. }
  9336. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9337. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9338. pric, _ := strconv.ParseFloat(item.Price, 32)
  9339. info := &models.HisOrderInfo{
  9340. OrderNumber: order.Number,
  9341. UploadDate: time.Now().Unix(),
  9342. AdviceId: advice_id,
  9343. DetItemFeeSumamt: detItemFeeSumamt,
  9344. Cnt: cut,
  9345. Pric: pric,
  9346. PatientId: id,
  9347. Status: 1,
  9348. Mtime: time.Now().Unix(),
  9349. Ctime: time.Now().Unix(),
  9350. UserOrgId: adminUser.CurrentOrgId,
  9351. HisPatientId: his.ID,
  9352. OrderId: order.ID,
  9353. ProjectId: project_id,
  9354. Type: types,
  9355. ItemId: item_id,
  9356. }
  9357. service.CreateOrderInfo(info)
  9358. }
  9359. his.SickType = sick_type
  9360. service.UpdataHisPateint(&his)
  9361. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9362. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9363. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9364. if err == nil {
  9365. c.ServeSuccessJSON(map[string]interface{}{
  9366. "msg": "结算成功",
  9367. })
  9368. }
  9369. }
  9370. type CustomOrderInfo struct {
  9371. Name string
  9372. Spec string
  9373. Unit string
  9374. Count float64
  9375. Price float64
  9376. Total float64
  9377. }
  9378. func (c *HisApiController) GetPrivateExpensesInfo() {
  9379. order_id, _ := c.GetInt64("id", 0)
  9380. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9381. order, _ := service.GetHisOrderByID(order_id)
  9382. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9383. if order.ID == 0 {
  9384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9385. return
  9386. }
  9387. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9388. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9389. org_id := c.GetAdminUserInfo().CurrentOrgId
  9390. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9391. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9392. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9393. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9394. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9395. //var orderInfos_four []*models.HisOrderInfoTwo
  9396. //for _, item := range orderInfos_three {
  9397. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9398. // item.HisPrescriptionProject.IsCheckTeam = 1
  9399. // orderInfos_four = append(orderInfos_four, item)
  9400. //
  9401. // }
  9402. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9403. // item.HisPrescriptionProject.IsCheckTeam = 2
  9404. // orderInfos_two = append(orderInfos_two, item)
  9405. // }
  9406. //}
  9407. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9408. //var cus_slice []CustomOrderInfo
  9409. //for _, item := range new_order_info {
  9410. // var cus CustomOrderInfo
  9411. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9412. // cus.Unit = ""
  9413. // cus.Spec = ""
  9414. // var total float64
  9415. // for _, subItem := range orderInfos_four {
  9416. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9417. // total = total + subItem.DetItemFeeSumamt
  9418. // fmt.Println(subItem.DetItemFeeSumamt)
  9419. // }
  9420. // }
  9421. // cus.Count = 1
  9422. // cus.Total = total
  9423. // cus_slice = append(cus_slice, cus)
  9424. //}
  9425. orderInfos = append(orderInfos, orderInfos_two...)
  9426. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9427. //orderInfos = append(orderInfos, orderInfos_three...)
  9428. //}/**/
  9429. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9430. c.ServeSuccessJSON(map[string]interface{}{
  9431. "order": order,
  9432. "order_info": orderInfos,
  9433. "patient": patient,
  9434. "admin_info": adminInfo,
  9435. "his": his,
  9436. "current_admin": role,
  9437. "org_config": miConfig,
  9438. //"new_order_info": cus_slice,
  9439. })
  9440. }
  9441. func (this *HisApiController) ChangeMedType() {
  9442. med_type := this.GetString("med_type")
  9443. old_med_type := this.GetString("old_med_type")
  9444. ids := this.GetString("ids")
  9445. settle_type, _ := this.GetInt64("settle_type")
  9446. start_time := this.GetString("start_time")
  9447. end_time := this.GetString("end_time")
  9448. ids_arr := strings.Split(ids, ",")
  9449. if settle_type == 1 { //日结
  9450. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9451. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9452. prescription.MedType = med_type
  9453. err := service.SaveHisPrescription(&prescription)
  9454. if err == nil {
  9455. this.ServeSuccessJSON(map[string]interface{}{
  9456. "msg": "修改成功",
  9457. })
  9458. } else {
  9459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9460. return
  9461. }
  9462. } else if settle_type == 2 {
  9463. timeLayout := "2006-01-02"
  9464. loc, _ := time.LoadLocation("Local")
  9465. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9466. if err != nil {
  9467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9468. return
  9469. }
  9470. recordStartTime := theStartTime.Unix()
  9471. start_time_timestamp := recordStartTime
  9472. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9473. if err != nil {
  9474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9475. return
  9476. }
  9477. recordEndTime := theEndTime.Unix()
  9478. end_time_timestamp := recordEndTime
  9479. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9480. if updateErr == nil {
  9481. this.ServeSuccessJSON(map[string]interface{}{
  9482. "msg": "修改成功",
  9483. })
  9484. } else {
  9485. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9486. return
  9487. }
  9488. }
  9489. }
  9490. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9491. patient_id, _ := c.GetInt64("patient_id")
  9492. his_patient_id, _ := c.GetInt64("his_patient_id")
  9493. record_date := c.GetString("record_date")
  9494. start_time := c.GetString("start_time")
  9495. end_time := c.GetString("end_time")
  9496. order_status, _ := c.GetInt64("type", 0)
  9497. p_type, _ := c.GetInt64("p_type", 0)
  9498. order_id, _ := c.GetInt64("order_id", 0)
  9499. timeLayout := "2006-01-02"
  9500. loc, _ := time.LoadLocation("Local")
  9501. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9502. if err != nil {
  9503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9504. return
  9505. }
  9506. recordDateTime := theTime.Unix()
  9507. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9508. if err != nil {
  9509. }
  9510. startRecordDateTime := startTime.Unix()
  9511. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9512. if err != nil {
  9513. }
  9514. endRecordDateTime := endTime.Unix()
  9515. admin := c.GetAdminUserInfo()
  9516. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9517. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9518. order, _ := service.GetHisOrderByID(order_id)
  9519. var monthPrescriptions []*models.HisPrescription
  9520. if order_status == 1 || order_status == 0 {
  9521. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9522. } else if order_status == 2 {
  9523. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9524. }
  9525. var settle_total float64
  9526. for _, item := range monthPrescriptions {
  9527. if len(item.HisPrescriptionProject) > 0 {
  9528. for _, subItem := range item.HisPrescriptionProject {
  9529. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9530. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9531. settle_total = settle_total + total
  9532. }
  9533. }
  9534. if len(item.HisDoctorAdviceInfo) > 0 {
  9535. for _, subItem := range item.HisDoctorAdviceInfo {
  9536. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9537. settle_total = settle_total + total
  9538. }
  9539. }
  9540. }
  9541. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9542. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9543. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9544. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9545. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9546. //获取所有科室信息
  9547. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9548. c.ServeSuccessJSON(map[string]interface{}{
  9549. "his_info": his_patient_info,
  9550. "xt_info": xt_patient_info,
  9551. "case_history": case_history,
  9552. "info": patientPrescriptionInfo,
  9553. "last_info": lastPatientPrescriptionInfo,
  9554. "month_prescriptions": monthPrescriptions,
  9555. "order": order,
  9556. "doctors": doctors,
  9557. "department": department,
  9558. "settle_total": settle_total,
  9559. })
  9560. return
  9561. }
  9562. func (c *HisApiController) GetHisMonthPatientInfo() {
  9563. patient_id, _ := c.GetInt64("patient_id")
  9564. his_patient_id, _ := c.GetInt64("his_patient_id")
  9565. record_date := c.GetString("record_date")
  9566. number := c.GetString("number")
  9567. start_time := c.GetString("start_time")
  9568. end_time := c.GetString("end_time")
  9569. p_type, _ := c.GetInt64("p_type")
  9570. timeLayout := "2006-01-02"
  9571. loc, _ := time.LoadLocation("Local")
  9572. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9573. if err != nil {
  9574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9575. return
  9576. }
  9577. recordDateTime := theTime.Unix()
  9578. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9579. if err != nil {
  9580. }
  9581. startRecordDateTime := startTime.Unix()
  9582. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9583. if err != nil {
  9584. }
  9585. endRecordDateTime := endTime.Unix()
  9586. admin := c.GetAdminUserInfo()
  9587. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9588. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9589. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9590. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9591. var settle_total float64
  9592. for _, item := range monthPrescriptions {
  9593. if len(item.HisPrescriptionProject) > 0 {
  9594. for _, subItem := range item.HisPrescriptionProject {
  9595. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9596. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9597. settle_total = settle_total + total
  9598. }
  9599. }
  9600. if len(item.HisDoctorAdviceInfo) > 0 {
  9601. for _, subItem := range item.HisDoctorAdviceInfo {
  9602. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9603. settle_total = settle_total + total
  9604. }
  9605. }
  9606. }
  9607. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9608. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9609. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9610. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9611. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9612. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9613. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9614. //获取所有科室信息
  9615. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9616. c.ServeSuccessJSON(map[string]interface{}{
  9617. "his_info": his_patient_info,
  9618. "xt_info": xt_patient_info,
  9619. "case_history": case_history,
  9620. "info": patientPrescriptionInfo,
  9621. "month_prescriptions": monthPrescriptions,
  9622. "order": order,
  9623. "doctors": doctors,
  9624. "department": department,
  9625. "count": count,
  9626. "drugStockConfig": drugStockConfig,
  9627. "last_info": lastPatientPrescriptionInfo,
  9628. "settle_total": settle_total,
  9629. })
  9630. return
  9631. }
  9632. func (c *HisApiController) GetAllOrder() {
  9633. org_id := c.GetAdminUserInfo().CurrentOrgId
  9634. orders, _ := service.GetNewHisOrderList(org_id)
  9635. c.ServeSuccessJSON(map[string]interface{}{
  9636. "order": orders,
  9637. })
  9638. return
  9639. }
  9640. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9641. newArr = make([]*models.HisOrderInfoTwo, 0)
  9642. for i := 0; i < len(arr); i++ {
  9643. repeat := false
  9644. for j := i + 1; j < len(arr); j++ {
  9645. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9646. repeat = true
  9647. break
  9648. }
  9649. }
  9650. if !repeat {
  9651. newArr = append(newArr, arr[i])
  9652. }
  9653. }
  9654. return
  9655. }
  9656. // 修改处方退库操作 参数传修改之前的处方数据
  9657. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9658. if advice.ExecutionState == 1 {
  9659. //查询该病人该药品是否有库存记录
  9660. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9661. if errcode == gorm.ErrRecordNotFound {
  9662. } else {
  9663. //退库
  9664. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9665. if advice.PrescribingNumberUnit == drug.MinUnit {
  9666. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9667. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9668. //退库
  9669. warehouseInfo := models.DrugWarehouseInfo{
  9670. StockMinNumber: prescribingNumber,
  9671. }
  9672. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9673. operation_time := time.Now().Unix()
  9674. creater := advice.AdviceDoctor
  9675. ctime := time.Now().Unix()
  9676. timeStr := time.Now().Format("2006-01-02")
  9677. timeArr := strings.Split(timeStr, "-")
  9678. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9679. total = total + 1
  9680. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9681. cancelStock := models.DrugCancelStock{
  9682. OrderNumber: orderNumber,
  9683. OperaTime: operation_time,
  9684. OrgId: advice.UserOrgId,
  9685. Creater: creater,
  9686. Ctime: ctime,
  9687. Status: 1,
  9688. ReturnTime: advice.AdviceDate,
  9689. Dealer: info.Dealer,
  9690. Manufacturer: info.Manufacturer,
  9691. Type: 1,
  9692. }
  9693. service.AddSigleDrugCancelStock(&cancelStock)
  9694. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9695. dealer, _ := service.GetDealerById(info.Dealer)
  9696. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9697. cancelStockInfo := models.DrugCancelStockInfo{
  9698. OrderNumber: cancelInfo.OrderNumber,
  9699. CancelStockId: cancelInfo.ID,
  9700. DrugId: info.DrugId,
  9701. Count: info.Count,
  9702. Status: 1,
  9703. Ctime: ctime,
  9704. OrgId: advice.UserOrgId,
  9705. Type: 1,
  9706. Manufacturer: manufactureName.ManufacturerName,
  9707. Dealer: dealer.DealerName,
  9708. Total: 0,
  9709. RetailPrice: info.RetailPrice,
  9710. RetailTotalPrice: info.RetailTotalPrice,
  9711. Price: info.Price,
  9712. RegisterAccount: "",
  9713. Remark: info.Remark,
  9714. BatchNumber: info.BatchNumber,
  9715. MaxUnit: info.CountUnit,
  9716. ProductDate: info.ProductDate,
  9717. ExpiryDate: info.ExpiryDate,
  9718. BatchNumberId: info.WarehouseInfoId,
  9719. }
  9720. flow := models.DrugFlow{
  9721. WarehousingId: 0,
  9722. DrugId: info.DrugId,
  9723. Number: "",
  9724. BatchNumber: info.BatchNumber,
  9725. Count: info.Count,
  9726. UserOrgId: advice.UserOrgId,
  9727. PatientId: 0,
  9728. SystemTime: ctime,
  9729. ConsumableType: 4,
  9730. IsSys: 0,
  9731. WarehousingOrder: "",
  9732. WarehouseOutId: 0,
  9733. WarehouseOutOrderNumber: "",
  9734. IsEdit: 0,
  9735. CancelStockId: cancelStock.ID,
  9736. CancelOrderNumber: cancelStock.OrderNumber,
  9737. Manufacturer: info.Manufacturer,
  9738. Dealer: info.Dealer,
  9739. Creator: advice.UserOrgId,
  9740. UpdateCreator: 0,
  9741. Status: 1,
  9742. Ctime: time.Now().Unix(),
  9743. Mtime: 0,
  9744. Price: info.Price,
  9745. WarehousingDetailId: 0,
  9746. WarehouseOutDetailId: 0,
  9747. CancelOutDetailId: 0,
  9748. ExpireDate: info.ExpiryDate,
  9749. ProductDate: info.ProductDate,
  9750. MaxUnit: info.CountUnit,
  9751. MinUnit: "",
  9752. }
  9753. service.CreatedCancelStock(cancelStockInfo)
  9754. service.CreateDrugFlowOne(flow)
  9755. } else {
  9756. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9757. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9758. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9759. warehouseInfo := models.DrugWarehouseInfo{
  9760. StockMinNumber: prescribingNumber,
  9761. }
  9762. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9763. }
  9764. operation_time := time.Now().Unix()
  9765. creater := advice.AdviceDoctor
  9766. ctime := time.Now().Unix()
  9767. timeStr := time.Now().Format("2006-01-02")
  9768. timeArr := strings.Split(timeStr, "-")
  9769. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9770. total = total + 1
  9771. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9772. cancelStock := models.DrugCancelStock{
  9773. OrderNumber: orderNumber,
  9774. OperaTime: operation_time,
  9775. OrgId: advice.UserOrgId,
  9776. Creater: creater,
  9777. Ctime: ctime,
  9778. Status: 1,
  9779. ReturnTime: advice.AdviceDate,
  9780. Dealer: info.Dealer,
  9781. Manufacturer: info.Manufacturer,
  9782. Type: 1,
  9783. }
  9784. service.AddSigleDrugCancelStock(&cancelStock)
  9785. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9786. dealer, _ := service.GetDealerById(info.Dealer)
  9787. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9788. cancelStockInfo := models.DrugCancelStockInfo{
  9789. OrderNumber: cancelInfo.OrderNumber,
  9790. CancelStockId: cancelInfo.ID,
  9791. DrugId: info.DrugId,
  9792. Count: info.Count,
  9793. Status: 1,
  9794. Ctime: ctime,
  9795. OrgId: advice.UserOrgId,
  9796. Type: 1,
  9797. Manufacturer: manufactureName.ManufacturerName,
  9798. Dealer: dealer.DealerName,
  9799. Total: 0,
  9800. RetailPrice: info.RetailPrice,
  9801. RetailTotalPrice: info.RetailTotalPrice,
  9802. Price: info.Price,
  9803. RegisterAccount: "",
  9804. Remark: info.Remark,
  9805. BatchNumber: info.BatchNumber,
  9806. MaxUnit: info.CountUnit,
  9807. ProductDate: info.ProductDate,
  9808. ExpiryDate: info.ExpiryDate,
  9809. BatchNumberId: info.WarehouseInfoId,
  9810. }
  9811. flow := models.DrugFlow{
  9812. WarehousingId: 0,
  9813. DrugId: info.DrugId,
  9814. Number: "",
  9815. BatchNumber: info.BatchNumber,
  9816. Count: info.Count,
  9817. UserOrgId: advice.UserOrgId,
  9818. PatientId: 0,
  9819. SystemTime: ctime,
  9820. ConsumableType: 4,
  9821. IsSys: 0,
  9822. WarehousingOrder: "",
  9823. WarehouseOutId: 0,
  9824. WarehouseOutOrderNumber: "",
  9825. IsEdit: 0,
  9826. CancelStockId: cancelStock.ID,
  9827. CancelOrderNumber: cancelStock.OrderNumber,
  9828. Manufacturer: info.Manufacturer,
  9829. Dealer: info.Dealer,
  9830. Creator: advice.AdviceDoctor,
  9831. UpdateCreator: 0,
  9832. Status: 1,
  9833. Ctime: time.Now().Unix(),
  9834. Mtime: 0,
  9835. Price: info.Price,
  9836. WarehousingDetailId: 0,
  9837. WarehouseOutDetailId: 0,
  9838. CancelOutDetailId: 0,
  9839. ExpireDate: info.ExpiryDate,
  9840. ProductDate: info.ProductDate,
  9841. MaxUnit: info.CountUnit,
  9842. MinUnit: "",
  9843. }
  9844. service.CreatedCancelStock(cancelStockInfo)
  9845. service.CreateDrugFlowOne(flow)
  9846. }
  9847. }
  9848. }
  9849. return err
  9850. }
  9851. func (this *HisApiController) DeleteNCDS() {
  9852. id, _ := this.GetInt64("id", 0)
  9853. if id > 0 {
  9854. service.DeletePsnNCDSRecordById(id)
  9855. this.ServeSuccessJSON(map[string]interface{}{
  9856. "msg": "删除成功",
  9857. })
  9858. } else {
  9859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9860. return
  9861. }
  9862. }
  9863. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9864. id, _ := c.GetInt64("id")
  9865. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9866. c.ServeSuccessJSON(map[string]interface{}{
  9867. "advice": advice,
  9868. })
  9869. return
  9870. }
  9871. func (c *HisApiController) GetHisMonthChargePatientList() {
  9872. record_date := c.GetString("record_date")
  9873. start_time := c.GetString("start_time")
  9874. end_time := c.GetString("end_time")
  9875. timeLayout := "2006-01-02"
  9876. loc, _ := time.LoadLocation("Local")
  9877. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9878. if err != nil {
  9879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9880. return
  9881. }
  9882. if err != nil {
  9883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9884. return
  9885. }
  9886. recordDateTime := theTime.Unix()
  9887. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9888. if err != nil {
  9889. }
  9890. startRecordDateTime := startTime.Unix()
  9891. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9892. if err != nil {
  9893. }
  9894. endRecordDateTime := endTime.Unix()
  9895. adminInfo := c.GetAdminUserInfo()
  9896. var tempMonthChargePatients []*service.MonthChargePatients
  9897. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9898. for _, item := range tempPatients {
  9899. //过滤没有处方的
  9900. if len(item.HisPrescription) == 0 {
  9901. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9902. }
  9903. }
  9904. c.ServeSuccessJSON(map[string]interface{}{
  9905. "list": tempMonthChargePatients,
  9906. })
  9907. }