his_api_controller.go 375KB

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