his_api_controller.go 440KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. }
  90. func (c *HisApiController) CheckHisPatient() {
  91. record_date := c.GetString("record_date")
  92. patient_id, _ := c.GetInt64("patient_id")
  93. timeLayout := "2006-01-02"
  94. loc, _ := time.LoadLocation("Local")
  95. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  96. if err != nil {
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. recordDateTime := theTime.Unix()
  101. adminInfo := c.GetAdminUserInfo()
  102. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  103. if len(patients) > 1 {
  104. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  105. if len(ps) > 0 {
  106. c.ServeSuccessJSON(map[string]interface{}{
  107. "status": 1,
  108. "msg": "关联",
  109. "ps": ps,
  110. "his_patient_id": patients[len(patients)-1].ID,
  111. "patient_id": patients[len(patients)-1].PatientId,
  112. })
  113. } else {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 0,
  116. "msg": "无需关联",
  117. })
  118. }
  119. } else {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 0,
  122. "msg": "无需关联",
  123. })
  124. return
  125. }
  126. }
  127. func (c *HisApiController) AssociationHisPrescription() {
  128. record_date := c.GetString("record_date")
  129. his_patient_id, _ := c.GetInt64("his_patient_id")
  130. patient_id, _ := c.GetInt64("patient_id")
  131. p_ids := c.GetString("p_ids")
  132. p_ids_arr := strings.Split(p_ids, ",")
  133. timeLayout := "2006-01-02"
  134. loc, _ := time.LoadLocation("Local")
  135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  136. if err != nil {
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. recordDateTime := theTime.Unix()
  141. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  142. if his_patient_id == 0 || his_patient.ID == 0 {
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  147. if err == nil {
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "msg": "关联处方成功",
  150. })
  151. return
  152. } else {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  154. return
  155. }
  156. }
  157. //func (c *HisApiController) AssociationHisPrescription() {
  158. // record_date, _ := c.GetInt64("record_date")
  159. // his_patient_id, _ := c.GetInt64("his_patient_id")
  160. // patient_id, _ := c.GetInt64("patient_id")
  161. // p_ids := c.GetString("p_ids")
  162. // p_ids_arr := strings.Split(p_ids, ",")
  163. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  164. // if his_patient_id == 0 || his_patient.ID == 0 {
  165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  166. // return
  167. // }
  168. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  169. // if err == nil {
  170. // c.ServeSuccessJSON(map[string]interface{}{
  171. // "msg": "关联处方成功",
  172. // })
  173. // return
  174. // } else {
  175. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  176. // return
  177. // }
  178. //}
  179. func (c *HisApiController) GetFaPiaoNumber() {
  180. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  181. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  182. fmt.Println(count)
  183. var zero string
  184. number := count + 1
  185. if number >= 1000 {
  186. zero = "0000" + strconv.FormatInt(number, 10)
  187. } else if number >= 10000 {
  188. zero = "000" + strconv.FormatInt(number, 10)
  189. } else if number >= 100000 {
  190. zero = "00" + strconv.FormatInt(number, 10)
  191. } else if number >= 1000000 {
  192. zero = "0" + strconv.FormatInt(number, 10)
  193. } else {
  194. zero = strconv.FormatInt(number, 10)
  195. }
  196. c.ServeSuccessJSON(map[string]interface{}{
  197. "fapiao_number": zero,
  198. })
  199. return
  200. }
  201. func (c *HisApiController) ChangeOrderDesc() {
  202. id, _ := c.GetInt64("id")
  203. desc := c.GetString("desc")
  204. change_type := c.GetString("change_type")
  205. order, _ := service.GetHisOrderByID(id)
  206. if order.ID == 0 {
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  208. return
  209. }
  210. switch change_type {
  211. case "oth_desc":
  212. order.OthDesc = desc
  213. break
  214. case "cash_pay":
  215. order.CashPay = desc
  216. break
  217. case "jifen_pay":
  218. order.JifenPay = desc
  219. break
  220. case "band_card_pay":
  221. order.BandCardPay = desc
  222. break
  223. case "ali_pay":
  224. order.AliPay = desc
  225. break
  226. case "wechat_pay":
  227. order.WechatPay = desc
  228. break
  229. case "fa_piao_number":
  230. order.FaPiaoNumber = desc
  231. break
  232. case "fa_piao_code":
  233. order.FaPiaoCode = desc
  234. break
  235. }
  236. err := service.SaveHisOrder(&order)
  237. if err == nil {
  238. c.ServeSuccessJSON(map[string]interface{}{
  239. "msg": "修改成功",
  240. })
  241. return
  242. } else {
  243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  244. return
  245. }
  246. }
  247. func (c *HisApiController) GetMonthHisPatient() {
  248. record_date := c.GetString("record_date")
  249. //order_status, _ := c.GetInt64("type")
  250. timeLayout := "2006-01-02"
  251. loc, _ := time.LoadLocation("Local")
  252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  253. if err != nil {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. recordDateTime := theTime.Unix()
  258. adminInfo := c.GetAdminUserInfo()
  259. var tempPatients []service.NewTempPatients
  260. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  261. // 获取当前时间
  262. now := time.Now()
  263. // 获取本月的第一天
  264. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  265. // 获取下个月的第一天
  266. nextMonth := firstDay.AddDate(0, 1, 0)
  267. // 获取本月的最后一天
  268. lastDay := nextMonth.Add(-time.Nanosecond)
  269. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  270. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  271. var patients []service.NewTempPatients
  272. var patients_two []service.NewTempPatients
  273. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  274. for _, item := range tempPatients {
  275. //过滤掉没挂号的和没开处方的
  276. if len(item.HisPrescription) > 0 {
  277. patients = append(patients, item)
  278. patients_two = append(patients_two, item)
  279. }
  280. ////过滤掉没挂号的
  281. //if len(item.HisPatient) > 0 {
  282. //}
  283. }
  284. } else {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. }
  290. ////过滤掉没挂号的
  291. //if len(item.HisPatient) > 0 {
  292. // patients_two = append(patients_two, item)
  293. //}
  294. }
  295. }
  296. c.ServeSuccessJSON(map[string]interface{}{
  297. "list": patients,
  298. "list_two": patients_two,
  299. "chargePatients": chargePatients,
  300. })
  301. }
  302. func (c *HisApiController) GetBatchSettleAccounts() {
  303. order_ids := c.GetString("order_ids")
  304. admin_user_id, _ := c.GetInt64("admin_user_id")
  305. adminUser := c.GetAdminUserInfo()
  306. orders := strings.Split(order_ids, ",")
  307. var newOrders []models.Orders
  308. for _, item := range orders {
  309. order, _ := service.GetHisOrderByIDTenOne(item)
  310. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  311. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  312. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  313. orderInfos = append(orderInfos, orderInfos_two...)
  314. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  315. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  316. var diagnosis_ids []string
  317. if his.ID > 0 {
  318. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  319. } else {
  320. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  321. }
  322. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  323. var dia_config []*models.HisXtDiagnoseConfig
  324. var name string
  325. for _, item := range diagnosis_ids {
  326. id, _ := strconv.ParseInt(item, 10, 64)
  327. diagnosisConfig, _ := service.FindDiagnoseById(id)
  328. dia_config = append(dia_config, diagnosisConfig)
  329. if len(name) == 0 {
  330. name = diagnosisConfig.ClassName
  331. } else {
  332. name = name + "," + diagnosisConfig.ClassName
  333. }
  334. }
  335. var bedCostTotal float64 = 0 //床位总费
  336. var bedCostSelfTotal float64 = 0 //床位自费
  337. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  338. var bedSelfTotal float64 = 0 //床位部分项目自费
  339. var bedInscpTotal float64 = 0 //床位部分项目自费
  340. var operationCostTotal float64 = 0 //手术费
  341. var operationCostSelfTotal float64 = 0 //手术费
  342. var operationCostPartSelfTotal float64 = 0 //手术费
  343. var operationSelfTotal float64 = 0 //床位部分项目自费
  344. var operationInscpTotal float64 = 0 //床位部分项目自费
  345. var otherCostTotal float64 = 0 //其他费用
  346. var otherCostSelfTotal float64 = 0 //其他费用
  347. var otherCostPartSelfTotal float64 = 0 //其他费用
  348. var otherSelfTotal float64 = 0 //床位部分项目自费
  349. var otherInscpTotal float64 = 0 //床位部分项目自费
  350. var materialCostTotal float64 = 0 //材料费
  351. var materialCostSelfTotal float64 = 0 //材料费
  352. var materialCostPartSelfTotal float64 = 0 //材料费
  353. var materialSelfTotal float64 = 0 //床位部分项目自费
  354. var materialInscpTotal float64 = 0 //床位部分项目自费
  355. var westernMedicineCostTotal float64 = 0 //西药费
  356. var westernMedicineCostSelfTotal float64 = 0 //西药费
  357. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  358. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  359. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  360. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  361. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  364. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  365. var checkCostTotal float64 = 0 //检查费
  366. var checkCostSelfTotal float64 = 0 //检查费
  367. var checkCostPartSelfTotal float64 = 0 //检查费
  368. var checkSelfTotal float64 = 0 //床位部分项目自费
  369. var checkInscpTotal float64 = 0 //床位部分项目自费
  370. var laboratoryCostTotal float64 = 0 //化验费
  371. var laboratoryCostSelfTotal float64 = 0 //化验费
  372. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  373. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  374. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  375. var treatCostTotal float64 = 0 //治疗费用
  376. var treatCostSelfTotal float64 = 0 //治疗费用
  377. var treatCostPartSelfTotal float64 = 0 //治疗费用
  378. var treatSelfTotal float64 = 0 //床位部分项目自费
  379. var treatInscpTotal float64 = 0 //床位部分项目自费
  380. decimal.DivisionPrecision = 2
  381. for _, item := range orderInfos {
  382. if item.MedChrgitmType == "01" { //床位费
  383. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  384. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  385. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  386. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  387. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  388. }
  389. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  390. if item.MedChrgitmType == "03" { //检查费
  391. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. } else {
  398. if item.MedChrgitmType == "03" { //检查费
  399. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. }
  406. if item.MedChrgitmType == "04" { //化验费
  407. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. if item.MedChrgitmType == "05" { //治疗费
  414. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  415. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  416. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  417. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  418. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  419. }
  420. if item.MedChrgitmType == "06" { //手术费
  421. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  422. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  423. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  424. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  425. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  426. }
  427. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  428. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  429. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  430. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  431. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  432. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  433. }
  434. if item.MedChrgitmType == "09" { //西药费
  435. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  436. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  437. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  438. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  439. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  440. }
  441. if item.MedChrgitmType == "11" { //中成费
  442. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  443. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  444. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  445. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  446. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  447. }
  448. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  449. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  450. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  451. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  452. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  453. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  454. }
  455. }
  456. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  457. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  458. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  459. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  460. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  461. var doctor_name string
  462. if roles.ID == 0 {
  463. doctor_name = "管理员"
  464. } else {
  465. doctor_name = roles.UserName
  466. }
  467. yiliao_leibie := ""
  468. switch order.MedType {
  469. case "11":
  470. yiliao_leibie = "普通门诊"
  471. break
  472. case "12":
  473. yiliao_leibie = "门诊挂号"
  474. break
  475. case "13":
  476. yiliao_leibie = "急诊"
  477. break
  478. case "14":
  479. yiliao_leibie = "门诊特殊病"
  480. break
  481. case "15":
  482. yiliao_leibie = "门诊统筹"
  483. break
  484. case "16":
  485. yiliao_leibie = "门诊慢性病"
  486. break
  487. case "21":
  488. yiliao_leibie = "普通住院"
  489. break
  490. }
  491. var newOrder models.Orders
  492. newOrder.Diagnosis = name
  493. newOrder.OrderInfos = orderInfos
  494. newOrder.Number = order.MdtrtId
  495. newOrder.Date = order.SettleAccountsDate
  496. newOrder.ChargeAdmin = charge_admin
  497. newOrder.PrintorAdmin = printor_admin
  498. newOrder.Order = order
  499. newOrder.BedCostTotal = bedCostTotal
  500. newOrder.BedCostSelfTotal = bedCostSelfTotal
  501. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  502. newOrder.BedSelfTotal = bedSelfTotal
  503. newOrder.BedInscpTotal = bedInscpTotal
  504. newOrder.OperationCostTotal = operationCostTotal
  505. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  506. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  507. newOrder.OperationSelfTotal = operationSelfTotal
  508. newOrder.OperationInscpTotal = operationInscpTotal
  509. newOrder.OtherCostTotal = otherCostTotal
  510. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  511. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  512. newOrder.OtherSelfTotal = otherSelfTotal
  513. newOrder.OtherInscpTotal = otherInscpTotal
  514. newOrder.MaterialCostTotal = materialCostTotal
  515. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  516. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  517. newOrder.MaterialSelfTotal = materialSelfTotal
  518. newOrder.MaterialInscpTotal = materialInscpTotal
  519. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  520. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  521. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  522. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  523. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  524. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  525. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  526. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  527. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  528. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  529. newOrder.CheckCostTotal = checkCostTotal
  530. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  531. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  532. newOrder.CheckSelfTotal = checkSelfTotal
  533. newOrder.CheckInscpTotal = checkInscpTotal
  534. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  535. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  536. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  537. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  538. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  539. newOrder.TreatCostTotal = treatCostTotal
  540. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  541. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  542. newOrder.TreatSelfTotal = treatSelfTotal
  543. newOrder.TreatInscpTotal = treatInscpTotal
  544. newOrder.DoctorInfo = doctor_info
  545. newOrder.DoctorName = doctor_name
  546. newOrder.HealthCardNo = order.PsnNo
  547. newOrder.YiliaoLeibie = yiliao_leibie
  548. newOrder.Patient = patient
  549. newOrder.OrgName = miConfig.OrgName
  550. newOrder.OrgCode = miConfig.Code
  551. newOrder.OrderNumber = order.Number
  552. newOrder.HisPatient = his
  553. newOrder.DiaConfig = dia_config
  554. newOrders = append(newOrders, newOrder)
  555. }
  556. c.ServeSuccessJSON(map[string]interface{}{
  557. "orders": newOrders,
  558. })
  559. }
  560. func (c *HisApiController) GetTestOrder() {
  561. order_id, _ := c.GetInt64("order_id")
  562. admin_user_id, _ := c.GetInt64("admin_user_id")
  563. adminUser := c.GetAdminUserInfo()
  564. order, _ := service.GetHisOrderByID(order_id)
  565. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  566. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  567. orderInfos = append(orderInfos, orderInfos_two...)
  568. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  569. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  570. var dia_config []*models.HisXtDiagnoseConfig
  571. var name string
  572. var bedCostTotal float64 = 0 //床位总费
  573. var bedCostSelfTotal float64 = 0 //床位自费
  574. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  575. var bedSelfTotal float64 = 0 //床位部分项目自费
  576. var bedInscpTotal float64 = 0 //床位部分项目自费
  577. var operationCostTotal float64 = 0 //手术费
  578. var operationCostSelfTotal float64 = 0 //手术费
  579. var operationCostPartSelfTotal float64 = 0 //手术费
  580. var operationSelfTotal float64 = 0 //床位部分项目自费
  581. var operationInscpTotal float64 = 0 //床位部分项目自费
  582. var otherCostTotal float64 = 0 //其他费用
  583. var otherCostSelfTotal float64 = 0 //其他费用
  584. var otherCostPartSelfTotal float64 = 0 //其他费用
  585. var otherSelfTotal float64 = 0 //床位部分项目自费
  586. var otherInscpTotal float64 = 0 //床位部分项目自费
  587. var materialCostTotal float64 = 0 //材料费
  588. var materialCostSelfTotal float64 = 0 //材料费
  589. var materialCostPartSelfTotal float64 = 0 //材料费
  590. var materialSelfTotal float64 = 0 //床位部分项目自费
  591. var materialInscpTotal float64 = 0 //床位部分项目自费
  592. var westernMedicineCostTotal float64 = 0 //西药费
  593. var westernMedicineCostSelfTotal float64 = 0 //西药费
  594. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  595. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  596. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  597. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  598. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  601. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  602. var checkCostTotal float64 = 0 //检查费
  603. var checkCostSelfTotal float64 = 0 //检查费
  604. var checkCostPartSelfTotal float64 = 0 //检查费
  605. var checkSelfTotal float64 = 0 //床位部分项目自费
  606. var checkInscpTotal float64 = 0 //床位部分项目自费
  607. var laboratoryCostTotal float64 = 0 //化验费
  608. var laboratoryCostSelfTotal float64 = 0 //化验费
  609. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  610. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  611. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  612. var treatCostTotal float64 = 0 //治疗费用
  613. var treatCostSelfTotal float64 = 0 //治疗费用
  614. var treatCostPartSelfTotal float64 = 0 //治疗费用
  615. var treatSelfTotal float64 = 0 //床位部分项目自费
  616. var treatInscpTotal float64 = 0 //床位部分项目自费
  617. decimal.DivisionPrecision = 2
  618. for _, item := range orderInfos {
  619. if item.MedChrgitmType == "01" { //床位费
  620. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  621. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  622. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  623. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  624. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  625. }
  626. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  627. if item.MedChrgitmType == "03" { //检查费
  628. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. } else {
  635. if item.MedChrgitmType == "03" { //检查费
  636. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. }
  643. if item.MedChrgitmType == "04" { //化验费
  644. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. if item.MedChrgitmType == "05" { //治疗费
  651. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  652. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  653. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  654. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  655. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  656. }
  657. if item.MedChrgitmType == "06" { //手术费
  658. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  659. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  660. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  661. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  662. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  663. }
  664. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  665. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  666. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  667. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  668. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  669. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  670. }
  671. if item.MedChrgitmType == "09" { //西药费
  672. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  673. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  674. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  675. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  676. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  677. }
  678. if item.MedChrgitmType == "11" { //中成费
  679. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  680. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  681. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  682. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  683. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  684. }
  685. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  686. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  687. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  688. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  689. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  690. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  691. }
  692. }
  693. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  694. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  695. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  696. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  697. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  698. var doctor_name string
  699. if roles.ID == 0 {
  700. doctor_name = "管理员"
  701. } else {
  702. doctor_name = roles.UserName
  703. }
  704. yiliao_leibie := ""
  705. switch order.MedType {
  706. case "11":
  707. yiliao_leibie = "普通门诊"
  708. break
  709. case "12":
  710. yiliao_leibie = "门诊挂号"
  711. break
  712. case "13":
  713. yiliao_leibie = "急诊"
  714. break
  715. case "14":
  716. yiliao_leibie = "门诊特殊病"
  717. break
  718. case "15":
  719. yiliao_leibie = "门诊统筹"
  720. break
  721. case "16":
  722. yiliao_leibie = "门诊慢性病"
  723. break
  724. case "21":
  725. yiliao_leibie = "普通住院"
  726. break
  727. }
  728. c.ServeSuccessJSON(map[string]interface{}{
  729. "diagnosis": name,
  730. "order_infos": orderInfos,
  731. "number": order.MdtrtId,
  732. "date": order.SettleAccountsDate,
  733. "charge_admin": charge_admin,
  734. "printor_admin": printor_admin,
  735. "info": order,
  736. "order": order,
  737. "bedCostTotal": bedCostTotal,
  738. "bedCostSelfTotal": bedCostSelfTotal,
  739. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  740. "bedSelfTotal": bedSelfTotal,
  741. "bedInscpTotal": bedInscpTotal,
  742. "operationCostTotal": operationCostTotal,
  743. "operationCostSelfTotal": operationCostSelfTotal,
  744. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  745. "operationSelfTotal": operationSelfTotal,
  746. "operationInscpTotal": operationInscpTotal,
  747. "otherCostTotal": otherCostTotal,
  748. "otherCostSelfTotal": otherCostSelfTotal,
  749. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  750. "otherSelfTotal": otherSelfTotal,
  751. "otherInscpTotal": otherInscpTotal,
  752. "materialCostTotal": materialCostTotal,
  753. "materialCostSelfTotal": materialCostSelfTotal,
  754. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  755. "materialSelfTotal": materialSelfTotal,
  756. "materialInscpTotal": materialInscpTotal,
  757. "westernMedicineCostTotal": westernMedicineCostTotal,
  758. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  759. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  760. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  761. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  762. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  763. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  764. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  765. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  766. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  767. "checkCostTotal": checkCostTotal,
  768. "checkCostSelfTotal": checkCostSelfTotal,
  769. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  770. "checkSelfTotal": checkSelfTotal,
  771. "checkInscpTotal": checkInscpTotal,
  772. "laboratoryCostTotal": laboratoryCostTotal,
  773. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  774. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  775. "laboratorySelfTotal": laboratorySelfTotal,
  776. "laboratoryInscpTotal": laboratoryInscpTotal,
  777. "treatCostTotal": treatCostTotal,
  778. "treatCostSelfTotal": treatCostSelfTotal,
  779. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  780. "treatSelfTotal": treatSelfTotal,
  781. "treatInscpTotal": treatInscpTotal,
  782. "doctor_info": doctor_info,
  783. "doctor_name": doctor_name,
  784. "health_card_no": order.PsnNo,
  785. "yiliao_leibie": yiliao_leibie,
  786. "patient": patient,
  787. "org_name": miConfig.OrgName,
  788. "org_code": miConfig.Code,
  789. "order_number": order.Number,
  790. "his_hospital": his_hospital,
  791. "dia_config": dia_config,
  792. })
  793. }
  794. func (c *PublicApiController) GetBaiLinExportData() {
  795. data := service.GetBaiLinOrderData()
  796. fmt.Println(len(data))
  797. var new_data []*models.NewCustomHisOrder
  798. for _, item := range data {
  799. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  800. new_data = append(new_data, item)
  801. }
  802. }
  803. fmt.Println(len(new_data))
  804. c.ServeSuccessJSON(map[string]interface{}{
  805. "list": new_data,
  806. })
  807. }
  808. func (c *HisApiController) GetHisUnChargePatientList() {
  809. record_date := c.GetString("record_date")
  810. sch_type, _ := c.GetInt64("sch_type")
  811. timeLayout := "2006-01-02"
  812. loc, _ := time.LoadLocation("Local")
  813. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  814. if err != nil {
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  816. return
  817. }
  818. recordDateTime := theTime.Unix()
  819. adminInfo := c.GetAdminUserInfo()
  820. var tempPatients []*service.NewTempPatients
  821. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  822. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  823. var patients []*service.NewTempPatients
  824. var patients_two []*service.NewTempPatients
  825. for _, item := range tempPatients {
  826. //过滤掉没挂号的和没开处方的
  827. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  828. patients = append(patients, item)
  829. }
  830. //过滤掉没挂号的
  831. if len(item.HisPatient) > 0 {
  832. patients_two = append(patients_two, item)
  833. }
  834. }
  835. c.ServeSuccessJSON(map[string]interface{}{
  836. "list": patients,
  837. "list_two": patients_two,
  838. })
  839. }
  840. func (c *HisApiController) GetPrivateExpensesOrder() {
  841. //id, _ := c.GetInt64("id")
  842. //record_time := c.GetString("record_time")
  843. order_id, _ := c.GetInt64("order_id")
  844. admin_user_id, _ := c.GetInt64("admin_user_id")
  845. //timeLayout := "2006-01-02"
  846. //loc, _ := time.LoadLocation("Local")
  847. //
  848. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  849. //if err != nil {
  850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  851. // return
  852. //}
  853. //recordDateTime := theTime.Unix()
  854. adminUser := c.GetAdminUserInfo()
  855. order, _ := service.GetHisOrderByID(order_id)
  856. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  857. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  858. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  859. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  860. //var config []*models.HisXtDiagnoseConfig
  861. var name string
  862. if order.PType == 1 {
  863. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  864. for _, item := range diagnosis_ids {
  865. id, _ := strconv.ParseInt(item, 10, 64)
  866. diagnosisConfig, _ := service.FindDiagnoseById(id)
  867. if len(name) == 0 {
  868. name = diagnosisConfig.ClassName
  869. } else {
  870. name = name + "," + diagnosisConfig.ClassName
  871. }
  872. }
  873. } else {
  874. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  875. for _, item := range diagnosis_ids {
  876. id, _ := strconv.ParseInt(item, 10, 64)
  877. diagnosisConfig, _ := service.FindDiagnoseById(id)
  878. if len(name) == 0 {
  879. name = diagnosisConfig.ClassName
  880. } else {
  881. name = name + "," + diagnosisConfig.ClassName
  882. }
  883. }
  884. }
  885. var bedCostTotal float64 = 0 //床位总费
  886. //var bedCostSelfTotal float64 = 0 //床位自费
  887. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  888. var operationCostTotal float64 = 0 //手术费
  889. //var operationCostSelfTotal float64 = 0 //手术费
  890. var operationCostPartSelfTotal float64 = 0 //手术费
  891. var otherCostTotal float64 = 0 //其他费用
  892. //var otherCostSelfTotal float64 = 0 //其他费用
  893. var otherCostPartSelfTotal float64 = 0 //其他费用
  894. var materialCostTotal float64 = 0 //材料费
  895. //var materialCostSelfTotal float64 = 0 //材料费
  896. var materialCostPartSelfTotal float64 = 0 //材料费
  897. var westernMedicineCostTotal float64 = 0 //西药费
  898. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  899. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  900. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  901. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  902. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  903. var checkCostTotal float64 = 0 //检查费
  904. //var checkCostSelfTotal float64 = 0 //检查费
  905. var checkCostPartSelfTotal float64 = 0 //检查费
  906. var laboratoryCostTotal float64 = 0 //化验费
  907. //var laboratoryCostSelfTotal float64 = 0 //化验费
  908. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  909. var treatCostTotal float64 = 0 //治疗费用
  910. //var treatCostSelfTotal float64 = 0 //治疗费用
  911. var treatCostPartSelfTotal float64 = 0 //治疗费用
  912. var zhenChaCostTotal float64 = 0 //其他费用
  913. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  914. decimal.DivisionPrecision = 2
  915. for _, item := range orderInfos {
  916. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  917. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  918. item.MedChrgitmType = "09"
  919. }
  920. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  921. if item.HisPrescriptionProject.Type == 2 {
  922. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  923. fmt.Println("CostClassify")
  924. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  925. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  926. case 0:
  927. item.MedChrgitmType = "0"
  928. break
  929. case 1:
  930. item.MedChrgitmType = "14"
  931. break
  932. case 2:
  933. item.MedChrgitmType = "05"
  934. break
  935. case 3:
  936. item.MedChrgitmType = "03"
  937. break
  938. case 4:
  939. item.MedChrgitmType = "03"
  940. break
  941. case 5:
  942. item.MedChrgitmType = "08"
  943. break
  944. case 6:
  945. item.MedChrgitmType = "14"
  946. break
  947. case 7:
  948. item.MedChrgitmType = "14"
  949. break
  950. case 8:
  951. item.MedChrgitmType = "03"
  952. break
  953. case 9:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 10:
  957. item.MedChrgitmType = "14"
  958. break
  959. case 11:
  960. item.MedChrgitmType = "06"
  961. break
  962. case 12:
  963. item.MedChrgitmType = "12"
  964. break
  965. case 13:
  966. item.MedChrgitmType = "01"
  967. break
  968. case 14:
  969. item.MedChrgitmType = "04"
  970. break
  971. case 15:
  972. item.MedChrgitmType = "14"
  973. break
  974. }
  975. } else {
  976. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  977. case 1:
  978. item.MedChrgitmType = "14"
  979. break
  980. case 2:
  981. item.MedChrgitmType = "05"
  982. break
  983. case 3:
  984. item.MedChrgitmType = "04"
  985. break
  986. case 4:
  987. item.MedChrgitmType = "14"
  988. break
  989. case 5:
  990. item.MedChrgitmType = "08"
  991. break
  992. case 6:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 7:
  996. item.MedChrgitmType = "14"
  997. break
  998. case 8:
  999. item.MedChrgitmType = "03"
  1000. break
  1001. case 9:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. default:
  1005. item.MedChrgitmType = "14"
  1006. break
  1007. }
  1008. }
  1009. } else if item.HisPrescriptionProject.Type == 3 {
  1010. item.MedChrgitmType = "08"
  1011. }
  1012. }
  1013. }
  1014. order.PsnCashPay = order.MedfeeSumamt
  1015. for _, item := range orderInfos {
  1016. if item.MedChrgitmType == "01" { //床位费
  1017. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1018. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1019. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1020. }
  1021. if item.MedChrgitmType == "02" { //诊察费
  1022. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1023. //zhenChaCostSelfTotal = zhenChaCostTotal
  1024. }
  1025. if item.MedChrgitmType == "03" { //检查费
  1026. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //检查费
  1031. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1033. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1034. }
  1035. if item.MedChrgitmType == "04" { //化验费
  1036. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1037. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1038. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1039. }
  1040. if item.MedChrgitmType == "05" { //治疗费
  1041. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "06" { //手术费
  1046. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1051. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "09" { //西药费
  1056. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "11" { //中成费
  1061. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1066. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. }
  1071. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1072. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1073. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1074. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1075. c.ServeSuccessJSON(map[string]interface{}{
  1076. "patient": patient,
  1077. "order_infos": orderInfos,
  1078. "diagnosis": name,
  1079. "bedCostTotal": bedCostTotal,
  1080. "bedCostSelfTotal": bedCostTotal,
  1081. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1082. "operationCostTotal": operationCostTotal,
  1083. "operationCostSelfTotal": operationCostTotal,
  1084. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1085. "otherCostTotal": otherCostTotal,
  1086. "otherCostSelfTotal": otherCostTotal,
  1087. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1088. "materialCostTotal": materialCostTotal,
  1089. "materialCostSelfTotal": materialCostTotal,
  1090. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1091. "westernMedicineCostTotal": westernMedicineCostTotal,
  1092. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1093. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1094. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1095. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1096. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1097. "checkCostTotal": checkCostTotal,
  1098. "checkCostSelfTotal": checkCostTotal,
  1099. "zhenChaCostTotal": zhenChaCostTotal,
  1100. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1101. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1102. "laboratoryCostTotal": laboratoryCostTotal,
  1103. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1104. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1105. "treatCostTotal": treatCostTotal,
  1106. "treatCostSelfTotal": treatCostTotal,
  1107. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1108. "charge_admin": charge_admin,
  1109. "printor_admin": printor_admin,
  1110. "org_name": org.OrgName,
  1111. "org_code": miConfig.Code,
  1112. "name": patient.Name,
  1113. "number": order.MdtrtId,
  1114. "date": order.SettleAccountsDate,
  1115. "info": order,
  1116. "his_hospital": his_hospital,
  1117. "his": his,
  1118. })
  1119. }
  1120. func (c *HisApiController) RefudDetail() {
  1121. order_id, _ := c.GetInt64("order_id")
  1122. order, _ := service.GetHisOrderByID(order_id)
  1123. adminUser := c.GetAdminUserInfo()
  1124. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1125. c.ServeSuccessJSON(map[string]interface{}{
  1126. "msg": "撤销成功",
  1127. })
  1128. }
  1129. func (c *HisApiController) Sscard() {
  1130. //r := CardInit()
  1131. //if r == 0 {
  1132. // GetBaseInfo()
  1133. //}
  1134. //c.ServeSuccessJSON(map[string]interface{}{
  1135. // "list": "11",
  1136. //})
  1137. }
  1138. func GetBaseInfo() error {
  1139. //handle := syscall.MustLoadDLL("SSCard.dll")
  1140. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1141. //
  1142. //str := make([]byte, 256)
  1143. //str1 := make([]byte, 256)
  1144. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1145. //if ferr != nil {
  1146. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1147. // return ferr
  1148. //}
  1149. //
  1150. //fmt.Println(string(str))
  1151. //
  1152. //fmt.Println(r)
  1153. return nil
  1154. }
  1155. func CardInit() int {
  1156. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1157. //add := DllTestDef.MustFindProc("Init")
  1158. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1159. //if err != nil {
  1160. // fmt.Println("SSCard的运算结果为:", ret)
  1161. //}
  1162. //result := int(ret)
  1163. return 0
  1164. }
  1165. func IntPtr(n int) uintptr {
  1166. return uintptr(n)
  1167. }
  1168. func StrPtr(s string) uintptr {
  1169. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1170. }
  1171. func (c *HisApiController) GetHisPatientList() {
  1172. //types, _ := c.GetInt64("type", 0)
  1173. record_date := c.GetString("record_date")
  1174. sch_type, _ := c.GetInt64("sch_type")
  1175. timeLayout := "2006-01-02"
  1176. loc, _ := time.LoadLocation("Local")
  1177. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1178. if err != nil {
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. recordDateTime := theTime.Unix()
  1183. adminInfo := c.GetAdminUserInfo()
  1184. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1185. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1186. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1187. //获取当前用户的信息
  1188. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1189. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1190. //获取所有科室信息
  1191. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1192. c.ServeSuccessJSON(map[string]interface{}{
  1193. "list": patients,
  1194. "list_two": patients_two,
  1195. "info": adminUserInfo,
  1196. "doctors": doctors,
  1197. "department": department,
  1198. })
  1199. }
  1200. type CustomTemplate struct {
  1201. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1202. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1203. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1204. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1205. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1206. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1207. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1208. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1209. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1210. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1211. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1212. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1213. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1214. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1215. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1216. }
  1217. func (c *HisApiController) GetHisPatientInfo() {
  1218. patient_id, _ := c.GetInt64("patient_id")
  1219. his_patient_id, _ := c.GetInt64("his_patient_id")
  1220. record_date := c.GetString("record_date")
  1221. number := c.GetString("number")
  1222. //start_time := c.GetString("start_time")
  1223. //end_time := c.GetString("end_time")
  1224. p_type, _ := c.GetInt64("p_type")
  1225. timeLayout := "2006-01-02"
  1226. loc, _ := time.LoadLocation("Local")
  1227. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1228. if err != nil {
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. return
  1231. }
  1232. recordDateTime := theTime.Unix()
  1233. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1234. //if err != nil {
  1235. //
  1236. //}
  1237. //startRecordDateTime := startTime.Unix()
  1238. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1239. //if err != nil {
  1240. //
  1241. //}
  1242. //endRecordDateTime := endTime.Unix()
  1243. admin := c.GetAdminUserInfo()
  1244. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1245. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1246. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1247. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1248. var prescriptions []*models.HisPrescription
  1249. var last_prescriptions []*models.HisPrescription
  1250. var sch_prescriptions []CustomTemplate
  1251. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1252. if p_type == 1 { //住院
  1253. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1254. for _, item := range prescriptions {
  1255. for _, subItem := range item.HisDoctorAdviceInfo {
  1256. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1257. if info.RetailPrice > 0 {
  1258. subItem.Drug.MinPrice = info.RetailPrice
  1259. }
  1260. }
  1261. }
  1262. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1263. } else { //门诊
  1264. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1265. for _, item := range prescriptions {
  1266. for _, subItem := range item.HisDoctorAdviceInfo {
  1267. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1268. if info.RetailPrice > 0 {
  1269. subItem.Drug.MinPrice = info.RetailPrice
  1270. }
  1271. }
  1272. }
  1273. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1274. }
  1275. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1276. if sch.ID > 0 {
  1277. var week string
  1278. t := time.Now()
  1279. switch t.Weekday().String() {
  1280. case "Monday":
  1281. week = "周一"
  1282. break
  1283. case "Tuesday":
  1284. week = "周二"
  1285. break
  1286. case "Wednesday":
  1287. week = "周三"
  1288. break
  1289. case "Thursday":
  1290. week = "周四"
  1291. break
  1292. case "Friday":
  1293. week = "周五"
  1294. break
  1295. case "Saturday":
  1296. week = "周六"
  1297. break
  1298. case "Sunday":
  1299. week = "周日"
  1300. break
  1301. }
  1302. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1303. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1304. //根据推送频率组装新的数组
  1305. for _, item := range temp_sch_prescriptions {
  1306. var cus CustomTemplate
  1307. cus.ID = item.ID
  1308. cus.UserOrgId = item.UserOrgId
  1309. cus.PatientId = item.PatientId
  1310. cus.MedType = item.MedType
  1311. cus.RecordDate = item.RecordDate
  1312. cus.Type = item.Type
  1313. cus.PType = item.PType
  1314. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1315. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1316. if subItem.FrequencyType == 1 { //每次必推
  1317. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1318. }
  1319. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1320. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1321. }
  1322. if subItem.FrequencyType == 2 { //按照天数频率
  1323. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1324. now := p.Unix()
  1325. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1326. dayStr2 := "-" + dayStr
  1327. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1328. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1329. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1330. if len(advices) == 0 {
  1331. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1332. }
  1333. }
  1334. }
  1335. }
  1336. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1337. if subItem.Type == 2 {
  1338. if subItem.XtHisProject.MedicalStatus != 1 {
  1339. if subItem.FrequencyType == 1 {
  1340. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1343. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 {
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1353. if len(projects) == 0 {
  1354. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. } else if subItem.Type == 3 {
  1359. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1360. if subItem.FrequencyType == 1 {
  1361. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1362. }
  1363. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1364. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1365. }
  1366. if subItem.FrequencyType == 2 {
  1367. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1368. now := p.Unix()
  1369. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1370. dayStr2 := "-" + dayStr
  1371. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1372. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1373. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1374. if len(projects) == 0 {
  1375. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. sch_prescriptions = append(sch_prescriptions, cus)
  1382. }
  1383. for _, item := range sch_prescriptions {
  1384. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1385. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1386. }
  1387. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1388. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1389. }
  1390. }
  1391. }
  1392. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1393. if config.ID > 0 && config.IsOpen == 1 {
  1394. for _, item := range sch_prescriptions {
  1395. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1396. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1397. if info.RetailPrice > 0 {
  1398. subItem.Drug.MinPrice = info.RetailPrice
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if config.ID > 0 && config.IsOpen == 1 {
  1404. for _, item := range sch_prescriptions {
  1405. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1406. if subItem.Type == 3 {
  1407. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1408. if info.Price > 0 {
  1409. subItem.GoodInfo.PackingPrice = info.Price
  1410. }
  1411. }
  1412. }
  1413. }
  1414. }
  1415. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1416. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1417. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1418. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1419. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1420. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1421. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1422. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1423. //获取所有科室信息
  1424. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1425. c.ServeSuccessJSON(map[string]interface{}{
  1426. "his_info": his_patient_info,
  1427. "xt_info": xt_patient_info,
  1428. "prescription": prescriptions,
  1429. "case_history": case_history,
  1430. "info": patientPrescriptionInfo,
  1431. //"month_prescriptions": monthPrescriptions,
  1432. "order": order,
  1433. "doctors": doctors,
  1434. "department": department,
  1435. "sch_prescriptions": sch_prescriptions,
  1436. "last_prescriptions": last_prescriptions,
  1437. "schedule": sch,
  1438. "count": count,
  1439. "drugStockConfig": drugStockConfig,
  1440. "last_info": lastPatientPrescriptionInfo,
  1441. })
  1442. return
  1443. }
  1444. func (c *HisApiController) GetHisPrescriptionConfig() {
  1445. adminInfo := c.GetAdminUserInfo()
  1446. //获取医嘱模版
  1447. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1448. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1449. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1450. //获取所有基础药
  1451. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1452. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1453. if config.ID > 0 && config.IsOpen == 1 {
  1454. for _, item := range drugs {
  1455. var index = 0
  1456. for _, subItem := range item.OtherDrugWarehouseInfo {
  1457. if index == 0 {
  1458. index = index + 1
  1459. if subItem.RetailPrice > 0 {
  1460. item.MinPrice = subItem.RetailPrice
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1467. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1468. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1469. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1470. //获取所有科室信息
  1471. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1472. //获取诊断信息
  1473. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1474. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1475. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1476. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1477. //获取是否开启保存耗材出库的开关
  1478. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1479. c.ServeSuccessJSON(map[string]interface{}{
  1480. "drugs": drugs,
  1481. "advices_template": advices,
  1482. "drugways": drugways,
  1483. "efs": efs,
  1484. "doctors": doctors,
  1485. "department": department,
  1486. "sick": sick,
  1487. "additions": additions,
  1488. "diagnose": diagnose,
  1489. "manufacturers": manufacturers,
  1490. "goodOutOpen": goodOutOpen,
  1491. "patientDiagnose": patientDiagnose,
  1492. })
  1493. }
  1494. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1495. //获取所有基础药
  1496. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1497. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1498. if config.ID > 0 && config.IsOpen == 1 {
  1499. for _, item := range drugs {
  1500. var index = 0
  1501. for _, subItem := range item.OtherDrugWarehouseInfo {
  1502. if index == 0 {
  1503. index = index + 1
  1504. if subItem.RetailPrice > 0 {
  1505. item.MinPrice = subItem.RetailPrice
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1512. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1513. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1514. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1515. //获取所有科室信息
  1516. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1517. //获取诊断信息
  1518. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1519. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1520. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1521. //获取是否开启保存耗材出库的开关
  1522. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1523. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1524. c.ServeSuccessJSON(map[string]interface{}{
  1525. "drugs": drugs,
  1526. "advices_template": advices,
  1527. "drugways": drugways,
  1528. "efs": efs,
  1529. "doctors": doctors,
  1530. "department": department,
  1531. "sick": sick,
  1532. "additions": additions,
  1533. "diagnose": diagnose,
  1534. "manufacturers": manufacturers,
  1535. "goodOutOpen": goodOutOpen,
  1536. "patientDiagnose": patientDiagnose,
  1537. })
  1538. }
  1539. }
  1540. func (c *HisApiController) CreateHisPrescription() {
  1541. record_date := c.GetString("record_date")
  1542. patient_id, _ := c.GetInt64("patient_id")
  1543. reg_type, _ := c.GetInt64("reg_type")
  1544. diagnose := c.GetString("diagnose")
  1545. sick_type, _ := c.GetInt64("sick_type")
  1546. sick_history := c.GetString("sick_history")
  1547. doctor_id, _ := c.GetInt64("doctor", 0)
  1548. department, _ := c.GetInt64("department", 0)
  1549. his_patient_id, _ := c.GetInt64("his_patient_id")
  1550. p_type, _ := c.GetInt64("p_type")
  1551. patient_diagnose := c.GetString("patient_diagnose")
  1552. dataBody := make(map[string]interface{}, 0)
  1553. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1554. if err != nil {
  1555. utils.ErrorLog(err.Error())
  1556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1557. return
  1558. }
  1559. timeLayout := "2006-01-02"
  1560. loc, _ := time.LoadLocation("Local")
  1561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1562. if err != nil {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1564. return
  1565. }
  1566. adminInfo := c.GetAdminUserInfo()
  1567. recordDateTime := theTime.Unix()
  1568. //查询默认出库仓库库存
  1569. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1570. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1571. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1572. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1573. if len(lists) == 1 {
  1574. his_patient_id = lists[0].ID
  1575. }
  1576. }
  1577. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1578. //保存处方出库
  1579. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1580. //自动出库
  1581. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1582. //耗材保存处方出库
  1583. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1584. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1585. //已发药和已收费限制逻辑
  1586. isMidicine := false
  1587. isCharge := false
  1588. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1589. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1590. if len(prescriptions) > 0 {
  1591. for _, item := range prescriptions {
  1592. items := item.(map[string]interface{})
  1593. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1594. utils.ErrorLog("id")
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1596. return
  1597. }
  1598. id := int64(items["id"].(float64))
  1599. if id > 0 {
  1600. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1601. if err != nil {
  1602. if new_prescription.OrderStatus == 4 {
  1603. isCharge = true
  1604. }
  1605. }
  1606. }
  1607. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1608. advices := items["advices"].([]interface{})
  1609. if len(advices) > 0 {
  1610. for _, advice := range advices {
  1611. var adviceId int64
  1612. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1613. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1614. }
  1615. if adviceId > 0 {
  1616. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1617. if err == nil {
  1618. if his_advice_info.IsMedicine == 1 {
  1619. isMidicine = true
  1620. }
  1621. }
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. if isMidicine == true {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1631. return
  1632. }
  1633. if isCharge == true {
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1635. return
  1636. }
  1637. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1638. //药品发药出库
  1639. if pharmacyConfig.IsOpen == 1 {
  1640. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1641. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1642. if len(prescriptions) > 0 {
  1643. for _, item := range prescriptions {
  1644. items := item.(map[string]interface{})
  1645. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1646. advices := items["advices"].([]interface{})
  1647. if len(advices) > 0 {
  1648. for _, advice := range advices {
  1649. var drug_id int64
  1650. var prescribing_number float64
  1651. var prescribingNumberUnit string
  1652. var adviceId int64
  1653. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1654. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1655. }
  1656. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1657. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1658. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1659. }
  1660. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1661. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1662. }
  1663. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1664. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1665. }
  1666. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1667. if drug.ID == 0 {
  1668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1669. return
  1670. }
  1671. //查询药品的所有库存
  1672. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1673. var total_count int64
  1674. for _, it := range list {
  1675. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1676. }
  1677. totals := strconv.FormatInt(total_count, 10)
  1678. //查询该药品是否存在开药记录
  1679. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1680. fmt.Println("wooooooooooooo", advicelist.ID)
  1681. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1682. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1683. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1684. //新增处方
  1685. if advicelist.ID == 0 {
  1686. all_count, _ := strconv.ParseFloat(totals, 64)
  1687. if prescribingNumberUnit == drug.MinUnit {
  1688. fmt.Println("prescribing_number", prescribing_number)
  1689. fmt.Println("all_count", all_count)
  1690. if drug.IsUse != 1 {
  1691. if drug.IsProject == 0 || drug.IsProject == 2 {
  1692. if all_count == 0 {
  1693. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1694. return
  1695. }
  1696. if prescribing_number > all_count {
  1697. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1698. return
  1699. }
  1700. }
  1701. }
  1702. }
  1703. if prescribingNumberUnit == drug.MaxUnit {
  1704. num := prescribing_number * float64(drug.MinNumber)
  1705. if drug.IsUse != 1 {
  1706. if drug.IsProject == 0 || drug.IsProject == 2 {
  1707. if all_count == 0 {
  1708. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1709. return
  1710. }
  1711. if num > all_count {
  1712. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1713. return
  1714. }
  1715. }
  1716. }
  1717. }
  1718. }
  1719. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1720. if drugOutConfig.IsOpen != 1 {
  1721. //修改处方
  1722. for _, advice := range advices {
  1723. var drug_id int64
  1724. var prescribing_number float64
  1725. var prescribingNumberUnit string
  1726. var prescribingNumber string
  1727. var adviceId int64
  1728. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1729. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1730. }
  1731. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1732. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1733. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1734. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1735. }
  1736. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1737. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1738. }
  1739. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1740. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1741. }
  1742. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1743. if drug.ID == 0 {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1745. return
  1746. }
  1747. //查询药品的所有库存
  1748. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1749. var total_count int64
  1750. for _, it := range list {
  1751. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1752. }
  1753. totals := strconv.FormatInt(total_count, 10)
  1754. //查询该药品是否存在开药记录
  1755. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1756. //新增处方
  1757. if advicelist.ID == 0 {
  1758. all_count, _ := strconv.ParseFloat(totals, 64)
  1759. if prescribingNumberUnit == drug.MinUnit {
  1760. if drug.IsUse != 1 {
  1761. if drug.IsProject == 0 || drug.IsProject == 2 {
  1762. if all_count == 0 {
  1763. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1764. return
  1765. }
  1766. if prescribing_number > all_count {
  1767. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1768. return
  1769. }
  1770. }
  1771. }
  1772. } else {
  1773. if prescribingNumberUnit == drug.MaxUnit {
  1774. num := prescribing_number * float64(drug.MinNumber)
  1775. if drug.IsUse != 1 {
  1776. if drug.IsProject == 0 || drug.IsProject == 2 {
  1777. if all_count == 0 {
  1778. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1779. return
  1780. }
  1781. if num > all_count {
  1782. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1783. return
  1784. }
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. //修改处方
  1791. if advicelist.ID > 0 {
  1792. var device_number int64
  1793. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1794. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1795. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1796. device_number = prescribingNumberInt * drug.MinNumber
  1797. }
  1798. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1799. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1800. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1801. device_number = prescribingNumberInt
  1802. }
  1803. var number_count int64
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1806. number_count = prescribingNumberInt * drug.MinNumber
  1807. }
  1808. if prescribingNumberUnit == drug.MinUnit {
  1809. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1810. number_count = prescribingNumberInt
  1811. }
  1812. //如果修改的数量大于之前修改的数量
  1813. if (number_count - device_number) > 0 {
  1814. //如果修改的差数量 大于库存数量
  1815. if drug.IsUse != 1 {
  1816. if (number_count - device_number) > total_count {
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1818. return
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //已发药和已收费限制逻辑
  1833. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1834. //校验库存总量
  1835. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1836. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1837. if len(prescriptions) > 0 {
  1838. for _, item := range prescriptions {
  1839. items := item.(map[string]interface{})
  1840. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1841. advices := items["advices"].([]interface{})
  1842. if len(advices) > 0 {
  1843. for _, advice := range advices {
  1844. var drug_id int64
  1845. var prescribing_number float64
  1846. var prescribingNumberUnit string
  1847. var adviceId int64
  1848. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1849. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1850. }
  1851. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1852. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1853. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1854. }
  1855. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1856. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1857. }
  1858. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1859. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1860. }
  1861. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1862. if drug.ID == 0 {
  1863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1864. return
  1865. }
  1866. //查询药品的所有库存
  1867. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1868. var total_count int64
  1869. for _, it := range list {
  1870. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1871. }
  1872. totals := strconv.FormatInt(total_count, 10)
  1873. //查询该药品是否存在开药记录
  1874. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1875. //查询最新批次库存
  1876. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1877. var batch_number_count int64
  1878. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1879. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1880. //新增处方
  1881. if advicelist.ID == 0 {
  1882. all_count, _ := strconv.ParseFloat(totals, 64)
  1883. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1884. if prescribingNumberUnit == drug.MinUnit {
  1885. if drug.IsUse != 1 {
  1886. if drug.IsProject == 0 || drug.IsProject == 2 {
  1887. if all_count == 0 {
  1888. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1889. return
  1890. }
  1891. if prescribing_number > all_count {
  1892. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1893. return
  1894. }
  1895. }
  1896. if adminInfo.CurrentOrgId == 10215 {
  1897. if prescribing_number > batch_number_all_count {
  1898. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1899. return
  1900. }
  1901. }
  1902. }
  1903. }
  1904. if prescribingNumberUnit == drug.MaxUnit {
  1905. num := prescribing_number * float64(drug.MinNumber)
  1906. if drug.IsUse != 1 {
  1907. if drug.IsProject == 0 || drug.IsProject == 2 {
  1908. if all_count == 0 {
  1909. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1910. return
  1911. }
  1912. if num > all_count {
  1913. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1914. return
  1915. }
  1916. }
  1917. if adminInfo.CurrentOrgId == 10215 {
  1918. if num > batch_number_all_count {
  1919. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1920. return
  1921. }
  1922. }
  1923. }
  1924. }
  1925. }
  1926. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1927. if drugOutConfig.IsOpen != 1 {
  1928. //修改处方
  1929. for _, advice := range advices {
  1930. var drug_id int64
  1931. var prescribing_number float64
  1932. var prescribingNumberUnit string
  1933. var prescribingNumber string
  1934. var adviceId int64
  1935. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1936. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1937. }
  1938. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1939. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1940. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1941. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1942. }
  1943. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1944. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1945. }
  1946. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1947. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1948. }
  1949. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1950. if drug.ID == 0 {
  1951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1952. return
  1953. }
  1954. //查询药品的所有库存
  1955. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1956. var total_count int64
  1957. for _, it := range list {
  1958. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1959. }
  1960. totals := strconv.FormatInt(total_count, 10)
  1961. //查询该药品是否存在开药记录
  1962. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1963. //新增处方
  1964. if advicelist.ID == 0 {
  1965. //查询最新批次库存
  1966. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1967. var batch_number_count int64
  1968. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1969. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1970. all_count, _ := strconv.ParseFloat(totals, 64)
  1971. if prescribingNumberUnit == drug.MinUnit {
  1972. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1977. return
  1978. }
  1979. if prescribing_number > all_count {
  1980. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1981. return
  1982. }
  1983. }
  1984. if adminInfo.CurrentOrgId == 10215 {
  1985. if prescribing_number > batch_number_all_count {
  1986. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1987. return
  1988. }
  1989. }
  1990. }
  1991. } else {
  1992. if prescribingNumberUnit == drug.MaxUnit {
  1993. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1994. num := prescribing_number * float64(drug.MinNumber)
  1995. if drug.IsUse != 1 {
  1996. if drug.IsProject == 0 || drug.IsProject == 2 {
  1997. if all_count == 0 {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1999. return
  2000. }
  2001. if num > all_count {
  2002. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2003. return
  2004. }
  2005. }
  2006. if adminInfo.CurrentOrgId == 10215 {
  2007. if prescribing_number > batch_number_all_count {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2009. return
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. //修改处方
  2017. if advicelist.ID > 0 {
  2018. //查询最新批次库存
  2019. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2020. var batch_number_count int64
  2021. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2022. var device_number int64
  2023. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2024. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2025. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2026. device_number = prescribingNumberInt * drug.MinNumber
  2027. }
  2028. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2029. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2030. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2031. device_number = prescribingNumberInt
  2032. }
  2033. var number_count int64
  2034. if prescribingNumberUnit == drug.MaxUnit {
  2035. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2036. number_count = prescribingNumberInt * drug.MinNumber
  2037. }
  2038. if prescribingNumberUnit == drug.MinUnit {
  2039. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2040. number_count = prescribingNumberInt
  2041. }
  2042. //如果修改的数量大于之前修改的数量
  2043. if (number_count - device_number) > 0 {
  2044. //如果修改的差数量 大于库存数量
  2045. if drug.IsUse != 1 {
  2046. if drug.IsProject == 0 || drug.IsProject == 2 {
  2047. if total_count == 0 {
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2049. return
  2050. }
  2051. if (number_count - device_number) > total_count {
  2052. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2053. return
  2054. }
  2055. if (number_count - device_number) > batch_number_count {
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2057. return
  2058. }
  2059. }
  2060. if adminInfo.CurrentOrgId == 10215 {
  2061. // 查询该药品最后一次出库记录
  2062. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2063. var out_count int64
  2064. var in_count int64
  2065. var stock_max_number int64
  2066. var stock_min_number int64
  2067. for _, it := range outInfo {
  2068. if it.CountUnit == drug.MaxUnit {
  2069. it.Count = it.Count * drug.MinNumber
  2070. }
  2071. out_count += it.Count
  2072. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2073. stock_max_number = warehouseInfoList.StockMaxNumber
  2074. stock_min_number = warehouseInfoList.StockMinNumber
  2075. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2076. }
  2077. if out_count > 0 {
  2078. if (number_count - device_number) > in_count {
  2079. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2080. return
  2081. }
  2082. }
  2083. // 未出库
  2084. if out_count == 0 {
  2085. var sum_in_count int64
  2086. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2087. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2088. fmt.Println("sum_in_count", sum_in_count)
  2089. //如果修改的数量大于有库存的第一个批次
  2090. if number_count > sum_in_count {
  2091. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2092. return
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2099. if pharmacyConfig.IsOpen != 1 {
  2100. if device_number != number_count {
  2101. // 查询该药品最后一次出库记录
  2102. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2103. //回退库存
  2104. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2105. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2106. }
  2107. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2108. var stock_max_number int64
  2109. var stock_min_number int64
  2110. if number_count >= drug.MinNumber {
  2111. stock_max_number = device_number / drug.MinNumber
  2112. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2113. stock_min_number = device_number % drug.MinNumber
  2114. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2115. } else {
  2116. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2117. }
  2118. }
  2119. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2120. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2121. }
  2122. //删除记录
  2123. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2124. //查询默认仓库剩余多少库存
  2125. var sum_count int64
  2126. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2127. for _, its := range stockInfo {
  2128. if its.MaxUnit == drug.MaxUnit {
  2129. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2130. }
  2131. sum_count += its.StockMaxNumber + its.StockMinNumber
  2132. }
  2133. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. //保存处方开药
  2140. if drugOutConfig.IsOpen == 1 {
  2141. //修改处方
  2142. for _, advice := range advices {
  2143. var drug_id int64
  2144. var prescribing_number float64
  2145. var prescribingNumberUnit string
  2146. var prescribingNumber string
  2147. var adviceId int64
  2148. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2149. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2150. }
  2151. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2152. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2153. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2154. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2155. }
  2156. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2157. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2158. }
  2159. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2160. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2161. }
  2162. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2163. if drug.ID == 0 {
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2165. return
  2166. }
  2167. //查询药品的所有库存
  2168. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2169. var total_count int64
  2170. for _, it := range list {
  2171. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2172. }
  2173. totals := strconv.FormatInt(total_count, 10)
  2174. //查询该药品是否存在开药记录
  2175. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. //查询最新批次库存
  2179. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2180. var batch_number_count int64
  2181. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2182. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2183. all_count, _ := strconv.ParseFloat(totals, 64)
  2184. if prescribingNumberUnit == drug.MinUnit {
  2185. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2186. if drug.IsUse != 1 {
  2187. if drug.IsProject == 0 || drug.IsProject == 2 {
  2188. if all_count == 0 {
  2189. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2190. return
  2191. }
  2192. if prescribing_number > all_count {
  2193. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2194. return
  2195. }
  2196. }
  2197. if adminInfo.CurrentOrgId == 10215 {
  2198. if prescribing_number > batch_number_all_count {
  2199. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2200. return
  2201. }
  2202. }
  2203. }
  2204. } else {
  2205. if prescribingNumberUnit == drug.MaxUnit {
  2206. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2207. num := prescribing_number * float64(drug.MinNumber)
  2208. if drug.IsUse != 1 {
  2209. if drug.IsProject == 0 || drug.IsProject == 2 {
  2210. if all_count == 0 {
  2211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2212. return
  2213. }
  2214. if num > all_count {
  2215. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2216. return
  2217. }
  2218. }
  2219. if adminInfo.CurrentOrgId == 10215 {
  2220. if prescribing_number > batch_number_all_count {
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. //修改处方
  2230. if advicelist.ID > 0 {
  2231. //查询最新批次库存
  2232. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2233. var batch_number_count int64
  2234. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2235. var device_number int64
  2236. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2237. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2238. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2239. device_number = prescribingNumberInt * drug.MinNumber
  2240. }
  2241. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2242. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2243. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2244. device_number = prescribingNumberInt
  2245. }
  2246. var number_count int64
  2247. if prescribingNumberUnit == drug.MaxUnit {
  2248. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2249. number_count = prescribingNumberInt * drug.MinNumber
  2250. }
  2251. if prescribingNumberUnit == drug.MinUnit {
  2252. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2253. number_count = prescribingNumberInt
  2254. }
  2255. //如果修改的数量大于之前修改的数量
  2256. if (number_count - device_number) > 0 {
  2257. //如果修改的差数量 大于库存数量
  2258. if drug.IsUse != 1 {
  2259. if drug.IsProject == 0 || drug.IsProject == 2 {
  2260. if total_count == 0 {
  2261. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2262. return
  2263. }
  2264. if (number_count - device_number) > total_count {
  2265. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2266. return
  2267. }
  2268. }
  2269. if adminInfo.CurrentOrgId == 10215 {
  2270. if (number_count - device_number) > batch_number_count {
  2271. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2272. return
  2273. }
  2274. }
  2275. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2276. //查询历史出库数据总批次
  2277. // 查询该药品最后一次出库记录
  2278. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2279. var out_count int64
  2280. var in_count int64
  2281. var stock_max_number int64
  2282. var stock_min_number int64
  2283. for _, it := range outInfo {
  2284. if it.CountUnit == drug.MaxUnit {
  2285. it.Count = it.Count * drug.MinNumber
  2286. }
  2287. out_count += it.Count
  2288. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2289. stock_max_number = warehouseInfoList.StockMaxNumber
  2290. stock_min_number = warehouseInfoList.StockMinNumber
  2291. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2292. }
  2293. if out_count > 0 {
  2294. if (number_count - device_number) > in_count {
  2295. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2296. return
  2297. }
  2298. }
  2299. // 未出库
  2300. if out_count == 0 {
  2301. var sum_in_count int64
  2302. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2303. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2304. if sum_in_count == 0 {
  2305. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2306. return
  2307. }
  2308. //如果修改的数量大于有库存的第一个批次
  2309. if number_count > sum_in_count {
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2311. return
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. }
  2322. }
  2323. }
  2324. }
  2325. }
  2326. }
  2327. //校验耗材库存
  2328. if goodOutConfig.IsOpen == 1 {
  2329. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2330. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2331. if len(prescriptions) > 0 {
  2332. for _, item := range prescriptions {
  2333. items := item.(map[string]interface{})
  2334. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2335. projects := items["project"].([]interface{})
  2336. if len(projects) > 0 {
  2337. for _, project := range projects {
  2338. var project_id int64
  2339. var project_type int64
  2340. var totals float64
  2341. var project_name string
  2342. var parsetotal int64
  2343. var id int64
  2344. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2345. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2346. }
  2347. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2348. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2349. }
  2350. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2351. total, _ := project.(map[string]interface{})["total"].(string)
  2352. totals, _ = strconv.ParseFloat(total, 64)
  2353. }
  2354. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2355. project_name = project.(map[string]interface{})["project_name"].(string)
  2356. }
  2357. if project_type == 3 {
  2358. //查找该耗材的出库记录
  2359. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2360. if len(goodWarehouseInfo) == 0 {
  2361. //查询耗材库存
  2362. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2363. var stock_count int64
  2364. for _, it := range list {
  2365. stock_count += it.StockCount
  2366. }
  2367. stock_counts := strconv.FormatInt(stock_count, 10)
  2368. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2369. if stock_total_count == 0 {
  2370. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2371. return
  2372. }
  2373. if totals > stock_total_count {
  2374. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2375. return
  2376. }
  2377. }
  2378. if len(goodWarehouseInfo) > 0 {
  2379. //查询该患者耗材的历史数据
  2380. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2381. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2382. //数量发生改变
  2383. if parsetotal != count {
  2384. //如果现在的数量大于历史数量,就要看库存是否足够
  2385. if parsetotal > count {
  2386. //查询耗材所有库存
  2387. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2388. var stock_count int64
  2389. for _, it := range list {
  2390. stock_count += it.StockCount
  2391. }
  2392. //库存不足
  2393. if stock_count == 0 {
  2394. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2395. return
  2396. }
  2397. if (parsetotal - count) > stock_count {
  2398. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2399. return
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. //不使用耗材保存处方出库
  2413. if goodOutConfig.IsOpen != 1 {
  2414. if stockConfig.IsOpen == 1 {
  2415. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2416. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2417. if len(prescriptions) > 0 {
  2418. for _, item := range prescriptions {
  2419. items := item.(map[string]interface{})
  2420. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2421. projects := items["project"].([]interface{})
  2422. if len(projects) > 0 {
  2423. for _, project := range projects {
  2424. var project_id int64
  2425. var project_type int64
  2426. var totals float64
  2427. var project_name string
  2428. var parsetotal int64
  2429. var id int64
  2430. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2431. id = int64(project.(map[string]interface{})["id"].(float64))
  2432. }
  2433. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2434. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2435. }
  2436. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2437. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2438. }
  2439. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2440. total, _ := project.(map[string]interface{})["total"].(string)
  2441. totals, _ = strconv.ParseFloat(total, 64)
  2442. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2443. }
  2444. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2445. project_name = project.(map[string]interface{})["project_name"].(string)
  2446. }
  2447. if project_type == 3 {
  2448. //查找该耗材的出库记录
  2449. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2450. //没有出库记录
  2451. if len(goodWarehouseInfo) == 0 {
  2452. //查询耗材库存
  2453. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2454. var stock_count int64
  2455. for _, it := range list {
  2456. stock_count += it.StockCount
  2457. }
  2458. stock_counts := strconv.FormatInt(stock_count, 10)
  2459. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2460. if stock_total_count == 0 {
  2461. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2462. return
  2463. }
  2464. if totals > stock_total_count {
  2465. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2466. return
  2467. }
  2468. //查找今日该患者已经出库的所有耗材
  2469. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2470. for _, item := range goodList {
  2471. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2472. var flush_count int64
  2473. for _, it := range goodListSix {
  2474. flush_count += it.StockCount
  2475. }
  2476. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2477. creater := adminInfo.AdminUser.Id
  2478. if errs != nil {
  2479. goodErrcode := models.XtGoodErrcode{
  2480. UserOrgId: item.OrgId,
  2481. Errcode: "手动出库更新剩余出库失败",
  2482. GoodId: item.GoodId,
  2483. Status: 1,
  2484. Ctime: time.Now().Unix(),
  2485. Mtime: 0,
  2486. Count: 0,
  2487. StockCount: 0,
  2488. Creater: creater,
  2489. BatchNumberId: 0,
  2490. WarehouseOutId: 0,
  2491. }
  2492. service.CreateGoodErrcode(goodErrcode)
  2493. }
  2494. }
  2495. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2496. }
  2497. //有出库记录
  2498. if len(goodWarehouseInfo) > 0 {
  2499. //查询该患者耗材的历史数据
  2500. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2501. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2502. //数量发生改变
  2503. if parsetotal != count {
  2504. //查找今日该患者已经出库的所有耗材
  2505. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2506. for _, item := range goodList {
  2507. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2508. var flush_count int64
  2509. for _, it := range goodListSix {
  2510. flush_count += it.StockCount
  2511. }
  2512. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2513. //减少出库数量
  2514. creater := adminInfo.AdminUser.Id
  2515. if errs != nil {
  2516. goodErrcode := models.XtGoodErrcode{
  2517. UserOrgId: item.OrgId,
  2518. Errcode: "手动出库更新剩余出库失败",
  2519. GoodId: item.GoodId,
  2520. Status: 1,
  2521. Ctime: time.Now().Unix(),
  2522. Mtime: 0,
  2523. Count: 0,
  2524. StockCount: 0,
  2525. Creater: creater,
  2526. BatchNumberId: 0,
  2527. WarehouseOutId: 0,
  2528. }
  2529. service.CreateGoodErrcode(goodErrcode)
  2530. }
  2531. //查询默认仓库
  2532. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2533. var total_count int64
  2534. for _, it := range stockList {
  2535. total_count += it.StockCount
  2536. }
  2537. //基础库插入数据
  2538. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2539. }
  2540. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2541. }
  2542. }
  2543. }
  2544. }
  2545. }
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. }
  2552. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2553. var hpInfo models.HisPrescriptionInfo
  2554. if info.ID == 0 {
  2555. var randNum int
  2556. randNum = rand.Intn(10000) + 1000
  2557. timestamp := time.Now().Unix()
  2558. tempTime := time.Unix(timestamp, 0)
  2559. timeFormat := tempTime.Format("20060102150405")
  2560. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2561. hpInfo = models.HisPrescriptionInfo{
  2562. HisPatientId: his_patient_id,
  2563. UserOrgId: adminInfo.CurrentOrgId,
  2564. RecordDate: theTime.Unix(),
  2565. PatientId: patient_id,
  2566. Status: 1,
  2567. Ctime: time.Now().Unix(),
  2568. Mtime: time.Now().Unix(),
  2569. Creator: adminInfo.AdminUser.Id,
  2570. Modifier: adminInfo.AdminUser.Id,
  2571. Diagnosis: diagnose,
  2572. SickHistory: sick_history,
  2573. Departments: department,
  2574. RegisterType: reg_type,
  2575. PrescriptionNumber: p_number,
  2576. PrescriptionStatus: 1,
  2577. Doctor: role.UserName,
  2578. DoctorId: doctor_id,
  2579. SickType: sick_type,
  2580. PType: p_type,
  2581. PatientDiagnosis: patient_diagnose,
  2582. }
  2583. service.SavePatientPrescriptionInfo(hpInfo)
  2584. //创建步骤表
  2585. finish := models.XtDialysisFinish{
  2586. IsFinish: 1,
  2587. UserOrgId: adminInfo.CurrentOrgId,
  2588. Status: 1,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: 0,
  2591. Module: 4,
  2592. RecordDate: theTime.Unix(),
  2593. Sourse: 1,
  2594. PatientId: patient_id,
  2595. }
  2596. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2597. if dialysisFinish.ID == 0 {
  2598. service.CreateDialysisFinish(finish)
  2599. }
  2600. redis := service.RedisClient()
  2601. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2602. redis.Set(key, "", time.Second)
  2603. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2604. redis.Set(keyOne, "", time.Second)
  2605. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2606. redis.Set(keySeven, "", time.Second)
  2607. defer redis.Close()
  2608. } else {
  2609. hpInfo = models.HisPrescriptionInfo{
  2610. ID: info.ID,
  2611. UserOrgId: adminInfo.CurrentOrgId,
  2612. RecordDate: info.RecordDate,
  2613. PatientId: info.PatientId,
  2614. Status: 1,
  2615. Ctime: info.Ctime,
  2616. Mtime: time.Now().Unix(),
  2617. Creator: info.Creator,
  2618. Modifier: adminInfo.AdminUser.Id,
  2619. Diagnosis: diagnose,
  2620. SickHistory: sick_history,
  2621. Departments: department,
  2622. RegisterType: reg_type,
  2623. PrescriptionNumber: info.PrescriptionNumber,
  2624. Doctor: role.UserName,
  2625. PrescriptionStatus: info.PrescriptionStatus,
  2626. DoctorId: doctor_id,
  2627. SickType: sick_type,
  2628. PType: info.PType,
  2629. HisPatientId: info.HisPatientId,
  2630. PatientDiagnosis: patient_diagnose,
  2631. }
  2632. service.SavePatientPrescriptionInfo(hpInfo)
  2633. //创建步骤表
  2634. finish := models.XtDialysisFinish{
  2635. IsFinish: 1,
  2636. UserOrgId: adminInfo.CurrentOrgId,
  2637. Status: 1,
  2638. Ctime: time.Now().Unix(),
  2639. Mtime: 0,
  2640. Module: 4,
  2641. RecordDate: info.RecordDate,
  2642. Sourse: 1,
  2643. PatientId: info.PatientId,
  2644. }
  2645. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2646. if dialysisFinish.ID == 0 {
  2647. service.CreateDialysisFinish(finish)
  2648. }
  2649. redis := service.RedisClient()
  2650. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2651. redis.Set(key, "", time.Second)
  2652. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2653. redis.Set(keyOne, "", time.Second)
  2654. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2655. redis.Set(keySeven, "", time.Second)
  2656. defer redis.Close()
  2657. }
  2658. //定义切片
  2659. var adviceList []models.HisDoctorAdviceInfo
  2660. var projectList []models.HisPrescriptionProject
  2661. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2662. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2663. var tempPrescription *models.HisPrescription
  2664. if len(prescriptions) > 0 {
  2665. for _, item := range prescriptions {
  2666. items := item.(map[string]interface{})
  2667. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2668. utils.ErrorLog("id")
  2669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2670. return
  2671. }
  2672. id := int64(items["id"].(float64))
  2673. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2674. tempPrescription = &new_prescription
  2675. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2676. utils.ErrorLog("type")
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2678. return
  2679. }
  2680. types := int64(items["type"].(float64))
  2681. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2682. utils.ErrorLog("med_type")
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2684. return
  2685. }
  2686. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2687. if med_type == "0" {
  2688. med_type = "14"
  2689. }
  2690. //if order_status == 0 {
  2691. // order_status = 1
  2692. //}
  2693. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2694. utils.ErrorLog("pre_time")
  2695. }
  2696. preTime, _ := items["pre_time"].(string)
  2697. timeLayout := "2006-01-02"
  2698. loc, _ := time.LoadLocation("Local")
  2699. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2700. if err != nil {
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. pTime := theTime2.Unix()
  2705. ctime := time.Now().Unix()
  2706. if tempPrescription.ID == 0 {
  2707. prescription := &models.HisPrescription{
  2708. ID: 0,
  2709. PatientId: patient_id,
  2710. UserOrgId: adminInfo.CurrentOrgId,
  2711. RecordDate: recordDateTime,
  2712. Ctime: ctime,
  2713. Mtime: ctime,
  2714. Type: types,
  2715. Modifier: adminInfo.AdminUser.Id,
  2716. Creator: adminInfo.AdminUser.Id,
  2717. Status: 1,
  2718. Doctor: role.UserName,
  2719. HisPatientId: his_patient_id,
  2720. OrderStatus: 1,
  2721. BatchNumber: "",
  2722. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2723. PreTime: pTime,
  2724. PType: p_type,
  2725. MedType: med_type,
  2726. }
  2727. tempPrescription = prescription
  2728. service.SaveHisPrescription(tempPrescription)
  2729. redis := service.RedisClient()
  2730. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2731. redis.Set(key, "", time.Second)
  2732. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2733. redis.Set(keyOne, "", time.Second)
  2734. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2735. redis.Set(keySeven, "", time.Second)
  2736. defer redis.Close()
  2737. } else {
  2738. tempPrescription.ID = id
  2739. tempPrescription.Type = types
  2740. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2741. tempPrescription.Mtime = time.Now().Unix()
  2742. tempPrescription.Doctor = role.UserName
  2743. //tempPrescription.OrderStatus = order_status
  2744. tempPrescription.PreTime = pTime
  2745. tempPrescription.MedType = med_type
  2746. service.SaveHisPrescription(tempPrescription)
  2747. redis := service.RedisClient()
  2748. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2749. redis.Set(key, "", time.Second)
  2750. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2751. redis.Set(keyOne, "", time.Second)
  2752. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2753. redis.Set(keySeven, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. //service.SaveHisPrescription(prescription)
  2757. //更改患者挂号状态
  2758. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2759. fmt.Println("更改失败", err2)
  2760. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2761. advices := items["advices"].([]interface{})
  2762. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2763. groupNo := int64(0)
  2764. ctime := time.Now().Unix()
  2765. mtime := ctime
  2766. if len(advices) > 0 {
  2767. for _, advice := range advices {
  2768. var s models.HisDoctorAdviceInfo
  2769. s.PrescriptionId = tempPrescription.ID
  2770. s.AdviceType = 2
  2771. s.AdviceDoctor = doctor_id
  2772. s.StopState = 2
  2773. s.ExecutionState = 2
  2774. s.AdviceDate = recordDateTime
  2775. s.Status = 1
  2776. s.UserOrgId = adminInfo.CurrentOrgId
  2777. s.RecordDate = recordDateTime
  2778. s.StartTime = tempPrescription.PreTime
  2779. s.Groupno = groupNo
  2780. s.CreatedTime = ctime
  2781. s.UpdatedTime = mtime
  2782. s.PatientId = patient_id
  2783. s.HisPatientId = his_patient_id
  2784. s.StartTime = pTime
  2785. s.IsSettle = 2
  2786. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2787. if errcode > 0 {
  2788. c.ServeFailJSONWithSGJErrorCode(errcode)
  2789. return
  2790. }
  2791. s.StartTime = pTime
  2792. var total_count int64 //处方总库存
  2793. //查询改药品信息
  2794. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2795. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2796. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2797. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2798. total_count += prescribingNumberSeven * medical.MinNumber
  2799. }
  2800. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2801. total_count += prescribingNumberSeven
  2802. }
  2803. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2804. total_count += prescribingNumberSeven
  2805. }
  2806. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2807. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2808. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2809. if s.Price != lastWarehouse.RetailPrice {
  2810. s.Price = lastWarehouse.RetailPrice
  2811. }
  2812. if s.Price == 0 {
  2813. s.Price = lastWarehouse.RetailPrice
  2814. }
  2815. }
  2816. service.CreateHisDoctorAdvice(&s)
  2817. //记录日志
  2818. byterequest, _ := json.Marshal(s)
  2819. adviceLog := models.XtDoctorAdviceLog{
  2820. UserOrgId: s.UserOrgId,
  2821. PatientId: s.PatientId,
  2822. AdminUserId: adminInfo.AdminUser.Id,
  2823. Module: 1,
  2824. ErrLog: string(byterequest),
  2825. Status: 1,
  2826. Ctime: time.Now().Unix(),
  2827. Mtime: 0,
  2828. Source: "电脑端新建his医嘱",
  2829. RecordDate: s.AdviceDate,
  2830. }
  2831. service.CreateDoctorAdviceLog(adviceLog)
  2832. //存储切片中
  2833. adviceList = append(adviceList, s)
  2834. redis := service.RedisClient()
  2835. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2836. redis.Set(key, "", time.Second)
  2837. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2838. redis.Set(keyOne, "", time.Second)
  2839. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2840. redis.Set(keySeven, "", time.Second)
  2841. var randNum int
  2842. randNum = rand.Intn(10000) + 1000
  2843. timestamp := time.Now().Unix()
  2844. tempTime := time.Unix(timestamp, 0)
  2845. timeFormat := tempTime.Format("20060102150405")
  2846. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2847. service.CreateHisDoctorAdvice(&s)
  2848. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2849. redis.Set(keySix, "", time.Second)
  2850. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2851. redis.Set(keyFive, "", time.Second)
  2852. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2853. redis.Set(keyEight, "", time.Second)
  2854. defer redis.Close()
  2855. }
  2856. }
  2857. }
  2858. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2859. projects := items["project"].([]interface{})
  2860. if len(projects) > 0 {
  2861. for _, project := range projects {
  2862. var p models.HisPrescriptionProject
  2863. p.PrescriptionId = tempPrescription.ID
  2864. p.Ctime = time.Now().Unix()
  2865. p.Mtime = time.Now().Unix()
  2866. p.PatientId = patient_id
  2867. p.RecordDate = recordDateTime
  2868. p.Doctor = doctor_id
  2869. p.UserOrgId = adminInfo.CurrentOrgId
  2870. p.HisPatientId = his_patient_id
  2871. p.Status = 1
  2872. p.StartTime = pTime
  2873. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2874. if errcode > 0 {
  2875. c.ServeFailJSONWithSGJErrorCode(errcode)
  2876. return
  2877. }
  2878. if p.ID == 0 {
  2879. p.IsOut = 2
  2880. }
  2881. if p.ID > 0 {
  2882. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2883. p.IsOut = projectDetail.IsOut
  2884. }
  2885. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2886. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2887. if p.Type == 3 {
  2888. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2889. if p.Price != lastWarehouse.PackingPrice {
  2890. p.Price = lastWarehouse.PackingPrice
  2891. }
  2892. if p.Unit == "" {
  2893. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2894. p.Unit = goodInfoOne.PackingUnit
  2895. }
  2896. }
  2897. }
  2898. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2899. //
  2900. // if p.Type == 3 {
  2901. // //查询该耗材是否停用
  2902. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2903. // //表示该耗材已经停用,不能保存
  2904. // if goodInfoSeven.ID == 0 {
  2905. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2906. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2907. // return
  2908. // }
  2909. // }
  2910. //
  2911. //}
  2912. service.CreateHisProjectTwo(&p)
  2913. //记录日志
  2914. byterequest, _ := json.Marshal(p)
  2915. adviceLog := models.XtDoctorAdviceLog{
  2916. UserOrgId: p.UserOrgId,
  2917. PatientId: p.PatientId,
  2918. AdminUserId: adminInfo.AdminUser.Id,
  2919. Module: 1,
  2920. ErrLog: string(byterequest),
  2921. Status: 1,
  2922. Ctime: time.Now().Unix(),
  2923. Mtime: 0,
  2924. Source: "电脑端新建his项目",
  2925. RecordDate: p.RecordDate,
  2926. }
  2927. service.CreateDoctorAdviceLog(adviceLog)
  2928. projectList = append(projectList, p)
  2929. var randNum int
  2930. randNum = rand.Intn(10000) + 1000
  2931. timestamp := time.Now().Unix()
  2932. tempTime := time.Unix(timestamp, 0)
  2933. timeFormat := tempTime.Format("20060102150405")
  2934. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2935. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2936. //新增或者编辑项目,修改对应的标签数据
  2937. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2938. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2939. var label models.HisLabelPrintInfo
  2940. project, _ := service.GetProjectDetail(p.ProjectId)
  2941. if project.CostClassify == 3 { //类别为检验检查
  2942. if p.TeamId > 0 { //检验检查组套
  2943. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2944. if tempLabel.ID == 0 {
  2945. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2946. label.Number = tempPrescription.PrescriptionNumber
  2947. label.ProjectId = project.ID
  2948. label.Status = 1
  2949. label.IsPrint = 2
  2950. label.DoctorId = info.DoctorId
  2951. label.UserOrgId = p.UserOrgId
  2952. label.PatientId = patient_id
  2953. label.RecordDate = recordDateTime
  2954. label.Ctime = time.Now().Unix()
  2955. label.Mtime = time.Now().Unix()
  2956. label.ItemId = p.TeamId
  2957. label.FeedetlSn = p.FeedetlSn
  2958. label.PProjectId = p.ID
  2959. label.ProjectName = team.ProjectTeam
  2960. label.PatientName = patient.Name
  2961. service.CreateHisLabelRecord(&label)
  2962. }
  2963. } else { //单条检验检查项目
  2964. label.Number = tempPrescription.PrescriptionNumber
  2965. label.ProjectId = project.ID
  2966. label.Status = 1
  2967. label.DoctorId = info.DoctorId
  2968. label.UserOrgId = p.UserOrgId
  2969. label.PatientId = patient_id
  2970. label.RecordDate = recordDateTime
  2971. label.IsPrint = 2
  2972. label.Ctime = time.Now().Unix()
  2973. label.Mtime = time.Now().Unix()
  2974. label.FeedetlSn = p.FeedetlSn
  2975. label.PProjectId = p.ID
  2976. label.ItemId = p.TeamId
  2977. label.ProjectName = project.ProjectName
  2978. label.PatientName = patient.Name
  2979. service.CreateHisLabelRecord(&label)
  2980. }
  2981. }
  2982. }
  2983. }
  2984. service.SaveHisProjectTwo(&p)
  2985. }
  2986. }
  2987. }
  2988. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2989. // addition := items["addition"].([]interface{})
  2990. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2991. // ctime := time.Now().Unix()
  2992. // mtime := ctime
  2993. // if len(addition) > 0 {
  2994. // for _, item := range addition {
  2995. // var s models.HisAdditionalCharge
  2996. // s.PrescriptionId = tempPrescription.ID
  2997. // s.Status = 1
  2998. // s.UserOrgId = adminInfo.CurrentOrgId
  2999. // s.RecordDate = recordDateTime
  3000. // s.CreatedTime = ctime
  3001. // s.UpdatedTime = mtime
  3002. // s.PatientId = patient_id
  3003. // s.HisPatientId = his_patient_id
  3004. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3005. // if errcode > 0 {
  3006. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3007. // return
  3008. // }
  3009. // service.CreateAdditionalCharge(&s)
  3010. // var randNum int
  3011. // randNum = rand.Intn(10000) + 1000
  3012. // timestamp := time.Now().Unix()
  3013. // tempTime := time.Unix(timestamp, 0)
  3014. // timeFormat := tempTime.Format("20060102150405")
  3015. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3016. // service.CreateAdditionalCharge(&s)
  3017. //
  3018. // }
  3019. // }
  3020. //}
  3021. }
  3022. }
  3023. //查询今日该患者开的药品处方
  3024. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3025. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3026. //药品出库
  3027. if drugOutConfig.IsOpen == 1 {
  3028. for _, item := range hisdoctorlist {
  3029. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3030. // 查询该药品最后一次出库记录
  3031. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3032. if len(druginfo) > 0 {
  3033. //回退库存
  3034. for _, it := range druginfo {
  3035. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3036. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3037. }
  3038. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3039. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3040. }
  3041. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3042. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3043. }
  3044. }
  3045. }
  3046. //删除记录
  3047. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3048. //查询最后一次数据
  3049. if drugOutConfig.IsOpen == 1 {
  3050. //出库
  3051. if drug.IsUse == 2 {
  3052. creater := adminInfo.AdminUser.Id
  3053. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3054. }
  3055. //更新字典里面的库存
  3056. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3057. var sum_count int64
  3058. for _, its := range stockInfo {
  3059. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3060. if its.MaxUnit == baseDrug.MaxUnit {
  3061. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3062. }
  3063. sum_count += its.StockMaxNumber + its.StockMinNumber
  3064. }
  3065. //更新基础库存
  3066. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3067. //剩余库存
  3068. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3069. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3070. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3071. }
  3072. }
  3073. }
  3074. //耗材保存处方出库
  3075. if goodOutConfig.IsOpen == 1 {
  3076. //查询今日耗材出库数量
  3077. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3078. for _, item := range hisgoodlist {
  3079. //查询历史出库数据
  3080. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3081. var out_count_five int64
  3082. for _, item := range flowGood {
  3083. out_count_five += item.Count
  3084. }
  3085. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3086. if out_count_five != parseIntCount {
  3087. //查询耗材最后一次出库记录
  3088. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3089. //查询默认出库仓库库存
  3090. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3091. if len(wareOut) > 0 {
  3092. for _, it := range wareOut {
  3093. //回退库存
  3094. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3095. //删除出库记录
  3096. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3097. }
  3098. }
  3099. timeStr := time.Now().Format("2006-01-02")
  3100. timeArr := strings.Split(timeStr, "-")
  3101. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3102. total = total + 1
  3103. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3104. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3105. number = number + total
  3106. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3107. operation_time := time.Now().Unix()
  3108. creater := c.GetAdminUserInfo().AdminUser.Id
  3109. recordDateStr := time.Now().Format("2006-01-02")
  3110. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3111. nowtime := recordDate.Unix()
  3112. warehouseOut := models.WarehouseOut{
  3113. WarehouseOutOrderNumber: warehousing_out_order,
  3114. OperationTime: operation_time,
  3115. OrgId: adminInfo.CurrentOrgId,
  3116. Creater: creater,
  3117. Ctime: time.Now().Unix(),
  3118. Status: 1,
  3119. WarehouseOutTime: nowtime,
  3120. Type: 1,
  3121. StorehouseId: storeConfig.StorehouseOutInfo,
  3122. IsCheck: 1,
  3123. IsSys: 1,
  3124. }
  3125. //查询是否生成出库单
  3126. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3127. if out.ID == 0 {
  3128. service.AddSigleWarehouseOut(&warehouseOut)
  3129. }
  3130. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3131. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3132. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3133. dialyPrepareOne := models.DialysisBeforePrepare{
  3134. GoodTypeId: goodObj.GoodTypeId,
  3135. GoodId: item.ProjectId,
  3136. PatientId: item.PatientId,
  3137. RecordDate: item.RecordDate,
  3138. UserOrgId: adminInfo.CurrentOrgId,
  3139. Count: parseIntCount,
  3140. Ctime: time.Now().Unix(),
  3141. Creater: creater,
  3142. Status: 1,
  3143. StorehouseId: houseConfig.StorehouseOutInfo,
  3144. ProjectId: item.ID,
  3145. }
  3146. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3147. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3148. //查询历史出库数据
  3149. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3150. var out_count int64
  3151. for _, item := range flowGood {
  3152. out_count += item.Count
  3153. }
  3154. //如果历史数和当前数据不想等才进行退库出库
  3155. if out_count != parseIntCount {
  3156. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3157. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3158. detail := models.AutomaticReduceDetail{
  3159. WarehouseOutId: 0,
  3160. WarehouseOutOrderNumber: "",
  3161. PatientId: item.PatientId,
  3162. Ctime: time.Now().Unix(),
  3163. Mtime: 0,
  3164. Status: 1,
  3165. RecordTime: item.RecordDate,
  3166. OrgId: item.UserOrgId,
  3167. GoodId: item.ProjectId,
  3168. GoodTypeId: 0,
  3169. Count: parseIntCount,
  3170. Type: 0,
  3171. ProjectId: item.ID,
  3172. StorehouseId: 0,
  3173. }
  3174. service.CreateAutoDetail(detail)
  3175. //查询剩余库存
  3176. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3177. var sum_count int64
  3178. for _, item := range goodList {
  3179. sum_count += item.StockCount
  3180. }
  3181. //更新剩余库存
  3182. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3183. //耗材
  3184. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3185. }
  3186. }
  3187. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3188. //查询历史出库数据
  3189. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3190. var out_count int64
  3191. for _, item := range flowGood {
  3192. out_count += item.Count
  3193. }
  3194. //如果历史数和当前数据不想等才进行退库出库
  3195. if out_count != parseIntCount {
  3196. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3197. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3198. detail := models.AutomaticReduceDetail{
  3199. WarehouseOutId: 0,
  3200. WarehouseOutOrderNumber: "",
  3201. PatientId: item.PatientId,
  3202. Ctime: time.Now().Unix(),
  3203. Mtime: 0,
  3204. Status: 1,
  3205. RecordTime: item.RecordDate,
  3206. OrgId: item.UserOrgId,
  3207. GoodId: item.ProjectId,
  3208. GoodTypeId: 0,
  3209. Count: parseIntCount,
  3210. Type: 0,
  3211. ProjectId: item.ID,
  3212. StorehouseId: 0,
  3213. }
  3214. service.CreateAutoDetail(detail)
  3215. //查询剩余库存
  3216. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3217. var sum_count int64
  3218. for _, item := range goodList {
  3219. sum_count += item.StockCount
  3220. }
  3221. //更新剩余库存
  3222. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3223. //耗材
  3224. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3225. }
  3226. }
  3227. }
  3228. }
  3229. }
  3230. }
  3231. //redisClient := service.RedisClient()
  3232. //defer redisClient.Close()
  3233. //
  3234. //list := models.HisList{
  3235. // Patient_id: patient_id,
  3236. // Advice_id:0,
  3237. // Record_date: 0,
  3238. // Advice: adviceList,
  3239. // Project: nil,
  3240. //}
  3241. //hisLis = append(hisLis, list)
  3242. //
  3243. //advice_json, _ := json.Marshal(&hisLis)
  3244. //redisClient.RPush("111", advice_json).Result()
  3245. //result, _ := redisClient.RPop("111").Result()
  3246. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3247. //
  3248. //var dat []map[string]interface{}
  3249. //json.Unmarshal([]byte(result), &dat)
  3250. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3251. //
  3252. //for k,v:=range dat{
  3253. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3254. //}
  3255. //project_json, _ := json.Marshal(&projectList)
  3256. //redisClient.LPush("222", project_json).Result()
  3257. if err == nil {
  3258. c.ServeSuccessJSON(map[string]interface{}{
  3259. "msg": "保存成功",
  3260. })
  3261. return
  3262. } else {
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3264. return
  3265. }
  3266. }
  3267. func (c *HisApiController) EditHisPrescription() {
  3268. record_date := c.GetString("record_date")
  3269. patient_id, _ := c.GetInt64("patient_id")
  3270. reg_type, _ := c.GetInt64("reg_type")
  3271. //diagnose, _ := c.GetInt64("diagnose", 0)
  3272. diagnose := c.GetString("diagnose")
  3273. sick_type, _ := c.GetInt64("sick_type")
  3274. sick_history := c.GetString("sick_history")
  3275. doctor_id, _ := c.GetInt64("doctor", 0)
  3276. department, _ := c.GetInt64("department", 0)
  3277. his_patient_id, _ := c.GetInt64("his_patient_id")
  3278. p_type, _ := c.GetInt64("p_type")
  3279. dataBody := make(map[string]interface{}, 0)
  3280. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3281. if err != nil {
  3282. utils.ErrorLog(err.Error())
  3283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3284. return
  3285. }
  3286. timeLayout := "2006-01-02"
  3287. loc, _ := time.LoadLocation("Local")
  3288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3289. if err != nil {
  3290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3291. return
  3292. }
  3293. adminInfo := c.GetAdminUserInfo()
  3294. recordDateTime := theTime.Unix()
  3295. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3296. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3297. var hpInfo models.HisPrescriptionInfo
  3298. if info.ID == 0 {
  3299. var randNum int
  3300. randNum = rand.Intn(10000) + 1000
  3301. timestamp := time.Now().Unix()
  3302. tempTime := time.Unix(timestamp, 0)
  3303. timeFormat := tempTime.Format("20060102150405")
  3304. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3305. hpInfo = models.HisPrescriptionInfo{
  3306. UserOrgId: adminInfo.CurrentOrgId,
  3307. RecordDate: theTime.Unix(),
  3308. PatientId: patient_id,
  3309. Status: 1,
  3310. Ctime: time.Now().Unix(),
  3311. Mtime: time.Now().Unix(),
  3312. Creator: adminInfo.AdminUser.Id,
  3313. Modifier: adminInfo.AdminUser.Id,
  3314. Diagnosis: diagnose,
  3315. SickHistory: sick_history,
  3316. Departments: department,
  3317. RegisterType: reg_type,
  3318. PrescriptionNumber: p_number,
  3319. PrescriptionStatus: 1,
  3320. Doctor: role.UserName,
  3321. DoctorId: doctor_id,
  3322. SickType: sick_type,
  3323. PType: p_type,
  3324. }
  3325. service.SavePatientPrescriptionInfo(hpInfo)
  3326. } else {
  3327. hpInfo = models.HisPrescriptionInfo{
  3328. ID: info.ID,
  3329. UserOrgId: adminInfo.CurrentOrgId,
  3330. RecordDate: info.RecordDate,
  3331. PatientId: info.PatientId,
  3332. Status: 1,
  3333. Ctime: info.Ctime,
  3334. Mtime: time.Now().Unix(),
  3335. Creator: info.Creator,
  3336. Modifier: adminInfo.AdminUser.Id,
  3337. Diagnosis: diagnose,
  3338. SickHistory: sick_history,
  3339. Departments: department,
  3340. RegisterType: reg_type,
  3341. PrescriptionNumber: info.PrescriptionNumber,
  3342. Doctor: role.UserName,
  3343. PrescriptionStatus: info.PrescriptionStatus,
  3344. DoctorId: doctor_id,
  3345. SickType: sick_type,
  3346. PType: info.PType,
  3347. }
  3348. service.SavePatientPrescriptionInfo(hpInfo)
  3349. }
  3350. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3351. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3352. if len(prescriptions) > 0 {
  3353. for _, item := range prescriptions {
  3354. items := item.(map[string]interface{})
  3355. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3356. utils.ErrorLog("id")
  3357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3358. return
  3359. }
  3360. id := int64(items["id"].(float64))
  3361. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3362. utils.ErrorLog("type")
  3363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3364. return
  3365. }
  3366. types := int64(items["type"].(float64))
  3367. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3368. utils.ErrorLog("med_type")
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3370. return
  3371. }
  3372. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3373. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3374. ctime := time.Now().Unix()
  3375. prescription := &models.HisPrescription{
  3376. ID: id,
  3377. PatientId: patient_id,
  3378. UserOrgId: adminInfo.CurrentOrgId,
  3379. RecordDate: recordDateTime,
  3380. Ctime: ctime,
  3381. Mtime: ctime,
  3382. Type: types,
  3383. Modifier: adminInfo.AdminUser.Id,
  3384. Creator: adminInfo.AdminUser.Id,
  3385. Status: 1,
  3386. Doctor: role.UserName,
  3387. HisPatientId: his_patient_id,
  3388. OrderStatus: 1,
  3389. BatchNumber: "",
  3390. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3391. PType: hpInfo.PType,
  3392. MedType: med_type,
  3393. }
  3394. if historyPrescription.ID > 0 {
  3395. prescription.PreTime = historyPrescription.PreTime
  3396. }
  3397. service.SaveHisPrescription(prescription)
  3398. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3399. advices := items["advices"].([]interface{})
  3400. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3401. groupNo := int64(0)
  3402. ctime := time.Now().Unix()
  3403. mtime := ctime
  3404. if len(advices) > 0 {
  3405. for _, advice := range advices {
  3406. var s models.HisDoctorAdviceInfo
  3407. s.PrescriptionId = prescription.ID
  3408. s.AdviceType = 2
  3409. s.AdviceDoctor = adminInfo.AdminUser.Id
  3410. s.StopState = 2
  3411. s.ExecutionState = 2
  3412. s.AdviceDate = recordDateTime
  3413. s.Status = 1
  3414. s.UserOrgId = adminInfo.CurrentOrgId
  3415. s.RecordDate = recordDateTime
  3416. s.StartTime = prescription.PreTime
  3417. s.Groupno = groupNo
  3418. s.CreatedTime = ctime
  3419. s.UpdatedTime = mtime
  3420. s.PatientId = patient_id
  3421. s.HisPatientId = his_patient_id
  3422. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3423. if errcode > 0 {
  3424. c.ServeFailJSONWithSGJErrorCode(errcode)
  3425. return
  3426. }
  3427. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3428. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3429. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3430. if s.Price == 0 {
  3431. s.Price = lastWarehouse.RetailPrice
  3432. }
  3433. }
  3434. service.CreateHisDoctorAdvice(&s)
  3435. //记录日志
  3436. byterequest, _ := json.Marshal(s)
  3437. adviceLog := models.XtDoctorAdviceLog{
  3438. UserOrgId: s.UserOrgId,
  3439. PatientId: s.PatientId,
  3440. AdminUserId: adminInfo.AdminUser.Id,
  3441. Module: 1,
  3442. ErrLog: string(byterequest),
  3443. Status: 1,
  3444. Ctime: time.Now().Unix(),
  3445. Mtime: 0,
  3446. Source: "电脑端his医嘱修改",
  3447. RecordDate: s.AdviceDate,
  3448. }
  3449. service.CreateDoctorAdviceLog(adviceLog)
  3450. redis := service.RedisClient()
  3451. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3452. redis.Set(key, "", time.Second)
  3453. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3454. fmt.Println("keyOne", keyOne)
  3455. redis.Set(keyOne, "", time.Second)
  3456. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3457. redis.Set(keySeven, "", time.Second)
  3458. redis.Close()
  3459. }
  3460. }
  3461. }
  3462. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3463. projects := items["project"].([]interface{})
  3464. if len(projects) > 0 {
  3465. for _, project := range projects {
  3466. var p models.HisPrescriptionProject
  3467. p.PrescriptionId = prescription.ID
  3468. p.Ctime = time.Now().Unix()
  3469. p.Mtime = time.Now().Unix()
  3470. p.PatientId = patient_id
  3471. p.RecordDate = recordDateTime
  3472. p.UserOrgId = adminInfo.CurrentOrgId
  3473. p.HisPatientId = his_patient_id
  3474. p.Status = 1
  3475. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3476. if errcode > 0 {
  3477. c.ServeFailJSONWithSGJErrorCode(errcode)
  3478. return
  3479. }
  3480. service.CreateHisProjectTwo(&p)
  3481. //记录日志
  3482. byterequest, _ := json.Marshal(p)
  3483. adviceLog := models.XtDoctorAdviceLog{
  3484. UserOrgId: p.UserOrgId,
  3485. PatientId: p.PatientId,
  3486. AdminUserId: adminInfo.AdminUser.Id,
  3487. Module: 1,
  3488. ErrLog: string(byterequest),
  3489. Status: 1,
  3490. Ctime: time.Now().Unix(),
  3491. Mtime: 0,
  3492. Source: "电脑端his项目修改",
  3493. RecordDate: p.RecordDate,
  3494. }
  3495. service.CreateDoctorAdviceLog(adviceLog)
  3496. }
  3497. }
  3498. }
  3499. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3500. addition := items["addition"].([]interface{})
  3501. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3502. ctime := time.Now().Unix()
  3503. mtime := ctime
  3504. if len(addition) > 0 {
  3505. for _, item := range addition {
  3506. var s models.HisAdditionalCharge
  3507. s.PrescriptionId = prescription.ID
  3508. s.Status = 1
  3509. s.UserOrgId = adminInfo.CurrentOrgId
  3510. s.RecordDate = recordDateTime
  3511. s.CreatedTime = ctime
  3512. s.UpdatedTime = mtime
  3513. s.PatientId = patient_id
  3514. s.HisPatientId = his_patient_id
  3515. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3516. if errcode > 0 {
  3517. c.ServeFailJSONWithSGJErrorCode(errcode)
  3518. return
  3519. }
  3520. service.CreateAdditionalCharge(&s)
  3521. }
  3522. }
  3523. }
  3524. }
  3525. }
  3526. }
  3527. if err == nil {
  3528. c.ServeSuccessJSON(map[string]interface{}{
  3529. "msg": "保存成功",
  3530. })
  3531. return
  3532. } else {
  3533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3534. return
  3535. }
  3536. }
  3537. func (c *HisApiController) DeletePrescription() {
  3538. prescription_id, _ := c.GetInt64("id")
  3539. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3540. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3541. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3542. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3543. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3544. //耗材保存处方出库
  3545. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3546. //已收费和已发药限制逻辑
  3547. isCharge := false
  3548. isMedicine := false
  3549. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3550. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3551. for _, item := range new_prescriptions {
  3552. if item.IsMedicine == 1 {
  3553. isMedicine = true
  3554. }
  3555. }
  3556. for _, item := range new_prescriptions {
  3557. if item.OrderStatus == 4 {
  3558. isCharge = true
  3559. }
  3560. }
  3561. if p_err != nil {
  3562. if new_prescription.ID > 0 {
  3563. if new_prescription.OrderStatus == 2 {
  3564. isCharge = true
  3565. }
  3566. }
  3567. }
  3568. for _, item := range advices {
  3569. if item.IsMedicine == 1 {
  3570. isMedicine = true
  3571. }
  3572. }
  3573. if isCharge {
  3574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3575. return
  3576. }
  3577. if isMedicine {
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3579. return
  3580. }
  3581. //已收费和已发药限制逻辑
  3582. if len(projects) > 0 {
  3583. for _, item := range projects {
  3584. service.DeletePrintInfo(item.ID) //删除打印信息
  3585. if goodOutConfig.IsOpen != 1 {
  3586. if stockConfig.IsOpen == 1 {
  3587. if item.Type == 3 && item.IsOut == 1 {
  3588. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3589. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3590. good.Total = good.Total + f_count
  3591. service.UpdateGoodInfo(&good)
  3592. operation_time := time.Now().Unix()
  3593. creater := c.GetAdminUserInfo().AdminUser.Id
  3594. //创建退库单
  3595. timeStr := time.Now().Format("2006-01-02")
  3596. timeArr := strings.Split(timeStr, "-")
  3597. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3598. total = total + 1
  3599. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3600. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3601. cancelStock := models.CancelStock{
  3602. OrderNumber: orderNumber,
  3603. OperaTime: operation_time,
  3604. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3605. Creater: creater,
  3606. Ctime: time.Now().Unix(),
  3607. Status: 1,
  3608. ReturnTime: item.RecordDate,
  3609. Type: 1,
  3610. StorehouseId: houseConfig.StorehouseOutInfo,
  3611. IsCheck: 1,
  3612. }
  3613. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3614. if msgerrkonde == gorm.ErrRecordNotFound {
  3615. service.AddSigleCancelStock(&cancelStock)
  3616. }
  3617. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3618. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3619. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3620. //查询该耗材是否出库
  3621. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3622. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3623. deaerler, _ := service.GetDealerById(info.Dealer)
  3624. var total_count int64
  3625. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3626. total_count += count
  3627. if info.ID > 0 {
  3628. if info.Count >= total_count {
  3629. //回退库存
  3630. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3631. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3632. var flush_count int64
  3633. for _, it := range goodList {
  3634. flush_count += it.StockCount
  3635. }
  3636. cancelStockInfo := models.CancelStockInfo{
  3637. GoodId: item.ProjectId,
  3638. CancelStockId: cancel.ID,
  3639. GoodTypeId: good.GoodTypeId,
  3640. Count: prescribingNumber,
  3641. Price: info.Price,
  3642. Total: 0,
  3643. ProductDate: info.ProductDate,
  3644. ExpiryDate: info.ExpiryDate,
  3645. Ctime: time.Now().Unix(),
  3646. Status: 1,
  3647. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3648. OrderNumber: cancel.OrderNumber,
  3649. Type: 0,
  3650. Dealer: deaerler.DealerName,
  3651. Manufacturer: manufacturer.ManufacturerName,
  3652. Number: info.Number,
  3653. RegisterAccount: "",
  3654. Remark: "",
  3655. WarehouseInfoId: info.WarehouseInfotId,
  3656. PatientId: info.PatientId,
  3657. RecordDate: info.SysRecordTime,
  3658. StorehouseId: houseConfig.StorehouseOutInfo,
  3659. IsCheck: 1,
  3660. }
  3661. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3662. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3663. flow := models.VmStockFlow{
  3664. WarehousingId: info.WarehouseInfotId,
  3665. GoodId: item.ProjectId,
  3666. Number: info.Number,
  3667. LicenseNumber: info.LicenseNumber,
  3668. Count: prescribingNumber,
  3669. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3670. PatientId: item.PatientId,
  3671. SystemTime: info.SysRecordTime,
  3672. ConsumableType: 7,
  3673. IsSys: 0,
  3674. WarehousingOrder: "",
  3675. WarehouseOutId: info.WarehouseOutId,
  3676. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3677. IsEdit: 0,
  3678. CancelStockId: cancel.ID,
  3679. CancelOrderNumber: cancel.OrderNumber,
  3680. Manufacturer: manufacturer.ID,
  3681. Dealer: 0,
  3682. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3683. UpdateCreator: 0,
  3684. Status: 1,
  3685. Ctime: time.Now().Unix(),
  3686. Mtime: 0,
  3687. Price: info.Price,
  3688. WarehousingDetailId: info.WarehouseInfotId,
  3689. WarehouseOutDetailId: info.ID,
  3690. CancelOutDetailId: cancelInfo.ID,
  3691. ProductDate: info.ProductDate,
  3692. ExpireDate: info.ExpiryDate,
  3693. StorehouseId: houseConfig.StorehouseOutInfo,
  3694. OverCount: flush_count,
  3695. }
  3696. service.CreateStockFlowOne(flow)
  3697. //退库数量增加
  3698. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3699. //出库数量减少
  3700. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3701. }
  3702. if info.Count < total_count {
  3703. //回退库存
  3704. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3705. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3706. var flush_count int64
  3707. for _, it := range goodList {
  3708. flush_count += it.StockCount
  3709. }
  3710. cancelStockInfo := models.CancelStockInfo{
  3711. GoodId: item.ProjectId,
  3712. CancelStockId: cancel.ID,
  3713. GoodTypeId: good.GoodTypeId,
  3714. Count: info.Count,
  3715. Price: info.Price,
  3716. Total: 0,
  3717. ProductDate: info.ProductDate,
  3718. ExpiryDate: info.ExpiryDate,
  3719. Ctime: time.Now().Unix(),
  3720. Status: 1,
  3721. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3722. OrderNumber: cancel.OrderNumber,
  3723. Type: 0,
  3724. Dealer: deaerler.DealerName,
  3725. Manufacturer: manufacturer.ManufacturerName,
  3726. Number: info.Number,
  3727. RegisterAccount: "",
  3728. Remark: "",
  3729. WarehouseInfoId: info.WarehouseInfotId,
  3730. PatientId: info.PatientId,
  3731. RecordDate: info.SysRecordTime,
  3732. StorehouseId: houseConfig.StorehouseOutInfo,
  3733. IsCheck: 1,
  3734. }
  3735. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3736. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3737. flow := models.VmStockFlow{
  3738. WarehousingId: info.WarehouseInfotId,
  3739. GoodId: item.ProjectId,
  3740. Number: info.Number,
  3741. LicenseNumber: info.LicenseNumber,
  3742. Count: info.Count,
  3743. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3744. PatientId: item.PatientId,
  3745. SystemTime: info.SysRecordTime,
  3746. ConsumableType: 7,
  3747. IsSys: 0,
  3748. WarehousingOrder: "",
  3749. WarehouseOutId: info.WarehouseOutId,
  3750. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3751. IsEdit: 0,
  3752. CancelStockId: cancel.ID,
  3753. CancelOrderNumber: cancel.OrderNumber,
  3754. Manufacturer: manufacturer.ID,
  3755. Dealer: 0,
  3756. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3757. UpdateCreator: 0,
  3758. Status: 1,
  3759. Ctime: time.Now().Unix(),
  3760. Mtime: 0,
  3761. Price: info.Price,
  3762. WarehousingDetailId: info.WarehouseInfotId,
  3763. WarehouseOutDetailId: info.ID,
  3764. CancelOutDetailId: cancelInfo.ID,
  3765. ProductDate: info.ProductDate,
  3766. ExpireDate: info.ExpiryDate,
  3767. StorehouseId: houseConfig.StorehouseOutInfo,
  3768. OverCount: flush_count,
  3769. }
  3770. service.CreateStockFlowOne(flow)
  3771. //退库数量增加
  3772. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3773. //出库数量减少
  3774. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3775. }
  3776. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3777. var flush_count int64
  3778. for _, it := range goodList {
  3779. flush_count += it.StockCount
  3780. }
  3781. //查询已出库数量
  3782. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3783. if prescribingNumber < dialysisInfo.Count {
  3784. //改变数量
  3785. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3786. }
  3787. if prescribingNumber >= dialysisInfo.Count {
  3788. //删除出库表
  3789. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3790. }
  3791. //更新库存
  3792. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3793. //更新基础库库存
  3794. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3795. }
  3796. }
  3797. }
  3798. }
  3799. //保存耗材出库
  3800. if goodOutConfig.IsOpen == 1 {
  3801. if item.Type == 3 {
  3802. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3803. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3804. good.Total = good.Total + f_count
  3805. service.UpdateGoodInfo(&good)
  3806. operation_time := time.Now().Unix()
  3807. creater := c.GetAdminUserInfo().AdminUser.Id
  3808. //创建退库单
  3809. timeStr := time.Now().Format("2006-01-02")
  3810. timeArr := strings.Split(timeStr, "-")
  3811. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3812. total = total + 1
  3813. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3814. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3815. cancelStock := models.CancelStock{
  3816. OrderNumber: orderNumber,
  3817. OperaTime: operation_time,
  3818. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3819. Creater: creater,
  3820. Ctime: time.Now().Unix(),
  3821. Status: 1,
  3822. ReturnTime: item.RecordDate,
  3823. Type: 1,
  3824. StorehouseId: houseConfig.StorehouseOutInfo,
  3825. IsCheck: 1,
  3826. }
  3827. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3828. if msgerrkonde == gorm.ErrRecordNotFound {
  3829. service.AddSigleCancelStock(&cancelStock)
  3830. }
  3831. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3832. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3833. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3834. //查询该耗材是否出库
  3835. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3836. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3837. deaerler, _ := service.GetDealerById(info.Dealer)
  3838. var total_count int64
  3839. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3840. total_count += count
  3841. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3842. var flush_count int64
  3843. for _, it := range goodList {
  3844. flush_count += it.StockCount
  3845. }
  3846. fmt.Println("历史出库数据", info.Count)
  3847. fmt.Println("出库数量", total_count)
  3848. if info.ID > 0 {
  3849. cancelStockInfo := models.CancelStockInfo{
  3850. GoodId: item.ProjectId,
  3851. CancelStockId: cancel.ID,
  3852. GoodTypeId: good.GoodTypeId,
  3853. Count: prescribingNumber,
  3854. Price: info.Price,
  3855. Total: 0,
  3856. ProductDate: info.ProductDate,
  3857. ExpiryDate: info.ExpiryDate,
  3858. Ctime: time.Now().Unix(),
  3859. Status: 1,
  3860. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3861. OrderNumber: cancel.OrderNumber,
  3862. Type: 0,
  3863. Dealer: deaerler.DealerName,
  3864. Manufacturer: manufacturer.ManufacturerName,
  3865. Number: info.Number,
  3866. RegisterAccount: "",
  3867. Remark: "",
  3868. WarehouseInfoId: info.WarehouseInfotId,
  3869. PatientId: info.PatientId,
  3870. RecordDate: info.SysRecordTime,
  3871. StorehouseId: houseConfig.StorehouseOutInfo,
  3872. IsCheck: 1,
  3873. }
  3874. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3875. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3876. //查询出库数量
  3877. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3878. //出库数据 大于 退库数量
  3879. if len(list) > 0 {
  3880. for _, it := range list {
  3881. //回退库存
  3882. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3883. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3884. var flush_count_one int64
  3885. for _, it := range goodList {
  3886. flush_count_one += it.StockCount
  3887. }
  3888. //查询该批次是否有退库数据
  3889. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3890. creater := c.GetAdminUserInfo().AdminUser.Id
  3891. flow := models.VmStockFlow{
  3892. WarehousingId: it.WarehouseInfotId,
  3893. GoodId: it.GoodId,
  3894. Number: it.Number,
  3895. LicenseNumber: it.LicenseNumber,
  3896. Count: it.Count,
  3897. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3898. PatientId: it.PatientId,
  3899. SystemTime: it.SysRecordTime,
  3900. ConsumableType: 7,
  3901. IsSys: 0,
  3902. WarehousingOrder: "",
  3903. WarehouseOutId: it.WarehouseOutId,
  3904. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3905. IsEdit: 0,
  3906. CancelStockId: cancel.ID,
  3907. CancelOrderNumber: cancel.OrderNumber,
  3908. Manufacturer: manufacturer.ID,
  3909. Dealer: 0,
  3910. Creator: creater,
  3911. UpdateCreator: 0,
  3912. Status: 1,
  3913. Ctime: time.Now().Unix(),
  3914. Mtime: 0,
  3915. Price: it.Price,
  3916. WarehousingDetailId: it.WarehouseInfotId,
  3917. WarehouseOutDetailId: it.ID,
  3918. CancelOutDetailId: cancelInfo.ID,
  3919. ProductDate: it.ProductDate,
  3920. ExpireDate: it.ExpiryDate,
  3921. StorehouseId: houseConfig.StorehouseOutInfo,
  3922. OverCount: flush_count_one,
  3923. }
  3924. service.CreateStockFlowOne(flow)
  3925. //if flow.ID > 0 {
  3926. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3927. //}
  3928. }
  3929. }
  3930. //flow := models.VmStockFlow{
  3931. // WarehousingId: info.WarehouseInfotId,
  3932. // GoodId: item.ProjectId,
  3933. // Number: info.Number,
  3934. // LicenseNumber: info.LicenseNumber,
  3935. // Count: prescribingNumber,
  3936. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3937. // PatientId: item.PatientId,
  3938. // SystemTime: info.SysRecordTime,
  3939. // ConsumableType: 7,
  3940. // IsSys: 0,
  3941. // WarehousingOrder: "",
  3942. // WarehouseOutId: info.WarehouseOutId,
  3943. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3944. // IsEdit: 0,
  3945. // CancelStockId: cancel.ID,
  3946. // CancelOrderNumber: cancel.OrderNumber,
  3947. // Manufacturer: manufacturer.ID,
  3948. // Dealer: 0,
  3949. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3950. // UpdateCreator: 0,
  3951. // Status: 1,
  3952. // Ctime: time.Now().Unix(),
  3953. // Mtime: 0,
  3954. // Price: info.Price,
  3955. // WarehousingDetailId: info.WarehouseInfotId,
  3956. // WarehouseOutDetailId: info.ID,
  3957. // CancelOutDetailId: cancelInfo.ID,
  3958. // ProductDate: info.ProductDate,
  3959. // ExpireDate: info.ExpiryDate,
  3960. // StorehouseId: houseConfig.StorehouseOutInfo,
  3961. // OverCount: flush_count,
  3962. //}
  3963. //service.CreateStockFlowOne(flow)
  3964. //退库数量增加
  3965. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3966. //出库数量减少
  3967. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3968. //查询已出库数量
  3969. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3970. if prescribingNumber < dialysisInfo.Count {
  3971. //改变数量
  3972. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3973. }
  3974. if prescribingNumber >= dialysisInfo.Count {
  3975. //删除出库表
  3976. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3977. }
  3978. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3979. var flush_count_one int64
  3980. for _, it := range goodList {
  3981. flush_count_one += it.StockCount
  3982. }
  3983. //更新库存
  3984. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3985. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3986. //更新基础库库存
  3987. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3988. }
  3989. }
  3990. }
  3991. }
  3992. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3993. fmt.Println(err)
  3994. }
  3995. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3996. fmt.Println(err)
  3997. if len(advices) > 0 {
  3998. for _, item := range advices {
  3999. redis := service.RedisClient()
  4000. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4001. redis.Set(keyFive, "", time.Second)
  4002. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4003. redis.Set(keyOne, "", time.Second)
  4004. redis.Close()
  4005. }
  4006. }
  4007. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4008. if len(advices) > 0 {
  4009. for _, item := range advices {
  4010. creater := c.GetAdminUserInfo().AdminUser.Id
  4011. service.DrugAutoAddCancelInfo(item, creater)
  4012. }
  4013. }
  4014. } else {
  4015. if drugOutConfig.IsOpen == 1 {
  4016. if len(advices) > 0 {
  4017. for _, item := range advices {
  4018. creater := c.GetAdminUserInfo().AdminUser.Id
  4019. service.DrugAutoAddCancelInfo(item, creater)
  4020. }
  4021. }
  4022. } else {
  4023. if len(advices) > 0 {
  4024. for _, item := range advices {
  4025. creater := c.GetAdminUserInfo().AdminUser.Id
  4026. service.DrugAutoAddCancelInfo(item, creater)
  4027. }
  4028. }
  4029. }
  4030. }
  4031. c.ServeSuccessJSON(map[string]interface{}{
  4032. "msg": "删除成功",
  4033. })
  4034. return
  4035. }
  4036. func (c *HisApiController) DeleteDoctorAdvice() {
  4037. id, _ := c.GetInt64("id")
  4038. advice, _ := service.GetHisDoctorAdvicesById(id)
  4039. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4040. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4041. //已收费和已发药的限制逻辑
  4042. isCharge := false
  4043. isMedicine := false
  4044. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4045. //获取今天该患者所有处方,判断是否发药或者收费
  4046. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4047. for _, item := range new_prescriptions {
  4048. if item.IsMedicine == 1 {
  4049. isMedicine = true
  4050. }
  4051. }
  4052. for _, item := range new_prescriptions {
  4053. if item.OrderStatus == 4 {
  4054. isCharge = true
  4055. }
  4056. }
  4057. if isMedicine {
  4058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4059. return
  4060. }
  4061. if isCharge {
  4062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4063. return
  4064. }
  4065. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4066. for _, item := range advices {
  4067. if item.IsMedicine == 1 {
  4068. isMedicine = true
  4069. }
  4070. }
  4071. if isMedicine {
  4072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4073. return
  4074. }
  4075. if new_prescription.ID > 0 {
  4076. if new_prescription.OrderStatus == 2 {
  4077. isCharge = true
  4078. }
  4079. }
  4080. if isCharge {
  4081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4082. return
  4083. }
  4084. //已收费和已发药的限制逻辑
  4085. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4086. redis := service.RedisClient()
  4087. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4088. redis.Set(keyFive, "", time.Second)
  4089. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4090. redis.Set(keyOne, "", time.Second)
  4091. defer redis.Close()
  4092. if err == nil {
  4093. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4094. //查询是否在处方中出库
  4095. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4096. if openConfig.IsOpen != 1 {
  4097. //判断该医嘱是否执行了
  4098. if advice.ExecutionState == 1 {
  4099. creater := c.GetAdminUserInfo().AdminUser.Id
  4100. service.DrugAutoAddCancelInfo(&advice, creater)
  4101. }
  4102. }
  4103. //开启保存处方扣减功能
  4104. if openConfig.IsOpen == 1 {
  4105. creater := c.GetAdminUserInfo().AdminUser.Id
  4106. service.DrugAutoAddCancelInfo(&advice, creater)
  4107. }
  4108. } else {
  4109. if drugOutConfig.IsOpen == 1 {
  4110. //查询是否在处方中出库
  4111. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4112. if openConfig.IsOpen != 1 {
  4113. //判断该医嘱是否执行了
  4114. if advice.ExecutionState == 1 {
  4115. creater := c.GetAdminUserInfo().AdminUser.Id
  4116. service.DrugAutoAddCancelInfo(&advice, creater)
  4117. }
  4118. }
  4119. //开启保存处方扣减功能
  4120. if openConfig.IsOpen == 1 {
  4121. creater := c.GetAdminUserInfo().AdminUser.Id
  4122. service.DrugAutoAddCancelInfo(&advice, creater)
  4123. }
  4124. } else {
  4125. //判断该医嘱是否执行了
  4126. if advice.ExecutionState == 1 {
  4127. creater := c.GetAdminUserInfo().AdminUser.Id
  4128. service.DrugAutoAddCancelInfo(&advice, creater)
  4129. }
  4130. }
  4131. }
  4132. c.ServeSuccessJSON(map[string]interface{}{
  4133. "msg": "删除成功",
  4134. })
  4135. return
  4136. } else {
  4137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4138. return
  4139. }
  4140. }
  4141. func (c *HisApiController) DeleteProject() {
  4142. id, _ := c.GetInt64("id")
  4143. adminInfo := c.GetAdminUserInfo()
  4144. project, _ := service.GetHisProjectByID(id)
  4145. // var consumable models.DialysisBeforePrepare
  4146. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4147. //耗材保存处方出库
  4148. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4149. isCharge := false
  4150. isMedicine := false
  4151. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4152. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4153. for _, item := range new_prescriptions {
  4154. if item.IsMedicine == 1 {
  4155. isMedicine = true
  4156. }
  4157. }
  4158. for _, item := range new_prescriptions {
  4159. if item.OrderStatus == 4 {
  4160. isCharge = true
  4161. }
  4162. }
  4163. if isMedicine {
  4164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4165. return
  4166. }
  4167. if isCharge {
  4168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4169. return
  4170. }
  4171. if new_prescription.ID > 0 {
  4172. if new_prescription.OrderStatus == 2 {
  4173. isCharge = true
  4174. }
  4175. }
  4176. if isCharge {
  4177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4178. return
  4179. }
  4180. service.DeletePrintInfo(id)
  4181. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4182. label.Status = 0
  4183. service.CreateHisLabelRecord(&label)
  4184. fmt.Println(goodOutConfig.IsOpen)
  4185. if goodOutConfig.IsOpen != 1 {
  4186. if stockConfig.IsOpen == 1 {
  4187. if project.Type == 2 {
  4188. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4189. fmt.Println(err)
  4190. }
  4191. if project.Type == 3 && project.IsOut == 1 {
  4192. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4193. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4194. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4195. operation_time := time.Now().Unix()
  4196. creater := adminInfo.AdminUser.Id
  4197. //创建退库单
  4198. timeStr := time.Now().Format("2006-01-02")
  4199. timeArr := strings.Split(timeStr, "-")
  4200. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4201. total = total + 1
  4202. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4203. cancelStock := models.CancelStock{
  4204. OrderNumber: orderNumber,
  4205. OperaTime: operation_time,
  4206. OrgId: adminInfo.CurrentOrgId,
  4207. Creater: creater,
  4208. Ctime: time.Now().Unix(),
  4209. Status: 1,
  4210. ReturnTime: project.RecordDate,
  4211. Type: 1,
  4212. StorehouseId: houseConfig.StorehouseOutInfo,
  4213. IsCheck: 1,
  4214. }
  4215. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4216. if msgerrkonde == gorm.ErrRecordNotFound {
  4217. service.AddSigleCancelStock(&cancelStock)
  4218. }
  4219. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4220. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4221. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4222. //查询是否有出库
  4223. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4224. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4225. deaerler, _ := service.GetDealerById(info.Dealer)
  4226. if info.ID > 0 {
  4227. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4228. if info.Count >= prescribingNumber {
  4229. cancelStockInfo := models.CancelStockInfo{
  4230. GoodId: project.ProjectId,
  4231. CancelStockId: cancel.ID,
  4232. GoodTypeId: good.GoodTypeId,
  4233. Count: prescribingNumber,
  4234. Price: info.Price,
  4235. Total: 0,
  4236. ProductDate: info.ProductDate,
  4237. ExpiryDate: info.ExpiryDate,
  4238. Ctime: time.Now().Unix(),
  4239. Status: 1,
  4240. OrgId: adminInfo.CurrentOrgId,
  4241. OrderNumber: cancel.OrderNumber,
  4242. Type: 0,
  4243. Dealer: deaerler.DealerName,
  4244. Manufacturer: manufacturer.ManufacturerName,
  4245. Number: info.Number,
  4246. RegisterAccount: "",
  4247. Remark: "",
  4248. WarehouseInfoId: info.WarehouseInfotId,
  4249. PatientId: info.PatientId,
  4250. RecordDate: info.SysRecordTime,
  4251. StorehouseId: houseConfig.StorehouseOutInfo,
  4252. IsCheck: 1,
  4253. }
  4254. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4255. //回退库存
  4256. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4257. //退库数量增加
  4258. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4259. //出库数量减少
  4260. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4261. }
  4262. if info.Count < prescribingNumber {
  4263. cancelStockInfo := models.CancelStockInfo{
  4264. GoodId: project.ProjectId,
  4265. CancelStockId: cancel.ID,
  4266. GoodTypeId: good.GoodTypeId,
  4267. Count: info.Count,
  4268. Price: info.Price,
  4269. Total: 0,
  4270. ProductDate: info.ProductDate,
  4271. ExpiryDate: info.ExpiryDate,
  4272. Ctime: time.Now().Unix(),
  4273. Status: 1,
  4274. OrgId: adminInfo.CurrentOrgId,
  4275. OrderNumber: cancel.OrderNumber,
  4276. Type: 0,
  4277. Dealer: deaerler.DealerName,
  4278. Manufacturer: manufacturer.ManufacturerName,
  4279. Number: info.Number,
  4280. RegisterAccount: "",
  4281. Remark: "",
  4282. WarehouseInfoId: info.WarehouseInfotId,
  4283. PatientId: info.PatientId,
  4284. RecordDate: info.SysRecordTime,
  4285. StorehouseId: houseConfig.StorehouseOutInfo,
  4286. IsCheck: 1,
  4287. }
  4288. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4289. //回退库存
  4290. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4291. //退库数量增加
  4292. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4293. //出库数量减少
  4294. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4295. }
  4296. //查询剩余库存
  4297. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4298. var over_count int64
  4299. for _, it := range goodList {
  4300. over_count += it.StockCount
  4301. }
  4302. //出库数据 大于 退库数量
  4303. if info.Count >= prescribingNumber {
  4304. flow := models.VmStockFlow{
  4305. WarehousingId: info.WarehouseInfotId,
  4306. GoodId: project.ProjectId,
  4307. Number: info.Number,
  4308. LicenseNumber: info.LicenseNumber,
  4309. Count: prescribingNumber,
  4310. UserOrgId: adminInfo.CurrentOrgId,
  4311. PatientId: project.PatientId,
  4312. SystemTime: info.SysRecordTime,
  4313. ConsumableType: 7,
  4314. IsSys: 0,
  4315. WarehousingOrder: "",
  4316. WarehouseOutId: info.WarehouseOutId,
  4317. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4318. IsEdit: 0,
  4319. CancelStockId: cancel.ID,
  4320. CancelOrderNumber: cancel.OrderNumber,
  4321. Manufacturer: manufacturer.ID,
  4322. Dealer: 0,
  4323. Creator: adminInfo.AdminUser.Id,
  4324. UpdateCreator: 0,
  4325. Status: 1,
  4326. Ctime: time.Now().Unix(),
  4327. Mtime: 0,
  4328. Price: info.Price,
  4329. WarehousingDetailId: info.WarehouseInfotId,
  4330. WarehouseOutDetailId: info.ID,
  4331. CancelOutDetailId: cancelInfo.ID,
  4332. ProductDate: info.ProductDate,
  4333. ExpireDate: info.ExpiryDate,
  4334. StorehouseId: houseConfig.StorehouseOutInfo,
  4335. OverCount: over_count,
  4336. }
  4337. service.CreateStockFlowOne(flow)
  4338. }
  4339. //出库数据小于退库数据
  4340. if info.Count < prescribingNumber {
  4341. flow := models.VmStockFlow{
  4342. WarehousingId: info.WarehouseInfotId,
  4343. GoodId: project.ProjectId,
  4344. Number: info.Number,
  4345. LicenseNumber: info.LicenseNumber,
  4346. Count: info.Count,
  4347. UserOrgId: adminInfo.CurrentOrgId,
  4348. PatientId: project.PatientId,
  4349. SystemTime: info.SysRecordTime,
  4350. ConsumableType: 7,
  4351. IsSys: 0,
  4352. WarehousingOrder: "",
  4353. WarehouseOutId: info.WarehouseOutId,
  4354. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4355. IsEdit: 0,
  4356. CancelStockId: cancel.ID,
  4357. CancelOrderNumber: cancel.OrderNumber,
  4358. Manufacturer: manufacturer.ID,
  4359. Dealer: 0,
  4360. Creator: adminInfo.AdminUser.Id,
  4361. UpdateCreator: 0,
  4362. Status: 1,
  4363. Ctime: time.Now().Unix(),
  4364. Mtime: 0,
  4365. Price: info.Price,
  4366. WarehousingDetailId: info.WarehouseInfotId,
  4367. WarehouseOutDetailId: info.ID,
  4368. CancelOutDetailId: cancelInfo.ID,
  4369. ProductDate: info.ProductDate,
  4370. ExpireDate: info.ExpiryDate,
  4371. StorehouseId: houseConfig.StorehouseOutInfo,
  4372. OverCount: over_count,
  4373. }
  4374. service.CreateStockFlowOne(flow)
  4375. }
  4376. //查询已出库数量
  4377. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4378. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4379. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4380. if prescribingNumber < dialysisInfo.Count {
  4381. //改变数量
  4382. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4383. }
  4384. if prescribingNumber >= dialysisInfo.Count {
  4385. //删除出库表
  4386. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4387. }
  4388. //更新剩余库存
  4389. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4390. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4391. var total_count_one int64
  4392. for _, it := range stockList {
  4393. total_count_one += it.StockCount
  4394. }
  4395. //基础库插入数据
  4396. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4397. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4398. var flush_count int64
  4399. for _, it := range goodListOne {
  4400. flush_count += it.StockCount
  4401. }
  4402. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4403. if errs != nil {
  4404. goodErrcode := models.XtGoodErrcode{
  4405. UserOrgId: project.UserOrgId,
  4406. Errcode: "手动出库更新剩余出库失败",
  4407. GoodId: project.ProjectId,
  4408. Status: 1,
  4409. Ctime: time.Now().Unix(),
  4410. Mtime: 0,
  4411. Count: 0,
  4412. StockCount: 0,
  4413. Creater: creater,
  4414. BatchNumberId: 0,
  4415. WarehouseOutId: 0,
  4416. }
  4417. service.CreateGoodErrcode(goodErrcode)
  4418. }
  4419. }
  4420. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4421. fmt.Println(err)
  4422. } else {
  4423. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4424. fmt.Println(err)
  4425. }
  4426. } else {
  4427. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4428. fmt.Println(err)
  4429. }
  4430. }
  4431. //保存处方出库
  4432. if goodOutConfig.IsOpen == 1 {
  4433. if project.Type == 3 {
  4434. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4435. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4436. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4437. operation_time := time.Now().Unix()
  4438. creater := adminInfo.AdminUser.Id
  4439. //创建退库单
  4440. timeStr := time.Now().Format("2006-01-02")
  4441. timeArr := strings.Split(timeStr, "-")
  4442. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4443. total = total + 1
  4444. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4445. cancelStock := models.CancelStock{
  4446. OrderNumber: orderNumber,
  4447. OperaTime: operation_time,
  4448. OrgId: adminInfo.CurrentOrgId,
  4449. Creater: creater,
  4450. Ctime: time.Now().Unix(),
  4451. Status: 1,
  4452. ReturnTime: project.RecordDate,
  4453. Type: 1,
  4454. StorehouseId: houseConfig.StorehouseOutInfo,
  4455. IsCheck: 1,
  4456. }
  4457. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4458. if msgerrkonde == gorm.ErrRecordNotFound {
  4459. service.AddSigleCancelStock(&cancelStock)
  4460. }
  4461. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4462. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4463. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4464. //获取出库数据
  4465. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4466. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4467. deaerler, _ := service.GetDealerById(info.Dealer)
  4468. if info.ID > 0 {
  4469. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4470. if info.Count >= prescribingNumber {
  4471. cancelStockInfo := models.CancelStockInfo{
  4472. GoodId: project.ProjectId,
  4473. CancelStockId: cancel.ID,
  4474. GoodTypeId: good.GoodTypeId,
  4475. Count: prescribingNumber,
  4476. Price: info.Price,
  4477. Total: 0,
  4478. ProductDate: info.ProductDate,
  4479. ExpiryDate: info.ExpiryDate,
  4480. Ctime: time.Now().Unix(),
  4481. Status: 1,
  4482. OrgId: adminInfo.CurrentOrgId,
  4483. OrderNumber: cancel.OrderNumber,
  4484. Type: 0,
  4485. Dealer: deaerler.DealerName,
  4486. Manufacturer: manufacturer.ManufacturerName,
  4487. Number: info.Number,
  4488. RegisterAccount: "",
  4489. Remark: "",
  4490. WarehouseInfoId: info.WarehouseInfotId,
  4491. PatientId: info.PatientId,
  4492. RecordDate: info.SysRecordTime,
  4493. StorehouseId: houseConfig.StorehouseOutInfo,
  4494. IsCheck: 1,
  4495. }
  4496. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4497. //退库数量增加
  4498. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4499. //出库数量减少
  4500. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4501. }
  4502. if info.Count < prescribingNumber {
  4503. cancelStockInfo := models.CancelStockInfo{
  4504. GoodId: project.ProjectId,
  4505. CancelStockId: cancel.ID,
  4506. GoodTypeId: good.GoodTypeId,
  4507. Count: prescribingNumber,
  4508. Price: info.Price,
  4509. Total: 0,
  4510. ProductDate: info.ProductDate,
  4511. ExpiryDate: info.ExpiryDate,
  4512. Ctime: time.Now().Unix(),
  4513. Status: 1,
  4514. OrgId: adminInfo.CurrentOrgId,
  4515. OrderNumber: cancel.OrderNumber,
  4516. Type: 0,
  4517. Dealer: deaerler.DealerName,
  4518. Manufacturer: manufacturer.ManufacturerName,
  4519. Number: info.Number,
  4520. RegisterAccount: "",
  4521. Remark: "",
  4522. WarehouseInfoId: info.WarehouseInfotId,
  4523. PatientId: info.PatientId,
  4524. RecordDate: info.SysRecordTime,
  4525. StorehouseId: houseConfig.StorehouseOutInfo,
  4526. IsCheck: 1,
  4527. }
  4528. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4529. //回退库存
  4530. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4531. }
  4532. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4533. var over_count int64
  4534. for _, it := range goodList {
  4535. over_count += it.StockCount
  4536. }
  4537. //查询出库数量
  4538. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4539. //出库数据 大于 退库数量
  4540. if len(list) > 0 {
  4541. for _, it := range list {
  4542. //回退库存
  4543. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4544. //退库数量增加
  4545. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4546. //出库数量减少
  4547. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4548. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4549. var over_count_one int64
  4550. for _, it := range goodList {
  4551. over_count_one += it.StockCount
  4552. }
  4553. //查询该批次是否有退库数据
  4554. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4555. flow := models.VmStockFlow{
  4556. WarehousingId: it.WarehouseInfotId,
  4557. GoodId: it.GoodId,
  4558. Number: it.Number,
  4559. LicenseNumber: it.LicenseNumber,
  4560. Count: it.Count,
  4561. UserOrgId: adminInfo.CurrentOrgId,
  4562. PatientId: it.PatientId,
  4563. SystemTime: it.SysRecordTime,
  4564. ConsumableType: 7,
  4565. IsSys: 0,
  4566. WarehousingOrder: "",
  4567. WarehouseOutId: it.WarehouseOutId,
  4568. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4569. IsEdit: 0,
  4570. CancelStockId: cancel.ID,
  4571. CancelOrderNumber: cancel.OrderNumber,
  4572. Manufacturer: manufacturer.ID,
  4573. Dealer: 0,
  4574. Creator: adminInfo.AdminUser.Id,
  4575. UpdateCreator: 0,
  4576. Status: 1,
  4577. Ctime: time.Now().Unix(),
  4578. Mtime: 0,
  4579. Price: it.Price,
  4580. WarehousingDetailId: it.WarehouseInfotId,
  4581. WarehouseOutDetailId: it.ID,
  4582. CancelOutDetailId: cancelInfo.ID,
  4583. ProductDate: it.ProductDate,
  4584. ExpireDate: it.ExpiryDate,
  4585. StorehouseId: houseConfig.StorehouseOutInfo,
  4586. OverCount: over_count_one,
  4587. }
  4588. service.CreateStockFlowOne(flow)
  4589. }
  4590. }
  4591. //查询已出库数量
  4592. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4593. if prescribingNumber < dialysisInfo.Count {
  4594. //改变数量
  4595. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4596. }
  4597. if prescribingNumber >= dialysisInfo.Count {
  4598. //删除出库表
  4599. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4600. }
  4601. //更新剩余库存
  4602. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4603. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4604. var total_count_one int64
  4605. for _, it := range stockList {
  4606. total_count_one += it.StockCount
  4607. }
  4608. //基础库插入数据
  4609. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4610. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4611. var flush_count int64
  4612. for _, it := range goodListOne {
  4613. flush_count += it.StockCount
  4614. }
  4615. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4616. if errs != nil {
  4617. goodErrcode := models.XtGoodErrcode{
  4618. UserOrgId: project.UserOrgId,
  4619. Errcode: "手动出库更新剩余出库失败",
  4620. GoodId: project.ProjectId,
  4621. Status: 1,
  4622. Ctime: time.Now().Unix(),
  4623. Mtime: 0,
  4624. Count: 0,
  4625. StockCount: 0,
  4626. Creater: creater,
  4627. BatchNumberId: 0,
  4628. WarehouseOutId: 0,
  4629. }
  4630. service.CreateGoodErrcode(goodErrcode)
  4631. }
  4632. }
  4633. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4634. fmt.Println(err)
  4635. } else {
  4636. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4637. fmt.Println(err)
  4638. }
  4639. }
  4640. c.ServeSuccessJSON(map[string]interface{}{
  4641. "msg": "删除成功",
  4642. })
  4643. return
  4644. }
  4645. func (c *HisApiController) CreateHisAdditionalCharge() {
  4646. his_patient_id, _ := c.GetInt64("his_patient_id")
  4647. patient_id, _ := c.GetInt64("patient_id")
  4648. record_date := c.GetString("record_date")
  4649. timeLayout := "2006-01-02"
  4650. loc, _ := time.LoadLocation("Local")
  4651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4652. if err != nil {
  4653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4654. return
  4655. }
  4656. adminInfo := c.GetAdminUserInfo()
  4657. recordDateTime := theTime.Unix()
  4658. dataBody := make(map[string]interface{}, 0)
  4659. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4660. if err != nil {
  4661. utils.ErrorLog(err.Error())
  4662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4663. return
  4664. }
  4665. var additions []*models.HisAdditionalCharge
  4666. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4667. additions, _ := dataBody["addition"].([]interface{})
  4668. if len(additions) > 0 {
  4669. for _, item := range additions {
  4670. items := item.(map[string]interface{})
  4671. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4672. utils.ErrorLog("item_id")
  4673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4674. return
  4675. }
  4676. item_id := int64(items["item_id"].(float64))
  4677. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4678. utils.ErrorLog("item_name")
  4679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4680. return
  4681. }
  4682. item_name := items["item_name"].(string)
  4683. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4684. utils.ErrorLog("price")
  4685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4686. return
  4687. }
  4688. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4689. ctime := time.Now().Unix()
  4690. additional := &models.HisAdditionalCharge{
  4691. PatientId: patient_id,
  4692. HisPatientId: his_patient_id,
  4693. UserOrgId: adminInfo.CurrentOrgId,
  4694. RecordDate: recordDateTime,
  4695. CreatedTime: ctime,
  4696. UpdatedTime: ctime,
  4697. Modifier: adminInfo.AdminUser.Id,
  4698. Creator: adminInfo.AdminUser.Id,
  4699. Price: price,
  4700. ItemName: item_name,
  4701. ItemId: item_id,
  4702. Status: 1,
  4703. }
  4704. additions = append(additions, additional)
  4705. }
  4706. }
  4707. }
  4708. for _, item := range additions {
  4709. service.CreateAddtionalCharge(item)
  4710. }
  4711. c.ServeSuccessJSON(map[string]interface{}{
  4712. "msg": "创建成功",
  4713. })
  4714. }
  4715. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4716. blood_fat := c.GetString("blood_fat")
  4717. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4718. blood_sugar := c.GetString("blood_sugar")
  4719. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4720. chief_conplaint := c.GetString("chief_conplaint")
  4721. dbp := c.GetString("dbp")
  4722. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4723. delivery_way, _ := c.GetInt64("delivery_way")
  4724. diagnostic := c.GetString("diagnostic")
  4725. family_history := c.GetString("family_history")
  4726. height := c.GetString("height")
  4727. history_of_present_illness := c.GetString("history_of_present_illness")
  4728. is_infect, _ := c.GetInt64("is_infect")
  4729. past_history := c.GetString("past_history")
  4730. patient_id, _ := c.GetInt64("patient_id")
  4731. his_patient_id, _ := c.GetInt64("his_patient_id")
  4732. personal_history := c.GetString("personal_history")
  4733. pulse := c.GetString("pulse")
  4734. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4735. sbp := c.GetString("sbp")
  4736. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4737. heightfloat, _ := strconv.ParseFloat(height, 64)
  4738. sicktype := c.GetString("sick_type")
  4739. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4740. symptom := c.GetString("symptom")
  4741. sick_date := c.GetString("sick_date")
  4742. temperatures := c.GetString("temperature")
  4743. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4744. record_date := c.GetString("record_date")
  4745. breathing := c.GetString("breathing")
  4746. doctor_advice := c.GetString("doctor_advice")
  4747. remark := c.GetString("remark")
  4748. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4749. sick, _ := c.GetInt64("sick")
  4750. diagnose, _ := c.GetInt64("diagnose")
  4751. //id, _ := c.GetInt64("id")
  4752. timeLayout := "2006-01-02"
  4753. loc, _ := time.LoadLocation("Local")
  4754. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4755. allergic_history := c.GetString("allergic_history")
  4756. if err != nil {
  4757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4758. return
  4759. }
  4760. recordDateTime := theTime.Unix()
  4761. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4762. if err != nil {
  4763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4764. return
  4765. }
  4766. sickTimes := sickTime.Unix()
  4767. ctime := time.Now().Unix()
  4768. primary_disease := c.GetString("primary_disease")
  4769. confirm_failure_date := c.GetString("confirm_failure_date")
  4770. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4771. drug_allergy_history := c.GetString("drug_allergy_history")
  4772. physical_examination := c.GetString("physical_examination")
  4773. special_inspection := c.GetString("special_inspection")
  4774. lab_apparatus := c.GetString("lab_apparatus")
  4775. caseHistory := models.HisPatientCaseHistory{
  4776. HisPatientId: his_patient_id,
  4777. PatientId: patient_id,
  4778. Temperature: temperature,
  4779. BloodSugar: bloodsugarfloat,
  4780. Pulse: pulsefloat,
  4781. Sbp: sbpfloat,
  4782. Dbp: dbpfloat,
  4783. Height: heightfloat,
  4784. BloodFat: bloodfatfloat,
  4785. SickType: sick_type,
  4786. Symptom: symptom,
  4787. SickDate: sickTimes,
  4788. IsInfect: is_infect,
  4789. HistoryOfPresentIllness: history_of_present_illness,
  4790. PastHistory: past_history,
  4791. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4792. ChiefConplaint: chief_conplaint,
  4793. PersonalHistory: personal_history,
  4794. FamilyHistory: family_history,
  4795. Diagnostic: diagnostic,
  4796. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4797. Status: 1,
  4798. Ctime: ctime,
  4799. Mtime: ctime,
  4800. RecordDate: recordDateTime,
  4801. DeliveryWay: delivery_way,
  4802. Breathing: breathingfloat,
  4803. DoctorAdvice: doctor_advice,
  4804. Remark: remark,
  4805. Sick: sick,
  4806. Diagnose: diagnose,
  4807. AllergicHistory: allergic_history,
  4808. PrimaryDisease: primary_disease,
  4809. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4810. DrugAllergyHistory: drug_allergy_history,
  4811. PhysicalExamination: physical_examination,
  4812. SpecialInspection: special_inspection,
  4813. LabApparatus: lab_apparatus,
  4814. }
  4815. //查询该患者是否有病历
  4816. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4817. if errcodes == gorm.ErrRecordNotFound {
  4818. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4819. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4820. if err != nil {
  4821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4822. return
  4823. }
  4824. c.ServeSuccessJSON(map[string]interface{}{
  4825. "caseHistory": caseHistory,
  4826. "historyInfo": historyInfo,
  4827. })
  4828. return
  4829. } else if errcodes == nil {
  4830. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4831. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4832. if err != nil {
  4833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4834. return
  4835. }
  4836. c.ServeSuccessJSON(map[string]interface{}{
  4837. "caseHistory": caseHistory,
  4838. "historyInfo": historyInfo,
  4839. })
  4840. }
  4841. //查询该患者是否有病历
  4842. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4843. //if errcode == gorm.ErrRecordNotFound {
  4844. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4845. // if err != nil {
  4846. // c.ServeSuccessJSON(map[string]interface{}{
  4847. // "msg": "保存成功",
  4848. // })
  4849. // }
  4850. //} else if errcode == nil {
  4851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4852. // return
  4853. //}
  4854. }
  4855. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4856. patient_id, _ := c.GetInt64("patient_id", 0)
  4857. adminUser := c.GetAdminUserInfo()
  4858. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4859. c.ServeSuccessJSON(map[string]interface{}{
  4860. "list": caseHistorys,
  4861. })
  4862. }
  4863. func (c *HisApiController) GetHisPatientCaseHistory() {
  4864. record_date, _ := c.GetInt64("record_date", 0)
  4865. patient_id, _ := c.GetInt64("patient_id", 0)
  4866. admin := c.GetAdminUserInfo()
  4867. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4868. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4869. c.ServeSuccessJSON(map[string]interface{}{
  4870. "info": info,
  4871. "case_history": case_history,
  4872. })
  4873. }
  4874. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4875. template_name := c.GetString("template_name")
  4876. template_remark := c.GetString("template_remark")
  4877. doctor := c.GetAdminUserInfo().AdminUser.Id
  4878. diagnostic := c.GetString("diagnostic")
  4879. chief_conplaint := c.GetString("chief_conplain")
  4880. history_of_present_illness := c.GetString("history_of_present_illness")
  4881. past_history := c.GetString("past_history")
  4882. personal_history := c.GetString("personal_history")
  4883. family_history := c.GetString("family_history")
  4884. user_name := c.GetString("user_name")
  4885. doctor_advice := c.GetString("doctor_advice")
  4886. remark := c.GetString("remark")
  4887. //record_date := c.GetString("record_date")
  4888. //fmt.Println("record_date--------",record_date)
  4889. //timeLayout := "2006-01-02"
  4890. //loc, _ := time.LoadLocation("Local")
  4891. //
  4892. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4893. //if err != nil {
  4894. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4895. // return
  4896. //}
  4897. //recordDateTime := theTime.Unix()
  4898. ctime := time.Now().Unix()
  4899. template := models.HisCaseHistoryTemplate{
  4900. HistoryOfPresentIllness: history_of_present_illness,
  4901. PastHistory: past_history,
  4902. ChiefConplaint: chief_conplaint,
  4903. PersonalHistory: personal_history,
  4904. FamilyHistory: family_history,
  4905. Diagnostic: diagnostic,
  4906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4907. Status: 1,
  4908. Ctime: ctime,
  4909. Mtime: ctime,
  4910. RecordDate: time.Now().Unix(),
  4911. TemplateName: template_name,
  4912. TemplateRemark: template_remark,
  4913. Creator: doctor,
  4914. Modifier: doctor,
  4915. UserName: user_name,
  4916. DoctorAdvice: doctor_advice,
  4917. Remark: remark,
  4918. }
  4919. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4920. if err == nil {
  4921. c.ServeSuccessJSON(map[string]interface{}{
  4922. "msg": "保存成功",
  4923. })
  4924. } else {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4926. return
  4927. }
  4928. }
  4929. func (c *HisApiController) GetCaseHistoryTemplate() {
  4930. timeLayout := "2006-01-02"
  4931. loc, _ := time.LoadLocation("Local")
  4932. keyword := c.GetString("keyword")
  4933. start_time := c.GetString("start_time")
  4934. end_time := c.GetString("end_time")
  4935. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4936. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4937. admin := c.GetAdminUserInfo()
  4938. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4939. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4940. c.ServeSuccessJSON(map[string]interface{}{
  4941. "template": template,
  4942. //"history": history,
  4943. })
  4944. }
  4945. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4946. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4947. utils.ErrorLog("drug_name")
  4948. return enums.ErrorCodeParamWrong
  4949. }
  4950. adviceName, _ := json["drug_name"].(string)
  4951. if len(adviceName) == 0 {
  4952. utils.ErrorLog("len(advice_name) == 0")
  4953. return enums.ErrorCodeParamWrong
  4954. }
  4955. advice.AdviceName = adviceName
  4956. adviceDesc, _ := json["advice_desc"].(string)
  4957. advice.AdviceDesc = adviceDesc
  4958. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4959. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4960. advice.DrugSpec = drugSpec
  4961. }
  4962. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4963. remark, _ := json["remark"].(string)
  4964. advice.Remark = remark
  4965. }
  4966. if json["id"] == nil {
  4967. advice.DrugId = 0
  4968. } else {
  4969. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4970. drug_id := int64(json["id"].(float64))
  4971. advice.DrugId = drug_id
  4972. }
  4973. }
  4974. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4975. advice_id := int64(json["advice_id"].(float64))
  4976. advice.ID = advice_id
  4977. if advice.ID > 0 {
  4978. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4979. if err == nil {
  4980. if hisAdvice.ID > 0 {
  4981. advice.ExecutionTime = hisAdvice.ExecutionTime
  4982. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4983. advice.ExecutionState = hisAdvice.ExecutionState
  4984. advice.CheckTime = hisAdvice.CheckTime
  4985. advice.Checker = hisAdvice.Checker
  4986. advice.CheckState = hisAdvice.CheckState
  4987. advice.StartTime = hisAdvice.StartTime
  4988. advice.FeedetlSn = hisAdvice.FeedetlSn
  4989. }
  4990. }
  4991. }
  4992. }
  4993. //
  4994. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4995. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4996. // advice.ExecutionTime = execution_time
  4997. //}
  4998. //
  4999. //
  5000. //
  5001. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5002. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5003. // advice.ExecutionStaff = execution_staff
  5004. //}
  5005. //
  5006. //
  5007. //
  5008. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5009. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5010. // advice.ExecutionState = execution_state
  5011. //}
  5012. //
  5013. //
  5014. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5015. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5016. // advice.CheckTime = check_time
  5017. //}
  5018. //
  5019. //
  5020. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5021. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5022. // advice.CheckState = check_state
  5023. //}
  5024. //
  5025. //
  5026. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5027. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5028. // advice.Checker = checker
  5029. //}
  5030. //
  5031. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5032. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5033. // advice.StartTime = start_time
  5034. //}
  5035. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5036. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5037. advice.IsSelfDrug = is_self_drug
  5038. }
  5039. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5040. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5041. drug_way_count, _ := json["drug_way_count"].(string)
  5042. advice.DrugWayCount = drug_way_count
  5043. }
  5044. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5045. drugSpecUnit, _ := json["min_unit"].(string)
  5046. advice.DrugSpecUnit = drugSpecUnit
  5047. }
  5048. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5049. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5050. advice.SingleDose = singleDose
  5051. }
  5052. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5053. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5054. advice.SingleDoseUnit = singleDoseUnit
  5055. }
  5056. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5057. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5058. advice.PrescribingNumber = prescribingNumber
  5059. }
  5060. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5061. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5062. advice.PrescribingNumberUnit = prescribingNumberUnit
  5063. }
  5064. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5065. deliveryWay, _ := json["delivery_way"].(string)
  5066. advice.DeliveryWay = deliveryWay
  5067. }
  5068. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5069. executionFrequency, _ := json["execution_frequency"].(string)
  5070. advice.ExecutionFrequency = executionFrequency
  5071. }
  5072. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5073. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5074. advice.Price = price
  5075. }
  5076. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5077. med_list_codg, _ := json["medical_insurance_number"].(string)
  5078. advice.MedListCodg = med_list_codg
  5079. }
  5080. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5081. day := int64(json["day"].(float64))
  5082. advice.Day = day
  5083. }
  5084. return 0
  5085. }
  5086. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5087. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5088. id := int64(json["id"].(float64))
  5089. project.ID = id
  5090. historyProject, _ := service.GetHisProjectByID(id)
  5091. project.FeedetlSn = historyProject.FeedetlSn
  5092. }
  5093. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5094. project_id := int64(json["project_id"].(float64))
  5095. project.ProjectId = project_id
  5096. }
  5097. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5098. // price := int64(json["price"].(float64))
  5099. // formatInt_price := strconv.FormatInt(price, 10)
  5100. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5101. // project.Price = float_price
  5102. // }
  5103. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5104. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5105. project.Price = price
  5106. }
  5107. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5108. total, _ := json["total"].(string)
  5109. project.Count = total
  5110. }
  5111. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5112. medical_code, _ := json["medical_code"].(string)
  5113. project.MedListCodg = medical_code
  5114. }
  5115. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5116. single_dose, _ := json["single_dose"].(string)
  5117. project.SingleDose = single_dose
  5118. }
  5119. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5120. delivery_way, _ := json["delivery_way"].(string)
  5121. project.DeliveryWay = delivery_way
  5122. }
  5123. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5124. execution_frequency, _ := json["execution_frequency"].(string)
  5125. project.ExecutionFrequency = execution_frequency
  5126. }
  5127. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5128. remark, _ := json["remark"].(string)
  5129. project.Remark = remark
  5130. }
  5131. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5132. day, _ := json["number_days"].(string)
  5133. project.Day = day
  5134. }
  5135. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5136. unit, _ := json["unit"].(string)
  5137. project.Unit = unit
  5138. }
  5139. return 0
  5140. }
  5141. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5142. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5143. id := int64(json["id"].(float64))
  5144. historyAddtions, _ := service.GetHisAdditionByID(id)
  5145. additionalCharge.ID = id
  5146. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5147. }
  5148. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5149. item_id := int64(json["item_id"].(float64))
  5150. additionalCharge.ItemId = item_id
  5151. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5152. if config.ID > 0 {
  5153. if len(config.Code) > 0 {
  5154. additionalCharge.MedListCodg = config.Code
  5155. }
  5156. }
  5157. }
  5158. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5159. // price := int64(json["price"].(float64))
  5160. // formatInt_price := strconv.FormatInt(price, 10)
  5161. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5162. // additionalCharge.Price = float_price
  5163. // }
  5164. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5165. // price := int64(json["price"].(float64))
  5166. // formatInt_price := strconv.FormatInt(price, 10)
  5167. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5168. // additionalCharge.Price = float_price
  5169. //}
  5170. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5171. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5172. additionalCharge.Price = price
  5173. }
  5174. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5175. count, _ := json["count"].(string)
  5176. counts, _ := strconv.ParseInt(count, 10, 64)
  5177. additionalCharge.Count = counts
  5178. }
  5179. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5180. item_name, _ := json["item_name"].(string)
  5181. additionalCharge.ItemName = item_name
  5182. }
  5183. return 0
  5184. }
  5185. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5186. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5187. utils.ErrorLog("drug_name")
  5188. return enums.ErrorCodeParamWrong
  5189. }
  5190. adviceName, _ := json["drug_name"].(string)
  5191. if len(adviceName) == 0 {
  5192. utils.ErrorLog("len(advice_name) == 0")
  5193. return enums.ErrorCodeParamWrong
  5194. }
  5195. advice.AdviceName = adviceName
  5196. adviceDesc, _ := json["advice_desc"].(string)
  5197. advice.AdviceDesc = adviceDesc
  5198. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5199. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5200. advice.DrugSpec = drugSpec
  5201. }
  5202. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5203. remark, _ := json["remark"].(string)
  5204. advice.Remark = remark
  5205. }
  5206. if json["id"] == nil {
  5207. advice.DrugId = 0
  5208. } else {
  5209. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5210. drug_id := int64(json["id"].(float64))
  5211. advice.DrugId = drug_id
  5212. }
  5213. }
  5214. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5215. groupno := int64(json["groupno"].(float64))
  5216. advice.Groupno = groupno
  5217. }
  5218. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5219. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5220. advice.IsSelfDrug = is_self_drug
  5221. }
  5222. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5223. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5224. drug_way_count, _ := json["drug_way_count"].(string)
  5225. advice.DrugWayCount = drug_way_count
  5226. }
  5227. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5228. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5229. advice.HospApprFlag = hosp_appr_flag
  5230. }
  5231. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5232. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5233. advice.PrescribingNumber = prescribingNumber
  5234. }
  5235. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5236. // frequency_type := int64(json["frequency_type"].(float64))
  5237. // advice.FrequencyType = frequency_type
  5238. //}
  5239. //
  5240. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5241. // day_count := int64(json["day_count"].(float64))
  5242. // advice.DayCount = day_count
  5243. //}
  5244. //
  5245. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5246. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5247. // week_day, _ := json["week_day"].(string)
  5248. // advice.WeekDay = week_day
  5249. //}
  5250. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5251. drugSpecUnit, _ := json["min_unit"].(string)
  5252. advice.DrugSpecUnit = drugSpecUnit
  5253. }
  5254. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5255. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5256. advice.SingleDose = singleDose
  5257. }
  5258. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5259. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5260. advice.SingleDoseUnit = singleDoseUnit
  5261. }
  5262. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5263. deliveryWay, _ := json["delivery_way"].(string)
  5264. advice.DeliveryWay = deliveryWay
  5265. }
  5266. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5267. executionFrequency, _ := json["execution_frequency"].(string)
  5268. advice.ExecutionFrequency = executionFrequency
  5269. }
  5270. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5271. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5272. advice.Price = price
  5273. }
  5274. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5275. med_list_codg, _ := json["medical_insurance_number"].(string)
  5276. advice.MedListCodg = med_list_codg
  5277. }
  5278. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5279. day := int64(json["day"].(float64))
  5280. advice.Day = day
  5281. }
  5282. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5283. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5284. advice.PrescribingNumberUnit = prescribingNumberUnit
  5285. }
  5286. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5287. advice_id := int64(json["advice_id"].(float64))
  5288. advice.ID = advice_id
  5289. if advice.ID > 0 {
  5290. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5291. if err == nil {
  5292. if hisAdvice.ID > 0 {
  5293. advice.ExecutionTime = hisAdvice.ExecutionTime
  5294. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5295. advice.ExecutionState = hisAdvice.ExecutionState
  5296. advice.CheckTime = hisAdvice.CheckTime
  5297. advice.Checker = hisAdvice.Checker
  5298. advice.CheckState = hisAdvice.CheckState
  5299. advice.StartTime = hisAdvice.StartTime
  5300. advice.HospApprFlag = hisAdvice.HospApprFlag
  5301. advice.IsMedicine = hisAdvice.IsMedicine
  5302. if hisAdvice.UserOrgId == 10028 {
  5303. 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 {
  5304. advice.ExecutionTime = 0
  5305. advice.ExecutionStaff = 0
  5306. advice.ExecutionState = 2
  5307. advice.CheckTime = 0
  5308. advice.Checker = 0
  5309. advice.CheckState = 2
  5310. }
  5311. } else {
  5312. 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 {
  5313. advice.ExecutionTime = 0
  5314. advice.ExecutionStaff = 0
  5315. advice.ExecutionState = 2
  5316. advice.CheckTime = 0
  5317. advice.Checker = 0
  5318. advice.CheckState = 2
  5319. }
  5320. }
  5321. //advice.Groupno = hisAdvice.Groupno
  5322. }
  5323. }
  5324. }
  5325. }
  5326. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5327. //
  5328. //if drugStockConfig.IsOpen == 1 {
  5329. //
  5330. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5331. // if advice.ID == 0 { //医嘱不存在
  5332. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5333. // drug.Total = drug.Total - advice.PrescribingNumber
  5334. // service.UpdateBaseDrugLib(&drug)
  5335. //
  5336. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5337. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5338. // drug.Total = drug.Total - num
  5339. // service.UpdateBaseDrugLib(&drug)
  5340. // }
  5341. //
  5342. // } else if advice.ID > 0 { //医嘱存在
  5343. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5344. // var num float64
  5345. //
  5346. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5347. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5348. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5349. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5350. // drug.Total = drug.Total + num
  5351. // service.UpdateBaseDrugLib(&drug)
  5352. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5353. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5354. // drug.Total = drug.Total - num
  5355. // service.UpdateBaseDrugLib(&drug)
  5356. // }
  5357. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5358. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5359. // if num2 > advice.PrescribingNumber {
  5360. // num = num2 - advice.PrescribingNumber
  5361. // drug.Total = drug.Total + num
  5362. // service.UpdateBaseDrugLib(&drug)
  5363. // } else if num2 < advice.PrescribingNumber {
  5364. // num = advice.PrescribingNumber - num2
  5365. // drug.Total = drug.Total - num
  5366. // service.UpdateBaseDrugLib(&drug)
  5367. // }
  5368. //
  5369. // }
  5370. //
  5371. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5372. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5373. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5374. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5375. // if num1 > num2 {
  5376. // num = num1 - num2
  5377. // drug.Total = drug.Total + num
  5378. // service.UpdateBaseDrugLib(&drug)
  5379. // } else if num1 < num2 {
  5380. // num = num2 - num1
  5381. // drug.Total = drug.Total - num
  5382. // service.UpdateBaseDrugLib(&drug)
  5383. // }
  5384. //
  5385. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5386. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5387. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5388. // if hisAdvice.PrescribingNumber > num2 {
  5389. // num = hisAdvice.PrescribingNumber - num2
  5390. // drug.Total = drug.Total + num
  5391. // service.UpdateBaseDrugLib(&drug)
  5392. // } else if num2 < advice.PrescribingNumber {
  5393. // num = num2 - hisAdvice.PrescribingNumber
  5394. // drug.Total = drug.Total - num
  5395. // service.UpdateBaseDrugLib(&drug)
  5396. // }
  5397. //
  5398. // }
  5399. // }
  5400. // }
  5401. //}
  5402. //
  5403. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5404. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5405. // advice.ExecutionTime = execution_time
  5406. //}
  5407. //
  5408. //
  5409. //
  5410. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5411. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5412. // advice.ExecutionStaff = execution_staff
  5413. //}
  5414. //
  5415. //
  5416. //
  5417. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5418. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5419. // advice.ExecutionState = execution_state
  5420. //}
  5421. //
  5422. //
  5423. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5424. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5425. // advice.CheckTime = check_time
  5426. //}
  5427. //
  5428. //
  5429. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5430. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5431. // advice.CheckState = check_state
  5432. //}
  5433. //
  5434. //
  5435. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5436. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5437. // advice.Checker = checker
  5438. //}
  5439. //
  5440. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5441. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5442. // advice.StartTime = start_time
  5443. //}
  5444. return 0
  5445. }
  5446. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5447. project.ExecutionStaff = 0
  5448. project.ExecutionState = 2
  5449. project.ExecutionTime = 0
  5450. project.Checker = 0
  5451. project.CheckState = 2
  5452. project.CheckTime = 0
  5453. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5454. id := int64(json["id"].(float64))
  5455. project.ID = id
  5456. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5457. project.ExecutionStaff = temp_project.ExecutionStaff
  5458. project.ExecutionState = temp_project.ExecutionState
  5459. project.ExecutionTime = temp_project.ExecutionTime
  5460. project.Checker = temp_project.Checker
  5461. project.CheckState = temp_project.CheckState
  5462. project.CheckTime = temp_project.CheckTime
  5463. project.TeamId = temp_project.TeamId
  5464. }
  5465. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5466. types := int64(json["type"].(float64))
  5467. project.Type = types
  5468. }
  5469. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5470. project_id := int64(json["project_id"].(float64))
  5471. project.ProjectId = project_id
  5472. }
  5473. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5474. team_id := int64(json["team_id"].(float64))
  5475. project.TeamId = team_id
  5476. }
  5477. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5478. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5479. project.Price = price
  5480. }
  5481. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5482. total, _ := json["total"].(string)
  5483. //totals, _ := strconv.ParseInt(total, 10, 64)
  5484. project.Count = total
  5485. }
  5486. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5487. medical_code, _ := json["medical_code"].(string)
  5488. project.MedListCodg = medical_code
  5489. }
  5490. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5491. single_dose, _ := json["single_dose"].(string)
  5492. project.SingleDose = single_dose
  5493. }
  5494. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5495. delivery_way, _ := json["delivery_way"].(string)
  5496. project.DeliveryWay = delivery_way
  5497. }
  5498. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5499. execution_frequency, _ := json["execution_frequency"].(string)
  5500. project.ExecutionFrequency = execution_frequency
  5501. }
  5502. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5503. remark, _ := json["remark"].(string)
  5504. project.Remark = remark
  5505. }
  5506. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5507. day, _ := json["number_days"].(string)
  5508. project.Day = day
  5509. }
  5510. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5511. unit, _ := json["unit"].(string)
  5512. project.Unit = unit
  5513. }
  5514. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5515. // frequency_type := int64(json["frequency_type"].(float64))
  5516. // project.FrequencyType = frequency_type
  5517. //}
  5518. //
  5519. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5520. // day_count := int64(json["day_count"].(float64))
  5521. // project.DayCount = day_count
  5522. //}
  5523. //
  5524. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5525. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5526. // week_day, _ := json["week_day"].(string)
  5527. // project.WeekDay = week_day
  5528. //}
  5529. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5530. //
  5531. //if project.ID == 0 {
  5532. // if stockConfig.IsOpen == 1 {
  5533. // if project.Type == 3 {
  5534. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5535. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5536. // good.Total = good.Total - f_count
  5537. // service.UpdateGoodInfo(&good)
  5538. // }
  5539. // }
  5540. //
  5541. //} else {
  5542. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5543. //
  5544. // if stockConfig.IsOpen == 1 {
  5545. // if project.Type == 3 {
  5546. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5547. // if project.Count < temp_project.Count {
  5548. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5549. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5550. //
  5551. // other_count := f_count_two - f_count_one
  5552. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5553. // good.Total = good.Total + other_count_two
  5554. // service.UpdateGoodInfo(&good)
  5555. // } else if project.Count > temp_project.Count {
  5556. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5557. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5558. //
  5559. // other_count := f_count_one - f_count_two
  5560. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5561. // good.Total = good.Total - other_count_two
  5562. // service.UpdateGoodInfo(&good)
  5563. // }
  5564. //
  5565. // }
  5566. // }
  5567. //
  5568. //}
  5569. return 0
  5570. }
  5571. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5572. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5573. id := int64(json["id"].(float64))
  5574. additionalCharge.ID = id
  5575. }
  5576. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5577. item_id := int64(json["item_id"].(float64))
  5578. additionalCharge.ItemId = item_id
  5579. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5580. if config.ID > 0 {
  5581. if len(config.Code) > 0 {
  5582. additionalCharge.MedListCodg = config.Code
  5583. }
  5584. }
  5585. }
  5586. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5587. // price := int64(json["price"].(float64))
  5588. // formatInt_price := strconv.FormatInt(price, 10)
  5589. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5590. // additionalCharge.Price = float_price
  5591. // }
  5592. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5593. // price := int64(json["price"].(float64))
  5594. // formatInt_price := strconv.FormatInt(price, 10)
  5595. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5596. // additionalCharge.Price = float_price
  5597. //}
  5598. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5599. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5600. additionalCharge.Price = price
  5601. }
  5602. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5603. count, _ := json["count"].(string)
  5604. counts, _ := strconv.ParseInt(count, 10, 64)
  5605. additionalCharge.Count = counts
  5606. }
  5607. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5608. item_name, _ := json["item_name"].(string)
  5609. additionalCharge.ItemName = item_name
  5610. }
  5611. return 0
  5612. }
  5613. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5614. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5615. utils.ErrorLog("drug_name")
  5616. return enums.ErrorCodeParamWrong
  5617. }
  5618. adviceName, _ := json["drug_name"].(string)
  5619. if len(adviceName) == 0 {
  5620. utils.ErrorLog("len(advice_name) == 0")
  5621. return enums.ErrorCodeParamWrong
  5622. }
  5623. advice.AdviceName = adviceName
  5624. adviceDesc, _ := json["advice_desc"].(string)
  5625. advice.AdviceDesc = adviceDesc
  5626. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5627. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5628. advice.DrugSpec = drugSpec
  5629. }
  5630. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5631. remark, _ := json["remark"].(string)
  5632. advice.Remark = remark
  5633. }
  5634. if json["id"] == nil {
  5635. advice.DrugId = 0
  5636. } else {
  5637. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5638. drug_id := int64(json["id"].(float64))
  5639. advice.DrugId = drug_id
  5640. }
  5641. }
  5642. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5643. groupno := int64(json["groupno"].(float64))
  5644. advice.Groupno = groupno
  5645. }
  5646. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5647. drugSpecUnit, _ := json["min_unit"].(string)
  5648. advice.DrugSpecUnit = drugSpecUnit
  5649. }
  5650. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5651. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5652. advice.SingleDose = singleDose
  5653. }
  5654. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5655. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5656. advice.SingleDoseUnit = singleDoseUnit
  5657. }
  5658. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5659. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5660. advice.PrescribingNumber = prescribingNumber
  5661. }
  5662. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5663. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5664. advice.PrescribingNumberUnit = prescribingNumberUnit
  5665. }
  5666. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5667. deliveryWay, _ := json["delivery_way"].(string)
  5668. advice.DeliveryWay = deliveryWay
  5669. }
  5670. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5671. executionFrequency, _ := json["execution_frequency"].(string)
  5672. advice.ExecutionFrequency = executionFrequency
  5673. }
  5674. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5675. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5676. advice.Price = price
  5677. }
  5678. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5679. med_list_codg, _ := json["medical_insurance_number"].(string)
  5680. advice.MedListCodg = med_list_codg
  5681. }
  5682. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5683. day := int64(json["day"].(float64))
  5684. advice.Day = day
  5685. }
  5686. advice.FrequencyType = 1
  5687. return 0
  5688. }
  5689. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5690. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5691. types := int64(json["type"].(float64))
  5692. project.Type = types
  5693. }
  5694. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5695. project_id := int64(json["project_id"].(float64))
  5696. project.ProjectId = project_id
  5697. }
  5698. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5699. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5700. project.Price = price
  5701. }
  5702. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5703. total, _ := json["total"].(string)
  5704. //totals, _ := strconv.ParseInt(total, 10, 64)
  5705. project.Count = total
  5706. }
  5707. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5708. medical_code, _ := json["medical_code"].(string)
  5709. project.MedListCodg = medical_code
  5710. }
  5711. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5712. single_dose, _ := json["single_dose"].(string)
  5713. project.SingleDose = single_dose
  5714. }
  5715. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5716. delivery_way, _ := json["delivery_way"].(string)
  5717. project.DeliveryWay = delivery_way
  5718. }
  5719. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5720. execution_frequency, _ := json["execution_frequency"].(string)
  5721. project.ExecutionFrequency = execution_frequency
  5722. }
  5723. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5724. remark, _ := json["remark"].(string)
  5725. project.Remark = remark
  5726. }
  5727. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5728. day, _ := json["number_days"].(string)
  5729. project.Day = day
  5730. }
  5731. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5732. unit, _ := json["unit"].(string)
  5733. project.Unit = unit
  5734. }
  5735. project.FrequencyType = 1
  5736. return 0
  5737. }
  5738. func (c *HisApiController) GetHisOrderList() {
  5739. page, _ := c.GetInt64("page", -1)
  5740. limit, _ := c.GetInt64("limit", -1)
  5741. start_time := c.GetString("start_time")
  5742. end_time := c.GetString("end_time")
  5743. types, _ := c.GetInt64("type", 0)
  5744. keywords := c.GetString("keywords")
  5745. p_type, _ := c.GetInt64("p_type", 0)
  5746. sort_type, _ := c.GetInt64("sort_type", 0)
  5747. charge_type, _ := c.GetInt64("charge_type", 0)
  5748. sch_type, _ := c.GetInt64("sch_type", 0)
  5749. zone_type, _ := c.GetInt64("zone_type", 0)
  5750. med_type, _ := c.GetInt64("med_type", 0)
  5751. timeLayout := "2006-01-02"
  5752. loc, _ := time.LoadLocation("Local")
  5753. var startTime int64
  5754. if len(start_time) > 0 {
  5755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5756. if err != nil {
  5757. //fmt.Println(err)
  5758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5759. return
  5760. }
  5761. startTime = theTime.Unix()
  5762. }
  5763. var endTime int64
  5764. if len(end_time) > 0 {
  5765. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5766. if err != nil {
  5767. utils.ErrorLog(err.Error())
  5768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5769. return
  5770. }
  5771. endTime = theTime.Unix()
  5772. }
  5773. adminUser := c.GetAdminUserInfo()
  5774. org_id := adminUser.CurrentOrgId
  5775. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  5776. for _, item := range order {
  5777. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5778. item.DoctorName = info.Doctor
  5779. item.DepartmentName = info.XtHisDepartment.Name
  5780. }
  5781. if err == nil {
  5782. c.ServeSuccessJSON(map[string]interface{}{
  5783. "order": order,
  5784. "total": total,
  5785. })
  5786. } else {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5788. return
  5789. }
  5790. }
  5791. func (c *HisApiController) GetHisOrder() {
  5792. patient_id, _ := c.GetInt64("patient_id", 0)
  5793. number := c.GetString("number")
  5794. adminInfo := c.GetAdminUserInfo()
  5795. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5796. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5797. if err == nil {
  5798. c.ServeSuccessJSON(map[string]interface{}{
  5799. "order": order,
  5800. "prescription": prescriptions,
  5801. })
  5802. } else {
  5803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5804. return
  5805. }
  5806. }
  5807. func (c *HisApiController) GetHisPrescriptionList() {
  5808. record_date := c.GetString("record_date")
  5809. keywords := c.GetString("keywords")
  5810. page, _ := c.GetInt64("page")
  5811. limit, _ := c.GetInt64("limit")
  5812. sch_type, _ := c.GetInt64("sch_type")
  5813. timeLayout := "2006-01-02"
  5814. loc, _ := time.LoadLocation("Local")
  5815. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5816. if err != nil {
  5817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5818. return
  5819. }
  5820. recordDateTime := theTime.Unix()
  5821. adminInfo := c.GetAdminUserInfo()
  5822. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5823. //adminInfo := c.GetAdminUserInfo()
  5824. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5825. //fmt.Println(prescriptionOrder)
  5826. if err == nil {
  5827. c.ServeSuccessJSON(map[string]interface{}{
  5828. "order": prescriptionOrder,
  5829. "total": total,
  5830. })
  5831. } else {
  5832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5833. return
  5834. }
  5835. }
  5836. func (c *HisApiController) GetHisPrescriptionInfo() {
  5837. id, _ := c.GetInt64("id")
  5838. adminInfo := c.GetAdminUserInfo()
  5839. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5840. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5841. if err == nil {
  5842. c.ServeSuccessJSON(map[string]interface{}{
  5843. "order": prescriptionOrder,
  5844. "prescription": prescription,
  5845. })
  5846. } else {
  5847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5848. return
  5849. }
  5850. }
  5851. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5852. adminUser := c.GetAdminUserInfo()
  5853. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5854. c.ServeSuccessJSON(map[string]interface{}{
  5855. "config": config,
  5856. })
  5857. }
  5858. type ResultTwo struct {
  5859. ErrMsg interface{} `json:"err_msg"`
  5860. InfRefmsgid string `json:"inf_refmsgid"`
  5861. Infcode int64 `json:"infcode"`
  5862. Output struct {
  5863. Baseinfo struct {
  5864. Age float64 `json:"age"`
  5865. Brdy string `json:"brdy"`
  5866. Certno string `json:"certno"`
  5867. Gend string `json:"gend"`
  5868. Naty string `json:"naty"`
  5869. PsnCertType string `json:"psn_cert_type"`
  5870. PsnName string `json:"psn_name"`
  5871. PsnNo string `json:"psn_no"`
  5872. } `json:"baseinfo"`
  5873. Idetinfo []interface{} `json:"idetinfo"`
  5874. Iinfo []struct {
  5875. Balc float64 `json:"balc"`
  5876. CvlservFlag string `json:"cvlserv_flag"`
  5877. EmpName string `json:"emp_name"`
  5878. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5879. Insutype string `json:"insutype"`
  5880. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5881. PausInsuDate interface{} `json:"paus_insu_date"`
  5882. PsnInsuDate string `json:"psn_insu_date"`
  5883. PsnInsuStas string `json:"psn_insu_stas"`
  5884. PsnType string `json:"psn_type"`
  5885. } `json:"insuinfo"`
  5886. } `json:"output"`
  5887. RefmsgTime string `json:"refmsg_time"`
  5888. RespondTime string `json:"respond_time"`
  5889. Signtype interface{} `json:"signtype"`
  5890. WarnInfo interface{} `json:"warn_info"`
  5891. }
  5892. type ResultThree struct {
  5893. Cainfo interface{} `json:"cainfo"`
  5894. ErrMsg interface{} `json:"err_msg"`
  5895. InfRefmsgid string `json:"inf_refmsgid"`
  5896. Infcode int64 `json:"infcode"`
  5897. Output struct {
  5898. Data struct {
  5899. IptOtpNo string `json:"ipt_otp_no"`
  5900. MdtrtID string `json:"mdtrt_id"`
  5901. PsnNo string `json:"psn_no"`
  5902. } `json:"data"`
  5903. } `json:"output"`
  5904. RefmsgTime string `json:"refmsg_time"`
  5905. RespondTime string `json:"respond_time"`
  5906. Signtype interface{} `json:"signtype"`
  5907. WarnMsg interface{} `json:"warn_msg"`
  5908. }
  5909. type ResultFour struct {
  5910. Cainfo string `json:"cainfo"`
  5911. ErrMsg string `json:"err_msg"`
  5912. InfRefmsgid string `json:"inf_refmsgid"`
  5913. Infcode int64 `json:"infcode"`
  5914. Output struct {
  5915. Result []struct {
  5916. BasMednFlag string `json:"bas_medn_flag"`
  5917. ChldMedcFlag string `json:"chld_medc_flag"`
  5918. ChrgitmLv string `json:"chrgitm_lv"`
  5919. Cnt float64 `json:"cnt"`
  5920. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5921. DrtReimFlag string `json:"drt_reim_flag"`
  5922. FeedetlSn string `json:"feedetl_sn"`
  5923. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5924. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5925. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5926. ListSpItemFlag string `json:"list_sp_item_flag"`
  5927. LmtUsedFlag string `json:"lmt_used_flag"`
  5928. MedChrgitmType string `json:"med_chrgitm_type"`
  5929. Memo string `json:"memo"`
  5930. OverlmtAmt float64 `json:"overlmt_amt"`
  5931. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5932. Pric float64 `json:"pric"`
  5933. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5934. SelfpayProp float64 `json:"selfpay_prop"`
  5935. } `json:"result"`
  5936. } `json:"output"`
  5937. RefmsgTime string `json:"refmsg_time"`
  5938. RespondTime string `json:"respond_time"`
  5939. Signtype string `json:"signtype"`
  5940. WarnMsg string `json:"warn_msg"`
  5941. }
  5942. type ResultFive struct {
  5943. Insutype string `json:"insutype"`
  5944. }
  5945. type ResultSix struct {
  5946. Cainfo interface{} `json:"cainfo"`
  5947. ErrMsg interface{} `json:"err_msg"`
  5948. InfRefmsgid string `json:"inf_refmsgid"`
  5949. Infcode int64 `json:"infcode"`
  5950. Output struct {
  5951. } `json:"output"`
  5952. RefmsgTime string `json:"refmsg_time"`
  5953. RespondTime string `json:"respond_time"`
  5954. Signtype interface{} `json:"signtype"`
  5955. WarnMsg interface{} `json:"warn_msg"`
  5956. }
  5957. type ResultSeven struct {
  5958. Cainfo string `json:"cainfo"`
  5959. ErrMsg string `json:"err_msg"`
  5960. InfRefmsgid string `json:"inf_refmsgid"`
  5961. Infcode int64 `json:"infcode"`
  5962. Output struct {
  5963. Setldetail []interface{} `json:"setldetail"`
  5964. Setlinfo struct {
  5965. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5966. AcctPay float64 `json:"acct_pay"`
  5967. ActPayDedc float64 `json:"act_pay_dedc"`
  5968. Age float64 `json:"age"`
  5969. Balc float64 `json:"balc"`
  5970. Brdy string `json:"brdy"`
  5971. Certno string `json:"certno"`
  5972. ClrOptins string `json:"clr_optins"`
  5973. ClrType string `json:"clr_type"`
  5974. ClrWay string `json:"clr_way"`
  5975. CvlservFlag string `json:"cvlserv_flag"`
  5976. CvlservPay float64 `json:"cvlserv_pay"`
  5977. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5978. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5979. Gend string `json:"gend"`
  5980. HifesPay float64 `json:"hifes_pay"`
  5981. HifmiPay float64 `json:"hifmi_pay"`
  5982. HifobPay float64 `json:"hifob_pay"`
  5983. HifpPay float64 `json:"hifp_pay"`
  5984. HospPartAmt float64 `json:"hosp_part_amt"`
  5985. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5986. Insutype string `json:"insutype"`
  5987. MafPay float64 `json:"maf_pay"`
  5988. MdtrtCertType string `json:"mdtrt_cert_type"`
  5989. MdtrtID string `json:"mdtrt_id"`
  5990. MedType string `json:"med_type"`
  5991. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5992. MedinsSetlID string `json:"medins_setl_id"`
  5993. Naty string `json:"naty"`
  5994. OthPay float64 `json:"oth_pay"`
  5995. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5996. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5997. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5998. PsnCashPay float64 `json:"psn_cash_pay"`
  5999. PsnCertType string `json:"psn_cert_type"`
  6000. PsnName string `json:"psn_name"`
  6001. PsnNo string `json:"psn_no"`
  6002. PsnPartAmt float64 `json:"psn_part_amt"`
  6003. PsnType string `json:"psn_type"`
  6004. SetlID string `json:"setl_id"`
  6005. SetlTime string `json:"setl_time"`
  6006. } `json:"setlinfo"`
  6007. } `json:"output"`
  6008. RefmsgTime string `json:"refmsg_time"`
  6009. RespondTime string `json:"respond_time"`
  6010. Signtype interface{} `json:"signtype"`
  6011. WarnMsg interface{} `json:"warn_msg"`
  6012. }
  6013. type ResultEight struct {
  6014. Cainfo string `json:"cainfo"`
  6015. ErrMsg string `json:"err_msg"`
  6016. InfRefmsgid string `json:"inf_refmsgid"`
  6017. Infcode int64 `json:"infcode"`
  6018. Output struct {
  6019. Stmtinfo struct {
  6020. SetlOptins string `json:"setl_optins"`
  6021. StmtRslt string `json:"stmt_rslt"`
  6022. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6023. } `json:"stmtinfo"`
  6024. } `json:"output"`
  6025. RefmsgTime string `json:"refmsg_time"`
  6026. RespondTime string `json:"respond_time"`
  6027. Signtype interface{} `json:"signtype"`
  6028. WarnMsg interface{} `json:"warn_msg"`
  6029. }
  6030. type ResultNine struct {
  6031. Cainfo string `json:"cainfo"`
  6032. ErrMsg string `json:"err_msg"`
  6033. InfRefmsgid string `json:"inf_refmsgid"`
  6034. Infcode int64 `json:"infcode"`
  6035. Output struct {
  6036. FileQuryNo string `json:"file_qury_no"`
  6037. } `json:"output"`
  6038. RefmsgTime string `json:"refmsg_time"`
  6039. RespondTime string `json:"respond_time"`
  6040. Signtype interface{} `json:"signtype"`
  6041. WarnMsg interface{} `json:"warn_msg"`
  6042. }
  6043. type ResultTen struct {
  6044. Cainfo string `json:"cainfo"`
  6045. ErrMsg string `json:"err_msg"`
  6046. InfRefmsgid string `json:"inf_refmsgid"`
  6047. Infcode int64 `json:"infcode"`
  6048. Output struct {
  6049. DldEndtime string `json:"dld_endtime"`
  6050. FileQuryNo string `json:"file_qury_no"`
  6051. Filename string `json:"filename"`
  6052. } `json:"output"`
  6053. RefmsgTime string `json:"refmsg_time"`
  6054. RespondTime string `json:"respond_time"`
  6055. Signtype interface{} `json:"signtype"`
  6056. WarnMsg interface{} `json:"warn_msg"`
  6057. }
  6058. type ResultEleven struct {
  6059. Cainfo string `json:"cainfo"`
  6060. ErrMsg string `json:"err_msg"`
  6061. InfRefmsgid string `json:"inf_refmsgid"`
  6062. Infcode int64 `json:"infcode"`
  6063. Output struct {
  6064. Setlinfo struct {
  6065. FixmedinsName string `json:"fixmedins_name"`
  6066. FixmedinsCode string `json:"fixmedins_code"`
  6067. PsnNo string `json:"psn_no"`
  6068. PsnName string `json:"psn_name"`
  6069. HifobPay float64 `json:"hifob_pay"`
  6070. Gend string `json:"gend"`
  6071. Brdy string `json:"brdy"`
  6072. PsnCertType string `json:"psn_cert_type"`
  6073. PsnType string `json:"psn_type"`
  6074. EmpName string `json:"emp_name"`
  6075. Certno string `json:"certno"`
  6076. Insutype string `json:"insutype"`
  6077. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6078. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6079. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6080. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6081. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6082. ActPayDedc float64 `json:"act_pay_dedc"`
  6083. HifpPay float64 `json:"hifp_pay"`
  6084. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6085. CvlservPay float64 `json:"cvlserv_pay"`
  6086. HifesPay float64 `json:"hifes_pay"`
  6087. HifmiPay float64 `json:"hifmi_pay"`
  6088. MafPay float64 `json:"maf_pay"`
  6089. OthPay float64 `json:"oth_pay"`
  6090. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6091. PsnPay float64 `json:"psn_pay"`
  6092. AcctPay float64 `json:"acct_pay"`
  6093. CashPayamt float64 `json:"cash_payamt"`
  6094. Balc float64 `json:"balc"`
  6095. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6096. MedinsSetlId string `json:"medins_setl_id"`
  6097. RefdSetlFlag string `json:"refd_setl_flag"`
  6098. SetlTime string `json:"setl_time"`
  6099. MedType string `json:"med_type"`
  6100. } `json:"setlinfo"`
  6101. } `json:"output"`
  6102. RefmsgTime string `json:"refmsg_time"`
  6103. RespondTime string `json:"respond_time"`
  6104. Signtype interface{} `json:"signtype"`
  6105. WarnMsg interface{} `json:"warn_msg"`
  6106. }
  6107. type Custom struct {
  6108. DetItemFeeSumamt string
  6109. Cut string
  6110. FeedetlSn string
  6111. Price string
  6112. MedListCodg string
  6113. Type int64
  6114. AdviceId int64
  6115. ProjectId int64
  6116. ItemId int64
  6117. }
  6118. // 获取个人信息----挂号-----上传就诊信息
  6119. func (c *HisApiController) GetRegisterInfo() {
  6120. id, _ := c.GetInt64("id")
  6121. record_time := c.GetString("record_time")
  6122. settlementValue, _ := c.GetInt64("settlement_value")
  6123. medical_insurance_card := c.GetString("medical_insurance_card")
  6124. name := c.GetString("name")
  6125. id_card_type, _ := c.GetInt64("id_card_type")
  6126. certificates, _ := c.GetInt64("certificates")
  6127. medical_care, _ := c.GetInt64("medical_care")
  6128. birthday := c.GetString("birthday")
  6129. age, _ := c.GetInt64("age")
  6130. id_card := c.GetString("id_card")
  6131. register_type, _ := c.GetInt64("register")
  6132. doctor, _ := c.GetInt64("doctor")
  6133. department, _ := c.GetInt64("department")
  6134. gender, _ := c.GetInt64("sex")
  6135. phone := c.GetString("phone")
  6136. registration_fee, _ := c.GetFloat("registration_fee")
  6137. medical_expenses, _ := c.GetFloat("medical_expenses")
  6138. social_type, _ := c.GetInt64("social_type")
  6139. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6140. diagnosis_ids := c.GetString("diagnosis")
  6141. sick_type, _ := c.GetInt64("sick_type")
  6142. reg_type := c.GetString("p_type")
  6143. timeLayout := "2006-01-02"
  6144. loc, _ := time.LoadLocation("Local")
  6145. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6146. birthUnix := birthdays.Unix()
  6147. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6148. if err != nil {
  6149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6150. return
  6151. }
  6152. recordDateTime := theTime.Unix()
  6153. adminInfo := c.GetAdminUserInfo()
  6154. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6155. if tempPatient.ID == 0 {
  6156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6157. return
  6158. }
  6159. var patient service.Patients
  6160. if id == 0 {
  6161. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6162. } else {
  6163. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6164. }
  6165. if patient.ID == 0 {
  6166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6167. return
  6168. }
  6169. if len(patient.IdCardNo) == 0 {
  6170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6171. return
  6172. }
  6173. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6174. if len(his) >= 1 {
  6175. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6176. if len(his) >= 1 && order.ID == 0 {
  6177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6178. return
  6179. }
  6180. }
  6181. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6182. fmt.Println(timeStr)
  6183. timeArr := strings.Split(timeStr, " ")
  6184. fmt.Println(timeArr)
  6185. timeArrTwo := strings.Split(timeArr[0], "-")
  6186. timeArrThree := strings.Split(timeArr[1], ":")
  6187. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6188. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6189. if len(lists) == 0 {
  6190. var hisPatient models.XtHisPatient
  6191. hisPatient = models.XtHisPatient{
  6192. Name: name,
  6193. Age: age,
  6194. Gender: gender,
  6195. Birthday: birthUnix,
  6196. Phone: phone,
  6197. MedicalTreatmentType: medical_care,
  6198. IdType: certificates,
  6199. IdCardNo: id_card,
  6200. BalanceAccountsType: settlementValue,
  6201. SocialType: social_type,
  6202. MedicalInsuranceNumber: medical_insurance_card,
  6203. RegisterType: register_type,
  6204. RegisterCost: registration_fee,
  6205. TreatmentCost: medical_expenses,
  6206. AdminUserId: adminInfo.AdminUser.Id,
  6207. UserOrgId: adminInfo.CurrentOrgId,
  6208. Status: 1,
  6209. RecordDate: recordDateTime,
  6210. IsReturn: 1,
  6211. PatientId: patient.ID,
  6212. Ctime: time.Now().Unix(),
  6213. Mtime: time.Now().Unix(),
  6214. Number: str,
  6215. IdCardType: id_card_type,
  6216. Departments: department,
  6217. Doctor: doctor,
  6218. PType: reg_type,
  6219. Diagnosis: diagnosis_ids,
  6220. SickType: sick_type,
  6221. }
  6222. service.CreateHisPatient(&hisPatient)
  6223. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6224. c.ServeSuccessJSON(map[string]interface{}{
  6225. "his_info": hisPatient,
  6226. })
  6227. } else {
  6228. //chrgBchno := rand.Intn(1000000) + 10000
  6229. var hisPatient models.XtHisPatient
  6230. hisPatient = models.XtHisPatient{
  6231. Name: name,
  6232. Age: age,
  6233. Gender: gender,
  6234. Birthday: birthUnix,
  6235. Phone: phone,
  6236. MedicalTreatmentType: medical_care,
  6237. IdType: certificates,
  6238. IdCardNo: id_card,
  6239. BalanceAccountsType: settlementValue,
  6240. SocialType: social_type,
  6241. MedicalInsuranceNumber: medical_insurance_card,
  6242. RegisterType: register_type,
  6243. RegisterCost: registration_fee,
  6244. TreatmentCost: medical_expenses,
  6245. AdminUserId: adminInfo.AdminUser.Id,
  6246. UserOrgId: adminInfo.CurrentOrgId,
  6247. Status: 1,
  6248. RecordDate: recordDateTime,
  6249. IsReturn: 1,
  6250. PatientId: patient.ID,
  6251. Ctime: time.Now().Unix(),
  6252. Mtime: time.Now().Unix(),
  6253. Number: str,
  6254. IdCardType: id_card_type,
  6255. Departments: department,
  6256. Doctor: doctor,
  6257. PType: reg_type,
  6258. Diagnosis: diagnosis_ids,
  6259. SickType: sick_type,
  6260. }
  6261. service.CreateHisPatient(&hisPatient)
  6262. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6263. c.ServeSuccessJSON(map[string]interface{}{
  6264. "his_info": hisPatient,
  6265. })
  6266. }
  6267. }
  6268. // 上传明细----结算
  6269. func (c *HisApiController) GetUploadInfo() {
  6270. id, _ := c.GetInt64("id")
  6271. record_time := c.GetString("record_time")
  6272. his_patient_id, _ := c.GetInt64("his_patient_id")
  6273. oth_desc := c.GetString("oth_desc")
  6274. pay_way, _ := c.GetInt64("pay_way")
  6275. pay_ways := c.GetString("pay_ways")
  6276. pay_price, _ := c.GetFloat("pay_price")
  6277. pay_card_no := c.GetString("pay_card_no")
  6278. discount_price, _ := c.GetFloat("discount_price")
  6279. preferential_price, _ := c.GetFloat("preferential_price")
  6280. reality_price, _ := c.GetFloat("reality_price")
  6281. found_price, _ := c.GetFloat("found_price")
  6282. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6283. private_price, _ := c.GetFloat("private_price")
  6284. timeLayout := "2006-01-02"
  6285. loc, _ := time.LoadLocation("Local")
  6286. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6287. fapiao_code := c.GetString("fapiao_code")
  6288. fapiao_number := c.GetString("fapiao_number")
  6289. diagnosis_id := c.GetString("diagnosis")
  6290. sick_type, _ := c.GetInt64("sick_type")
  6291. reg_type, _ := c.GetInt64("p_type")
  6292. order_id, _ := c.GetInt64("order_id")
  6293. cash_pay := c.GetString("cash_pay")
  6294. wechat_pay := c.GetString("wechat_pay")
  6295. ali_pay := c.GetString("ali_pay")
  6296. jifen_pay := c.GetString("jifen_pay")
  6297. band_card_pay := c.GetString("band_card_pay")
  6298. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6299. tmp_decimal := c.GetString("tmp_decimal")
  6300. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6301. var decimal float64 //本次使用的押金
  6302. var errmsg error
  6303. tx := service.XTWriteDB().Begin() //开了事务
  6304. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6305. defer func() {
  6306. if errmsg != nil {
  6307. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6308. tx.Rollback()
  6309. } else {
  6310. tx.Commit()
  6311. }
  6312. }()
  6313. fmt.Println("dec_way", dec_way)
  6314. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6315. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6316. return
  6317. }
  6318. if len(tmp_decimal) > 0 {
  6319. if tmp_decimal[0] == 45 {
  6320. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6321. return
  6322. }
  6323. }
  6324. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6325. fmt.Println(errs)
  6326. decimal = tt
  6327. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6328. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6329. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6330. if err != nil {
  6331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6332. return
  6333. }
  6334. recordDateTime := theTime.Unix()
  6335. adminUser := c.GetAdminUserInfo()
  6336. var prescriptions []*models.HisPrescription
  6337. var prescriptionsOne []*models.HisPrescription
  6338. var start_time int64
  6339. var end_time int64
  6340. ids_str := c.GetString("ids")
  6341. ids_arr := strings.Split(ids_str, ",")
  6342. if tempOrder.ID == 0 {
  6343. if settle_accounts_type == 1 { //日结
  6344. fmt.Println(reg_type)
  6345. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6346. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6347. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6348. } else {
  6349. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6350. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6351. }
  6352. } else { //月结
  6353. start_time_str := c.GetString("start_time")
  6354. end_time_str := c.GetString("end_time")
  6355. timeLayout := "2006-01-02"
  6356. loc, _ := time.LoadLocation("Local")
  6357. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6358. if err != nil {
  6359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6360. return
  6361. }
  6362. recordStartTime := theStartTime.Unix()
  6363. start_time = recordStartTime
  6364. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6365. if err != nil {
  6366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6367. return
  6368. }
  6369. recordEndTime := theEndTime.Unix()
  6370. end_time = recordEndTime
  6371. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6372. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6373. }
  6374. var goods []*models.DialysisBeforePrepareGoods
  6375. var newGoods []*models.NewDialysisBeforePrepareGoods
  6376. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6377. var infos []*models.HisDoctorAdviceInfo
  6378. var infoList []*models.HisDoctorAdviceInfo
  6379. var hisAdvice []*models.HisDoctorAdviceInfo
  6380. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6381. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6382. //判断库存不足
  6383. //结算出库开关
  6384. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6385. if settConfig.IsOpen == 1 {
  6386. //判断库存的地方
  6387. for _, info := range prescriptions {
  6388. if info.Type == 1 {
  6389. infos = append(infos, info.HisDoctorAdviceInfo...)
  6390. }
  6391. if info.Type == 2 {
  6392. for _, sumItem := range info.HisPrescriptionProject {
  6393. if sumItem.Type == 3 {
  6394. var good models.DialysisBeforePrepareGoods
  6395. var newGood models.NewDialysisBeforePrepareGoods
  6396. good.GoodId = sumItem.GoodInfo.ID
  6397. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6398. count, _ := strconv.Atoi(sumItem.Count)
  6399. good.Count = int64(count)
  6400. good.StorehouseId = houseConfig.StorehouseOutInfo
  6401. good.ProjectId = sumItem.ID
  6402. goods = append(goods, &good)
  6403. newGood.GoodId = sumItem.GoodInfo.ID
  6404. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6405. count2, _ := strconv.Atoi(sumItem.Count)
  6406. newGood.Count = int64(count2)
  6407. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6408. newGood.ProjectId = sumItem.ID
  6409. newGoods = append(newGoods, &newGood)
  6410. }
  6411. }
  6412. }
  6413. }
  6414. for _, info := range prescriptionsOne {
  6415. if info.Type == 1 {
  6416. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6417. }
  6418. if info.Type == 2 {
  6419. for _, sumItem := range info.HisPrescriptionProject {
  6420. if sumItem.Type == 3 {
  6421. var newGood models.NewDialysisBeforePrepareGoods
  6422. newGood.GoodId = sumItem.GoodInfo.ID
  6423. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6424. count2, _ := strconv.Atoi(sumItem.Count)
  6425. newGood.Count = int64(count2)
  6426. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6427. newGood.ProjectId = sumItem.ID
  6428. newGoodOne = append(newGoodOne, &newGood)
  6429. }
  6430. }
  6431. }
  6432. }
  6433. //判断
  6434. for _, itemOne := range infos {
  6435. for _, itemTwo := range hisAdvice {
  6436. if itemOne.DrugId == itemTwo.DrugId {
  6437. itemTwo.Child = append(itemTwo.Child, itemOne)
  6438. }
  6439. }
  6440. }
  6441. for _, itemTwo := range hisAdvice {
  6442. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6443. var sum_out_count int64
  6444. for _, itemThree := range itemTwo.Child {
  6445. var prescribing_number int64
  6446. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6447. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6448. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6449. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6450. }
  6451. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6452. prescribing_number = parseIntPrescribingNumber
  6453. }
  6454. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6455. prescribing_number = parseIntPrescribingNumber
  6456. }
  6457. sum_out_count += prescribing_number
  6458. }
  6459. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6460. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6461. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6462. if sum_out_count > drugStockOut.FlushCount {
  6463. c.ServeSuccessJSON(map[string]interface{}{
  6464. "msg": "2",
  6465. "drug": medical,
  6466. })
  6467. return
  6468. }
  6469. }
  6470. fmt.Println("newGoods99999988882os", newGoods)
  6471. for _, itemOne := range newGoods {
  6472. for _, item := range newGoodOne {
  6473. if itemOne.GoodId == item.GoodId {
  6474. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6475. }
  6476. }
  6477. }
  6478. for _, item := range newGoodOne {
  6479. var sum_out_count_one int64
  6480. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6481. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6482. sum_out_count_one += itemOne.Count
  6483. }
  6484. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6485. fmt.Println("sum_out_count_one", sum_out_count_one)
  6486. fmt.Println("list.FlushCount", list.FlushCount)
  6487. if sum_out_count_one > list.FlushCount {
  6488. c.ServeSuccessJSON(map[string]interface{}{
  6489. "msg": "3",
  6490. "good": good,
  6491. })
  6492. return
  6493. }
  6494. }
  6495. }
  6496. timestamp := time.Now().Unix()
  6497. tempTime := time.Unix(timestamp, 0)
  6498. timeFormat := tempTime.Format("20060102150405")
  6499. chrgBchno := rand.Intn(100000) + 10000
  6500. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6501. strconv.FormatInt(his.PatientId, 10)
  6502. var ids []int64
  6503. for _, item := range prescriptions {
  6504. ids = append(ids, item.ID)
  6505. }
  6506. var total float64
  6507. for _, item := range prescriptions {
  6508. fmt.Println(item)
  6509. if item.Type == 1 { //药品
  6510. for _, subItem := range item.HisDoctorAdviceInfo {
  6511. total = total + (subItem.Price * subItem.PrescribingNumber)
  6512. }
  6513. }
  6514. if item.Type == 2 { //项目
  6515. for _, subItem := range item.HisPrescriptionProject {
  6516. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6517. total = total + (subItem.Price * cnt)
  6518. }
  6519. }
  6520. for _, subItem := range item.HisAdditionalCharge {
  6521. total = total + (subItem.Price * float64(subItem.Count))
  6522. }
  6523. }
  6524. if reg_type == 1111 || reg_type == 1112 {
  6525. reg_type = 11
  6526. }
  6527. tm := time.Unix(time.Now().Unix(), 0)
  6528. allTotal := fmt.Sprintf("%.4f", total)
  6529. totals, _ := strconv.ParseFloat(allTotal, 64)
  6530. order := &models.HisOrder{
  6531. UserOrgId: adminUser.CurrentOrgId,
  6532. HisPatientId: his.ID,
  6533. PatientId: id,
  6534. SettleAccountsDate: recordDateTime,
  6535. Ctime: time.Now().Unix(),
  6536. Mtime: time.Now().Unix(),
  6537. Status: 1,
  6538. OrderStatus: 2,
  6539. MdtrtId: his.Number,
  6540. Number: chrg_bchno,
  6541. MedfeeSumamt: totals,
  6542. PayWay: pay_way,
  6543. PayWays: pay_ways,
  6544. PayPrice: pay_price,
  6545. MedType: strconv.Itoa(int(reg_type)),
  6546. PayCardNo: pay_card_no,
  6547. DiscountPrice: discount_price,
  6548. PreferentialPrice: preferential_price,
  6549. RealityPrice: reality_price,
  6550. FoundPrice: found_price,
  6551. MedicalInsurancePrice: medical_insurance_price,
  6552. PrivatePrice: private_price,
  6553. SettleEndTime: end_time,
  6554. SettleStartTime: start_time,
  6555. PsnPartAmt: totals,
  6556. PsnCashPay: totals,
  6557. SettleType: settle_accounts_type,
  6558. FaPiaoCode: fapiao_code,
  6559. FaPiaoNumber: fapiao_number,
  6560. Diagnosis: diagnosis_id,
  6561. PType: 2,
  6562. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6563. Decimal: decimal,
  6564. OthDesc: oth_desc,
  6565. CashPay: cash_pay,
  6566. WechatPay: wechat_pay,
  6567. AliPay: ali_pay,
  6568. JifenPay: jifen_pay,
  6569. BandCardPay: band_card_pay,
  6570. }
  6571. err = service.CreateOrderTX(order, tx)
  6572. if err != nil {
  6573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6574. return
  6575. }
  6576. var customs []*Custom
  6577. for _, item := range prescriptions {
  6578. if item.Type == 1 { //药品a
  6579. for _, subItem := range item.HisDoctorAdviceInfo {
  6580. cus := &Custom{
  6581. AdviceId: subItem.ID,
  6582. ProjectId: 0,
  6583. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6584. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6585. FeedetlSn: subItem.FeedetlSn,
  6586. Price: fmt.Sprintf("%.4f", subItem.Price),
  6587. MedListCodg: subItem.MedListCodg,
  6588. Type: 1,
  6589. }
  6590. customs = append(customs, cus)
  6591. }
  6592. }
  6593. if item.Type == 2 { //项目
  6594. for _, subItem := range item.HisPrescriptionProject {
  6595. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6596. cus := &Custom{
  6597. AdviceId: 0,
  6598. ProjectId: subItem.ID,
  6599. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6600. Cut: fmt.Sprintf("%.4f", cnt),
  6601. FeedetlSn: subItem.FeedetlSn,
  6602. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6603. MedListCodg: subItem.MedListCodg,
  6604. Type: 2,
  6605. }
  6606. customs = append(customs, cus)
  6607. }
  6608. }
  6609. for _, item := range item.HisAdditionalCharge {
  6610. cus := &Custom{
  6611. ItemId: item.ID,
  6612. AdviceId: 0,
  6613. ProjectId: 0,
  6614. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6615. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6616. FeedetlSn: item.FeedetlSn,
  6617. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6618. MedListCodg: item.XtHisAddtionConfig.Code,
  6619. Type: 3,
  6620. }
  6621. customs = append(customs, cus)
  6622. }
  6623. }
  6624. for _, item := range customs {
  6625. var advice_id int64 = 0
  6626. var project_id int64 = 0
  6627. var item_id int64 = 0
  6628. var types int64 = 0
  6629. if item.Type == 1 {
  6630. advice_id = item.AdviceId
  6631. project_id = 0
  6632. item_id = 0
  6633. } else if item.Type == 2 {
  6634. advice_id = 0
  6635. item_id = 0
  6636. project_id = item.ProjectId
  6637. } else if item.Type == 3 {
  6638. advice_id = 0
  6639. item_id = item.ItemId
  6640. project_id = 0
  6641. }
  6642. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6643. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6644. pric, _ := strconv.ParseFloat(item.Price, 32)
  6645. info := &models.HisOrderInfo{
  6646. OrderNumber: order.Number,
  6647. UploadDate: time.Now().Unix(),
  6648. AdviceId: advice_id,
  6649. DetItemFeeSumamt: detItemFeeSumamt,
  6650. Cnt: cut,
  6651. Pric: pric,
  6652. PatientId: id,
  6653. Status: 1,
  6654. Mtime: time.Now().Unix(),
  6655. Ctime: time.Now().Unix(),
  6656. UserOrgId: adminUser.CurrentOrgId,
  6657. HisPatientId: his.ID,
  6658. OrderId: order.ID,
  6659. ProjectId: project_id,
  6660. Type: types,
  6661. ItemId: item_id,
  6662. }
  6663. service.CreateOrderInfoTX(info, tx)
  6664. }
  6665. his.Diagnosis = diagnosis_id
  6666. his.SickType = sick_type
  6667. his.RegisterType = reg_type
  6668. his.MedicalTreatmentType = reg_type
  6669. service.UpdataHisPateintTX(&his, tx)
  6670. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6671. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6672. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6673. //判断是否使用了押金
  6674. if dec_way == "true" {
  6675. tmpstring := strconv.FormatInt(order.ID, 10)
  6676. //扣押金
  6677. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6678. order.Decimal = decimal
  6679. service.UpDateOrderTwo(order, tx)
  6680. if errmsg != nil {
  6681. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6682. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6683. return
  6684. }
  6685. }
  6686. if err == nil {
  6687. for _, info := range prescriptions {
  6688. if info.Type == 1 {
  6689. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6690. }
  6691. if info.Type == 2 {
  6692. for _, sumItem := range info.HisPrescriptionProject {
  6693. if sumItem.Type == 3 {
  6694. var good models.DialysisBeforePrepareGoods
  6695. var newGood models.NewDialysisBeforePrepareGoods
  6696. var oldGood models.OldDialysisBeforePrepareGoods
  6697. good.GoodId = sumItem.GoodInfo.ID
  6698. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6699. count, _ := strconv.Atoi(sumItem.Count)
  6700. good.Count = int64(count)
  6701. good.StorehouseId = houseConfig.StorehouseOutInfo
  6702. good.ProjectId = sumItem.ID
  6703. good.PatientId = sumItem.PatientId
  6704. goods = append(goods, &good)
  6705. newGood.GoodId = sumItem.GoodInfo.ID
  6706. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6707. count2, _ := strconv.Atoi(sumItem.Count)
  6708. newGood.Count = int64(count2)
  6709. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6710. newGood.ProjectId = sumItem.ID
  6711. newGood.PatientId = sumItem.HisPatientId
  6712. newGoods = append(newGoods, &newGood)
  6713. oldGood.GoodId = sumItem.GoodInfo.ID
  6714. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6715. count3, _ := strconv.Atoi(sumItem.Count)
  6716. oldGood.Count = int64(count3)
  6717. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6718. oldGood.ProjectId = sumItem.ID
  6719. oldGood.RecordDate = sumItem.RecordDate
  6720. oldGood.PatientId = sumItem.HisPatientId
  6721. oldGoods = append(oldGoods, &oldGood)
  6722. }
  6723. }
  6724. }
  6725. }
  6726. if settConfig.IsOpen == 1 {
  6727. for _, item := range infoList {
  6728. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6729. if medical.IsUse == 2 {
  6730. //药品出库
  6731. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6732. //查询默认仓库
  6733. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6734. //查询默认仓库剩余多少库存
  6735. var sum_count int64
  6736. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6737. for _, its := range stockInfo {
  6738. if its.MaxUnit == medical.MaxUnit {
  6739. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6740. }
  6741. sum_count += its.StockMaxNumber + its.StockMinNumber
  6742. }
  6743. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6744. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6745. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6746. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6747. }
  6748. }
  6749. orgId := c.GetAdminUserInfo().CurrentOrgId
  6750. if len(oldGoods) > 0 {
  6751. timeStr := time.Now().Format("2006-01-02")
  6752. timeArr := strings.Split(timeStr, "-")
  6753. total, _ := service.FindAllWarehouseOut(orgId)
  6754. total = total + 1
  6755. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6756. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6757. number = number + total
  6758. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6759. operation_time := time.Now().Unix()
  6760. creater := c.GetAdminUserInfo().AdminUser.Id
  6761. //查询默认出库仓库库存
  6762. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6763. recordDateStr := time.Now().Format("2006-01-02")
  6764. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6765. nowtime := recordDate.Unix()
  6766. warehouseOut := models.WarehouseOut{
  6767. WarehouseOutOrderNumber: warehousing_out_order,
  6768. OperationTime: operation_time,
  6769. OrgId: orgId,
  6770. Creater: creater,
  6771. Ctime: time.Now().Unix(),
  6772. Status: 1,
  6773. WarehouseOutTime: nowtime,
  6774. Type: 1,
  6775. StorehouseId: storeConfig.StorehouseOutInfo,
  6776. IsCheck: 1,
  6777. OrderId: order.ID,
  6778. IsSys: 5,
  6779. }
  6780. //查询是否生成出库单
  6781. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6782. if out.ID == 0 {
  6783. service.AddSigleWarehouseOut(&warehouseOut)
  6784. }
  6785. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6786. for _, item := range oldGoods {
  6787. dialyPrepareOne := models.DialysisBeforePrepare{
  6788. GoodTypeId: item.GoodTypeId,
  6789. GoodId: item.GoodId,
  6790. PatientId: his.PatientId,
  6791. RecordDate: item.RecordDate,
  6792. UserOrgId: adminUser.CurrentOrgId,
  6793. Count: item.Count,
  6794. Ctime: time.Now().Unix(),
  6795. Creater: adminUser.AdminUser.Id,
  6796. CommdityCode: item.CommdityCode,
  6797. Status: 1,
  6798. StorehouseId: houseConfig.StorehouseOutInfo,
  6799. }
  6800. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6801. //非零用
  6802. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6803. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6804. //查询剩余库存
  6805. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6806. var sum_count int64
  6807. for _, item := range goodList {
  6808. sum_count += item.StockCount
  6809. }
  6810. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6811. //耗材
  6812. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6813. }
  6814. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6815. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6816. //查询剩余库存
  6817. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6818. var sum_count int64
  6819. for _, item := range goodList {
  6820. sum_count += item.StockCount
  6821. }
  6822. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6823. //耗材
  6824. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6825. }
  6826. }
  6827. }
  6828. }
  6829. c.ServeSuccessJSON(map[string]interface{}{
  6830. "msg": "结算成功",
  6831. })
  6832. }
  6833. }
  6834. }
  6835. // 退款
  6836. func (c *HisApiController) Refund() {
  6837. order_id, _ := c.GetInt64("order_id")
  6838. order, _ := service.GetHisOrderByID(order_id)
  6839. adminUser := c.GetAdminUserInfo()
  6840. orgid := c.GetAdminUserInfo().CurrentOrgId
  6841. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6842. if err != nil {
  6843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6844. return
  6845. }
  6846. tmp := strconv.FormatInt(order.ID, 10)
  6847. //当押金不为零时产生退费记录
  6848. if order.Decimal != 0 {
  6849. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6850. if err != nil {
  6851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6852. return
  6853. }
  6854. }
  6855. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6856. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6857. var goods []*models.DialysisBeforePrepareGoods
  6858. var newGoods []*models.NewDialysisBeforePrepareGoods
  6859. var infos []*models.HisDoctorAdviceInfo
  6860. for _, info := range orders {
  6861. if info.AdviceId > 0 && info.ProjectId == 0 {
  6862. infos = append(infos, &info.HisDoctorAdviceInfo)
  6863. }
  6864. if info.ProjectId > 0 && info.AdviceId == 0 {
  6865. if info.HisPrescriptionProject.Type == 3 {
  6866. var good models.DialysisBeforePrepareGoods
  6867. var newGood models.NewDialysisBeforePrepareGoods
  6868. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6869. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6870. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6871. good.Count = int64(count)
  6872. good.StorehouseId = houseConfig.StorehouseOutInfo
  6873. good.ProjectId = info.HisPrescriptionProject.ID
  6874. good.PatientId = info.PatientId
  6875. good.OrderId = order_id
  6876. goods = append(goods, &good)
  6877. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6878. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6879. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6880. newGood.Count = int64(count2)
  6881. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6882. newGood.ProjectId = info.HisPrescriptionProject.ID
  6883. newGood.RecordDate = order.SettleAccountsDate
  6884. newGood.UserOrgId = order.UserOrgId
  6885. newGood.PatientId = info.PatientId
  6886. newGood.OrderId = order_id
  6887. newGoods = append(newGoods, &newGood)
  6888. }
  6889. }
  6890. }
  6891. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6892. if settConfig.IsOpen == 1 {
  6893. for _, item := range infos {
  6894. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6895. }
  6896. for _, item := range newGoods {
  6897. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6898. }
  6899. }
  6900. c.ServeSuccessJSON(map[string]interface{}{
  6901. "msg": "退费成功",
  6902. })
  6903. }
  6904. func (c *HisApiController) RefundNumber() {
  6905. his_patient_id, _ := c.GetInt64("id")
  6906. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6907. info.Status = 0
  6908. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6909. if count > 0 {
  6910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6911. return
  6912. }
  6913. err := service.SaveHisPatient(info)
  6914. if err == nil {
  6915. c.ServeSuccessJSON(map[string]interface{}{
  6916. "msg": "退号成功",
  6917. })
  6918. } else {
  6919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6920. return
  6921. }
  6922. }
  6923. func (this *HisApiController) AdditionalCharge() {
  6924. dataBody := make(map[string]interface{}, 0)
  6925. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6926. fmt.Println(err)
  6927. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6928. patient_id := int64(dataBody["patient_id"].(float64))
  6929. medicineData, _ := dataBody["medicineData"].([]interface{})
  6930. adminUserInfo := this.GetAdminUserInfo()
  6931. orgId := adminUserInfo.CurrentOrgId
  6932. admin_user_id := adminUserInfo.AdminUser.Id
  6933. timeStr := time.Now().Format("2006-01-02")
  6934. timeLayout := "2006-01-02 15:04:05"
  6935. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6936. timenow := timeStringToTime.Unix()
  6937. var additionalCharges []*models.HisAdditionalCharge
  6938. for _, item := range medicineData {
  6939. var randNum int
  6940. randNum = rand.Intn(10000) + 1000
  6941. timestamp := time.Now().Unix()
  6942. tempTime := time.Unix(timestamp, 0)
  6943. timeFormat := tempTime.Format("20060102150405")
  6944. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6945. items := item.(map[string]interface{})
  6946. money := items["price"].(string)
  6947. item_id_str := items["item_id"].(string)
  6948. name := items["name"].(string)
  6949. id_str := items["id"].(string)
  6950. moneys, _ := strconv.ParseInt(money, 10, 64)
  6951. monStr := strconv.FormatInt(moneys, 10)
  6952. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6953. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6954. id, _ := strconv.ParseInt(id_str, 10, 64)
  6955. additionalCharge := &models.HisAdditionalCharge{
  6956. ID: id,
  6957. HisPatientId: his_patient_id,
  6958. UserOrgId: orgId,
  6959. PatientId: patient_id,
  6960. RecordDate: timenow,
  6961. Price: monneyStr,
  6962. Status: 1,
  6963. ItemName: name,
  6964. ItemId: item_id,
  6965. AdminUserId: admin_user_id,
  6966. CreatedTime: time.Now().Unix(),
  6967. OrderStatus: 0,
  6968. PrescriptionNumber: "",
  6969. BatchNumber: "",
  6970. FeedetlSn: p_number,
  6971. }
  6972. service.CreateAdditionalCharge(additionalCharge)
  6973. additionalCharges = append(additionalCharges, additionalCharge)
  6974. }
  6975. this.ServeSuccessJSON(map[string]interface{}{
  6976. "msg": "添加成功",
  6977. "additional_charges": additionalCharges,
  6978. })
  6979. }
  6980. func (this *HisApiController) DeleteAddition() {
  6981. id, _ := this.GetInt64("id")
  6982. //TODO 需要判断是否已经结算
  6983. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6984. if err == nil {
  6985. this.ServeSuccessJSON(map[string]interface{}{
  6986. "msg": "删除成功",
  6987. })
  6988. return
  6989. } else {
  6990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6991. return
  6992. }
  6993. }
  6994. func (this *HisApiController) GetAdminUsers() {
  6995. adminUser := this.GetAdminUserInfo()
  6996. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6997. this.ServeSuccessJSON(map[string]interface{}{
  6998. "doctors": doctors,
  6999. })
  7000. }
  7001. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7002. change_type, _ := this.GetInt64("type", 0)
  7003. record_date := this.GetString("record_time")
  7004. patient_id, _ := this.GetInt64("patient_id", 0)
  7005. p_type, _ := this.GetInt64("p_type", 0)
  7006. timeLayout := "2006-01-02"
  7007. loc, _ := time.LoadLocation("Local")
  7008. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7009. record_time := theAdviceRecordTime.Unix()
  7010. adminUserInfo := this.GetAdminUserInfo()
  7011. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7012. if err == nil {
  7013. if len(prescriptions) == 0 {
  7014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7015. return
  7016. } else {
  7017. this.ServeSuccessJSON(map[string]interface{}{
  7018. "prescriptions": prescriptions,
  7019. })
  7020. return
  7021. }
  7022. } else {
  7023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7024. return
  7025. }
  7026. }
  7027. func (this *HisApiController) GetCallHisPrescription() {
  7028. patient_id, _ := this.GetInt64("patient_id", 0)
  7029. timeLayout := "2006-01-02"
  7030. loc, _ := time.LoadLocation("Local")
  7031. start_time := this.GetString("start_time")
  7032. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7033. end_time := this.GetString("end_time")
  7034. p_type, _ := this.GetInt64("p_type")
  7035. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7036. adminUserInfo := this.GetAdminUserInfo()
  7037. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7038. if err == nil {
  7039. this.ServeSuccessJSON(map[string]interface{}{
  7040. "prescriptions": prescriptions,
  7041. })
  7042. return
  7043. } else {
  7044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7045. return
  7046. }
  7047. }
  7048. func (this *HisApiController) GetHisDayPrescription() {
  7049. timeLayout := "2006-01-02"
  7050. loc, _ := time.LoadLocation("Local")
  7051. start_time := this.GetString("start_time")
  7052. patient_id, _ := this.GetInt64("patient_id", 0)
  7053. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7054. end_time := this.GetString("end_time")
  7055. p_type, _ := this.GetInt64("p_type")
  7056. order_status, _ := this.GetInt64("type")
  7057. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7058. adminUserInfo := this.GetAdminUserInfo()
  7059. var dayHisPrescription []*models.HisPrescription
  7060. var err error
  7061. if order_status == 1 || order_status == 0 {
  7062. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7063. } else if order_status == 2 {
  7064. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7065. }
  7066. var settle_total float64
  7067. for _, item := range dayHisPrescription {
  7068. if len(item.HisPrescriptionProject) > 0 {
  7069. for _, subItem := range item.HisPrescriptionProject {
  7070. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7071. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7072. settle_total = settle_total + total
  7073. }
  7074. }
  7075. if len(item.HisDoctorAdviceInfo) > 0 {
  7076. for _, subItem := range item.HisDoctorAdviceInfo {
  7077. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7078. settle_total = settle_total + total
  7079. }
  7080. }
  7081. }
  7082. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7083. if err == nil {
  7084. this.ServeSuccessJSON(map[string]interface{}{
  7085. "day_prescription": dayHisPrescription,
  7086. "settle_total": settle_total,
  7087. })
  7088. return
  7089. } else {
  7090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7091. return
  7092. }
  7093. }
  7094. func (c *HisApiController) GetHisChargePatientList() {
  7095. record_date := c.GetString("record_date")
  7096. order_status, _ := c.GetInt64("type")
  7097. sch_type, _ := c.GetInt64("sch_type")
  7098. timeLayout := "2006-01-02"
  7099. loc, _ := time.LoadLocation("Local")
  7100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7101. if err != nil {
  7102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7103. return
  7104. }
  7105. recordDateTime := theTime.Unix()
  7106. adminInfo := c.GetAdminUserInfo()
  7107. var tempPatients []*service.NewTempPatients
  7108. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7109. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7110. if order_status != 2 {
  7111. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7112. } else {
  7113. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7114. }
  7115. } else {
  7116. if order_status != 2 {
  7117. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7118. } else {
  7119. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7120. }
  7121. }
  7122. var patients []*service.NewTempPatients
  7123. var patients_two []*service.NewTempPatients
  7124. for _, item := range tempPatients {
  7125. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7126. //过滤掉没挂号的和没开处方的
  7127. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7128. patients = append(patients, item)
  7129. }
  7130. //过滤掉没挂号的
  7131. if len(item.HisPatient) > 0 {
  7132. patients_two = append(patients_two, item)
  7133. }
  7134. } else {
  7135. if len(item.HisPrescription) > 0 {
  7136. patients = append(patients, item)
  7137. }
  7138. }
  7139. }
  7140. c.ServeSuccessJSON(map[string]interface{}{
  7141. "list": patients,
  7142. "list_two": patients_two,
  7143. })
  7144. }
  7145. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7146. record_date := c.GetString("record_date")
  7147. timeLayout := "2006-01-02"
  7148. loc, _ := time.LoadLocation("Local")
  7149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7150. if err != nil {
  7151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7152. return
  7153. }
  7154. recordDateTime := theTime.Unix()
  7155. adminUser := c.GetAdminUserInfo()
  7156. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7157. var patients []*service.Patients
  7158. for _, item := range tempPatients {
  7159. if item.HisPatient.ID == 0 {
  7160. patients = append(patients, item)
  7161. }
  7162. }
  7163. c.ServeSuccessJSON(map[string]interface{}{
  7164. "list": patients,
  7165. //"list_two": patients_two,
  7166. })
  7167. }
  7168. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7169. newArr = make([]*service.Patients, 0)
  7170. for i := 0; i < len(patient); i++ {
  7171. repeat := false
  7172. for j := i + 1; j < len(patient); j++ {
  7173. if patient[i].ID == patient[j].ID {
  7174. repeat = true
  7175. break
  7176. }
  7177. }
  7178. if !repeat {
  7179. newArr = append(newArr, patient[i])
  7180. }
  7181. }
  7182. return
  7183. }
  7184. func (c *HisApiController) GetHisChargePatientInfo() {
  7185. patient_id, _ := c.GetInt64("patient_id")
  7186. his_patient_id, _ := c.GetInt64("his_patient_id")
  7187. record_date := c.GetString("record_date")
  7188. //start_time := c.GetString("start_time")
  7189. //end_time := c.GetString("end_time")
  7190. order_status, _ := c.GetInt64("type", 0)
  7191. p_type, _ := c.GetInt64("p_type", 0)
  7192. order_id, _ := c.GetInt64("order_id", 0)
  7193. timeLayout := "2006-01-02"
  7194. loc, _ := time.LoadLocation("Local")
  7195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7196. if err != nil {
  7197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7198. return
  7199. }
  7200. recordDateTime := theTime.Unix()
  7201. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7202. //if err != nil {
  7203. //
  7204. //}
  7205. //startRecordDateTime := startTime.Unix()
  7206. //
  7207. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7208. //if err != nil {
  7209. //
  7210. //}
  7211. //endRecordDateTime := endTime.Unix()
  7212. admin := c.GetAdminUserInfo()
  7213. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7214. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7215. var prescriptions []*models.HisPrescription
  7216. //var unChargeMonthPrescriptions []*models.HisPrescription
  7217. order, _ := service.GetHisOrderByID(order_id)
  7218. if order_status == 1 || order_status == 0 {
  7219. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7220. } else if order_status == 2 {
  7221. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7222. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7223. }
  7224. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7225. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7226. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7227. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7228. //获取所有科室信息
  7229. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7230. c.ServeSuccessJSON(map[string]interface{}{
  7231. "his_info": his_patient_info,
  7232. "xt_info": xt_patient_info,
  7233. "prescription": prescriptions,
  7234. "case_history": case_history,
  7235. "info": patientPrescriptionInfo,
  7236. "last_info": lastPatientPrescriptionInfo,
  7237. "order": order,
  7238. "doctors": doctors,
  7239. "department": department,
  7240. })
  7241. return
  7242. }
  7243. func (c *HisApiController) GetAllOrderDetail() {
  7244. order_id, _ := c.GetInt64("id", 0)
  7245. order, _ := service.GetHisOrderByID(order_id)
  7246. if order.ID == 0 {
  7247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7248. return
  7249. }
  7250. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7251. org_id := c.GetAdminUserInfo().CurrentOrgId
  7252. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7253. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7254. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7255. c.ServeSuccessJSON(map[string]interface{}{
  7256. "order": order,
  7257. "order_info": order_info,
  7258. "patient": patient,
  7259. "admin_info": adminInfo,
  7260. "hospital_record": record,
  7261. })
  7262. return
  7263. }
  7264. func (c *HisApiController) GetAllOrderDetailCollect() {
  7265. order_id, _ := c.GetInt64("id", 0)
  7266. order, _ := service.GetHisOrderByID(order_id)
  7267. if order.ID == 0 {
  7268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7269. return
  7270. }
  7271. org_id := c.GetAdminUserInfo().CurrentOrgId
  7272. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7273. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7274. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7275. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7276. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7277. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7278. var bedCostTotal float64 = 0 //床位总费
  7279. //var bedCostSelfTotal float64 = 0 //床位自费
  7280. var operationCostTotal float64 = 0 //手术费
  7281. //var operationCostSelfTotal float64 = 0 //手术费
  7282. var otherCostTotal float64 = 0 //其他费用
  7283. //var otherCostSelfTotal float64 = 0 //其他费用
  7284. var materialCostTotal float64 = 0 //材料费
  7285. //var materialCostSelfTotal float64 = 0 //材料费
  7286. var westernMedicineCostTotal float64 = 0 //西药费
  7287. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7288. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7289. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7290. var checkCostTotal float64 = 0 //检查费
  7291. //var checkCostSelfTotal float64 = 0 //检查费
  7292. var laboratoryCostTotal float64 = 0 //化验费
  7293. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7294. var treatCostTotal float64 = 0 //治疗费用
  7295. //var treatCostSelfTotal float64 = 0 //治疗费用
  7296. var zhenChaCostTotal float64 = 0 //其他费用
  7297. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7298. decimal.DivisionPrecision = 2
  7299. var BalanceAccountsType int64
  7300. if his.ID > 0 {
  7301. BalanceAccountsType = his.BalanceAccountsType
  7302. } else {
  7303. BalanceAccountsType = record.BalanceAccountsType
  7304. }
  7305. if BalanceAccountsType != 2 {
  7306. for _, item := range order_info {
  7307. if org_id == 10215 {
  7308. if item.MedChrgitmType == "01" { //床位费
  7309. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7310. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7311. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7312. }
  7313. if item.MedChrgitmType == "02" { //诊察费
  7314. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7315. //zhenChaCostSelfTotal = zhenChaCostTotal
  7316. }
  7317. if item.MedChrgitmType == "03" { //检查费
  7318. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7319. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7320. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7321. }
  7322. //if item.MedChrgitmType == "02" { //检查费
  7323. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7324. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7325. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7326. //}
  7327. if item.MedChrgitmType == "04" { //化验费
  7328. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7329. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7330. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7331. }
  7332. if item.MedChrgitmType == "05" { //治疗费
  7333. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7334. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7335. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7336. }
  7337. if item.MedChrgitmType == "06" { //手术费
  7338. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7339. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7340. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7341. }
  7342. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7343. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7344. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7345. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7346. }
  7347. if item.MedChrgitmType == "09" { //西药费
  7348. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7349. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7350. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7351. }
  7352. if item.MedChrgitmType == "11" { //中成费
  7353. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7354. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7355. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7356. }
  7357. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7358. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7359. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7360. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7361. }
  7362. } else if org_id == 10188 || org_id == 10217 {
  7363. if item.MedChrgitmType == "01" { //床位费
  7364. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7365. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7366. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7367. }
  7368. if item.MedChrgitmType == "02" { //诊察费
  7369. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7370. //zhenChaCostSelfTotal = zhenChaCostTotal
  7371. }
  7372. if item.MedChrgitmType == "03" { //检查费
  7373. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7374. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7375. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7376. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7377. }
  7378. //if item.MedChrgitmType == "02" { //检查费
  7379. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7380. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7381. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7382. //}
  7383. if item.MedChrgitmType == "04" { //化验费
  7384. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7385. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7386. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7387. }
  7388. if item.MedChrgitmType == "05" { //治疗费
  7389. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7390. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7391. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7392. }
  7393. if item.MedChrgitmType == "06" { //手术费
  7394. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7395. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7396. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7397. }
  7398. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7399. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7400. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7401. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7402. }
  7403. if item.MedChrgitmType == "09" { //西药费
  7404. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7405. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7406. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7407. }
  7408. if item.MedChrgitmType == "11" { //中成费
  7409. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7410. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7411. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7412. }
  7413. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7414. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7415. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7416. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7417. }
  7418. } else {
  7419. if item.MedChrgitmType == "01" { //床位费
  7420. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7421. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7422. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7423. }
  7424. //if item.MedChrgitmType == "02" { //诊察费
  7425. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7426. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7427. //}
  7428. if item.MedChrgitmType == "03" { //检查费
  7429. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7430. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7431. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7432. }
  7433. //if item.MedChrgitmType == "02" { //检查费
  7434. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7435. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7436. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7437. //}
  7438. if item.MedChrgitmType == "04" { //化验费
  7439. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7440. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7441. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7442. }
  7443. if item.MedChrgitmType == "05" { //治疗费
  7444. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7445. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7446. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7447. }
  7448. if item.MedChrgitmType == "06" { //手术费
  7449. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7450. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7451. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7452. }
  7453. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7454. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7455. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7456. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7457. }
  7458. if item.MedChrgitmType == "09" { //西药费
  7459. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7460. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7461. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7462. }
  7463. if item.MedChrgitmType == "11" { //中成费
  7464. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7465. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7466. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7467. }
  7468. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7469. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7470. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7471. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7472. }
  7473. }
  7474. }
  7475. c.ServeSuccessJSON(map[string]interface{}{
  7476. "order": order,
  7477. "order_info": order_info,
  7478. "patient": patient,
  7479. "admin_info": adminInfo,
  7480. "his_hospital": record,
  7481. "bedCostTotal": bedCostTotal,
  7482. "operationCostTotal": operationCostTotal,
  7483. "otherCostTotal": otherCostTotal,
  7484. "materialCostTotal": materialCostTotal,
  7485. "westernMedicineCostTotal": westernMedicineCostTotal,
  7486. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7487. "checkCostTotal": checkCostTotal,
  7488. "zhenChaCostTotal": zhenChaCostTotal,
  7489. "laboratoryCostTotal": laboratoryCostTotal,
  7490. "treatCostTotal": treatCostTotal,
  7491. })
  7492. } else {
  7493. for _, item := range order_info {
  7494. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7495. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7496. item.MedChrgitmType = "09"
  7497. }
  7498. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7499. if item.HisPrescriptionProject.Type == 2 {
  7500. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7501. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7502. case 0:
  7503. item.MedChrgitmType = "0"
  7504. break
  7505. case 1:
  7506. item.MedChrgitmType = "14"
  7507. break
  7508. case 2:
  7509. item.MedChrgitmType = "05"
  7510. break
  7511. case 3:
  7512. item.MedChrgitmType = "03"
  7513. break
  7514. case 4:
  7515. item.MedChrgitmType = "03"
  7516. break
  7517. case 5:
  7518. item.MedChrgitmType = "08"
  7519. break
  7520. case 6:
  7521. item.MedChrgitmType = "14"
  7522. break
  7523. case 7:
  7524. item.MedChrgitmType = "14"
  7525. break
  7526. case 8:
  7527. item.MedChrgitmType = "03"
  7528. break
  7529. case 9:
  7530. item.MedChrgitmType = "14"
  7531. break
  7532. case 10:
  7533. item.MedChrgitmType = "14"
  7534. break
  7535. case 11:
  7536. item.MedChrgitmType = "06"
  7537. break
  7538. case 12:
  7539. item.MedChrgitmType = "12"
  7540. break
  7541. case 13:
  7542. item.MedChrgitmType = "01"
  7543. break
  7544. case 14:
  7545. item.MedChrgitmType = "04"
  7546. break
  7547. case 15:
  7548. item.MedChrgitmType = "14"
  7549. break
  7550. }
  7551. } else {
  7552. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7553. case 1:
  7554. item.MedChrgitmType = "14"
  7555. break
  7556. case 2:
  7557. item.MedChrgitmType = "05"
  7558. break
  7559. case 3:
  7560. item.MedChrgitmType = "04"
  7561. break
  7562. case 4:
  7563. item.MedChrgitmType = "14"
  7564. break
  7565. case 5:
  7566. item.MedChrgitmType = "08"
  7567. break
  7568. case 6:
  7569. item.MedChrgitmType = "14"
  7570. break
  7571. case 7:
  7572. item.MedChrgitmType = "14"
  7573. break
  7574. case 8:
  7575. item.MedChrgitmType = "03"
  7576. break
  7577. case 9:
  7578. item.MedChrgitmType = "14"
  7579. break
  7580. }
  7581. }
  7582. } else if item.HisPrescriptionProject.Type == 3 {
  7583. item.MedChrgitmType = "08"
  7584. }
  7585. }
  7586. }
  7587. for _, item := range order_info {
  7588. if org_id == 10215 {
  7589. if item.MedChrgitmType == "01" { //床位费
  7590. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7591. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7592. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7593. }
  7594. if item.MedChrgitmType == "02" { //诊察费
  7595. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7596. //zhenChaCostSelfTotal = zhenChaCostTotal
  7597. }
  7598. if item.MedChrgitmType == "03" { //检查费
  7599. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7600. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7601. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7602. }
  7603. //if item.MedChrgitmType == "02" { //检查费
  7604. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7605. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7606. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7607. //}
  7608. if item.MedChrgitmType == "04" { //化验费
  7609. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7610. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7611. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7612. }
  7613. if item.MedChrgitmType == "05" { //治疗费
  7614. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7615. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7616. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7617. }
  7618. if item.MedChrgitmType == "06" { //手术费
  7619. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7620. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7621. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7622. }
  7623. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7624. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7625. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7626. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7627. }
  7628. if item.MedChrgitmType == "09" { //西药费
  7629. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7630. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7631. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7632. }
  7633. if item.MedChrgitmType == "11" { //中成费
  7634. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7635. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7636. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7637. }
  7638. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7639. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7640. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7641. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7642. }
  7643. } else {
  7644. if item.MedChrgitmType == "01" { //床位费
  7645. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7646. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7647. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7648. }
  7649. //if item.MedChrgitmType == "02" { //诊察费
  7650. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7651. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7652. //}
  7653. if item.MedChrgitmType == "03" { //检查费
  7654. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7655. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7656. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7657. }
  7658. //if item.MedChrgitmType == "02" { //检查费
  7659. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7660. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7661. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7662. //}
  7663. if item.MedChrgitmType == "04" { //化验费
  7664. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7665. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7666. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7667. }
  7668. if item.MedChrgitmType == "05" { //治疗费
  7669. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7670. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7671. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7672. }
  7673. if item.MedChrgitmType == "06" { //手术费
  7674. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7675. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7676. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7677. }
  7678. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7679. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7680. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7681. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7682. }
  7683. if item.MedChrgitmType == "09" { //西药费
  7684. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7685. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7686. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7687. }
  7688. if item.MedChrgitmType == "11" { //中成费
  7689. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7690. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7691. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7692. }
  7693. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7694. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7695. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7696. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7697. }
  7698. }
  7699. }
  7700. c.ServeSuccessJSON(map[string]interface{}{
  7701. "order": order,
  7702. "order_info": order_info,
  7703. "patient": patient,
  7704. "admin_info": adminInfo,
  7705. "his_hospital": record,
  7706. "bedCostTotal": bedCostTotal,
  7707. "operationCostTotal": operationCostTotal,
  7708. "otherCostTotal": otherCostTotal,
  7709. "materialCostTotal": materialCostTotal,
  7710. "westernMedicineCostTotal": westernMedicineCostTotal,
  7711. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7712. "checkCostTotal": checkCostTotal,
  7713. "zhenChaCostTotal": zhenChaCostTotal,
  7714. "laboratoryCostTotal": laboratoryCostTotal,
  7715. "treatCostTotal": treatCostTotal,
  7716. })
  7717. }
  7718. }
  7719. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7720. page, _ := c.GetInt64("page")
  7721. limit, _ := c.GetInt64("limit")
  7722. keywords := c.GetString("keywords")
  7723. start_time := c.GetString("start_time")
  7724. end_time := c.GetString("end_time")
  7725. //clr_type := c.GetString("clr_type")
  7726. insutype := c.GetString("insutype")
  7727. timeLayout := "2006-01-02"
  7728. loc, _ := time.LoadLocation("Local")
  7729. var theStartTIme int64
  7730. if len(start_time) > 0 {
  7731. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7732. theStartTIme = theTime.Unix()
  7733. }
  7734. var theEndtTIme int64
  7735. if len(end_time) > 0 {
  7736. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7737. theEndtTIme = theTime.Unix()
  7738. }
  7739. if page <= 0 {
  7740. page = 1
  7741. }
  7742. if limit <= 0 {
  7743. limit = 10
  7744. }
  7745. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7746. c.ServeSuccessJSON(map[string]interface{}{
  7747. "total": total,
  7748. "list": list,
  7749. })
  7750. return
  7751. }
  7752. func (c *HisApiController) GetPutOnRecordList() {
  7753. page, _ := c.GetInt64("page")
  7754. limit, _ := c.GetInt64("limit")
  7755. keywords := c.GetString("keywords")
  7756. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7757. if page <= 0 {
  7758. page = 1
  7759. }
  7760. if limit <= 0 {
  7761. limit = 10
  7762. }
  7763. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7764. c.ServeSuccessJSON(map[string]interface{}{
  7765. "total": total,
  7766. "list": list,
  7767. })
  7768. return
  7769. }
  7770. func (c *HisApiController) GetCompareData() {
  7771. start_time := c.GetString("start_time")
  7772. end_time := c.GetString("end_time")
  7773. insutype := c.GetString("insutype")
  7774. clr_type := c.GetString("clr_type")
  7775. timeLayout := "2006-01-02"
  7776. loc, _ := time.LoadLocation("Local")
  7777. var theStartTIme int64
  7778. if len(start_time) > 0 {
  7779. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7780. if err != nil {
  7781. theStartTIme = 0
  7782. }
  7783. theStartTIme = theTime.Unix()
  7784. }
  7785. var theEndtTIme int64
  7786. if len(end_time) > 0 {
  7787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7788. if err != nil {
  7789. theEndtTIme = 0
  7790. }
  7791. theEndtTIme = theTime.Unix()
  7792. }
  7793. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7794. fmt.Println(err)
  7795. if err == nil {
  7796. c.ServeSuccessJSON(map[string]interface{}{
  7797. "list": formData,
  7798. })
  7799. } else {
  7800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7801. return
  7802. }
  7803. }
  7804. func (c *HisApiController) GetFaPiaoData() {
  7805. order_id, _ := c.GetInt64("order_id")
  7806. patient_id, _ := c.GetInt64("patient_id")
  7807. //number := c.GetString("number")
  7808. adminUser := c.GetAdminUserInfo()
  7809. order, _ := service.GetHisOrderByID(order_id)
  7810. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7811. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7812. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7813. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7814. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7815. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7816. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7817. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7818. var bedCostTotal float64 = 0 //床位总费
  7819. var bedCostSelfTotal float64 = 0 //床位自费
  7820. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7821. var operationCostTotal float64 = 0 //手术费
  7822. var operationCostSelfTotal float64 = 0 //手术费
  7823. var operationCostPartSelfTotal float64 = 0 //手术费
  7824. var otherCostTotal float64 = 0 //其他费用
  7825. var otherCostSelfTotal float64 = 0 //其他费用
  7826. var otherCostPartSelfTotal float64 = 0 //其他费用
  7827. var materialCostTotal float64 = 0 //材料费
  7828. var materialCostSelfTotal float64 = 0 //材料费
  7829. var materialCostPartSelfTotal float64 = 0 //材料费
  7830. var westernMedicineCostTotal float64 = 0 //西药费
  7831. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7832. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7833. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7834. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7835. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7836. var checkCostTotal float64 = 0 //检查费
  7837. var checkCostSelfTotal float64 = 0 //检查费
  7838. var checkCostPartSelfTotal float64 = 0 //检查费
  7839. var hiliCostTotal float64 = 0 //护理费
  7840. var hiliCostSelfTotal float64 = 0 //护理费
  7841. var hiliCostPartSelfTotal float64 = 0 //护理费
  7842. var laboratoryCostTotal float64 = 0 //化验费
  7843. var laboratoryCostSelfTotal float64 = 0 //化验费
  7844. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7845. var treatCostTotal float64 = 0 //治疗费用
  7846. var treatCostSelfTotal float64 = 0 //治疗费用
  7847. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7848. var zhenChaCostTotal float64 = 0 //其他费用
  7849. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7850. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7851. decimal.DivisionPrecision = 2
  7852. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7853. var balanceAccountsType int64
  7854. if his.ID > 0 {
  7855. balanceAccountsType = his.BalanceAccountsType
  7856. } else {
  7857. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7858. }
  7859. if balanceAccountsType == 2 {
  7860. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7861. for _, item := range orderInfos_two {
  7862. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7863. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7864. item.MedChrgitmType = "09"
  7865. }
  7866. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7867. if item.HisPrescriptionProject.Type == 2 {
  7868. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7869. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7870. case 0:
  7871. item.MedChrgitmType = "0"
  7872. break
  7873. case 1:
  7874. item.MedChrgitmType = "14"
  7875. break
  7876. case 2:
  7877. item.MedChrgitmType = "05"
  7878. break
  7879. case 3:
  7880. item.MedChrgitmType = "03"
  7881. break
  7882. case 4:
  7883. item.MedChrgitmType = "03"
  7884. break
  7885. case 5:
  7886. item.MedChrgitmType = "08"
  7887. break
  7888. case 6:
  7889. item.MedChrgitmType = "14"
  7890. break
  7891. case 7:
  7892. item.MedChrgitmType = "14"
  7893. break
  7894. case 8:
  7895. item.MedChrgitmType = "03"
  7896. break
  7897. case 9:
  7898. item.MedChrgitmType = "14"
  7899. break
  7900. case 10:
  7901. item.MedChrgitmType = "14"
  7902. break
  7903. case 11:
  7904. item.MedChrgitmType = "06"
  7905. break
  7906. case 12:
  7907. item.MedChrgitmType = "12"
  7908. break
  7909. case 13:
  7910. item.MedChrgitmType = "01"
  7911. break
  7912. case 14:
  7913. item.MedChrgitmType = "04"
  7914. break
  7915. case 15:
  7916. item.MedChrgitmType = "02"
  7917. break
  7918. }
  7919. } else {
  7920. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7921. case 1:
  7922. item.MedChrgitmType = "14"
  7923. break
  7924. case 2:
  7925. item.MedChrgitmType = "05"
  7926. break
  7927. case 3:
  7928. item.MedChrgitmType = "03"
  7929. break
  7930. case 4:
  7931. item.MedChrgitmType = "03"
  7932. break
  7933. case 5:
  7934. item.MedChrgitmType = "08"
  7935. break
  7936. case 6:
  7937. item.MedChrgitmType = "14"
  7938. break
  7939. case 7:
  7940. item.MedChrgitmType = "14"
  7941. break
  7942. case 8:
  7943. item.MedChrgitmType = "03"
  7944. break
  7945. case 9:
  7946. item.MedChrgitmType = "14"
  7947. break
  7948. }
  7949. }
  7950. } else if item.HisPrescriptionProject.Type == 3 {
  7951. item.MedChrgitmType = "08"
  7952. }
  7953. }
  7954. }
  7955. for _, item := range orderInfos_two {
  7956. fmt.Println(item.MedChrgitmType)
  7957. if item.MedChrgitmType == "07" { //床位费
  7958. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7959. hiliCostSelfTotal = hiliCostTotal
  7960. }
  7961. if item.MedChrgitmType == "01" { //床位费
  7962. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7963. bedCostSelfTotal = bedCostTotal
  7964. }
  7965. if item.MedChrgitmType == "02" { //诊察费
  7966. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7967. zhenChaCostSelfTotal = zhenChaCostTotal
  7968. }
  7969. if item.MedChrgitmType == "03" { //检查费
  7970. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7971. checkCostSelfTotal = checkCostTotal
  7972. }
  7973. if item.MedChrgitmType == "04" { //化验费
  7974. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7975. laboratoryCostSelfTotal = laboratoryCostTotal
  7976. }
  7977. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7978. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7979. treatCostSelfTotal = treatCostTotal
  7980. }
  7981. if item.MedChrgitmType == "06" { //手术费
  7982. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7983. operationCostSelfTotal = treatCostTotal
  7984. }
  7985. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7986. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7987. materialCostSelfTotal = materialCostTotal
  7988. }
  7989. if item.MedChrgitmType == "09" { //西药费
  7990. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7991. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7992. }
  7993. if item.MedChrgitmType == "11" { //中成费
  7994. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7995. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7996. }
  7997. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7998. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7999. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8000. otherCostSelfTotal = otherCostTotal
  8001. }
  8002. } else {
  8003. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8004. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8005. otherCostSelfTotal = otherCostTotal
  8006. }
  8007. }
  8008. }
  8009. } else {
  8010. for _, item := range orderInfos {
  8011. if item.MedChrgitmType == "01" { //床位费
  8012. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8013. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8014. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8015. }
  8016. if item.MedChrgitmType == "02" { //诊察费
  8017. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8018. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8019. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8020. }
  8021. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8022. if item.MedChrgitmType == "03" { //检查费
  8023. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8024. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8025. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8026. }
  8027. } else {
  8028. if item.MedChrgitmType == "03" { //检查费
  8029. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8030. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8031. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8032. }
  8033. }
  8034. if item.MedChrgitmType == "04" { //化验费
  8035. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8036. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8037. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8038. }
  8039. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8040. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8041. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8042. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8043. }
  8044. if item.MedChrgitmType == "06" { //手术费
  8045. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8046. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8047. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8048. }
  8049. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8050. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8051. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8052. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8053. }
  8054. if item.MedChrgitmType == "07" { //西药费
  8055. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8056. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8057. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8058. }
  8059. if item.MedChrgitmType == "09" { //西药费
  8060. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8061. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8062. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8063. }
  8064. if item.MedChrgitmType == "11" { //中成费
  8065. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8066. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8067. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8068. }
  8069. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8070. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8071. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8072. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8073. }
  8074. }
  8075. }
  8076. timeLayout := "2006-01-02"
  8077. loc, _ := time.LoadLocation("Local")
  8078. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8079. if err != nil {
  8080. }
  8081. startRecordDateTime := startTime.Unix()
  8082. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8083. if err != nil {
  8084. }
  8085. endRecordDateTime := endTime.Unix()
  8086. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8087. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8088. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8089. c.ServeSuccessJSON(map[string]interface{}{
  8090. "order_number": order.Number, //业务流水号
  8091. "id_card_no": his.IdCardNo, //社会保障号
  8092. "patient": patient,
  8093. "department_name": department.Name, //科室
  8094. "number": his.Number, //门诊号
  8095. "date": order.SettleAccountsDate, //结算日期
  8096. "name": order.PsnName, //姓名
  8097. "gender": patient.Gender, //性别
  8098. "psn_cash_money": order.PsnCashPay, //个人支付
  8099. "pay_way": "门诊", //结算方式
  8100. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8101. "admin_user_name": admin.UserName, //收款员
  8102. "order": order,
  8103. "order_info": orderInfos_two,
  8104. "his": his,
  8105. "bedCostTotal": bedCostTotal,
  8106. "bedCostSelfTotal": bedCostSelfTotal,
  8107. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8108. "operationCostTotal": operationCostTotal,
  8109. "operationCostSelfTotal": operationCostSelfTotal,
  8110. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8111. "otherCostTotal": otherCostTotal,
  8112. "otherCostSelfTotal": otherCostSelfTotal,
  8113. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8114. "materialCostTotal": materialCostTotal,
  8115. "materialCostSelfTotal": materialCostSelfTotal,
  8116. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8117. "westernMedicineCostTotal": westernMedicineCostTotal,
  8118. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8119. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8120. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8121. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8122. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8123. "checkCostTotal": checkCostTotal,
  8124. "checkCostSelfTotal": checkCostSelfTotal,
  8125. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8126. "laboratoryCostTotal": laboratoryCostTotal,
  8127. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8128. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8129. "treatCostTotal": treatCostTotal,
  8130. "treatCostSelfTotal": treatCostSelfTotal,
  8131. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8132. "zhenChaCostTotal": zhenChaCostTotal,
  8133. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8134. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8135. "his_hospital_record": his_hospital_record,
  8136. "pre_pay_money": pre_pay_money,
  8137. "refund_sum": sum,
  8138. "doctor_info": doctor_info,
  8139. "hiliCostTotal": hiliCostTotal,
  8140. "hiliCostSelfTotal": hiliCostSelfTotal,
  8141. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8142. })
  8143. }
  8144. //func (c *HisApiController) GetFaPiaoDatas() {
  8145. // order_ids := c.GetString("order_ids")
  8146. // patient_id, _ := c.GetInt64("patient_id")
  8147. // adminUser := c.GetAdminUserInfo()
  8148. //
  8149. // orders := strings.Split(order_ids, ",")
  8150. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8151. //
  8152. // for _, item := range orders {
  8153. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8154. // order, _ := service.GetHisOrderByID(order_id)
  8155. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8156. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8157. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8158. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8159. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8160. //
  8161. // }
  8162. //
  8163. // var bedCostTotal float64 = 0 //床位总费
  8164. // var bedCostSelfTotal float64 = 0 //床位自费
  8165. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8166. //
  8167. // var operationCostTotal float64 = 0 //手术费
  8168. // var operationCostSelfTotal float64 = 0 //手术费
  8169. // var operationCostPartSelfTotal float64 = 0 //手术费
  8170. //
  8171. // var otherCostTotal float64 = 0 //其他费用
  8172. // var otherCostSelfTotal float64 = 0 //其他费用
  8173. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8174. //
  8175. // var materialCostTotal float64 = 0 //材料费
  8176. // var materialCostSelfTotal float64 = 0 //材料费
  8177. // var materialCostPartSelfTotal float64 = 0 //材料费
  8178. //
  8179. // var westernMedicineCostTotal float64 = 0 //西药费
  8180. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8181. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8182. //
  8183. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8184. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8185. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8186. //
  8187. // var checkCostTotal float64 = 0 //检查费
  8188. // var checkCostSelfTotal float64 = 0 //检查费
  8189. // var checkCostPartSelfTotal float64 = 0 //检查费
  8190. //
  8191. // var laboratoryCostTotal float64 = 0 //化验费
  8192. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8193. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8194. //
  8195. // var treatCostTotal float64 = 0 //治疗费用
  8196. // var treatCostSelfTotal float64 = 0 //治疗费用
  8197. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8198. //
  8199. // var zhenChaCostTotal float64 = 0 //其他费用
  8200. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8201. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8202. //
  8203. // decimal.DivisionPrecision = 2
  8204. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8205. //
  8206. // var balanceAccountsType int64
  8207. // if his.ID > 0 {
  8208. // balanceAccountsType = his.BalanceAccountsType
  8209. // } else {
  8210. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8211. // }
  8212. // if balanceAccountsType == 2 {
  8213. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8214. // for _, item := range orderInfos_two {
  8215. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8216. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8217. // item.MedChrgitmType = "09"
  8218. // }
  8219. //
  8220. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8221. // if item.HisPrescriptionProject.Type == 2 {
  8222. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8223. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8224. // case 0:
  8225. // item.MedChrgitmType = "0"
  8226. // break
  8227. // case 1:
  8228. // item.MedChrgitmType = "14"
  8229. // break
  8230. // case 2:
  8231. // item.MedChrgitmType = "05"
  8232. //
  8233. // break
  8234. // case 3:
  8235. // item.MedChrgitmType = "03"
  8236. //
  8237. // break
  8238. // case 4:
  8239. // item.MedChrgitmType = "03"
  8240. //
  8241. // break
  8242. // case 5:
  8243. // item.MedChrgitmType = "08"
  8244. //
  8245. // break
  8246. // case 6:
  8247. // item.MedChrgitmType = "14"
  8248. //
  8249. // break
  8250. // case 7:
  8251. // item.MedChrgitmType = "14"
  8252. //
  8253. // break
  8254. // case 8:
  8255. // item.MedChrgitmType = "03"
  8256. // break
  8257. // case 9:
  8258. // item.MedChrgitmType = "14"
  8259. // break
  8260. // case 10:
  8261. // item.MedChrgitmType = "14"
  8262. // break
  8263. // case 11:
  8264. // item.MedChrgitmType = "06"
  8265. // break
  8266. // case 12:
  8267. // item.MedChrgitmType = "12"
  8268. // break
  8269. // case 13:
  8270. // item.MedChrgitmType = "01"
  8271. // break
  8272. // case 14:
  8273. // item.MedChrgitmType = "04"
  8274. // break
  8275. // case 15:
  8276. // item.MedChrgitmType = "02"
  8277. // break
  8278. //
  8279. // }
  8280. //
  8281. // } else {
  8282. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8283. //
  8284. // case 1:
  8285. // item.MedChrgitmType = "14"
  8286. // break
  8287. // case 2:
  8288. // item.MedChrgitmType = "05"
  8289. //
  8290. // break
  8291. // case 3:
  8292. // item.MedChrgitmType = "03"
  8293. //
  8294. // break
  8295. // case 4:
  8296. // item.MedChrgitmType = "03"
  8297. //
  8298. // break
  8299. // case 5:
  8300. // item.MedChrgitmType = "08"
  8301. //
  8302. // break
  8303. // case 6:
  8304. // item.MedChrgitmType = "14"
  8305. //
  8306. // break
  8307. // case 7:
  8308. // item.MedChrgitmType = "14"
  8309. //
  8310. // break
  8311. // case 8:
  8312. // item.MedChrgitmType = "03"
  8313. // break
  8314. // case 9:
  8315. // item.MedChrgitmType = "14"
  8316. // break
  8317. //
  8318. // }
  8319. //
  8320. // }
  8321. //
  8322. // } else if item.HisPrescriptionProject.Type == 3 {
  8323. // item.MedChrgitmType = "08"
  8324. // }
  8325. // }
  8326. // }
  8327. //
  8328. // for _, item := range orderInfos_two {
  8329. // fmt.Println(item.MedChrgitmType)
  8330. // if item.MedChrgitmType == "01" { //床位费
  8331. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8332. // bedCostSelfTotal = bedCostTotal
  8333. // }
  8334. //
  8335. // if item.MedChrgitmType == "02" { //诊察费
  8336. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8337. // zhenChaCostSelfTotal = zhenChaCostTotal
  8338. // }
  8339. //
  8340. // if item.MedChrgitmType == "03" { //检查费
  8341. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8342. // checkCostSelfTotal = checkCostTotal
  8343. // }
  8344. //
  8345. // if item.MedChrgitmType == "04" { //化验费
  8346. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8347. // laboratoryCostSelfTotal = laboratoryCostTotal
  8348. // }
  8349. //
  8350. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8351. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8352. // treatCostSelfTotal = treatCostTotal
  8353. // }
  8354. //
  8355. // if item.MedChrgitmType == "06" { //手术费
  8356. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8357. // operationCostSelfTotal = treatCostTotal
  8358. // }
  8359. //
  8360. // if item.MedChrgitmType == "08" { //材料费
  8361. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8362. // materialCostSelfTotal = materialCostTotal
  8363. // }
  8364. //
  8365. // if item.MedChrgitmType == "09" { //西药费
  8366. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8367. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8368. // }
  8369. //
  8370. // if item.MedChrgitmType == "11" { //中成费
  8371. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8372. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8373. // }
  8374. //
  8375. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8376. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8377. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8378. // otherCostSelfTotal = otherCostTotal
  8379. // }
  8380. // } else {
  8381. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8382. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8383. // otherCostSelfTotal = otherCostTotal
  8384. // }
  8385. //
  8386. // }
  8387. //
  8388. // }
  8389. //
  8390. // } else {
  8391. // for _, item := range orderInfos {
  8392. // if item.MedChrgitmType == "01" { //床位费
  8393. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8394. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8395. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8396. // }
  8397. //
  8398. // if item.MedChrgitmType == "02" { //诊察费
  8399. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8400. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8401. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8402. // }
  8403. //
  8404. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8405. // if item.MedChrgitmType == "03" { //检查费
  8406. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8407. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8408. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8409. //
  8410. // }
  8411. // } else {
  8412. // if item.MedChrgitmType == "03" { //检查费
  8413. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8414. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8415. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8416. // }
  8417. //
  8418. // }
  8419. //
  8420. // if item.MedChrgitmType == "04" { //化验费
  8421. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8422. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8423. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8424. //
  8425. // }
  8426. //
  8427. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8428. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8429. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8430. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8431. //
  8432. // }
  8433. //
  8434. // if item.MedChrgitmType == "06" { //手术费
  8435. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8436. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8437. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8438. // }
  8439. //
  8440. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8441. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8442. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8443. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8444. // }
  8445. //
  8446. // if item.MedChrgitmType == "09" { //西药费
  8447. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8448. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8449. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8450. // }
  8451. //
  8452. // if item.MedChrgitmType == "11" { //中成费
  8453. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8454. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8455. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8456. // }
  8457. //
  8458. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8459. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8460. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8461. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8462. // }
  8463. //
  8464. // }
  8465. // }
  8466. // timeLayout := "2006-01-02"
  8467. // loc, _ := time.LoadLocation("Local")
  8468. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8469. // if err != nil {
  8470. // }
  8471. // startRecordDateTime := startTime.Unix()
  8472. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8473. // if err != nil {
  8474. // }
  8475. // endRecordDateTime := endTime.Unix()
  8476. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8477. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8478. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8479. //
  8480. // c.ServeSuccessJSON(map[string]interface{}{
  8481. // "order_number": order.Number, //业务流水号
  8482. // "id_card_no": his.IdCardNo, //社会保障号
  8483. // "department_name": department.Name, //科室
  8484. // "number": his.Number, //门诊号
  8485. // "date": order.SettleAccountsDate, //结算日期
  8486. // "name": order.PsnName, //姓名
  8487. // "gender": patient.Gender, //性别
  8488. // "psn_cash_money": order.PsnCashPay, //个人支付
  8489. // "pay_way": "门诊", //结算方式
  8490. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8491. // "admin_user_name": admin.UserName, //收款员
  8492. // "order": order,
  8493. // "order_info": orderInfos_two,
  8494. // "his": his,
  8495. // "bedCostTotal": bedCostTotal,
  8496. // "bedCostSelfTotal": bedCostSelfTotal,
  8497. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8498. // "operationCostTotal": operationCostTotal,
  8499. // "operationCostSelfTotal": operationCostSelfTotal,
  8500. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8501. // "otherCostTotal": otherCostTotal,
  8502. // "otherCostSelfTotal": otherCostSelfTotal,
  8503. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8504. // "materialCostTotal": materialCostTotal,
  8505. // "materialCostSelfTotal": materialCostSelfTotal,
  8506. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8507. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8508. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8509. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8510. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8511. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8512. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8513. // "checkCostTotal": checkCostTotal,
  8514. // "checkCostSelfTotal": checkCostSelfTotal,
  8515. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8516. // "laboratoryCostTotal": laboratoryCostTotal,
  8517. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8518. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8519. // "treatCostTotal": treatCostTotal,
  8520. // "treatCostSelfTotal": treatCostSelfTotal,
  8521. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8522. // "zhenChaCostTotal": zhenChaCostTotal,
  8523. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8524. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8525. // "his_hospital_record": his_hospital_record,
  8526. // "pre_pay_money": pre_pay_money,
  8527. // "refund_sum": sum,
  8528. // })
  8529. //
  8530. //}
  8531. func (this *HisApiController) GetIncomeStatisticsData() {
  8532. start_time := this.GetString("start_time")
  8533. end_time := this.GetString("end_time")
  8534. key_words := this.GetString("key_words")
  8535. limit, _ := this.GetInt64("limit")
  8536. page, _ := this.GetInt64("page")
  8537. if page <= 0 {
  8538. page = 1
  8539. }
  8540. if limit <= 0 {
  8541. limit = 10
  8542. }
  8543. statistics_type, _ := this.GetInt64("statistics_type")
  8544. admin := this.GetAdminUserInfo()
  8545. timeLayout := "2006-01-02"
  8546. loc, _ := time.LoadLocation("Local")
  8547. var theStartTIme int64
  8548. if len(start_time) > 0 {
  8549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8550. if err != nil {
  8551. theStartTIme = 0
  8552. }
  8553. theStartTIme = theTime.Unix()
  8554. }
  8555. var theEndtTIme int64
  8556. if len(end_time) > 0 {
  8557. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8558. if err != nil {
  8559. theEndtTIme = 0
  8560. }
  8561. theEndtTIme = theTime.Unix()
  8562. }
  8563. if statistics_type == 1 {
  8564. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8565. this.ServeSuccessJSON(map[string]interface{}{
  8566. "list": list,
  8567. "total": total,
  8568. })
  8569. } else {
  8570. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8571. this.ServeSuccessJSON(map[string]interface{}{
  8572. "list": list,
  8573. "total": total,
  8574. })
  8575. }
  8576. }
  8577. func (c *HisApiController) PostProjectInformation() {
  8578. adminUser := c.GetAdminUserInfo()
  8579. orgId := adminUser.CurrentOrgId
  8580. dataBody := make(map[string]interface{}, 0)
  8581. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8582. if err != nil {
  8583. utils.ErrorLog(err.Error())
  8584. return
  8585. }
  8586. utils.ErrorLog("%v", dataBody)
  8587. var projectList []*models.HisProject
  8588. var total_goods []interface{}
  8589. tempProjects := dataBody["projects"].([]interface{})
  8590. total_goods = tempProjects
  8591. for index, projectMap := range tempProjects {
  8592. projectM := projectMap.(map[string]interface{})
  8593. var project models.HisProject
  8594. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8595. utils.ErrorLog("project_name")
  8596. return
  8597. }
  8598. project_name, _ := projectM["project_name"].(string)
  8599. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8600. err_log := models.ExportErrLog{
  8601. LogType: 6,
  8602. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8603. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8604. Status: 1,
  8605. CreateTime: time.Now().Unix(),
  8606. UpdateTime: time.Now().Unix(),
  8607. ExportTime: time.Now().Unix(),
  8608. }
  8609. service.CreateExportErrLog(&err_log)
  8610. continue
  8611. }
  8612. project.ProjectName = project_name
  8613. prices := projectM["price"].(string)
  8614. price, _ := strconv.ParseFloat(prices, 64)
  8615. if price <= 0 { //名字为空则生成一条导入错误日志
  8616. err_log := models.ExportErrLog{
  8617. LogType: 6,
  8618. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8619. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8620. Status: 1,
  8621. CreateTime: time.Now().Unix(),
  8622. UpdateTime: time.Now().Unix(),
  8623. ExportTime: time.Now().Unix(),
  8624. }
  8625. service.CreateExportErrLog(&err_log)
  8626. continue
  8627. }
  8628. project.Price = price
  8629. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8630. utils.ErrorLog("unit_id")
  8631. return
  8632. }
  8633. unit := projectM["unit"].(string)
  8634. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8635. err_log := models.ExportErrLog{
  8636. LogType: 6,
  8637. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8638. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8639. Status: 1,
  8640. CreateTime: time.Now().Unix(),
  8641. UpdateTime: time.Now().Unix(),
  8642. ExportTime: time.Now().Unix(),
  8643. }
  8644. service.CreateExportErrLog(&err_log)
  8645. continue
  8646. }
  8647. project.Unit = unit
  8648. cost_classify := projectM["cost_classify"].(string)
  8649. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8650. err_log := models.ExportErrLog{
  8651. LogType: 6,
  8652. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8653. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8654. Status: 1,
  8655. CreateTime: time.Now().Unix(),
  8656. UpdateTime: time.Now().Unix(),
  8657. ExportTime: time.Now().Unix(),
  8658. }
  8659. service.CreateExportErrLog(&err_log)
  8660. continue
  8661. }
  8662. var costClassify = "费用类别"
  8663. var cost_classify_id int64
  8664. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8665. if len(cost_classify) != 0 {
  8666. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8667. if errcode == gorm.ErrRecordNotFound {
  8668. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8669. dataconfig := models.DictDataconfig{
  8670. ParentId: costClassifyConfig.ID,
  8671. Module: "system",
  8672. OrgId: orgId,
  8673. Name: cost_classify,
  8674. FieldName: "",
  8675. Value: costConfig.Value + 1,
  8676. CreatedTime: "",
  8677. UpdatedTime: "",
  8678. CreateUserId: adminUser.AdminUser.Id,
  8679. Status: 1,
  8680. Remark: "",
  8681. DeleteIdSystem: 0,
  8682. Title: "",
  8683. Content: "",
  8684. Order: 0,
  8685. Code: "",
  8686. }
  8687. service.CreatedDicConfig(&dataconfig)
  8688. }
  8689. }
  8690. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8691. for _, it := range costClassList {
  8692. if cost_classify == it.Name {
  8693. cost_classify_id = int64(it.Value)
  8694. }
  8695. }
  8696. project.CostClassify = cost_classify_id
  8697. executive_section := projectM["executive_section"].(string)
  8698. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8699. err_log := models.ExportErrLog{
  8700. LogType: 6,
  8701. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8702. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8703. Status: 1,
  8704. CreateTime: time.Now().Unix(),
  8705. UpdateTime: time.Now().Unix(),
  8706. ExportTime: time.Now().Unix(),
  8707. }
  8708. service.CreateExportErrLog(&err_log)
  8709. continue
  8710. }
  8711. if len(executive_section) != 0 {
  8712. //查找科室是否有内容
  8713. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8714. if errcodedepart == gorm.ErrRecordNotFound {
  8715. department := models.XtHisDepartment{
  8716. Name: executive_section,
  8717. Status: 1,
  8718. UserOrgId: adminUser.CurrentOrgId,
  8719. CreatedTime: time.Now().Unix(),
  8720. }
  8721. service.CreateDePartment(&department)
  8722. }
  8723. }
  8724. var executive_section_id int64
  8725. departMentList, _ := service.GetAllDepartMent(orgId)
  8726. for _, it := range departMentList {
  8727. if executive_section == it.Name {
  8728. executive_section_id = it.ID
  8729. }
  8730. }
  8731. project.ExecutiveSection = executive_section_id
  8732. medical_coverage := projectM["medical_coverage"].(string)
  8733. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8734. err_log := models.ExportErrLog{
  8735. LogType: 6,
  8736. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8737. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8738. Status: 1,
  8739. CreateTime: time.Now().Unix(),
  8740. UpdateTime: time.Now().Unix(),
  8741. ExportTime: time.Now().Unix(),
  8742. }
  8743. service.CreateExportErrLog(&err_log)
  8744. continue
  8745. }
  8746. var medicalCoverage = "医保等级"
  8747. var medical_coverage_id int64
  8748. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8749. if len(medical_coverage) != 0 {
  8750. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8751. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8752. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8753. dataconfig := models.DictDataconfig{
  8754. ParentId: medicalCoverageConfig.ID,
  8755. Module: "system",
  8756. OrgId: orgId,
  8757. Name: medical_coverage,
  8758. FieldName: "",
  8759. Value: medicalCoverageConfig.Value + 1,
  8760. CreatedTime: "",
  8761. UpdatedTime: "",
  8762. CreateUserId: adminUser.AdminUser.Id,
  8763. Status: 1,
  8764. Remark: "",
  8765. DeleteIdSystem: 0,
  8766. Title: "",
  8767. Content: "",
  8768. Order: 0,
  8769. Code: "",
  8770. }
  8771. service.CreatedDicConfig(&dataconfig)
  8772. }
  8773. }
  8774. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8775. for _, it := range medicalCoverageList {
  8776. if medical_coverage == it.Name {
  8777. medical_coverage_id = int64(it.Value)
  8778. }
  8779. }
  8780. project.MedicalCoverage = medical_coverage_id
  8781. pinyin := projectM["pinyin"].(string)
  8782. project.Pinyin = pinyin
  8783. wubi := projectM["wubi"].(string)
  8784. project.Wubi = wubi
  8785. statistical_classification := projectM["statistical_classification"].(string)
  8786. var statisticalClassification = "统计分类"
  8787. var statistical_classification_id int64
  8788. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8789. if len(statistical_classification) != 0 {
  8790. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8791. if classificationerrcodes == gorm.ErrRecordNotFound {
  8792. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8793. dataconfig := models.DictDataconfig{
  8794. ParentId: classiFication.ID,
  8795. Module: "system",
  8796. OrgId: orgId,
  8797. Name: statistical_classification,
  8798. FieldName: "",
  8799. Value: classiFicationConfig.Value + 1,
  8800. CreatedTime: "",
  8801. UpdatedTime: "",
  8802. CreateUserId: adminUser.AdminUser.Id,
  8803. Status: 1,
  8804. Remark: "",
  8805. DeleteIdSystem: 0,
  8806. Title: "",
  8807. Content: "",
  8808. Order: 0,
  8809. Code: "",
  8810. }
  8811. service.CreatedDicConfig(&dataconfig)
  8812. }
  8813. }
  8814. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8815. for _, it := range classiFicationList {
  8816. if statistical_classification == it.Name {
  8817. statistical_classification_id = int64(it.Value)
  8818. }
  8819. }
  8820. project.StatisticalClassification = statistical_classification_id
  8821. disease_directory := int64(projectM["disease_directory"].(float64))
  8822. project.DiseaseDirectory = disease_directory
  8823. is_record := int64(projectM["is_record"].(float64))
  8824. project.IsRecord = is_record
  8825. medical_code := projectM["medical_code"].(string)
  8826. project.MedicalCode = medical_code
  8827. tube_color := projectM["tube_color"].(string)
  8828. var tubeColor = "试管颜色"
  8829. var tube_color_id int64
  8830. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8831. if len(tube_color) != 0 {
  8832. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8833. if errcodetube == gorm.ErrRecordNotFound {
  8834. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8835. dataconfig := models.DictDataconfig{
  8836. ParentId: tubeColorConfig.ID,
  8837. Module: "system",
  8838. OrgId: orgId,
  8839. Name: tube_color,
  8840. FieldName: "",
  8841. Value: tubeConfig.Value + 1,
  8842. CreatedTime: "",
  8843. UpdatedTime: "",
  8844. CreateUserId: adminUser.AdminUser.Id,
  8845. Status: 1,
  8846. Remark: "",
  8847. DeleteIdSystem: 0,
  8848. Title: "",
  8849. Content: "",
  8850. Order: 0,
  8851. Code: "",
  8852. }
  8853. service.CreatedDicConfig(&dataconfig)
  8854. }
  8855. }
  8856. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8857. for _, it := range tubeColorList {
  8858. if tube_color == it.Name {
  8859. tube_color_id = int64(it.Value)
  8860. }
  8861. }
  8862. project.TubeColor = tube_color_id
  8863. single_dose := projectM["single_dose"].(string)
  8864. project.SingleDose = single_dose
  8865. execution_frequency := projectM["execution_frequency"].(string)
  8866. project.ExecutionFrequency = execution_frequency
  8867. delivery_way := projectM["delivery_way"].(string)
  8868. project.DeliveryWay = delivery_way
  8869. number_days := projectM["number_days"].(string)
  8870. project.NumberDays = number_days
  8871. total := projectM["total"].(string)
  8872. project.Total = total
  8873. medical_status := int64(projectM["medical_status"].(float64))
  8874. project.MedicalStatus = medical_status
  8875. category := int64(projectM["category"].(float64))
  8876. project.Category = category
  8877. specail_project := int64(projectM["specail_project"].(float64))
  8878. project.SpecailProject = specail_project
  8879. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8880. project.SocialSecurityDirectoryCode = social_security_directory_code
  8881. remark := projectM["remark"].(string)
  8882. project.Remark = remark
  8883. record_date := projectM["record_date"].(string)
  8884. timeLayout := "2006-01-02"
  8885. loc, _ := time.LoadLocation("Local")
  8886. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8887. project.RecordDate = theTime.Unix()
  8888. projectList = append(projectList, &project)
  8889. }
  8890. export_time := time.Now().Unix()
  8891. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8892. if len(projectList) > 0 {
  8893. for _, item := range projectList {
  8894. project := models.HisProject{
  8895. ProjectName: item.ProjectName,
  8896. Price: item.Price,
  8897. Unit: item.Unit,
  8898. CostClassify: item.CostClassify,
  8899. ExecutiveSection: item.ExecutiveSection,
  8900. MedicalCoverage: item.MedicalCoverage,
  8901. UserOrgId: orgId,
  8902. Status: 1,
  8903. CreatedTime: time.Now().Unix(),
  8904. Pinyin: item.Pinyin,
  8905. Wubi: item.Wubi,
  8906. StatisticalClassification: item.StatisticalClassification,
  8907. DiseaseDirectory: item.DiseaseDirectory,
  8908. IsRecord: item.IsRecord,
  8909. MedicalCode: item.MedicalCode,
  8910. TubeColor: item.TubeColor,
  8911. SingleDose: item.SingleDose,
  8912. DeliveryWay: item.DeliveryWay,
  8913. NumberDays: item.NumberDays,
  8914. Total: item.Total,
  8915. Category: item.Category,
  8916. MedicalStatus: item.MedicalStatus,
  8917. SpecailProject: item.SpecailProject,
  8918. RecordDate: item.RecordDate,
  8919. Remark: item.Remark,
  8920. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8921. ExecutionFrequency: item.ExecutionFrequency,
  8922. }
  8923. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8924. if errcodeproject == gorm.ErrRecordNotFound {
  8925. service.CreateProjectInfomation(&project)
  8926. } else if errcodeproject == nil {
  8927. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8928. }
  8929. log := models.ExportLog{
  8930. LogType: 6,
  8931. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8932. TotalNum: int64(len(total_goods)),
  8933. FailNum: int64(len(errLogs)),
  8934. SuccessNum: int64(len(projectList)),
  8935. CreateTime: time.Now().Unix(),
  8936. UpdateTime: time.Now().Unix(),
  8937. ExportTime: export_time,
  8938. Status: 1,
  8939. }
  8940. service.CreateExportLog(&log)
  8941. c.ServeSuccessJSON(map[string]interface{}{
  8942. "msg": "导入成功",
  8943. "total_num": len(total_goods),
  8944. "success_num": len(projectList),
  8945. "fail_num": int64(len(errLogs)),
  8946. })
  8947. }
  8948. } else {
  8949. log := models.ExportLog{
  8950. LogType: 6,
  8951. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8952. TotalNum: int64(len(total_goods)),
  8953. FailNum: int64(len(errLogs)),
  8954. SuccessNum: int64(len(projectList)),
  8955. CreateTime: time.Now().Unix(),
  8956. UpdateTime: time.Now().Unix(),
  8957. ExportTime: export_time,
  8958. Status: 1,
  8959. }
  8960. service.CreateExportLog(&log)
  8961. c.ServeSuccessJSON(map[string]interface{}{
  8962. "msg": "导入成功",
  8963. "total_num": len(total_goods),
  8964. "success_num": len(projectList),
  8965. "fail_num": int64(len(errLogs)),
  8966. })
  8967. }
  8968. }
  8969. //func (this *HisApiController) EditProjectInformation(){
  8970. //
  8971. // id, _ := this.GetInt64("id")
  8972. // project_team := this.GetString("project_team")
  8973. // price := this.GetString("price")
  8974. // price_float, _ := strconv.ParseFloat(price, 64)
  8975. // pinyin := this.GetString("pinyin")
  8976. // wubi := this.GetString("wubi")
  8977. // tube_color, _ := this.GetInt64("tube_color")
  8978. // team_type, _ := this.GetInt64("team_type")
  8979. // remark := this.GetString("remark")
  8980. // ids := this.GetString("ids")
  8981. // item_id := this.GetString("item_id")
  8982. // projectTeam := models.XtHisProjectTeam{
  8983. // ProjectTeam: project_team,
  8984. // Price: price_float,
  8985. // Pinyin: pinyin,
  8986. // Wubi: wubi,
  8987. // TubeColor: tube_color,
  8988. // TeamType: team_type,
  8989. // Remark: remark,
  8990. // ProjectId: ids,
  8991. // ItemId: item_id,
  8992. // }
  8993. //
  8994. //
  8995. // dataBody := make(map[string]interface{}, 0)
  8996. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8997. // if err != nil {
  8998. // utils.ErrorLog(err.Error())
  8999. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9000. // return
  9001. // }
  9002. //
  9003. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9004. //
  9005. //
  9006. // if err != nil {
  9007. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9008. // return
  9009. // }
  9010. //
  9011. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9012. // infos, _ := dataBody["info"].([]interface{})
  9013. // if len(infos) > 0 {
  9014. // var ids []string
  9015. //
  9016. // for _, item := range infos {
  9017. // items := item.(map[string]interface{})
  9018. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9019. // utils.ErrorLog("id")
  9020. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9021. // return
  9022. // }
  9023. // id := int64(items["id"].(float64))
  9024. //
  9025. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9026. // utils.ErrorLog("type")
  9027. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9028. // return
  9029. // }
  9030. // types := int64(items["type"].(float64))
  9031. //
  9032. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9033. // utils.ErrorLog("number")
  9034. // }
  9035. //
  9036. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9037. //
  9038. // projectList := models.XtHisProjectList{
  9039. // Number: number,
  9040. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9041. // ProjectId: id,
  9042. // Status: 1,
  9043. // CreatedTime: time.Now().Unix(),
  9044. // UpdatedTime: time.Now().Unix(),
  9045. // TeamId: projectTeam.ID,
  9046. // Type: types,
  9047. // }
  9048. // list := projectList
  9049. //
  9050. // service.CreateProjectList(&list)
  9051. //
  9052. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9053. //
  9054. // }
  9055. // ids_str := strings.Join(ids, ",")
  9056. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9057. // service.SaveProjectTeam(&projectTeam)
  9058. // this.ServeSuccessJSON(map[string]interface{}{
  9059. // "projectTeam": projectTeam,
  9060. // })
  9061. // }
  9062. // }
  9063. //}
  9064. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9065. name := c.GetString("name")
  9066. mode_id, _ := c.GetInt64("mode", 0)
  9067. types, _ := c.GetInt64("type", 0)
  9068. patient_id, _ := c.GetInt64("patient_id", 0)
  9069. types = 1
  9070. adminInfo := c.GetAdminUserInfo()
  9071. template := &models.HisPrescriptionTemplate{
  9072. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9073. PatientId: patient_id,
  9074. Type: types,
  9075. Status: 1,
  9076. Ctime: time.Now().Unix(),
  9077. Mtime: time.Now().Unix(),
  9078. Name: name,
  9079. Mode: mode_id,
  9080. }
  9081. dataBody := make(map[string]interface{}, 0)
  9082. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9083. if err != nil {
  9084. utils.ErrorLog(err.Error())
  9085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9086. return
  9087. }
  9088. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9089. //如果已经存在记录则删除处方
  9090. if template_one.ID > 0 {
  9091. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9092. for _, item := range ps {
  9093. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  9094. }
  9095. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9096. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9097. if len(prescriptions) > 0 {
  9098. for _, item := range prescriptions {
  9099. items := item.(map[string]interface{})
  9100. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9101. utils.ErrorLog("type")
  9102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9103. return
  9104. }
  9105. types := int64(items["type"].(float64))
  9106. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9107. utils.ErrorLog("med_type")
  9108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9109. return
  9110. }
  9111. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9112. ctime := time.Now().Unix()
  9113. prescription := &models.HisPrescriptionInfoTemplate{
  9114. PatientId: patient_id,
  9115. UserOrgId: adminInfo.CurrentOrgId,
  9116. Ctime: ctime,
  9117. Mtime: ctime,
  9118. Type: types,
  9119. Modifier: adminInfo.AdminUser.Id,
  9120. Creator: adminInfo.AdminUser.Id,
  9121. Status: 1,
  9122. PTemplateId: template_one.ID,
  9123. MedType: med_type,
  9124. }
  9125. service.CreateHisPrescriptionInfoTemplate(prescription)
  9126. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9127. advices := items["advices"].([]interface{})
  9128. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9129. ctime := time.Now().Unix()
  9130. mtime := ctime
  9131. if len(advices) > 0 {
  9132. for _, advice := range advices {
  9133. var s models.HisPrescriptionAdviceTemplate
  9134. s.PrescriptionId = prescription.ID
  9135. s.AdviceType = 2
  9136. s.StopState = 2
  9137. s.ExecutionState = 2
  9138. s.Status = 1
  9139. s.UserOrgId = adminInfo.CurrentOrgId
  9140. s.CreatedTime = ctime
  9141. s.UpdatedTime = mtime
  9142. s.PatientId = patient_id
  9143. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9144. if errcode > 0 {
  9145. c.ServeFailJSONWithSGJErrorCode(errcode)
  9146. return
  9147. }
  9148. service.CreateHisPrescriptionAdviceTemplate(&s)
  9149. }
  9150. }
  9151. }
  9152. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9153. projects := items["project"].([]interface{})
  9154. if len(projects) > 0 {
  9155. for _, project := range projects {
  9156. var p models.HisPrescriptionProjectTemplate
  9157. p.PrescriptionId = prescription.ID
  9158. p.Ctime = time.Now().Unix()
  9159. p.Mtime = time.Now().Unix()
  9160. p.PatientId = patient_id
  9161. p.UserOrgId = adminInfo.CurrentOrgId
  9162. p.Status = 1
  9163. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9164. if errcode > 0 {
  9165. c.ServeFailJSONWithSGJErrorCode(errcode)
  9166. return
  9167. }
  9168. service.CreateHisPrescriptionProjectTemplate(&p)
  9169. }
  9170. }
  9171. }
  9172. }
  9173. c.ServeSuccessJSON(map[string]interface{}{
  9174. "msg": "创建成功",
  9175. })
  9176. }
  9177. }
  9178. } else {
  9179. err = service.CreateHisPrescriptionTemplate(template)
  9180. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9181. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9182. if len(prescriptions) > 0 {
  9183. for _, item := range prescriptions {
  9184. items := item.(map[string]interface{})
  9185. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9186. utils.ErrorLog("type")
  9187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9188. return
  9189. }
  9190. types := int64(items["type"].(float64))
  9191. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9192. utils.ErrorLog("med_type")
  9193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9194. return
  9195. }
  9196. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9197. ctime := time.Now().Unix()
  9198. prescription := &models.HisPrescriptionInfoTemplate{
  9199. PatientId: patient_id,
  9200. UserOrgId: adminInfo.CurrentOrgId,
  9201. Ctime: ctime,
  9202. Mtime: ctime,
  9203. Type: types,
  9204. Modifier: adminInfo.AdminUser.Id,
  9205. Creator: adminInfo.AdminUser.Id,
  9206. Status: 1,
  9207. PTemplateId: template.ID,
  9208. MedType: med_type,
  9209. }
  9210. service.CreateHisPrescriptionInfoTemplate(prescription)
  9211. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9212. advices := items["advices"].([]interface{})
  9213. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9214. ctime := time.Now().Unix()
  9215. mtime := ctime
  9216. if len(advices) > 0 {
  9217. for _, advice := range advices {
  9218. var s models.HisPrescriptionAdviceTemplate
  9219. s.PrescriptionId = prescription.ID
  9220. s.AdviceType = 2
  9221. s.StopState = 2
  9222. s.ExecutionState = 2
  9223. s.Status = 1
  9224. s.UserOrgId = adminInfo.CurrentOrgId
  9225. s.CreatedTime = ctime
  9226. s.UpdatedTime = mtime
  9227. s.PatientId = patient_id
  9228. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9229. if errcode > 0 {
  9230. c.ServeFailJSONWithSGJErrorCode(errcode)
  9231. return
  9232. }
  9233. service.CreateHisPrescriptionAdviceTemplate(&s)
  9234. }
  9235. }
  9236. }
  9237. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9238. projects := items["project"].([]interface{})
  9239. if len(projects) > 0 {
  9240. for _, project := range projects {
  9241. var p models.HisPrescriptionProjectTemplate
  9242. p.PrescriptionId = prescription.ID
  9243. p.Ctime = time.Now().Unix()
  9244. p.Mtime = time.Now().Unix()
  9245. p.PatientId = patient_id
  9246. p.UserOrgId = adminInfo.CurrentOrgId
  9247. p.Status = 1
  9248. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9249. if errcode > 0 {
  9250. c.ServeFailJSONWithSGJErrorCode(errcode)
  9251. return
  9252. }
  9253. service.CreateHisPrescriptionProjectTemplate(&p)
  9254. }
  9255. }
  9256. }
  9257. }
  9258. c.ServeSuccessJSON(map[string]interface{}{
  9259. "msg": "创建成功",
  9260. })
  9261. }
  9262. }
  9263. }
  9264. }
  9265. func (c *HisApiController) PreSettle() {
  9266. id, _ := c.GetInt64("id")
  9267. record_time := c.GetString("record_time")
  9268. his_patient_id, _ := c.GetInt64("his_patient_id")
  9269. timeLayout := "2006-01-02"
  9270. loc, _ := time.LoadLocation("Local")
  9271. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9272. diagnosis_id := c.GetString("diagnosis")
  9273. sick_type, _ := c.GetInt64("sick_type")
  9274. reg_type, _ := c.GetInt64("p_type")
  9275. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9276. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9277. if err != nil {
  9278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9279. return
  9280. }
  9281. recordDateTime := theTime.Unix()
  9282. adminUser := c.GetAdminUserInfo()
  9283. var prescriptions []*models.HisPrescription
  9284. var start_time int64
  9285. var end_time int64
  9286. ids_str := c.GetString("ids")
  9287. ids_arr := strings.Split(ids_str, ",")
  9288. fmt.Println(reg_type)
  9289. if settle_accounts_type == 1 { //日结
  9290. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9291. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9292. } else {
  9293. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9294. }
  9295. fmt.Println(prescriptions)
  9296. } else { //月结
  9297. start_time_str := c.GetString("start_time")
  9298. end_time_str := c.GetString("end_time")
  9299. timeLayout := "2006-01-02"
  9300. loc, _ := time.LoadLocation("Local")
  9301. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9302. if err != nil {
  9303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9304. return
  9305. }
  9306. recordStartTime := theStartTime.Unix()
  9307. start_time = recordStartTime
  9308. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9309. if err != nil {
  9310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9311. return
  9312. }
  9313. recordEndTime := theEndTime.Unix()
  9314. end_time = recordEndTime
  9315. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9316. }
  9317. if reg_type == 1111 || reg_type == 1112 {
  9318. reg_type = 11
  9319. }
  9320. timestamp := time.Now().Unix()
  9321. tempTime := time.Unix(timestamp, 0)
  9322. timeFormat := tempTime.Format("20060102150405")
  9323. chrgBchno := rand.Intn(100000) + 10000
  9324. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9325. strconv.FormatInt(his.PatientId, 10)
  9326. var ids []int64
  9327. for _, item := range prescriptions {
  9328. ids = append(ids, item.ID)
  9329. }
  9330. fmt.Println(ids)
  9331. var total float64
  9332. for _, item := range prescriptions {
  9333. fmt.Println(item)
  9334. if item.Type == 1 { //药品
  9335. for _, subItem := range item.HisDoctorAdviceInfo {
  9336. total = total + (subItem.Price * subItem.PrescribingNumber)
  9337. }
  9338. }
  9339. if item.Type == 2 { //项目
  9340. for _, subItem := range item.HisPrescriptionProject {
  9341. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9342. total = total + (subItem.Price * cnt)
  9343. }
  9344. }
  9345. for _, subItem := range item.HisAdditionalCharge {
  9346. total = total + (subItem.Price * float64(subItem.Count))
  9347. }
  9348. }
  9349. allTotal := fmt.Sprintf("%.2f", total)
  9350. totals, _ := strconv.ParseFloat(allTotal, 64)
  9351. order := &models.HisOrder{
  9352. UserOrgId: adminUser.CurrentOrgId,
  9353. HisPatientId: his.ID,
  9354. PatientId: id,
  9355. SettleAccountsDate: recordDateTime,
  9356. Ctime: time.Now().Unix(),
  9357. Mtime: time.Now().Unix(),
  9358. Status: 1,
  9359. OrderStatus: 1,
  9360. MdtrtId: his.Number,
  9361. Number: chrg_bchno,
  9362. MedfeeSumamt: totals,
  9363. SettleEndTime: end_time,
  9364. SettleStartTime: start_time,
  9365. SettleType: settle_accounts_type,
  9366. PsnPartAmt: totals,
  9367. PsnCashPay: totals,
  9368. PType: 2,
  9369. IsPre: 1,
  9370. MedType: strconv.Itoa(int(reg_type)),
  9371. Diagnosis: diagnosis_id,
  9372. }
  9373. err = service.CreateOrder(order)
  9374. if err != nil {
  9375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9376. return
  9377. }
  9378. var customs []*Custom
  9379. for _, item := range prescriptions {
  9380. fmt.Println(item.Type)
  9381. if item.Type == 1 { //药品
  9382. for _, subItem := range item.HisDoctorAdviceInfo {
  9383. cus := &Custom{
  9384. AdviceId: subItem.ID,
  9385. ProjectId: 0,
  9386. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9387. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9388. FeedetlSn: subItem.FeedetlSn,
  9389. Price: fmt.Sprintf("%.2f", subItem.Price),
  9390. MedListCodg: subItem.MedListCodg,
  9391. Type: 1,
  9392. }
  9393. customs = append(customs, cus)
  9394. }
  9395. }
  9396. if item.Type == 2 { //项目
  9397. for _, subItem := range item.HisPrescriptionProject {
  9398. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9399. cus := &Custom{
  9400. AdviceId: 0,
  9401. ProjectId: subItem.ID,
  9402. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9403. Cut: fmt.Sprintf("%.2f", cnt),
  9404. FeedetlSn: subItem.FeedetlSn,
  9405. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9406. MedListCodg: subItem.MedListCodg,
  9407. Type: 2,
  9408. }
  9409. customs = append(customs, cus)
  9410. }
  9411. }
  9412. for _, item := range item.HisAdditionalCharge {
  9413. cus := &Custom{
  9414. ItemId: item.ID,
  9415. AdviceId: 0,
  9416. ProjectId: 0,
  9417. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9418. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9419. FeedetlSn: item.FeedetlSn,
  9420. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9421. MedListCodg: item.XtHisAddtionConfig.Code,
  9422. Type: 3,
  9423. }
  9424. customs = append(customs, cus)
  9425. }
  9426. }
  9427. fmt.Println(customs)
  9428. for _, item := range customs {
  9429. var advice_id int64 = 0
  9430. var project_id int64 = 0
  9431. var item_id int64 = 0
  9432. var types int64 = 0
  9433. if item.Type == 1 {
  9434. advice_id = item.AdviceId
  9435. project_id = 0
  9436. item_id = 0
  9437. } else if item.Type == 2 {
  9438. advice_id = 0
  9439. item_id = 0
  9440. project_id = item.ProjectId
  9441. } else if item.Type == 3 {
  9442. advice_id = 0
  9443. item_id = item.ItemId
  9444. project_id = 0
  9445. }
  9446. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9447. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9448. pric, _ := strconv.ParseFloat(item.Price, 32)
  9449. info := &models.HisOrderInfo{
  9450. OrderNumber: order.Number,
  9451. UploadDate: time.Now().Unix(),
  9452. AdviceId: advice_id,
  9453. DetItemFeeSumamt: detItemFeeSumamt,
  9454. Cnt: cut,
  9455. Pric: pric,
  9456. PatientId: id,
  9457. Status: 1,
  9458. Mtime: time.Now().Unix(),
  9459. Ctime: time.Now().Unix(),
  9460. UserOrgId: adminUser.CurrentOrgId,
  9461. HisPatientId: his.ID,
  9462. OrderId: order.ID,
  9463. ProjectId: project_id,
  9464. Type: types,
  9465. ItemId: item_id,
  9466. }
  9467. service.CreateOrderInfo(info)
  9468. }
  9469. his.SickType = sick_type
  9470. service.UpdataHisPateint(&his)
  9471. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9472. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9473. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9474. if err == nil {
  9475. c.ServeSuccessJSON(map[string]interface{}{
  9476. "msg": "结算成功",
  9477. })
  9478. }
  9479. }
  9480. type CustomOrderInfo struct {
  9481. Name string
  9482. Spec string
  9483. Unit string
  9484. Count float64
  9485. Price float64
  9486. Total float64
  9487. }
  9488. func (c *HisApiController) GetPrivateExpensesInfo() {
  9489. order_id, _ := c.GetInt64("id", 0)
  9490. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9491. order, _ := service.GetHisOrderByID(order_id)
  9492. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9493. if order.ID == 0 {
  9494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9495. return
  9496. }
  9497. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9498. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9499. org_id := c.GetAdminUserInfo().CurrentOrgId
  9500. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9501. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9502. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9503. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9504. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9505. //var orderInfos_four []*models.HisOrderInfoTwo
  9506. //for _, item := range orderInfos_three {
  9507. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9508. // item.HisPrescriptionProject.IsCheckTeam = 1
  9509. // orderInfos_four = append(orderInfos_four, item)
  9510. //
  9511. // }
  9512. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9513. // item.HisPrescriptionProject.IsCheckTeam = 2
  9514. // orderInfos_two = append(orderInfos_two, item)
  9515. // }
  9516. //}
  9517. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9518. //var cus_slice []CustomOrderInfo
  9519. //for _, item := range new_order_info {
  9520. // var cus CustomOrderInfo
  9521. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9522. // cus.Unit = ""
  9523. // cus.Spec = ""
  9524. // var total float64
  9525. // for _, subItem := range orderInfos_four {
  9526. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9527. // total = total + subItem.DetItemFeeSumamt
  9528. // fmt.Println(subItem.DetItemFeeSumamt)
  9529. // }
  9530. // }
  9531. // cus.Count = 1
  9532. // cus.Total = total
  9533. // cus_slice = append(cus_slice, cus)
  9534. //}
  9535. orderInfos = append(orderInfos, orderInfos_two...)
  9536. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9537. //orderInfos = append(orderInfos, orderInfos_three...)
  9538. //}/**/
  9539. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9540. c.ServeSuccessJSON(map[string]interface{}{
  9541. "order": order,
  9542. "order_info": orderInfos,
  9543. "patient": patient,
  9544. "admin_info": adminInfo,
  9545. "his": his,
  9546. "current_admin": role,
  9547. "org_config": miConfig,
  9548. //"new_order_info": cus_slice,
  9549. })
  9550. }
  9551. func (this *HisApiController) ChangeMedType() {
  9552. med_type := this.GetString("med_type")
  9553. old_med_type := this.GetString("old_med_type")
  9554. ids := this.GetString("ids")
  9555. settle_type, _ := this.GetInt64("settle_type")
  9556. start_time := this.GetString("start_time")
  9557. end_time := this.GetString("end_time")
  9558. ids_arr := strings.Split(ids, ",")
  9559. if settle_type == 1 { //日结
  9560. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9561. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9562. prescription.MedType = med_type
  9563. err := service.SaveHisPrescription(&prescription)
  9564. if err == nil {
  9565. this.ServeSuccessJSON(map[string]interface{}{
  9566. "msg": "修改成功",
  9567. })
  9568. } else {
  9569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9570. return
  9571. }
  9572. } else if settle_type == 2 {
  9573. timeLayout := "2006-01-02"
  9574. loc, _ := time.LoadLocation("Local")
  9575. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9576. if err != nil {
  9577. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9578. return
  9579. }
  9580. recordStartTime := theStartTime.Unix()
  9581. start_time_timestamp := recordStartTime
  9582. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9583. if err != nil {
  9584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9585. return
  9586. }
  9587. recordEndTime := theEndTime.Unix()
  9588. end_time_timestamp := recordEndTime
  9589. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9590. if updateErr == nil {
  9591. this.ServeSuccessJSON(map[string]interface{}{
  9592. "msg": "修改成功",
  9593. })
  9594. } else {
  9595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9596. return
  9597. }
  9598. }
  9599. }
  9600. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9601. patient_id, _ := c.GetInt64("patient_id")
  9602. his_patient_id, _ := c.GetInt64("his_patient_id")
  9603. record_date := c.GetString("record_date")
  9604. start_time := c.GetString("start_time")
  9605. end_time := c.GetString("end_time")
  9606. order_status, _ := c.GetInt64("type", 0)
  9607. p_type, _ := c.GetInt64("p_type", 0)
  9608. order_id, _ := c.GetInt64("order_id", 0)
  9609. timeLayout := "2006-01-02"
  9610. loc, _ := time.LoadLocation("Local")
  9611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9612. if err != nil {
  9613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9614. return
  9615. }
  9616. recordDateTime := theTime.Unix()
  9617. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9618. if err != nil {
  9619. }
  9620. startRecordDateTime := startTime.Unix()
  9621. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9622. if err != nil {
  9623. }
  9624. endRecordDateTime := endTime.Unix()
  9625. admin := c.GetAdminUserInfo()
  9626. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9627. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9628. order, _ := service.GetHisOrderByID(order_id)
  9629. var monthPrescriptions []*models.HisPrescription
  9630. if order_status == 1 || order_status == 0 {
  9631. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9632. } else if order_status == 2 {
  9633. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9634. }
  9635. var settle_total float64
  9636. for _, item := range monthPrescriptions {
  9637. if len(item.HisPrescriptionProject) > 0 {
  9638. for _, subItem := range item.HisPrescriptionProject {
  9639. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9640. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9641. settle_total = settle_total + total
  9642. }
  9643. }
  9644. if len(item.HisDoctorAdviceInfo) > 0 {
  9645. for _, subItem := range item.HisDoctorAdviceInfo {
  9646. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9647. settle_total = settle_total + total
  9648. }
  9649. }
  9650. }
  9651. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9652. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9653. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9654. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9655. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9656. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9657. //获取所有科室信息
  9658. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9659. var dia string
  9660. for _, item := range month_p_info {
  9661. if len(dia) == 0 {
  9662. dia = item.Diagnosis
  9663. } else {
  9664. dia = dia + "," + item.Diagnosis
  9665. }
  9666. }
  9667. dia_arr := removeDuplicates(strings.Split(dia, ","))
  9668. dia_arr = removeEmptyStrings(dia_arr)
  9669. c.ServeSuccessJSON(map[string]interface{}{
  9670. "his_info": his_patient_info,
  9671. "xt_info": xt_patient_info,
  9672. "case_history": case_history,
  9673. "info": patientPrescriptionInfo,
  9674. "last_info": lastPatientPrescriptionInfo,
  9675. "month_prescriptions": monthPrescriptions,
  9676. "order": order,
  9677. "doctors": doctors,
  9678. "department": department,
  9679. "settle_total": settle_total,
  9680. "dia_arr": dia_arr,
  9681. })
  9682. return
  9683. }
  9684. func removeEmptyStrings(input []string) []string {
  9685. var output []string
  9686. for _, s := range input {
  9687. if s != "" {
  9688. output = append(output, s)
  9689. }
  9690. }
  9691. return output
  9692. }
  9693. func removeDuplicates(input []string) []string {
  9694. seen := make(map[string]bool)
  9695. output := []string{}
  9696. for _, s := range input {
  9697. if _, exists := seen[s]; !exists {
  9698. seen[s] = true
  9699. output = append(output, s)
  9700. }
  9701. }
  9702. return output
  9703. }
  9704. func (c *HisApiController) GetHisMonthPatientInfo() {
  9705. patient_id, _ := c.GetInt64("patient_id")
  9706. his_patient_id, _ := c.GetInt64("his_patient_id")
  9707. record_date := c.GetString("record_date")
  9708. number := c.GetString("number")
  9709. start_time := c.GetString("start_time")
  9710. end_time := c.GetString("end_time")
  9711. p_type, _ := c.GetInt64("p_type")
  9712. timeLayout := "2006-01-02"
  9713. loc, _ := time.LoadLocation("Local")
  9714. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9715. if err != nil {
  9716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9717. return
  9718. }
  9719. recordDateTime := theTime.Unix()
  9720. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9721. if err != nil {
  9722. }
  9723. startRecordDateTime := startTime.Unix()
  9724. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9725. if err != nil {
  9726. }
  9727. endRecordDateTime := endTime.Unix()
  9728. admin := c.GetAdminUserInfo()
  9729. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9730. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9731. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9732. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9733. var settle_total float64
  9734. for _, item := range monthPrescriptions {
  9735. if len(item.HisPrescriptionProject) > 0 {
  9736. for _, subItem := range item.HisPrescriptionProject {
  9737. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9738. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9739. settle_total = settle_total + total
  9740. }
  9741. }
  9742. if len(item.HisDoctorAdviceInfo) > 0 {
  9743. for _, subItem := range item.HisDoctorAdviceInfo {
  9744. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9745. settle_total = settle_total + total
  9746. }
  9747. }
  9748. }
  9749. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9750. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9751. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9752. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9753. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9754. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9755. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9756. //获取所有科室信息
  9757. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9758. c.ServeSuccessJSON(map[string]interface{}{
  9759. "his_info": his_patient_info,
  9760. "xt_info": xt_patient_info,
  9761. "case_history": case_history,
  9762. "info": patientPrescriptionInfo,
  9763. "month_prescriptions": monthPrescriptions,
  9764. "order": order,
  9765. "doctors": doctors,
  9766. "department": department,
  9767. "count": count,
  9768. "drugStockConfig": drugStockConfig,
  9769. "last_info": lastPatientPrescriptionInfo,
  9770. "settle_total": settle_total,
  9771. })
  9772. return
  9773. }
  9774. func (c *HisApiController) GetAllOrder() {
  9775. org_id := c.GetAdminUserInfo().CurrentOrgId
  9776. orders, _ := service.GetNewHisOrderList(org_id)
  9777. c.ServeSuccessJSON(map[string]interface{}{
  9778. "order": orders,
  9779. })
  9780. return
  9781. }
  9782. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9783. newArr = make([]*models.HisOrderInfoTwo, 0)
  9784. for i := 0; i < len(arr); i++ {
  9785. repeat := false
  9786. for j := i + 1; j < len(arr); j++ {
  9787. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9788. repeat = true
  9789. break
  9790. }
  9791. }
  9792. if !repeat {
  9793. newArr = append(newArr, arr[i])
  9794. }
  9795. }
  9796. return
  9797. }
  9798. // 修改处方退库操作 参数传修改之前的处方数据
  9799. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9800. if advice.ExecutionState == 1 {
  9801. //查询该病人该药品是否有库存记录
  9802. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9803. if errcode == gorm.ErrRecordNotFound {
  9804. } else {
  9805. //退库
  9806. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9807. if advice.PrescribingNumberUnit == drug.MinUnit {
  9808. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9809. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9810. //退库
  9811. warehouseInfo := models.DrugWarehouseInfo{
  9812. StockMinNumber: prescribingNumber,
  9813. }
  9814. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9815. operation_time := time.Now().Unix()
  9816. creater := advice.AdviceDoctor
  9817. ctime := time.Now().Unix()
  9818. timeStr := time.Now().Format("2006-01-02")
  9819. timeArr := strings.Split(timeStr, "-")
  9820. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9821. total = total + 1
  9822. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9823. cancelStock := models.DrugCancelStock{
  9824. OrderNumber: orderNumber,
  9825. OperaTime: operation_time,
  9826. OrgId: advice.UserOrgId,
  9827. Creater: creater,
  9828. Ctime: ctime,
  9829. Status: 1,
  9830. ReturnTime: advice.AdviceDate,
  9831. Dealer: info.Dealer,
  9832. Manufacturer: info.Manufacturer,
  9833. Type: 1,
  9834. }
  9835. service.AddSigleDrugCancelStock(&cancelStock)
  9836. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9837. dealer, _ := service.GetDealerById(info.Dealer)
  9838. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9839. cancelStockInfo := models.DrugCancelStockInfo{
  9840. OrderNumber: cancelInfo.OrderNumber,
  9841. CancelStockId: cancelInfo.ID,
  9842. DrugId: info.DrugId,
  9843. Count: info.Count,
  9844. Status: 1,
  9845. Ctime: ctime,
  9846. OrgId: advice.UserOrgId,
  9847. Type: 1,
  9848. Manufacturer: manufactureName.ManufacturerName,
  9849. Dealer: dealer.DealerName,
  9850. Total: 0,
  9851. RetailPrice: info.RetailPrice,
  9852. RetailTotalPrice: info.RetailTotalPrice,
  9853. Price: info.Price,
  9854. RegisterAccount: "",
  9855. Remark: info.Remark,
  9856. BatchNumber: info.BatchNumber,
  9857. MaxUnit: info.CountUnit,
  9858. ProductDate: info.ProductDate,
  9859. ExpiryDate: info.ExpiryDate,
  9860. BatchNumberId: info.WarehouseInfoId,
  9861. }
  9862. flow := models.DrugFlow{
  9863. WarehousingId: 0,
  9864. DrugId: info.DrugId,
  9865. Number: "",
  9866. BatchNumber: info.BatchNumber,
  9867. Count: info.Count,
  9868. UserOrgId: advice.UserOrgId,
  9869. PatientId: 0,
  9870. SystemTime: ctime,
  9871. ConsumableType: 4,
  9872. IsSys: 0,
  9873. WarehousingOrder: "",
  9874. WarehouseOutId: 0,
  9875. WarehouseOutOrderNumber: "",
  9876. IsEdit: 0,
  9877. CancelStockId: cancelStock.ID,
  9878. CancelOrderNumber: cancelStock.OrderNumber,
  9879. Manufacturer: info.Manufacturer,
  9880. Dealer: info.Dealer,
  9881. Creator: advice.UserOrgId,
  9882. UpdateCreator: 0,
  9883. Status: 1,
  9884. Ctime: time.Now().Unix(),
  9885. Mtime: 0,
  9886. Price: info.Price,
  9887. WarehousingDetailId: 0,
  9888. WarehouseOutDetailId: 0,
  9889. CancelOutDetailId: 0,
  9890. ExpireDate: info.ExpiryDate,
  9891. ProductDate: info.ProductDate,
  9892. MaxUnit: info.CountUnit,
  9893. MinUnit: "",
  9894. }
  9895. service.CreatedCancelStock(cancelStockInfo)
  9896. service.CreateDrugFlowOne(flow)
  9897. } else {
  9898. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9899. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9900. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9901. warehouseInfo := models.DrugWarehouseInfo{
  9902. StockMinNumber: prescribingNumber,
  9903. }
  9904. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9905. }
  9906. operation_time := time.Now().Unix()
  9907. creater := advice.AdviceDoctor
  9908. ctime := time.Now().Unix()
  9909. timeStr := time.Now().Format("2006-01-02")
  9910. timeArr := strings.Split(timeStr, "-")
  9911. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9912. total = total + 1
  9913. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9914. cancelStock := models.DrugCancelStock{
  9915. OrderNumber: orderNumber,
  9916. OperaTime: operation_time,
  9917. OrgId: advice.UserOrgId,
  9918. Creater: creater,
  9919. Ctime: ctime,
  9920. Status: 1,
  9921. ReturnTime: advice.AdviceDate,
  9922. Dealer: info.Dealer,
  9923. Manufacturer: info.Manufacturer,
  9924. Type: 1,
  9925. }
  9926. service.AddSigleDrugCancelStock(&cancelStock)
  9927. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9928. dealer, _ := service.GetDealerById(info.Dealer)
  9929. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9930. cancelStockInfo := models.DrugCancelStockInfo{
  9931. OrderNumber: cancelInfo.OrderNumber,
  9932. CancelStockId: cancelInfo.ID,
  9933. DrugId: info.DrugId,
  9934. Count: info.Count,
  9935. Status: 1,
  9936. Ctime: ctime,
  9937. OrgId: advice.UserOrgId,
  9938. Type: 1,
  9939. Manufacturer: manufactureName.ManufacturerName,
  9940. Dealer: dealer.DealerName,
  9941. Total: 0,
  9942. RetailPrice: info.RetailPrice,
  9943. RetailTotalPrice: info.RetailTotalPrice,
  9944. Price: info.Price,
  9945. RegisterAccount: "",
  9946. Remark: info.Remark,
  9947. BatchNumber: info.BatchNumber,
  9948. MaxUnit: info.CountUnit,
  9949. ProductDate: info.ProductDate,
  9950. ExpiryDate: info.ExpiryDate,
  9951. BatchNumberId: info.WarehouseInfoId,
  9952. }
  9953. flow := models.DrugFlow{
  9954. WarehousingId: 0,
  9955. DrugId: info.DrugId,
  9956. Number: "",
  9957. BatchNumber: info.BatchNumber,
  9958. Count: info.Count,
  9959. UserOrgId: advice.UserOrgId,
  9960. PatientId: 0,
  9961. SystemTime: ctime,
  9962. ConsumableType: 4,
  9963. IsSys: 0,
  9964. WarehousingOrder: "",
  9965. WarehouseOutId: 0,
  9966. WarehouseOutOrderNumber: "",
  9967. IsEdit: 0,
  9968. CancelStockId: cancelStock.ID,
  9969. CancelOrderNumber: cancelStock.OrderNumber,
  9970. Manufacturer: info.Manufacturer,
  9971. Dealer: info.Dealer,
  9972. Creator: advice.AdviceDoctor,
  9973. UpdateCreator: 0,
  9974. Status: 1,
  9975. Ctime: time.Now().Unix(),
  9976. Mtime: 0,
  9977. Price: info.Price,
  9978. WarehousingDetailId: 0,
  9979. WarehouseOutDetailId: 0,
  9980. CancelOutDetailId: 0,
  9981. ExpireDate: info.ExpiryDate,
  9982. ProductDate: info.ProductDate,
  9983. MaxUnit: info.CountUnit,
  9984. MinUnit: "",
  9985. }
  9986. service.CreatedCancelStock(cancelStockInfo)
  9987. service.CreateDrugFlowOne(flow)
  9988. }
  9989. }
  9990. }
  9991. return err
  9992. }
  9993. func (this *HisApiController) DeleteNCDS() {
  9994. id, _ := this.GetInt64("id", 0)
  9995. if id > 0 {
  9996. service.DeletePsnNCDSRecordById(id)
  9997. this.ServeSuccessJSON(map[string]interface{}{
  9998. "msg": "删除成功",
  9999. })
  10000. } else {
  10001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10002. return
  10003. }
  10004. }
  10005. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10006. id, _ := c.GetInt64("id")
  10007. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10008. c.ServeSuccessJSON(map[string]interface{}{
  10009. "advice": advice,
  10010. })
  10011. return
  10012. }
  10013. func (c *HisApiController) GetHisMonthChargePatientList() {
  10014. record_date := c.GetString("record_date")
  10015. start_time := c.GetString("start_time")
  10016. end_time := c.GetString("end_time")
  10017. timeLayout := "2006-01-02"
  10018. loc, _ := time.LoadLocation("Local")
  10019. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10020. if err != nil {
  10021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10022. return
  10023. }
  10024. if err != nil {
  10025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10026. return
  10027. }
  10028. recordDateTime := theTime.Unix()
  10029. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10030. if err != nil {
  10031. }
  10032. startRecordDateTime := startTime.Unix()
  10033. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10034. if err != nil {
  10035. }
  10036. endRecordDateTime := endTime.Unix()
  10037. adminInfo := c.GetAdminUserInfo()
  10038. var tempMonthChargePatients []*service.MonthChargePatients
  10039. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10040. for _, item := range tempPatients {
  10041. //过滤没有处方的
  10042. if len(item.HisPrescription) == 0 {
  10043. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10044. }
  10045. }
  10046. c.ServeSuccessJSON(map[string]interface{}{
  10047. "list": tempMonthChargePatients,
  10048. })
  10049. }