his_api_controller.go 542KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1214. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1215. //获取当前用户的信息
  1216. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1217. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1218. //获取所有科室信息
  1219. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1220. //var aa []service.PatientThree
  1221. noElementsSlice := make([]service.PatientThree, 0)
  1222. c.ServeSuccessJSON(map[string]interface{}{
  1223. "list": patients,
  1224. "list_two": patients_two,
  1225. "list_three": noElementsSlice,
  1226. "info": adminUserInfo,
  1227. "doctors": doctors,
  1228. "department": department,
  1229. })
  1230. }
  1231. type CustomTemplate struct {
  1232. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1233. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1234. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1235. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1236. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1237. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1238. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1239. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1240. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1241. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1242. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1243. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1244. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1245. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1246. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1247. }
  1248. func (c *HisApiController) GetHisPatientInfo() {
  1249. patient_id, _ := c.GetInt64("patient_id")
  1250. his_patient_id, _ := c.GetInt64("his_patient_id")
  1251. record_date := c.GetString("record_date")
  1252. number := c.GetString("number")
  1253. //start_time := c.GetString("start_time")
  1254. //end_time := c.GetString("end_time")
  1255. p_type, _ := c.GetInt64("p_type")
  1256. timeLayout := "2006-01-02"
  1257. loc, _ := time.LoadLocation("Local")
  1258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1259. if err != nil {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. recordDateTime := theTime.Unix()
  1264. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //startRecordDateTime := startTime.Unix()
  1269. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1270. //if err != nil {
  1271. //
  1272. //}
  1273. //endRecordDateTime := endTime.Unix()
  1274. admin := c.GetAdminUserInfo()
  1275. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1277. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1278. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1279. var prescriptions []*models.HisPrescription
  1280. var last_prescriptions []*models.HisPrescription
  1281. var sch_prescriptions []CustomTemplate
  1282. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1283. if p_type == 1 { //住院
  1284. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1285. for _, item := range prescriptions {
  1286. for _, subItem := range item.HisDoctorAdviceInfo {
  1287. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1288. if info.RetailPrice > 0 {
  1289. subItem.Drug.MinPrice = info.RetailPrice
  1290. }
  1291. }
  1292. }
  1293. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1294. } else { //门诊
  1295. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1296. for _, item := range prescriptions {
  1297. for _, subItem := range item.HisDoctorAdviceInfo {
  1298. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1299. if info.RetailPrice > 0 {
  1300. subItem.Drug.MinPrice = info.RetailPrice
  1301. }
  1302. }
  1303. }
  1304. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1305. }
  1306. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1307. if sch.ID > 0 {
  1308. var week string
  1309. t := time.Now()
  1310. switch t.Weekday().String() {
  1311. case "Monday":
  1312. week = "周一"
  1313. break
  1314. case "Tuesday":
  1315. week = "周二"
  1316. break
  1317. case "Wednesday":
  1318. week = "周三"
  1319. break
  1320. case "Thursday":
  1321. week = "周四"
  1322. break
  1323. case "Friday":
  1324. week = "周五"
  1325. break
  1326. case "Saturday":
  1327. week = "周六"
  1328. break
  1329. case "Sunday":
  1330. week = "周日"
  1331. break
  1332. }
  1333. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1334. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1335. //根据推送频率组装新的数组
  1336. for _, item := range temp_sch_prescriptions {
  1337. var cus CustomTemplate
  1338. cus.ID = item.ID
  1339. cus.UserOrgId = item.UserOrgId
  1340. cus.PatientId = item.PatientId
  1341. cus.MedType = item.MedType
  1342. cus.RecordDate = item.RecordDate
  1343. cus.Type = item.Type
  1344. cus.PType = item.PType
  1345. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1346. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1347. if subItem.FrequencyType == 1 { //每次必推
  1348. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1349. }
  1350. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1351. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1352. }
  1353. if subItem.FrequencyType == 2 { //按照天数频率
  1354. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1355. now := p.Unix()
  1356. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1357. dayStr2 := "-" + dayStr
  1358. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1359. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1360. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1361. if len(advices) == 0 {
  1362. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1363. }
  1364. }
  1365. }
  1366. }
  1367. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1368. if subItem.Type == 2 {
  1369. if subItem.XtHisProject.MedicalStatus != 1 {
  1370. if subItem.FrequencyType == 1 {
  1371. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1372. }
  1373. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1374. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1375. }
  1376. if subItem.FrequencyType == 2 {
  1377. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1378. now := p.Unix()
  1379. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1380. dayStr2 := "-" + dayStr
  1381. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1382. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1383. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1384. if len(projects) == 0 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. }
  1388. }
  1389. } else if subItem.Type == 3 {
  1390. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1391. if subItem.FrequencyType == 1 {
  1392. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1393. }
  1394. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1395. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1396. }
  1397. if subItem.FrequencyType == 2 {
  1398. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1399. now := p.Unix()
  1400. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1401. dayStr2 := "-" + dayStr
  1402. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1403. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1404. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1405. if len(projects) == 0 {
  1406. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. sch_prescriptions = append(sch_prescriptions, cus)
  1413. }
  1414. for _, item := range sch_prescriptions {
  1415. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1416. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1417. }
  1418. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1419. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1420. }
  1421. }
  1422. }
  1423. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1424. if config.ID > 0 && config.IsOpen == 1 {
  1425. for _, item := range sch_prescriptions {
  1426. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1427. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1428. if info.RetailPrice > 0 {
  1429. subItem.Drug.MinPrice = info.RetailPrice
  1430. if admin.CurrentOrgId != 10598 {
  1431. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1432. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if config.ID > 0 && config.IsOpen == 1 {
  1439. for _, item := range sch_prescriptions {
  1440. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1441. if subItem.Type == 3 {
  1442. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1443. if info.Price > 0 {
  1444. subItem.GoodInfo.PackingPrice = info.Price
  1445. if admin.CurrentOrgId != 10598 {
  1446. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1447. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1455. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1456. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1457. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1458. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1459. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1460. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1461. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1462. //获取所有科室信息
  1463. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1464. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1465. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1466. c.ServeSuccessJSON(map[string]interface{}{
  1467. "his_info": his_patient_info,
  1468. "xt_info": xt_patient_info,
  1469. "prescription": prescriptions,
  1470. "case_history": case_history,
  1471. "info": patientPrescriptionInfo,
  1472. //"month_prescriptions": monthPrescriptions,
  1473. "order": order,
  1474. "doctors": doctors,
  1475. "department": department,
  1476. "sch_prescriptions": sch_prescriptions,
  1477. "last_prescriptions": last_prescriptions,
  1478. "schedule": sch,
  1479. "count": count,
  1480. "drugStockConfig": drugStockConfig,
  1481. "last_info": lastPatientPrescriptionInfo,
  1482. "befor": beforThrity,
  1483. "LastCaseHistory": LastCaseHistory,
  1484. })
  1485. return
  1486. }
  1487. func (c *HisApiController) GetHisPrescriptionConfig() {
  1488. adminInfo := c.GetAdminUserInfo()
  1489. //获取医嘱模版
  1490. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1491. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1492. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1493. //获取所有基础药
  1494. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1495. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1496. if config.ID > 0 && config.IsOpen == 1 {
  1497. for _, item := range drugs {
  1498. var index = 0
  1499. for _, subItem := range item.OtherDrugWarehouseInfo {
  1500. if index == 0 {
  1501. index = index + 1
  1502. if subItem.RetailPrice > 0 {
  1503. item.MinPrice = subItem.RetailPrice
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1510. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1511. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1512. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1513. //获取所有科室信息
  1514. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1515. //获取诊断信息
  1516. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1517. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1518. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1519. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1520. //获取是否开启保存耗材出库的开关
  1521. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1522. c.ServeSuccessJSON(map[string]interface{}{
  1523. "drugs": drugs,
  1524. "advices_template": advices,
  1525. "drugways": drugways,
  1526. "efs": efs,
  1527. "doctors": doctors,
  1528. "department": department,
  1529. "sick": sick,
  1530. "additions": additions,
  1531. "diagnose": diagnose,
  1532. "manufacturers": manufacturers,
  1533. "goodOutOpen": goodOutOpen,
  1534. "patientDiagnose": patientDiagnose,
  1535. })
  1536. }
  1537. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1538. //获取所有基础药
  1539. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1540. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1541. if config.ID > 0 && config.IsOpen == 1 {
  1542. for _, item := range drugs {
  1543. var index = 0
  1544. for _, subItem := range item.OtherDrugWarehouseInfo {
  1545. if index == 0 {
  1546. index = index + 1
  1547. if subItem.RetailPrice > 0 {
  1548. item.MinPrice = subItem.RetailPrice
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1555. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1556. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1557. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1558. //获取所有科室信息
  1559. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1560. //获取诊断信息
  1561. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1562. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1563. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1564. //获取是否开启保存耗材出库的开关
  1565. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1566. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1567. c.ServeSuccessJSON(map[string]interface{}{
  1568. "drugs": drugs,
  1569. "advices_template": advices,
  1570. "drugways": drugways,
  1571. "efs": efs,
  1572. "doctors": doctors,
  1573. "department": department,
  1574. "sick": sick,
  1575. "additions": additions,
  1576. "diagnose": diagnose,
  1577. "manufacturers": manufacturers,
  1578. "goodOutOpen": goodOutOpen,
  1579. "patientDiagnose": patientDiagnose,
  1580. })
  1581. }
  1582. }
  1583. func (c *HisApiController) CreateHisPrescription() {
  1584. record_date := c.GetString("record_date")
  1585. patient_id, _ := c.GetInt64("patient_id")
  1586. reg_type, _ := c.GetInt64("reg_type")
  1587. diagnose := c.GetString("diagnose")
  1588. sick_type, _ := c.GetInt64("sick_type")
  1589. sick_history := c.GetString("sick_history")
  1590. doctor_id, _ := c.GetInt64("doctor", 0)
  1591. department, _ := c.GetInt64("department", 0)
  1592. his_patient_id, _ := c.GetInt64("his_patient_id")
  1593. p_type, _ := c.GetInt64("p_type")
  1594. patient_diagnose := c.GetString("patient_diagnose")
  1595. dataBody := make(map[string]interface{}, 0)
  1596. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1597. if err != nil {
  1598. utils.ErrorLog(err.Error())
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. //edit, src := GetCompareData(dataBody)
  1603. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1604. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1605. //fmt.Println(drugResult)
  1606. //fmt.Println(goodResult)
  1607. timeLayout := "2006-01-02"
  1608. loc, _ := time.LoadLocation("Local")
  1609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1610. if err != nil {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1612. return
  1613. }
  1614. adminInfo := c.GetAdminUserInfo()
  1615. recordDateTime := theTime.Unix()
  1616. //查询默认出库仓库库存
  1617. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1618. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1619. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1620. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1621. if len(lists) == 1 {
  1622. his_patient_id = lists[0].ID
  1623. }
  1624. }
  1625. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1626. //自动出库的开关开启
  1627. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1628. //自动出库
  1629. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1630. //耗材保存处方出库
  1631. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1633. //已发药和已收费限制逻辑
  1634. isMidicine := false
  1635. isCharge := false
  1636. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1637. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1638. if len(prescriptions) > 0 {
  1639. for _, item := range prescriptions {
  1640. items := item.(map[string]interface{})
  1641. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1642. utils.ErrorLog("id")
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. id := int64(items["id"].(float64))
  1647. if id > 0 {
  1648. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1649. if err != nil {
  1650. if new_prescription.OrderStatus == 4 {
  1651. isCharge = true
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. if isMidicine == true {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1660. return
  1661. }
  1662. if isCharge == true {
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1664. return
  1665. }
  1666. // 开始主事务
  1667. db := service.XTWriteDB()
  1668. tx := db.Begin()
  1669. // 在函数结束时处理事务回滚
  1670. defer func() {
  1671. if r := recover(); r != nil {
  1672. tx.Rollback()
  1673. }
  1674. }()
  1675. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1676. //药品发药出库
  1677. if pharmacyConfig.IsOpen == 1 {
  1678. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1679. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1680. if len(prescriptions) > 0 {
  1681. for _, item := range prescriptions {
  1682. items := item.(map[string]interface{})
  1683. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1684. advices := items["advices"].([]interface{})
  1685. if len(advices) > 0 {
  1686. for _, advice := range advices {
  1687. var drug_id int64
  1688. var prescribing_number float64
  1689. var prescribingNumberUnit string
  1690. var adviceId int64
  1691. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1692. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1693. }
  1694. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1695. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1696. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1697. }
  1698. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1699. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1700. }
  1701. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1702. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1703. }
  1704. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1705. if drug.ID == 0 {
  1706. tx.Rollback()
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. return
  1709. }
  1710. //查询药品的所有库存
  1711. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1712. var total_count int64
  1713. for _, it := range list {
  1714. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1715. }
  1716. totals := strconv.FormatInt(total_count, 10)
  1717. //查询该药品是否存在开药记录
  1718. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1719. //新增处方盘点库存是否充足
  1720. if advicelist.ID == 0 {
  1721. all_count, _ := strconv.ParseFloat(totals, 64)
  1722. if prescribingNumberUnit == drug.MinUnit {
  1723. if drug.IsUse != 1 {
  1724. if drug.IsProject == 0 || drug.IsProject == 2 {
  1725. if all_count == 0 {
  1726. tx.Rollback()
  1727. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1728. return
  1729. }
  1730. if prescribing_number > all_count {
  1731. tx.Rollback()
  1732. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1733. return
  1734. }
  1735. }
  1736. }
  1737. }
  1738. if prescribingNumberUnit == drug.MaxUnit {
  1739. num := prescribing_number * float64(drug.MinNumber)
  1740. if drug.IsUse != 1 {
  1741. if drug.IsProject == 0 || drug.IsProject == 2 {
  1742. if all_count == 0 {
  1743. tx.Rollback()
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. if num > all_count {
  1748. tx.Rollback()
  1749. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1750. return
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }
  1756. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1757. //不使用保存处方出库
  1758. if drugOutConfig.IsOpen != 1 {
  1759. //修改处方
  1760. for _, advice := range advices {
  1761. var drug_id int64
  1762. var prescribing_number float64
  1763. var prescribingNumberUnit string
  1764. var prescribingNumber string
  1765. var adviceId int64
  1766. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1767. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1768. }
  1769. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1770. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1771. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1772. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1773. }
  1774. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1775. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1776. }
  1777. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1778. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1779. }
  1780. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1781. if drug.ID == 0 {
  1782. tx.Rollback()
  1783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1784. return
  1785. }
  1786. //查询药品的所有库存
  1787. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1788. var total_count int64
  1789. for _, it := range list {
  1790. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1791. }
  1792. totals := strconv.FormatInt(total_count, 10)
  1793. //查询该药品是否存在开药记录
  1794. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1795. //新增处方
  1796. if advicelist.ID == 0 {
  1797. all_count, _ := strconv.ParseFloat(totals, 64)
  1798. if prescribingNumberUnit == drug.MinUnit {
  1799. if drug.IsUse != 1 {
  1800. if drug.IsProject == 0 || drug.IsProject == 2 {
  1801. if all_count == 0 {
  1802. tx.Rollback()
  1803. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1804. return
  1805. }
  1806. if prescribing_number > all_count {
  1807. tx.Rollback()
  1808. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1809. return
  1810. }
  1811. }
  1812. }
  1813. } else {
  1814. if prescribingNumberUnit == drug.MaxUnit {
  1815. num := prescribing_number * float64(drug.MinNumber)
  1816. if drug.IsUse != 1 {
  1817. if drug.IsProject == 0 || drug.IsProject == 2 {
  1818. if all_count == 0 {
  1819. tx.Rollback()
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. if num > all_count {
  1824. tx.Rollback()
  1825. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1826. return
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. //修改处方
  1834. if advicelist.ID > 0 {
  1835. var device_number int64
  1836. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1837. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1838. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1839. device_number = prescribingNumberInt * drug.MinNumber
  1840. }
  1841. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1842. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1843. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1844. device_number = prescribingNumberInt
  1845. }
  1846. var number_count int64
  1847. if prescribingNumberUnit == drug.MaxUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if prescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1853. number_count = prescribingNumberInt
  1854. }
  1855. //如果修改的数量大于之前修改的数量
  1856. if (number_count - device_number) > 0 {
  1857. //如果修改的差数量 大于库存数量
  1858. if drug.IsUse != 1 {
  1859. if (number_count - device_number) > total_count {
  1860. tx.Rollback()
  1861. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1862. return
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. //已发药和已收费限制逻辑
  1877. //执行出库的逻辑
  1878. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1879. //校验库存总量
  1880. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1881. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1882. if len(prescriptions) > 0 {
  1883. for _, item := range prescriptions {
  1884. items := item.(map[string]interface{})
  1885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1886. advices := items["advices"].([]interface{})
  1887. if len(advices) > 0 {
  1888. for _, advice := range advices {
  1889. var drug_id int64
  1890. var prescribing_number float64
  1891. var prescribingNumberUnit string
  1892. var adviceId int64
  1893. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1894. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1895. }
  1896. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1897. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1898. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1899. }
  1900. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1901. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1902. }
  1903. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1904. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1905. }
  1906. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1907. if drug.ID == 0 {
  1908. tx.Rollback()
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1910. return
  1911. }
  1912. //查询药品的所有库存
  1913. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1914. var total_count int64
  1915. for _, it := range list {
  1916. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1917. }
  1918. totals := strconv.FormatInt(total_count, 10)
  1919. //查询该药品是否存在开药记录
  1920. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1921. //查询最新批次库存
  1922. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1923. var batch_number_count int64
  1924. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1925. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1926. //新增处方
  1927. if advicelist.ID == 0 {
  1928. all_count, _ := strconv.ParseFloat(totals, 64)
  1929. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1930. if prescribingNumberUnit == drug.MinUnit {
  1931. if drug.IsUse != 1 {
  1932. if drug.IsProject == 0 || drug.IsProject == 2 {
  1933. if all_count == 0 {
  1934. tx.Rollback()
  1935. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1936. return
  1937. }
  1938. if prescribing_number > all_count {
  1939. tx.Rollback()
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1941. return
  1942. }
  1943. }
  1944. if adminInfo.CurrentOrgId == 10215 {
  1945. if prescribing_number > batch_number_all_count {
  1946. tx.Rollback()
  1947. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1948. return
  1949. }
  1950. }
  1951. }
  1952. }
  1953. if prescribingNumberUnit == drug.MaxUnit {
  1954. num := prescribing_number * float64(drug.MinNumber)
  1955. if drug.IsUse != 1 {
  1956. if drug.IsProject == 0 || drug.IsProject == 2 {
  1957. if all_count == 0 {
  1958. tx.Rollback()
  1959. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1960. return
  1961. }
  1962. if num > all_count {
  1963. tx.Rollback()
  1964. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1965. return
  1966. }
  1967. }
  1968. if adminInfo.CurrentOrgId == 10215 {
  1969. if num > batch_number_all_count {
  1970. tx.Rollback()
  1971. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1972. return
  1973. }
  1974. }
  1975. }
  1976. }
  1977. }
  1978. //不是保存处方出库
  1979. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1980. if drugOutConfig.IsOpen != 1 {
  1981. //修改处方
  1982. for _, advice := range advices {
  1983. var drug_id int64
  1984. var prescribing_number float64
  1985. var prescribingNumberUnit string
  1986. var prescribingNumber string
  1987. var adviceId int64
  1988. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1989. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1990. }
  1991. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1992. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1993. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1994. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1995. }
  1996. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1997. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1998. }
  1999. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2000. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2001. }
  2002. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2003. if drug.ID == 0 {
  2004. tx.Rollback()
  2005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2006. return
  2007. }
  2008. //查询药品的所有库存
  2009. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2010. var total_count int64
  2011. for _, it := range list {
  2012. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2013. }
  2014. totals := strconv.FormatInt(total_count, 10)
  2015. //查询该药品是否存在开药记录
  2016. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2017. //新增处方
  2018. if advicelist.ID == 0 {
  2019. //查询最新批次库存
  2020. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2021. var batch_number_count int64
  2022. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2023. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2024. all_count, _ := strconv.ParseFloat(totals, 64)
  2025. if all_count == 0 {
  2026. tx.Rollback()
  2027. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2028. return
  2029. }
  2030. if prescribingNumberUnit == drug.MinUnit {
  2031. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2032. if drug.IsUse != 1 {
  2033. if drug.IsProject == 0 || drug.IsProject == 2 {
  2034. if all_count == 0 {
  2035. tx.Rollback()
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2037. return
  2038. }
  2039. if prescribing_number > all_count {
  2040. tx.Rollback()
  2041. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2042. return
  2043. }
  2044. }
  2045. if adminInfo.CurrentOrgId == 10215 {
  2046. if prescribing_number > batch_number_all_count {
  2047. tx.Rollback()
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2049. return
  2050. }
  2051. }
  2052. }
  2053. } else {
  2054. if prescribingNumberUnit == drug.MaxUnit {
  2055. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2056. num := prescribing_number * float64(drug.MinNumber)
  2057. if drug.IsUse != 1 {
  2058. if drug.IsProject == 0 || drug.IsProject == 2 {
  2059. if all_count == 0 {
  2060. tx.Rollback()
  2061. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2062. return
  2063. }
  2064. if num > all_count {
  2065. tx.Rollback()
  2066. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2067. return
  2068. }
  2069. }
  2070. if adminInfo.CurrentOrgId == 10215 {
  2071. if prescribing_number > batch_number_all_count {
  2072. tx.Rollback()
  2073. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2074. return
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. //修改处方
  2082. if advicelist.ID > 0 {
  2083. //查询最新批次库存
  2084. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2085. var batch_number_count int64
  2086. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2087. var device_number int64
  2088. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2089. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2090. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2091. device_number = prescribingNumberInt * drug.MinNumber
  2092. }
  2093. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2094. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2095. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2096. device_number = prescribingNumberInt
  2097. //回退库存
  2098. }
  2099. var number_count int64
  2100. if prescribingNumberUnit == drug.MaxUnit {
  2101. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2102. number_count = prescribingNumberInt * drug.MinNumber
  2103. //回退库存
  2104. }
  2105. if prescribingNumberUnit == drug.MinUnit {
  2106. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2107. number_count = prescribingNumberInt
  2108. //回退库存
  2109. }
  2110. //如果修改的数量大于之前修改的数量
  2111. if (number_count - device_number) > 0 {
  2112. //如果修改的差数量 大于库存数量
  2113. if drug.IsUse != 1 {
  2114. if drug.IsProject == 0 || drug.IsProject == 2 {
  2115. if total_count == 0 {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if (number_count - device_number) > total_count {
  2121. tx.Rollback()
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2123. return
  2124. }
  2125. if (number_count - device_number) > batch_number_count {
  2126. tx.Rollback()
  2127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2128. return
  2129. }
  2130. }
  2131. if adminInfo.CurrentOrgId == 10215 {
  2132. // 查询该药品最后一次出库记录
  2133. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2134. var out_count int64
  2135. var in_count int64
  2136. var stock_max_number int64
  2137. var stock_min_number int64
  2138. for _, it := range outInfo {
  2139. if it.CountUnit == drug.MaxUnit {
  2140. it.Count = it.Count * drug.MinNumber
  2141. }
  2142. out_count += it.Count
  2143. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2144. stock_max_number = warehouseInfoList.StockMaxNumber
  2145. stock_min_number = warehouseInfoList.StockMinNumber
  2146. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2147. }
  2148. if out_count > 0 {
  2149. if (number_count - device_number) > in_count {
  2150. tx.Rollback()
  2151. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2152. return
  2153. }
  2154. }
  2155. // 未出库
  2156. if out_count == 0 {
  2157. var sum_in_count int64
  2158. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2159. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2160. //如果修改的数量大于有库存的第一个批次
  2161. if number_count > sum_in_count {
  2162. tx.Rollback()
  2163. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2164. return
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //药品发药
  2171. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. //不使用药品发药的功能
  2173. //if pharmacyConfig.IsOpen != 1 {
  2174. // if device_number != number_count {
  2175. //
  2176. // //查询该药品的出库记录
  2177. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2178. // if len(outListExport) > 0 {
  2179. // //
  2180. // for _, item := range outListExport {
  2181. // //回退库存
  2182. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2183. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2184. // }
  2185. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2186. // var stock_max_number int64
  2187. // var stock_min_number int64
  2188. //
  2189. // if number_count >= drug.MinNumber {
  2190. //
  2191. // stock_max_number = device_number / drug.MinNumber
  2192. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2193. //
  2194. // stock_min_number = device_number % drug.MinNumber
  2195. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2196. //
  2197. // } else {
  2198. //
  2199. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2200. //
  2201. // }
  2202. // }
  2203. //
  2204. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2205. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2206. // }
  2207. // }
  2208. // }
  2209. //
  2210. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2211. // var sum_count int64
  2212. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2213. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2214. // for _, its := range stockInfo {
  2215. // if its.MaxUnit == drug.MaxUnit {
  2216. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2217. // }
  2218. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2219. // }
  2220. // //更新字典里面的库存
  2221. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2222. //
  2223. // //剩余库存
  2224. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2225. //
  2226. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2227. // //减少出库数量
  2228. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2229. //
  2230. // }
  2231. //}
  2232. }
  2233. }
  2234. }
  2235. //保存处方开药
  2236. if drugOutConfig.IsOpen == 1 {
  2237. //修改处方
  2238. for _, advice := range advices {
  2239. var drug_id int64
  2240. var prescribing_number float64
  2241. var prescribingNumberUnit string
  2242. var prescribingNumber string
  2243. var adviceId int64
  2244. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2245. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2246. }
  2247. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2248. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2249. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2250. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2251. }
  2252. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2253. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2254. }
  2255. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2256. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2257. }
  2258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2259. if drug.ID == 0 {
  2260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2261. return
  2262. }
  2263. //查询药品的所有库存
  2264. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2265. var total_count int64
  2266. for _, it := range list {
  2267. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2268. }
  2269. totals := strconv.FormatInt(total_count, 10)
  2270. //查询该药品是否存在开药记录
  2271. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2272. //新增处方
  2273. if advicelist.ID == 0 {
  2274. //查询最新批次库存
  2275. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2276. var batch_number_count int64
  2277. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2278. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2279. all_count, _ := strconv.ParseFloat(totals, 64)
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. }
  2348. var number_count int64
  2349. if prescribingNumberUnit == drug.MaxUnit {
  2350. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2351. number_count = prescribingNumberInt * drug.MinNumber
  2352. }
  2353. if prescribingNumberUnit == drug.MinUnit {
  2354. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2355. number_count = prescribingNumberInt
  2356. }
  2357. //如果修改的数量大于之前修改的数量
  2358. if (number_count - device_number) > 0 {
  2359. //如果修改的差数量 大于库存数量
  2360. if drug.IsUse != 1 {
  2361. if drug.IsProject == 0 || drug.IsProject == 2 {
  2362. if total_count == 0 {
  2363. tx.Rollback()
  2364. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2365. return
  2366. }
  2367. if (number_count - device_number) > total_count {
  2368. tx.Rollback()
  2369. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2370. return
  2371. }
  2372. }
  2373. if adminInfo.CurrentOrgId == 10215 {
  2374. if (number_count - device_number) > batch_number_count {
  2375. tx.Rollback()
  2376. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2377. return
  2378. }
  2379. }
  2380. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2381. //查询历史出库数据总批次
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. if sum_in_count == 0 {
  2411. tx.Rollback()
  2412. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2413. return
  2414. }
  2415. //如果修改的数量大于有库存的第一个批次
  2416. if number_count > sum_in_count {
  2417. tx.Rollback()
  2418. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2419. return
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. //校验耗材库存
  2436. if goodOutConfig.IsOpen == 1 {
  2437. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2438. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2439. if len(prescriptions) > 0 {
  2440. for _, item := range prescriptions {
  2441. items := item.(map[string]interface{})
  2442. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2443. projects := items["project"].([]interface{})
  2444. if len(projects) > 0 {
  2445. for _, project := range projects {
  2446. var project_id int64
  2447. var project_type int64
  2448. var totals float64
  2449. var project_name string
  2450. var parsetotal int64
  2451. var id int64
  2452. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2453. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2454. }
  2455. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2456. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2457. }
  2458. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2459. total, _ := project.(map[string]interface{})["total"].(string)
  2460. totals, _ = strconv.ParseFloat(total, 64)
  2461. }
  2462. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2463. project_name = project.(map[string]interface{})["project_name"].(string)
  2464. }
  2465. if project_type == 3 {
  2466. //查找该耗材的出库记录
  2467. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2468. if len(goodWarehouseInfo) == 0 {
  2469. //查询耗材库存
  2470. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2471. var stock_count int64
  2472. for _, it := range list {
  2473. stock_count += it.StockCount
  2474. }
  2475. stock_counts := strconv.FormatInt(stock_count, 10)
  2476. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2477. if stock_total_count == 0 {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2480. return
  2481. }
  2482. if totals > stock_total_count {
  2483. tx.Rollback()
  2484. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2485. return
  2486. }
  2487. }
  2488. if len(goodWarehouseInfo) > 0 {
  2489. //查询该患者耗材的历史数据
  2490. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2491. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2492. //数量发生改变
  2493. if parsetotal != count {
  2494. //如果现在的数量大于历史数量,就要看库存是否足够
  2495. if parsetotal > count {
  2496. //查询耗材所有库存
  2497. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2498. var stock_count int64
  2499. for _, it := range list {
  2500. stock_count += it.StockCount
  2501. }
  2502. //库存不足
  2503. if stock_count == 0 {
  2504. tx.Rollback()
  2505. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2506. return
  2507. }
  2508. if (parsetotal - count) > stock_count {
  2509. tx.Rollback()
  2510. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2511. return
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. //不使用耗材保存处方出库
  2525. if goodOutConfig.IsOpen != 1 {
  2526. if stockConfig.IsOpen == 1 {
  2527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2529. if len(prescriptions) > 0 {
  2530. for _, item := range prescriptions {
  2531. items := item.(map[string]interface{})
  2532. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2533. projects := items["project"].([]interface{})
  2534. if len(projects) > 0 {
  2535. for _, project := range projects {
  2536. var project_id int64
  2537. var project_type int64
  2538. var totals float64
  2539. var project_name string
  2540. var parsetotal int64
  2541. var id int64
  2542. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2543. id = int64(project.(map[string]interface{})["id"].(float64))
  2544. }
  2545. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2546. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2547. }
  2548. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2549. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2550. }
  2551. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2552. total, _ := project.(map[string]interface{})["total"].(string)
  2553. totals, _ = strconv.ParseFloat(total, 64)
  2554. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2555. }
  2556. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2557. project_name = project.(map[string]interface{})["project_name"].(string)
  2558. }
  2559. if project_type == 3 {
  2560. //查找该耗材的出库记录
  2561. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2562. //没有出库记录
  2563. if len(goodWarehouseInfo) == 0 {
  2564. //查询耗材库存
  2565. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2566. var stock_count int64
  2567. for _, it := range list {
  2568. stock_count += it.StockCount
  2569. }
  2570. stock_counts := strconv.FormatInt(stock_count, 10)
  2571. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2572. if stock_total_count == 0 {
  2573. tx.Rollback()
  2574. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2575. return
  2576. }
  2577. if totals > stock_total_count {
  2578. tx.Rollback()
  2579. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2580. return
  2581. }
  2582. //查找今日该患者已经出库的所有耗材
  2583. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2584. for _, item := range goodList {
  2585. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2586. var flush_count int64
  2587. for _, it := range goodListSix {
  2588. flush_count += it.StockCount
  2589. }
  2590. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2591. creater := adminInfo.AdminUser.Id
  2592. if errs != nil {
  2593. goodErrcode := models.XtGoodErrcode{
  2594. UserOrgId: item.OrgId,
  2595. Errcode: "手动出库更新剩余出库失败",
  2596. GoodId: item.GoodId,
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: 0,
  2600. Count: 0,
  2601. StockCount: 0,
  2602. Creater: creater,
  2603. BatchNumberId: 0,
  2604. WarehouseOutId: 0,
  2605. }
  2606. service.CreateGoodErrcode(goodErrcode)
  2607. }
  2608. }
  2609. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2610. }
  2611. //有出库记录
  2612. if len(goodWarehouseInfo) > 0 {
  2613. //查询该患者耗材的历史数据
  2614. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2615. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2616. //数量发生改变
  2617. if parsetotal != count {
  2618. //查找今日该患者已经出库的所有耗材
  2619. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2620. for _, item := range goodList {
  2621. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2622. var flush_count int64
  2623. for _, it := range goodListSix {
  2624. flush_count += it.StockCount
  2625. }
  2626. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2627. //减少出库数量
  2628. creater := adminInfo.AdminUser.Id
  2629. if errs != nil {
  2630. goodErrcode := models.XtGoodErrcode{
  2631. UserOrgId: item.OrgId,
  2632. Errcode: "手动出库更新剩余出库失败",
  2633. GoodId: item.GoodId,
  2634. Status: 1,
  2635. Ctime: time.Now().Unix(),
  2636. Mtime: 0,
  2637. Count: 0,
  2638. StockCount: 0,
  2639. Creater: creater,
  2640. BatchNumberId: 0,
  2641. WarehouseOutId: 0,
  2642. }
  2643. service.CreateGoodErrcode(goodErrcode)
  2644. }
  2645. //查询默认仓库
  2646. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2647. var total_count int64
  2648. for _, it := range stockList {
  2649. total_count += it.StockCount
  2650. }
  2651. //基础库插入数据
  2652. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2653. }
  2654. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2667. var hpInfo models.HisPrescriptionInfo
  2668. if info.ID == 0 {
  2669. var randNum int
  2670. randNum = rand.Intn(10000) + 1000
  2671. timestamp := time.Now().Unix()
  2672. tempTime := time.Unix(timestamp, 0)
  2673. timeFormat := tempTime.Format("20060102150405")
  2674. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2675. hpInfo = models.HisPrescriptionInfo{
  2676. HisPatientId: his_patient_id,
  2677. UserOrgId: adminInfo.CurrentOrgId,
  2678. RecordDate: theTime.Unix(),
  2679. PatientId: patient_id,
  2680. Status: 1,
  2681. Ctime: time.Now().Unix(),
  2682. Mtime: time.Now().Unix(),
  2683. Creator: adminInfo.AdminUser.Id,
  2684. Modifier: adminInfo.AdminUser.Id,
  2685. Diagnosis: diagnose,
  2686. SickHistory: sick_history,
  2687. Departments: department,
  2688. RegisterType: reg_type,
  2689. PrescriptionNumber: p_number,
  2690. PrescriptionStatus: 1,
  2691. Doctor: role.UserName,
  2692. DoctorId: doctor_id,
  2693. SickType: sick_type,
  2694. PType: p_type,
  2695. PatientDiagnosis: patient_diagnose,
  2696. }
  2697. service.SavePatientPrescriptionInfo(hpInfo)
  2698. //创建步骤表
  2699. finish := models.XtDialysisFinish{
  2700. IsFinish: 1,
  2701. UserOrgId: adminInfo.CurrentOrgId,
  2702. Status: 1,
  2703. Ctime: time.Now().Unix(),
  2704. Mtime: 0,
  2705. Module: 4,
  2706. RecordDate: theTime.Unix(),
  2707. Sourse: 1,
  2708. PatientId: patient_id,
  2709. }
  2710. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2711. if dialysisFinish.ID == 0 {
  2712. service.CreateDialysisFinish(finish)
  2713. }
  2714. redis := service.RedisClient()
  2715. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2716. redis.Set(key, "", time.Second)
  2717. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2718. redis.Set(keyOne, "", time.Second)
  2719. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2720. redis.Set(keySeven, "", time.Second)
  2721. defer redis.Close()
  2722. } else {
  2723. hpInfo = models.HisPrescriptionInfo{
  2724. ID: info.ID,
  2725. UserOrgId: adminInfo.CurrentOrgId,
  2726. RecordDate: info.RecordDate,
  2727. PatientId: info.PatientId,
  2728. Status: 1,
  2729. Ctime: info.Ctime,
  2730. Mtime: time.Now().Unix(),
  2731. Creator: info.Creator,
  2732. Modifier: adminInfo.AdminUser.Id,
  2733. Diagnosis: diagnose,
  2734. SickHistory: sick_history,
  2735. Departments: department,
  2736. RegisterType: reg_type,
  2737. PrescriptionNumber: info.PrescriptionNumber,
  2738. Doctor: role.UserName,
  2739. PrescriptionStatus: info.PrescriptionStatus,
  2740. DoctorId: doctor_id,
  2741. SickType: sick_type,
  2742. PType: info.PType,
  2743. HisPatientId: info.HisPatientId,
  2744. PatientDiagnosis: patient_diagnose,
  2745. }
  2746. service.SavePatientPrescriptionInfo(hpInfo)
  2747. //创建步骤表
  2748. finish := models.XtDialysisFinish{
  2749. IsFinish: 1,
  2750. UserOrgId: adminInfo.CurrentOrgId,
  2751. Status: 1,
  2752. Ctime: time.Now().Unix(),
  2753. Mtime: 0,
  2754. Module: 4,
  2755. RecordDate: info.RecordDate,
  2756. Sourse: 1,
  2757. PatientId: info.PatientId,
  2758. }
  2759. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2760. if dialysisFinish.ID == 0 {
  2761. service.CreateDialysisFinish(finish)
  2762. }
  2763. redis := service.RedisClient()
  2764. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2765. redis.Set(key, "", time.Second)
  2766. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2767. redis.Set(keyOne, "", time.Second)
  2768. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2769. redis.Set(keySeven, "", time.Second)
  2770. defer redis.Close()
  2771. }
  2772. //定义切片
  2773. var adviceList []models.HisDoctorAdviceInfo
  2774. var projectList []models.HisPrescriptionProject
  2775. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 {
  2776. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2777. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2778. var tempPrescription *models.HisPrescription
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. // 开始外部循环的事务
  2782. tx := db.Begin()
  2783. // 在函数结束时处理事务回滚
  2784. defer func() {
  2785. if r := recover(); r != nil {
  2786. tx.Rollback()
  2787. }
  2788. }()
  2789. items := item.(map[string]interface{})
  2790. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2791. utils.ErrorLog("id")
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. id := int64(items["id"].(float64))
  2796. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2797. tempPrescription = &new_prescription
  2798. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2799. utils.ErrorLog("type")
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. types := int64(items["type"].(float64))
  2804. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2805. utils.ErrorLog("med_type")
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2810. if med_type == "0" {
  2811. med_type = "14"
  2812. }
  2813. //if order_status == 0 {
  2814. // order_status = 1
  2815. //}
  2816. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2817. utils.ErrorLog("pre_time")
  2818. }
  2819. preTime, _ := items["pre_time"].(string)
  2820. fmt.Println("preTime", preTime)
  2821. timeLayout := "2006-01-02"
  2822. loc, _ := time.LoadLocation("Local")
  2823. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2824. result := strings.Split(preTime, " ")
  2825. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2826. if err != nil {
  2827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2828. return
  2829. }
  2830. pTime := theTime2.Unix()
  2831. ctime := time.Now().Unix()
  2832. if tempPrescription.ID == 0 {
  2833. prescription := &models.HisPrescription{
  2834. ID: 0,
  2835. PatientId: patient_id,
  2836. UserOrgId: adminInfo.CurrentOrgId,
  2837. RecordDate: recordDateTime,
  2838. Ctime: ctime,
  2839. Mtime: ctime,
  2840. Type: types,
  2841. Modifier: adminInfo.AdminUser.Id,
  2842. Creator: adminInfo.AdminUser.Id,
  2843. Status: 1,
  2844. Doctor: role.UserName,
  2845. HisPatientId: his_patient_id,
  2846. OrderStatus: 1,
  2847. BatchNumber: "",
  2848. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2849. PreTime: pTime,
  2850. PType: p_type,
  2851. MedType: med_type,
  2852. }
  2853. tempPrescription = prescription
  2854. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2855. redis := service.RedisClient()
  2856. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2857. redis.Set(key, "", time.Second)
  2858. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2859. redis.Set(keyOne, "", time.Second)
  2860. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2861. redis.Set(keySeven, "", time.Second)
  2862. defer redis.Close()
  2863. } else {
  2864. tempPrescription.ID = id
  2865. tempPrescription.Type = types
  2866. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2867. tempPrescription.Mtime = time.Now().Unix()
  2868. tempPrescription.Doctor = role.UserName
  2869. //tempPrescription.OrderStatus = order_status
  2870. tempPrescription.PreTime = pTime
  2871. tempPrescription.MedType = med_type
  2872. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2873. redis := service.RedisClient()
  2874. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2875. redis.Set(key, "", time.Second)
  2876. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2877. redis.Set(keyOne, "", time.Second)
  2878. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2879. redis.Set(keySeven, "", time.Second)
  2880. defer redis.Close()
  2881. }
  2882. //service.SaveHisPrescription(prescription)
  2883. //更改患者挂号状态
  2884. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2885. fmt.Println("更改失败", err2)
  2886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2887. advices := items["advices"].([]interface{})
  2888. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2889. groupNo := int64(0)
  2890. if len(advices) > 0 {
  2891. for _, advice := range advices {
  2892. tx := db.Begin()
  2893. // 在函数结束时处理事务回滚
  2894. defer func() {
  2895. if r := recover(); r != nil {
  2896. tx.Rollback()
  2897. }
  2898. }()
  2899. var s models.HisDoctorAdviceInfo
  2900. s.PrescriptionId = tempPrescription.ID
  2901. s.AdviceType = 2
  2902. s.AdviceDoctor = doctor_id
  2903. s.StopState = 2
  2904. s.ExecutionState = 2
  2905. s.AdviceDate = theTime3.Unix()
  2906. s.Status = 1
  2907. s.UserOrgId = adminInfo.CurrentOrgId
  2908. s.RecordDate = theTime3.Unix()
  2909. s.StartTime = tempPrescription.PreTime
  2910. s.Groupno = groupNo
  2911. s.PatientId = patient_id
  2912. s.HisPatientId = his_patient_id
  2913. s.StartTime = pTime
  2914. s.IsSettle = 2
  2915. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2916. if errcode > 0 {
  2917. c.ServeFailJSONWithSGJErrorCode(errcode)
  2918. return
  2919. }
  2920. s.StartTime = pTime
  2921. var total_count int64 //处方总库存
  2922. //查询改药品信息
  2923. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2924. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2925. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2926. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2927. total_count += prescribingNumberSeven * medical.MinNumber
  2928. }
  2929. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2930. total_count += prescribingNumberSeven
  2931. }
  2932. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2933. total_count += prescribingNumberSeven
  2934. }
  2935. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2936. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2937. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2938. if s.Price != lastWarehouse.RetailPrice {
  2939. s.Price = lastWarehouse.RetailPrice
  2940. }
  2941. if s.Price == 0 {
  2942. if lastWarehouse.ID == 0 {
  2943. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2944. s.Price = lastWarehouseTwo.RetailPrice
  2945. }
  2946. }
  2947. }
  2948. //查询保存处方出库开关是否打开
  2949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2950. if s.PatientId != 30038 {
  2951. if drugOutConfig.IsOpen == 1 {
  2952. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2953. // 查询该药品最后一次出库记录
  2954. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2955. var is_user_total int64
  2956. var no_user_total int64
  2957. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2958. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2959. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2960. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2961. }
  2962. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2963. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2964. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2965. no_user_total += prescribingNumberSevenTy
  2966. }
  2967. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2968. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2969. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2970. no_user_total += prescribingNumberSevenTy
  2971. }
  2972. if len(druginfo) > 0 {
  2973. for _, it := range druginfo {
  2974. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2975. it.Count = it.Count * drug.MinNumber
  2976. is_user_total += it.Count
  2977. }
  2978. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2979. is_user_total += it.Count
  2980. }
  2981. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2982. is_user_total += it.Count
  2983. }
  2984. }
  2985. }
  2986. //fmt.Println("药品名称----------------------", drug.DrugName)
  2987. //fmt.Println("药品名称----------------------", drug.IsUse)
  2988. //fmt.Println("is_user_total-------------------------", is_user_total)
  2989. //fmt.Println("no_user_total-------------------------", no_user_total)
  2990. if is_user_total != no_user_total {
  2991. //出库
  2992. if drug.IsUse == 2 {
  2993. creater := adminInfo.AdminUser.Id
  2994. newadviceInfo := &models.HisDoctorAdviceInfo{
  2995. ID: s.ID,
  2996. UserOrgId: s.UserOrgId,
  2997. PatientId: s.PatientId,
  2998. HisPatientId: s.HisPatientId,
  2999. AdviceType: s.AdviceType,
  3000. AdviceDate: s.AdviceDate,
  3001. StartTime: s.StartTime,
  3002. AdviceName: s.AdviceName,
  3003. AdviceDesc: s.AdviceDesc,
  3004. ReminderDate: s.ReminderDate,
  3005. SingleDose: s.SingleDose,
  3006. SingleDoseUnit: s.SingleDoseUnit,
  3007. PrescribingNumber: s.PrescribingNumber,
  3008. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3009. DeliveryWay: s.DeliveryWay,
  3010. ExecutionFrequency: s.ExecutionFrequency,
  3011. AdviceDoctor: s.AdviceDoctor,
  3012. Status: s.Status,
  3013. CreatedTime: s.CreatedTime,
  3014. UpdatedTime: s.UpdatedTime,
  3015. AdviceAffirm: s.AdviceAffirm,
  3016. Remark: s.Remark,
  3017. StopTime: s.StopTime,
  3018. StopReason: s.StopReason,
  3019. StopDoctor: s.StopDoctor,
  3020. StopState: s.StopState,
  3021. ParentId: s.ParentId,
  3022. ExecutionTime: s.ExecutionTime,
  3023. ExecutionStaff: s.ExecutionStaff,
  3024. ExecutionState: s.ExecutionState,
  3025. Checker: s.Checker,
  3026. RecordDate: s.RecordDate,
  3027. DialysisOrderId: s.DialysisOrderId,
  3028. CheckTime: s.CheckTime,
  3029. CheckState: s.CheckState,
  3030. DrugSpec: s.DrugSpec,
  3031. DrugSpecUnit: s.DrugSpecUnit,
  3032. Groupno: s.Groupno,
  3033. RemindType: s.RemindType,
  3034. FrequencyType: s.FrequencyType,
  3035. DayCount: s.DayCount,
  3036. WeekDay: s.WeekDay,
  3037. TemplateId: s.TemplateId,
  3038. Modifier: s.Modifier,
  3039. DrugId: s.DrugId,
  3040. Price: s.Price,
  3041. PrescriptionId: s.PrescriptionId,
  3042. MedListCodg: s.MedListCodg,
  3043. FeedetlSn: s.FeedetlSn,
  3044. Day: s.DayCount,
  3045. ChildDoctorAdvice: nil,
  3046. Drug: models.Drug{},
  3047. Diagnosis: s.Diagnosis,
  3048. Way: s.Way,
  3049. HospApprFlag: s.HospApprFlag,
  3050. LmtUsedFlag: s.LmtUsedFlag,
  3051. HisOrderInfo: models.HisOrderInfo{},
  3052. IsMedicine: s.IsMedicine,
  3053. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3054. Child: nil,
  3055. IsSettle: s.IsSettle,
  3056. IsMobile: s.IsMobile,
  3057. IsSelfDrug: s.IsSelfDrug,
  3058. DrugWayCount: s.DrugWayCount,
  3059. }
  3060. var history_count int64
  3061. var local_count int64
  3062. //查找已经开过的医嘱信息
  3063. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3064. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. local_count += prescribingNumberSevenTy * drug.MinNumber
  3068. }
  3069. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. local_count += prescribingNumberSevenTy
  3073. }
  3074. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3075. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3076. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3077. local_count += prescribingNumberSevenTy
  3078. }
  3079. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3080. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3081. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3082. history_count += prescribingNumberSevenTy * drug.MinNumber
  3083. }
  3084. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3085. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3086. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3087. history_count += prescribingNumberSevenTy
  3088. }
  3089. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3090. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3091. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3092. history_count += prescribingNumberSevenTy
  3093. }
  3094. //如果当前出库数量大于历史出库数量则需要出库
  3095. if local_count > history_count {
  3096. //按最小单位出库
  3097. var cha_count = local_count - history_count
  3098. newadviceInfo.PrescribingNumber = float64(cha_count)
  3099. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3100. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3101. }
  3102. //如果当前出库数量小于历史出库数量则需要退库
  3103. if local_count < history_count {
  3104. var cha_count = history_count - local_count
  3105. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. }
  3108. if local_count == history_count {
  3109. if is_user_total == 0 {
  3110. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3111. }
  3112. }
  3113. }
  3114. //更新字典里面的库存
  3115. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3116. var sum_count int64
  3117. for _, its := range stockInfo {
  3118. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3119. if its.MaxUnit == baseDrug.MaxUnit {
  3120. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3121. }
  3122. sum_count += its.StockMaxNumber + its.StockMinNumber
  3123. }
  3124. //更新基础库存
  3125. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3126. //剩余库存
  3127. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3128. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3129. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3130. //创建医嘱
  3131. service.CreateHisDoctorAdviceOne(&s, tx)
  3132. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. if len(outInfoTwo) > 0 {
  3135. for _, item := range outInfoTwo {
  3136. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3137. }
  3138. }
  3139. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3140. if len(drugAutoDetail) > 0 {
  3141. for _, item := range drugAutoDetail {
  3142. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. //记录日志
  3149. byterequest, _ := json.Marshal(s)
  3150. adviceLog := models.XtDoctorAdviceLog{
  3151. UserOrgId: s.UserOrgId,
  3152. PatientId: s.PatientId,
  3153. AdminUserId: adminInfo.AdminUser.Id,
  3154. Module: 1,
  3155. ErrLog: string(byterequest),
  3156. Status: 1,
  3157. Ctime: time.Now().Unix(),
  3158. Mtime: 0,
  3159. Source: "电脑端新建his医嘱",
  3160. RecordDate: s.AdviceDate,
  3161. }
  3162. service.CreateDoctorAdviceLog(adviceLog)
  3163. //存储切片中
  3164. adviceList = append(adviceList, s)
  3165. redis := service.RedisClient()
  3166. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3167. redis.Set(key, "", time.Second)
  3168. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3169. redis.Set(keyOne, "", time.Second)
  3170. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3171. redis.Set(keySeven, "", time.Second)
  3172. var randNum int
  3173. randNum = rand.Intn(10000) + 1000
  3174. timestamp := time.Now().Unix()
  3175. tempTime := time.Unix(timestamp, 0)
  3176. timeFormat := tempTime.Format("20060102150405")
  3177. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3178. //查询改药品是否已经停用
  3179. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3180. if base.ID > 0 {
  3181. tx.Rollback()
  3182. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3183. return
  3184. }
  3185. service.CreateHisDoctorAdviceOne(&s, tx)
  3186. tx.Commit()
  3187. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3188. redis.Set(keySix, "", time.Second)
  3189. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3190. redis.Set(keyFive, "", time.Second)
  3191. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3192. redis.Set(keyEight, "", time.Second)
  3193. defer redis.Close()
  3194. }
  3195. }
  3196. }
  3197. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3198. projects := items["project"].([]interface{})
  3199. if len(projects) > 0 {
  3200. for _, project := range projects {
  3201. tx := db.Begin()
  3202. // 在函数结束时处理事务回滚
  3203. defer func() {
  3204. if r := recover(); r != nil {
  3205. tx.Rollback()
  3206. }
  3207. }()
  3208. var p models.HisPrescriptionProject
  3209. p.PrescriptionId = tempPrescription.ID
  3210. p.PatientId = patient_id
  3211. p.RecordDate = theTime3.Unix()
  3212. p.Doctor = doctor_id
  3213. p.UserOrgId = adminInfo.CurrentOrgId
  3214. p.HisPatientId = his_patient_id
  3215. p.Status = 1
  3216. p.StartTime = pTime
  3217. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3218. if errcode > 0 {
  3219. c.ServeFailJSONWithSGJErrorCode(errcode)
  3220. return
  3221. }
  3222. if p.ID == 0 {
  3223. p.IsOut = 2
  3224. }
  3225. if p.ID > 0 {
  3226. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3227. p.IsOut = projectDetail.IsOut
  3228. }
  3229. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3230. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3231. if p.Type == 3 {
  3232. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3233. if p.Price != lastWarehouse.PackingPrice {
  3234. p.Price = lastWarehouse.PackingPrice
  3235. }
  3236. if p.Price == 0 {
  3237. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3238. p.Price = lastWarehouseTwo.PackingPrice
  3239. }
  3240. if p.Unit == "" {
  3241. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3242. p.Unit = goodInfoOne.PackingUnit
  3243. }
  3244. }
  3245. }
  3246. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3247. //
  3248. // if p.Type == 3 {
  3249. // //查询该耗材是否停用
  3250. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3251. // //表示该耗材已经停用,不能保存
  3252. // if goodInfoSeven.ID == 0 {
  3253. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3254. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3255. // return
  3256. // }
  3257. // }
  3258. //
  3259. //}
  3260. //查询保存耗材出库开关是否打开
  3261. if p.PatientId != 30038 {
  3262. if goodOutConfig.IsOpen == 1 {
  3263. //耗材出库
  3264. if p.Type == 3 {
  3265. //对比当前数据和历史出库数据
  3266. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3267. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3268. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3269. //如果当前处方数量大于历史数据,则需要出库
  3270. if nowCount > historyCount {
  3271. var cha_count int64
  3272. cha_count = nowCount - historyCount
  3273. timeStr := time.Now().Format("2006-01-02")
  3274. timeArr := strings.Split(timeStr, "-")
  3275. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3276. total = total + 1
  3277. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3278. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3279. number = number + total
  3280. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3281. operation_time := time.Now().Unix()
  3282. creater := c.GetAdminUserInfo().AdminUser.Id
  3283. recordDateStr := time.Now().Format("2006-01-02")
  3284. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3285. nowtime := recordDate.Unix()
  3286. warehouseOut := models.WarehouseOut{
  3287. WarehouseOutOrderNumber: warehousing_out_order,
  3288. OperationTime: operation_time,
  3289. OrgId: adminInfo.CurrentOrgId,
  3290. Creater: creater,
  3291. Ctime: time.Now().Unix(),
  3292. Status: 1,
  3293. WarehouseOutTime: nowtime,
  3294. Type: 1,
  3295. StorehouseId: storeConfig.StorehouseOutInfo,
  3296. IsCheck: 1,
  3297. IsSys: 1,
  3298. }
  3299. //查询是否生成出库单
  3300. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3301. if out.ID == 0 {
  3302. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3303. }
  3304. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3305. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3306. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3307. dialyPrepareOne := models.DialysisBeforePrepare{
  3308. GoodTypeId: goodObj.GoodTypeId,
  3309. GoodId: p.ProjectId,
  3310. PatientId: p.PatientId,
  3311. RecordDate: p.RecordDate,
  3312. UserOrgId: adminInfo.CurrentOrgId,
  3313. Count: cha_count,
  3314. Ctime: time.Now().Unix(),
  3315. Creater: creater,
  3316. Status: 1,
  3317. StorehouseId: houseConfig.StorehouseOutInfo,
  3318. ProjectId: p.ID,
  3319. }
  3320. //出库
  3321. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3322. }
  3323. //如果当前处方数量小于历史数据,怎需要退库
  3324. if nowCount < historyCount {
  3325. var cha_count int64
  3326. cha_count = historyCount - nowCount
  3327. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3328. creater := c.GetAdminUserInfo().AdminUser.Id
  3329. newPrescriptionProject := &models.HisPrescriptionProject{
  3330. ID: p.ID,
  3331. ProjectId: p.ProjectId,
  3332. Price: p.Price,
  3333. UserOrgId: p.UserOrgId,
  3334. Status: 1,
  3335. Ctime: time.Now().Unix(),
  3336. Mtime: time.Now().Unix(),
  3337. PatientId: p.PatientId,
  3338. HisPatientId: p.HisPatientId,
  3339. RecordDate: p.RecordDate,
  3340. PrescriptionId: p.PrescriptionId,
  3341. Count: p.Count,
  3342. FeedetlSn: p.FeedetlSn,
  3343. MedListCodg: p.MedListCodg,
  3344. SingleDose: p.SingleDose,
  3345. DeliveryWay: p.DeliveryWay,
  3346. ExecutionFrequency: p.ExecutionFrequency,
  3347. Day: p.Day,
  3348. HisProject: models.HisProject{},
  3349. GoodInfo: models.GoodInfo{},
  3350. Remark: p.Remark,
  3351. Unit: p.Unit,
  3352. Type: p.Type,
  3353. Doctor: p.Doctor,
  3354. ExecutionTime: p.ExecutionTime,
  3355. ExecutionStaff: p.ExecutionStaff,
  3356. ExecutionState: p.ExecutionState,
  3357. CheckTime: p.CheckTime,
  3358. CheckState: p.CheckState,
  3359. Checker: p.Checker,
  3360. StartTime: p.StartTime,
  3361. TeamId: p.TeamId,
  3362. XtHisProjectTeam: models.XtHisProjectTeam{},
  3363. FrequencyType: p.FrequencyType,
  3364. DayCount: p.DayCount,
  3365. WeekDay: p.WeekDay,
  3366. IsCheckTeam: p.IsCheckTeam,
  3367. HisOrderInfo: models.HisOrderInfo{},
  3368. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3369. IsOut: p.IsOut,
  3370. YbSyncStatus: p.YbSyncStatus,
  3371. }
  3372. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3373. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3374. }
  3375. if nowCount == historyCount {
  3376. if historyCount == 0 {
  3377. recordDateStr := time.Now().Format("2006-01-02")
  3378. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3379. nowtime := recordDate.Unix()
  3380. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3381. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3382. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3383. creater := c.GetAdminUserInfo().AdminUser.Id
  3384. dialyPrepareOne := models.DialysisBeforePrepare{
  3385. GoodTypeId: goodObj.GoodTypeId,
  3386. GoodId: p.ProjectId,
  3387. PatientId: p.PatientId,
  3388. RecordDate: p.RecordDate,
  3389. UserOrgId: adminInfo.CurrentOrgId,
  3390. Count: nowCount,
  3391. Ctime: time.Now().Unix(),
  3392. Creater: creater,
  3393. Status: 1,
  3394. StorehouseId: houseConfig.StorehouseOutInfo,
  3395. ProjectId: p.ID,
  3396. }
  3397. //出库
  3398. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3399. }
  3400. }
  3401. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3402. ////查询历史出库数据
  3403. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3404. //
  3405. //var out_count_five int64
  3406. //for _, item := range flowGood {
  3407. // out_count_five += item.Count
  3408. //}
  3409. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3410. //
  3411. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3412. //if out_count_five != parseIntCount {
  3413. // //查询耗材最后一次出库记录
  3414. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3415. // //查询默认出库仓库库存
  3416. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3417. // if len(wareOut) > 0 {
  3418. //
  3419. // for _, it := range wareOut {
  3420. // //回退库存
  3421. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3422. //
  3423. // //删除出库记录
  3424. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3425. //
  3426. // }
  3427. // }
  3428. //
  3429. // timeStr := time.Now().Format("2006-01-02")
  3430. // timeArr := strings.Split(timeStr, "-")
  3431. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3432. //
  3433. // total = total + 1
  3434. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3435. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3436. // number = number + total
  3437. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3438. //
  3439. // operation_time := time.Now().Unix()
  3440. // creater := c.GetAdminUserInfo().AdminUser.Id
  3441. //
  3442. // recordDateStr := time.Now().Format("2006-01-02")
  3443. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3444. // nowtime := recordDate.Unix()
  3445. // warehouseOut := models.WarehouseOut{
  3446. // WarehouseOutOrderNumber: warehousing_out_order,
  3447. // OperationTime: operation_time,
  3448. // OrgId: adminInfo.CurrentOrgId,
  3449. // Creater: creater,
  3450. // Ctime: time.Now().Unix(),
  3451. // Status: 1,
  3452. // WarehouseOutTime: nowtime,
  3453. // Type: 1,
  3454. // StorehouseId: storeConfig.StorehouseOutInfo,
  3455. // IsCheck: 1,
  3456. // IsSys: 1,
  3457. // }
  3458. // //查询是否生成出库单
  3459. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3460. // if out.ID == 0 {
  3461. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3462. // }
  3463. //
  3464. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3465. //
  3466. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3467. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3468. //
  3469. // dialyPrepareOne := models.DialysisBeforePrepare{
  3470. // GoodTypeId: goodObj.GoodTypeId,
  3471. // GoodId: p.ProjectId,
  3472. // PatientId: p.PatientId,
  3473. // RecordDate: p.RecordDate,
  3474. // UserOrgId: adminInfo.CurrentOrgId,
  3475. // Count: parseIntCount,
  3476. // Ctime: time.Now().Unix(),
  3477. // Creater: creater,
  3478. // Status: 1,
  3479. // StorehouseId: houseConfig.StorehouseOutInfo,
  3480. // ProjectId: lastHisProject.ID,
  3481. // }
  3482. // //判断是否是零用耗材(非零用)
  3483. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3484. //
  3485. // //查询历史出库数据
  3486. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3487. // var out_count int64
  3488. // for _, item := range flowGood {
  3489. // out_count += item.Count
  3490. // }
  3491. // //如果历史数和当前数据不想等才进行退库出库
  3492. // if out_count != parseIntCount {
  3493. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3494. //
  3495. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3496. // detail := models.AutomaticReduceDetail{
  3497. // WarehouseOutId: 0,
  3498. // WarehouseOutOrderNumber: "",
  3499. // PatientId: p.PatientId,
  3500. // Ctime: time.Now().Unix(),
  3501. // Mtime: 0,
  3502. // Status: 1,
  3503. // RecordTime: p.RecordDate,
  3504. // OrgId: p.UserOrgId,
  3505. // GoodId: p.ProjectId,
  3506. // GoodTypeId: 0,
  3507. // Count: parseIntCount,
  3508. // Type: 0,
  3509. // ProjectId: lastHisProject.ID,
  3510. // StorehouseId: 0,
  3511. // }
  3512. //
  3513. // service.CreateNewAutoDetail(detail, tx)
  3514. //
  3515. // //查询剩余库存
  3516. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3517. // var sum_count int64
  3518. // for _, item := range goodList {
  3519. // sum_count += item.StockCount
  3520. // }
  3521. //
  3522. // //更新剩余库存
  3523. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3524. //
  3525. // //耗材
  3526. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3527. //
  3528. // }
  3529. // //判断是否是零用耗材(零用但是是出库耗材)
  3530. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3531. //
  3532. // //查询历史出库数据
  3533. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3534. // var out_count int64
  3535. // for _, item := range flowGood {
  3536. // out_count += item.Count
  3537. // }
  3538. // //如果历史数和当前数据不想等才进行退库出库
  3539. // if out_count != parseIntCount {
  3540. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3541. //
  3542. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3543. // detail := models.AutomaticReduceDetail{
  3544. // WarehouseOutId: 0,
  3545. // WarehouseOutOrderNumber: "",
  3546. // PatientId: p.PatientId,
  3547. // Ctime: time.Now().Unix(),
  3548. // Mtime: 0,
  3549. // Status: 1,
  3550. // RecordTime: p.RecordDate,
  3551. // OrgId: p.UserOrgId,
  3552. // GoodId: p.ProjectId,
  3553. // GoodTypeId: 0,
  3554. // Count: parseIntCount,
  3555. // Type: 0,
  3556. // ProjectId: p.ID,
  3557. // StorehouseId: 0,
  3558. // }
  3559. //
  3560. // service.CreateNewAutoDetail(detail, tx)
  3561. //
  3562. // //查询剩余库存
  3563. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3564. // var sum_count int64
  3565. // for _, item := range goodList {
  3566. // sum_count += item.StockCount
  3567. // }
  3568. //
  3569. // //更新剩余库存
  3570. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3571. //
  3572. // //耗材
  3573. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3574. // }
  3575. //
  3576. // }
  3577. //
  3578. // }
  3579. //
  3580. //}
  3581. //记录日志
  3582. byterequest, _ := json.Marshal(p)
  3583. adviceLog := models.XtDoctorAdviceLog{
  3584. UserOrgId: p.UserOrgId,
  3585. PatientId: p.PatientId,
  3586. AdminUserId: adminInfo.AdminUser.Id,
  3587. Module: 1,
  3588. ErrLog: string(byterequest),
  3589. Status: 1,
  3590. Ctime: time.Now().Unix(),
  3591. Mtime: 0,
  3592. Source: "电脑端新建his项目",
  3593. RecordDate: p.RecordDate,
  3594. }
  3595. service.CreateDoctorAdviceLog(adviceLog)
  3596. projectList = append(projectList, p)
  3597. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3598. //新增或者编辑项目,修改对应的标签数据
  3599. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3600. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3601. var label models.HisLabelPrintInfo
  3602. project, _ := service.GetProjectDetail(p.ProjectId)
  3603. if project.CostClassify == 3 { //类别为检验检查
  3604. if p.TeamId > 0 { //检验检查组套
  3605. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3606. if tempLabel.ID == 0 {
  3607. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3608. label.Number = tempPrescription.PrescriptionNumber
  3609. label.ProjectId = project.ID
  3610. label.Status = 1
  3611. label.IsPrint = 2
  3612. label.DoctorId = info.DoctorId
  3613. label.UserOrgId = p.UserOrgId
  3614. label.PatientId = patient_id
  3615. label.RecordDate = recordDateTime
  3616. label.Ctime = time.Now().Unix()
  3617. label.Mtime = time.Now().Unix()
  3618. label.ItemId = p.TeamId
  3619. label.FeedetlSn = p.FeedetlSn
  3620. label.PProjectId = p.ID
  3621. label.ProjectName = team.ProjectTeam
  3622. label.PatientName = patient.Name
  3623. service.CreateNewHisLabelRecord(&label, tx)
  3624. }
  3625. } else { //单条检验检查项目
  3626. label.Number = tempPrescription.PrescriptionNumber
  3627. label.ProjectId = project.ID
  3628. label.Status = 1
  3629. label.DoctorId = info.DoctorId
  3630. label.UserOrgId = p.UserOrgId
  3631. label.PatientId = patient_id
  3632. label.RecordDate = recordDateTime
  3633. label.IsPrint = 2
  3634. label.Ctime = time.Now().Unix()
  3635. label.Mtime = time.Now().Unix()
  3636. label.FeedetlSn = p.FeedetlSn
  3637. label.PProjectId = p.ID
  3638. label.ItemId = p.TeamId
  3639. label.ProjectName = project.ProjectName
  3640. label.PatientName = patient.Name
  3641. service.CreateNewHisLabelRecord(&label, tx)
  3642. }
  3643. }
  3644. }
  3645. }
  3646. }
  3647. }
  3648. }
  3649. service.CreateNewHisProjectTwo(&p, tx)
  3650. var randNum int
  3651. randNum = rand.Intn(10000) + 1000
  3652. timestamp := time.Now().Unix()
  3653. tempTime := time.Unix(timestamp, 0)
  3654. timeFormat := tempTime.Format("20060102150405")
  3655. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3656. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3657. if goodBase.ID > 0 {
  3658. tx.Rollback()
  3659. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3660. return
  3661. }
  3662. service.CreateNewHisProjectTwo(&p, tx)
  3663. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3664. //查询剩余库存
  3665. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3666. var sum_count int64
  3667. for _, item := range goodList {
  3668. sum_count += item.StockCount
  3669. }
  3670. //更新剩余库存
  3671. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3672. //耗材
  3673. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3674. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3675. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3676. if len(outInfoTwo) > 0 {
  3677. for _, item := range outInfoTwo {
  3678. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3679. }
  3680. }
  3681. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3682. if len(drugAutoDetail) > 0 {
  3683. for _, item := range drugAutoDetail {
  3684. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3685. }
  3686. }
  3687. tx.Commit()
  3688. }
  3689. }
  3690. }
  3691. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3692. // addition := items["addition"].([]interface{})
  3693. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3694. // ctime := time.Now().Unix()
  3695. // mtime := ctime
  3696. // if len(addition) > 0 {
  3697. // for _, item := range addition {
  3698. // var s models.HisAdditionalCharge
  3699. // s.PrescriptionId = tempPrescription.ID
  3700. // s.Status = 1
  3701. // s.UserOrgId = adminInfo.CurrentOrgId
  3702. // s.RecordDate = recordDateTime
  3703. // s.CreatedTime = ctime
  3704. // s.UpdatedTime = mtime
  3705. // s.PatientId = patient_id
  3706. // s.HisPatientId = his_patient_id
  3707. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3708. // if errcode > 0 {
  3709. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3710. // return
  3711. // }
  3712. // service.CreateAdditionalCharge(&s)
  3713. // var randNum int
  3714. // randNum = rand.Intn(10000) + 1000
  3715. // timestamp := time.Now().Unix()
  3716. // tempTime := time.Unix(timestamp, 0)
  3717. // timeFormat := tempTime.Format("20060102150405")
  3718. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3719. // service.CreateAdditionalCharge(&s)
  3720. //
  3721. // }
  3722. // }
  3723. //}
  3724. }
  3725. }
  3726. }
  3727. tx.Commit()
  3728. if err == nil {
  3729. c.ServeSuccessJSON(map[string]interface{}{
  3730. "msg": "保存成功",
  3731. })
  3732. return
  3733. } else {
  3734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3735. return
  3736. }
  3737. } else {
  3738. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3739. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3740. var tempPrescription *models.HisPrescription
  3741. if len(prescriptions) > 0 {
  3742. for _, item := range prescriptions {
  3743. items := item.(map[string]interface{})
  3744. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3745. utils.ErrorLog("id")
  3746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3747. return
  3748. }
  3749. id := int64(items["id"].(float64))
  3750. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3751. tempPrescription = &new_prescription
  3752. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3753. utils.ErrorLog("type")
  3754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3755. return
  3756. }
  3757. types := int64(items["type"].(float64))
  3758. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3759. utils.ErrorLog("med_type")
  3760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3764. if med_type == "0" {
  3765. med_type = "14"
  3766. }
  3767. //if order_status == 0 {
  3768. // order_status = 1
  3769. //}
  3770. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3771. utils.ErrorLog("pre_time")
  3772. }
  3773. preTime, _ := items["pre_time"].(string)
  3774. timeLayout := "2006-01-02"
  3775. loc, _ := time.LoadLocation("Local")
  3776. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3777. result := strings.Split(preTime, " ")
  3778. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3779. if err != nil {
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3781. return
  3782. }
  3783. pTime := theTime2.Unix()
  3784. ctime := time.Now().Unix()
  3785. if tempPrescription.ID == 0 {
  3786. prescription := &models.HisPrescription{
  3787. ID: 0,
  3788. PatientId: patient_id,
  3789. UserOrgId: adminInfo.CurrentOrgId,
  3790. RecordDate: recordDateTime,
  3791. Ctime: ctime,
  3792. Mtime: ctime,
  3793. Type: types,
  3794. Modifier: adminInfo.AdminUser.Id,
  3795. Creator: adminInfo.AdminUser.Id,
  3796. Status: 1,
  3797. Doctor: role.UserName,
  3798. HisPatientId: his_patient_id,
  3799. OrderStatus: 1,
  3800. BatchNumber: "",
  3801. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3802. PreTime: pTime,
  3803. PType: p_type,
  3804. MedType: med_type,
  3805. }
  3806. tempPrescription = prescription
  3807. service.SaveHisPrescription(tempPrescription)
  3808. redis := service.RedisClient()
  3809. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3810. redis.Set(key, "", time.Second)
  3811. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3812. redis.Set(keyOne, "", time.Second)
  3813. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3814. redis.Set(keySeven, "", time.Second)
  3815. defer redis.Close()
  3816. } else {
  3817. tempPrescription.ID = id
  3818. tempPrescription.Type = types
  3819. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3820. tempPrescription.Mtime = time.Now().Unix()
  3821. tempPrescription.Doctor = role.UserName
  3822. //tempPrescription.OrderStatus = order_status
  3823. tempPrescription.PreTime = pTime
  3824. tempPrescription.MedType = med_type
  3825. service.SaveHisPrescription(tempPrescription)
  3826. redis := service.RedisClient()
  3827. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3828. redis.Set(key, "", time.Second)
  3829. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3830. redis.Set(keyOne, "", time.Second)
  3831. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3832. redis.Set(keySeven, "", time.Second)
  3833. defer redis.Close()
  3834. }
  3835. //service.SaveHisPrescription(prescription)
  3836. //更改患者挂号状态
  3837. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3838. fmt.Println("更改失败", err2)
  3839. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3840. advices := items["advices"].([]interface{})
  3841. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3842. groupNo := int64(0)
  3843. if len(advices) > 0 {
  3844. for _, advice := range advices {
  3845. var s models.HisDoctorAdviceInfo
  3846. s.PrescriptionId = tempPrescription.ID
  3847. s.AdviceType = 2
  3848. s.AdviceDoctor = doctor_id
  3849. s.StopState = 2
  3850. s.ExecutionState = 2
  3851. s.AdviceDate = theTime3.Unix()
  3852. s.Status = 1
  3853. s.UserOrgId = adminInfo.CurrentOrgId
  3854. s.RecordDate = theTime3.Unix()
  3855. s.StartTime = tempPrescription.PreTime
  3856. s.Groupno = groupNo
  3857. s.PatientId = patient_id
  3858. s.HisPatientId = his_patient_id
  3859. s.StartTime = pTime
  3860. s.IsSettle = 2
  3861. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3862. if errcode > 0 {
  3863. c.ServeFailJSONWithSGJErrorCode(errcode)
  3864. return
  3865. }
  3866. s.StartTime = pTime
  3867. var total_count int64 //处方总库存
  3868. //查询改药品信息
  3869. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3870. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3871. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3872. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3873. total_count += prescribingNumberSeven * medical.MinNumber
  3874. }
  3875. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3876. total_count += prescribingNumberSeven
  3877. }
  3878. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3879. total_count += prescribingNumberSeven
  3880. }
  3881. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3882. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3883. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3884. if s.Price != lastWarehouse.RetailPrice {
  3885. s.Price = lastWarehouse.RetailPrice
  3886. }
  3887. if s.Price == 0 {
  3888. if lastWarehouse.ID == 0 {
  3889. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3890. s.Price = lastWarehouseTwo.RetailPrice
  3891. }
  3892. }
  3893. }
  3894. service.CreateHisDoctorAdvice(&s)
  3895. //记录日志
  3896. byterequest, _ := json.Marshal(s)
  3897. adviceLog := models.XtDoctorAdviceLog{
  3898. UserOrgId: s.UserOrgId,
  3899. PatientId: s.PatientId,
  3900. AdminUserId: adminInfo.AdminUser.Id,
  3901. Module: 1,
  3902. ErrLog: string(byterequest),
  3903. Status: 1,
  3904. Ctime: time.Now().Unix(),
  3905. Mtime: 0,
  3906. Source: "电脑端新建his医嘱",
  3907. RecordDate: s.AdviceDate,
  3908. }
  3909. service.CreateDoctorAdviceLog(adviceLog)
  3910. //存储切片中
  3911. adviceList = append(adviceList, s)
  3912. redis := service.RedisClient()
  3913. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3914. redis.Set(key, "", time.Second)
  3915. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3916. redis.Set(keyOne, "", time.Second)
  3917. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3918. redis.Set(keySeven, "", time.Second)
  3919. var randNum int
  3920. randNum = rand.Intn(10000) + 1000
  3921. timestamp := time.Now().Unix()
  3922. tempTime := time.Unix(timestamp, 0)
  3923. timeFormat := tempTime.Format("20060102150405")
  3924. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3925. service.CreateHisDoctorAdvice(&s)
  3926. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3927. redis.Set(keySix, "", time.Second)
  3928. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3929. redis.Set(keyFive, "", time.Second)
  3930. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3931. redis.Set(keyEight, "", time.Second)
  3932. defer redis.Close()
  3933. }
  3934. }
  3935. }
  3936. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3937. projects := items["project"].([]interface{})
  3938. if len(projects) > 0 {
  3939. for _, project := range projects {
  3940. var p models.HisPrescriptionProject
  3941. p.PrescriptionId = tempPrescription.ID
  3942. p.PatientId = patient_id
  3943. p.RecordDate = theTime3.Unix()
  3944. p.Doctor = doctor_id
  3945. p.UserOrgId = adminInfo.CurrentOrgId
  3946. p.HisPatientId = his_patient_id
  3947. p.Status = 1
  3948. p.StartTime = pTime
  3949. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3950. if errcode > 0 {
  3951. c.ServeFailJSONWithSGJErrorCode(errcode)
  3952. return
  3953. }
  3954. if p.ID == 0 {
  3955. p.IsOut = 2
  3956. }
  3957. if p.ID > 0 {
  3958. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3959. p.IsOut = projectDetail.IsOut
  3960. }
  3961. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3962. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3963. if p.Type == 3 {
  3964. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3965. if p.Price != lastWarehouse.PackingPrice {
  3966. p.Price = lastWarehouse.PackingPrice
  3967. }
  3968. if p.Price == 0 {
  3969. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3970. p.Price = lastWarehouseTwo.PackingPrice
  3971. }
  3972. if p.Unit == "" {
  3973. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3974. p.Unit = goodInfoOne.PackingUnit
  3975. }
  3976. }
  3977. }
  3978. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3979. //
  3980. // if p.Type == 3 {
  3981. // //查询该耗材是否停用
  3982. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3983. // //表示该耗材已经停用,不能保存
  3984. // if goodInfoSeven.ID == 0 {
  3985. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3986. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3987. // return
  3988. // }
  3989. // }
  3990. //
  3991. //}
  3992. service.CreateHisProjectTwo(&p)
  3993. //记录日志
  3994. byterequest, _ := json.Marshal(p)
  3995. adviceLog := models.XtDoctorAdviceLog{
  3996. UserOrgId: p.UserOrgId,
  3997. PatientId: p.PatientId,
  3998. AdminUserId: adminInfo.AdminUser.Id,
  3999. Module: 1,
  4000. ErrLog: string(byterequest),
  4001. Status: 1,
  4002. Ctime: time.Now().Unix(),
  4003. Mtime: 0,
  4004. Source: "电脑端新建his项目",
  4005. RecordDate: p.RecordDate,
  4006. }
  4007. service.CreateDoctorAdviceLog(adviceLog)
  4008. projectList = append(projectList, p)
  4009. var randNum int
  4010. randNum = rand.Intn(10000) + 1000
  4011. timestamp := time.Now().Unix()
  4012. tempTime := time.Unix(timestamp, 0)
  4013. timeFormat := tempTime.Format("20060102150405")
  4014. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4015. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4016. //新增或者编辑项目,修改对应的标签数据
  4017. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4018. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4019. var label models.HisLabelPrintInfo
  4020. project, _ := service.GetProjectDetail(p.ProjectId)
  4021. if project.CostClassify == 3 { //类别为检验检查
  4022. if p.TeamId > 0 { //检验检查组套
  4023. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4024. if tempLabel.ID == 0 {
  4025. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4026. label.Number = tempPrescription.PrescriptionNumber
  4027. label.ProjectId = project.ID
  4028. label.Status = 1
  4029. label.IsPrint = 2
  4030. label.DoctorId = info.DoctorId
  4031. label.UserOrgId = p.UserOrgId
  4032. label.PatientId = patient_id
  4033. label.RecordDate = recordDateTime
  4034. label.Ctime = time.Now().Unix()
  4035. label.Mtime = time.Now().Unix()
  4036. label.ItemId = p.TeamId
  4037. label.FeedetlSn = p.FeedetlSn
  4038. label.PProjectId = p.ID
  4039. label.ProjectName = team.ProjectTeam
  4040. label.PatientName = patient.Name
  4041. service.CreateHisLabelRecord(&label)
  4042. }
  4043. } else { //单条检验检查项目
  4044. label.Number = tempPrescription.PrescriptionNumber
  4045. label.ProjectId = project.ID
  4046. label.Status = 1
  4047. label.DoctorId = info.DoctorId
  4048. label.UserOrgId = p.UserOrgId
  4049. label.PatientId = patient_id
  4050. label.RecordDate = recordDateTime
  4051. label.IsPrint = 2
  4052. label.Ctime = time.Now().Unix()
  4053. label.Mtime = time.Now().Unix()
  4054. label.FeedetlSn = p.FeedetlSn
  4055. label.PProjectId = p.ID
  4056. label.ItemId = p.TeamId
  4057. label.ProjectName = project.ProjectName
  4058. label.PatientName = patient.Name
  4059. service.CreateHisLabelRecord(&label)
  4060. }
  4061. }
  4062. }
  4063. }
  4064. service.SaveHisProjectTwo(&p)
  4065. }
  4066. }
  4067. }
  4068. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4069. // addition := items["addition"].([]interface{})
  4070. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4071. // ctime := time.Now().Unix()
  4072. // mtime := ctime
  4073. // if len(addition) > 0 {
  4074. // for _, item := range addition {
  4075. // var s models.HisAdditionalCharge
  4076. // s.PrescriptionId = tempPrescription.ID
  4077. // s.Status = 1
  4078. // s.UserOrgId = adminInfo.CurrentOrgId
  4079. // s.RecordDate = recordDateTime
  4080. // s.CreatedTime = ctime
  4081. // s.UpdatedTime = mtime
  4082. // s.PatientId = patient_id
  4083. // s.HisPatientId = his_patient_id
  4084. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4085. // if errcode > 0 {
  4086. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4087. // return
  4088. // }
  4089. // service.CreateAdditionalCharge(&s)
  4090. // var randNum int
  4091. // randNum = rand.Intn(10000) + 1000
  4092. // timestamp := time.Now().Unix()
  4093. // tempTime := time.Unix(timestamp, 0)
  4094. // timeFormat := tempTime.Format("20060102150405")
  4095. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4096. // service.CreateAdditionalCharge(&s)
  4097. //
  4098. // }
  4099. // }
  4100. //}
  4101. }
  4102. }
  4103. //查询今日该患者开的药品处方
  4104. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4105. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4106. //药品出库
  4107. if drugOutConfig.IsOpen == 1 {
  4108. for _, item := range hisdoctorlist {
  4109. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4110. // 查询该药品最后一次出库记录
  4111. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4112. if len(druginfo) > 0 {
  4113. //回退库存
  4114. for _, it := range druginfo {
  4115. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4116. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4117. }
  4118. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4119. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4120. }
  4121. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4122. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4123. }
  4124. }
  4125. }
  4126. //删除记录
  4127. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4128. //查询最后一次数据
  4129. if drugOutConfig.IsOpen == 1 {
  4130. //出库
  4131. if drug.IsUse == 2 {
  4132. creater := adminInfo.AdminUser.Id
  4133. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4134. }
  4135. //更新字典里面的库存
  4136. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4137. var sum_count int64
  4138. for _, its := range stockInfo {
  4139. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4140. if its.MaxUnit == baseDrug.MaxUnit {
  4141. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4142. }
  4143. sum_count += its.StockMaxNumber + its.StockMinNumber
  4144. }
  4145. //更新基础库存
  4146. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4147. //剩余库存
  4148. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4149. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4150. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4151. }
  4152. }
  4153. }
  4154. //耗材保存处方出库
  4155. if goodOutConfig.IsOpen == 1 {
  4156. //查询今日耗材出库数量
  4157. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4158. for _, item := range hisgoodlist {
  4159. //查询历史出库数据
  4160. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4161. var out_count_five int64
  4162. for _, item := range flowGood {
  4163. out_count_five += item.Count
  4164. }
  4165. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4166. if out_count_five != parseIntCount {
  4167. //查询耗材最后一次出库记录
  4168. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4169. //查询默认出库仓库库存
  4170. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4171. if len(wareOut) > 0 {
  4172. for _, it := range wareOut {
  4173. //回退库存
  4174. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4175. //删除出库记录
  4176. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4177. }
  4178. }
  4179. timeStr := time.Now().Format("2006-01-02")
  4180. timeArr := strings.Split(timeStr, "-")
  4181. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4182. total = total + 1
  4183. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4184. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4185. number = number + total
  4186. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4187. operation_time := time.Now().Unix()
  4188. creater := c.GetAdminUserInfo().AdminUser.Id
  4189. recordDateStr := time.Now().Format("2006-01-02")
  4190. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4191. nowtime := recordDate.Unix()
  4192. warehouseOut := models.WarehouseOut{
  4193. WarehouseOutOrderNumber: warehousing_out_order,
  4194. OperationTime: operation_time,
  4195. OrgId: adminInfo.CurrentOrgId,
  4196. Creater: creater,
  4197. Ctime: time.Now().Unix(),
  4198. Status: 1,
  4199. WarehouseOutTime: nowtime,
  4200. Type: 1,
  4201. StorehouseId: storeConfig.StorehouseOutInfo,
  4202. IsCheck: 1,
  4203. IsSys: 1,
  4204. }
  4205. //查询是否生成出库单
  4206. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4207. if out.ID == 0 {
  4208. service.AddSigleWarehouseOut(&warehouseOut)
  4209. }
  4210. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4211. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4212. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4213. dialyPrepareOne := models.DialysisBeforePrepare{
  4214. GoodTypeId: goodObj.GoodTypeId,
  4215. GoodId: item.ProjectId,
  4216. PatientId: item.PatientId,
  4217. RecordDate: item.RecordDate,
  4218. UserOrgId: adminInfo.CurrentOrgId,
  4219. Count: parseIntCount,
  4220. Ctime: time.Now().Unix(),
  4221. Creater: creater,
  4222. Status: 1,
  4223. StorehouseId: houseConfig.StorehouseOutInfo,
  4224. ProjectId: item.ID,
  4225. }
  4226. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4227. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4228. //查询历史出库数据
  4229. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4230. var out_count int64
  4231. for _, item := range flowGood {
  4232. out_count += item.Count
  4233. }
  4234. //如果历史数和当前数据不想等才进行退库出库
  4235. if out_count != parseIntCount {
  4236. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4237. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4238. detail := models.AutomaticReduceDetail{
  4239. WarehouseOutId: 0,
  4240. WarehouseOutOrderNumber: "",
  4241. PatientId: item.PatientId,
  4242. Ctime: time.Now().Unix(),
  4243. Mtime: 0,
  4244. Status: 1,
  4245. RecordTime: item.RecordDate,
  4246. OrgId: item.UserOrgId,
  4247. GoodId: item.ProjectId,
  4248. GoodTypeId: 0,
  4249. Count: parseIntCount,
  4250. Type: 0,
  4251. ProjectId: item.ID,
  4252. StorehouseId: 0,
  4253. }
  4254. service.CreateAutoDetail(detail)
  4255. //查询剩余库存
  4256. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4257. var sum_count int64
  4258. for _, item := range goodList {
  4259. sum_count += item.StockCount
  4260. }
  4261. //更新剩余库存
  4262. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4263. //耗材
  4264. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4265. }
  4266. }
  4267. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4268. //查询历史出库数据
  4269. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4270. var out_count int64
  4271. for _, item := range flowGood {
  4272. out_count += item.Count
  4273. }
  4274. //如果历史数和当前数据不想等才进行退库出库
  4275. if out_count != parseIntCount {
  4276. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4277. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4278. detail := models.AutomaticReduceDetail{
  4279. WarehouseOutId: 0,
  4280. WarehouseOutOrderNumber: "",
  4281. PatientId: item.PatientId,
  4282. Ctime: time.Now().Unix(),
  4283. Mtime: 0,
  4284. Status: 1,
  4285. RecordTime: item.RecordDate,
  4286. OrgId: item.UserOrgId,
  4287. GoodId: item.ProjectId,
  4288. GoodTypeId: 0,
  4289. Count: parseIntCount,
  4290. Type: 0,
  4291. ProjectId: item.ID,
  4292. StorehouseId: 0,
  4293. }
  4294. service.CreateAutoDetail(detail)
  4295. //查询剩余库存
  4296. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4297. var sum_count int64
  4298. for _, item := range goodList {
  4299. sum_count += item.StockCount
  4300. }
  4301. //更新剩余库存
  4302. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4303. //耗材
  4304. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4305. }
  4306. }
  4307. }
  4308. }
  4309. }
  4310. ////同步到自备药
  4311. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4312. if selfPrescriptionOpen.IsOpen == 1 {
  4313. timeStr := time.Now().Format("2006-01-02")
  4314. timeArr := strings.Split(timeStr, "-")
  4315. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4316. total = total + 1
  4317. operation_time := time.Now().Unix()
  4318. creater := adminInfo.AdminUser.Id
  4319. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4320. warehousing := models.XtSelfDrugWarehouse{
  4321. WarehousingOrder: warehousing_order,
  4322. OperationTime: operation_time,
  4323. OrgId: adminInfo.CurrentOrgId,
  4324. Creater: creater,
  4325. Ctime: time.Now().Unix(),
  4326. Status: 1,
  4327. WarehousingTime: recordDateTime,
  4328. Type: 0,
  4329. StorehouseId: 0,
  4330. IsCheck: 1,
  4331. PatientId: patient_id,
  4332. IsSys: 1,
  4333. }
  4334. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4335. if selfDrugWarehouse.ID == 0 {
  4336. service.AddSelfDrugWarehouse(&warehousing, tx)
  4337. }
  4338. if selfDrugWarehouse.ID > 0 {
  4339. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4340. }
  4341. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4342. fmt.Println(info)
  4343. for _, item := range hisdoctorlist {
  4344. //查询该病人的该药品是否已经入库
  4345. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4346. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4347. var in_count int64
  4348. if len(selfdruginfo) > 0 {
  4349. for _, item := range selfdruginfo {
  4350. var in_count_one int64
  4351. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4352. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4353. }
  4354. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4355. in_count_one = item.WarehousingCount
  4356. }
  4357. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4358. in_count_one = item.WarehousingCount
  4359. }
  4360. in_count += in_count_one
  4361. }
  4362. }
  4363. if selfBasedrug.IsSelfDrug == 1 {
  4364. var total_count int64
  4365. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4366. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4367. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4368. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4369. }
  4370. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4371. total_count += prescribingNumberSeven
  4372. }
  4373. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4374. total_count += prescribingNumberSeven
  4375. }
  4376. //入库
  4377. if total_count > in_count {
  4378. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4379. WarehousingOrder: warehousing_order,
  4380. WarehousingId: info.ID,
  4381. DrugId: item.DrugId,
  4382. Number: "",
  4383. ProductDate: 0,
  4384. ExpiryDate: 0,
  4385. WarehousingCount: total_count - in_count,
  4386. WarehouseingUnit: selfBasedrug.MinUnit,
  4387. Price: 0,
  4388. TotalPrice: 0,
  4389. Status: 1,
  4390. Ctime: time.Now().Unix(),
  4391. Remark: "",
  4392. OrgId: adminInfo.CurrentOrgId,
  4393. Type: 0,
  4394. Manufacturer: selfBasedrug.Manufacturer,
  4395. Dealer: selfBasedrug.Dealer,
  4396. StockMaxNumber: total_count - in_count,
  4397. RetailTotalPrice: 0,
  4398. BatchNumber: "",
  4399. MaxUnit: selfBasedrug.MinUnit,
  4400. MinUnit: selfBasedrug.MinUnit,
  4401. RetailPrice: 0,
  4402. StorehouseId: 0,
  4403. IsCheck: 1,
  4404. StockMinNumber: 0,
  4405. PatientId: patient_id,
  4406. IsSys: 1,
  4407. RecordDate: item.RecordDate,
  4408. AdviceId: item.ID,
  4409. }
  4410. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4411. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4412. Creator := adminInfo.AdminUser.Id
  4413. //查询默认仓库剩余多少库存
  4414. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4415. var sum_count int64
  4416. for _, it := range list {
  4417. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4418. if it.MaxUnit == baseDrug.MaxUnit {
  4419. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4420. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4421. }
  4422. sum_count += it.StockMaxNumber + it.StockMinNumber
  4423. }
  4424. flow := &models.XtSelfDrugFlow{
  4425. WarehousingId: info.ID,
  4426. DrugId: item.DrugId,
  4427. Number: "",
  4428. BatchNumber: "",
  4429. Count: total_count - in_count,
  4430. UserOrgId: adminInfo.CurrentOrgId,
  4431. PatientId: item.PatientId,
  4432. SystemTime: time.Now().Unix(),
  4433. ConsumableType: 1,
  4434. IsSys: 1,
  4435. WarehousingOrder: warehousing_order,
  4436. WarehouseOutId: 0,
  4437. WarehouseOutOrderNumber: "",
  4438. IsEdit: 0,
  4439. CancelStockId: 0,
  4440. CancelOrderNumber: "",
  4441. Manufacturer: selfBasedrug.Manufacturer,
  4442. Dealer: selfBasedrug.Dealer,
  4443. Creator: Creator,
  4444. UpdateCreator: Creator,
  4445. Status: 1,
  4446. Ctime: item.AdviceDate,
  4447. Mtime: 0,
  4448. Price: item.Price,
  4449. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4450. WarehouseOutDetailId: 0,
  4451. CancelOutDetailId: 0,
  4452. ExpireDate: 0,
  4453. ProductDate: 0,
  4454. MaxUnit: selfBasedrug.MinUnit,
  4455. MinUnit: selfBasedrug.MinUnit,
  4456. StorehouseId: 0,
  4457. OverCount: sum_count,
  4458. OperateTime: time.Now().Unix(),
  4459. AdviceId: item.ID,
  4460. }
  4461. service.CreateSelfDrugFlow(flow, tx)
  4462. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4463. var total_count int64 // 入库总数量
  4464. var over_count int64 //剩余库存
  4465. for _, it := range drugInfolist {
  4466. if it.MaxUnit == selfBasedrug.MaxUnit {
  4467. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4468. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4469. }
  4470. }
  4471. for _, it := range drugInfolist {
  4472. total_count += it.WarehousingCount
  4473. over_count += it.StockMaxNumber + it.StockMinNumber
  4474. }
  4475. //查询该仓库是否有默认数据
  4476. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4477. if selfDrugStock.ID == 0 {
  4478. drugStock := models.XtSelfDrugStockCount{
  4479. UserOrgId: item.UserOrgId,
  4480. PatientId: item.PatientId,
  4481. SumInCount: total_count,
  4482. SumOutCount: 0,
  4483. SumCancelCount: 0,
  4484. DrugId: item.DrugId,
  4485. Ctime: time.Now().Unix(),
  4486. Mtime: 0,
  4487. Status: 1,
  4488. FlushCount: over_count,
  4489. SumActOutCount: 0,
  4490. }
  4491. service.CreateSelfDrugStockSum(drugStock, tx)
  4492. }
  4493. if selfDrugStock.ID > 0 {
  4494. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4495. }
  4496. }
  4497. //查询这个单据的出库数量
  4498. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4499. var his_out_count int64
  4500. for _, item := range drugFlowList {
  4501. his_out_count += item.Count
  4502. }
  4503. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4504. if (total_count + his_out_count) <= in_count {
  4505. // 出库
  4506. if total_count < in_count {
  4507. var cha_count int64
  4508. cha_count = in_count - total_count
  4509. var stock_number int64 = 0
  4510. //查询库存是否充足
  4511. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4512. // 将该批次的剩余库存数量转换为拆零数量
  4513. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4514. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4515. }
  4516. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4517. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4518. }
  4519. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4520. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4521. }
  4522. if stock_number >= cha_count {
  4523. var maxNumber int64 = 0
  4524. var minNumber int64 = 0
  4525. maxNumber = cha_count / selfBasedrug.MinNumber
  4526. minNumber = cha_count % selfBasedrug.MinNumber
  4527. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4528. minNumber = maxNumber
  4529. }
  4530. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4531. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4533. return
  4534. }
  4535. }
  4536. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4537. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4538. }
  4539. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4540. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4541. }
  4542. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4543. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4544. }
  4545. if warehouse.StockMaxNumber < 0 {
  4546. warehouse.StockMaxNumber = 0
  4547. }
  4548. if warehouse.StockMinNumber < 0 {
  4549. warehouse.StockMinNumber = 0
  4550. }
  4551. warehouse.Mtime = time.Now().Unix()
  4552. if warehouse.StockMinNumber < minNumber {
  4553. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4554. if warehouse.MaxUnit != warehouse.MinUnit {
  4555. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4556. }
  4557. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4558. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4559. }
  4560. } else {
  4561. if minNumber > 0 {
  4562. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4563. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4564. }
  4565. }
  4566. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4567. if warehouse.StockMinNumber > 0 {
  4568. if warehouse.StockMinNumber-cha_count >= 0 {
  4569. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4570. }
  4571. }
  4572. }
  4573. }
  4574. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4575. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4576. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4577. }
  4578. }
  4579. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4580. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4582. return
  4583. }
  4584. }
  4585. if warehouse.StockMinNumber <= 0 {
  4586. warehouse.StockMinNumber = 0
  4587. }
  4588. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4589. //查询该药品剩余库存
  4590. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4591. var over_count int64
  4592. for _, its := range infolist {
  4593. if its.MaxUnit == selfBasedrug.MaxUnit {
  4594. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4595. }
  4596. over_count += its.StockMaxNumber + its.StockMinNumber
  4597. }
  4598. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4599. drugflow := models.XtSelfDrugFlow{
  4600. WarehouseOutId: 0,
  4601. WarehouseOutOrderNumber: warehousing_order,
  4602. WarehousingOrder: warehousing_order,
  4603. DrugId: item.DrugId,
  4604. Number: warehouse.Number,
  4605. ProductDate: warehouse.ProductDate,
  4606. ExpireDate: warehouse.ExpiryDate,
  4607. Count: cha_count,
  4608. Price: warehouse.RetailPrice,
  4609. Status: 1,
  4610. Ctime: item.AdviceDate,
  4611. Mtime: time.Now().Unix(),
  4612. UserOrgId: item.UserOrgId,
  4613. Manufacturer: warehouse.Manufacturer,
  4614. Dealer: warehouse.Dealer,
  4615. BatchNumber: warehouse.BatchNumber,
  4616. MaxUnit: selfBasedrug.MinUnit,
  4617. ConsumableType: 20,
  4618. IsEdit: 1,
  4619. Creator: 0,
  4620. IsSys: 3,
  4621. WarehouseOutDetailId: drugWareInfo.ID,
  4622. AdviceId: item.ID,
  4623. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4624. StorehouseId: 0,
  4625. AdminUserId: creater,
  4626. LastPrice: warehouse.Price,
  4627. StockCount: "",
  4628. WarehousingDetailId: 0,
  4629. OverCount: over_count,
  4630. RetailPrice: item.Price, //手动出库出库价格
  4631. WarehousingId: warehouse.ID,
  4632. SystemTime: item.AdviceDate,
  4633. PatientId: item.PatientId,
  4634. Remark: "保存处方入库数据差",
  4635. OperateTime: time.Now().Unix(),
  4636. }
  4637. if warehouse.RetailPrice == 0 {
  4638. drugflow.Price = item.Price
  4639. }
  4640. service.CreateSelfDrugFlowOne(drugflow, tx)
  4641. var out_count int64
  4642. out_count = in_count - total_count
  4643. fmt.Println("in_count------------------", in_count)
  4644. fmt.Println("total_count------------------", total_count)
  4645. //添加出库数量
  4646. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4647. //查询剩余库存
  4648. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4649. var sum_count int64
  4650. for _, its := range stockInfo {
  4651. if its.MaxUnit == selfBasedrug.MaxUnit {
  4652. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4653. }
  4654. sum_count += its.StockMaxNumber + its.StockMinNumber
  4655. }
  4656. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4657. } else {
  4658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4659. return
  4660. }
  4661. }
  4662. }
  4663. }
  4664. }
  4665. }
  4666. }
  4667. tx.Commit()
  4668. if err == nil {
  4669. c.ServeSuccessJSON(map[string]interface{}{
  4670. "msg": "保存成功",
  4671. })
  4672. return
  4673. } else {
  4674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4675. return
  4676. }
  4677. }
  4678. }
  4679. //func (c *HisApiController) EditHisPrescription() {
  4680. // record_date := c.GetString("record_date")
  4681. // patient_id, _ := c.GetInt64("patient_id")
  4682. // reg_type, _ := c.GetInt64("reg_type")
  4683. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4684. // diagnose := c.GetString("diagnose")
  4685. // sick_type, _ := c.GetInt64("sick_type")
  4686. // sick_history := c.GetString("sick_history")
  4687. // doctor_id, _ := c.GetInt64("doctor", 0)
  4688. // department, _ := c.GetInt64("department", 0)
  4689. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4690. // p_type, _ := c.GetInt64("p_type")
  4691. //
  4692. // dataBody := make(map[string]interface{}, 0)
  4693. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4694. // if err != nil {
  4695. // utils.ErrorLog(err.Error())
  4696. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4697. // return
  4698. // }
  4699. //
  4700. // timeLayout := "2006-01-02"
  4701. // loc, _ := time.LoadLocation("Local")
  4702. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4703. // if err != nil {
  4704. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4705. // return
  4706. // }
  4707. // adminInfo := c.GetAdminUserInfo()
  4708. // recordDateTime := theTime.Unix()
  4709. //
  4710. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4711. //
  4712. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4713. // var hpInfo models.HisPrescriptionInfo
  4714. // if info.ID == 0 {
  4715. // var randNum int
  4716. // randNum = rand.Intn(10000) + 1000
  4717. // timestamp := time.Now().Unix()
  4718. // tempTime := time.Unix(timestamp, 0)
  4719. // timeFormat := tempTime.Format("20060102150405")
  4720. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4721. //
  4722. // hpInfo = models.HisPrescriptionInfo{
  4723. // UserOrgId: adminInfo.CurrentOrgId,
  4724. // RecordDate: theTime.Unix(),
  4725. // PatientId: patient_id,
  4726. // Status: 1,
  4727. // Ctime: time.Now().Unix(),
  4728. // Mtime: time.Now().Unix(),
  4729. // Creator: adminInfo.AdminUser.Id,
  4730. // Modifier: adminInfo.AdminUser.Id,
  4731. // Diagnosis: diagnose,
  4732. // SickHistory: sick_history,
  4733. // Departments: department,
  4734. // RegisterType: reg_type,
  4735. // PrescriptionNumber: p_number,
  4736. // PrescriptionStatus: 1,
  4737. // Doctor: role.UserName,
  4738. // DoctorId: doctor_id,
  4739. // SickType: sick_type,
  4740. // PType: p_type,
  4741. // }
  4742. // service.SavePatientPrescriptionInfo(hpInfo)
  4743. //
  4744. // } else {
  4745. // hpInfo = models.HisPrescriptionInfo{
  4746. // ID: info.ID,
  4747. // UserOrgId: adminInfo.CurrentOrgId,
  4748. // RecordDate: info.RecordDate,
  4749. // PatientId: info.PatientId,
  4750. // Status: 1,
  4751. // Ctime: info.Ctime,
  4752. // Mtime: time.Now().Unix(),
  4753. // Creator: info.Creator,
  4754. // Modifier: adminInfo.AdminUser.Id,
  4755. // Diagnosis: diagnose,
  4756. // SickHistory: sick_history,
  4757. // Departments: department,
  4758. // RegisterType: reg_type,
  4759. // PrescriptionNumber: info.PrescriptionNumber,
  4760. // Doctor: role.UserName,
  4761. // PrescriptionStatus: info.PrescriptionStatus,
  4762. // DoctorId: doctor_id,
  4763. // SickType: sick_type,
  4764. // PType: info.PType,
  4765. // }
  4766. // service.SavePatientPrescriptionInfo(hpInfo)
  4767. // }
  4768. //
  4769. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4770. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4771. //
  4772. // if len(prescriptions) > 0 {
  4773. // for _, item := range prescriptions {
  4774. // items := item.(map[string]interface{})
  4775. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4776. // utils.ErrorLog("id")
  4777. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4778. // return
  4779. // }
  4780. // id := int64(items["id"].(float64))
  4781. //
  4782. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4783. // utils.ErrorLog("type")
  4784. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4785. // return
  4786. // }
  4787. // types := int64(items["type"].(float64))
  4788. //
  4789. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4790. // utils.ErrorLog("med_type")
  4791. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4792. // return
  4793. // }
  4794. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4795. //
  4796. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4797. //
  4798. // ctime := time.Now().Unix()
  4799. //
  4800. // prescription := &models.HisPrescription{
  4801. // ID: id,
  4802. // PatientId: patient_id,
  4803. // UserOrgId: adminInfo.CurrentOrgId,
  4804. // RecordDate: recordDateTime,
  4805. // Ctime: ctime,
  4806. // Mtime: ctime,
  4807. // Type: types,
  4808. // Modifier: adminInfo.AdminUser.Id,
  4809. // Creator: adminInfo.AdminUser.Id,
  4810. // Status: 1,
  4811. // Doctor: role.UserName,
  4812. // HisPatientId: his_patient_id,
  4813. // OrderStatus: 1,
  4814. // BatchNumber: "",
  4815. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4816. // PType: hpInfo.PType,
  4817. // MedType: med_type,
  4818. // }
  4819. //
  4820. // if historyPrescription.ID > 0 {
  4821. // prescription.PreTime = historyPrescription.PreTime
  4822. //
  4823. // }
  4824. //
  4825. // service.SaveHisPrescription(prescription)
  4826. //
  4827. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4828. // advices := items["advices"].([]interface{})
  4829. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4830. // groupNo := int64(0)
  4831. // ctime := time.Now().Unix()
  4832. // mtime := ctime
  4833. // if len(advices) > 0 {
  4834. // for _, advice := range advices {
  4835. // var s models.HisDoctorAdviceInfo
  4836. // s.PrescriptionId = prescription.ID
  4837. // s.AdviceType = 2
  4838. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4839. // s.StopState = 2
  4840. // s.ExecutionState = 2
  4841. // s.AdviceDate = recordDateTime
  4842. // s.Status = 1
  4843. // s.UserOrgId = adminInfo.CurrentOrgId
  4844. // s.RecordDate = recordDateTime
  4845. // s.StartTime = prescription.PreTime
  4846. // s.Groupno = groupNo
  4847. // s.CreatedTime = ctime
  4848. // s.UpdatedTime = mtime
  4849. // s.PatientId = patient_id
  4850. // s.HisPatientId = his_patient_id
  4851. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4852. // if errcode > 0 {
  4853. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4854. // return
  4855. // }
  4856. //
  4857. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4858. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4859. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4860. // if s.Price == 0 {
  4861. // s.Price = lastWarehouse.RetailPrice
  4862. // }
  4863. // }
  4864. //
  4865. // service.CreateHisDoctorAdvice(&s)
  4866. // //记录日志
  4867. // byterequest, _ := json.Marshal(s)
  4868. // adviceLog := models.XtDoctorAdviceLog{
  4869. // UserOrgId: s.UserOrgId,
  4870. // PatientId: s.PatientId,
  4871. // AdminUserId: adminInfo.AdminUser.Id,
  4872. // Module: 1,
  4873. // ErrLog: string(byterequest),
  4874. // Status: 1,
  4875. // Ctime: time.Now().Unix(),
  4876. // Mtime: 0,
  4877. // Source: "电脑端his医嘱修改",
  4878. // RecordDate: s.AdviceDate,
  4879. // }
  4880. // service.CreateDoctorAdviceLog(adviceLog)
  4881. // redis := service.RedisClient()
  4882. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4883. // redis.Set(key, "", time.Second)
  4884. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4885. // fmt.Println("keyOne", keyOne)
  4886. // redis.Set(keyOne, "", time.Second)
  4887. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4888. // redis.Set(keySeven, "", time.Second)
  4889. // redis.Close()
  4890. //
  4891. // }
  4892. // }
  4893. // }
  4894. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4895. // projects := items["project"].([]interface{})
  4896. // if len(projects) > 0 {
  4897. // for _, project := range projects {
  4898. // var p models.HisPrescriptionProject
  4899. // p.PrescriptionId = prescription.ID
  4900. // p.Ctime = time.Now().Unix()
  4901. // p.Mtime = time.Now().Unix()
  4902. // p.PatientId = patient_id
  4903. // p.RecordDate = recordDateTime
  4904. // p.UserOrgId = adminInfo.CurrentOrgId
  4905. // p.HisPatientId = his_patient_id
  4906. // p.Status = 1
  4907. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4908. // if errcode > 0 {
  4909. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4910. // return
  4911. // }
  4912. // service.CreateHisProjectTwo(&p)
  4913. //
  4914. // //记录日志
  4915. // byterequest, _ := json.Marshal(p)
  4916. // adviceLog := models.XtDoctorAdviceLog{
  4917. // UserOrgId: p.UserOrgId,
  4918. // PatientId: p.PatientId,
  4919. // AdminUserId: adminInfo.AdminUser.Id,
  4920. // Module: 1,
  4921. // ErrLog: string(byterequest),
  4922. // Status: 1,
  4923. // Ctime: time.Now().Unix(),
  4924. // Mtime: 0,
  4925. // Source: "电脑端his项目修改",
  4926. // RecordDate: p.RecordDate,
  4927. // }
  4928. // service.CreateDoctorAdviceLog(adviceLog)
  4929. // }
  4930. // }
  4931. // }
  4932. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4933. // addition := items["addition"].([]interface{})
  4934. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4935. // ctime := time.Now().Unix()
  4936. // mtime := ctime
  4937. // if len(addition) > 0 {
  4938. // for _, item := range addition {
  4939. // var s models.HisAdditionalCharge
  4940. // s.PrescriptionId = prescription.ID
  4941. // s.Status = 1
  4942. // s.UserOrgId = adminInfo.CurrentOrgId
  4943. // s.RecordDate = recordDateTime
  4944. // s.CreatedTime = ctime
  4945. // s.UpdatedTime = mtime
  4946. // s.PatientId = patient_id
  4947. // s.HisPatientId = his_patient_id
  4948. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4949. // if errcode > 0 {
  4950. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4951. // return
  4952. // }
  4953. // service.CreateAdditionalCharge(&s)
  4954. // }
  4955. // }
  4956. // }
  4957. //
  4958. // }
  4959. // }
  4960. // }
  4961. // if err == nil {
  4962. // c.ServeSuccessJSON(map[string]interface{}{
  4963. // "msg": "保存成功",
  4964. // })
  4965. // return
  4966. //
  4967. // } else {
  4968. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4969. // return
  4970. // }
  4971. //}
  4972. func (c *HisApiController) DeletePrescription() {
  4973. prescription_id, _ := c.GetInt64("id")
  4974. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4975. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4976. ////同步到自备药
  4977. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  4978. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  4979. if selfPrescriptionOpen.IsOpen == 1 {
  4980. // 在函数结束时处理事务回滚
  4981. db := service.XTWriteDB()
  4982. tx := db.Begin()
  4983. defer func() {
  4984. if r := recover(); r != nil {
  4985. tx.Rollback()
  4986. } else {
  4987. tx.Commit()
  4988. }
  4989. }()
  4990. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  4991. for _, item := range advicesList {
  4992. timeStr := time.Now().Format("2006-01-02")
  4993. timeArr := strings.Split(timeStr, "-")
  4994. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  4995. total = total + 1
  4996. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4997. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4998. number = number + total
  4999. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5000. operation_time := time.Now().Unix()
  5001. creater := c.GetAdminUserInfo().AdminUser.Id
  5002. //创建一个出库单
  5003. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5004. WarehouseOutOrderNumber: warehousing_out_order,
  5005. OperationTime: operation_time,
  5006. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5007. Creater: creater,
  5008. Ctime: time.Now().Unix(),
  5009. Status: 1,
  5010. WarehouseOutTime: item.AdviceDate,
  5011. Type: 0,
  5012. PatientId: item.PatientId,
  5013. IsCheck: 1,
  5014. }
  5015. //查询今日是否有出库数据
  5016. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5017. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5018. if lastWarehouseOut.ID == 0 {
  5019. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5020. }
  5021. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5022. var total_count int64
  5023. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5024. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5025. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5026. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5027. }
  5028. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5029. total_count += prescribingNumberSeven
  5030. }
  5031. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5032. total_count += prescribingNumberSeven
  5033. }
  5034. //出库
  5035. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5036. WarehouseOutOrderNumber: warehousing_out_order,
  5037. WarehouseOutId: lastWarehouseOut.ID,
  5038. DrugId: item.DrugId,
  5039. Count: total_count,
  5040. Price: 0,
  5041. TotalPrice: 0,
  5042. Status: 1,
  5043. Ctime: item.AdviceDate,
  5044. Mtime: item.AdviceDate,
  5045. Remark: "",
  5046. OrgId: item.UserOrgId,
  5047. Type: 0,
  5048. Manufacturer: selfBasedrug.Manufacturer,
  5049. Dealer: selfBasedrug.Dealer,
  5050. RetailPrice: 0,
  5051. RetailTotalPrice: 0,
  5052. CountUnit: selfBasedrug.MinUnit,
  5053. ExpiryDate: 0,
  5054. ProductDate: 0,
  5055. Number: "",
  5056. BatchNumber: "",
  5057. IsSys: 1,
  5058. WarehouseInfoId: 0,
  5059. AdminUserId: 0,
  5060. StockCount: "",
  5061. IsCheck: 1,
  5062. SysRecordTime: item.AdviceDate,
  5063. PatientId: item.PatientId,
  5064. ClassType: "",
  5065. AdviceId: item.ID,
  5066. }
  5067. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5068. }
  5069. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5070. for _, it := range warehousingOutInfo {
  5071. //查询今日是否有出库数据
  5072. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5073. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5074. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5075. //出库逻辑
  5076. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5077. //查询剩余库存
  5078. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5079. var sum_count int64
  5080. for _, its := range stockInfo {
  5081. if its.MaxUnit == medical.MaxUnit {
  5082. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5083. }
  5084. sum_count += its.StockMaxNumber + its.StockMinNumber
  5085. }
  5086. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5087. }
  5088. }
  5089. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5090. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5091. //耗材保存处方出库
  5092. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5093. //已收费和已发药限制逻辑
  5094. isCharge := false
  5095. isMedicine := false
  5096. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5097. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5098. if new_prescription.IsMedicine == 1 {
  5099. isMedicine = true
  5100. }
  5101. for _, item := range new_prescriptions {
  5102. if item.OrderStatus == 4 {
  5103. isCharge = true
  5104. }
  5105. }
  5106. if p_err != nil {
  5107. if new_prescription.ID > 0 {
  5108. if new_prescription.OrderStatus == 2 {
  5109. isCharge = true
  5110. }
  5111. }
  5112. }
  5113. for _, item := range advices {
  5114. if item.IsMedicine == 1 {
  5115. isMedicine = true
  5116. }
  5117. }
  5118. if isCharge {
  5119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5120. return
  5121. }
  5122. if isMedicine {
  5123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5124. return
  5125. }
  5126. //已收费和已发药限制逻辑
  5127. if len(projects) > 0 {
  5128. for _, item := range projects {
  5129. service.DeletePrintInfo(item.ID) //删除打印信息
  5130. if goodOutConfig.IsOpen != 1 {
  5131. if stockConfig.IsOpen == 1 {
  5132. if item.Type == 3 && item.IsOut == 1 {
  5133. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5134. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5135. good.Total = good.Total + f_count
  5136. service.UpdateGoodInfo(&good)
  5137. operation_time := time.Now().Unix()
  5138. creater := c.GetAdminUserInfo().AdminUser.Id
  5139. //创建退库单
  5140. timeStr := time.Now().Format("2006-01-02")
  5141. timeArr := strings.Split(timeStr, "-")
  5142. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5143. total = total + 1
  5144. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5145. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5146. cancelStock := models.CancelStock{
  5147. OrderNumber: orderNumber,
  5148. OperaTime: operation_time,
  5149. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5150. Creater: creater,
  5151. Ctime: time.Now().Unix(),
  5152. Status: 1,
  5153. ReturnTime: item.RecordDate,
  5154. Type: 1,
  5155. StorehouseId: houseConfig.StorehouseOutInfo,
  5156. IsCheck: 1,
  5157. }
  5158. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5159. if msgerrkonde == gorm.ErrRecordNotFound {
  5160. service.AddSigleCancelStock(&cancelStock)
  5161. }
  5162. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5163. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5164. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5165. //查询该耗材是否出库
  5166. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5167. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5168. deaerler, _ := service.GetDealerById(info.Dealer)
  5169. var total_count int64
  5170. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5171. total_count += count
  5172. if info.ID > 0 {
  5173. if info.Count >= total_count {
  5174. //回退库存
  5175. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5176. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5177. var flush_count int64
  5178. for _, it := range goodList {
  5179. flush_count += it.StockCount
  5180. }
  5181. cancelStockInfo := models.CancelStockInfo{
  5182. GoodId: item.ProjectId,
  5183. CancelStockId: cancel.ID,
  5184. GoodTypeId: good.GoodTypeId,
  5185. Count: prescribingNumber,
  5186. Price: info.Price,
  5187. Total: 0,
  5188. ProductDate: info.ProductDate,
  5189. ExpiryDate: info.ExpiryDate,
  5190. Ctime: time.Now().Unix(),
  5191. Status: 1,
  5192. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5193. OrderNumber: cancel.OrderNumber,
  5194. Type: 0,
  5195. Dealer: deaerler.DealerName,
  5196. Manufacturer: manufacturer.ManufacturerName,
  5197. Number: info.Number,
  5198. RegisterAccount: "",
  5199. Remark: "",
  5200. WarehouseInfoId: info.WarehouseInfotId,
  5201. PatientId: info.PatientId,
  5202. RecordDate: info.SysRecordTime,
  5203. StorehouseId: houseConfig.StorehouseOutInfo,
  5204. IsCheck: 1,
  5205. }
  5206. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5207. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5208. flow := models.VmStockFlow{
  5209. WarehousingId: info.WarehouseInfotId,
  5210. GoodId: item.ProjectId,
  5211. Number: info.Number,
  5212. LicenseNumber: info.LicenseNumber,
  5213. Count: prescribingNumber,
  5214. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5215. PatientId: item.PatientId,
  5216. SystemTime: info.SysRecordTime,
  5217. ConsumableType: 7,
  5218. IsSys: 0,
  5219. WarehousingOrder: "",
  5220. WarehouseOutId: info.WarehouseOutId,
  5221. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5222. IsEdit: 0,
  5223. CancelStockId: cancel.ID,
  5224. CancelOrderNumber: cancel.OrderNumber,
  5225. Manufacturer: manufacturer.ID,
  5226. Dealer: 0,
  5227. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5228. UpdateCreator: 0,
  5229. Status: 1,
  5230. Ctime: time.Now().Unix(),
  5231. Mtime: 0,
  5232. Price: info.Price,
  5233. WarehousingDetailId: info.WarehouseInfotId,
  5234. WarehouseOutDetailId: info.ID,
  5235. CancelOutDetailId: cancelInfo.ID,
  5236. ProductDate: info.ProductDate,
  5237. ExpireDate: info.ExpiryDate,
  5238. StorehouseId: houseConfig.StorehouseOutInfo,
  5239. OverCount: flush_count,
  5240. OperateTime: time.Now().Unix(),
  5241. }
  5242. service.CreateStockFlowOne(flow)
  5243. //退库数量增加
  5244. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5245. //出库数量减少
  5246. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5247. }
  5248. if info.Count < total_count {
  5249. //回退库存
  5250. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5251. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5252. var flush_count int64
  5253. for _, it := range goodList {
  5254. flush_count += it.StockCount
  5255. }
  5256. cancelStockInfo := models.CancelStockInfo{
  5257. GoodId: item.ProjectId,
  5258. CancelStockId: cancel.ID,
  5259. GoodTypeId: good.GoodTypeId,
  5260. Count: info.Count,
  5261. Price: info.Price,
  5262. Total: 0,
  5263. ProductDate: info.ProductDate,
  5264. ExpiryDate: info.ExpiryDate,
  5265. Ctime: time.Now().Unix(),
  5266. Status: 1,
  5267. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5268. OrderNumber: cancel.OrderNumber,
  5269. Type: 0,
  5270. Dealer: deaerler.DealerName,
  5271. Manufacturer: manufacturer.ManufacturerName,
  5272. Number: info.Number,
  5273. RegisterAccount: "",
  5274. Remark: "",
  5275. WarehouseInfoId: info.WarehouseInfotId,
  5276. PatientId: info.PatientId,
  5277. RecordDate: info.SysRecordTime,
  5278. StorehouseId: houseConfig.StorehouseOutInfo,
  5279. IsCheck: 1,
  5280. }
  5281. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5282. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5283. flow := models.VmStockFlow{
  5284. WarehousingId: info.WarehouseInfotId,
  5285. GoodId: item.ProjectId,
  5286. Number: info.Number,
  5287. LicenseNumber: info.LicenseNumber,
  5288. Count: info.Count,
  5289. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5290. PatientId: item.PatientId,
  5291. SystemTime: info.SysRecordTime,
  5292. ConsumableType: 7,
  5293. IsSys: 0,
  5294. WarehousingOrder: "",
  5295. WarehouseOutId: info.WarehouseOutId,
  5296. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5297. IsEdit: 0,
  5298. CancelStockId: cancel.ID,
  5299. CancelOrderNumber: cancel.OrderNumber,
  5300. Manufacturer: manufacturer.ID,
  5301. Dealer: 0,
  5302. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5303. UpdateCreator: 0,
  5304. Status: 1,
  5305. Ctime: time.Now().Unix(),
  5306. Mtime: 0,
  5307. Price: info.Price,
  5308. WarehousingDetailId: info.WarehouseInfotId,
  5309. WarehouseOutDetailId: info.ID,
  5310. CancelOutDetailId: cancelInfo.ID,
  5311. ProductDate: info.ProductDate,
  5312. ExpireDate: info.ExpiryDate,
  5313. StorehouseId: houseConfig.StorehouseOutInfo,
  5314. OverCount: flush_count,
  5315. OperateTime: time.Now().Unix(),
  5316. }
  5317. service.CreateStockFlowOne(flow)
  5318. //退库数量增加
  5319. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5320. //出库数量减少
  5321. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5322. }
  5323. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5324. var flush_count int64
  5325. for _, it := range goodList {
  5326. flush_count += it.StockCount
  5327. }
  5328. //查询已出库数量
  5329. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5330. if prescribingNumber < dialysisInfo.Count {
  5331. //改变数量
  5332. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5333. }
  5334. if prescribingNumber >= dialysisInfo.Count {
  5335. //删除出库表
  5336. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5337. }
  5338. //更新库存
  5339. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5340. //更新基础库库存
  5341. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5342. }
  5343. }
  5344. }
  5345. }
  5346. //保存耗材出库
  5347. if goodOutConfig.IsOpen == 1 {
  5348. if item.Type == 3 {
  5349. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5350. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5351. good.Total = good.Total + f_count
  5352. service.UpdateGoodInfo(&good)
  5353. operation_time := time.Now().Unix()
  5354. creater := c.GetAdminUserInfo().AdminUser.Id
  5355. //创建退库单
  5356. timeStr := time.Now().Format("2006-01-02")
  5357. timeArr := strings.Split(timeStr, "-")
  5358. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5359. total = total + 1
  5360. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5361. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5362. cancelStock := models.CancelStock{
  5363. OrderNumber: orderNumber,
  5364. OperaTime: operation_time,
  5365. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5366. Creater: creater,
  5367. Ctime: time.Now().Unix(),
  5368. Status: 1,
  5369. ReturnTime: item.RecordDate,
  5370. Type: 1,
  5371. StorehouseId: houseConfig.StorehouseOutInfo,
  5372. IsCheck: 1,
  5373. }
  5374. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5375. if msgerrkonde == gorm.ErrRecordNotFound {
  5376. service.AddSigleCancelStock(&cancelStock)
  5377. }
  5378. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5379. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5380. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5381. //查询该耗材是否出库
  5382. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5383. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5384. deaerler, _ := service.GetDealerById(info.Dealer)
  5385. var total_count int64
  5386. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5387. total_count += count
  5388. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5389. var flush_count int64
  5390. for _, it := range goodList {
  5391. flush_count += it.StockCount
  5392. }
  5393. fmt.Println("历史出库数据", info.Count)
  5394. fmt.Println("出库数量", total_count)
  5395. if info.ID > 0 {
  5396. cancelStockInfo := models.CancelStockInfo{
  5397. GoodId: item.ProjectId,
  5398. CancelStockId: cancel.ID,
  5399. GoodTypeId: good.GoodTypeId,
  5400. Count: prescribingNumber,
  5401. Price: info.Price,
  5402. Total: 0,
  5403. ProductDate: info.ProductDate,
  5404. ExpiryDate: info.ExpiryDate,
  5405. Ctime: time.Now().Unix(),
  5406. Status: 1,
  5407. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5408. OrderNumber: cancel.OrderNumber,
  5409. Type: 0,
  5410. Dealer: deaerler.DealerName,
  5411. Manufacturer: manufacturer.ManufacturerName,
  5412. Number: info.Number,
  5413. RegisterAccount: "",
  5414. Remark: "",
  5415. WarehouseInfoId: info.WarehouseInfotId,
  5416. PatientId: info.PatientId,
  5417. RecordDate: info.SysRecordTime,
  5418. StorehouseId: houseConfig.StorehouseOutInfo,
  5419. IsCheck: 1,
  5420. }
  5421. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5422. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5423. //查询出库数量
  5424. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5425. //出库数据 大于 退库数量
  5426. if len(list) > 0 {
  5427. for _, it := range list {
  5428. //回退库存
  5429. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5430. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5431. var flush_count_one int64
  5432. for _, it := range goodList {
  5433. flush_count_one += it.StockCount
  5434. }
  5435. //查询该批次是否有退库数据
  5436. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5437. creater := c.GetAdminUserInfo().AdminUser.Id
  5438. flow := models.VmStockFlow{
  5439. WarehousingId: it.WarehouseInfotId,
  5440. GoodId: it.GoodId,
  5441. Number: it.Number,
  5442. LicenseNumber: it.LicenseNumber,
  5443. Count: it.Count,
  5444. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5445. PatientId: it.PatientId,
  5446. SystemTime: it.SysRecordTime,
  5447. ConsumableType: 7,
  5448. IsSys: 0,
  5449. WarehousingOrder: "",
  5450. WarehouseOutId: it.WarehouseOutId,
  5451. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5452. IsEdit: 0,
  5453. CancelStockId: cancel.ID,
  5454. CancelOrderNumber: cancel.OrderNumber,
  5455. Manufacturer: manufacturer.ID,
  5456. Dealer: 0,
  5457. Creator: creater,
  5458. UpdateCreator: 0,
  5459. Status: 1,
  5460. Ctime: time.Now().Unix(),
  5461. Mtime: 0,
  5462. Price: it.Price,
  5463. WarehousingDetailId: it.WarehouseInfotId,
  5464. WarehouseOutDetailId: it.ID,
  5465. CancelOutDetailId: cancelInfo.ID,
  5466. ProductDate: it.ProductDate,
  5467. ExpireDate: it.ExpiryDate,
  5468. StorehouseId: houseConfig.StorehouseOutInfo,
  5469. OverCount: flush_count_one,
  5470. }
  5471. service.CreateStockFlowOne(flow)
  5472. //if flow.ID > 0 {
  5473. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5474. //}
  5475. }
  5476. }
  5477. //flow := models.VmStockFlow{
  5478. // WarehousingId: info.WarehouseInfotId,
  5479. // GoodId: item.ProjectId,
  5480. // Number: info.Number,
  5481. // LicenseNumber: info.LicenseNumber,
  5482. // Count: prescribingNumber,
  5483. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5484. // PatientId: item.PatientId,
  5485. // SystemTime: info.SysRecordTime,
  5486. // ConsumableType: 7,
  5487. // IsSys: 0,
  5488. // WarehousingOrder: "",
  5489. // WarehouseOutId: info.WarehouseOutId,
  5490. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5491. // IsEdit: 0,
  5492. // CancelStockId: cancel.ID,
  5493. // CancelOrderNumber: cancel.OrderNumber,
  5494. // Manufacturer: manufacturer.ID,
  5495. // Dealer: 0,
  5496. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5497. // UpdateCreator: 0,
  5498. // Status: 1,
  5499. // Ctime: time.Now().Unix(),
  5500. // Mtime: 0,
  5501. // Price: info.Price,
  5502. // WarehousingDetailId: info.WarehouseInfotId,
  5503. // WarehouseOutDetailId: info.ID,
  5504. // CancelOutDetailId: cancelInfo.ID,
  5505. // ProductDate: info.ProductDate,
  5506. // ExpireDate: info.ExpiryDate,
  5507. // StorehouseId: houseConfig.StorehouseOutInfo,
  5508. // OverCount: flush_count,
  5509. //}
  5510. //service.CreateStockFlowOne(flow)
  5511. //退库数量增加
  5512. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5513. //出库数量减少
  5514. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5515. //查询已出库数量
  5516. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5517. if prescribingNumber < dialysisInfo.Count {
  5518. //改变数量
  5519. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5520. }
  5521. if prescribingNumber >= dialysisInfo.Count {
  5522. //删除出库表
  5523. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5524. }
  5525. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5526. var flush_count_one int64
  5527. for _, it := range goodList {
  5528. flush_count_one += it.StockCount
  5529. }
  5530. //更新库存
  5531. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5532. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5533. //更新基础库库存
  5534. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5535. }
  5536. }
  5537. }
  5538. }
  5539. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5540. fmt.Println(err)
  5541. }
  5542. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5543. fmt.Println(err)
  5544. if len(advices) > 0 {
  5545. for _, item := range advices {
  5546. redis := service.RedisClient()
  5547. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5548. redis.Set(keyFive, "", time.Second)
  5549. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5550. redis.Set(keyOne, "", time.Second)
  5551. redis.Close()
  5552. }
  5553. }
  5554. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5555. if len(advices) > 0 {
  5556. for _, item := range advices {
  5557. creater := c.GetAdminUserInfo().AdminUser.Id
  5558. service.DrugAutoAddCancelInfo(item, creater)
  5559. }
  5560. }
  5561. } else {
  5562. if drugOutConfig.IsOpen == 1 {
  5563. if len(advices) > 0 {
  5564. for _, item := range advices {
  5565. creater := c.GetAdminUserInfo().AdminUser.Id
  5566. service.DrugAutoAddCancelInfo(item, creater)
  5567. }
  5568. }
  5569. } else {
  5570. if len(advices) > 0 {
  5571. for _, item := range advices {
  5572. creater := c.GetAdminUserInfo().AdminUser.Id
  5573. service.DrugAutoAddCancelInfo(item, creater)
  5574. }
  5575. }
  5576. }
  5577. }
  5578. c.ServeSuccessJSON(map[string]interface{}{
  5579. "msg": "删除成功",
  5580. })
  5581. return
  5582. }
  5583. func (c *HisApiController) DeleteDoctorAdvice() {
  5584. id, _ := c.GetInt64("id")
  5585. advice, _ := service.GetHisDoctorAdvicesById(id)
  5586. ////同步到自备药
  5587. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5588. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5589. if selfPrescriptionOpen.IsOpen == 1 {
  5590. db := service.XTWriteDB()
  5591. tx := db.Begin()
  5592. defer func() {
  5593. if r := recover(); r != nil {
  5594. tx.Rollback()
  5595. } else {
  5596. tx.Commit()
  5597. }
  5598. }()
  5599. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5600. var total_count int64
  5601. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5602. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5603. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5604. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5605. }
  5606. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5607. total_count += prescribingNumberSeven
  5608. }
  5609. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5610. total_count += prescribingNumberSeven
  5611. }
  5612. timeStr := time.Now().Format("2006-01-02")
  5613. timeArr := strings.Split(timeStr, "-")
  5614. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5615. total = total + 1
  5616. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5617. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5618. number = number + total
  5619. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5620. operation_time := time.Now().Unix()
  5621. creater := c.GetAdminUserInfo().AdminUser.Id
  5622. //创建一个出库单
  5623. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5624. WarehouseOutOrderNumber: warehousing_out_order,
  5625. OperationTime: operation_time,
  5626. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5627. Creater: creater,
  5628. Ctime: time.Now().Unix(),
  5629. Status: 1,
  5630. WarehouseOutTime: advice.AdviceDate,
  5631. Type: 0,
  5632. PatientId: advice.PatientId,
  5633. IsCheck: 1,
  5634. }
  5635. //查询今日是否有出库数据
  5636. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5637. if lastWarehouseOut.ID == 0 {
  5638. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5639. }
  5640. //出库
  5641. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5642. WarehouseOutId: lastWarehouseOut.ID,
  5643. WarehouseOutOrderNumber: warehousing_out_order,
  5644. DrugId: advice.DrugId,
  5645. Count: total_count,
  5646. Price: 0,
  5647. TotalPrice: 0,
  5648. Status: 1,
  5649. Ctime: advice.AdviceDate,
  5650. Mtime: advice.AdviceDate,
  5651. Remark: "",
  5652. OrgId: advice.UserOrgId,
  5653. Type: 0,
  5654. Manufacturer: selfBasedrug.Manufacturer,
  5655. Dealer: selfBasedrug.Dealer,
  5656. RetailPrice: 0,
  5657. RetailTotalPrice: 0,
  5658. CountUnit: advice.PrescribingNumberUnit,
  5659. ExpiryDate: 0,
  5660. ProductDate: 0,
  5661. Number: "",
  5662. BatchNumber: "",
  5663. IsSys: 0,
  5664. WarehouseInfoId: 0,
  5665. AdminUserId: 0,
  5666. StockCount: "",
  5667. IsCheck: 1,
  5668. SysRecordTime: advice.AdviceDate,
  5669. PatientId: advice.PatientId,
  5670. AdviceId: advice.ID,
  5671. ClassType: "",
  5672. }
  5673. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5674. for _, it := range warehousingOutInfo {
  5675. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5676. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5677. //出库逻辑
  5678. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5679. //查询剩余库存
  5680. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5681. var sum_count int64
  5682. for _, its := range stockInfo {
  5683. if its.MaxUnit == medical.MaxUnit {
  5684. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5685. }
  5686. sum_count += its.StockMaxNumber + its.StockMinNumber
  5687. }
  5688. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5689. }
  5690. }
  5691. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5692. //已收费和已发药的限制逻辑
  5693. isCharge := false
  5694. isMedicine := false
  5695. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5696. //获取今天该患者所有处方,判断是否发药或者收费
  5697. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5698. //for _, item := range new_prescriptions {
  5699. if new_prescription.IsMedicine == 1 {
  5700. isMedicine = true
  5701. }
  5702. //}
  5703. for _, item := range new_prescriptions {
  5704. if item.OrderStatus == 4 {
  5705. isCharge = true
  5706. }
  5707. }
  5708. if isMedicine {
  5709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5710. return
  5711. }
  5712. if isCharge {
  5713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5714. return
  5715. }
  5716. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5717. for _, item := range advices {
  5718. if item.IsMedicine == 1 {
  5719. isMedicine = true
  5720. }
  5721. }
  5722. if isMedicine {
  5723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5724. return
  5725. }
  5726. if new_prescription.ID > 0 {
  5727. if new_prescription.OrderStatus == 2 {
  5728. isCharge = true
  5729. }
  5730. }
  5731. if isCharge {
  5732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5733. return
  5734. }
  5735. //已收费和已发药的限制逻辑
  5736. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5737. redis := service.RedisClient()
  5738. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5739. redis.Set(keyFive, "", time.Second)
  5740. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5741. redis.Set(keyOne, "", time.Second)
  5742. defer redis.Close()
  5743. if err == nil {
  5744. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5745. //查询是否在处方中出库
  5746. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5747. if openConfig.IsOpen != 1 {
  5748. //判断该医嘱是否执行了
  5749. if advice.ExecutionState == 1 {
  5750. creater := c.GetAdminUserInfo().AdminUser.Id
  5751. service.DrugAutoAddCancelInfo(&advice, creater)
  5752. }
  5753. }
  5754. //开启保存处方扣减功能
  5755. if openConfig.IsOpen == 1 {
  5756. creater := c.GetAdminUserInfo().AdminUser.Id
  5757. service.DrugAutoAddCancelInfo(&advice, creater)
  5758. }
  5759. } else {
  5760. if drugOutConfig.IsOpen == 1 {
  5761. //查询是否在处方中出库
  5762. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5763. if openConfig.IsOpen != 1 {
  5764. //判断该医嘱是否执行了
  5765. if advice.ExecutionState == 1 {
  5766. creater := c.GetAdminUserInfo().AdminUser.Id
  5767. service.DrugAutoAddCancelInfo(&advice, creater)
  5768. }
  5769. }
  5770. //开启保存处方扣减功能
  5771. if openConfig.IsOpen == 1 {
  5772. creater := c.GetAdminUserInfo().AdminUser.Id
  5773. service.DrugAutoAddCancelInfo(&advice, creater)
  5774. }
  5775. } else {
  5776. //判断该医嘱是否执行了
  5777. if advice.ExecutionState == 1 {
  5778. creater := c.GetAdminUserInfo().AdminUser.Id
  5779. service.DrugAutoAddCancelInfo(&advice, creater)
  5780. }
  5781. }
  5782. }
  5783. c.ServeSuccessJSON(map[string]interface{}{
  5784. "msg": "删除成功",
  5785. })
  5786. return
  5787. } else {
  5788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5789. return
  5790. }
  5791. }
  5792. func (c *HisApiController) DeleteProject() {
  5793. id, _ := c.GetInt64("id")
  5794. adminInfo := c.GetAdminUserInfo()
  5795. project, _ := service.GetHisProjectByID(id)
  5796. // var consumable models.DialysisBeforePrepare
  5797. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5798. //耗材保存处方出库
  5799. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5800. isCharge := false
  5801. isMedicine := false
  5802. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5803. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5804. for _, item := range new_prescriptions {
  5805. if item.IsMedicine == 1 {
  5806. isMedicine = true
  5807. }
  5808. }
  5809. for _, item := range new_prescriptions {
  5810. if item.OrderStatus == 4 {
  5811. isCharge = true
  5812. }
  5813. }
  5814. if isMedicine {
  5815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5816. return
  5817. }
  5818. if isCharge {
  5819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5820. return
  5821. }
  5822. if new_prescription.ID > 0 {
  5823. if new_prescription.OrderStatus == 2 {
  5824. isCharge = true
  5825. }
  5826. }
  5827. if isCharge {
  5828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5829. return
  5830. }
  5831. service.DeletePrintInfo(id)
  5832. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5833. label.Status = 0
  5834. service.CreateHisLabelRecordTwo(&label)
  5835. fmt.Println(goodOutConfig.IsOpen)
  5836. if goodOutConfig.IsOpen != 1 {
  5837. if stockConfig.IsOpen == 1 {
  5838. if project.Type == 2 {
  5839. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5840. fmt.Println(err)
  5841. }
  5842. if project.Type == 3 && project.IsOut == 1 {
  5843. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5844. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5845. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5846. operation_time := time.Now().Unix()
  5847. creater := adminInfo.AdminUser.Id
  5848. //创建退库单
  5849. timeStr := time.Now().Format("2006-01-02")
  5850. timeArr := strings.Split(timeStr, "-")
  5851. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5852. total = total + 1
  5853. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5854. cancelStock := models.CancelStock{
  5855. OrderNumber: orderNumber,
  5856. OperaTime: operation_time,
  5857. OrgId: adminInfo.CurrentOrgId,
  5858. Creater: creater,
  5859. Ctime: time.Now().Unix(),
  5860. Status: 1,
  5861. ReturnTime: project.RecordDate,
  5862. Type: 1,
  5863. StorehouseId: houseConfig.StorehouseOutInfo,
  5864. IsCheck: 1,
  5865. }
  5866. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5867. if msgerrkonde == gorm.ErrRecordNotFound {
  5868. service.AddSigleCancelStock(&cancelStock)
  5869. }
  5870. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5871. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5872. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5873. //查询是否有出库
  5874. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5875. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5876. deaerler, _ := service.GetDealerById(info.Dealer)
  5877. if info.ID > 0 {
  5878. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5879. if info.Count >= prescribingNumber {
  5880. cancelStockInfo := models.CancelStockInfo{
  5881. GoodId: project.ProjectId,
  5882. CancelStockId: cancel.ID,
  5883. GoodTypeId: good.GoodTypeId,
  5884. Count: prescribingNumber,
  5885. Price: info.Price,
  5886. Total: 0,
  5887. ProductDate: info.ProductDate,
  5888. ExpiryDate: info.ExpiryDate,
  5889. Ctime: time.Now().Unix(),
  5890. Status: 1,
  5891. OrgId: adminInfo.CurrentOrgId,
  5892. OrderNumber: cancel.OrderNumber,
  5893. Type: 0,
  5894. Dealer: deaerler.DealerName,
  5895. Manufacturer: manufacturer.ManufacturerName,
  5896. Number: info.Number,
  5897. RegisterAccount: "",
  5898. Remark: "",
  5899. WarehouseInfoId: info.WarehouseInfotId,
  5900. PatientId: info.PatientId,
  5901. RecordDate: info.SysRecordTime,
  5902. StorehouseId: houseConfig.StorehouseOutInfo,
  5903. IsCheck: 1,
  5904. }
  5905. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5906. //回退库存
  5907. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5908. //退库数量增加
  5909. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5910. //出库数量减少
  5911. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5912. }
  5913. if info.Count < prescribingNumber {
  5914. cancelStockInfo := models.CancelStockInfo{
  5915. GoodId: project.ProjectId,
  5916. CancelStockId: cancel.ID,
  5917. GoodTypeId: good.GoodTypeId,
  5918. Count: info.Count,
  5919. Price: info.Price,
  5920. Total: 0,
  5921. ProductDate: info.ProductDate,
  5922. ExpiryDate: info.ExpiryDate,
  5923. Ctime: time.Now().Unix(),
  5924. Status: 1,
  5925. OrgId: adminInfo.CurrentOrgId,
  5926. OrderNumber: cancel.OrderNumber,
  5927. Type: 0,
  5928. Dealer: deaerler.DealerName,
  5929. Manufacturer: manufacturer.ManufacturerName,
  5930. Number: info.Number,
  5931. RegisterAccount: "",
  5932. Remark: "",
  5933. WarehouseInfoId: info.WarehouseInfotId,
  5934. PatientId: info.PatientId,
  5935. RecordDate: info.SysRecordTime,
  5936. StorehouseId: houseConfig.StorehouseOutInfo,
  5937. IsCheck: 1,
  5938. }
  5939. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5940. //回退库存
  5941. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5942. //退库数量增加
  5943. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5944. //出库数量减少
  5945. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5946. }
  5947. //查询剩余库存
  5948. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5949. var over_count int64
  5950. for _, it := range goodList {
  5951. over_count += it.StockCount
  5952. }
  5953. //出库数据 大于 退库数量
  5954. if info.Count >= prescribingNumber {
  5955. flow := models.VmStockFlow{
  5956. WarehousingId: info.WarehouseInfotId,
  5957. GoodId: project.ProjectId,
  5958. Number: info.Number,
  5959. LicenseNumber: info.LicenseNumber,
  5960. Count: prescribingNumber,
  5961. UserOrgId: adminInfo.CurrentOrgId,
  5962. PatientId: project.PatientId,
  5963. SystemTime: info.SysRecordTime,
  5964. ConsumableType: 7,
  5965. IsSys: 0,
  5966. WarehousingOrder: "",
  5967. WarehouseOutId: info.WarehouseOutId,
  5968. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5969. IsEdit: 0,
  5970. CancelStockId: cancel.ID,
  5971. CancelOrderNumber: cancel.OrderNumber,
  5972. Manufacturer: manufacturer.ID,
  5973. Dealer: 0,
  5974. Creator: adminInfo.AdminUser.Id,
  5975. UpdateCreator: 0,
  5976. Status: 1,
  5977. Ctime: time.Now().Unix(),
  5978. Mtime: 0,
  5979. Price: info.Price,
  5980. WarehousingDetailId: info.WarehouseInfotId,
  5981. WarehouseOutDetailId: info.ID,
  5982. CancelOutDetailId: cancelInfo.ID,
  5983. ProductDate: info.ProductDate,
  5984. ExpireDate: info.ExpiryDate,
  5985. StorehouseId: houseConfig.StorehouseOutInfo,
  5986. OverCount: over_count,
  5987. OperateTime: time.Now().Unix(),
  5988. }
  5989. service.CreateStockFlowOne(flow)
  5990. }
  5991. //出库数据小于退库数据
  5992. if info.Count < prescribingNumber {
  5993. flow := models.VmStockFlow{
  5994. WarehousingId: info.WarehouseInfotId,
  5995. GoodId: project.ProjectId,
  5996. Number: info.Number,
  5997. LicenseNumber: info.LicenseNumber,
  5998. Count: info.Count,
  5999. UserOrgId: adminInfo.CurrentOrgId,
  6000. PatientId: project.PatientId,
  6001. SystemTime: info.SysRecordTime,
  6002. ConsumableType: 7,
  6003. IsSys: 0,
  6004. WarehousingOrder: "",
  6005. WarehouseOutId: info.WarehouseOutId,
  6006. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6007. IsEdit: 0,
  6008. CancelStockId: cancel.ID,
  6009. CancelOrderNumber: cancel.OrderNumber,
  6010. Manufacturer: manufacturer.ID,
  6011. Dealer: 0,
  6012. Creator: adminInfo.AdminUser.Id,
  6013. UpdateCreator: 0,
  6014. Status: 1,
  6015. Ctime: time.Now().Unix(),
  6016. Mtime: 0,
  6017. Price: info.Price,
  6018. WarehousingDetailId: info.WarehouseInfotId,
  6019. WarehouseOutDetailId: info.ID,
  6020. CancelOutDetailId: cancelInfo.ID,
  6021. ProductDate: info.ProductDate,
  6022. ExpireDate: info.ExpiryDate,
  6023. StorehouseId: houseConfig.StorehouseOutInfo,
  6024. OverCount: over_count,
  6025. OperateTime: time.Now().Unix(),
  6026. }
  6027. service.CreateStockFlowOne(flow)
  6028. }
  6029. //查询已出库数量
  6030. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6031. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6032. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6033. if prescribingNumber < dialysisInfo.Count {
  6034. //改变数量
  6035. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6036. }
  6037. if prescribingNumber >= dialysisInfo.Count {
  6038. //删除出库表
  6039. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6040. }
  6041. //更新剩余库存
  6042. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6043. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6044. var total_count_one int64
  6045. for _, it := range stockList {
  6046. total_count_one += it.StockCount
  6047. }
  6048. //基础库插入数据
  6049. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6050. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6051. var flush_count int64
  6052. for _, it := range goodListOne {
  6053. flush_count += it.StockCount
  6054. }
  6055. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6056. if errs != nil {
  6057. goodErrcode := models.XtGoodErrcode{
  6058. UserOrgId: project.UserOrgId,
  6059. Errcode: "手动出库更新剩余出库失败",
  6060. GoodId: project.ProjectId,
  6061. Status: 1,
  6062. Ctime: time.Now().Unix(),
  6063. Mtime: 0,
  6064. Count: 0,
  6065. StockCount: 0,
  6066. Creater: creater,
  6067. BatchNumberId: 0,
  6068. WarehouseOutId: 0,
  6069. }
  6070. service.CreateGoodErrcode(goodErrcode)
  6071. }
  6072. }
  6073. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6074. fmt.Println(err)
  6075. } else {
  6076. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6077. fmt.Println(err)
  6078. }
  6079. } else {
  6080. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6081. fmt.Println(err)
  6082. }
  6083. }
  6084. //保存处方出库
  6085. if goodOutConfig.IsOpen == 1 {
  6086. if project.Type == 3 {
  6087. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6088. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6089. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6090. operation_time := time.Now().Unix()
  6091. creater := adminInfo.AdminUser.Id
  6092. //创建退库单
  6093. timeStr := time.Now().Format("2006-01-02")
  6094. timeArr := strings.Split(timeStr, "-")
  6095. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6096. total = total + 1
  6097. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6098. cancelStock := models.CancelStock{
  6099. OrderNumber: orderNumber,
  6100. OperaTime: operation_time,
  6101. OrgId: adminInfo.CurrentOrgId,
  6102. Creater: creater,
  6103. Ctime: time.Now().Unix(),
  6104. Status: 1,
  6105. ReturnTime: project.RecordDate,
  6106. Type: 1,
  6107. StorehouseId: houseConfig.StorehouseOutInfo,
  6108. IsCheck: 1,
  6109. }
  6110. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6111. if msgerrkonde == gorm.ErrRecordNotFound {
  6112. service.AddSigleCancelStock(&cancelStock)
  6113. }
  6114. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6115. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6116. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6117. //获取出库数据
  6118. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6119. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6120. deaerler, _ := service.GetDealerById(info.Dealer)
  6121. if info.ID > 0 {
  6122. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6123. if info.Count >= prescribingNumber {
  6124. cancelStockInfo := models.CancelStockInfo{
  6125. GoodId: project.ProjectId,
  6126. CancelStockId: cancel.ID,
  6127. GoodTypeId: good.GoodTypeId,
  6128. Count: prescribingNumber,
  6129. Price: info.Price,
  6130. Total: 0,
  6131. ProductDate: info.ProductDate,
  6132. ExpiryDate: info.ExpiryDate,
  6133. Ctime: time.Now().Unix(),
  6134. Status: 1,
  6135. OrgId: adminInfo.CurrentOrgId,
  6136. OrderNumber: cancel.OrderNumber,
  6137. Type: 0,
  6138. Dealer: deaerler.DealerName,
  6139. Manufacturer: manufacturer.ManufacturerName,
  6140. Number: info.Number,
  6141. RegisterAccount: "",
  6142. Remark: "",
  6143. WarehouseInfoId: info.WarehouseInfotId,
  6144. PatientId: info.PatientId,
  6145. RecordDate: info.SysRecordTime,
  6146. StorehouseId: houseConfig.StorehouseOutInfo,
  6147. IsCheck: 1,
  6148. }
  6149. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6150. //退库数量增加
  6151. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6152. //出库数量减少
  6153. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6154. }
  6155. if info.Count < prescribingNumber {
  6156. cancelStockInfo := models.CancelStockInfo{
  6157. GoodId: project.ProjectId,
  6158. CancelStockId: cancel.ID,
  6159. GoodTypeId: good.GoodTypeId,
  6160. Count: prescribingNumber,
  6161. Price: info.Price,
  6162. Total: 0,
  6163. ProductDate: info.ProductDate,
  6164. ExpiryDate: info.ExpiryDate,
  6165. Ctime: time.Now().Unix(),
  6166. Status: 1,
  6167. OrgId: adminInfo.CurrentOrgId,
  6168. OrderNumber: cancel.OrderNumber,
  6169. Type: 0,
  6170. Dealer: deaerler.DealerName,
  6171. Manufacturer: manufacturer.ManufacturerName,
  6172. Number: info.Number,
  6173. RegisterAccount: "",
  6174. Remark: "",
  6175. WarehouseInfoId: info.WarehouseInfotId,
  6176. PatientId: info.PatientId,
  6177. RecordDate: info.SysRecordTime,
  6178. StorehouseId: houseConfig.StorehouseOutInfo,
  6179. IsCheck: 1,
  6180. }
  6181. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6182. //回退库存
  6183. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6184. }
  6185. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6186. var over_count int64
  6187. for _, it := range goodList {
  6188. over_count += it.StockCount
  6189. }
  6190. //查询出库数量
  6191. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6192. //出库数据 大于 退库数量
  6193. if len(list) > 0 {
  6194. for _, it := range list {
  6195. //回退库存
  6196. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6197. //退库数量增加
  6198. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6199. //出库数量减少
  6200. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6201. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6202. var over_count_one int64
  6203. for _, it := range goodList {
  6204. over_count_one += it.StockCount
  6205. }
  6206. //查询该批次是否有退库数据
  6207. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6208. flow := models.VmStockFlow{
  6209. WarehousingId: it.WarehouseInfotId,
  6210. GoodId: it.GoodId,
  6211. Number: it.Number,
  6212. LicenseNumber: it.LicenseNumber,
  6213. Count: it.Count,
  6214. UserOrgId: adminInfo.CurrentOrgId,
  6215. PatientId: it.PatientId,
  6216. SystemTime: it.SysRecordTime,
  6217. ConsumableType: 7,
  6218. IsSys: 0,
  6219. WarehousingOrder: "",
  6220. WarehouseOutId: it.WarehouseOutId,
  6221. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6222. IsEdit: 0,
  6223. CancelStockId: cancel.ID,
  6224. CancelOrderNumber: cancel.OrderNumber,
  6225. Manufacturer: manufacturer.ID,
  6226. Dealer: 0,
  6227. Creator: adminInfo.AdminUser.Id,
  6228. UpdateCreator: 0,
  6229. Status: 1,
  6230. Ctime: time.Now().Unix(),
  6231. Mtime: 0,
  6232. Price: it.Price,
  6233. WarehousingDetailId: it.WarehouseInfotId,
  6234. WarehouseOutDetailId: it.ID,
  6235. CancelOutDetailId: cancelInfo.ID,
  6236. ProductDate: it.ProductDate,
  6237. ExpireDate: it.ExpiryDate,
  6238. StorehouseId: houseConfig.StorehouseOutInfo,
  6239. OverCount: over_count_one,
  6240. OperateTime: time.Now().Unix(),
  6241. }
  6242. service.CreateStockFlowOne(flow)
  6243. }
  6244. }
  6245. //查询已出库数量
  6246. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6247. if prescribingNumber < dialysisInfo.Count {
  6248. //改变数量
  6249. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6250. }
  6251. if prescribingNumber >= dialysisInfo.Count {
  6252. //删除出库表
  6253. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6254. }
  6255. //更新剩余库存
  6256. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6257. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6258. var total_count_one int64
  6259. for _, it := range stockList {
  6260. total_count_one += it.StockCount
  6261. }
  6262. //基础库插入数据
  6263. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6264. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6265. var flush_count int64
  6266. for _, it := range goodListOne {
  6267. flush_count += it.StockCount
  6268. }
  6269. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6270. if errs != nil {
  6271. goodErrcode := models.XtGoodErrcode{
  6272. UserOrgId: project.UserOrgId,
  6273. Errcode: "手动出库更新剩余出库失败",
  6274. GoodId: project.ProjectId,
  6275. Status: 1,
  6276. Ctime: time.Now().Unix(),
  6277. Mtime: 0,
  6278. Count: 0,
  6279. StockCount: 0,
  6280. Creater: creater,
  6281. BatchNumberId: 0,
  6282. WarehouseOutId: 0,
  6283. }
  6284. service.CreateGoodErrcode(goodErrcode)
  6285. }
  6286. }
  6287. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6288. fmt.Println(err)
  6289. } else {
  6290. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6291. fmt.Println(err)
  6292. }
  6293. }
  6294. c.ServeSuccessJSON(map[string]interface{}{
  6295. "msg": "删除成功",
  6296. })
  6297. return
  6298. }
  6299. func (c *HisApiController) CreateHisAdditionalCharge() {
  6300. his_patient_id, _ := c.GetInt64("his_patient_id")
  6301. patient_id, _ := c.GetInt64("patient_id")
  6302. record_date := c.GetString("record_date")
  6303. timeLayout := "2006-01-02"
  6304. loc, _ := time.LoadLocation("Local")
  6305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6306. if err != nil {
  6307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6308. return
  6309. }
  6310. adminInfo := c.GetAdminUserInfo()
  6311. recordDateTime := theTime.Unix()
  6312. dataBody := make(map[string]interface{}, 0)
  6313. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6314. if err != nil {
  6315. utils.ErrorLog(err.Error())
  6316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6317. return
  6318. }
  6319. var additions []*models.HisAdditionalCharge
  6320. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6321. additions, _ := dataBody["addition"].([]interface{})
  6322. if len(additions) > 0 {
  6323. for _, item := range additions {
  6324. items := item.(map[string]interface{})
  6325. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6326. utils.ErrorLog("item_id")
  6327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6328. return
  6329. }
  6330. item_id := int64(items["item_id"].(float64))
  6331. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6332. utils.ErrorLog("item_name")
  6333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6334. return
  6335. }
  6336. item_name := items["item_name"].(string)
  6337. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6338. utils.ErrorLog("price")
  6339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6340. return
  6341. }
  6342. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6343. ctime := time.Now().Unix()
  6344. additional := &models.HisAdditionalCharge{
  6345. PatientId: patient_id,
  6346. HisPatientId: his_patient_id,
  6347. UserOrgId: adminInfo.CurrentOrgId,
  6348. RecordDate: recordDateTime,
  6349. CreatedTime: ctime,
  6350. UpdatedTime: ctime,
  6351. Modifier: adminInfo.AdminUser.Id,
  6352. Creator: adminInfo.AdminUser.Id,
  6353. Price: price,
  6354. ItemName: item_name,
  6355. ItemId: item_id,
  6356. Status: 1,
  6357. }
  6358. additions = append(additions, additional)
  6359. }
  6360. }
  6361. }
  6362. for _, item := range additions {
  6363. service.CreateAddtionalCharge(item)
  6364. }
  6365. c.ServeSuccessJSON(map[string]interface{}{
  6366. "msg": "创建成功",
  6367. })
  6368. }
  6369. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6370. blood_fat := c.GetString("blood_fat")
  6371. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6372. blood_sugar := c.GetString("blood_sugar")
  6373. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6374. chief_conplaint := c.GetString("chief_conplaint")
  6375. dbp := c.GetString("dbp")
  6376. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6377. delivery_way, _ := c.GetInt64("delivery_way")
  6378. diagnostic := c.GetString("diagnostic")
  6379. family_history := c.GetString("family_history")
  6380. height := c.GetString("height")
  6381. history_of_present_illness := c.GetString("history_of_present_illness")
  6382. is_infect, _ := c.GetInt64("is_infect")
  6383. past_history := c.GetString("past_history")
  6384. patient_id, _ := c.GetInt64("patient_id")
  6385. his_patient_id, _ := c.GetInt64("his_patient_id")
  6386. personal_history := c.GetString("personal_history")
  6387. pulse := c.GetString("pulse")
  6388. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6389. sbp := c.GetString("sbp")
  6390. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6391. heightfloat, _ := strconv.ParseFloat(height, 64)
  6392. sicktype := c.GetString("sick_type")
  6393. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6394. symptom := c.GetString("symptom")
  6395. sick_date := c.GetString("sick_date")
  6396. temperatures := c.GetString("temperature")
  6397. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6398. record_date := c.GetString("record_date")
  6399. breathing := c.GetString("breathing")
  6400. doctor_advice := c.GetString("doctor_advice")
  6401. remark := c.GetString("remark")
  6402. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6403. sick, _ := c.GetInt64("sick")
  6404. diagnose, _ := c.GetInt64("diagnose")
  6405. //id, _ := c.GetInt64("id")
  6406. timeLayout := "2006-01-02"
  6407. loc, _ := time.LoadLocation("Local")
  6408. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6409. allergic_history := c.GetString("allergic_history")
  6410. if err != nil {
  6411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6412. return
  6413. }
  6414. recordDateTime := theTime.Unix()
  6415. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6416. if err != nil {
  6417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6418. return
  6419. }
  6420. sickTimes := sickTime.Unix()
  6421. ctime := time.Now().Unix()
  6422. primary_disease := c.GetString("primary_disease")
  6423. confirm_failure_date := c.GetString("confirm_failure_date")
  6424. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6425. drug_allergy_history := c.GetString("drug_allergy_history")
  6426. physical_examination := c.GetString("physical_examination")
  6427. special_inspection := c.GetString("special_inspection")
  6428. lab_apparatus := c.GetString("lab_apparatus")
  6429. caseHistory := models.HisPatientCaseHistory{
  6430. HisPatientId: his_patient_id,
  6431. PatientId: patient_id,
  6432. Temperature: temperature,
  6433. BloodSugar: bloodsugarfloat,
  6434. Pulse: pulsefloat,
  6435. Sbp: sbpfloat,
  6436. Dbp: dbpfloat,
  6437. Height: heightfloat,
  6438. BloodFat: bloodfatfloat,
  6439. SickType: sick_type,
  6440. Symptom: symptom,
  6441. SickDate: sickTimes,
  6442. IsInfect: is_infect,
  6443. HistoryOfPresentIllness: history_of_present_illness,
  6444. PastHistory: past_history,
  6445. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6446. ChiefConplaint: chief_conplaint,
  6447. PersonalHistory: personal_history,
  6448. FamilyHistory: family_history,
  6449. Diagnostic: diagnostic,
  6450. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6451. Status: 1,
  6452. Ctime: ctime,
  6453. Mtime: ctime,
  6454. RecordDate: recordDateTime,
  6455. DeliveryWay: delivery_way,
  6456. Breathing: breathingfloat,
  6457. DoctorAdvice: doctor_advice,
  6458. Remark: remark,
  6459. Sick: sick,
  6460. Diagnose: diagnose,
  6461. AllergicHistory: allergic_history,
  6462. PrimaryDisease: primary_disease,
  6463. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6464. DrugAllergyHistory: drug_allergy_history,
  6465. PhysicalExamination: physical_examination,
  6466. SpecialInspection: special_inspection,
  6467. LabApparatus: lab_apparatus,
  6468. }
  6469. //查询该患者是否有病历
  6470. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6471. if errcodes == gorm.ErrRecordNotFound {
  6472. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6473. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6474. if err != nil {
  6475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6476. return
  6477. }
  6478. c.ServeSuccessJSON(map[string]interface{}{
  6479. "caseHistory": caseHistory,
  6480. "historyInfo": historyInfo,
  6481. })
  6482. return
  6483. } else if errcodes == nil {
  6484. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6485. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6486. if err != nil {
  6487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6488. return
  6489. }
  6490. c.ServeSuccessJSON(map[string]interface{}{
  6491. "caseHistory": caseHistory,
  6492. "historyInfo": historyInfo,
  6493. })
  6494. }
  6495. //查询该患者是否有病历
  6496. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6497. //if errcode == gorm.ErrRecordNotFound {
  6498. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6499. // if err != nil {
  6500. // c.ServeSuccessJSON(map[string]interface{}{
  6501. // "msg": "保存成功",
  6502. // })
  6503. // }
  6504. //} else if errcode == nil {
  6505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6506. // return
  6507. //}
  6508. }
  6509. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6510. patient_id, _ := c.GetInt64("patient_id", 0)
  6511. adminUser := c.GetAdminUserInfo()
  6512. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6513. c.ServeSuccessJSON(map[string]interface{}{
  6514. "list": caseHistorys,
  6515. })
  6516. }
  6517. func (c *HisApiController) GetHisPatientCaseHistory() {
  6518. record_date, _ := c.GetInt64("record_date", 0)
  6519. patient_id, _ := c.GetInt64("patient_id", 0)
  6520. admin := c.GetAdminUserInfo()
  6521. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6522. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6523. c.ServeSuccessJSON(map[string]interface{}{
  6524. "info": info,
  6525. "case_history": case_history,
  6526. })
  6527. }
  6528. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6529. template_name := c.GetString("template_name")
  6530. template_remark := c.GetString("template_remark")
  6531. doctor := c.GetAdminUserInfo().AdminUser.Id
  6532. diagnostic := c.GetString("diagnostic")
  6533. chief_conplaint := c.GetString("chief_conplain")
  6534. history_of_present_illness := c.GetString("history_of_present_illness")
  6535. past_history := c.GetString("past_history")
  6536. personal_history := c.GetString("personal_history")
  6537. family_history := c.GetString("family_history")
  6538. user_name := c.GetString("user_name")
  6539. doctor_advice := c.GetString("doctor_advice")
  6540. remark := c.GetString("remark")
  6541. //record_date := c.GetString("record_date")
  6542. //fmt.Println("record_date--------",record_date)
  6543. //timeLayout := "2006-01-02"
  6544. //loc, _ := time.LoadLocation("Local")
  6545. //
  6546. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6547. //if err != nil {
  6548. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6549. // return
  6550. //}
  6551. //recordDateTime := theTime.Unix()
  6552. ctime := time.Now().Unix()
  6553. template := models.HisCaseHistoryTemplate{
  6554. HistoryOfPresentIllness: history_of_present_illness,
  6555. PastHistory: past_history,
  6556. ChiefConplaint: chief_conplaint,
  6557. PersonalHistory: personal_history,
  6558. FamilyHistory: family_history,
  6559. Diagnostic: diagnostic,
  6560. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6561. Status: 1,
  6562. Ctime: ctime,
  6563. Mtime: ctime,
  6564. RecordDate: time.Now().Unix(),
  6565. TemplateName: template_name,
  6566. TemplateRemark: template_remark,
  6567. Creator: doctor,
  6568. Modifier: doctor,
  6569. UserName: user_name,
  6570. DoctorAdvice: doctor_advice,
  6571. Remark: remark,
  6572. }
  6573. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6574. if err == nil {
  6575. c.ServeSuccessJSON(map[string]interface{}{
  6576. "msg": "保存成功",
  6577. })
  6578. } else {
  6579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6580. return
  6581. }
  6582. }
  6583. func (c *HisApiController) GetCaseHistoryTemplate() {
  6584. timeLayout := "2006-01-02"
  6585. loc, _ := time.LoadLocation("Local")
  6586. keyword := c.GetString("keyword")
  6587. start_time := c.GetString("start_time")
  6588. end_time := c.GetString("end_time")
  6589. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6590. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6591. admin := c.GetAdminUserInfo()
  6592. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6593. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6594. c.ServeSuccessJSON(map[string]interface{}{
  6595. "template": template,
  6596. //"history": history,
  6597. })
  6598. }
  6599. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6600. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6601. utils.ErrorLog("drug_name")
  6602. return enums.ErrorCodeParamWrong
  6603. }
  6604. adviceName, _ := json["drug_name"].(string)
  6605. if len(adviceName) == 0 {
  6606. utils.ErrorLog("len(advice_name) == 0")
  6607. return enums.ErrorCodeParamWrong
  6608. }
  6609. advice.AdviceName = adviceName
  6610. adviceDesc, _ := json["advice_desc"].(string)
  6611. advice.AdviceDesc = adviceDesc
  6612. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6613. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6614. advice.DrugSpec = drugSpec
  6615. }
  6616. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6617. remark, _ := json["remark"].(string)
  6618. advice.Remark = remark
  6619. }
  6620. if json["id"] == nil {
  6621. advice.DrugId = 0
  6622. } else {
  6623. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6624. drug_id := int64(json["id"].(float64))
  6625. advice.DrugId = drug_id
  6626. }
  6627. }
  6628. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6629. advice_id := int64(json["advice_id"].(float64))
  6630. advice.ID = advice_id
  6631. if advice.ID > 0 {
  6632. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6633. if err == nil {
  6634. if hisAdvice.ID > 0 {
  6635. advice.ExecutionTime = hisAdvice.ExecutionTime
  6636. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6637. advice.ExecutionState = hisAdvice.ExecutionState
  6638. advice.CheckTime = hisAdvice.CheckTime
  6639. advice.Checker = hisAdvice.Checker
  6640. advice.CheckState = hisAdvice.CheckState
  6641. advice.StartTime = hisAdvice.StartTime
  6642. advice.FeedetlSn = hisAdvice.FeedetlSn
  6643. }
  6644. }
  6645. }
  6646. }
  6647. //
  6648. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6649. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6650. // advice.ExecutionTime = execution_time
  6651. //}
  6652. //
  6653. //
  6654. //
  6655. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6656. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6657. // advice.ExecutionStaff = execution_staff
  6658. //}
  6659. //
  6660. //
  6661. //
  6662. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6663. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6664. // advice.ExecutionState = execution_state
  6665. //}
  6666. //
  6667. //
  6668. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6669. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6670. // advice.CheckTime = check_time
  6671. //}
  6672. //
  6673. //
  6674. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6675. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6676. // advice.CheckState = check_state
  6677. //}
  6678. //
  6679. //
  6680. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6681. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6682. // advice.Checker = checker
  6683. //}
  6684. //
  6685. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6686. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6687. // advice.StartTime = start_time
  6688. //}
  6689. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6690. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6691. advice.IsSelfDrug = is_self_drug
  6692. }
  6693. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6694. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6695. drug_way_count, _ := json["drug_way_count"].(string)
  6696. advice.DrugWayCount = drug_way_count
  6697. }
  6698. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6699. drugSpecUnit, _ := json["min_unit"].(string)
  6700. advice.DrugSpecUnit = drugSpecUnit
  6701. }
  6702. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6703. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6704. advice.SingleDose = singleDose
  6705. }
  6706. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6707. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6708. advice.SingleDoseUnit = singleDoseUnit
  6709. }
  6710. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6711. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6712. advice.PrescribingNumber = prescribingNumber
  6713. }
  6714. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6715. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6716. advice.PrescribingNumberUnit = prescribingNumberUnit
  6717. }
  6718. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6719. deliveryWay, _ := json["delivery_way"].(string)
  6720. advice.DeliveryWay = deliveryWay
  6721. }
  6722. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6723. executionFrequency, _ := json["execution_frequency"].(string)
  6724. advice.ExecutionFrequency = executionFrequency
  6725. }
  6726. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6727. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6728. advice.Price = price
  6729. }
  6730. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6731. med_list_codg, _ := json["medical_insurance_number"].(string)
  6732. advice.MedListCodg = med_list_codg
  6733. }
  6734. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6735. day := int64(json["day"].(float64))
  6736. advice.Day = day
  6737. }
  6738. return 0
  6739. }
  6740. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6741. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6742. id := int64(json["id"].(float64))
  6743. project.ID = id
  6744. historyProject, _ := service.GetHisProjectByID(id)
  6745. project.FeedetlSn = historyProject.FeedetlSn
  6746. }
  6747. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6748. project_id := int64(json["project_id"].(float64))
  6749. project.ProjectId = project_id
  6750. }
  6751. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6752. // price := int64(json["price"].(float64))
  6753. // formatInt_price := strconv.FormatInt(price, 10)
  6754. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6755. // project.Price = float_price
  6756. // }
  6757. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6758. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6759. project.Price = price
  6760. }
  6761. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6762. total, _ := json["total"].(string)
  6763. project.Count = total
  6764. }
  6765. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6766. medical_code, _ := json["medical_code"].(string)
  6767. project.MedListCodg = medical_code
  6768. }
  6769. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6770. single_dose, _ := json["single_dose"].(string)
  6771. project.SingleDose = single_dose
  6772. }
  6773. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6774. delivery_way, _ := json["delivery_way"].(string)
  6775. project.DeliveryWay = delivery_way
  6776. }
  6777. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6778. execution_frequency, _ := json["execution_frequency"].(string)
  6779. project.ExecutionFrequency = execution_frequency
  6780. }
  6781. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6782. remark, _ := json["remark"].(string)
  6783. project.Remark = remark
  6784. }
  6785. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6786. day, _ := json["number_days"].(string)
  6787. project.Day = day
  6788. }
  6789. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6790. unit, _ := json["unit"].(string)
  6791. project.Unit = unit
  6792. }
  6793. return 0
  6794. }
  6795. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6796. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6797. id := int64(json["id"].(float64))
  6798. historyAddtions, _ := service.GetHisAdditionByID(id)
  6799. additionalCharge.ID = id
  6800. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6801. }
  6802. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6803. item_id := int64(json["item_id"].(float64))
  6804. additionalCharge.ItemId = item_id
  6805. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6806. if config.ID > 0 {
  6807. if len(config.Code) > 0 {
  6808. additionalCharge.MedListCodg = config.Code
  6809. }
  6810. }
  6811. }
  6812. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6813. // price := int64(json["price"].(float64))
  6814. // formatInt_price := strconv.FormatInt(price, 10)
  6815. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6816. // additionalCharge.Price = float_price
  6817. // }
  6818. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6819. // price := int64(json["price"].(float64))
  6820. // formatInt_price := strconv.FormatInt(price, 10)
  6821. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6822. // additionalCharge.Price = float_price
  6823. //}
  6824. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6825. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6826. additionalCharge.Price = price
  6827. }
  6828. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6829. count, _ := json["count"].(string)
  6830. counts, _ := strconv.ParseInt(count, 10, 64)
  6831. additionalCharge.Count = counts
  6832. }
  6833. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6834. item_name, _ := json["item_name"].(string)
  6835. additionalCharge.ItemName = item_name
  6836. }
  6837. return 0
  6838. }
  6839. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6840. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6841. utils.ErrorLog("drug_name")
  6842. return enums.ErrorCodeParamWrong
  6843. }
  6844. adviceName, _ := json["drug_name"].(string)
  6845. if len(adviceName) == 0 {
  6846. utils.ErrorLog("len(advice_name) == 0")
  6847. return enums.ErrorCodeParamWrong
  6848. }
  6849. advice.AdviceName = adviceName
  6850. adviceDesc, _ := json["advice_desc"].(string)
  6851. advice.AdviceDesc = adviceDesc
  6852. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6853. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6854. advice.DrugSpec = drugSpec
  6855. }
  6856. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6857. remark, _ := json["remark"].(string)
  6858. advice.Remark = remark
  6859. }
  6860. if json["id"] == nil {
  6861. advice.DrugId = 0
  6862. } else {
  6863. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6864. drug_id := int64(json["id"].(float64))
  6865. advice.DrugId = drug_id
  6866. }
  6867. }
  6868. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6869. groupno := int64(json["groupno"].(float64))
  6870. advice.Groupno = groupno
  6871. }
  6872. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6873. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6874. advice.IsSelfDrug = is_self_drug
  6875. }
  6876. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6877. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6878. drug_way_count, _ := json["drug_way_count"].(string)
  6879. advice.DrugWayCount = drug_way_count
  6880. }
  6881. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6882. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6883. advice.HospApprFlag = hosp_appr_flag
  6884. }
  6885. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6886. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6887. advice.PrescribingNumber = prescribingNumber
  6888. }
  6889. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6890. // frequency_type := int64(json["frequency_type"].(float64))
  6891. // advice.FrequencyType = frequency_type
  6892. //}
  6893. //
  6894. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6895. // day_count := int64(json["day_count"].(float64))
  6896. // advice.DayCount = day_count
  6897. //}
  6898. //
  6899. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6900. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6901. // week_day, _ := json["week_day"].(string)
  6902. // advice.WeekDay = week_day
  6903. //}
  6904. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6905. drugSpecUnit, _ := json["min_unit"].(string)
  6906. advice.DrugSpecUnit = drugSpecUnit
  6907. }
  6908. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6909. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6910. advice.SingleDose = singleDose
  6911. }
  6912. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6913. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6914. advice.SingleDoseUnit = singleDoseUnit
  6915. }
  6916. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6917. deliveryWay, _ := json["delivery_way"].(string)
  6918. advice.DeliveryWay = deliveryWay
  6919. }
  6920. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6921. executionFrequency, _ := json["execution_frequency"].(string)
  6922. advice.ExecutionFrequency = executionFrequency
  6923. }
  6924. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6925. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6926. advice.Price = price
  6927. }
  6928. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6929. med_list_codg, _ := json["medical_insurance_number"].(string)
  6930. advice.MedListCodg = med_list_codg
  6931. }
  6932. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6933. day := int64(json["day"].(float64))
  6934. advice.Day = day
  6935. }
  6936. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6937. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6938. advice.PrescribingNumberUnit = prescribingNumberUnit
  6939. }
  6940. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6941. advice_id := int64(json["advice_id"].(float64))
  6942. advice.ID = advice_id
  6943. if advice.ID > 0 {
  6944. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6945. if err == nil {
  6946. if hisAdvice.ID > 0 {
  6947. advice.ExecutionTime = hisAdvice.ExecutionTime
  6948. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6949. advice.ExecutionState = hisAdvice.ExecutionState
  6950. advice.CheckTime = hisAdvice.CheckTime
  6951. advice.Checker = hisAdvice.Checker
  6952. advice.CheckState = hisAdvice.CheckState
  6953. advice.StartTime = hisAdvice.StartTime
  6954. advice.HospApprFlag = hisAdvice.HospApprFlag
  6955. advice.IsMedicine = hisAdvice.IsMedicine
  6956. if hisAdvice.UserOrgId == 10028 {
  6957. 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 {
  6958. advice.ExecutionTime = 0
  6959. advice.ExecutionStaff = 0
  6960. advice.ExecutionState = 2
  6961. advice.CheckTime = 0
  6962. advice.Checker = 0
  6963. advice.CheckState = 2
  6964. }
  6965. } else {
  6966. 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 {
  6967. advice.ExecutionTime = 0
  6968. advice.ExecutionStaff = 0
  6969. advice.ExecutionState = 2
  6970. advice.CheckTime = 0
  6971. advice.Checker = 0
  6972. advice.CheckState = 2
  6973. advice.UpdatedTime = time.Now().Unix()
  6974. }
  6975. }
  6976. //advice.Groupno = hisAdvice.Groupno
  6977. }
  6978. }
  6979. }
  6980. }
  6981. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6982. //
  6983. //if drugStockConfig.IsOpen == 1 {
  6984. //
  6985. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6986. // if advice.ID == 0 { //医嘱不存在
  6987. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6988. // drug.Total = drug.Total - advice.PrescribingNumber
  6989. // service.UpdateBaseDrugLib(&drug)
  6990. //
  6991. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6992. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6993. // drug.Total = drug.Total - num
  6994. // service.UpdateBaseDrugLib(&drug)
  6995. // }
  6996. //
  6997. // } else if advice.ID > 0 { //医嘱存在
  6998. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6999. // var num float64
  7000. //
  7001. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7002. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7003. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7004. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7005. // drug.Total = drug.Total + num
  7006. // service.UpdateBaseDrugLib(&drug)
  7007. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7008. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7009. // drug.Total = drug.Total - num
  7010. // service.UpdateBaseDrugLib(&drug)
  7011. // }
  7012. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7013. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7014. // if num2 > advice.PrescribingNumber {
  7015. // num = num2 - advice.PrescribingNumber
  7016. // drug.Total = drug.Total + num
  7017. // service.UpdateBaseDrugLib(&drug)
  7018. // } else if num2 < advice.PrescribingNumber {
  7019. // num = advice.PrescribingNumber - num2
  7020. // drug.Total = drug.Total - num
  7021. // service.UpdateBaseDrugLib(&drug)
  7022. // }
  7023. //
  7024. // }
  7025. //
  7026. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7027. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7028. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7029. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7030. // if num1 > num2 {
  7031. // num = num1 - num2
  7032. // drug.Total = drug.Total + num
  7033. // service.UpdateBaseDrugLib(&drug)
  7034. // } else if num1 < num2 {
  7035. // num = num2 - num1
  7036. // drug.Total = drug.Total - num
  7037. // service.UpdateBaseDrugLib(&drug)
  7038. // }
  7039. //
  7040. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7041. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7042. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7043. // if hisAdvice.PrescribingNumber > num2 {
  7044. // num = hisAdvice.PrescribingNumber - num2
  7045. // drug.Total = drug.Total + num
  7046. // service.UpdateBaseDrugLib(&drug)
  7047. // } else if num2 < advice.PrescribingNumber {
  7048. // num = num2 - hisAdvice.PrescribingNumber
  7049. // drug.Total = drug.Total - num
  7050. // service.UpdateBaseDrugLib(&drug)
  7051. // }
  7052. //
  7053. // }
  7054. // }
  7055. // }
  7056. //}
  7057. //
  7058. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7059. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7060. // advice.ExecutionTime = execution_time
  7061. //}
  7062. //
  7063. //
  7064. //
  7065. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7066. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7067. // advice.ExecutionStaff = execution_staff
  7068. //}
  7069. //
  7070. //
  7071. //
  7072. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7073. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7074. // advice.ExecutionState = execution_state
  7075. //}
  7076. //
  7077. //
  7078. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7079. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7080. // advice.CheckTime = check_time
  7081. //}
  7082. //
  7083. //
  7084. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7085. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7086. // advice.CheckState = check_state
  7087. //}
  7088. //
  7089. //
  7090. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7091. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7092. // advice.Checker = checker
  7093. //}
  7094. //
  7095. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7096. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7097. // advice.StartTime = start_time
  7098. //}
  7099. return 0
  7100. }
  7101. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7102. project.ExecutionStaff = 0
  7103. project.ExecutionState = 2
  7104. project.ExecutionTime = 0
  7105. project.Checker = 0
  7106. project.CheckState = 2
  7107. project.CheckTime = 0
  7108. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7109. id := int64(json["id"].(float64))
  7110. project.ID = id
  7111. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7112. project.ExecutionStaff = temp_project.ExecutionStaff
  7113. project.ExecutionState = temp_project.ExecutionState
  7114. project.ExecutionTime = temp_project.ExecutionTime
  7115. project.Checker = temp_project.Checker
  7116. project.CheckState = temp_project.CheckState
  7117. project.CheckTime = temp_project.CheckTime
  7118. project.TeamId = temp_project.TeamId
  7119. }
  7120. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7121. types := int64(json["type"].(float64))
  7122. project.Type = types
  7123. }
  7124. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7125. project_id := int64(json["project_id"].(float64))
  7126. project.ProjectId = project_id
  7127. }
  7128. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7129. team_id := int64(json["team_id"].(float64))
  7130. project.TeamId = team_id
  7131. }
  7132. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7133. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7134. project.Price = price
  7135. }
  7136. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7137. total, _ := json["total"].(string)
  7138. //totals, _ := strconv.ParseInt(total, 10, 64)
  7139. project.Count = total
  7140. }
  7141. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7142. medical_code, _ := json["medical_code"].(string)
  7143. project.MedListCodg = medical_code
  7144. }
  7145. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7146. single_dose, _ := json["single_dose"].(string)
  7147. project.SingleDose = single_dose
  7148. }
  7149. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7150. delivery_way, _ := json["delivery_way"].(string)
  7151. project.DeliveryWay = delivery_way
  7152. }
  7153. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7154. execution_frequency, _ := json["execution_frequency"].(string)
  7155. project.ExecutionFrequency = execution_frequency
  7156. }
  7157. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7158. remark, _ := json["remark"].(string)
  7159. project.Remark = remark
  7160. }
  7161. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7162. day, _ := json["number_days"].(string)
  7163. project.Day = day
  7164. }
  7165. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7166. unit, _ := json["unit"].(string)
  7167. project.Unit = unit
  7168. }
  7169. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7170. // frequency_type := int64(json["frequency_type"].(float64))
  7171. // project.FrequencyType = frequency_type
  7172. //}
  7173. //
  7174. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7175. // day_count := int64(json["day_count"].(float64))
  7176. // project.DayCount = day_count
  7177. //}
  7178. //
  7179. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7180. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7181. // week_day, _ := json["week_day"].(string)
  7182. // project.WeekDay = week_day
  7183. //}
  7184. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7185. //
  7186. //if project.ID == 0 {
  7187. // if stockConfig.IsOpen == 1 {
  7188. // if project.Type == 3 {
  7189. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7190. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7191. // good.Total = good.Total - f_count
  7192. // service.UpdateGoodInfo(&good)
  7193. // }
  7194. // }
  7195. //
  7196. //} else {
  7197. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7198. //
  7199. // if stockConfig.IsOpen == 1 {
  7200. // if project.Type == 3 {
  7201. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7202. // if project.Count < temp_project.Count {
  7203. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7204. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7205. //
  7206. // other_count := f_count_two - f_count_one
  7207. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7208. // good.Total = good.Total + other_count_two
  7209. // service.UpdateGoodInfo(&good)
  7210. // } else if project.Count > temp_project.Count {
  7211. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7212. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7213. //
  7214. // other_count := f_count_one - f_count_two
  7215. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7216. // good.Total = good.Total - other_count_two
  7217. // service.UpdateGoodInfo(&good)
  7218. // }
  7219. //
  7220. // }
  7221. // }
  7222. //
  7223. //}
  7224. return 0
  7225. }
  7226. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7227. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7228. utils.ErrorLog("drug_name")
  7229. return enums.ErrorCodeParamWrong
  7230. }
  7231. adviceName, _ := json["drug_name"].(string)
  7232. if len(adviceName) == 0 {
  7233. utils.ErrorLog("len(advice_name) == 0")
  7234. return enums.ErrorCodeParamWrong
  7235. }
  7236. advice.AdviceName = adviceName
  7237. adviceDesc, _ := json["advice_desc"].(string)
  7238. advice.AdviceDesc = adviceDesc
  7239. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7240. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7241. advice.DrugSpec = drugSpec
  7242. }
  7243. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7244. remark, _ := json["remark"].(string)
  7245. advice.Remark = remark
  7246. }
  7247. if json["id"] == nil {
  7248. advice.DrugId = 0
  7249. } else {
  7250. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7251. drug_id := int64(json["id"].(float64))
  7252. advice.DrugId = drug_id
  7253. }
  7254. }
  7255. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7256. groupno := int64(json["groupno"].(float64))
  7257. advice.Groupno = groupno
  7258. }
  7259. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7260. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7261. advice.IsSelfDrug = is_self_drug
  7262. }
  7263. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7264. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7265. drug_way_count, _ := json["drug_way_count"].(string)
  7266. advice.DrugWayCount = drug_way_count
  7267. }
  7268. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7269. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7270. advice.HospApprFlag = hosp_appr_flag
  7271. }
  7272. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7273. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7274. advice.PrescribingNumber = prescribingNumber
  7275. }
  7276. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7277. // frequency_type := int64(json["frequency_type"].(float64))
  7278. // advice.FrequencyType = frequency_type
  7279. //}
  7280. //
  7281. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7282. // day_count := int64(json["day_count"].(float64))
  7283. // advice.DayCount = day_count
  7284. //}
  7285. //
  7286. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7287. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7288. // week_day, _ := json["week_day"].(string)
  7289. // advice.WeekDay = week_day
  7290. //}
  7291. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7292. drugSpecUnit, _ := json["min_unit"].(string)
  7293. advice.DrugSpecUnit = drugSpecUnit
  7294. }
  7295. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7296. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7297. advice.SingleDose = singleDose
  7298. }
  7299. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7300. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7301. advice.SingleDoseUnit = singleDoseUnit
  7302. }
  7303. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7304. deliveryWay, _ := json["delivery_way"].(string)
  7305. advice.DeliveryWay = deliveryWay
  7306. }
  7307. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7308. executionFrequency, _ := json["execution_frequency"].(string)
  7309. advice.ExecutionFrequency = executionFrequency
  7310. }
  7311. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7312. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7313. advice.Price = price
  7314. }
  7315. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7316. med_list_codg, _ := json["medical_insurance_number"].(string)
  7317. advice.MedListCodg = med_list_codg
  7318. }
  7319. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7320. day := int64(json["day"].(float64))
  7321. advice.Day = day
  7322. }
  7323. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7324. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7325. advice.PrescribingNumberUnit = prescribingNumberUnit
  7326. }
  7327. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7328. advice_id := int64(json["advice_id"].(float64))
  7329. advice.ID = advice_id
  7330. if advice.ID > 0 {
  7331. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7332. if err == nil {
  7333. if hisAdvice.ID > 0 {
  7334. advice.ExecutionTime = hisAdvice.ExecutionTime
  7335. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7336. advice.ExecutionState = hisAdvice.ExecutionState
  7337. advice.CheckTime = hisAdvice.CheckTime
  7338. advice.Checker = hisAdvice.Checker
  7339. advice.CheckState = hisAdvice.CheckState
  7340. advice.StartTime = hisAdvice.StartTime
  7341. advice.HospApprFlag = hisAdvice.HospApprFlag
  7342. advice.IsMedicine = hisAdvice.IsMedicine
  7343. if hisAdvice.UserOrgId == 10028 {
  7344. 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 {
  7345. advice.ExecutionTime = 0
  7346. advice.ExecutionStaff = 0
  7347. advice.ExecutionState = 2
  7348. advice.CheckTime = 0
  7349. advice.Checker = 0
  7350. advice.CheckState = 2
  7351. }
  7352. } else {
  7353. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
  7354. advice.ExecutionTime = 0
  7355. advice.ExecutionStaff = 0
  7356. advice.ExecutionState = 2
  7357. advice.CheckTime = 0
  7358. advice.Checker = 0
  7359. advice.CheckState = 2
  7360. //advice.UpdatedTime = time.Now().Unix()
  7361. advice.CreatedTime = hisAdvice.CreatedTime
  7362. advice.UpdatedTime = time.Now().Unix()
  7363. } else {
  7364. advice.CreatedTime = hisAdvice.CreatedTime
  7365. advice.UpdatedTime = hisAdvice.UpdatedTime
  7366. }
  7367. }
  7368. //advice.Groupno = hisAdvice.Groupno
  7369. } else {
  7370. advice.IsMedicine = 0
  7371. ctime := time.Now().Unix()
  7372. advice.CreatedTime = ctime
  7373. advice.UpdatedTime = ctime
  7374. }
  7375. }
  7376. } else {
  7377. advice.IsMedicine = 0
  7378. ctime := time.Now().Unix()
  7379. advice.CreatedTime = ctime
  7380. advice.UpdatedTime = ctime
  7381. }
  7382. }
  7383. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7384. //
  7385. //if drugStockConfig.IsOpen == 1 {
  7386. //
  7387. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7388. // if advice.ID == 0 { //医嘱不存在
  7389. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7390. // drug.Total = drug.Total - advice.PrescribingNumber
  7391. // service.UpdateBaseDrugLib(&drug)
  7392. //
  7393. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7394. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7395. // drug.Total = drug.Total - num
  7396. // service.UpdateBaseDrugLib(&drug)
  7397. // }
  7398. //
  7399. // } else if advice.ID > 0 { //医嘱存在
  7400. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7401. // var num float64
  7402. //
  7403. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7404. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7405. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7406. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7407. // drug.Total = drug.Total + num
  7408. // service.UpdateBaseDrugLib(&drug)
  7409. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7410. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7411. // drug.Total = drug.Total - num
  7412. // service.UpdateBaseDrugLib(&drug)
  7413. // }
  7414. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7415. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7416. // if num2 > advice.PrescribingNumber {
  7417. // num = num2 - advice.PrescribingNumber
  7418. // drug.Total = drug.Total + num
  7419. // service.UpdateBaseDrugLib(&drug)
  7420. // } else if num2 < advice.PrescribingNumber {
  7421. // num = advice.PrescribingNumber - num2
  7422. // drug.Total = drug.Total - num
  7423. // service.UpdateBaseDrugLib(&drug)
  7424. // }
  7425. //
  7426. // }
  7427. //
  7428. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7429. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7430. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7431. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7432. // if num1 > num2 {
  7433. // num = num1 - num2
  7434. // drug.Total = drug.Total + num
  7435. // service.UpdateBaseDrugLib(&drug)
  7436. // } else if num1 < num2 {
  7437. // num = num2 - num1
  7438. // drug.Total = drug.Total - num
  7439. // service.UpdateBaseDrugLib(&drug)
  7440. // }
  7441. //
  7442. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7443. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7444. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7445. // if hisAdvice.PrescribingNumber > num2 {
  7446. // num = hisAdvice.PrescribingNumber - num2
  7447. // drug.Total = drug.Total + num
  7448. // service.UpdateBaseDrugLib(&drug)
  7449. // } else if num2 < advice.PrescribingNumber {
  7450. // num = num2 - hisAdvice.PrescribingNumber
  7451. // drug.Total = drug.Total - num
  7452. // service.UpdateBaseDrugLib(&drug)
  7453. // }
  7454. //
  7455. // }
  7456. // }
  7457. // }
  7458. //}
  7459. //
  7460. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7461. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7462. // advice.ExecutionTime = execution_time
  7463. //}
  7464. //
  7465. //
  7466. //
  7467. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7468. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7469. // advice.ExecutionStaff = execution_staff
  7470. //}
  7471. //
  7472. //
  7473. //
  7474. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7475. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7476. // advice.ExecutionState = execution_state
  7477. //}
  7478. //
  7479. //
  7480. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7481. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7482. // advice.CheckTime = check_time
  7483. //}
  7484. //
  7485. //
  7486. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7487. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7488. // advice.CheckState = check_state
  7489. //}
  7490. //
  7491. //
  7492. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7493. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7494. // advice.Checker = checker
  7495. //}
  7496. //
  7497. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7498. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7499. // advice.StartTime = start_time
  7500. //}
  7501. return 0
  7502. }
  7503. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7504. project.ExecutionStaff = 0
  7505. project.ExecutionState = 2
  7506. project.ExecutionTime = 0
  7507. project.Checker = 0
  7508. project.CheckState = 2
  7509. project.CheckTime = 0
  7510. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7511. id := int64(json["id"].(float64))
  7512. project.ID = id
  7513. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7514. project.ExecutionStaff = temp_project.ExecutionStaff
  7515. project.ExecutionState = temp_project.ExecutionState
  7516. project.ExecutionTime = temp_project.ExecutionTime
  7517. project.Checker = temp_project.Checker
  7518. project.CheckState = temp_project.CheckState
  7519. project.CheckTime = temp_project.CheckTime
  7520. project.TeamId = temp_project.TeamId
  7521. }
  7522. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7523. types := int64(json["type"].(float64))
  7524. project.Type = types
  7525. }
  7526. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7527. project_id := int64(json["project_id"].(float64))
  7528. project.ProjectId = project_id
  7529. }
  7530. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7531. team_id := int64(json["team_id"].(float64))
  7532. project.TeamId = team_id
  7533. }
  7534. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7535. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7536. project.Price = price
  7537. }
  7538. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7539. total, _ := json["total"].(string)
  7540. //totals, _ := strconv.ParseInt(total, 10, 64)
  7541. project.Count = total
  7542. }
  7543. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7544. medical_code, _ := json["medical_code"].(string)
  7545. project.MedListCodg = medical_code
  7546. }
  7547. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7548. single_dose, _ := json["single_dose"].(string)
  7549. project.SingleDose = single_dose
  7550. }
  7551. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7552. delivery_way, _ := json["delivery_way"].(string)
  7553. project.DeliveryWay = delivery_way
  7554. }
  7555. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7556. execution_frequency, _ := json["execution_frequency"].(string)
  7557. project.ExecutionFrequency = execution_frequency
  7558. }
  7559. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7560. remark, _ := json["remark"].(string)
  7561. project.Remark = remark
  7562. }
  7563. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7564. day, _ := json["number_days"].(string)
  7565. project.Day = day
  7566. }
  7567. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7568. unit, _ := json["unit"].(string)
  7569. project.Unit = unit
  7570. }
  7571. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7572. // frequency_type := int64(json["frequency_type"].(float64))
  7573. // project.FrequencyType = frequency_type
  7574. //}
  7575. //
  7576. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7577. // day_count := int64(json["day_count"].(float64))
  7578. // project.DayCount = day_count
  7579. //}
  7580. //
  7581. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7582. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7583. // week_day, _ := json["week_day"].(string)
  7584. // project.WeekDay = week_day
  7585. //}
  7586. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7587. //
  7588. //if project.ID == 0 {
  7589. // if stockConfig.IsOpen == 1 {
  7590. // if project.Type == 3 {
  7591. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7592. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7593. // good.Total = good.Total - f_count
  7594. // service.UpdateGoodInfo(&good)
  7595. // }
  7596. // }
  7597. //
  7598. //} else {
  7599. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7600. //
  7601. // if stockConfig.IsOpen == 1 {
  7602. // if project.Type == 3 {
  7603. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7604. // if project.Count < temp_project.Count {
  7605. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7606. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7607. //
  7608. // other_count := f_count_two - f_count_one
  7609. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7610. // good.Total = good.Total + other_count_two
  7611. // service.UpdateGoodInfo(&good)
  7612. // } else if project.Count > temp_project.Count {
  7613. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7614. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7615. //
  7616. // other_count := f_count_one - f_count_two
  7617. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7618. // good.Total = good.Total - other_count_two
  7619. // service.UpdateGoodInfo(&good)
  7620. // }
  7621. //
  7622. // }
  7623. // }
  7624. //
  7625. //}
  7626. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7627. id := int64(json["id"].(float64))
  7628. if id > 0 {
  7629. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7630. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7631. fmt.Println("666666")
  7632. project.Mtime = time.Now().Unix()
  7633. project.Ctime = temp_project.Ctime
  7634. } else {
  7635. project.Mtime = temp_project.Mtime
  7636. project.Ctime = temp_project.Ctime
  7637. }
  7638. } else {
  7639. ctime := time.Now().Unix()
  7640. project.Mtime = ctime
  7641. project.Ctime = ctime
  7642. }
  7643. }
  7644. return 0
  7645. }
  7646. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7647. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7648. id := int64(json["id"].(float64))
  7649. additionalCharge.ID = id
  7650. }
  7651. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7652. item_id := int64(json["item_id"].(float64))
  7653. additionalCharge.ItemId = item_id
  7654. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7655. if config.ID > 0 {
  7656. if len(config.Code) > 0 {
  7657. additionalCharge.MedListCodg = config.Code
  7658. }
  7659. }
  7660. }
  7661. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7662. // price := int64(json["price"].(float64))
  7663. // formatInt_price := strconv.FormatInt(price, 10)
  7664. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7665. // additionalCharge.Price = float_price
  7666. // }
  7667. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7668. // price := int64(json["price"].(float64))
  7669. // formatInt_price := strconv.FormatInt(price, 10)
  7670. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7671. // additionalCharge.Price = float_price
  7672. //}
  7673. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7674. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7675. additionalCharge.Price = price
  7676. }
  7677. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7678. count, _ := json["count"].(string)
  7679. counts, _ := strconv.ParseInt(count, 10, 64)
  7680. additionalCharge.Count = counts
  7681. }
  7682. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7683. item_name, _ := json["item_name"].(string)
  7684. additionalCharge.ItemName = item_name
  7685. }
  7686. return 0
  7687. }
  7688. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7689. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7690. utils.ErrorLog("drug_name")
  7691. return enums.ErrorCodeParamWrong
  7692. }
  7693. adviceName, _ := json["drug_name"].(string)
  7694. if len(adviceName) == 0 {
  7695. utils.ErrorLog("len(advice_name) == 0")
  7696. return enums.ErrorCodeParamWrong
  7697. }
  7698. advice.AdviceName = adviceName
  7699. adviceDesc, _ := json["advice_desc"].(string)
  7700. advice.AdviceDesc = adviceDesc
  7701. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7702. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7703. advice.DrugSpec = drugSpec
  7704. }
  7705. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7706. remark, _ := json["remark"].(string)
  7707. advice.Remark = remark
  7708. }
  7709. if json["id"] == nil {
  7710. advice.DrugId = 0
  7711. } else {
  7712. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7713. drug_id := int64(json["id"].(float64))
  7714. advice.DrugId = drug_id
  7715. }
  7716. }
  7717. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7718. groupno := int64(json["groupno"].(float64))
  7719. advice.Groupno = groupno
  7720. }
  7721. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7722. drugSpecUnit, _ := json["min_unit"].(string)
  7723. advice.DrugSpecUnit = drugSpecUnit
  7724. }
  7725. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7726. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7727. advice.SingleDose = singleDose
  7728. }
  7729. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7730. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7731. advice.SingleDoseUnit = singleDoseUnit
  7732. }
  7733. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7734. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7735. advice.PrescribingNumber = prescribingNumber
  7736. }
  7737. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7738. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7739. advice.PrescribingNumberUnit = prescribingNumberUnit
  7740. }
  7741. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7742. deliveryWay, _ := json["delivery_way"].(string)
  7743. advice.DeliveryWay = deliveryWay
  7744. }
  7745. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7746. executionFrequency, _ := json["execution_frequency"].(string)
  7747. advice.ExecutionFrequency = executionFrequency
  7748. }
  7749. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7750. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7751. advice.Price = price
  7752. }
  7753. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7754. med_list_codg, _ := json["medical_insurance_number"].(string)
  7755. advice.MedListCodg = med_list_codg
  7756. }
  7757. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7758. day := int64(json["day"].(float64))
  7759. advice.Day = day
  7760. }
  7761. advice.FrequencyType = 1
  7762. return 0
  7763. }
  7764. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7765. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7766. types := int64(json["type"].(float64))
  7767. project.Type = types
  7768. }
  7769. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7770. project_id := int64(json["project_id"].(float64))
  7771. project.ProjectId = project_id
  7772. }
  7773. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7774. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7775. project.Price = price
  7776. }
  7777. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7778. total, _ := json["total"].(string)
  7779. //totals, _ := strconv.ParseInt(total, 10, 64)
  7780. project.Count = total
  7781. }
  7782. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7783. medical_code, _ := json["medical_code"].(string)
  7784. project.MedListCodg = medical_code
  7785. }
  7786. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7787. single_dose, _ := json["single_dose"].(string)
  7788. project.SingleDose = single_dose
  7789. }
  7790. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7791. delivery_way, _ := json["delivery_way"].(string)
  7792. project.DeliveryWay = delivery_way
  7793. }
  7794. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7795. execution_frequency, _ := json["execution_frequency"].(string)
  7796. project.ExecutionFrequency = execution_frequency
  7797. }
  7798. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7799. remark, _ := json["remark"].(string)
  7800. project.Remark = remark
  7801. }
  7802. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7803. day, _ := json["number_days"].(string)
  7804. project.Day = day
  7805. }
  7806. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7807. unit, _ := json["unit"].(string)
  7808. project.Unit = unit
  7809. }
  7810. project.FrequencyType = 1
  7811. return 0
  7812. }
  7813. func (c *HisApiController) GetHisOrderListTwo() {
  7814. start_time := c.GetString("start_time")
  7815. end_time := c.GetString("end_time")
  7816. timeLayout := "2006-01-02"
  7817. loc, _ := time.LoadLocation("Local")
  7818. var startTime int64
  7819. if len(start_time) > 0 {
  7820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7821. if err != nil {
  7822. //fmt.Println(err)
  7823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7824. return
  7825. }
  7826. startTime = theTime.Unix()
  7827. }
  7828. var endTime int64
  7829. if len(end_time) > 0 {
  7830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7831. if err != nil {
  7832. utils.ErrorLog(err.Error())
  7833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7834. return
  7835. }
  7836. endTime = theTime.Unix()
  7837. }
  7838. adminUser := c.GetAdminUserInfo()
  7839. org_id := adminUser.CurrentOrgId
  7840. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7841. if err == nil {
  7842. c.ServeSuccessJSON(map[string]interface{}{
  7843. "order2": order,
  7844. })
  7845. } else {
  7846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7847. return
  7848. }
  7849. }
  7850. func (c *HisApiController) GetHisOrderList() {
  7851. page, _ := c.GetInt64("page", -1)
  7852. limit, _ := c.GetInt64("limit", -1)
  7853. start_time := c.GetString("start_time")
  7854. end_time := c.GetString("end_time")
  7855. types, _ := c.GetInt64("type", 0)
  7856. keywords := c.GetString("keywords")
  7857. p_type, _ := c.GetInt64("p_type", 0)
  7858. sort_type, _ := c.GetInt64("sort_type", 0)
  7859. charge_type, _ := c.GetInt64("charge_type", 0)
  7860. sch_type, _ := c.GetInt64("sch_type", 0)
  7861. zone_type, _ := c.GetInt64("zone_type", 0)
  7862. med_type, _ := c.GetInt64("med_type", 0)
  7863. timeLayout := "2006-01-02"
  7864. loc, _ := time.LoadLocation("Local")
  7865. var startTime int64
  7866. if len(start_time) > 0 {
  7867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7868. if err != nil {
  7869. //fmt.Println(err)
  7870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7871. return
  7872. }
  7873. startTime = theTime.Unix()
  7874. }
  7875. var endTime int64
  7876. if len(end_time) > 0 {
  7877. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7878. if err != nil {
  7879. utils.ErrorLog(err.Error())
  7880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7881. return
  7882. }
  7883. endTime = theTime.Unix()
  7884. }
  7885. adminUser := c.GetAdminUserInfo()
  7886. org_id := adminUser.CurrentOrgId
  7887. 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)
  7888. for _, item := range order {
  7889. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7890. item.DoctorName = info.Doctor
  7891. item.DepartmentName = info.XtHisDepartment.Name
  7892. }
  7893. if err == nil {
  7894. c.ServeSuccessJSON(map[string]interface{}{
  7895. "order": order,
  7896. "total": total,
  7897. })
  7898. } else {
  7899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7900. return
  7901. }
  7902. }
  7903. func (c *HisApiController) GetHisOrder() {
  7904. patient_id, _ := c.GetInt64("patient_id", 0)
  7905. number := c.GetString("number")
  7906. adminInfo := c.GetAdminUserInfo()
  7907. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7908. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7909. if err == nil {
  7910. c.ServeSuccessJSON(map[string]interface{}{
  7911. "order": order,
  7912. "prescription": prescriptions,
  7913. })
  7914. } else {
  7915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7916. return
  7917. }
  7918. }
  7919. func (c *HisApiController) GetHisPrescriptionList() {
  7920. record_date := c.GetString("record_date")
  7921. keywords := c.GetString("keywords")
  7922. page, _ := c.GetInt64("page")
  7923. limit, _ := c.GetInt64("limit")
  7924. sch_type, _ := c.GetInt64("sch_type")
  7925. timeLayout := "2006-01-02"
  7926. loc, _ := time.LoadLocation("Local")
  7927. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7928. if err != nil {
  7929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7930. return
  7931. }
  7932. recordDateTime := theTime.Unix()
  7933. adminInfo := c.GetAdminUserInfo()
  7934. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7935. //adminInfo := c.GetAdminUserInfo()
  7936. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7937. //fmt.Println(prescriptionOrder)
  7938. if err == nil {
  7939. c.ServeSuccessJSON(map[string]interface{}{
  7940. "order": prescriptionOrder,
  7941. "total": total,
  7942. })
  7943. } else {
  7944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7945. return
  7946. }
  7947. }
  7948. func (c *HisApiController) GetHisPrescriptionInfo() {
  7949. id, _ := c.GetInt64("id")
  7950. adminInfo := c.GetAdminUserInfo()
  7951. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7952. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7953. if err == nil {
  7954. c.ServeSuccessJSON(map[string]interface{}{
  7955. "order": prescriptionOrder,
  7956. "prescription": prescription,
  7957. })
  7958. } else {
  7959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7960. return
  7961. }
  7962. }
  7963. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7964. adminUser := c.GetAdminUserInfo()
  7965. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7966. c.ServeSuccessJSON(map[string]interface{}{
  7967. "config": config,
  7968. })
  7969. }
  7970. type ResultTwo struct {
  7971. ErrMsg interface{} `json:"err_msg"`
  7972. InfRefmsgid string `json:"inf_refmsgid"`
  7973. Infcode int64 `json:"infcode"`
  7974. Output struct {
  7975. Baseinfo struct {
  7976. Age float64 `json:"age"`
  7977. Brdy string `json:"brdy"`
  7978. Certno string `json:"certno"`
  7979. Gend string `json:"gend"`
  7980. Naty string `json:"naty"`
  7981. PsnCertType string `json:"psn_cert_type"`
  7982. PsnName string `json:"psn_name"`
  7983. PsnNo string `json:"psn_no"`
  7984. } `json:"baseinfo"`
  7985. Idetinfo []interface{} `json:"idetinfo"`
  7986. Iinfo []struct {
  7987. Balc float64 `json:"balc"`
  7988. CvlservFlag string `json:"cvlserv_flag"`
  7989. EmpName string `json:"emp_name"`
  7990. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7991. Insutype string `json:"insutype"`
  7992. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7993. PausInsuDate interface{} `json:"paus_insu_date"`
  7994. PsnInsuDate string `json:"psn_insu_date"`
  7995. PsnInsuStas string `json:"psn_insu_stas"`
  7996. PsnType string `json:"psn_type"`
  7997. } `json:"insuinfo"`
  7998. } `json:"output"`
  7999. RefmsgTime string `json:"refmsg_time"`
  8000. RespondTime string `json:"respond_time"`
  8001. Signtype interface{} `json:"signtype"`
  8002. WarnInfo interface{} `json:"warn_info"`
  8003. }
  8004. type ResultThree struct {
  8005. Cainfo interface{} `json:"cainfo"`
  8006. ErrMsg interface{} `json:"err_msg"`
  8007. InfRefmsgid string `json:"inf_refmsgid"`
  8008. Infcode int64 `json:"infcode"`
  8009. Output struct {
  8010. Data struct {
  8011. IptOtpNo string `json:"ipt_otp_no"`
  8012. MdtrtID string `json:"mdtrt_id"`
  8013. PsnNo string `json:"psn_no"`
  8014. } `json:"data"`
  8015. } `json:"output"`
  8016. RefmsgTime string `json:"refmsg_time"`
  8017. RespondTime string `json:"respond_time"`
  8018. Signtype interface{} `json:"signtype"`
  8019. WarnMsg interface{} `json:"warn_msg"`
  8020. }
  8021. type ResultFour struct {
  8022. Cainfo string `json:"cainfo"`
  8023. ErrMsg string `json:"err_msg"`
  8024. InfRefmsgid string `json:"inf_refmsgid"`
  8025. Infcode int64 `json:"infcode"`
  8026. Output struct {
  8027. Result []struct {
  8028. BasMednFlag string `json:"bas_medn_flag"`
  8029. ChldMedcFlag string `json:"chld_medc_flag"`
  8030. ChrgitmLv string `json:"chrgitm_lv"`
  8031. Cnt float64 `json:"cnt"`
  8032. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8033. DrtReimFlag string `json:"drt_reim_flag"`
  8034. FeedetlSn string `json:"feedetl_sn"`
  8035. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8036. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8037. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8038. ListSpItemFlag string `json:"list_sp_item_flag"`
  8039. LmtUsedFlag string `json:"lmt_used_flag"`
  8040. MedChrgitmType string `json:"med_chrgitm_type"`
  8041. Memo string `json:"memo"`
  8042. OverlmtAmt float64 `json:"overlmt_amt"`
  8043. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8044. Pric float64 `json:"pric"`
  8045. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8046. SelfpayProp float64 `json:"selfpay_prop"`
  8047. } `json:"result"`
  8048. } `json:"output"`
  8049. RefmsgTime string `json:"refmsg_time"`
  8050. RespondTime string `json:"respond_time"`
  8051. Signtype string `json:"signtype"`
  8052. WarnMsg string `json:"warn_msg"`
  8053. }
  8054. type ResultFive struct {
  8055. Insutype string `json:"insutype"`
  8056. }
  8057. type ResultSix struct {
  8058. Cainfo interface{} `json:"cainfo"`
  8059. ErrMsg interface{} `json:"err_msg"`
  8060. InfRefmsgid string `json:"inf_refmsgid"`
  8061. Infcode int64 `json:"infcode"`
  8062. Output struct {
  8063. } `json:"output"`
  8064. RefmsgTime string `json:"refmsg_time"`
  8065. RespondTime string `json:"respond_time"`
  8066. Signtype interface{} `json:"signtype"`
  8067. WarnMsg interface{} `json:"warn_msg"`
  8068. }
  8069. type ResultSeven struct {
  8070. Cainfo string `json:"cainfo"`
  8071. ErrMsg string `json:"err_msg"`
  8072. InfRefmsgid string `json:"inf_refmsgid"`
  8073. Infcode int64 `json:"infcode"`
  8074. Output struct {
  8075. Setldetail []interface{} `json:"setldetail"`
  8076. Setlinfo struct {
  8077. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8078. AcctPay float64 `json:"acct_pay"`
  8079. ActPayDedc float64 `json:"act_pay_dedc"`
  8080. Age float64 `json:"age"`
  8081. Balc float64 `json:"balc"`
  8082. Brdy string `json:"brdy"`
  8083. Certno string `json:"certno"`
  8084. ClrOptins string `json:"clr_optins"`
  8085. ClrType string `json:"clr_type"`
  8086. ClrWay string `json:"clr_way"`
  8087. CvlservFlag string `json:"cvlserv_flag"`
  8088. CvlservPay float64 `json:"cvlserv_pay"`
  8089. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8090. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8091. Gend string `json:"gend"`
  8092. HifesPay float64 `json:"hifes_pay"`
  8093. HifmiPay float64 `json:"hifmi_pay"`
  8094. HifobPay float64 `json:"hifob_pay"`
  8095. HifpPay float64 `json:"hifp_pay"`
  8096. HospPartAmt float64 `json:"hosp_part_amt"`
  8097. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8098. Insutype string `json:"insutype"`
  8099. MafPay float64 `json:"maf_pay"`
  8100. MdtrtCertType string `json:"mdtrt_cert_type"`
  8101. MdtrtID string `json:"mdtrt_id"`
  8102. MedType string `json:"med_type"`
  8103. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8104. MedinsSetlID string `json:"medins_setl_id"`
  8105. Naty string `json:"naty"`
  8106. OthPay float64 `json:"oth_pay"`
  8107. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8108. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8109. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8110. PsnCashPay float64 `json:"psn_cash_pay"`
  8111. PsnCertType string `json:"psn_cert_type"`
  8112. PsnName string `json:"psn_name"`
  8113. PsnNo string `json:"psn_no"`
  8114. PsnPartAmt float64 `json:"psn_part_amt"`
  8115. PsnType string `json:"psn_type"`
  8116. SetlID string `json:"setl_id"`
  8117. SetlTime string `json:"setl_time"`
  8118. } `json:"setlinfo"`
  8119. } `json:"output"`
  8120. RefmsgTime string `json:"refmsg_time"`
  8121. RespondTime string `json:"respond_time"`
  8122. Signtype interface{} `json:"signtype"`
  8123. WarnMsg interface{} `json:"warn_msg"`
  8124. }
  8125. type ResultEight struct {
  8126. Cainfo string `json:"cainfo"`
  8127. ErrMsg string `json:"err_msg"`
  8128. InfRefmsgid string `json:"inf_refmsgid"`
  8129. Infcode int64 `json:"infcode"`
  8130. Output struct {
  8131. Stmtinfo struct {
  8132. SetlOptins string `json:"setl_optins"`
  8133. StmtRslt string `json:"stmt_rslt"`
  8134. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8135. } `json:"stmtinfo"`
  8136. } `json:"output"`
  8137. RefmsgTime string `json:"refmsg_time"`
  8138. RespondTime string `json:"respond_time"`
  8139. Signtype interface{} `json:"signtype"`
  8140. WarnMsg interface{} `json:"warn_msg"`
  8141. }
  8142. type ResultNine struct {
  8143. Cainfo string `json:"cainfo"`
  8144. ErrMsg string `json:"err_msg"`
  8145. InfRefmsgid string `json:"inf_refmsgid"`
  8146. Infcode int64 `json:"infcode"`
  8147. Output struct {
  8148. FileQuryNo string `json:"file_qury_no"`
  8149. } `json:"output"`
  8150. RefmsgTime string `json:"refmsg_time"`
  8151. RespondTime string `json:"respond_time"`
  8152. Signtype interface{} `json:"signtype"`
  8153. WarnMsg interface{} `json:"warn_msg"`
  8154. }
  8155. type ResultTen struct {
  8156. Cainfo string `json:"cainfo"`
  8157. ErrMsg string `json:"err_msg"`
  8158. InfRefmsgid string `json:"inf_refmsgid"`
  8159. Infcode int64 `json:"infcode"`
  8160. Output struct {
  8161. DldEndtime string `json:"dld_endtime"`
  8162. FileQuryNo string `json:"file_qury_no"`
  8163. Filename string `json:"filename"`
  8164. } `json:"output"`
  8165. RefmsgTime string `json:"refmsg_time"`
  8166. RespondTime string `json:"respond_time"`
  8167. Signtype interface{} `json:"signtype"`
  8168. WarnMsg interface{} `json:"warn_msg"`
  8169. }
  8170. type ResultEleven struct {
  8171. Cainfo string `json:"cainfo"`
  8172. ErrMsg string `json:"err_msg"`
  8173. InfRefmsgid string `json:"inf_refmsgid"`
  8174. Infcode int64 `json:"infcode"`
  8175. Output struct {
  8176. Setlinfo struct {
  8177. FixmedinsName string `json:"fixmedins_name"`
  8178. FixmedinsCode string `json:"fixmedins_code"`
  8179. PsnNo string `json:"psn_no"`
  8180. PsnName string `json:"psn_name"`
  8181. HifobPay float64 `json:"hifob_pay"`
  8182. Gend string `json:"gend"`
  8183. Brdy string `json:"brdy"`
  8184. PsnCertType string `json:"psn_cert_type"`
  8185. PsnType string `json:"psn_type"`
  8186. EmpName string `json:"emp_name"`
  8187. Certno string `json:"certno"`
  8188. Insutype string `json:"insutype"`
  8189. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8190. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8191. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8192. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8193. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8194. ActPayDedc float64 `json:"act_pay_dedc"`
  8195. HifpPay float64 `json:"hifp_pay"`
  8196. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8197. CvlservPay float64 `json:"cvlserv_pay"`
  8198. HifesPay float64 `json:"hifes_pay"`
  8199. HifmiPay float64 `json:"hifmi_pay"`
  8200. MafPay float64 `json:"maf_pay"`
  8201. OthPay float64 `json:"oth_pay"`
  8202. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8203. PsnPay float64 `json:"psn_pay"`
  8204. AcctPay float64 `json:"acct_pay"`
  8205. CashPayamt float64 `json:"cash_payamt"`
  8206. Balc float64 `json:"balc"`
  8207. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8208. MedinsSetlId string `json:"medins_setl_id"`
  8209. RefdSetlFlag string `json:"refd_setl_flag"`
  8210. SetlTime string `json:"setl_time"`
  8211. MedType string `json:"med_type"`
  8212. } `json:"setlinfo"`
  8213. } `json:"output"`
  8214. RefmsgTime string `json:"refmsg_time"`
  8215. RespondTime string `json:"respond_time"`
  8216. Signtype interface{} `json:"signtype"`
  8217. WarnMsg interface{} `json:"warn_msg"`
  8218. }
  8219. type Custom struct {
  8220. DetItemFeeSumamt string
  8221. Cut string
  8222. FeedetlSn string
  8223. Price string
  8224. MedListCodg string
  8225. Type int64
  8226. AdviceId int64
  8227. ProjectId int64
  8228. ItemId int64
  8229. }
  8230. // 获取个人信息----挂号-----上传就诊信息
  8231. func (c *HisApiController) GetRegisterInfo() {
  8232. id, _ := c.GetInt64("id")
  8233. record_time := c.GetString("record_time")
  8234. settlementValue, _ := c.GetInt64("settlement_value")
  8235. medical_insurance_card := c.GetString("medical_insurance_card")
  8236. name := c.GetString("name")
  8237. id_card_type, _ := c.GetInt64("id_card_type")
  8238. certificates, _ := c.GetInt64("certificates")
  8239. medical_care, _ := c.GetInt64("medical_care")
  8240. birthday := c.GetString("birthday")
  8241. age, _ := c.GetInt64("age")
  8242. id_card := c.GetString("id_card")
  8243. register_type, _ := c.GetInt64("register")
  8244. doctor, _ := c.GetInt64("doctor")
  8245. department, _ := c.GetInt64("department")
  8246. gender, _ := c.GetInt64("sex")
  8247. phone := c.GetString("phone")
  8248. registration_fee, _ := c.GetFloat("registration_fee")
  8249. medical_expenses, _ := c.GetFloat("medical_expenses")
  8250. social_type, _ := c.GetInt64("social_type")
  8251. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8252. diagnosis_ids := c.GetString("diagnosis")
  8253. sick_type, _ := c.GetInt64("sick_type")
  8254. reg_type := c.GetString("p_type")
  8255. timeLayout := "2006-01-02"
  8256. loc, _ := time.LoadLocation("Local")
  8257. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8258. birthUnix := birthdays.Unix()
  8259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8260. if err != nil {
  8261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8262. return
  8263. }
  8264. recordDateTime := theTime.Unix()
  8265. adminInfo := c.GetAdminUserInfo()
  8266. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8267. if tempPatient.ID == 0 {
  8268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8269. return
  8270. }
  8271. var patient service.Patients
  8272. if id == 0 {
  8273. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8274. } else {
  8275. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8276. }
  8277. if patient.ID == 0 {
  8278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8279. return
  8280. }
  8281. if len(patient.IdCardNo) == 0 {
  8282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8283. return
  8284. }
  8285. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8286. if len(his) >= 1 {
  8287. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8288. if len(his) >= 1 && order.ID == 0 {
  8289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8290. return
  8291. }
  8292. }
  8293. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8294. fmt.Println(timeStr)
  8295. timeArr := strings.Split(timeStr, " ")
  8296. fmt.Println(timeArr)
  8297. timeArrTwo := strings.Split(timeArr[0], "-")
  8298. timeArrThree := strings.Split(timeArr[1], ":")
  8299. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8300. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8301. if len(lists) == 0 {
  8302. var hisPatient models.XtHisPatient
  8303. hisPatient = models.XtHisPatient{
  8304. Name: name,
  8305. Age: age,
  8306. Gender: gender,
  8307. Birthday: birthUnix,
  8308. Phone: phone,
  8309. MedicalTreatmentType: medical_care,
  8310. IdType: certificates,
  8311. IdCardNo: id_card,
  8312. BalanceAccountsType: settlementValue,
  8313. SocialType: social_type,
  8314. MedicalInsuranceNumber: medical_insurance_card,
  8315. RegisterType: register_type,
  8316. RegisterCost: registration_fee,
  8317. TreatmentCost: medical_expenses,
  8318. AdminUserId: adminInfo.AdminUser.Id,
  8319. UserOrgId: adminInfo.CurrentOrgId,
  8320. Status: 1,
  8321. RecordDate: recordDateTime,
  8322. IsReturn: 1,
  8323. PatientId: patient.ID,
  8324. Ctime: time.Now().Unix(),
  8325. Mtime: time.Now().Unix(),
  8326. Number: str,
  8327. IdCardType: id_card_type,
  8328. Departments: department,
  8329. Doctor: doctor,
  8330. PType: reg_type,
  8331. Diagnosis: diagnosis_ids,
  8332. SickType: sick_type,
  8333. }
  8334. service.CreateHisPatient(&hisPatient)
  8335. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8336. c.ServeSuccessJSON(map[string]interface{}{
  8337. "his_info": hisPatient,
  8338. })
  8339. } else {
  8340. //chrgBchno := rand.Intn(1000000) + 10000
  8341. var hisPatient models.XtHisPatient
  8342. hisPatient = models.XtHisPatient{
  8343. Name: name,
  8344. Age: age,
  8345. Gender: gender,
  8346. Birthday: birthUnix,
  8347. Phone: phone,
  8348. MedicalTreatmentType: medical_care,
  8349. IdType: certificates,
  8350. IdCardNo: id_card,
  8351. BalanceAccountsType: settlementValue,
  8352. SocialType: social_type,
  8353. MedicalInsuranceNumber: medical_insurance_card,
  8354. RegisterType: register_type,
  8355. RegisterCost: registration_fee,
  8356. TreatmentCost: medical_expenses,
  8357. AdminUserId: adminInfo.AdminUser.Id,
  8358. UserOrgId: adminInfo.CurrentOrgId,
  8359. Status: 1,
  8360. RecordDate: recordDateTime,
  8361. IsReturn: 1,
  8362. PatientId: patient.ID,
  8363. Ctime: time.Now().Unix(),
  8364. Mtime: time.Now().Unix(),
  8365. Number: str,
  8366. IdCardType: id_card_type,
  8367. Departments: department,
  8368. Doctor: doctor,
  8369. PType: reg_type,
  8370. Diagnosis: diagnosis_ids,
  8371. SickType: sick_type,
  8372. }
  8373. service.CreateHisPatient(&hisPatient)
  8374. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8375. c.ServeSuccessJSON(map[string]interface{}{
  8376. "his_info": hisPatient,
  8377. })
  8378. }
  8379. }
  8380. // 上传明细----结算
  8381. func (c *HisApiController) GetUploadInfo() {
  8382. id, _ := c.GetInt64("id")
  8383. record_time := c.GetString("record_time")
  8384. his_patient_id, _ := c.GetInt64("his_patient_id")
  8385. oth_desc := c.GetString("oth_desc")
  8386. pay_way, _ := c.GetInt64("pay_way")
  8387. pay_ways := c.GetString("pay_ways")
  8388. pay_price, _ := c.GetFloat("pay_price")
  8389. pay_card_no := c.GetString("pay_card_no")
  8390. discount_price, _ := c.GetFloat("discount_price")
  8391. preferential_price, _ := c.GetFloat("preferential_price")
  8392. reality_price, _ := c.GetFloat("reality_price")
  8393. found_price, _ := c.GetFloat("found_price")
  8394. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8395. private_price, _ := c.GetFloat("private_price")
  8396. timeLayout := "2006-01-02"
  8397. loc, _ := time.LoadLocation("Local")
  8398. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8399. fapiao_code := c.GetString("fapiao_code")
  8400. fapiao_number := c.GetString("fapiao_number")
  8401. diagnosis_id := c.GetString("diagnosis")
  8402. sick_type, _ := c.GetInt64("sick_type")
  8403. reg_type, _ := c.GetInt64("p_type")
  8404. order_id, _ := c.GetInt64("order_id")
  8405. cash_pay := c.GetString("cash_pay")
  8406. wechat_pay := c.GetString("wechat_pay")
  8407. ali_pay := c.GetString("ali_pay")
  8408. jifen_pay := c.GetString("jifen_pay")
  8409. band_card_pay := c.GetString("band_card_pay")
  8410. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8411. tmp_decimal := c.GetString("tmp_decimal")
  8412. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8413. var decimal float64 //本次使用的押金
  8414. var errmsg error
  8415. tx := service.XTWriteDB().Begin() //开了事务
  8416. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8417. defer func() {
  8418. if errmsg != nil {
  8419. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8420. tx.Rollback()
  8421. } else {
  8422. tx.Commit()
  8423. }
  8424. }()
  8425. fmt.Println("dec_way", dec_way)
  8426. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8427. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8428. return
  8429. }
  8430. if len(tmp_decimal) > 0 {
  8431. if tmp_decimal[0] == 45 {
  8432. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8433. return
  8434. }
  8435. }
  8436. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8437. fmt.Println(errs)
  8438. decimal = tt
  8439. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8440. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8441. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8442. if err != nil {
  8443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8444. return
  8445. }
  8446. recordDateTime := theTime.Unix()
  8447. adminUser := c.GetAdminUserInfo()
  8448. var prescriptions []*models.HisPrescription
  8449. var prescriptionsOne []*models.HisPrescription
  8450. var start_time int64
  8451. var end_time int64
  8452. ids_str := c.GetString("ids")
  8453. ids_arr := strings.Split(ids_str, ",")
  8454. if tempOrder.ID == 0 {
  8455. if settle_accounts_type == 1 { //日结
  8456. fmt.Println(reg_type)
  8457. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8458. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8459. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8460. } else {
  8461. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8462. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8463. }
  8464. } else { //月结
  8465. start_time_str := c.GetString("start_time")
  8466. end_time_str := c.GetString("end_time")
  8467. timeLayout := "2006-01-02"
  8468. loc, _ := time.LoadLocation("Local")
  8469. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8470. if err != nil {
  8471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8472. return
  8473. }
  8474. recordStartTime := theStartTime.Unix()
  8475. start_time = recordStartTime
  8476. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8477. if err != nil {
  8478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8479. return
  8480. }
  8481. recordEndTime := theEndTime.Unix()
  8482. end_time = recordEndTime
  8483. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8484. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8485. }
  8486. var goods []*models.DialysisBeforePrepareGoods
  8487. var newGoods []*models.NewDialysisBeforePrepareGoods
  8488. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8489. var infos []*models.HisDoctorAdviceInfo
  8490. var infoList []*models.HisDoctorAdviceInfo
  8491. var hisAdvice []*models.HisDoctorAdviceInfo
  8492. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8493. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8494. //判断库存不足
  8495. //结算出库开关
  8496. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8497. if settConfig.IsOpen == 1 {
  8498. //判断库存的地方
  8499. for _, info := range prescriptions {
  8500. if info.Type == 1 {
  8501. infos = append(infos, info.HisDoctorAdviceInfo...)
  8502. }
  8503. if info.Type == 2 {
  8504. for _, sumItem := range info.HisPrescriptionProject {
  8505. if sumItem.Type == 3 {
  8506. var good models.DialysisBeforePrepareGoods
  8507. var newGood models.NewDialysisBeforePrepareGoods
  8508. good.GoodId = sumItem.GoodInfo.ID
  8509. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8510. count, _ := strconv.Atoi(sumItem.Count)
  8511. good.Count = int64(count)
  8512. good.StorehouseId = houseConfig.StorehouseOutInfo
  8513. good.ProjectId = sumItem.ID
  8514. goods = append(goods, &good)
  8515. newGood.GoodId = sumItem.GoodInfo.ID
  8516. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8517. count2, _ := strconv.Atoi(sumItem.Count)
  8518. newGood.Count = int64(count2)
  8519. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8520. newGood.ProjectId = sumItem.ID
  8521. newGoods = append(newGoods, &newGood)
  8522. }
  8523. }
  8524. }
  8525. }
  8526. for _, info := range prescriptionsOne {
  8527. if info.Type == 1 {
  8528. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8529. }
  8530. if info.Type == 2 {
  8531. for _, sumItem := range info.HisPrescriptionProject {
  8532. if sumItem.Type == 3 {
  8533. var newGood models.NewDialysisBeforePrepareGoods
  8534. newGood.GoodId = sumItem.GoodInfo.ID
  8535. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8536. count2, _ := strconv.Atoi(sumItem.Count)
  8537. newGood.Count = int64(count2)
  8538. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8539. newGood.ProjectId = sumItem.ID
  8540. newGoodOne = append(newGoodOne, &newGood)
  8541. }
  8542. }
  8543. }
  8544. }
  8545. //判断
  8546. for _, itemOne := range infos {
  8547. for _, itemTwo := range hisAdvice {
  8548. if itemOne.DrugId == itemTwo.DrugId {
  8549. itemTwo.Child = append(itemTwo.Child, itemOne)
  8550. }
  8551. }
  8552. }
  8553. for _, itemTwo := range hisAdvice {
  8554. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8555. var sum_out_count int64
  8556. for _, itemThree := range itemTwo.Child {
  8557. var prescribing_number int64
  8558. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8559. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8560. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8561. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8562. }
  8563. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8564. prescribing_number = parseIntPrescribingNumber
  8565. }
  8566. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8567. prescribing_number = parseIntPrescribingNumber
  8568. }
  8569. sum_out_count += prescribing_number
  8570. }
  8571. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8572. if sum_out_count > drugStockOut.FlushCount {
  8573. c.ServeSuccessJSON(map[string]interface{}{
  8574. "msg": "2",
  8575. "drug": medical,
  8576. })
  8577. return
  8578. }
  8579. }
  8580. for _, itemOne := range newGoods {
  8581. for _, item := range newGoodOne {
  8582. if itemOne.GoodId == item.GoodId {
  8583. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8584. }
  8585. }
  8586. }
  8587. for _, item := range newGoodOne {
  8588. var sum_out_count_one int64
  8589. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8590. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8591. sum_out_count_one += itemOne.Count
  8592. }
  8593. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8594. fmt.Println("sum_out_count_one", sum_out_count_one)
  8595. fmt.Println("list.FlushCount", list.FlushCount)
  8596. if sum_out_count_one > list.FlushCount {
  8597. c.ServeSuccessJSON(map[string]interface{}{
  8598. "msg": "3",
  8599. "good": good,
  8600. })
  8601. return
  8602. }
  8603. }
  8604. }
  8605. timestamp := time.Now().Unix()
  8606. tempTime := time.Unix(timestamp, 0)
  8607. timeFormat := tempTime.Format("20060102150405")
  8608. chrgBchno := rand.Intn(100000) + 10000
  8609. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8610. strconv.FormatInt(his.PatientId, 10)
  8611. var ids []int64
  8612. for _, item := range prescriptions {
  8613. ids = append(ids, item.ID)
  8614. }
  8615. var total float64
  8616. for _, item := range prescriptions {
  8617. fmt.Println(item)
  8618. if item.Type == 1 { //药品
  8619. for _, subItem := range item.HisDoctorAdviceInfo {
  8620. total = total + (subItem.Price * subItem.PrescribingNumber)
  8621. }
  8622. }
  8623. if item.Type == 2 { //项目
  8624. for _, subItem := range item.HisPrescriptionProject {
  8625. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8626. total = total + (subItem.Price * cnt)
  8627. }
  8628. }
  8629. for _, subItem := range item.HisAdditionalCharge {
  8630. total = total + (subItem.Price * float64(subItem.Count))
  8631. }
  8632. }
  8633. if reg_type == 1111 || reg_type == 1112 {
  8634. reg_type = 11
  8635. }
  8636. tm := time.Unix(time.Now().Unix(), 0)
  8637. allTotal := fmt.Sprintf("%.4f", total)
  8638. totals, _ := strconv.ParseFloat(allTotal, 64)
  8639. order := &models.HisOrder{
  8640. UserOrgId: adminUser.CurrentOrgId,
  8641. HisPatientId: his.ID,
  8642. PatientId: id,
  8643. SettleAccountsDate: recordDateTime,
  8644. Ctime: time.Now().Unix(),
  8645. Mtime: time.Now().Unix(),
  8646. Status: 1,
  8647. OrderStatus: 2,
  8648. MdtrtId: his.Number,
  8649. Number: chrg_bchno,
  8650. MedfeeSumamt: totals,
  8651. PayWay: pay_way,
  8652. PayWays: pay_ways,
  8653. PayPrice: pay_price,
  8654. MedType: strconv.Itoa(int(reg_type)),
  8655. PayCardNo: pay_card_no,
  8656. DiscountPrice: discount_price,
  8657. PreferentialPrice: preferential_price,
  8658. RealityPrice: reality_price,
  8659. FoundPrice: found_price,
  8660. MedicalInsurancePrice: medical_insurance_price,
  8661. PrivatePrice: private_price,
  8662. SettleEndTime: end_time,
  8663. SettleStartTime: start_time,
  8664. PsnPartAmt: totals,
  8665. PsnCashPay: totals,
  8666. SettleType: settle_accounts_type,
  8667. FaPiaoCode: fapiao_code,
  8668. FaPiaoNumber: fapiao_number,
  8669. Diagnosis: diagnosis_id,
  8670. PType: 2,
  8671. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8672. Decimal: decimal,
  8673. OthDesc: oth_desc,
  8674. CashPay: cash_pay,
  8675. WechatPay: wechat_pay,
  8676. AliPay: ali_pay,
  8677. JifenPay: jifen_pay,
  8678. BandCardPay: band_card_pay,
  8679. Creator: adminUser.AdminUser.Id,
  8680. }
  8681. err = service.CreateOrderTX(order, tx)
  8682. if err != nil {
  8683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8684. return
  8685. }
  8686. var customs []*Custom
  8687. for _, item := range prescriptions {
  8688. if item.Type == 1 { //药品a
  8689. for _, subItem := range item.HisDoctorAdviceInfo {
  8690. cus := &Custom{
  8691. AdviceId: subItem.ID,
  8692. ProjectId: 0,
  8693. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8694. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8695. FeedetlSn: subItem.FeedetlSn,
  8696. Price: fmt.Sprintf("%.4f", subItem.Price),
  8697. MedListCodg: subItem.MedListCodg,
  8698. Type: 1,
  8699. }
  8700. customs = append(customs, cus)
  8701. }
  8702. }
  8703. if item.Type == 2 { //项目
  8704. for _, subItem := range item.HisPrescriptionProject {
  8705. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8706. cus := &Custom{
  8707. AdviceId: 0,
  8708. ProjectId: subItem.ID,
  8709. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8710. Cut: fmt.Sprintf("%.4f", cnt),
  8711. FeedetlSn: subItem.FeedetlSn,
  8712. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8713. MedListCodg: subItem.MedListCodg,
  8714. Type: 2,
  8715. }
  8716. customs = append(customs, cus)
  8717. }
  8718. }
  8719. for _, item := range item.HisAdditionalCharge {
  8720. cus := &Custom{
  8721. ItemId: item.ID,
  8722. AdviceId: 0,
  8723. ProjectId: 0,
  8724. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8725. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8726. FeedetlSn: item.FeedetlSn,
  8727. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8728. MedListCodg: item.XtHisAddtionConfig.Code,
  8729. Type: 3,
  8730. }
  8731. customs = append(customs, cus)
  8732. }
  8733. }
  8734. for _, item := range customs {
  8735. var advice_id int64 = 0
  8736. var project_id int64 = 0
  8737. var item_id int64 = 0
  8738. var types int64 = 0
  8739. if item.Type == 1 {
  8740. advice_id = item.AdviceId
  8741. project_id = 0
  8742. item_id = 0
  8743. } else if item.Type == 2 {
  8744. advice_id = 0
  8745. item_id = 0
  8746. project_id = item.ProjectId
  8747. } else if item.Type == 3 {
  8748. advice_id = 0
  8749. item_id = item.ItemId
  8750. project_id = 0
  8751. }
  8752. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8753. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8754. pric, _ := strconv.ParseFloat(item.Price, 32)
  8755. info := &models.HisOrderInfo{
  8756. OrderNumber: order.Number,
  8757. UploadDate: time.Now().Unix(),
  8758. AdviceId: advice_id,
  8759. DetItemFeeSumamt: detItemFeeSumamt,
  8760. Cnt: cut,
  8761. Pric: pric,
  8762. PatientId: id,
  8763. Status: 1,
  8764. Mtime: time.Now().Unix(),
  8765. Ctime: time.Now().Unix(),
  8766. UserOrgId: adminUser.CurrentOrgId,
  8767. HisPatientId: his.ID,
  8768. OrderId: order.ID,
  8769. ProjectId: project_id,
  8770. Type: types,
  8771. ItemId: item_id,
  8772. }
  8773. service.CreateOrderInfoTX(info, tx)
  8774. }
  8775. his.Diagnosis = diagnosis_id
  8776. his.SickType = sick_type
  8777. his.RegisterType = reg_type
  8778. his.MedicalTreatmentType = reg_type
  8779. service.UpdataHisPateintTX(&his, tx)
  8780. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8781. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8782. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8783. //判断是否使用了押金
  8784. if dec_way == "true" {
  8785. tmpstring := strconv.FormatInt(order.ID, 10)
  8786. //扣押金
  8787. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8788. order.Decimal = decimal
  8789. service.UpDateOrderTwo(order, tx)
  8790. if errmsg != nil {
  8791. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8792. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8793. return
  8794. }
  8795. }
  8796. if err == nil {
  8797. for _, info := range prescriptions {
  8798. if info.Type == 1 {
  8799. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8800. }
  8801. if info.Type == 2 {
  8802. for _, sumItem := range info.HisPrescriptionProject {
  8803. if sumItem.Type == 3 {
  8804. var good models.DialysisBeforePrepareGoods
  8805. var newGood models.NewDialysisBeforePrepareGoods
  8806. var oldGood models.OldDialysisBeforePrepareGoods
  8807. good.GoodId = sumItem.GoodInfo.ID
  8808. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8809. count, _ := strconv.Atoi(sumItem.Count)
  8810. good.Count = int64(count)
  8811. good.StorehouseId = houseConfig.StorehouseOutInfo
  8812. good.ProjectId = sumItem.ID
  8813. good.PatientId = sumItem.PatientId
  8814. goods = append(goods, &good)
  8815. newGood.GoodId = sumItem.GoodInfo.ID
  8816. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8817. count2, _ := strconv.Atoi(sumItem.Count)
  8818. newGood.Count = int64(count2)
  8819. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8820. newGood.ProjectId = sumItem.ID
  8821. newGood.PatientId = sumItem.HisPatientId
  8822. newGoods = append(newGoods, &newGood)
  8823. oldGood.GoodId = sumItem.GoodInfo.ID
  8824. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8825. count3, _ := strconv.Atoi(sumItem.Count)
  8826. oldGood.Count = int64(count3)
  8827. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8828. oldGood.ProjectId = sumItem.ID
  8829. oldGood.RecordDate = sumItem.RecordDate
  8830. oldGood.PatientId = sumItem.HisPatientId
  8831. oldGoods = append(oldGoods, &oldGood)
  8832. }
  8833. }
  8834. }
  8835. }
  8836. if settConfig.IsOpen == 1 {
  8837. for _, item := range infoList {
  8838. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8839. if medical.IsUse == 2 {
  8840. //药品出库
  8841. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8842. //查询默认仓库
  8843. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8844. //查询默认仓库剩余多少库存
  8845. var sum_count int64
  8846. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8847. for _, its := range stockInfo {
  8848. if its.MaxUnit == medical.MaxUnit {
  8849. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8850. }
  8851. sum_count += its.StockMaxNumber + its.StockMinNumber
  8852. }
  8853. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8854. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8855. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8856. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8857. }
  8858. }
  8859. orgId := c.GetAdminUserInfo().CurrentOrgId
  8860. if len(oldGoods) > 0 {
  8861. timeStr := time.Now().Format("2006-01-02")
  8862. timeArr := strings.Split(timeStr, "-")
  8863. total, _ := service.FindAllWarehouseOut(orgId)
  8864. total = total + 1
  8865. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8866. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8867. number = number + total
  8868. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8869. operation_time := time.Now().Unix()
  8870. creater := c.GetAdminUserInfo().AdminUser.Id
  8871. //查询默认出库仓库库存
  8872. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8873. recordDateStr := time.Now().Format("2006-01-02")
  8874. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8875. nowtime := recordDate.Unix()
  8876. warehouseOut := models.WarehouseOut{
  8877. WarehouseOutOrderNumber: warehousing_out_order,
  8878. OperationTime: operation_time,
  8879. OrgId: orgId,
  8880. Creater: creater,
  8881. Ctime: time.Now().Unix(),
  8882. Status: 1,
  8883. WarehouseOutTime: nowtime,
  8884. Type: 1,
  8885. StorehouseId: storeConfig.StorehouseOutInfo,
  8886. IsCheck: 1,
  8887. OrderId: order.ID,
  8888. IsSys: 5,
  8889. }
  8890. //查询是否生成出库单
  8891. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8892. if out.ID == 0 {
  8893. service.AddSigleWarehouseOut(&warehouseOut)
  8894. }
  8895. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8896. for _, item := range oldGoods {
  8897. dialyPrepareOne := models.DialysisBeforePrepare{
  8898. GoodTypeId: item.GoodTypeId,
  8899. GoodId: item.GoodId,
  8900. PatientId: his.PatientId,
  8901. RecordDate: item.RecordDate,
  8902. UserOrgId: adminUser.CurrentOrgId,
  8903. Count: item.Count,
  8904. Ctime: time.Now().Unix(),
  8905. Creater: adminUser.AdminUser.Id,
  8906. CommdityCode: item.CommdityCode,
  8907. Status: 1,
  8908. StorehouseId: houseConfig.StorehouseOutInfo,
  8909. }
  8910. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8911. //非零用
  8912. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8913. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8914. //查询剩余库存
  8915. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8916. var sum_count int64
  8917. for _, item := range goodList {
  8918. sum_count += item.StockCount
  8919. }
  8920. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8921. //耗材
  8922. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8923. }
  8924. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8925. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8926. //查询剩余库存
  8927. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8928. var sum_count int64
  8929. for _, item := range goodList {
  8930. sum_count += item.StockCount
  8931. }
  8932. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8933. //耗材
  8934. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8935. }
  8936. }
  8937. }
  8938. }
  8939. c.ServeSuccessJSON(map[string]interface{}{
  8940. "msg": "结算成功",
  8941. })
  8942. }
  8943. }
  8944. }
  8945. // 退款
  8946. func (c *HisApiController) Refund() {
  8947. order_id, _ := c.GetInt64("order_id")
  8948. order, _ := service.GetHisOrderByID(order_id)
  8949. adminUser := c.GetAdminUserInfo()
  8950. orgid := c.GetAdminUserInfo().CurrentOrgId
  8951. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8952. if err != nil {
  8953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8954. return
  8955. }
  8956. tmp := strconv.FormatInt(order.ID, 10)
  8957. //当押金不为零时产生退费记录
  8958. if order.Decimal != 0 {
  8959. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8960. if err != nil {
  8961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8962. return
  8963. }
  8964. }
  8965. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8966. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8967. var goods []*models.DialysisBeforePrepareGoods
  8968. var newGoods []*models.NewDialysisBeforePrepareGoods
  8969. var infos []*models.HisDoctorAdviceInfo
  8970. for _, info := range orders {
  8971. if info.AdviceId > 0 && info.ProjectId == 0 {
  8972. infos = append(infos, &info.HisDoctorAdviceInfo)
  8973. }
  8974. if info.ProjectId > 0 && info.AdviceId == 0 {
  8975. if info.HisPrescriptionProject.Type == 3 {
  8976. var good models.DialysisBeforePrepareGoods
  8977. var newGood models.NewDialysisBeforePrepareGoods
  8978. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8979. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8980. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8981. good.Count = int64(count)
  8982. good.StorehouseId = houseConfig.StorehouseOutInfo
  8983. good.ProjectId = info.HisPrescriptionProject.ID
  8984. good.PatientId = info.PatientId
  8985. good.OrderId = order_id
  8986. goods = append(goods, &good)
  8987. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8988. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8989. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8990. newGood.Count = int64(count2)
  8991. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8992. newGood.ProjectId = info.HisPrescriptionProject.ID
  8993. newGood.RecordDate = order.SettleAccountsDate
  8994. newGood.UserOrgId = order.UserOrgId
  8995. newGood.PatientId = info.PatientId
  8996. newGood.OrderId = order_id
  8997. newGoods = append(newGoods, &newGood)
  8998. }
  8999. }
  9000. }
  9001. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9002. if settConfig.IsOpen == 1 {
  9003. for _, item := range infos {
  9004. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9005. }
  9006. for _, item := range newGoods {
  9007. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9008. }
  9009. }
  9010. c.ServeSuccessJSON(map[string]interface{}{
  9011. "msg": "退费成功",
  9012. })
  9013. }
  9014. func (c *HisApiController) RefundNumber() {
  9015. his_patient_id, _ := c.GetInt64("id")
  9016. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9017. info.Status = 0
  9018. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9019. if count > 0 {
  9020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9021. return
  9022. }
  9023. err := service.SaveHisPatient(info)
  9024. if err == nil {
  9025. c.ServeSuccessJSON(map[string]interface{}{
  9026. "msg": "退号成功",
  9027. })
  9028. } else {
  9029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9030. return
  9031. }
  9032. }
  9033. func (this *HisApiController) AdditionalCharge() {
  9034. dataBody := make(map[string]interface{}, 0)
  9035. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9036. fmt.Println(err)
  9037. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9038. patient_id := int64(dataBody["patient_id"].(float64))
  9039. medicineData, _ := dataBody["medicineData"].([]interface{})
  9040. adminUserInfo := this.GetAdminUserInfo()
  9041. orgId := adminUserInfo.CurrentOrgId
  9042. admin_user_id := adminUserInfo.AdminUser.Id
  9043. timeStr := time.Now().Format("2006-01-02")
  9044. timeLayout := "2006-01-02 15:04:05"
  9045. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9046. timenow := timeStringToTime.Unix()
  9047. var additionalCharges []*models.HisAdditionalCharge
  9048. for _, item := range medicineData {
  9049. var randNum int
  9050. randNum = rand.Intn(10000) + 1000
  9051. timestamp := time.Now().Unix()
  9052. tempTime := time.Unix(timestamp, 0)
  9053. timeFormat := tempTime.Format("20060102150405")
  9054. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9055. items := item.(map[string]interface{})
  9056. money := items["price"].(string)
  9057. item_id_str := items["item_id"].(string)
  9058. name := items["name"].(string)
  9059. id_str := items["id"].(string)
  9060. moneys, _ := strconv.ParseInt(money, 10, 64)
  9061. monStr := strconv.FormatInt(moneys, 10)
  9062. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9063. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9064. id, _ := strconv.ParseInt(id_str, 10, 64)
  9065. additionalCharge := &models.HisAdditionalCharge{
  9066. ID: id,
  9067. HisPatientId: his_patient_id,
  9068. UserOrgId: orgId,
  9069. PatientId: patient_id,
  9070. RecordDate: timenow,
  9071. Price: monneyStr,
  9072. Status: 1,
  9073. ItemName: name,
  9074. ItemId: item_id,
  9075. AdminUserId: admin_user_id,
  9076. CreatedTime: time.Now().Unix(),
  9077. OrderStatus: 0,
  9078. PrescriptionNumber: "",
  9079. BatchNumber: "",
  9080. FeedetlSn: p_number,
  9081. }
  9082. service.CreateAdditionalCharge(additionalCharge)
  9083. additionalCharges = append(additionalCharges, additionalCharge)
  9084. }
  9085. this.ServeSuccessJSON(map[string]interface{}{
  9086. "msg": "添加成功",
  9087. "additional_charges": additionalCharges,
  9088. })
  9089. }
  9090. func (this *HisApiController) DeleteAddition() {
  9091. id, _ := this.GetInt64("id")
  9092. //TODO 需要判断是否已经结算
  9093. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9094. if err == nil {
  9095. this.ServeSuccessJSON(map[string]interface{}{
  9096. "msg": "删除成功",
  9097. })
  9098. return
  9099. } else {
  9100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9101. return
  9102. }
  9103. }
  9104. func (this *HisApiController) GetAdminUsers() {
  9105. adminUser := this.GetAdminUserInfo()
  9106. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9107. this.ServeSuccessJSON(map[string]interface{}{
  9108. "doctors": doctors,
  9109. })
  9110. }
  9111. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9112. change_type, _ := this.GetInt64("type", 0)
  9113. record_date := this.GetString("record_time")
  9114. patient_id, _ := this.GetInt64("patient_id", 0)
  9115. p_type, _ := this.GetInt64("p_type", 0)
  9116. timeLayout := "2006-01-02"
  9117. loc, _ := time.LoadLocation("Local")
  9118. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9119. record_time := theAdviceRecordTime.Unix()
  9120. adminUserInfo := this.GetAdminUserInfo()
  9121. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9122. if err == nil {
  9123. if len(prescriptions) == 0 {
  9124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9125. return
  9126. } else {
  9127. this.ServeSuccessJSON(map[string]interface{}{
  9128. "prescriptions": prescriptions,
  9129. })
  9130. return
  9131. }
  9132. } else {
  9133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9134. return
  9135. }
  9136. }
  9137. func (this *HisApiController) GetCallHisPrescription() {
  9138. patient_id, _ := this.GetInt64("patient_id", 0)
  9139. timeLayout := "2006-01-02"
  9140. loc, _ := time.LoadLocation("Local")
  9141. start_time := this.GetString("start_time")
  9142. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9143. end_time := this.GetString("end_time")
  9144. p_type, _ := this.GetInt64("p_type")
  9145. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9146. adminUserInfo := this.GetAdminUserInfo()
  9147. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9148. //if
  9149. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9150. //
  9151. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9152. if adminUserInfo.CurrentOrgId == 10265 {
  9153. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9154. if config.ID > 0 && config.IsOpen == 1 {
  9155. for _, subitems := range prescriptions {
  9156. for _, item := range subitems.VMHisPrescription {
  9157. for _, subItem := range item.HisDoctorAdviceInfo {
  9158. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9159. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9160. if info.RetailPrice > 0 {
  9161. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9162. subItem.Drug.RetailPrice = info.RetailPrice * float64(drug.MinNumber)
  9163. }
  9164. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9165. subItem.Drug.MinPrice = info.RetailPrice
  9166. subItem.Drug.RetailPrice = info.RetailPrice
  9167. }
  9168. }
  9169. }
  9170. }
  9171. }
  9172. }
  9173. if config.ID > 0 && config.IsOpen == 1 {
  9174. for _, subitems := range prescriptions {
  9175. for _, item := range subitems.VMHisPrescription {
  9176. for _, subItem := range item.HisPrescriptionProject {
  9177. if subItem.Type == 3 {
  9178. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9179. if info.Price > 0 {
  9180. subItem.GoodInfo.PackingPrice = info.Price
  9181. }
  9182. }
  9183. }
  9184. }
  9185. }
  9186. }
  9187. }
  9188. if err == nil {
  9189. this.ServeSuccessJSON(map[string]interface{}{
  9190. "prescriptions": prescriptions,
  9191. })
  9192. return
  9193. } else {
  9194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9195. return
  9196. }
  9197. }
  9198. func (this *HisApiController) GetHisDayPrescription() {
  9199. timeLayout := "2006-01-02"
  9200. loc, _ := time.LoadLocation("Local")
  9201. start_time := this.GetString("start_time")
  9202. patient_id, _ := this.GetInt64("patient_id", 0)
  9203. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9204. end_time := this.GetString("end_time")
  9205. p_type, _ := this.GetInt64("p_type")
  9206. order_status, _ := this.GetInt64("type")
  9207. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9208. adminUserInfo := this.GetAdminUserInfo()
  9209. var dayHisPrescription []*models.HisPrescription
  9210. var err error
  9211. if order_status == 1 || order_status == 0 {
  9212. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9213. } else if order_status == 2 {
  9214. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9215. }
  9216. var settle_total float64
  9217. for _, item := range dayHisPrescription {
  9218. if len(item.HisPrescriptionProject) > 0 {
  9219. for _, subItem := range item.HisPrescriptionProject {
  9220. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9221. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9222. settle_total = settle_total + total
  9223. }
  9224. }
  9225. if len(item.HisDoctorAdviceInfo) > 0 {
  9226. for _, subItem := range item.HisDoctorAdviceInfo {
  9227. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9228. settle_total = settle_total + total
  9229. }
  9230. }
  9231. }
  9232. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9233. if err == nil {
  9234. this.ServeSuccessJSON(map[string]interface{}{
  9235. "day_prescription": dayHisPrescription,
  9236. "settle_total": settle_total,
  9237. })
  9238. return
  9239. } else {
  9240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9241. return
  9242. }
  9243. }
  9244. func (c *HisApiController) GetHisChargePatientList() {
  9245. record_date := c.GetString("record_date")
  9246. order_status, _ := c.GetInt64("type")
  9247. sch_type, _ := c.GetInt64("sch_type")
  9248. timeLayout := "2006-01-02"
  9249. loc, _ := time.LoadLocation("Local")
  9250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9251. if err != nil {
  9252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9253. return
  9254. }
  9255. recordDateTime := theTime.Unix()
  9256. adminInfo := c.GetAdminUserInfo()
  9257. var tempPatients []*service.NewTempPatients
  9258. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9259. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9260. if order_status != 2 {
  9261. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9262. } else {
  9263. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9264. }
  9265. } else {
  9266. if order_status != 2 {
  9267. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9268. } else {
  9269. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9270. }
  9271. }
  9272. var patients []*service.NewTempPatients
  9273. var patients_two []*service.NewTempPatients
  9274. for _, item := range tempPatients {
  9275. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9276. //过滤掉没挂号的和没开处方的
  9277. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9278. patients = append(patients, item)
  9279. }
  9280. //过滤掉没挂号的
  9281. if len(item.HisPatient) > 0 {
  9282. patients_two = append(patients_two, item)
  9283. }
  9284. } else {
  9285. if len(item.HisPrescription) > 0 {
  9286. patients = append(patients, item)
  9287. }
  9288. }
  9289. }
  9290. c.ServeSuccessJSON(map[string]interface{}{
  9291. "list": patients,
  9292. "list_two": patients_two,
  9293. })
  9294. }
  9295. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9296. record_date := c.GetString("record_date")
  9297. timeLayout := "2006-01-02"
  9298. loc, _ := time.LoadLocation("Local")
  9299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9300. if err != nil {
  9301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9302. return
  9303. }
  9304. recordDateTime := theTime.Unix()
  9305. adminUser := c.GetAdminUserInfo()
  9306. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9307. var patients []*service.Patients
  9308. for _, item := range tempPatients {
  9309. if item.HisPatient.ID == 0 {
  9310. patients = append(patients, item)
  9311. }
  9312. }
  9313. c.ServeSuccessJSON(map[string]interface{}{
  9314. "list": patients,
  9315. //"list_two": patients_two,
  9316. })
  9317. }
  9318. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9319. newArr = make([]*service.Patients, 0)
  9320. for i := 0; i < len(patient); i++ {
  9321. repeat := false
  9322. for j := i + 1; j < len(patient); j++ {
  9323. if patient[i].ID == patient[j].ID {
  9324. repeat = true
  9325. break
  9326. }
  9327. }
  9328. if !repeat {
  9329. newArr = append(newArr, patient[i])
  9330. }
  9331. }
  9332. return
  9333. }
  9334. func (c *HisApiController) GetHisChargePatientInfo() {
  9335. patient_id, _ := c.GetInt64("patient_id")
  9336. his_patient_id, _ := c.GetInt64("his_patient_id")
  9337. record_date := c.GetString("record_date")
  9338. //start_time := c.GetString("start_time")
  9339. //end_time := c.GetString("end_time")
  9340. order_status, _ := c.GetInt64("type", 0)
  9341. p_type, _ := c.GetInt64("p_type", 0)
  9342. order_id, _ := c.GetInt64("order_id", 0)
  9343. timeLayout := "2006-01-02"
  9344. loc, _ := time.LoadLocation("Local")
  9345. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9346. if err != nil {
  9347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9348. return
  9349. }
  9350. recordDateTime := theTime.Unix()
  9351. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9352. //if err != nil {
  9353. //
  9354. //}
  9355. //startRecordDateTime := startTime.Unix()
  9356. //
  9357. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9358. //if err != nil {
  9359. //
  9360. //}
  9361. //endRecordDateTime := endTime.Unix()
  9362. admin := c.GetAdminUserInfo()
  9363. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9364. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9365. var prescriptions []*models.HisPrescription
  9366. //var unChargeMonthPrescriptions []*models.HisPrescription
  9367. order, _ := service.GetHisOrderByID(order_id)
  9368. if order_status == 1 || order_status == 0 {
  9369. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9370. } else if order_status == 2 {
  9371. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9372. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9373. }
  9374. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9375. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9376. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9377. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9378. //获取所有科室信息
  9379. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9380. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9381. c.ServeSuccessJSON(map[string]interface{}{
  9382. "his_info": his_patient_info,
  9383. "xt_info": xt_patient_info,
  9384. "prescription": prescriptions,
  9385. "case_history": case_history,
  9386. "info": patientPrescriptionInfo,
  9387. "last_info": lastPatientPrescriptionInfo,
  9388. "order": order,
  9389. "doctors": doctors,
  9390. "department": department,
  9391. "sch": sch,
  9392. })
  9393. return
  9394. }
  9395. func (c *HisApiController) GetAllOrderDetail() {
  9396. order_id, _ := c.GetInt64("id", 0)
  9397. order, _ := service.GetHisOrderByID(order_id)
  9398. if order.ID == 0 {
  9399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9400. return
  9401. }
  9402. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9403. org_id := c.GetAdminUserInfo().CurrentOrgId
  9404. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9405. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9406. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9407. c.ServeSuccessJSON(map[string]interface{}{
  9408. "order": order,
  9409. "order_info": order_info,
  9410. "patient": patient,
  9411. "admin_info": adminInfo,
  9412. "hospital_record": record,
  9413. })
  9414. return
  9415. }
  9416. func (c *HisApiController) GetAllOrderDetailCollect() {
  9417. order_id, _ := c.GetInt64("id", 0)
  9418. order, _ := service.GetHisOrderByID(order_id)
  9419. if order.ID == 0 {
  9420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9421. return
  9422. }
  9423. org_id := c.GetAdminUserInfo().CurrentOrgId
  9424. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9425. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9426. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9427. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9428. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9429. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9430. var bedCostTotal float64 = 0 //床位总费
  9431. //var bedCostSelfTotal float64 = 0 //床位自费
  9432. var operationCostTotal float64 = 0 //手术费
  9433. //var operationCostSelfTotal float64 = 0 //手术费
  9434. var otherCostTotal float64 = 0 //其他费用
  9435. //var otherCostSelfTotal float64 = 0 //其他费用
  9436. var materialCostTotal float64 = 0 //材料费
  9437. //var materialCostSelfTotal float64 = 0 //材料费
  9438. var westernMedicineCostTotal float64 = 0 //西药费
  9439. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9440. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9441. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9442. var checkCostTotal float64 = 0 //检查费
  9443. //var checkCostSelfTotal float64 = 0 //检查费
  9444. var laboratoryCostTotal float64 = 0 //化验费
  9445. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9446. var treatCostTotal float64 = 0 //治疗费用
  9447. //var treatCostSelfTotal float64 = 0 //治疗费用
  9448. var zhenChaCostTotal float64 = 0 //其他费用
  9449. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9450. decimal.DivisionPrecision = 2
  9451. var BalanceAccountsType int64
  9452. if his.ID > 0 {
  9453. BalanceAccountsType = his.BalanceAccountsType
  9454. } else {
  9455. BalanceAccountsType = record.BalanceAccountsType
  9456. }
  9457. if BalanceAccountsType != 2 {
  9458. for _, item := range order_info {
  9459. if org_id == 10215 {
  9460. if item.MedChrgitmType == "01" { //床位费
  9461. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9462. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9463. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9464. }
  9465. if item.MedChrgitmType == "02" { //诊察费
  9466. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9467. //zhenChaCostSelfTotal = zhenChaCostTotal
  9468. }
  9469. if item.MedChrgitmType == "03" { //检查费
  9470. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9471. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9472. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9473. }
  9474. //if item.MedChrgitmType == "02" { //检查费
  9475. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9476. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9477. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9478. //}
  9479. if item.MedChrgitmType == "04" { //化验费
  9480. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9481. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9482. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9483. }
  9484. if item.MedChrgitmType == "05" { //治疗费
  9485. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9486. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9487. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9488. }
  9489. if item.MedChrgitmType == "06" { //手术费
  9490. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9491. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9492. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9493. }
  9494. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9495. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9496. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9497. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9498. }
  9499. if item.MedChrgitmType == "09" { //西药费
  9500. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9501. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9502. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9503. }
  9504. if item.MedChrgitmType == "11" { //中成费
  9505. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9506. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9507. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9508. }
  9509. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9510. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9511. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9512. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9513. }
  9514. } else if org_id == 10188 || org_id == 10217 {
  9515. if item.MedChrgitmType == "01" { //床位费
  9516. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9517. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9518. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9519. }
  9520. if item.MedChrgitmType == "02" { //诊察费
  9521. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9522. //zhenChaCostSelfTotal = zhenChaCostTotal
  9523. }
  9524. if item.MedChrgitmType == "03" { //检查费
  9525. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9526. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9527. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9528. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9529. }
  9530. //if item.MedChrgitmType == "02" { //检查费
  9531. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9532. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9533. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9534. //}
  9535. if item.MedChrgitmType == "04" { //化验费
  9536. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9537. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9538. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9539. }
  9540. if item.MedChrgitmType == "05" { //治疗费
  9541. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9542. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9543. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9544. }
  9545. if item.MedChrgitmType == "06" { //手术费
  9546. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9547. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9548. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9549. }
  9550. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9551. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9552. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9553. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9554. }
  9555. if item.MedChrgitmType == "09" { //西药费
  9556. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9557. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9558. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9559. }
  9560. if item.MedChrgitmType == "11" { //中成费
  9561. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9562. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9563. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9564. }
  9565. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9566. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9567. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9568. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9569. }
  9570. } else {
  9571. if item.MedChrgitmType == "01" { //床位费
  9572. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9573. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9574. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9575. }
  9576. //if item.MedChrgitmType == "02" { //诊察费
  9577. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9578. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9579. //}
  9580. if item.MedChrgitmType == "03" { //检查费
  9581. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9582. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9583. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9584. }
  9585. //if item.MedChrgitmType == "02" { //检查费
  9586. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9587. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9588. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9589. //}
  9590. if item.MedChrgitmType == "04" { //化验费
  9591. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9592. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9593. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9594. }
  9595. if item.MedChrgitmType == "05" { //治疗费
  9596. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9597. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9598. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9599. }
  9600. if item.MedChrgitmType == "06" { //手术费
  9601. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9602. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9603. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9604. }
  9605. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9606. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9607. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9608. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9609. }
  9610. if item.MedChrgitmType == "09" { //西药费
  9611. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9612. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9613. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9614. }
  9615. if item.MedChrgitmType == "11" { //中成费
  9616. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9617. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9618. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9619. }
  9620. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9621. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9622. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9623. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9624. }
  9625. }
  9626. }
  9627. c.ServeSuccessJSON(map[string]interface{}{
  9628. "order": order,
  9629. "order_info": order_info,
  9630. "patient": patient,
  9631. "admin_info": adminInfo,
  9632. "his_hospital": record,
  9633. "bedCostTotal": bedCostTotal,
  9634. "operationCostTotal": operationCostTotal,
  9635. "otherCostTotal": otherCostTotal,
  9636. "materialCostTotal": materialCostTotal,
  9637. "westernMedicineCostTotal": westernMedicineCostTotal,
  9638. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9639. "checkCostTotal": checkCostTotal,
  9640. "zhenChaCostTotal": zhenChaCostTotal,
  9641. "laboratoryCostTotal": laboratoryCostTotal,
  9642. "treatCostTotal": treatCostTotal,
  9643. })
  9644. } else {
  9645. for _, item := range order_info {
  9646. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9647. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9648. item.MedChrgitmType = "09"
  9649. }
  9650. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9651. if item.HisPrescriptionProject.Type == 2 {
  9652. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9653. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9654. case 0:
  9655. item.MedChrgitmType = "0"
  9656. break
  9657. case 1:
  9658. item.MedChrgitmType = "14"
  9659. break
  9660. case 2:
  9661. item.MedChrgitmType = "05"
  9662. break
  9663. case 3:
  9664. item.MedChrgitmType = "03"
  9665. break
  9666. case 4:
  9667. item.MedChrgitmType = "03"
  9668. break
  9669. case 5:
  9670. item.MedChrgitmType = "08"
  9671. break
  9672. case 6:
  9673. item.MedChrgitmType = "14"
  9674. break
  9675. case 7:
  9676. item.MedChrgitmType = "14"
  9677. break
  9678. case 8:
  9679. item.MedChrgitmType = "03"
  9680. break
  9681. case 9:
  9682. item.MedChrgitmType = "14"
  9683. break
  9684. case 10:
  9685. item.MedChrgitmType = "14"
  9686. break
  9687. case 11:
  9688. item.MedChrgitmType = "06"
  9689. break
  9690. case 12:
  9691. item.MedChrgitmType = "12"
  9692. break
  9693. case 13:
  9694. item.MedChrgitmType = "01"
  9695. break
  9696. case 14:
  9697. item.MedChrgitmType = "04"
  9698. break
  9699. case 15:
  9700. item.MedChrgitmType = "14"
  9701. break
  9702. }
  9703. } else {
  9704. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9705. case 1:
  9706. item.MedChrgitmType = "14"
  9707. break
  9708. case 2:
  9709. item.MedChrgitmType = "05"
  9710. break
  9711. case 3:
  9712. item.MedChrgitmType = "04"
  9713. break
  9714. case 4:
  9715. item.MedChrgitmType = "14"
  9716. break
  9717. case 5:
  9718. item.MedChrgitmType = "08"
  9719. break
  9720. case 6:
  9721. item.MedChrgitmType = "14"
  9722. break
  9723. case 7:
  9724. item.MedChrgitmType = "14"
  9725. break
  9726. case 8:
  9727. item.MedChrgitmType = "03"
  9728. break
  9729. case 9:
  9730. item.MedChrgitmType = "14"
  9731. break
  9732. }
  9733. }
  9734. } else if item.HisPrescriptionProject.Type == 3 {
  9735. item.MedChrgitmType = "08"
  9736. }
  9737. }
  9738. }
  9739. for _, item := range order_info {
  9740. if org_id == 10215 {
  9741. if item.MedChrgitmType == "01" { //床位费
  9742. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9743. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9744. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9745. }
  9746. if item.MedChrgitmType == "02" { //诊察费
  9747. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9748. //zhenChaCostSelfTotal = zhenChaCostTotal
  9749. }
  9750. if item.MedChrgitmType == "03" { //检查费
  9751. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9752. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9753. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9754. }
  9755. //if item.MedChrgitmType == "02" { //检查费
  9756. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9757. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9758. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9759. //}
  9760. if item.MedChrgitmType == "04" { //化验费
  9761. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9762. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9763. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9764. }
  9765. if item.MedChrgitmType == "05" { //治疗费
  9766. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9767. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9768. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9769. }
  9770. if item.MedChrgitmType == "06" { //手术费
  9771. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9772. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9773. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9774. }
  9775. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9776. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9777. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9778. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9779. }
  9780. if item.MedChrgitmType == "09" { //西药费
  9781. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9782. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9783. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9784. }
  9785. if item.MedChrgitmType == "11" { //中成费
  9786. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9787. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9788. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9789. }
  9790. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9791. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9792. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9793. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9794. }
  9795. } else {
  9796. if item.MedChrgitmType == "01" { //床位费
  9797. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9798. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9799. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9800. }
  9801. //if item.MedChrgitmType == "02" { //诊察费
  9802. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9803. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9804. //}
  9805. if item.MedChrgitmType == "03" { //检查费
  9806. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9807. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9808. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9809. }
  9810. //if item.MedChrgitmType == "02" { //检查费
  9811. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9812. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9813. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9814. //}
  9815. if item.MedChrgitmType == "04" { //化验费
  9816. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9817. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9818. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9819. }
  9820. if item.MedChrgitmType == "05" { //治疗费
  9821. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9822. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9823. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9824. }
  9825. if item.MedChrgitmType == "06" { //手术费
  9826. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9827. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9828. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9829. }
  9830. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9831. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9832. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9833. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9834. }
  9835. if item.MedChrgitmType == "09" { //西药费
  9836. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9837. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9838. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9839. }
  9840. if item.MedChrgitmType == "11" { //中成费
  9841. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9842. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9843. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9844. }
  9845. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9846. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9847. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9848. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9849. }
  9850. }
  9851. }
  9852. c.ServeSuccessJSON(map[string]interface{}{
  9853. "order": order,
  9854. "order_info": order_info,
  9855. "patient": patient,
  9856. "admin_info": adminInfo,
  9857. "his_hospital": record,
  9858. "bedCostTotal": bedCostTotal,
  9859. "operationCostTotal": operationCostTotal,
  9860. "otherCostTotal": otherCostTotal,
  9861. "materialCostTotal": materialCostTotal,
  9862. "westernMedicineCostTotal": westernMedicineCostTotal,
  9863. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9864. "checkCostTotal": checkCostTotal,
  9865. "zhenChaCostTotal": zhenChaCostTotal,
  9866. "laboratoryCostTotal": laboratoryCostTotal,
  9867. "treatCostTotal": treatCostTotal,
  9868. })
  9869. }
  9870. }
  9871. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9872. page, _ := c.GetInt64("page")
  9873. limit, _ := c.GetInt64("limit")
  9874. keywords := c.GetString("keywords")
  9875. start_time := c.GetString("start_time")
  9876. end_time := c.GetString("end_time")
  9877. //clr_type := c.GetString("clr_type")
  9878. insutype := c.GetString("insutype")
  9879. timeLayout := "2006-01-02"
  9880. loc, _ := time.LoadLocation("Local")
  9881. var theStartTIme int64
  9882. if len(start_time) > 0 {
  9883. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9884. theStartTIme = theTime.Unix()
  9885. }
  9886. var theEndtTIme int64
  9887. if len(end_time) > 0 {
  9888. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9889. theEndtTIme = theTime.Unix()
  9890. }
  9891. if page <= 0 {
  9892. page = 1
  9893. }
  9894. if limit <= 0 {
  9895. limit = 10
  9896. }
  9897. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9898. c.ServeSuccessJSON(map[string]interface{}{
  9899. "total": total,
  9900. "list": list,
  9901. })
  9902. return
  9903. }
  9904. func (c *HisApiController) GetPutOnRecordList() {
  9905. page, _ := c.GetInt64("page")
  9906. limit, _ := c.GetInt64("limit")
  9907. keywords := c.GetString("keywords")
  9908. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9909. if page <= 0 {
  9910. page = 1
  9911. }
  9912. if limit <= 0 {
  9913. limit = 10
  9914. }
  9915. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9916. c.ServeSuccessJSON(map[string]interface{}{
  9917. "total": total,
  9918. "list": list,
  9919. })
  9920. return
  9921. }
  9922. func (c *HisApiController) GetCompareData() {
  9923. start_time := c.GetString("start_time")
  9924. end_time := c.GetString("end_time")
  9925. insutype := c.GetString("insutype")
  9926. clr_type := c.GetString("clr_type")
  9927. timeLayout := "2006-01-02"
  9928. loc, _ := time.LoadLocation("Local")
  9929. var theStartTIme int64
  9930. if len(start_time) > 0 {
  9931. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9932. if err != nil {
  9933. theStartTIme = 0
  9934. }
  9935. theStartTIme = theTime.Unix()
  9936. }
  9937. var theEndtTIme int64
  9938. if len(end_time) > 0 {
  9939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9940. if err != nil {
  9941. theEndtTIme = 0
  9942. }
  9943. theEndtTIme = theTime.Unix()
  9944. }
  9945. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9946. fmt.Println(err)
  9947. if err == nil {
  9948. c.ServeSuccessJSON(map[string]interface{}{
  9949. "list": formData,
  9950. })
  9951. } else {
  9952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9953. return
  9954. }
  9955. }
  9956. func (c *HisApiController) GetFaPiaoData() {
  9957. order_id, _ := c.GetInt64("order_id")
  9958. patient_id, _ := c.GetInt64("patient_id")
  9959. //number := c.GetString("number")
  9960. adminUser := c.GetAdminUserInfo()
  9961. order, _ := service.GetHisOrderByID(order_id)
  9962. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9963. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9964. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9965. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9966. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9967. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9968. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9969. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9970. var bedCostTotal float64 = 0 //床位总费
  9971. var bedCostSelfTotal float64 = 0 //床位自费
  9972. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9973. var operationCostTotal float64 = 0 //手术费
  9974. var operationCostSelfTotal float64 = 0 //手术费
  9975. var operationCostPartSelfTotal float64 = 0 //手术费
  9976. var otherCostTotal float64 = 0 //其他费用
  9977. var otherCostSelfTotal float64 = 0 //其他费用
  9978. var otherCostPartSelfTotal float64 = 0 //其他费用
  9979. var materialCostTotal float64 = 0 //材料费
  9980. var materialCostSelfTotal float64 = 0 //材料费
  9981. var materialCostPartSelfTotal float64 = 0 //材料费
  9982. var westernMedicineCostTotal float64 = 0 //西药费
  9983. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9984. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9985. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9986. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9987. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9988. var checkCostTotal float64 = 0 //检查费
  9989. var checkCostSelfTotal float64 = 0 //检查费
  9990. var checkCostPartSelfTotal float64 = 0 //检查费
  9991. var hiliCostTotal float64 = 0 //护理费
  9992. var hiliCostSelfTotal float64 = 0 //护理费
  9993. var hiliCostPartSelfTotal float64 = 0 //护理费
  9994. var laboratoryCostTotal float64 = 0 //化验费
  9995. var laboratoryCostSelfTotal float64 = 0 //化验费
  9996. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9997. var treatCostTotal float64 = 0 //治疗费用
  9998. var treatCostSelfTotal float64 = 0 //治疗费用
  9999. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10000. var zhenChaCostTotal float64 = 0 //其他费用
  10001. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10002. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10003. decimal.DivisionPrecision = 2
  10004. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10005. var balanceAccountsType int64
  10006. if his.ID > 0 {
  10007. balanceAccountsType = his.BalanceAccountsType
  10008. } else {
  10009. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10010. }
  10011. if balanceAccountsType == 2 {
  10012. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10013. for _, item := range orderInfos_two {
  10014. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10015. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10016. item.MedChrgitmType = "09"
  10017. }
  10018. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10019. if item.HisPrescriptionProject.Type == 2 {
  10020. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10021. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10022. case 0:
  10023. item.MedChrgitmType = "0"
  10024. break
  10025. case 1:
  10026. item.MedChrgitmType = "14"
  10027. break
  10028. case 2:
  10029. item.MedChrgitmType = "05"
  10030. break
  10031. case 3:
  10032. item.MedChrgitmType = "03"
  10033. break
  10034. case 4:
  10035. item.MedChrgitmType = "03"
  10036. break
  10037. case 5:
  10038. item.MedChrgitmType = "08"
  10039. break
  10040. case 6:
  10041. item.MedChrgitmType = "14"
  10042. break
  10043. case 7:
  10044. item.MedChrgitmType = "14"
  10045. break
  10046. case 8:
  10047. item.MedChrgitmType = "03"
  10048. break
  10049. case 9:
  10050. item.MedChrgitmType = "14"
  10051. break
  10052. case 10:
  10053. item.MedChrgitmType = "14"
  10054. break
  10055. case 11:
  10056. item.MedChrgitmType = "06"
  10057. break
  10058. case 12:
  10059. item.MedChrgitmType = "12"
  10060. break
  10061. case 13:
  10062. item.MedChrgitmType = "01"
  10063. break
  10064. case 14:
  10065. item.MedChrgitmType = "04"
  10066. break
  10067. case 15:
  10068. item.MedChrgitmType = "02"
  10069. break
  10070. }
  10071. } else {
  10072. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10073. case 1:
  10074. item.MedChrgitmType = "14"
  10075. break
  10076. case 2:
  10077. item.MedChrgitmType = "05"
  10078. break
  10079. case 3:
  10080. item.MedChrgitmType = "04"
  10081. break
  10082. case 4:
  10083. item.MedChrgitmType = "03"
  10084. break
  10085. case 5:
  10086. item.MedChrgitmType = "08"
  10087. break
  10088. case 6:
  10089. item.MedChrgitmType = "14"
  10090. break
  10091. case 7:
  10092. item.MedChrgitmType = "14"
  10093. break
  10094. case 8:
  10095. item.MedChrgitmType = "03"
  10096. break
  10097. case 9:
  10098. item.MedChrgitmType = "14"
  10099. break
  10100. }
  10101. }
  10102. } else if item.HisPrescriptionProject.Type == 3 {
  10103. item.MedChrgitmType = "08"
  10104. }
  10105. }
  10106. }
  10107. for _, item := range orderInfos_two {
  10108. fmt.Println(item.MedChrgitmType)
  10109. if item.MedChrgitmType == "07" { //床位费
  10110. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10111. hiliCostSelfTotal = hiliCostTotal
  10112. }
  10113. if item.MedChrgitmType == "01" { //床位费
  10114. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10115. bedCostSelfTotal = bedCostTotal
  10116. }
  10117. if item.MedChrgitmType == "02" { //诊察费
  10118. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10119. zhenChaCostSelfTotal = zhenChaCostTotal
  10120. }
  10121. if item.MedChrgitmType == "03" { //检查费
  10122. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10123. checkCostSelfTotal = checkCostTotal
  10124. }
  10125. if item.MedChrgitmType == "04" { //化验费
  10126. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10127. laboratoryCostSelfTotal = laboratoryCostTotal
  10128. }
  10129. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10130. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10131. treatCostSelfTotal = treatCostTotal
  10132. }
  10133. if item.MedChrgitmType == "06" { //手术费
  10134. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10135. operationCostSelfTotal = treatCostTotal
  10136. }
  10137. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10138. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10139. materialCostSelfTotal = materialCostTotal
  10140. }
  10141. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10142. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10143. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10144. }
  10145. if item.MedChrgitmType == "11" { //中成费
  10146. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10147. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10148. }
  10149. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10150. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10151. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10152. otherCostSelfTotal = otherCostTotal
  10153. }
  10154. } else {
  10155. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10156. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10157. otherCostSelfTotal = otherCostTotal
  10158. }
  10159. }
  10160. }
  10161. } else {
  10162. for _, item := range orderInfos {
  10163. if item.MedChrgitmType == "01" { //床位费
  10164. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10165. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10166. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10167. }
  10168. if item.MedChrgitmType == "02" { //诊察费
  10169. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10170. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10171. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10172. }
  10173. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10174. if item.MedChrgitmType == "03" { //检查费
  10175. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10176. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10177. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10178. }
  10179. } else {
  10180. if item.MedChrgitmType == "03" { //检查费
  10181. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10182. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10183. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10184. }
  10185. }
  10186. if item.MedChrgitmType == "04" { //化验费
  10187. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10188. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10189. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10190. }
  10191. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10192. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10193. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10194. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10195. }
  10196. if item.MedChrgitmType == "06" { //手术费
  10197. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10198. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10199. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10200. }
  10201. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10202. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10203. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10204. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10205. }
  10206. if item.MedChrgitmType == "07" { //护理
  10207. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10208. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10209. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10210. }
  10211. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10212. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10213. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10214. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10215. }
  10216. if item.MedChrgitmType == "11" { //中成费
  10217. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10218. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10219. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10220. }
  10221. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10222. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10223. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10224. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10225. }
  10226. }
  10227. }
  10228. timeLayout := "2006-01-02"
  10229. loc, _ := time.LoadLocation("Local")
  10230. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10231. if err != nil {
  10232. }
  10233. startRecordDateTime := startTime.Unix()
  10234. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10235. if err != nil {
  10236. }
  10237. endRecordDateTime := endTime.Unix()
  10238. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10239. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10240. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10241. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10242. c.ServeSuccessJSON(map[string]interface{}{
  10243. "charge_admin_name": charge_admin.UserName,
  10244. "order_number": order.Number, //业务流水号
  10245. "id_card_no": his.IdCardNo, //社会保障号
  10246. "patient": patient,
  10247. "department_name": department.Name, //科室
  10248. "number": his.Number, //门诊号
  10249. "date": order.SettleAccountsDate, //结算日期
  10250. "name": order.PsnName, //姓名
  10251. "gender": patient.Gender, //性别
  10252. "psn_cash_money": order.PsnCashPay, //个人支付
  10253. "pay_way": "门诊", //结算方式
  10254. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10255. "admin_user_name": admin.UserName, //收款员
  10256. "order": order,
  10257. "order_info": orderInfos_two,
  10258. "his": his,
  10259. "bedCostTotal": bedCostTotal,
  10260. "bedCostSelfTotal": bedCostSelfTotal,
  10261. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10262. "operationCostTotal": operationCostTotal,
  10263. "operationCostSelfTotal": operationCostSelfTotal,
  10264. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10265. "otherCostTotal": otherCostTotal,
  10266. "otherCostSelfTotal": otherCostSelfTotal,
  10267. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10268. "materialCostTotal": materialCostTotal,
  10269. "materialCostSelfTotal": materialCostSelfTotal,
  10270. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10271. "westernMedicineCostTotal": westernMedicineCostTotal,
  10272. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10273. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10274. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10275. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10276. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10277. "checkCostTotal": checkCostTotal,
  10278. "checkCostSelfTotal": checkCostSelfTotal,
  10279. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10280. "laboratoryCostTotal": laboratoryCostTotal,
  10281. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10282. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10283. "treatCostTotal": treatCostTotal,
  10284. "treatCostSelfTotal": treatCostSelfTotal,
  10285. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10286. "zhenChaCostTotal": zhenChaCostTotal,
  10287. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10288. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10289. "his_hospital_record": his_hospital_record,
  10290. "pre_pay_money": pre_pay_money,
  10291. "refund_sum": sum,
  10292. "doctor_info": doctor_info,
  10293. "hiliCostTotal": hiliCostTotal,
  10294. "hiliCostSelfTotal": hiliCostSelfTotal,
  10295. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10296. })
  10297. }
  10298. //func (c *HisApiController) GetFaPiaoDatas() {
  10299. // order_ids := c.GetString("order_ids")
  10300. // patient_id, _ := c.GetInt64("patient_id")
  10301. // adminUser := c.GetAdminUserInfo()
  10302. //
  10303. // orders := strings.Split(order_ids, ",")
  10304. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10305. //
  10306. // for _, item := range orders {
  10307. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10308. // order, _ := service.GetHisOrderByID(order_id)
  10309. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10310. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10311. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10312. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10313. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10314. //
  10315. // }
  10316. //
  10317. // var bedCostTotal float64 = 0 //床位总费
  10318. // var bedCostSelfTotal float64 = 0 //床位自费
  10319. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10320. //
  10321. // var operationCostTotal float64 = 0 //手术费
  10322. // var operationCostSelfTotal float64 = 0 //手术费
  10323. // var operationCostPartSelfTotal float64 = 0 //手术费
  10324. //
  10325. // var otherCostTotal float64 = 0 //其他费用
  10326. // var otherCostSelfTotal float64 = 0 //其他费用
  10327. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10328. //
  10329. // var materialCostTotal float64 = 0 //材料费
  10330. // var materialCostSelfTotal float64 = 0 //材料费
  10331. // var materialCostPartSelfTotal float64 = 0 //材料费
  10332. //
  10333. // var westernMedicineCostTotal float64 = 0 //西药费
  10334. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10335. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10336. //
  10337. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10338. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10339. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10340. //
  10341. // var checkCostTotal float64 = 0 //检查费
  10342. // var checkCostSelfTotal float64 = 0 //检查费
  10343. // var checkCostPartSelfTotal float64 = 0 //检查费
  10344. //
  10345. // var laboratoryCostTotal float64 = 0 //化验费
  10346. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10347. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10348. //
  10349. // var treatCostTotal float64 = 0 //治疗费用
  10350. // var treatCostSelfTotal float64 = 0 //治疗费用
  10351. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10352. //
  10353. // var zhenChaCostTotal float64 = 0 //其他费用
  10354. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10355. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10356. //
  10357. // decimal.DivisionPrecision = 2
  10358. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10359. //
  10360. // var balanceAccountsType int64
  10361. // if his.ID > 0 {
  10362. // balanceAccountsType = his.BalanceAccountsType
  10363. // } else {
  10364. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10365. // }
  10366. // if balanceAccountsType == 2 {
  10367. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10368. // for _, item := range orderInfos_two {
  10369. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10370. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10371. // item.MedChrgitmType = "09"
  10372. // }
  10373. //
  10374. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10375. // if item.HisPrescriptionProject.Type == 2 {
  10376. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10377. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10378. // case 0:
  10379. // item.MedChrgitmType = "0"
  10380. // break
  10381. // case 1:
  10382. // item.MedChrgitmType = "14"
  10383. // break
  10384. // case 2:
  10385. // item.MedChrgitmType = "05"
  10386. //
  10387. // break
  10388. // case 3:
  10389. // item.MedChrgitmType = "03"
  10390. //
  10391. // break
  10392. // case 4:
  10393. // item.MedChrgitmType = "03"
  10394. //
  10395. // break
  10396. // case 5:
  10397. // item.MedChrgitmType = "08"
  10398. //
  10399. // break
  10400. // case 6:
  10401. // item.MedChrgitmType = "14"
  10402. //
  10403. // break
  10404. // case 7:
  10405. // item.MedChrgitmType = "14"
  10406. //
  10407. // break
  10408. // case 8:
  10409. // item.MedChrgitmType = "03"
  10410. // break
  10411. // case 9:
  10412. // item.MedChrgitmType = "14"
  10413. // break
  10414. // case 10:
  10415. // item.MedChrgitmType = "14"
  10416. // break
  10417. // case 11:
  10418. // item.MedChrgitmType = "06"
  10419. // break
  10420. // case 12:
  10421. // item.MedChrgitmType = "12"
  10422. // break
  10423. // case 13:
  10424. // item.MedChrgitmType = "01"
  10425. // break
  10426. // case 14:
  10427. // item.MedChrgitmType = "04"
  10428. // break
  10429. // case 15:
  10430. // item.MedChrgitmType = "02"
  10431. // break
  10432. //
  10433. // }
  10434. //
  10435. // } else {
  10436. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10437. //
  10438. // case 1:
  10439. // item.MedChrgitmType = "14"
  10440. // break
  10441. // case 2:
  10442. // item.MedChrgitmType = "05"
  10443. //
  10444. // break
  10445. // case 3:
  10446. // item.MedChrgitmType = "03"
  10447. //
  10448. // break
  10449. // case 4:
  10450. // item.MedChrgitmType = "03"
  10451. //
  10452. // break
  10453. // case 5:
  10454. // item.MedChrgitmType = "08"
  10455. //
  10456. // break
  10457. // case 6:
  10458. // item.MedChrgitmType = "14"
  10459. //
  10460. // break
  10461. // case 7:
  10462. // item.MedChrgitmType = "14"
  10463. //
  10464. // break
  10465. // case 8:
  10466. // item.MedChrgitmType = "03"
  10467. // break
  10468. // case 9:
  10469. // item.MedChrgitmType = "14"
  10470. // break
  10471. //
  10472. // }
  10473. //
  10474. // }
  10475. //
  10476. // } else if item.HisPrescriptionProject.Type == 3 {
  10477. // item.MedChrgitmType = "08"
  10478. // }
  10479. // }
  10480. // }
  10481. //
  10482. // for _, item := range orderInfos_two {
  10483. // fmt.Println(item.MedChrgitmType)
  10484. // if item.MedChrgitmType == "01" { //床位费
  10485. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10486. // bedCostSelfTotal = bedCostTotal
  10487. // }
  10488. //
  10489. // if item.MedChrgitmType == "02" { //诊察费
  10490. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10491. // zhenChaCostSelfTotal = zhenChaCostTotal
  10492. // }
  10493. //
  10494. // if item.MedChrgitmType == "03" { //检查费
  10495. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10496. // checkCostSelfTotal = checkCostTotal
  10497. // }
  10498. //
  10499. // if item.MedChrgitmType == "04" { //化验费
  10500. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10501. // laboratoryCostSelfTotal = laboratoryCostTotal
  10502. // }
  10503. //
  10504. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10505. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10506. // treatCostSelfTotal = treatCostTotal
  10507. // }
  10508. //
  10509. // if item.MedChrgitmType == "06" { //手术费
  10510. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10511. // operationCostSelfTotal = treatCostTotal
  10512. // }
  10513. //
  10514. // if item.MedChrgitmType == "08" { //材料费
  10515. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10516. // materialCostSelfTotal = materialCostTotal
  10517. // }
  10518. //
  10519. // if item.MedChrgitmType == "09" { //西药费
  10520. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10521. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10522. // }
  10523. //
  10524. // if item.MedChrgitmType == "11" { //中成费
  10525. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10526. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10527. // }
  10528. //
  10529. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10530. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10531. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10532. // otherCostSelfTotal = otherCostTotal
  10533. // }
  10534. // } else {
  10535. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10536. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10537. // otherCostSelfTotal = otherCostTotal
  10538. // }
  10539. //
  10540. // }
  10541. //
  10542. // }
  10543. //
  10544. // } else {
  10545. // for _, item := range orderInfos {
  10546. // if item.MedChrgitmType == "01" { //床位费
  10547. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10548. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10549. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10550. // }
  10551. //
  10552. // if item.MedChrgitmType == "02" { //诊察费
  10553. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10554. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10555. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10556. // }
  10557. //
  10558. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10559. // if item.MedChrgitmType == "03" { //检查费
  10560. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10561. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10562. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10563. //
  10564. // }
  10565. // } else {
  10566. // if item.MedChrgitmType == "03" { //检查费
  10567. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10568. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10569. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10570. // }
  10571. //
  10572. // }
  10573. //
  10574. // if item.MedChrgitmType == "04" { //化验费
  10575. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10576. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10577. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10578. //
  10579. // }
  10580. //
  10581. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10582. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10583. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10584. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10585. //
  10586. // }
  10587. //
  10588. // if item.MedChrgitmType == "06" { //手术费
  10589. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10590. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10591. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10592. // }
  10593. //
  10594. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10595. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10596. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10597. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10598. // }
  10599. //
  10600. // if item.MedChrgitmType == "09" { //西药费
  10601. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10602. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10603. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10604. // }
  10605. //
  10606. // if item.MedChrgitmType == "11" { //中成费
  10607. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10608. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10609. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10610. // }
  10611. //
  10612. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10613. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10614. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10615. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10616. // }
  10617. //
  10618. // }
  10619. // }
  10620. // timeLayout := "2006-01-02"
  10621. // loc, _ := time.LoadLocation("Local")
  10622. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10623. // if err != nil {
  10624. // }
  10625. // startRecordDateTime := startTime.Unix()
  10626. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10627. // if err != nil {
  10628. // }
  10629. // endRecordDateTime := endTime.Unix()
  10630. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10631. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10632. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10633. //
  10634. // c.ServeSuccessJSON(map[string]interface{}{
  10635. // "order_number": order.Number, //业务流水号
  10636. // "id_card_no": his.IdCardNo, //社会保障号
  10637. // "department_name": department.Name, //科室
  10638. // "number": his.Number, //门诊号
  10639. // "date": order.SettleAccountsDate, //结算日期
  10640. // "name": order.PsnName, //姓名
  10641. // "gender": patient.Gender, //性别
  10642. // "psn_cash_money": order.PsnCashPay, //个人支付
  10643. // "pay_way": "门诊", //结算方式
  10644. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10645. // "admin_user_name": admin.UserName, //收款员
  10646. // "order": order,
  10647. // "order_info": orderInfos_two,
  10648. // "his": his,
  10649. // "bedCostTotal": bedCostTotal,
  10650. // "bedCostSelfTotal": bedCostSelfTotal,
  10651. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10652. // "operationCostTotal": operationCostTotal,
  10653. // "operationCostSelfTotal": operationCostSelfTotal,
  10654. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10655. // "otherCostTotal": otherCostTotal,
  10656. // "otherCostSelfTotal": otherCostSelfTotal,
  10657. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10658. // "materialCostTotal": materialCostTotal,
  10659. // "materialCostSelfTotal": materialCostSelfTotal,
  10660. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10661. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10662. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10663. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10664. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10665. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10666. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10667. // "checkCostTotal": checkCostTotal,
  10668. // "checkCostSelfTotal": checkCostSelfTotal,
  10669. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10670. // "laboratoryCostTotal": laboratoryCostTotal,
  10671. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10672. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10673. // "treatCostTotal": treatCostTotal,
  10674. // "treatCostSelfTotal": treatCostSelfTotal,
  10675. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10676. // "zhenChaCostTotal": zhenChaCostTotal,
  10677. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10678. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10679. // "his_hospital_record": his_hospital_record,
  10680. // "pre_pay_money": pre_pay_money,
  10681. // "refund_sum": sum,
  10682. // })
  10683. //
  10684. //}
  10685. func (this *HisApiController) GetIncomeStatisticsData() {
  10686. start_time := this.GetString("start_time")
  10687. end_time := this.GetString("end_time")
  10688. key_words := this.GetString("key_words")
  10689. limit, _ := this.GetInt64("limit")
  10690. page, _ := this.GetInt64("page")
  10691. if page <= 0 {
  10692. page = 1
  10693. }
  10694. if limit <= 0 {
  10695. limit = 10
  10696. }
  10697. statistics_type, _ := this.GetInt64("statistics_type")
  10698. admin := this.GetAdminUserInfo()
  10699. timeLayout := "2006-01-02"
  10700. loc, _ := time.LoadLocation("Local")
  10701. var theStartTIme int64
  10702. if len(start_time) > 0 {
  10703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10704. if err != nil {
  10705. theStartTIme = 0
  10706. }
  10707. theStartTIme = theTime.Unix()
  10708. }
  10709. var theEndtTIme int64
  10710. if len(end_time) > 0 {
  10711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10712. if err != nil {
  10713. theEndtTIme = 0
  10714. }
  10715. theEndtTIme = theTime.Unix()
  10716. }
  10717. if statistics_type == 1 {
  10718. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10719. this.ServeSuccessJSON(map[string]interface{}{
  10720. "list": list,
  10721. "total": total,
  10722. })
  10723. } else {
  10724. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10725. this.ServeSuccessJSON(map[string]interface{}{
  10726. "list": list,
  10727. "total": total,
  10728. })
  10729. }
  10730. }
  10731. func (c *HisApiController) PostProjectInformation() {
  10732. adminUser := c.GetAdminUserInfo()
  10733. orgId := adminUser.CurrentOrgId
  10734. dataBody := make(map[string]interface{}, 0)
  10735. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10736. if err != nil {
  10737. utils.ErrorLog(err.Error())
  10738. return
  10739. }
  10740. utils.ErrorLog("%v", dataBody)
  10741. var projectList []*models.HisProject
  10742. var total_goods []interface{}
  10743. tempProjects := dataBody["projects"].([]interface{})
  10744. total_goods = tempProjects
  10745. for index, projectMap := range tempProjects {
  10746. projectM := projectMap.(map[string]interface{})
  10747. var project models.HisProject
  10748. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10749. utils.ErrorLog("project_name")
  10750. return
  10751. }
  10752. project_name, _ := projectM["project_name"].(string)
  10753. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10754. err_log := models.ExportErrLog{
  10755. LogType: 6,
  10756. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10757. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10758. Status: 1,
  10759. CreateTime: time.Now().Unix(),
  10760. UpdateTime: time.Now().Unix(),
  10761. ExportTime: time.Now().Unix(),
  10762. }
  10763. service.CreateExportErrLog(&err_log)
  10764. continue
  10765. }
  10766. project.ProjectName = project_name
  10767. prices := projectM["price"].(string)
  10768. price, _ := strconv.ParseFloat(prices, 64)
  10769. if price <= 0 { //名字为空则生成一条导入错误日志
  10770. err_log := models.ExportErrLog{
  10771. LogType: 6,
  10772. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10773. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10774. Status: 1,
  10775. CreateTime: time.Now().Unix(),
  10776. UpdateTime: time.Now().Unix(),
  10777. ExportTime: time.Now().Unix(),
  10778. }
  10779. service.CreateExportErrLog(&err_log)
  10780. continue
  10781. }
  10782. project.Price = price
  10783. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10784. utils.ErrorLog("unit_id")
  10785. return
  10786. }
  10787. unit := projectM["unit"].(string)
  10788. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10789. err_log := models.ExportErrLog{
  10790. LogType: 6,
  10791. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10792. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10793. Status: 1,
  10794. CreateTime: time.Now().Unix(),
  10795. UpdateTime: time.Now().Unix(),
  10796. ExportTime: time.Now().Unix(),
  10797. }
  10798. service.CreateExportErrLog(&err_log)
  10799. continue
  10800. }
  10801. project.Unit = unit
  10802. cost_classify := projectM["cost_classify"].(string)
  10803. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10804. err_log := models.ExportErrLog{
  10805. LogType: 6,
  10806. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10807. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10808. Status: 1,
  10809. CreateTime: time.Now().Unix(),
  10810. UpdateTime: time.Now().Unix(),
  10811. ExportTime: time.Now().Unix(),
  10812. }
  10813. service.CreateExportErrLog(&err_log)
  10814. continue
  10815. }
  10816. var costClassify = "费用类别"
  10817. var cost_classify_id int64
  10818. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10819. if len(cost_classify) != 0 {
  10820. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10821. if errcode == gorm.ErrRecordNotFound {
  10822. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10823. dataconfig := models.DictDataconfig{
  10824. ParentId: costClassifyConfig.ID,
  10825. Module: "system",
  10826. OrgId: orgId,
  10827. Name: cost_classify,
  10828. FieldName: "",
  10829. Value: costConfig.Value + 1,
  10830. CreatedTime: "",
  10831. UpdatedTime: "",
  10832. CreateUserId: adminUser.AdminUser.Id,
  10833. Status: 1,
  10834. Remark: "",
  10835. DeleteIdSystem: 0,
  10836. Title: "",
  10837. Content: "",
  10838. Order: 0,
  10839. Code: "",
  10840. }
  10841. service.CreatedDicConfig(&dataconfig)
  10842. }
  10843. }
  10844. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10845. for _, it := range costClassList {
  10846. if cost_classify == it.Name {
  10847. cost_classify_id = int64(it.Value)
  10848. }
  10849. }
  10850. project.CostClassify = cost_classify_id
  10851. executive_section := projectM["executive_section"].(string)
  10852. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10853. err_log := models.ExportErrLog{
  10854. LogType: 6,
  10855. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10856. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10857. Status: 1,
  10858. CreateTime: time.Now().Unix(),
  10859. UpdateTime: time.Now().Unix(),
  10860. ExportTime: time.Now().Unix(),
  10861. }
  10862. service.CreateExportErrLog(&err_log)
  10863. continue
  10864. }
  10865. if len(executive_section) != 0 {
  10866. //查找科室是否有内容
  10867. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10868. if errcodedepart == gorm.ErrRecordNotFound {
  10869. department := models.XtHisDepartment{
  10870. Name: executive_section,
  10871. Status: 1,
  10872. UserOrgId: adminUser.CurrentOrgId,
  10873. CreatedTime: time.Now().Unix(),
  10874. }
  10875. service.CreateDePartment(&department)
  10876. }
  10877. }
  10878. var executive_section_id int64
  10879. departMentList, _ := service.GetAllDepartMent(orgId)
  10880. for _, it := range departMentList {
  10881. if executive_section == it.Name {
  10882. executive_section_id = it.ID
  10883. }
  10884. }
  10885. project.ExecutiveSection = executive_section_id
  10886. medical_coverage := projectM["medical_coverage"].(string)
  10887. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10888. err_log := models.ExportErrLog{
  10889. LogType: 6,
  10890. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10891. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10892. Status: 1,
  10893. CreateTime: time.Now().Unix(),
  10894. UpdateTime: time.Now().Unix(),
  10895. ExportTime: time.Now().Unix(),
  10896. }
  10897. service.CreateExportErrLog(&err_log)
  10898. continue
  10899. }
  10900. var medicalCoverage = "医保等级"
  10901. var medical_coverage_id int64
  10902. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10903. if len(medical_coverage) != 0 {
  10904. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10905. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10906. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10907. dataconfig := models.DictDataconfig{
  10908. ParentId: medicalCoverageConfig.ID,
  10909. Module: "system",
  10910. OrgId: orgId,
  10911. Name: medical_coverage,
  10912. FieldName: "",
  10913. Value: medicalCoverageConfig.Value + 1,
  10914. CreatedTime: "",
  10915. UpdatedTime: "",
  10916. CreateUserId: adminUser.AdminUser.Id,
  10917. Status: 1,
  10918. Remark: "",
  10919. DeleteIdSystem: 0,
  10920. Title: "",
  10921. Content: "",
  10922. Order: 0,
  10923. Code: "",
  10924. }
  10925. service.CreatedDicConfig(&dataconfig)
  10926. }
  10927. }
  10928. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10929. for _, it := range medicalCoverageList {
  10930. if medical_coverage == it.Name {
  10931. medical_coverage_id = int64(it.Value)
  10932. }
  10933. }
  10934. project.MedicalCoverage = medical_coverage_id
  10935. pinyin := projectM["pinyin"].(string)
  10936. project.Pinyin = pinyin
  10937. wubi := projectM["wubi"].(string)
  10938. project.Wubi = wubi
  10939. statistical_classification := projectM["statistical_classification"].(string)
  10940. var statisticalClassification = "统计分类"
  10941. var statistical_classification_id int64
  10942. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10943. if len(statistical_classification) != 0 {
  10944. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10945. if classificationerrcodes == gorm.ErrRecordNotFound {
  10946. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10947. dataconfig := models.DictDataconfig{
  10948. ParentId: classiFication.ID,
  10949. Module: "system",
  10950. OrgId: orgId,
  10951. Name: statistical_classification,
  10952. FieldName: "",
  10953. Value: classiFicationConfig.Value + 1,
  10954. CreatedTime: "",
  10955. UpdatedTime: "",
  10956. CreateUserId: adminUser.AdminUser.Id,
  10957. Status: 1,
  10958. Remark: "",
  10959. DeleteIdSystem: 0,
  10960. Title: "",
  10961. Content: "",
  10962. Order: 0,
  10963. Code: "",
  10964. }
  10965. service.CreatedDicConfig(&dataconfig)
  10966. }
  10967. }
  10968. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10969. for _, it := range classiFicationList {
  10970. if statistical_classification == it.Name {
  10971. statistical_classification_id = int64(it.Value)
  10972. }
  10973. }
  10974. project.StatisticalClassification = statistical_classification_id
  10975. disease_directory := int64(projectM["disease_directory"].(float64))
  10976. project.DiseaseDirectory = disease_directory
  10977. is_record := int64(projectM["is_record"].(float64))
  10978. project.IsRecord = is_record
  10979. medical_code := projectM["medical_code"].(string)
  10980. project.MedicalCode = medical_code
  10981. tube_color := projectM["tube_color"].(string)
  10982. var tubeColor = "试管颜色"
  10983. var tube_color_id int64
  10984. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10985. if len(tube_color) != 0 {
  10986. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10987. if errcodetube == gorm.ErrRecordNotFound {
  10988. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10989. dataconfig := models.DictDataconfig{
  10990. ParentId: tubeColorConfig.ID,
  10991. Module: "system",
  10992. OrgId: orgId,
  10993. Name: tube_color,
  10994. FieldName: "",
  10995. Value: tubeConfig.Value + 1,
  10996. CreatedTime: "",
  10997. UpdatedTime: "",
  10998. CreateUserId: adminUser.AdminUser.Id,
  10999. Status: 1,
  11000. Remark: "",
  11001. DeleteIdSystem: 0,
  11002. Title: "",
  11003. Content: "",
  11004. Order: 0,
  11005. Code: "",
  11006. }
  11007. service.CreatedDicConfig(&dataconfig)
  11008. }
  11009. }
  11010. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11011. for _, it := range tubeColorList {
  11012. if tube_color == it.Name {
  11013. tube_color_id = int64(it.Value)
  11014. }
  11015. }
  11016. project.TubeColor = tube_color_id
  11017. single_dose := projectM["single_dose"].(string)
  11018. project.SingleDose = single_dose
  11019. execution_frequency := projectM["execution_frequency"].(string)
  11020. project.ExecutionFrequency = execution_frequency
  11021. delivery_way := projectM["delivery_way"].(string)
  11022. project.DeliveryWay = delivery_way
  11023. number_days := projectM["number_days"].(string)
  11024. project.NumberDays = number_days
  11025. total := projectM["total"].(string)
  11026. project.Total = total
  11027. medical_status := int64(projectM["medical_status"].(float64))
  11028. project.MedicalStatus = medical_status
  11029. category := int64(projectM["category"].(float64))
  11030. project.Category = category
  11031. specail_project := int64(projectM["specail_project"].(float64))
  11032. project.SpecailProject = specail_project
  11033. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11034. project.SocialSecurityDirectoryCode = social_security_directory_code
  11035. remark := projectM["remark"].(string)
  11036. project.Remark = remark
  11037. record_date := projectM["record_date"].(string)
  11038. timeLayout := "2006-01-02"
  11039. loc, _ := time.LoadLocation("Local")
  11040. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11041. project.RecordDate = theTime.Unix()
  11042. projectList = append(projectList, &project)
  11043. }
  11044. export_time := time.Now().Unix()
  11045. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11046. if len(projectList) > 0 {
  11047. for _, item := range projectList {
  11048. hans := item.ProjectName // 要转换的汉字字符串
  11049. // 创建一个拼音转换器
  11050. p := pinyin.NewArgs()
  11051. // 将汉字转为拼音
  11052. pinyinSlice := pinyin.Pinyin(hans, p)
  11053. // 输出拼音
  11054. fmt.Println("Pinyin:", pinyinSlice)
  11055. // 获取首字母
  11056. firstLetter := ""
  11057. for _, py := range pinyinSlice {
  11058. if len(py) > 0 {
  11059. firstLetter += string(py[0][0])
  11060. }
  11061. }
  11062. item.FirstLetter = firstLetter
  11063. project := models.HisProject{
  11064. ProjectName: item.ProjectName,
  11065. Price: item.Price,
  11066. Unit: item.Unit,
  11067. CostClassify: item.CostClassify,
  11068. ExecutiveSection: item.ExecutiveSection,
  11069. MedicalCoverage: item.MedicalCoverage,
  11070. UserOrgId: orgId,
  11071. Status: 1,
  11072. CreatedTime: time.Now().Unix(),
  11073. Pinyin: item.Pinyin,
  11074. Wubi: item.Wubi,
  11075. StatisticalClassification: item.StatisticalClassification,
  11076. DiseaseDirectory: item.DiseaseDirectory,
  11077. IsRecord: item.IsRecord,
  11078. MedicalCode: item.MedicalCode,
  11079. TubeColor: item.TubeColor,
  11080. SingleDose: item.SingleDose,
  11081. DeliveryWay: item.DeliveryWay,
  11082. NumberDays: item.NumberDays,
  11083. Total: item.Total,
  11084. Category: item.Category,
  11085. MedicalStatus: item.MedicalStatus,
  11086. SpecailProject: item.SpecailProject,
  11087. RecordDate: item.RecordDate,
  11088. Remark: item.Remark,
  11089. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11090. ExecutionFrequency: item.ExecutionFrequency,
  11091. FirstLetter: item.FirstLetter,
  11092. }
  11093. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11094. if errcodeproject == gorm.ErrRecordNotFound {
  11095. service.CreateProjectInfomation(&project)
  11096. } else if errcodeproject == nil {
  11097. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11098. }
  11099. log := models.ExportLog{
  11100. LogType: 6,
  11101. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11102. TotalNum: int64(len(total_goods)),
  11103. FailNum: int64(len(errLogs)),
  11104. SuccessNum: int64(len(projectList)),
  11105. CreateTime: time.Now().Unix(),
  11106. UpdateTime: time.Now().Unix(),
  11107. ExportTime: export_time,
  11108. Status: 1,
  11109. }
  11110. service.CreateExportLog(&log)
  11111. c.ServeSuccessJSON(map[string]interface{}{
  11112. "msg": "导入成功",
  11113. "total_num": len(total_goods),
  11114. "success_num": len(projectList),
  11115. "fail_num": int64(len(errLogs)),
  11116. })
  11117. }
  11118. } else {
  11119. log := models.ExportLog{
  11120. LogType: 6,
  11121. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11122. TotalNum: int64(len(total_goods)),
  11123. FailNum: int64(len(errLogs)),
  11124. SuccessNum: int64(len(projectList)),
  11125. CreateTime: time.Now().Unix(),
  11126. UpdateTime: time.Now().Unix(),
  11127. ExportTime: export_time,
  11128. Status: 1,
  11129. }
  11130. service.CreateExportLog(&log)
  11131. c.ServeSuccessJSON(map[string]interface{}{
  11132. "msg": "导入成功",
  11133. "total_num": len(total_goods),
  11134. "success_num": len(projectList),
  11135. "fail_num": int64(len(errLogs)),
  11136. })
  11137. }
  11138. }
  11139. //func (this *HisApiController) EditProjectInformation(){
  11140. //
  11141. // id, _ := this.GetInt64("id")
  11142. // project_team := this.GetString("project_team")
  11143. // price := this.GetString("price")
  11144. // price_float, _ := strconv.ParseFloat(price, 64)
  11145. // pinyin := this.GetString("pinyin")
  11146. // wubi := this.GetString("wubi")
  11147. // tube_color, _ := this.GetInt64("tube_color")
  11148. // team_type, _ := this.GetInt64("team_type")
  11149. // remark := this.GetString("remark")
  11150. // ids := this.GetString("ids")
  11151. // item_id := this.GetString("item_id")
  11152. // projectTeam := models.XtHisProjectTeam{
  11153. // ProjectTeam: project_team,
  11154. // Price: price_float,
  11155. // Pinyin: pinyin,
  11156. // Wubi: wubi,
  11157. // TubeColor: tube_color,
  11158. // TeamType: team_type,
  11159. // Remark: remark,
  11160. // ProjectId: ids,
  11161. // ItemId: item_id,
  11162. // }
  11163. //
  11164. //
  11165. // dataBody := make(map[string]interface{}, 0)
  11166. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11167. // if err != nil {
  11168. // utils.ErrorLog(err.Error())
  11169. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11170. // return
  11171. // }
  11172. //
  11173. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11174. //
  11175. //
  11176. // if err != nil {
  11177. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11178. // return
  11179. // }
  11180. //
  11181. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11182. // infos, _ := dataBody["info"].([]interface{})
  11183. // if len(infos) > 0 {
  11184. // var ids []string
  11185. //
  11186. // for _, item := range infos {
  11187. // items := item.(map[string]interface{})
  11188. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11189. // utils.ErrorLog("id")
  11190. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11191. // return
  11192. // }
  11193. // id := int64(items["id"].(float64))
  11194. //
  11195. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11196. // utils.ErrorLog("type")
  11197. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11198. // return
  11199. // }
  11200. // types := int64(items["type"].(float64))
  11201. //
  11202. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11203. // utils.ErrorLog("number")
  11204. // }
  11205. //
  11206. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11207. //
  11208. // projectList := models.XtHisProjectList{
  11209. // Number: number,
  11210. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11211. // ProjectId: id,
  11212. // Status: 1,
  11213. // CreatedTime: time.Now().Unix(),
  11214. // UpdatedTime: time.Now().Unix(),
  11215. // TeamId: projectTeam.ID,
  11216. // Type: types,
  11217. // }
  11218. // list := projectList
  11219. //
  11220. // service.CreateProjectList(&list)
  11221. //
  11222. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11223. //
  11224. // }
  11225. // ids_str := strings.Join(ids, ",")
  11226. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11227. // service.SaveProjectTeam(&projectTeam)
  11228. // this.ServeSuccessJSON(map[string]interface{}{
  11229. // "projectTeam": projectTeam,
  11230. // })
  11231. // }
  11232. // }
  11233. //}
  11234. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11235. name := c.GetString("name")
  11236. mode_id, _ := c.GetInt64("mode", 0)
  11237. types, _ := c.GetInt64("type", 0)
  11238. patient_id, _ := c.GetInt64("patient_id", 0)
  11239. types = 1
  11240. adminInfo := c.GetAdminUserInfo()
  11241. template := &models.HisPrescriptionTemplate{
  11242. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11243. PatientId: patient_id,
  11244. Type: types,
  11245. Status: 1,
  11246. Ctime: time.Now().Unix(),
  11247. Mtime: time.Now().Unix(),
  11248. Name: name,
  11249. Mode: mode_id,
  11250. }
  11251. dataBody := make(map[string]interface{}, 0)
  11252. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11253. if err != nil {
  11254. utils.ErrorLog(err.Error())
  11255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11256. return
  11257. }
  11258. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11259. //如果已经存在记录则删除处方
  11260. if template_one.ID > 0 {
  11261. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11262. var ids []int64
  11263. var org_id int64
  11264. for _, item := range ps {
  11265. org_id = c.GetAdminUserInfo().CurrentOrgId
  11266. ids = append(ids, item.ID)
  11267. }
  11268. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11269. if err2 == nil {
  11270. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11271. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11272. if len(prescriptions) > 0 {
  11273. for _, item := range prescriptions {
  11274. items := item.(map[string]interface{})
  11275. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11276. utils.ErrorLog("type")
  11277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11278. return
  11279. }
  11280. types := int64(items["type"].(float64))
  11281. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11282. utils.ErrorLog("med_type")
  11283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11284. return
  11285. }
  11286. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11287. ctime := time.Now().Unix()
  11288. prescription := &models.HisPrescriptionInfoTemplate{
  11289. PatientId: patient_id,
  11290. UserOrgId: adminInfo.CurrentOrgId,
  11291. Ctime: ctime,
  11292. Mtime: ctime,
  11293. Type: types,
  11294. Modifier: adminInfo.AdminUser.Id,
  11295. Creator: adminInfo.AdminUser.Id,
  11296. Status: 1,
  11297. PTemplateId: template_one.ID,
  11298. MedType: med_type,
  11299. }
  11300. service.CreateHisPrescriptionInfoTemplate(prescription)
  11301. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11302. advices := items["advices"].([]interface{})
  11303. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11304. ctime := time.Now().Unix()
  11305. mtime := ctime
  11306. if len(advices) > 0 {
  11307. for _, advice := range advices {
  11308. var s models.HisPrescriptionAdviceTemplate
  11309. s.PrescriptionId = prescription.ID
  11310. s.AdviceType = 2
  11311. s.StopState = 2
  11312. s.ExecutionState = 2
  11313. s.Status = 1
  11314. s.UserOrgId = adminInfo.CurrentOrgId
  11315. s.CreatedTime = ctime
  11316. s.UpdatedTime = mtime
  11317. s.PatientId = patient_id
  11318. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11319. if errcode > 0 {
  11320. c.ServeFailJSONWithSGJErrorCode(errcode)
  11321. return
  11322. }
  11323. service.CreateHisPrescriptionAdviceTemplate(&s)
  11324. }
  11325. }
  11326. }
  11327. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11328. projects := items["project"].([]interface{})
  11329. if len(projects) > 0 {
  11330. for _, project := range projects {
  11331. var p models.HisPrescriptionProjectTemplate
  11332. p.PrescriptionId = prescription.ID
  11333. p.Ctime = time.Now().Unix()
  11334. p.Mtime = time.Now().Unix()
  11335. p.PatientId = patient_id
  11336. p.UserOrgId = adminInfo.CurrentOrgId
  11337. p.Status = 1
  11338. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11339. if errcode > 0 {
  11340. c.ServeFailJSONWithSGJErrorCode(errcode)
  11341. return
  11342. }
  11343. service.CreateHisPrescriptionProjectTemplate(&p)
  11344. }
  11345. }
  11346. }
  11347. }
  11348. c.ServeSuccessJSON(map[string]interface{}{
  11349. "msg": "创建成功",
  11350. })
  11351. }
  11352. }
  11353. } else {
  11354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11355. return
  11356. }
  11357. } else {
  11358. err3 := service.CreateHisPrescriptionTemplate(template)
  11359. if err3 == nil {
  11360. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11361. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11362. if len(prescriptions) > 0 {
  11363. for _, item := range prescriptions {
  11364. items := item.(map[string]interface{})
  11365. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11366. utils.ErrorLog("type")
  11367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11368. return
  11369. }
  11370. types := int64(items["type"].(float64))
  11371. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11372. utils.ErrorLog("med_type")
  11373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11374. return
  11375. }
  11376. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11377. ctime := time.Now().Unix()
  11378. prescription := &models.HisPrescriptionInfoTemplate{
  11379. PatientId: patient_id,
  11380. UserOrgId: adminInfo.CurrentOrgId,
  11381. Ctime: ctime,
  11382. Mtime: ctime,
  11383. Type: types,
  11384. Modifier: adminInfo.AdminUser.Id,
  11385. Creator: adminInfo.AdminUser.Id,
  11386. Status: 1,
  11387. PTemplateId: template.ID,
  11388. MedType: med_type,
  11389. }
  11390. service.CreateHisPrescriptionInfoTemplate(prescription)
  11391. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11392. advices := items["advices"].([]interface{})
  11393. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11394. ctime := time.Now().Unix()
  11395. mtime := ctime
  11396. if len(advices) > 0 {
  11397. for _, advice := range advices {
  11398. var s models.HisPrescriptionAdviceTemplate
  11399. s.PrescriptionId = prescription.ID
  11400. s.AdviceType = 2
  11401. s.StopState = 2
  11402. s.ExecutionState = 2
  11403. s.Status = 1
  11404. s.UserOrgId = adminInfo.CurrentOrgId
  11405. s.CreatedTime = ctime
  11406. s.UpdatedTime = mtime
  11407. s.PatientId = patient_id
  11408. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11409. if errcode > 0 {
  11410. c.ServeFailJSONWithSGJErrorCode(errcode)
  11411. return
  11412. }
  11413. service.CreateHisPrescriptionAdviceTemplate(&s)
  11414. }
  11415. }
  11416. }
  11417. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11418. projects := items["project"].([]interface{})
  11419. if len(projects) > 0 {
  11420. for _, project := range projects {
  11421. var p models.HisPrescriptionProjectTemplate
  11422. p.PrescriptionId = prescription.ID
  11423. p.Ctime = time.Now().Unix()
  11424. p.Mtime = time.Now().Unix()
  11425. p.PatientId = patient_id
  11426. p.UserOrgId = adminInfo.CurrentOrgId
  11427. p.Status = 1
  11428. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11429. if errcode > 0 {
  11430. c.ServeFailJSONWithSGJErrorCode(errcode)
  11431. return
  11432. }
  11433. service.CreateHisPrescriptionProjectTemplate(&p)
  11434. }
  11435. }
  11436. }
  11437. }
  11438. c.ServeSuccessJSON(map[string]interface{}{
  11439. "msg": "创建成功",
  11440. })
  11441. }
  11442. }
  11443. } else {
  11444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11445. return
  11446. }
  11447. }
  11448. }
  11449. func (c *HisApiController) PreSettle() {
  11450. id, _ := c.GetInt64("id")
  11451. record_time := c.GetString("record_time")
  11452. his_patient_id, _ := c.GetInt64("his_patient_id")
  11453. timeLayout := "2006-01-02"
  11454. loc, _ := time.LoadLocation("Local")
  11455. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11456. diagnosis_id := c.GetString("diagnosis")
  11457. sick_type, _ := c.GetInt64("sick_type")
  11458. reg_type, _ := c.GetInt64("p_type")
  11459. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11461. if err != nil {
  11462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11463. return
  11464. }
  11465. recordDateTime := theTime.Unix()
  11466. adminUser := c.GetAdminUserInfo()
  11467. var prescriptions []*models.HisPrescription
  11468. var start_time int64
  11469. var end_time int64
  11470. ids_str := c.GetString("ids")
  11471. ids_arr := strings.Split(ids_str, ",")
  11472. fmt.Println(reg_type)
  11473. if settle_accounts_type == 1 { //日结
  11474. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11475. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11476. } else {
  11477. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11478. }
  11479. fmt.Println(prescriptions)
  11480. } else { //月结
  11481. start_time_str := c.GetString("start_time")
  11482. end_time_str := c.GetString("end_time")
  11483. timeLayout := "2006-01-02"
  11484. loc, _ := time.LoadLocation("Local")
  11485. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11486. if err != nil {
  11487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11488. return
  11489. }
  11490. recordStartTime := theStartTime.Unix()
  11491. start_time = recordStartTime
  11492. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11493. if err != nil {
  11494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11495. return
  11496. }
  11497. recordEndTime := theEndTime.Unix()
  11498. end_time = recordEndTime
  11499. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11500. }
  11501. if reg_type == 1111 || reg_type == 1112 {
  11502. reg_type = 11
  11503. }
  11504. timestamp := time.Now().Unix()
  11505. tempTime := time.Unix(timestamp, 0)
  11506. timeFormat := tempTime.Format("20060102150405")
  11507. chrgBchno := rand.Intn(100000) + 10000
  11508. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11509. strconv.FormatInt(his.PatientId, 10)
  11510. var ids []int64
  11511. for _, item := range prescriptions {
  11512. ids = append(ids, item.ID)
  11513. }
  11514. fmt.Println(ids)
  11515. var total float64
  11516. for _, item := range prescriptions {
  11517. fmt.Println(item)
  11518. if item.Type == 1 { //药品
  11519. for _, subItem := range item.HisDoctorAdviceInfo {
  11520. total = total + (subItem.Price * subItem.PrescribingNumber)
  11521. }
  11522. }
  11523. if item.Type == 2 { //项目
  11524. for _, subItem := range item.HisPrescriptionProject {
  11525. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11526. total = total + (subItem.Price * cnt)
  11527. }
  11528. }
  11529. for _, subItem := range item.HisAdditionalCharge {
  11530. total = total + (subItem.Price * float64(subItem.Count))
  11531. }
  11532. }
  11533. allTotal := fmt.Sprintf("%.2f", total)
  11534. totals, _ := strconv.ParseFloat(allTotal, 64)
  11535. order := &models.HisOrder{
  11536. UserOrgId: adminUser.CurrentOrgId,
  11537. HisPatientId: his.ID,
  11538. PatientId: id,
  11539. SettleAccountsDate: recordDateTime,
  11540. Ctime: time.Now().Unix(),
  11541. Mtime: time.Now().Unix(),
  11542. Status: 1,
  11543. OrderStatus: 1,
  11544. MdtrtId: his.Number,
  11545. Number: chrg_bchno,
  11546. MedfeeSumamt: totals,
  11547. SettleEndTime: end_time,
  11548. SettleStartTime: start_time,
  11549. SettleType: settle_accounts_type,
  11550. PsnPartAmt: totals,
  11551. PsnCashPay: totals,
  11552. PType: 2,
  11553. IsPre: 1,
  11554. MedType: strconv.Itoa(int(reg_type)),
  11555. Diagnosis: diagnosis_id,
  11556. }
  11557. err = service.CreateOrder(order)
  11558. if err != nil {
  11559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11560. return
  11561. }
  11562. var customs []*Custom
  11563. for _, item := range prescriptions {
  11564. fmt.Println(item.Type)
  11565. if item.Type == 1 { //药品
  11566. for _, subItem := range item.HisDoctorAdviceInfo {
  11567. cus := &Custom{
  11568. AdviceId: subItem.ID,
  11569. ProjectId: 0,
  11570. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11571. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11572. FeedetlSn: subItem.FeedetlSn,
  11573. Price: fmt.Sprintf("%.2f", subItem.Price),
  11574. MedListCodg: subItem.MedListCodg,
  11575. Type: 1,
  11576. }
  11577. customs = append(customs, cus)
  11578. }
  11579. }
  11580. if item.Type == 2 { //项目
  11581. for _, subItem := range item.HisPrescriptionProject {
  11582. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11583. cus := &Custom{
  11584. AdviceId: 0,
  11585. ProjectId: subItem.ID,
  11586. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11587. Cut: fmt.Sprintf("%.2f", cnt),
  11588. FeedetlSn: subItem.FeedetlSn,
  11589. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11590. MedListCodg: subItem.MedListCodg,
  11591. Type: 2,
  11592. }
  11593. customs = append(customs, cus)
  11594. }
  11595. }
  11596. for _, item := range item.HisAdditionalCharge {
  11597. cus := &Custom{
  11598. ItemId: item.ID,
  11599. AdviceId: 0,
  11600. ProjectId: 0,
  11601. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11602. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11603. FeedetlSn: item.FeedetlSn,
  11604. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11605. MedListCodg: item.XtHisAddtionConfig.Code,
  11606. Type: 3,
  11607. }
  11608. customs = append(customs, cus)
  11609. }
  11610. }
  11611. fmt.Println(customs)
  11612. for _, item := range customs {
  11613. var advice_id int64 = 0
  11614. var project_id int64 = 0
  11615. var item_id int64 = 0
  11616. var types int64 = 0
  11617. if item.Type == 1 {
  11618. advice_id = item.AdviceId
  11619. project_id = 0
  11620. item_id = 0
  11621. } else if item.Type == 2 {
  11622. advice_id = 0
  11623. item_id = 0
  11624. project_id = item.ProjectId
  11625. } else if item.Type == 3 {
  11626. advice_id = 0
  11627. item_id = item.ItemId
  11628. project_id = 0
  11629. }
  11630. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11631. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11632. pric, _ := strconv.ParseFloat(item.Price, 32)
  11633. info := &models.HisOrderInfo{
  11634. OrderNumber: order.Number,
  11635. UploadDate: time.Now().Unix(),
  11636. AdviceId: advice_id,
  11637. DetItemFeeSumamt: detItemFeeSumamt,
  11638. Cnt: cut,
  11639. Pric: pric,
  11640. PatientId: id,
  11641. Status: 1,
  11642. Mtime: time.Now().Unix(),
  11643. Ctime: time.Now().Unix(),
  11644. UserOrgId: adminUser.CurrentOrgId,
  11645. HisPatientId: his.ID,
  11646. OrderId: order.ID,
  11647. ProjectId: project_id,
  11648. Type: types,
  11649. ItemId: item_id,
  11650. }
  11651. service.CreateOrderInfo(info)
  11652. }
  11653. his.SickType = sick_type
  11654. service.UpdataHisPateint(&his)
  11655. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11656. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11657. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11658. if err == nil {
  11659. c.ServeSuccessJSON(map[string]interface{}{
  11660. "msg": "结算成功",
  11661. })
  11662. }
  11663. }
  11664. type CustomOrderInfo struct {
  11665. Name string
  11666. Spec string
  11667. Unit string
  11668. Count float64
  11669. Price float64
  11670. Total float64
  11671. }
  11672. func (c *HisApiController) GetPrivateExpensesInfo() {
  11673. order_id, _ := c.GetInt64("id", 0)
  11674. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11675. order, _ := service.GetHisOrderByID(order_id)
  11676. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11677. if order.ID == 0 {
  11678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11679. return
  11680. }
  11681. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11682. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11683. org_id := c.GetAdminUserInfo().CurrentOrgId
  11684. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11685. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11686. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11687. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11688. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11689. //var orderInfos_four []*models.HisOrderInfoTwo
  11690. //for _, item := range orderInfos_three {
  11691. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11692. // item.HisPrescriptionProject.IsCheckTeam = 1
  11693. // orderInfos_four = append(orderInfos_four, item)
  11694. //
  11695. // }
  11696. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11697. // item.HisPrescriptionProject.IsCheckTeam = 2
  11698. // orderInfos_two = append(orderInfos_two, item)
  11699. // }
  11700. //}
  11701. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11702. //var cus_slice []CustomOrderInfo
  11703. //for _, item := range new_order_info {
  11704. // var cus CustomOrderInfo
  11705. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11706. // cus.Unit = ""
  11707. // cus.Spec = ""
  11708. // var total float64
  11709. // for _, subItem := range orderInfos_four {
  11710. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11711. // total = total + subItem.DetItemFeeSumamt
  11712. // fmt.Println(subItem.DetItemFeeSumamt)
  11713. // }
  11714. // }
  11715. // cus.Count = 1
  11716. // cus.Total = total
  11717. // cus_slice = append(cus_slice, cus)
  11718. //}
  11719. orderInfos = append(orderInfos, orderInfos_two...)
  11720. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11721. //orderInfos = append(orderInfos, orderInfos_three...)
  11722. //}/**/
  11723. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11724. c.ServeSuccessJSON(map[string]interface{}{
  11725. "order": order,
  11726. "order_info": orderInfos,
  11727. "patient": patient,
  11728. "admin_info": adminInfo,
  11729. "his": his,
  11730. "current_admin": role,
  11731. "org_config": miConfig,
  11732. //"new_order_info": cus_slice,
  11733. })
  11734. }
  11735. func (this *HisApiController) ChangeMedType() {
  11736. med_type := this.GetString("med_type")
  11737. old_med_type := this.GetString("old_med_type")
  11738. ids := this.GetString("ids")
  11739. settle_type, _ := this.GetInt64("settle_type")
  11740. start_time := this.GetString("start_time")
  11741. end_time := this.GetString("end_time")
  11742. ids_arr := strings.Split(ids, ",")
  11743. if settle_type == 1 { //日结
  11744. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11745. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11746. prescription.MedType = med_type
  11747. err := service.SaveHisPrescriptionTwo(&prescription)
  11748. if err == nil {
  11749. this.ServeSuccessJSON(map[string]interface{}{
  11750. "msg": "修改成功",
  11751. })
  11752. } else {
  11753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11754. return
  11755. }
  11756. } else if settle_type == 2 {
  11757. timeLayout := "2006-01-02"
  11758. loc, _ := time.LoadLocation("Local")
  11759. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11760. if err != nil {
  11761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11762. return
  11763. }
  11764. recordStartTime := theStartTime.Unix()
  11765. start_time_timestamp := recordStartTime
  11766. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11767. if err != nil {
  11768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11769. return
  11770. }
  11771. recordEndTime := theEndTime.Unix()
  11772. end_time_timestamp := recordEndTime
  11773. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11774. if updateErr == nil {
  11775. this.ServeSuccessJSON(map[string]interface{}{
  11776. "msg": "修改成功",
  11777. })
  11778. } else {
  11779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11780. return
  11781. }
  11782. }
  11783. }
  11784. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11785. patient_id, _ := c.GetInt64("patient_id")
  11786. his_patient_id, _ := c.GetInt64("his_patient_id")
  11787. record_date := c.GetString("record_date")
  11788. start_time := c.GetString("start_time")
  11789. end_time := c.GetString("end_time")
  11790. order_status, _ := c.GetInt64("type", 0)
  11791. p_type, _ := c.GetInt64("p_type", 0)
  11792. order_id, _ := c.GetInt64("order_id", 0)
  11793. timeLayout := "2006-01-02"
  11794. loc, _ := time.LoadLocation("Local")
  11795. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11796. if err != nil {
  11797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11798. return
  11799. }
  11800. recordDateTime := theTime.Unix()
  11801. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11802. if err != nil {
  11803. }
  11804. startRecordDateTime := startTime.Unix()
  11805. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11806. if err != nil {
  11807. }
  11808. endRecordDateTime := endTime.Unix()
  11809. admin := c.GetAdminUserInfo()
  11810. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11811. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11812. order, _ := service.GetHisOrderByID(order_id)
  11813. var monthPrescriptions []*models.HisPrescription
  11814. if order_status == 1 || order_status == 0 {
  11815. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11816. } else if order_status == 2 {
  11817. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11818. }
  11819. var settle_total float64
  11820. for _, item := range monthPrescriptions {
  11821. if len(item.HisPrescriptionProject) > 0 {
  11822. for _, subItem := range item.HisPrescriptionProject {
  11823. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11824. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11825. settle_total = settle_total + total
  11826. }
  11827. }
  11828. if len(item.HisDoctorAdviceInfo) > 0 {
  11829. for _, subItem := range item.HisDoctorAdviceInfo {
  11830. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11831. settle_total = settle_total + total
  11832. }
  11833. }
  11834. }
  11835. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11836. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11837. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11838. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11839. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11840. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11841. //获取所有科室信息
  11842. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11843. var dia string
  11844. for _, item := range month_p_info {
  11845. if len(dia) == 0 {
  11846. dia = item.Diagnosis
  11847. } else {
  11848. dia = dia + "," + item.Diagnosis
  11849. }
  11850. }
  11851. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11852. dia_arr = removeEmptyStrings(dia_arr)
  11853. c.ServeSuccessJSON(map[string]interface{}{
  11854. "his_info": his_patient_info,
  11855. "xt_info": xt_patient_info,
  11856. "case_history": case_history,
  11857. "info": patientPrescriptionInfo,
  11858. "last_info": lastPatientPrescriptionInfo,
  11859. "month_prescriptions": monthPrescriptions,
  11860. "order": order,
  11861. "doctors": doctors,
  11862. "department": department,
  11863. "settle_total": settle_total,
  11864. "dia_arr": dia_arr,
  11865. })
  11866. return
  11867. }
  11868. func removeEmptyStrings(input []string) []string {
  11869. var output []string
  11870. for _, s := range input {
  11871. if s != "" {
  11872. output = append(output, s)
  11873. }
  11874. }
  11875. return output
  11876. }
  11877. func removeDuplicates(input []string) []string {
  11878. seen := make(map[string]bool)
  11879. output := []string{}
  11880. for _, s := range input {
  11881. if _, exists := seen[s]; !exists {
  11882. seen[s] = true
  11883. output = append(output, s)
  11884. }
  11885. }
  11886. return output
  11887. }
  11888. func (c *HisApiController) GetHisMonthPatientInfo() {
  11889. patient_id, _ := c.GetInt64("patient_id")
  11890. his_patient_id, _ := c.GetInt64("his_patient_id")
  11891. record_date := c.GetString("record_date")
  11892. number := c.GetString("number")
  11893. start_time := c.GetString("start_time")
  11894. end_time := c.GetString("end_time")
  11895. p_type, _ := c.GetInt64("p_type")
  11896. timeLayout := "2006-01-02"
  11897. loc, _ := time.LoadLocation("Local")
  11898. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11899. if err != nil {
  11900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11901. return
  11902. }
  11903. recordDateTime := theTime.Unix()
  11904. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11905. if err != nil {
  11906. }
  11907. startRecordDateTime := startTime.Unix()
  11908. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11909. if err != nil {
  11910. }
  11911. endRecordDateTime := endTime.Unix()
  11912. admin := c.GetAdminUserInfo()
  11913. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11914. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11915. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11916. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11917. var settle_total float64
  11918. for _, item := range monthPrescriptions {
  11919. if len(item.HisPrescriptionProject) > 0 {
  11920. for _, subItem := range item.HisPrescriptionProject {
  11921. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11922. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11923. settle_total = settle_total + total
  11924. }
  11925. }
  11926. if len(item.HisDoctorAdviceInfo) > 0 {
  11927. for _, subItem := range item.HisDoctorAdviceInfo {
  11928. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11929. settle_total = settle_total + total
  11930. }
  11931. }
  11932. }
  11933. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11934. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11935. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11936. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11937. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11938. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11939. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11940. //获取所有科室信息
  11941. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11942. c.ServeSuccessJSON(map[string]interface{}{
  11943. "his_info": his_patient_info,
  11944. "xt_info": xt_patient_info,
  11945. "case_history": case_history,
  11946. "info": patientPrescriptionInfo,
  11947. "month_prescriptions": monthPrescriptions,
  11948. "order": order,
  11949. "doctors": doctors,
  11950. "department": department,
  11951. "count": count,
  11952. "drugStockConfig": drugStockConfig,
  11953. "last_info": lastPatientPrescriptionInfo,
  11954. "settle_total": settle_total,
  11955. })
  11956. return
  11957. }
  11958. func (c *HisApiController) GetAllOrder() {
  11959. org_id := c.GetAdminUserInfo().CurrentOrgId
  11960. orders, _ := service.GetNewHisOrderList(org_id)
  11961. c.ServeSuccessJSON(map[string]interface{}{
  11962. "order": orders,
  11963. })
  11964. return
  11965. }
  11966. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11967. newArr = make([]*models.HisOrderInfoTwo, 0)
  11968. for i := 0; i < len(arr); i++ {
  11969. repeat := false
  11970. for j := i + 1; j < len(arr); j++ {
  11971. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11972. repeat = true
  11973. break
  11974. }
  11975. }
  11976. if !repeat {
  11977. newArr = append(newArr, arr[i])
  11978. }
  11979. }
  11980. return
  11981. }
  11982. // 修改处方退库操作 参数传修改之前的处方数据
  11983. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11984. if advice.ExecutionState == 1 {
  11985. //查询该病人该药品是否有库存记录
  11986. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11987. if errcode == gorm.ErrRecordNotFound {
  11988. } else {
  11989. //退库
  11990. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11991. if advice.PrescribingNumberUnit == drug.MinUnit {
  11992. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11993. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11994. //退库
  11995. warehouseInfo := models.DrugWarehouseInfo{
  11996. StockMinNumber: prescribingNumber,
  11997. }
  11998. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11999. operation_time := time.Now().Unix()
  12000. creater := advice.AdviceDoctor
  12001. ctime := time.Now().Unix()
  12002. timeStr := time.Now().Format("2006-01-02")
  12003. timeArr := strings.Split(timeStr, "-")
  12004. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12005. total = total + 1
  12006. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12007. cancelStock := models.DrugCancelStock{
  12008. OrderNumber: orderNumber,
  12009. OperaTime: operation_time,
  12010. OrgId: advice.UserOrgId,
  12011. Creater: creater,
  12012. Ctime: ctime,
  12013. Status: 1,
  12014. ReturnTime: advice.AdviceDate,
  12015. Dealer: info.Dealer,
  12016. Manufacturer: info.Manufacturer,
  12017. Type: 1,
  12018. }
  12019. service.AddSigleDrugCancelStock(&cancelStock)
  12020. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12021. dealer, _ := service.GetDealerById(info.Dealer)
  12022. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12023. cancelStockInfo := models.DrugCancelStockInfo{
  12024. OrderNumber: cancelInfo.OrderNumber,
  12025. CancelStockId: cancelInfo.ID,
  12026. DrugId: info.DrugId,
  12027. Count: info.Count,
  12028. Status: 1,
  12029. Ctime: ctime,
  12030. OrgId: advice.UserOrgId,
  12031. Type: 1,
  12032. Manufacturer: manufactureName.ManufacturerName,
  12033. Dealer: dealer.DealerName,
  12034. Total: 0,
  12035. RetailPrice: info.RetailPrice,
  12036. RetailTotalPrice: info.RetailTotalPrice,
  12037. Price: info.Price,
  12038. RegisterAccount: "",
  12039. Remark: info.Remark,
  12040. BatchNumber: info.BatchNumber,
  12041. MaxUnit: info.CountUnit,
  12042. ProductDate: info.ProductDate,
  12043. ExpiryDate: info.ExpiryDate,
  12044. BatchNumberId: info.WarehouseInfoId,
  12045. }
  12046. flow := models.DrugFlow{
  12047. WarehousingId: 0,
  12048. DrugId: info.DrugId,
  12049. Number: "",
  12050. BatchNumber: info.BatchNumber,
  12051. Count: info.Count,
  12052. UserOrgId: advice.UserOrgId,
  12053. PatientId: 0,
  12054. SystemTime: ctime,
  12055. ConsumableType: 4,
  12056. IsSys: 0,
  12057. WarehousingOrder: "",
  12058. WarehouseOutId: 0,
  12059. WarehouseOutOrderNumber: "",
  12060. IsEdit: 0,
  12061. CancelStockId: cancelStock.ID,
  12062. CancelOrderNumber: cancelStock.OrderNumber,
  12063. Manufacturer: info.Manufacturer,
  12064. Dealer: info.Dealer,
  12065. Creator: advice.UserOrgId,
  12066. UpdateCreator: 0,
  12067. Status: 1,
  12068. Ctime: time.Now().Unix(),
  12069. Mtime: 0,
  12070. Price: info.Price,
  12071. WarehousingDetailId: 0,
  12072. WarehouseOutDetailId: 0,
  12073. CancelOutDetailId: 0,
  12074. ExpireDate: info.ExpiryDate,
  12075. ProductDate: info.ProductDate,
  12076. MaxUnit: info.CountUnit,
  12077. MinUnit: "",
  12078. }
  12079. service.CreatedCancelStock(cancelStockInfo)
  12080. service.CreateDrugFlowOne(flow)
  12081. } else {
  12082. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12083. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12084. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12085. warehouseInfo := models.DrugWarehouseInfo{
  12086. StockMinNumber: prescribingNumber,
  12087. }
  12088. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12089. }
  12090. operation_time := time.Now().Unix()
  12091. creater := advice.AdviceDoctor
  12092. ctime := time.Now().Unix()
  12093. timeStr := time.Now().Format("2006-01-02")
  12094. timeArr := strings.Split(timeStr, "-")
  12095. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12096. total = total + 1
  12097. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12098. cancelStock := models.DrugCancelStock{
  12099. OrderNumber: orderNumber,
  12100. OperaTime: operation_time,
  12101. OrgId: advice.UserOrgId,
  12102. Creater: creater,
  12103. Ctime: ctime,
  12104. Status: 1,
  12105. ReturnTime: advice.AdviceDate,
  12106. Dealer: info.Dealer,
  12107. Manufacturer: info.Manufacturer,
  12108. Type: 1,
  12109. }
  12110. service.AddSigleDrugCancelStock(&cancelStock)
  12111. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12112. dealer, _ := service.GetDealerById(info.Dealer)
  12113. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12114. cancelStockInfo := models.DrugCancelStockInfo{
  12115. OrderNumber: cancelInfo.OrderNumber,
  12116. CancelStockId: cancelInfo.ID,
  12117. DrugId: info.DrugId,
  12118. Count: info.Count,
  12119. Status: 1,
  12120. Ctime: ctime,
  12121. OrgId: advice.UserOrgId,
  12122. Type: 1,
  12123. Manufacturer: manufactureName.ManufacturerName,
  12124. Dealer: dealer.DealerName,
  12125. Total: 0,
  12126. RetailPrice: info.RetailPrice,
  12127. RetailTotalPrice: info.RetailTotalPrice,
  12128. Price: info.Price,
  12129. RegisterAccount: "",
  12130. Remark: info.Remark,
  12131. BatchNumber: info.BatchNumber,
  12132. MaxUnit: info.CountUnit,
  12133. ProductDate: info.ProductDate,
  12134. ExpiryDate: info.ExpiryDate,
  12135. BatchNumberId: info.WarehouseInfoId,
  12136. }
  12137. flow := models.DrugFlow{
  12138. WarehousingId: 0,
  12139. DrugId: info.DrugId,
  12140. Number: "",
  12141. BatchNumber: info.BatchNumber,
  12142. Count: info.Count,
  12143. UserOrgId: advice.UserOrgId,
  12144. PatientId: 0,
  12145. SystemTime: ctime,
  12146. ConsumableType: 4,
  12147. IsSys: 0,
  12148. WarehousingOrder: "",
  12149. WarehouseOutId: 0,
  12150. WarehouseOutOrderNumber: "",
  12151. IsEdit: 0,
  12152. CancelStockId: cancelStock.ID,
  12153. CancelOrderNumber: cancelStock.OrderNumber,
  12154. Manufacturer: info.Manufacturer,
  12155. Dealer: info.Dealer,
  12156. Creator: advice.AdviceDoctor,
  12157. UpdateCreator: 0,
  12158. Status: 1,
  12159. Ctime: time.Now().Unix(),
  12160. Mtime: 0,
  12161. Price: info.Price,
  12162. WarehousingDetailId: 0,
  12163. WarehouseOutDetailId: 0,
  12164. CancelOutDetailId: 0,
  12165. ExpireDate: info.ExpiryDate,
  12166. ProductDate: info.ProductDate,
  12167. MaxUnit: info.CountUnit,
  12168. MinUnit: "",
  12169. }
  12170. service.CreatedCancelStock(cancelStockInfo)
  12171. service.CreateDrugFlowOne(flow)
  12172. }
  12173. }
  12174. }
  12175. return err
  12176. }
  12177. func (this *HisApiController) DeleteNCDS() {
  12178. id, _ := this.GetInt64("id", 0)
  12179. if id > 0 {
  12180. service.DeletePsnNCDSRecordById(id)
  12181. this.ServeSuccessJSON(map[string]interface{}{
  12182. "msg": "删除成功",
  12183. })
  12184. } else {
  12185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12186. return
  12187. }
  12188. }
  12189. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12190. id, _ := c.GetInt64("id")
  12191. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12192. c.ServeSuccessJSON(map[string]interface{}{
  12193. "advice": advice,
  12194. })
  12195. return
  12196. }
  12197. func (c *HisApiController) GetHisMonthChargePatientList() {
  12198. record_date := c.GetString("record_date")
  12199. start_time := c.GetString("start_time")
  12200. end_time := c.GetString("end_time")
  12201. timeLayout := "2006-01-02"
  12202. loc, _ := time.LoadLocation("Local")
  12203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12204. if err != nil {
  12205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12206. return
  12207. }
  12208. if err != nil {
  12209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12210. return
  12211. }
  12212. recordDateTime := theTime.Unix()
  12213. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12214. if err != nil {
  12215. }
  12216. startRecordDateTime := startTime.Unix()
  12217. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12218. if err != nil {
  12219. }
  12220. endRecordDateTime := endTime.Unix()
  12221. adminInfo := c.GetAdminUserInfo()
  12222. var tempMonthChargePatients []*service.MonthChargePatients
  12223. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12224. for _, item := range tempPatients {
  12225. //过滤没有处方的
  12226. if len(item.HisPrescription) == 0 {
  12227. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12228. }
  12229. }
  12230. c.ServeSuccessJSON(map[string]interface{}{
  12231. "list": tempMonthChargePatients,
  12232. })
  12233. }
  12234. // PrescriptionDifference 医嘱数量差值结构体
  12235. type PrescriptionDrugDifference struct {
  12236. DrugID int64 //基础库药品id
  12237. ID int64 //医嘱id
  12238. Difference float64 //差值
  12239. Unit string //单位
  12240. }
  12241. type PrescriptionGoodDifference struct {
  12242. GoodID int64 //基础库项目耗材id
  12243. ID int64 //医嘱id
  12244. Difference int64 //差值
  12245. Unit string //单位
  12246. Type int64 //类型
  12247. }
  12248. type EditCustomData struct {
  12249. adviceList []*models.HisDoctorAdviceInfo
  12250. projectList []*models.HisPrescriptionProject
  12251. }
  12252. type SrcCustomData struct {
  12253. adviceList []*models.HisDoctorAdviceInfo
  12254. projectList []*models.HisPrescriptionProject
  12255. }
  12256. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12257. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12258. differences := make([]*PrescriptionDrugDifference, 0)
  12259. // 创建一个 map 来存储第一个切片中的药品信息
  12260. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12261. for _, advice := range firstPrescription {
  12262. firstMap[advice.DrugId] = advice
  12263. }
  12264. // 遍历第二个切片中的药品信息,并比较数量差值
  12265. for _, advice := range secondPrescription {
  12266. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12267. diff := &PrescriptionDrugDifference{
  12268. DrugID: advice.DrugId,
  12269. ID: firstAdvice.ID,
  12270. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12271. Unit: firstAdvice.PrescribingNumberUnit,
  12272. }
  12273. differences = append(differences, diff)
  12274. }
  12275. }
  12276. return differences
  12277. }
  12278. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12279. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12280. differences := make([]*PrescriptionGoodDifference, 0)
  12281. // 创建一个 map 来存储第一个切片中的耗材信息
  12282. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12283. for _, good := range firstPrescription {
  12284. firstMap[good.ProjectId] = good
  12285. }
  12286. // 遍历第二个切片中的耗材信息,并比较数量差值
  12287. for _, good := range secondPrescription {
  12288. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12289. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12290. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12291. diff := &PrescriptionGoodDifference{
  12292. GoodID: good.ProjectId,
  12293. ID: firstGood.ID,
  12294. Difference: count - firstCount,
  12295. Unit: firstGood.Unit,
  12296. Type: firstGood.Type,
  12297. }
  12298. differences = append(differences, diff)
  12299. }
  12300. }
  12301. return differences
  12302. }
  12303. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12304. var adviceList []*models.HisDoctorAdviceInfo
  12305. var projectList []*models.HisPrescriptionProject
  12306. var advice_ids []int64
  12307. var project_ids []int64
  12308. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12309. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12310. //var tempPrescription *models.HisPrescriptionProjectscription
  12311. if len(prescriptions) > 0 {
  12312. for _, item := range prescriptions {
  12313. items := item.(map[string]interface{})
  12314. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12315. advices := items["advices"].([]interface{})
  12316. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12317. groupNo := int64(0)
  12318. ctime := time.Now().Unix()
  12319. mtime := ctime
  12320. if len(advices) > 0 {
  12321. for _, advice := range advices {
  12322. var s models.HisDoctorAdviceInfo
  12323. s.AdviceType = 2
  12324. s.StopState = 2
  12325. s.ExecutionState = 2
  12326. s.Status = 1
  12327. s.Groupno = groupNo
  12328. s.CreatedTime = ctime
  12329. s.UpdatedTime = mtime
  12330. s.IsSettle = 2
  12331. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12332. //存储切片中
  12333. if s.ID > 0 {
  12334. advice_ids = append(advice_ids, s.ID)
  12335. adviceList = append(adviceList, &s)
  12336. }
  12337. }
  12338. }
  12339. }
  12340. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12341. projects := items["project"].([]interface{})
  12342. if len(projects) > 0 {
  12343. for _, project := range projects {
  12344. var p models.HisPrescriptionProject
  12345. p.Ctime = time.Now().Unix()
  12346. p.Mtime = time.Now().Unix()
  12347. p.Status = 1
  12348. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12349. if p.ID > 0 {
  12350. project_ids = append(project_ids, p.ID)
  12351. projectList = append(projectList, &p)
  12352. }
  12353. }
  12354. }
  12355. }
  12356. }
  12357. }
  12358. }
  12359. editCustomData.projectList = projectList
  12360. editCustomData.adviceList = adviceList
  12361. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12362. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12363. srcCustomData.adviceList = list
  12364. srcCustomData.projectList = list2
  12365. return
  12366. }