his_api_controller.go 547KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079
  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/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. //if number >= 1000 {
  187. // zero = "0000" + strconv.FormatInt(number, 10)
  188. //} else if number >= 10000 {
  189. // zero = "000" + strconv.FormatInt(number, 10)
  190. //} else if number >= 100000 {
  191. // zero = "00" + strconv.FormatInt(number, 10)
  192. //} else if number >= 1000000 {
  193. // zero = "0" + strconv.FormatInt(number, 10)
  194. //} else {
  195. zero = "0" + strconv.FormatInt(number, 10)
  196. //}
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. if order.IsMedicineInsurance != 1 {
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. }
  1023. for _, item := range orderInfos {
  1024. if item.MedChrgitmType == "01" { //床位费
  1025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1028. }
  1029. if item.MedChrgitmType == "02" { //诊察费
  1030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1031. //zhenChaCostSelfTotal = zhenChaCostTotal
  1032. }
  1033. if item.MedChrgitmType == "03" { //检查费
  1034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1037. }
  1038. if item.MedChrgitmType == "02" { //检查费
  1039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1042. }
  1043. if item.MedChrgitmType == "04" { //化验费
  1044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "05" { //治疗费
  1049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "06" { //手术费
  1054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "09" { //西药费
  1064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "11" { //中成费
  1069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. }
  1079. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1080. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1081. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1082. var dia_config []*models.HisXtDiagnoseConfig
  1083. var diagnosis_ids []string
  1084. if his.ID > 0 {
  1085. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1086. } else {
  1087. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1088. }
  1089. for _, item := range diagnosis_ids {
  1090. id, _ := strconv.ParseInt(item, 10, 64)
  1091. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1092. dia_config = append(dia_config, diagnosisConfig)
  1093. }
  1094. var rf []CustomFundPay
  1095. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1096. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "patient": patient,
  1099. "order_infos": orderInfos,
  1100. "diagnosis": name,
  1101. "bedCostTotal": bedCostTotal,
  1102. "bedCostSelfTotal": bedCostTotal,
  1103. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1104. "operationCostTotal": operationCostTotal,
  1105. "operationCostSelfTotal": operationCostTotal,
  1106. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1107. "otherCostTotal": otherCostTotal,
  1108. "otherCostSelfTotal": otherCostTotal,
  1109. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1110. "materialCostTotal": materialCostTotal,
  1111. "materialCostSelfTotal": materialCostTotal,
  1112. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1113. "westernMedicineCostTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1116. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1119. "checkCostTotal": checkCostTotal,
  1120. "checkCostSelfTotal": checkCostTotal,
  1121. "zhenChaCostTotal": zhenChaCostTotal,
  1122. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1123. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1124. "laboratoryCostTotal": laboratoryCostTotal,
  1125. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1126. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1127. "treatCostTotal": treatCostTotal,
  1128. "treatCostSelfTotal": treatCostTotal,
  1129. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1130. "charge_admin": charge_admin,
  1131. "printor_admin": printor_admin,
  1132. "org_name": org.OrgName,
  1133. "org_code": miConfig.Code,
  1134. "name": patient.Name,
  1135. "number": order.MdtrtId,
  1136. "date": order.SettleAccountsDate,
  1137. "info": order,
  1138. "new_order": order,
  1139. "his_hospital": his_hospital,
  1140. "his": his,
  1141. "funds": rf,
  1142. "dia_config": dia_config,
  1143. })
  1144. }
  1145. func (c *HisApiController) RefudDetail() {
  1146. order_id, _ := c.GetInt64("order_id")
  1147. order, _ := service.GetHisOrderByID(order_id)
  1148. adminUser := c.GetAdminUserInfo()
  1149. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "撤销成功",
  1152. })
  1153. }
  1154. func (c *HisApiController) Sscard() {
  1155. //r := CardInit()
  1156. //if r == 0 {
  1157. // GetBaseInfo()
  1158. //}
  1159. //c.ServeSuccessJSON(map[string]interface{}{
  1160. // "list": "11",
  1161. //})
  1162. }
  1163. func GetBaseInfo() error {
  1164. //handle := syscall.MustLoadDLL("SSCard.dll")
  1165. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1166. //
  1167. //str := make([]byte, 256)
  1168. //str1 := make([]byte, 256)
  1169. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1170. //if ferr != nil {
  1171. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1172. // return ferr
  1173. //}
  1174. //
  1175. //fmt.Println(string(str))
  1176. //
  1177. //fmt.Println(r)
  1178. return nil
  1179. }
  1180. func CardInit() int {
  1181. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1182. //add := DllTestDef.MustFindProc("Init")
  1183. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1184. //if err != nil {
  1185. // fmt.Println("SSCard的运算结果为:", ret)
  1186. //}
  1187. //result := int(ret)
  1188. return 0
  1189. }
  1190. func IntPtr(n int) uintptr {
  1191. return uintptr(n)
  1192. }
  1193. func StrPtr(s string) uintptr {
  1194. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1195. }
  1196. func (c *HisApiController) GetHisPatientList() {
  1197. //types, _ := c.GetInt64("type", 0)
  1198. record_date := c.GetString("record_date")
  1199. sch_type, _ := c.GetInt64("sch_type")
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. recordDateTime := theTime.Unix()
  1208. adminInfo := c.GetAdminUserInfo()
  1209. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1210. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1211. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1212. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1213. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1214. //获取当前用户的信息
  1215. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1216. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1217. //获取所有科室信息
  1218. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1219. //var aa []service.PatientThree
  1220. noElementsSlice := make([]service.PatientThree, 0)
  1221. c.ServeSuccessJSON(map[string]interface{}{
  1222. "list": patients,
  1223. "list_two": patients_two,
  1224. "list_three": noElementsSlice,
  1225. "info": adminUserInfo,
  1226. "doctors": doctors,
  1227. "department": department,
  1228. })
  1229. }
  1230. type CustomTemplate struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1233. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1235. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1236. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1237. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1238. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1239. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1240. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1241. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1242. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1243. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1244. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1245. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1246. }
  1247. func (c *HisApiController) GetHisPatientInfo() {
  1248. patient_id, _ := c.GetInt64("patient_id")
  1249. his_patient_id, _ := c.GetInt64("his_patient_id")
  1250. record_date := c.GetString("record_date")
  1251. number := c.GetString("number")
  1252. //start_time := c.GetString("start_time")
  1253. //end_time := c.GetString("end_time")
  1254. p_type, _ := c.GetInt64("p_type")
  1255. timeLayout := "2006-01-02"
  1256. loc, _ := time.LoadLocation("Local")
  1257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1258. if err != nil {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. recordDateTime := theTime.Unix()
  1263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1264. //if err != nil {
  1265. //
  1266. //}
  1267. //startRecordDateTime := startTime.Unix()
  1268. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1269. //if err != nil {
  1270. //
  1271. //}
  1272. //endRecordDateTime := endTime.Unix()
  1273. admin := c.GetAdminUserInfo()
  1274. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1275. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1277. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. var prescriptions []*models.HisPrescription
  1279. var last_prescriptions []*models.HisPrescription
  1280. var sch_prescriptions []CustomTemplate
  1281. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. if p_type == 1 { //住院
  1283. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. for _, item := range prescriptions {
  1285. for _, subItem := range item.HisDoctorAdviceInfo {
  1286. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1287. if info.RetailPrice > 0 {
  1288. subItem.Drug.MinPrice = info.RetailPrice
  1289. }
  1290. }
  1291. }
  1292. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1293. } else { //门诊
  1294. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1295. for _, item := range prescriptions {
  1296. for _, subItem := range item.HisDoctorAdviceInfo {
  1297. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1298. if info.RetailPrice > 0 {
  1299. subItem.Drug.MinPrice = info.RetailPrice
  1300. }
  1301. }
  1302. }
  1303. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1304. }
  1305. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1306. if sch.ID > 0 {
  1307. var week string
  1308. t := time.Now()
  1309. switch t.Weekday().String() {
  1310. case "Monday":
  1311. week = "周一"
  1312. break
  1313. case "Tuesday":
  1314. week = "周二"
  1315. break
  1316. case "Wednesday":
  1317. week = "周三"
  1318. break
  1319. case "Thursday":
  1320. week = "周四"
  1321. break
  1322. case "Friday":
  1323. week = "周五"
  1324. break
  1325. case "Saturday":
  1326. week = "周六"
  1327. break
  1328. case "Sunday":
  1329. week = "周日"
  1330. break
  1331. }
  1332. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1333. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1334. //根据推送频率组装新的数组
  1335. for _, item := range temp_sch_prescriptions {
  1336. var cus CustomTemplate
  1337. cus.ID = item.ID
  1338. cus.UserOrgId = item.UserOrgId
  1339. cus.PatientId = item.PatientId
  1340. cus.MedType = item.MedType
  1341. cus.RecordDate = item.RecordDate
  1342. cus.Type = item.Type
  1343. cus.PType = item.PType
  1344. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1345. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1346. if subItem.FrequencyType == 1 { //每次必推
  1347. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1348. }
  1349. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1350. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1351. }
  1352. if subItem.FrequencyType == 2 { //按照天数频率
  1353. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1354. now := p.Unix()
  1355. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1356. dayStr2 := "-" + dayStr
  1357. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1358. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1359. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1360. if len(advices) == 0 {
  1361. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1362. }
  1363. }
  1364. }
  1365. }
  1366. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1367. if subItem.Type == 2 {
  1368. if subItem.XtHisProject.MedicalStatus != 1 {
  1369. if subItem.FrequencyType == 1 {
  1370. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1371. }
  1372. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1373. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1374. }
  1375. if subItem.FrequencyType == 2 {
  1376. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1377. now := p.Unix()
  1378. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1379. dayStr2 := "-" + dayStr
  1380. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1381. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1382. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1383. if len(projects) == 0 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. }
  1387. }
  1388. } else if subItem.Type == 3 {
  1389. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1390. if subItem.FrequencyType == 1 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1394. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1395. }
  1396. if subItem.FrequencyType == 2 {
  1397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1398. now := p.Unix()
  1399. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1400. dayStr2 := "-" + dayStr
  1401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1403. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1404. if len(projects) == 0 {
  1405. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sch_prescriptions = append(sch_prescriptions, cus)
  1412. }
  1413. for _, item := range sch_prescriptions {
  1414. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1415. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1416. }
  1417. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1418. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1419. }
  1420. }
  1421. }
  1422. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1423. if config.ID > 0 && config.IsOpen == 1 {
  1424. for _, item := range sch_prescriptions {
  1425. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1426. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1427. if info.RetailPrice > 0 {
  1428. subItem.Drug.MinPrice = info.RetailPrice
  1429. if admin.CurrentOrgId != 10598 {
  1430. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1431. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if config.ID > 0 && config.IsOpen == 1 {
  1438. for _, item := range sch_prescriptions {
  1439. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1440. if subItem.Type == 3 {
  1441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1442. if info.Price > 0 {
  1443. subItem.GoodInfo.PackingPrice = info.Price
  1444. if admin.CurrentOrgId != 10598 {
  1445. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1446. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1454. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1455. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1456. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1457. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1458. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1459. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1460. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1463. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1464. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1465. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  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. "prescriptionInfo": prescriptionInfo,
  1485. })
  1486. return
  1487. }
  1488. func (c *HisApiController) GetHisPrescriptionConfig() {
  1489. adminInfo := c.GetAdminUserInfo()
  1490. //获取医嘱模版
  1491. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1492. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1493. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1494. //获取所有基础药
  1495. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1496. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1497. if config.ID > 0 && config.IsOpen == 1 {
  1498. for _, item := range drugs {
  1499. var index = 0
  1500. for _, subItem := range item.OtherDrugWarehouseInfo {
  1501. if index == 0 {
  1502. index = index + 1
  1503. if subItem.RetailPrice > 0 {
  1504. item.MinPrice = subItem.RetailPrice
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1511. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1512. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1513. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1514. //获取所有科室信息
  1515. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1516. //获取诊断信息
  1517. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1518. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1519. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1520. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1521. //获取是否开启保存耗材出库的开关
  1522. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1523. c.ServeSuccessJSON(map[string]interface{}{
  1524. "drugs": drugs,
  1525. "advices_template": advices,
  1526. "drugways": drugways,
  1527. "efs": efs,
  1528. "doctors": doctors,
  1529. "department": department,
  1530. "sick": sick,
  1531. "additions": additions,
  1532. "diagnose": diagnose,
  1533. "manufacturers": manufacturers,
  1534. "goodOutOpen": goodOutOpen,
  1535. "patientDiagnose": patientDiagnose,
  1536. })
  1537. }
  1538. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1539. //获取所有基础药
  1540. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1541. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1542. if config.ID > 0 && config.IsOpen == 1 {
  1543. for _, item := range drugs {
  1544. var index = 0
  1545. for _, subItem := range item.OtherDrugWarehouseInfo {
  1546. if index == 0 {
  1547. index = index + 1
  1548. if subItem.RetailPrice > 0 {
  1549. item.MinPrice = subItem.RetailPrice
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1556. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1557. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1558. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1559. //获取所有科室信息
  1560. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1561. //获取诊断信息
  1562. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1563. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1564. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1565. //获取是否开启保存耗材出库的开关
  1566. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1567. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1568. c.ServeSuccessJSON(map[string]interface{}{
  1569. "drugs": drugs,
  1570. "advices_template": advices,
  1571. "drugways": drugways,
  1572. "efs": efs,
  1573. "doctors": doctors,
  1574. "department": department,
  1575. "sick": sick,
  1576. "additions": additions,
  1577. "diagnose": diagnose,
  1578. "manufacturers": manufacturers,
  1579. "goodOutOpen": goodOutOpen,
  1580. "patientDiagnose": patientDiagnose,
  1581. })
  1582. }
  1583. }
  1584. func (c *HisApiController) CreateHisPrescription() {
  1585. record_date := c.GetString("record_date")
  1586. patient_id, _ := c.GetInt64("patient_id")
  1587. reg_type, _ := c.GetInt64("reg_type")
  1588. diagnose := c.GetString("diagnose")
  1589. sick_type, _ := c.GetInt64("sick_type")
  1590. sick_history := c.GetString("sick_history")
  1591. doctor_id, _ := c.GetInt64("doctor", 0)
  1592. department, _ := c.GetInt64("department", 0)
  1593. his_patient_id, _ := c.GetInt64("his_patient_id")
  1594. p_type, _ := c.GetInt64("p_type")
  1595. patient_diagnose := c.GetString("patient_diagnose")
  1596. dataBody := make(map[string]interface{}, 0)
  1597. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1598. if err != nil {
  1599. utils.ErrorLog(err.Error())
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1601. return
  1602. }
  1603. //edit, src := GetCompareData(dataBody)
  1604. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1605. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1606. //fmt.Println(drugResult)
  1607. //fmt.Println(goodResult)
  1608. timeLayout := "2006-01-02"
  1609. loc, _ := time.LoadLocation("Local")
  1610. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1611. if err != nil {
  1612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. adminInfo := c.GetAdminUserInfo()
  1616. recordDateTime := theTime.Unix()
  1617. //查询默认出库仓库库存
  1618. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1619. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1620. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1621. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1622. if len(lists) == 1 {
  1623. his_patient_id = lists[0].ID
  1624. }
  1625. }
  1626. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1627. //自动出库的开关开启
  1628. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1629. //自动出库
  1630. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1631. //耗材保存处方出库
  1632. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1633. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1634. //已发药和已收费限制逻辑
  1635. isMidicine := false
  1636. isCharge := false
  1637. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1638. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1639. if len(prescriptions) > 0 {
  1640. for _, item := range prescriptions {
  1641. items := item.(map[string]interface{})
  1642. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1643. utils.ErrorLog("id")
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. id := int64(items["id"].(float64))
  1648. if id > 0 {
  1649. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1650. if err != nil {
  1651. if new_prescription.OrderStatus == 4 {
  1652. isCharge = true
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. if isMidicine == true {
  1660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1661. return
  1662. }
  1663. if isCharge == true {
  1664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1665. return
  1666. }
  1667. // 开始主事务
  1668. db := service.XTWriteDB()
  1669. tx := db.Begin()
  1670. // 在函数结束时处理事务回滚
  1671. defer func() {
  1672. if r := recover(); r != nil {
  1673. tx.Rollback()
  1674. }
  1675. }()
  1676. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1677. //药品发药出库
  1678. if pharmacyConfig.IsOpen == 1 {
  1679. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1680. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1681. if len(prescriptions) > 0 {
  1682. for _, item := range prescriptions {
  1683. items := item.(map[string]interface{})
  1684. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1685. advices := items["advices"].([]interface{})
  1686. if len(advices) > 0 {
  1687. for _, advice := range advices {
  1688. var drug_id int64
  1689. var prescribing_number float64
  1690. var prescribingNumberUnit string
  1691. var adviceId int64
  1692. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1693. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1694. }
  1695. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1696. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1697. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1698. }
  1699. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1700. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1701. }
  1702. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1703. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1704. }
  1705. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1706. if drug.ID == 0 {
  1707. tx.Rollback()
  1708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1709. return
  1710. }
  1711. //查询药品的所有库存
  1712. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1713. var total_count int64
  1714. for _, it := range list {
  1715. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1716. }
  1717. totals := strconv.FormatInt(total_count, 10)
  1718. //查询该药品是否存在开药记录
  1719. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1720. //新增处方盘点库存是否充足
  1721. if advicelist.ID == 0 {
  1722. all_count, _ := strconv.ParseFloat(totals, 64)
  1723. if prescribingNumberUnit == drug.MinUnit {
  1724. if drug.IsUse != 1 {
  1725. if drug.IsProject == 0 || drug.IsProject == 2 {
  1726. if all_count == 0 {
  1727. tx.Rollback()
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1729. return
  1730. }
  1731. if prescribing_number > all_count {
  1732. tx.Rollback()
  1733. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1734. return
  1735. }
  1736. }
  1737. }
  1738. }
  1739. if prescribingNumberUnit == drug.MaxUnit {
  1740. num := prescribing_number * float64(drug.MinNumber)
  1741. if drug.IsUse != 1 {
  1742. if drug.IsProject == 0 || drug.IsProject == 2 {
  1743. if all_count == 0 {
  1744. tx.Rollback()
  1745. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1746. return
  1747. }
  1748. if num > all_count {
  1749. tx.Rollback()
  1750. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1751. return
  1752. }
  1753. }
  1754. }
  1755. }
  1756. }
  1757. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1758. //不使用保存处方出库
  1759. if drugOutConfig.IsOpen != 1 {
  1760. //修改处方
  1761. for _, advice := range advices {
  1762. var drug_id int64
  1763. var prescribing_number float64
  1764. var prescribingNumberUnit string
  1765. var prescribingNumber string
  1766. var adviceId int64
  1767. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1768. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1769. }
  1770. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1771. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1772. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1773. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1774. }
  1775. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1776. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1777. }
  1778. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1779. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1780. }
  1781. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1782. if drug.ID == 0 {
  1783. tx.Rollback()
  1784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1785. return
  1786. }
  1787. //查询药品的所有库存
  1788. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1789. var total_count int64
  1790. for _, it := range list {
  1791. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1792. }
  1793. totals := strconv.FormatInt(total_count, 10)
  1794. //查询该药品是否存在开药记录
  1795. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1796. //新增处方
  1797. if advicelist.ID == 0 {
  1798. all_count, _ := strconv.ParseFloat(totals, 64)
  1799. if prescribingNumberUnit == drug.MinUnit {
  1800. if drug.IsUse != 1 {
  1801. if drug.IsProject == 0 || drug.IsProject == 2 {
  1802. if all_count == 0 {
  1803. tx.Rollback()
  1804. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1805. return
  1806. }
  1807. if prescribing_number > all_count {
  1808. tx.Rollback()
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1810. return
  1811. }
  1812. }
  1813. }
  1814. } else {
  1815. if prescribingNumberUnit == drug.MaxUnit {
  1816. num := prescribing_number * float64(drug.MinNumber)
  1817. if drug.IsUse != 1 {
  1818. if drug.IsProject == 0 || drug.IsProject == 2 {
  1819. if all_count == 0 {
  1820. tx.Rollback()
  1821. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1822. return
  1823. }
  1824. if num > all_count {
  1825. tx.Rollback()
  1826. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1827. return
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. }
  1834. //修改处方
  1835. if advicelist.ID > 0 {
  1836. var device_number int64
  1837. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1838. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1839. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1840. device_number = prescribingNumberInt * drug.MinNumber
  1841. }
  1842. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1843. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1844. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1845. device_number = prescribingNumberInt
  1846. }
  1847. var number_count int64
  1848. if prescribingNumberUnit == drug.MaxUnit {
  1849. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1850. number_count = prescribingNumberInt * drug.MinNumber
  1851. }
  1852. if prescribingNumberUnit == drug.MinUnit {
  1853. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1854. number_count = prescribingNumberInt
  1855. }
  1856. //如果修改的数量大于之前修改的数量
  1857. if (number_count - device_number) > 0 {
  1858. //如果修改的差数量 大于库存数量
  1859. if drug.IsUse != 1 {
  1860. if (number_count - device_number) > total_count {
  1861. tx.Rollback()
  1862. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1863. return
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. //已发药和已收费限制逻辑
  1878. //执行出库的逻辑
  1879. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1880. //校验库存总量
  1881. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1882. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1883. if len(prescriptions) > 0 {
  1884. for _, item := range prescriptions {
  1885. items := item.(map[string]interface{})
  1886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1887. advices := items["advices"].([]interface{})
  1888. if len(advices) > 0 {
  1889. for _, advice := range advices {
  1890. var drug_id int64
  1891. var prescribing_number float64
  1892. var prescribingNumberUnit string
  1893. var adviceId int64
  1894. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1895. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1896. }
  1897. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1898. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1899. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1900. }
  1901. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1902. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1903. }
  1904. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1905. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1906. }
  1907. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1908. if drug.ID == 0 {
  1909. tx.Rollback()
  1910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1911. return
  1912. }
  1913. //查询药品的所有库存
  1914. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1915. var total_count int64
  1916. for _, it := range list {
  1917. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1918. }
  1919. totals := strconv.FormatInt(total_count, 10)
  1920. //查询该药品是否存在开药记录
  1921. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1922. //查询最新批次库存
  1923. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1924. var batch_number_count int64
  1925. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1926. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1927. //新增处方
  1928. if advicelist.ID == 0 {
  1929. all_count, _ := strconv.ParseFloat(totals, 64)
  1930. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1931. if prescribingNumberUnit == drug.MinUnit {
  1932. if drug.IsUse != 1 {
  1933. if drug.IsProject == 0 || drug.IsProject == 2 {
  1934. if all_count == 0 {
  1935. tx.Rollback()
  1936. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1937. return
  1938. }
  1939. if prescribing_number > all_count {
  1940. tx.Rollback()
  1941. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1942. return
  1943. }
  1944. }
  1945. if adminInfo.CurrentOrgId == 10215 {
  1946. if prescribing_number > batch_number_all_count {
  1947. tx.Rollback()
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1949. return
  1950. }
  1951. }
  1952. }
  1953. }
  1954. if prescribingNumberUnit == drug.MaxUnit {
  1955. num := prescribing_number * float64(drug.MinNumber)
  1956. if drug.IsUse != 1 {
  1957. if drug.IsProject == 0 || drug.IsProject == 2 {
  1958. if all_count == 0 {
  1959. tx.Rollback()
  1960. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1961. return
  1962. }
  1963. if num > all_count {
  1964. tx.Rollback()
  1965. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1966. return
  1967. }
  1968. }
  1969. if adminInfo.CurrentOrgId == 10215 {
  1970. if num > batch_number_all_count {
  1971. tx.Rollback()
  1972. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1973. return
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. //不是保存处方出库
  1980. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1981. if drugOutConfig.IsOpen != 1 {
  1982. //修改处方
  1983. for _, advice := range advices {
  1984. var drug_id int64
  1985. var prescribing_number float64
  1986. var prescribingNumberUnit string
  1987. var prescribingNumber string
  1988. var adviceId int64
  1989. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1990. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1991. }
  1992. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1993. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1994. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1995. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1996. }
  1997. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1998. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1999. }
  2000. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2001. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2002. }
  2003. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2004. if drug.ID == 0 {
  2005. tx.Rollback()
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2007. return
  2008. }
  2009. //查询药品的所有库存
  2010. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2011. var total_count int64
  2012. for _, it := range list {
  2013. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2014. }
  2015. totals := strconv.FormatInt(total_count, 10)
  2016. //查询该药品是否存在开药记录
  2017. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2018. //新增处方
  2019. if advicelist.ID == 0 {
  2020. //查询最新批次库存
  2021. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2022. var batch_number_count int64
  2023. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2024. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2025. all_count, _ := strconv.ParseFloat(totals, 64)
  2026. if all_count == 0 {
  2027. tx.Rollback()
  2028. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2029. return
  2030. }
  2031. if prescribingNumberUnit == drug.MinUnit {
  2032. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2033. if drug.IsUse != 1 {
  2034. if drug.IsProject == 0 || drug.IsProject == 2 {
  2035. if all_count == 0 {
  2036. tx.Rollback()
  2037. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2038. return
  2039. }
  2040. if prescribing_number > all_count {
  2041. tx.Rollback()
  2042. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2043. return
  2044. }
  2045. }
  2046. if adminInfo.CurrentOrgId == 10215 {
  2047. if prescribing_number > batch_number_all_count {
  2048. tx.Rollback()
  2049. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2050. return
  2051. }
  2052. }
  2053. }
  2054. } else {
  2055. if prescribingNumberUnit == drug.MaxUnit {
  2056. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2057. num := prescribing_number * float64(drug.MinNumber)
  2058. if drug.IsUse != 1 {
  2059. if drug.IsProject == 0 || drug.IsProject == 2 {
  2060. if all_count == 0 {
  2061. tx.Rollback()
  2062. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2063. return
  2064. }
  2065. if num > all_count {
  2066. tx.Rollback()
  2067. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2068. return
  2069. }
  2070. }
  2071. if adminInfo.CurrentOrgId == 10215 {
  2072. if prescribing_number > batch_number_all_count {
  2073. tx.Rollback()
  2074. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2075. return
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. //修改处方
  2083. if advicelist.ID > 0 {
  2084. //查询最新批次库存
  2085. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2086. var batch_number_count int64
  2087. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2088. var device_number int64
  2089. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2090. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2091. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2092. device_number = prescribingNumberInt * drug.MinNumber
  2093. }
  2094. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2095. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2096. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2097. device_number = prescribingNumberInt
  2098. //回退库存
  2099. }
  2100. var number_count int64
  2101. if prescribingNumberUnit == drug.MaxUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt * drug.MinNumber
  2104. //回退库存
  2105. }
  2106. if prescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt
  2109. //回退库存
  2110. }
  2111. //如果修改的数量大于之前修改的数量
  2112. if (number_count - device_number) > 0 {
  2113. //如果修改的差数量 大于库存数量
  2114. if drug.IsUse != 1 {
  2115. if drug.IsProject == 0 || drug.IsProject == 2 {
  2116. if total_count == 0 {
  2117. tx.Rollback()
  2118. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2119. return
  2120. }
  2121. if (number_count - device_number) > total_count {
  2122. tx.Rollback()
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2124. return
  2125. }
  2126. if (number_count - device_number) > batch_number_count {
  2127. tx.Rollback()
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2129. return
  2130. }
  2131. }
  2132. if adminInfo.CurrentOrgId == 10215 {
  2133. // 查询该药品最后一次出库记录
  2134. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2135. var out_count int64
  2136. var in_count int64
  2137. var stock_max_number int64
  2138. var stock_min_number int64
  2139. for _, it := range outInfo {
  2140. if it.CountUnit == drug.MaxUnit {
  2141. it.Count = it.Count * drug.MinNumber
  2142. }
  2143. out_count += it.Count
  2144. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2145. stock_max_number = warehouseInfoList.StockMaxNumber
  2146. stock_min_number = warehouseInfoList.StockMinNumber
  2147. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2148. }
  2149. if out_count > 0 {
  2150. if (number_count - device_number) > in_count {
  2151. tx.Rollback()
  2152. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2153. return
  2154. }
  2155. }
  2156. // 未出库
  2157. if out_count == 0 {
  2158. var sum_in_count int64
  2159. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2160. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2161. //如果修改的数量大于有库存的第一个批次
  2162. if number_count > sum_in_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //药品发药
  2172. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2173. //不使用药品发药的功能
  2174. //if pharmacyConfig.IsOpen != 1 {
  2175. // if device_number != number_count {
  2176. //
  2177. // //查询该药品的出库记录
  2178. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2179. // if len(outListExport) > 0 {
  2180. // //
  2181. // for _, item := range outListExport {
  2182. // //回退库存
  2183. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2184. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2185. // }
  2186. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2187. // var stock_max_number int64
  2188. // var stock_min_number int64
  2189. //
  2190. // if number_count >= drug.MinNumber {
  2191. //
  2192. // stock_max_number = device_number / drug.MinNumber
  2193. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2194. //
  2195. // stock_min_number = device_number % drug.MinNumber
  2196. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2197. //
  2198. // } else {
  2199. //
  2200. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2201. //
  2202. // }
  2203. // }
  2204. //
  2205. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2206. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2207. // }
  2208. // }
  2209. // }
  2210. //
  2211. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2212. // var sum_count int64
  2213. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2214. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2215. // for _, its := range stockInfo {
  2216. // if its.MaxUnit == drug.MaxUnit {
  2217. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2218. // }
  2219. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2220. // }
  2221. // //更新字典里面的库存
  2222. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2223. //
  2224. // //剩余库存
  2225. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2226. //
  2227. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2228. // //减少出库数量
  2229. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2230. //
  2231. // }
  2232. //}
  2233. }
  2234. }
  2235. }
  2236. //保存处方开药
  2237. if drugOutConfig.IsOpen == 1 {
  2238. //修改处方
  2239. for _, advice := range advices {
  2240. var drug_id int64
  2241. var prescribing_number float64
  2242. var prescribingNumberUnit string
  2243. var prescribingNumber string
  2244. var adviceId int64
  2245. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2246. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2247. }
  2248. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2249. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2250. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2251. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2252. }
  2253. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2254. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2255. }
  2256. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2257. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2258. }
  2259. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2260. if drug.ID == 0 {
  2261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2262. return
  2263. }
  2264. //查询药品的所有库存
  2265. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2266. var total_count int64
  2267. for _, it := range list {
  2268. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2269. }
  2270. totals := strconv.FormatInt(total_count, 10)
  2271. //查询该药品是否存在开药记录
  2272. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2273. //新增处方
  2274. if advicelist.ID == 0 {
  2275. //查询最新批次库存
  2276. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2277. var batch_number_count int64
  2278. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2279. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2280. all_count, _ := strconv.ParseFloat(totals, 64)
  2281. if prescribingNumberUnit == drug.MinUnit {
  2282. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2283. if drug.IsUse != 1 {
  2284. if drug.IsProject == 0 || drug.IsProject == 2 {
  2285. if all_count == 0 {
  2286. tx.Rollback()
  2287. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2288. return
  2289. }
  2290. if prescribing_number > all_count {
  2291. tx.Rollback()
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. }
  2296. if adminInfo.CurrentOrgId == 10215 {
  2297. if prescribing_number > batch_number_all_count {
  2298. tx.Rollback()
  2299. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2300. return
  2301. }
  2302. }
  2303. }
  2304. } else {
  2305. if prescribingNumberUnit == drug.MaxUnit {
  2306. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2307. num := prescribing_number * float64(drug.MinNumber)
  2308. if drug.IsUse != 1 {
  2309. if drug.IsProject == 0 || drug.IsProject == 2 {
  2310. if all_count == 0 {
  2311. tx.Rollback()
  2312. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2313. return
  2314. }
  2315. if num > all_count {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2318. return
  2319. }
  2320. }
  2321. if adminInfo.CurrentOrgId == 10215 {
  2322. if prescribing_number > batch_number_all_count {
  2323. tx.Rollback()
  2324. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2325. return
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. }
  2332. //修改处方
  2333. if advicelist.ID > 0 {
  2334. //查询最新批次库存
  2335. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2336. var batch_number_count int64
  2337. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2338. var device_number int64
  2339. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2340. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2341. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2342. device_number = prescribingNumberInt * drug.MinNumber
  2343. }
  2344. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2345. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2346. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2347. device_number = prescribingNumberInt
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. }
  2354. if prescribingNumberUnit == drug.MinUnit {
  2355. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2356. number_count = prescribingNumberInt
  2357. }
  2358. //如果修改的数量大于之前修改的数量
  2359. if (number_count - device_number) > 0 {
  2360. //如果修改的差数量 大于库存数量
  2361. if drug.IsUse != 1 {
  2362. if drug.IsProject == 0 || drug.IsProject == 2 {
  2363. if total_count == 0 {
  2364. tx.Rollback()
  2365. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2366. return
  2367. }
  2368. if (number_count - device_number) > total_count {
  2369. tx.Rollback()
  2370. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2371. return
  2372. }
  2373. }
  2374. if adminInfo.CurrentOrgId == 10215 {
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2382. //查询历史出库数据总批次
  2383. // 查询该药品最后一次出库记录
  2384. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2385. var out_count int64
  2386. var in_count int64
  2387. var stock_max_number int64
  2388. var stock_min_number int64
  2389. for _, it := range outInfo {
  2390. if it.CountUnit == drug.MaxUnit {
  2391. it.Count = it.Count * drug.MinNumber
  2392. }
  2393. out_count += it.Count
  2394. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2395. stock_max_number = warehouseInfoList.StockMaxNumber
  2396. stock_min_number = warehouseInfoList.StockMinNumber
  2397. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2398. }
  2399. if out_count > 0 {
  2400. if (number_count - device_number) > in_count {
  2401. tx.Rollback()
  2402. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2403. return
  2404. }
  2405. }
  2406. // 未出库
  2407. if out_count == 0 {
  2408. var sum_in_count int64
  2409. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2410. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2411. if sum_in_count == 0 {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. //如果修改的数量大于有库存的第一个批次
  2417. if number_count > sum_in_count {
  2418. tx.Rollback()
  2419. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2420. return
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. //校验耗材库存
  2437. if goodOutConfig.IsOpen == 1 {
  2438. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2439. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2440. if len(prescriptions) > 0 {
  2441. for _, item := range prescriptions {
  2442. items := item.(map[string]interface{})
  2443. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2444. projects := items["project"].([]interface{})
  2445. if len(projects) > 0 {
  2446. for _, project := range projects {
  2447. var project_id int64
  2448. var project_type int64
  2449. var totals float64
  2450. var project_name string
  2451. var parsetotal int64
  2452. var id int64
  2453. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2454. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2455. }
  2456. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2457. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2458. }
  2459. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2460. total, _ := project.(map[string]interface{})["total"].(string)
  2461. totals, _ = strconv.ParseFloat(total, 64)
  2462. }
  2463. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2464. project_name = project.(map[string]interface{})["project_name"].(string)
  2465. }
  2466. if project_type == 3 {
  2467. //查找该耗材的出库记录
  2468. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2469. if len(goodWarehouseInfo) == 0 {
  2470. //查询耗材库存
  2471. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2472. var stock_count int64
  2473. for _, it := range list {
  2474. stock_count += it.StockCount
  2475. }
  2476. stock_counts := strconv.FormatInt(stock_count, 10)
  2477. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2478. if stock_total_count == 0 {
  2479. tx.Rollback()
  2480. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2481. return
  2482. }
  2483. if totals > stock_total_count {
  2484. tx.Rollback()
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. }
  2489. if len(goodWarehouseInfo) > 0 {
  2490. //查询该患者耗材的历史数据
  2491. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2492. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2493. //数量发生改变
  2494. if parsetotal != count {
  2495. //如果现在的数量大于历史数量,就要看库存是否足够
  2496. if parsetotal > count {
  2497. //查询耗材所有库存
  2498. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2499. var stock_count int64
  2500. for _, it := range list {
  2501. stock_count += it.StockCount
  2502. }
  2503. //库存不足
  2504. if stock_count == 0 {
  2505. tx.Rollback()
  2506. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2507. return
  2508. }
  2509. if (parsetotal - count) > stock_count {
  2510. tx.Rollback()
  2511. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2512. return
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. }
  2525. //不使用耗材保存处方出库
  2526. if goodOutConfig.IsOpen != 1 {
  2527. if stockConfig.IsOpen == 1 {
  2528. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2529. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2530. if len(prescriptions) > 0 {
  2531. for _, item := range prescriptions {
  2532. items := item.(map[string]interface{})
  2533. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2534. projects := items["project"].([]interface{})
  2535. if len(projects) > 0 {
  2536. for _, project := range projects {
  2537. var project_id int64
  2538. var project_type int64
  2539. var totals float64
  2540. var project_name string
  2541. var parsetotal int64
  2542. var id int64
  2543. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2544. id = int64(project.(map[string]interface{})["id"].(float64))
  2545. }
  2546. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2547. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2548. }
  2549. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2550. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2551. }
  2552. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2553. total, _ := project.(map[string]interface{})["total"].(string)
  2554. totals, _ = strconv.ParseFloat(total, 64)
  2555. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2556. }
  2557. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2558. project_name = project.(map[string]interface{})["project_name"].(string)
  2559. }
  2560. if project_type == 3 {
  2561. //查找该耗材的出库记录
  2562. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2563. //没有出库记录
  2564. if len(goodWarehouseInfo) == 0 {
  2565. //查询耗材库存
  2566. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2567. var stock_count int64
  2568. for _, it := range list {
  2569. stock_count += it.StockCount
  2570. }
  2571. stock_counts := strconv.FormatInt(stock_count, 10)
  2572. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2573. if stock_total_count == 0 {
  2574. tx.Rollback()
  2575. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2576. return
  2577. }
  2578. if totals > stock_total_count {
  2579. tx.Rollback()
  2580. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2581. return
  2582. }
  2583. //查找今日该患者已经出库的所有耗材
  2584. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2585. for _, item := range goodList {
  2586. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2587. var flush_count int64
  2588. for _, it := range goodListSix {
  2589. flush_count += it.StockCount
  2590. }
  2591. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2592. creater := adminInfo.AdminUser.Id
  2593. if errs != nil {
  2594. goodErrcode := models.XtGoodErrcode{
  2595. UserOrgId: item.OrgId,
  2596. Errcode: "手动出库更新剩余出库失败",
  2597. GoodId: item.GoodId,
  2598. Status: 1,
  2599. Ctime: time.Now().Unix(),
  2600. Mtime: 0,
  2601. Count: 0,
  2602. StockCount: 0,
  2603. Creater: creater,
  2604. BatchNumberId: 0,
  2605. WarehouseOutId: 0,
  2606. }
  2607. service.CreateGoodErrcode(goodErrcode)
  2608. }
  2609. }
  2610. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2611. }
  2612. //有出库记录
  2613. if len(goodWarehouseInfo) > 0 {
  2614. //查询该患者耗材的历史数据
  2615. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2616. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2617. //数量发生改变
  2618. if parsetotal != count {
  2619. //查找今日该患者已经出库的所有耗材
  2620. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2621. for _, item := range goodList {
  2622. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2623. var flush_count int64
  2624. for _, it := range goodListSix {
  2625. flush_count += it.StockCount
  2626. }
  2627. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2628. //减少出库数量
  2629. creater := adminInfo.AdminUser.Id
  2630. if errs != nil {
  2631. goodErrcode := models.XtGoodErrcode{
  2632. UserOrgId: item.OrgId,
  2633. Errcode: "手动出库更新剩余出库失败",
  2634. GoodId: item.GoodId,
  2635. Status: 1,
  2636. Ctime: time.Now().Unix(),
  2637. Mtime: 0,
  2638. Count: 0,
  2639. StockCount: 0,
  2640. Creater: creater,
  2641. BatchNumberId: 0,
  2642. WarehouseOutId: 0,
  2643. }
  2644. service.CreateGoodErrcode(goodErrcode)
  2645. }
  2646. //查询默认仓库
  2647. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2648. var total_count int64
  2649. for _, it := range stockList {
  2650. total_count += it.StockCount
  2651. }
  2652. //基础库插入数据
  2653. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2654. }
  2655. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. }
  2667. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2668. var hpInfo models.HisPrescriptionInfo
  2669. if info.ID == 0 {
  2670. var randNum int
  2671. randNum = rand.Intn(10000) + 1000
  2672. timestamp := time.Now().Unix()
  2673. tempTime := time.Unix(timestamp, 0)
  2674. timeFormat := tempTime.Format("20060102150405")
  2675. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2676. hpInfo = models.HisPrescriptionInfo{
  2677. HisPatientId: his_patient_id,
  2678. UserOrgId: adminInfo.CurrentOrgId,
  2679. RecordDate: theTime.Unix(),
  2680. PatientId: patient_id,
  2681. Status: 1,
  2682. Ctime: time.Now().Unix(),
  2683. Mtime: time.Now().Unix(),
  2684. Creator: adminInfo.AdminUser.Id,
  2685. Modifier: adminInfo.AdminUser.Id,
  2686. Diagnosis: diagnose,
  2687. SickHistory: sick_history,
  2688. Departments: department,
  2689. RegisterType: reg_type,
  2690. PrescriptionNumber: p_number,
  2691. PrescriptionStatus: 1,
  2692. Doctor: role.UserName,
  2693. DoctorId: doctor_id,
  2694. SickType: sick_type,
  2695. PType: p_type,
  2696. PatientDiagnosis: patient_diagnose,
  2697. }
  2698. service.SavePatientPrescriptionInfo(hpInfo)
  2699. //创建步骤表
  2700. finish := models.XtDialysisFinish{
  2701. IsFinish: 1,
  2702. UserOrgId: adminInfo.CurrentOrgId,
  2703. Status: 1,
  2704. Ctime: time.Now().Unix(),
  2705. Mtime: 0,
  2706. Module: 4,
  2707. RecordDate: theTime.Unix(),
  2708. Sourse: 1,
  2709. PatientId: patient_id,
  2710. }
  2711. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2712. if dialysisFinish.ID == 0 {
  2713. service.CreateDialysisFinish(finish)
  2714. }
  2715. redis := service.RedisClient()
  2716. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2717. redis.Set(key, "", time.Second)
  2718. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2719. redis.Set(keyOne, "", time.Second)
  2720. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2721. redis.Set(keySeven, "", time.Second)
  2722. defer redis.Close()
  2723. } else {
  2724. hpInfo = models.HisPrescriptionInfo{
  2725. ID: info.ID,
  2726. UserOrgId: adminInfo.CurrentOrgId,
  2727. RecordDate: info.RecordDate,
  2728. PatientId: info.PatientId,
  2729. Status: 1,
  2730. Ctime: info.Ctime,
  2731. Mtime: time.Now().Unix(),
  2732. Creator: info.Creator,
  2733. Modifier: adminInfo.AdminUser.Id,
  2734. Diagnosis: diagnose,
  2735. SickHistory: sick_history,
  2736. Departments: department,
  2737. RegisterType: reg_type,
  2738. PrescriptionNumber: info.PrescriptionNumber,
  2739. Doctor: role.UserName,
  2740. PrescriptionStatus: info.PrescriptionStatus,
  2741. DoctorId: doctor_id,
  2742. SickType: sick_type,
  2743. PType: info.PType,
  2744. HisPatientId: info.HisPatientId,
  2745. PatientDiagnosis: patient_diagnose,
  2746. }
  2747. service.SavePatientPrescriptionInfo(hpInfo)
  2748. //创建步骤表
  2749. finish := models.XtDialysisFinish{
  2750. IsFinish: 1,
  2751. UserOrgId: adminInfo.CurrentOrgId,
  2752. Status: 1,
  2753. Ctime: time.Now().Unix(),
  2754. Mtime: 0,
  2755. Module: 4,
  2756. RecordDate: info.RecordDate,
  2757. Sourse: 1,
  2758. PatientId: info.PatientId,
  2759. }
  2760. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2761. if dialysisFinish.ID == 0 {
  2762. service.CreateDialysisFinish(finish)
  2763. }
  2764. redis := service.RedisClient()
  2765. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2766. redis.Set(key, "", time.Second)
  2767. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2768. redis.Set(keyOne, "", time.Second)
  2769. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2770. redis.Set(keySeven, "", time.Second)
  2771. defer redis.Close()
  2772. }
  2773. //定义切片
  2774. var adviceList []models.HisDoctorAdviceInfo
  2775. var projectList []models.HisPrescriptionProject
  2776. 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 || adminInfo.CurrentOrgId == 10644 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. var tempPrescription *models.HisPrescription
  2780. if len(prescriptions) > 0 {
  2781. for _, item := range prescriptions {
  2782. // 开始外部循环的事务
  2783. tx := db.Begin()
  2784. // 在函数结束时处理事务回滚
  2785. defer func() {
  2786. if r := recover(); r != nil {
  2787. tx.Rollback()
  2788. }
  2789. }()
  2790. items := item.(map[string]interface{})
  2791. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2792. utils.ErrorLog("id")
  2793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2794. return
  2795. }
  2796. id := int64(items["id"].(float64))
  2797. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2798. tempPrescription = &new_prescription
  2799. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2800. utils.ErrorLog("type")
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2802. return
  2803. }
  2804. types := int64(items["type"].(float64))
  2805. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2806. utils.ErrorLog("med_type")
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2811. if med_type == "0" {
  2812. med_type = "14"
  2813. }
  2814. //if order_status == 0 {
  2815. // order_status = 1
  2816. //}
  2817. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2818. utils.ErrorLog("pre_time")
  2819. }
  2820. preTime, _ := items["pre_time"].(string)
  2821. fmt.Println("preTime", preTime)
  2822. timeLayout := "2006-01-02"
  2823. loc, _ := time.LoadLocation("Local")
  2824. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2825. result := strings.Split(preTime, " ")
  2826. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2827. if err != nil {
  2828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2829. return
  2830. }
  2831. pTime := theTime2.Unix()
  2832. ctime := time.Now().Unix()
  2833. if tempPrescription.ID == 0 {
  2834. prescription := &models.HisPrescription{
  2835. ID: 0,
  2836. PatientId: patient_id,
  2837. UserOrgId: adminInfo.CurrentOrgId,
  2838. RecordDate: recordDateTime,
  2839. Ctime: ctime,
  2840. Mtime: ctime,
  2841. Type: types,
  2842. Modifier: adminInfo.AdminUser.Id,
  2843. Creator: adminInfo.AdminUser.Id,
  2844. Status: 1,
  2845. Doctor: role.UserName,
  2846. HisPatientId: his_patient_id,
  2847. OrderStatus: 1,
  2848. BatchNumber: "",
  2849. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2850. PreTime: pTime,
  2851. PType: p_type,
  2852. MedType: med_type,
  2853. }
  2854. tempPrescription = prescription
  2855. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2856. redis := service.RedisClient()
  2857. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2858. redis.Set(key, "", time.Second)
  2859. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2860. redis.Set(keyOne, "", time.Second)
  2861. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2862. redis.Set(keySeven, "", time.Second)
  2863. defer redis.Close()
  2864. } else {
  2865. tempPrescription.ID = id
  2866. tempPrescription.Type = types
  2867. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2868. tempPrescription.Mtime = time.Now().Unix()
  2869. tempPrescription.Doctor = role.UserName
  2870. //tempPrescription.OrderStatus = order_status
  2871. tempPrescription.PreTime = pTime
  2872. tempPrescription.MedType = med_type
  2873. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2874. redis := service.RedisClient()
  2875. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2876. redis.Set(key, "", time.Second)
  2877. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2878. redis.Set(keyOne, "", time.Second)
  2879. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2880. redis.Set(keySeven, "", time.Second)
  2881. defer redis.Close()
  2882. }
  2883. //service.SaveHisPrescription(prescription)
  2884. //更改患者挂号状态
  2885. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2886. fmt.Println("更改失败", err2)
  2887. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2888. advices := items["advices"].([]interface{})
  2889. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2890. groupNo := int64(0)
  2891. if len(advices) > 0 {
  2892. for _, advice := range advices {
  2893. tx := db.Begin()
  2894. // 在函数结束时处理事务回滚
  2895. defer func() {
  2896. if r := recover(); r != nil {
  2897. tx.Rollback()
  2898. }
  2899. }()
  2900. var s models.HisDoctorAdviceInfo
  2901. s.PrescriptionId = tempPrescription.ID
  2902. s.AdviceType = 2
  2903. s.AdviceDoctor = doctor_id
  2904. s.StopState = 2
  2905. s.ExecutionState = 2
  2906. s.AdviceDate = theTime3.Unix()
  2907. s.Status = 1
  2908. s.UserOrgId = adminInfo.CurrentOrgId
  2909. s.RecordDate = theTime3.Unix()
  2910. s.StartTime = tempPrescription.PreTime
  2911. s.Groupno = groupNo
  2912. s.PatientId = patient_id
  2913. s.HisPatientId = his_patient_id
  2914. s.StartTime = pTime
  2915. s.IsSettle = 2
  2916. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2917. if errcode > 0 {
  2918. c.ServeFailJSONWithSGJErrorCode(errcode)
  2919. return
  2920. }
  2921. s.StartTime = pTime
  2922. var total_count int64 //处方总库存
  2923. //查询改药品信息
  2924. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2925. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2926. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2927. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2928. total_count += prescribingNumberSeven * medical.MinNumber
  2929. }
  2930. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2931. total_count += prescribingNumberSeven
  2932. }
  2933. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2934. total_count += prescribingNumberSeven
  2935. }
  2936. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2937. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2938. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2939. if s.Price != lastWarehouse.RetailPrice {
  2940. s.Price = lastWarehouse.RetailPrice
  2941. }
  2942. if s.Price == 0 {
  2943. if lastWarehouse.ID == 0 {
  2944. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2945. s.Price = lastWarehouseTwo.RetailPrice
  2946. }
  2947. }
  2948. }
  2949. //查询保存处方出库开关是否打开
  2950. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2951. if s.PatientId != 30038 {
  2952. if drugOutConfig.IsOpen == 1 {
  2953. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2954. // 查询该药品最后一次出库记录
  2955. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2956. var is_user_total int64
  2957. var no_user_total int64
  2958. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2959. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2960. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2961. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2962. }
  2963. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2964. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2965. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2966. no_user_total += prescribingNumberSevenTy
  2967. }
  2968. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2969. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2970. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2971. no_user_total += prescribingNumberSevenTy
  2972. }
  2973. if len(druginfo) > 0 {
  2974. for _, it := range druginfo {
  2975. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2976. it.Count = it.Count * drug.MinNumber
  2977. is_user_total += it.Count
  2978. }
  2979. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2980. is_user_total += it.Count
  2981. }
  2982. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2983. is_user_total += it.Count
  2984. }
  2985. }
  2986. }
  2987. //fmt.Println("药品名称----------------------", drug.DrugName)
  2988. //fmt.Println("药品名称----------------------", drug.IsUse)
  2989. //fmt.Println("is_user_total-------------------------", is_user_total)
  2990. //fmt.Println("no_user_total-------------------------", no_user_total)
  2991. if is_user_total != no_user_total {
  2992. //出库
  2993. if drug.IsUse == 2 {
  2994. creater := adminInfo.AdminUser.Id
  2995. newadviceInfo := &models.HisDoctorAdviceInfo{
  2996. ID: s.ID,
  2997. UserOrgId: s.UserOrgId,
  2998. PatientId: s.PatientId,
  2999. HisPatientId: s.HisPatientId,
  3000. AdviceType: s.AdviceType,
  3001. AdviceDate: s.AdviceDate,
  3002. StartTime: s.StartTime,
  3003. AdviceName: s.AdviceName,
  3004. AdviceDesc: s.AdviceDesc,
  3005. ReminderDate: s.ReminderDate,
  3006. SingleDose: s.SingleDose,
  3007. SingleDoseUnit: s.SingleDoseUnit,
  3008. PrescribingNumber: s.PrescribingNumber,
  3009. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3010. DeliveryWay: s.DeliveryWay,
  3011. ExecutionFrequency: s.ExecutionFrequency,
  3012. AdviceDoctor: s.AdviceDoctor,
  3013. Status: s.Status,
  3014. CreatedTime: s.CreatedTime,
  3015. UpdatedTime: s.UpdatedTime,
  3016. AdviceAffirm: s.AdviceAffirm,
  3017. Remark: s.Remark,
  3018. StopTime: s.StopTime,
  3019. StopReason: s.StopReason,
  3020. StopDoctor: s.StopDoctor,
  3021. StopState: s.StopState,
  3022. ParentId: s.ParentId,
  3023. ExecutionTime: s.ExecutionTime,
  3024. ExecutionStaff: s.ExecutionStaff,
  3025. ExecutionState: s.ExecutionState,
  3026. Checker: s.Checker,
  3027. RecordDate: s.RecordDate,
  3028. DialysisOrderId: s.DialysisOrderId,
  3029. CheckTime: s.CheckTime,
  3030. CheckState: s.CheckState,
  3031. DrugSpec: s.DrugSpec,
  3032. DrugSpecUnit: s.DrugSpecUnit,
  3033. Groupno: s.Groupno,
  3034. RemindType: s.RemindType,
  3035. FrequencyType: s.FrequencyType,
  3036. DayCount: s.DayCount,
  3037. WeekDay: s.WeekDay,
  3038. TemplateId: s.TemplateId,
  3039. Modifier: s.Modifier,
  3040. DrugId: s.DrugId,
  3041. Price: s.Price,
  3042. PrescriptionId: s.PrescriptionId,
  3043. MedListCodg: s.MedListCodg,
  3044. FeedetlSn: s.FeedetlSn,
  3045. Day: s.DayCount,
  3046. ChildDoctorAdvice: nil,
  3047. Drug: models.Drug{},
  3048. Diagnosis: s.Diagnosis,
  3049. Way: s.Way,
  3050. HospApprFlag: s.HospApprFlag,
  3051. LmtUsedFlag: s.LmtUsedFlag,
  3052. HisOrderInfo: models.HisOrderInfo{},
  3053. IsMedicine: s.IsMedicine,
  3054. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3055. Child: nil,
  3056. IsSettle: s.IsSettle,
  3057. IsMobile: s.IsMobile,
  3058. IsSelfDrug: s.IsSelfDrug,
  3059. DrugWayCount: s.DrugWayCount,
  3060. }
  3061. var history_count int64
  3062. var local_count int64
  3063. //查找已经开过的医嘱信息
  3064. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3065. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3066. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3067. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3068. local_count += prescribingNumberSevenTy * drug.MinNumber
  3069. }
  3070. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3071. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3072. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3073. local_count += prescribingNumberSevenTy
  3074. }
  3075. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3076. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3077. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3078. local_count += prescribingNumberSevenTy
  3079. }
  3080. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3081. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3082. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3083. history_count += prescribingNumberSevenTy * drug.MinNumber
  3084. }
  3085. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3086. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3087. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3088. history_count += prescribingNumberSevenTy
  3089. }
  3090. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3091. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3092. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3093. history_count += prescribingNumberSevenTy
  3094. }
  3095. //如果当前出库数量大于历史出库数量则需要出库
  3096. if local_count > history_count {
  3097. //按最小单位出库
  3098. var cha_count = local_count - history_count
  3099. newadviceInfo.PrescribingNumber = float64(cha_count)
  3100. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3101. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3102. }
  3103. //如果当前出库数量小于历史出库数量则需要退库
  3104. if local_count < history_count {
  3105. var cha_count = history_count - local_count
  3106. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3108. }
  3109. if local_count == history_count {
  3110. if is_user_total == 0 {
  3111. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3112. }
  3113. }
  3114. }
  3115. //更新字典里面的库存
  3116. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3117. var sum_count int64
  3118. for _, its := range stockInfo {
  3119. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3120. if its.MaxUnit == baseDrug.MaxUnit {
  3121. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3122. }
  3123. sum_count += its.StockMaxNumber + its.StockMinNumber
  3124. }
  3125. //更新基础库存
  3126. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3127. //剩余库存
  3128. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3129. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3130. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3131. //创建医嘱
  3132. service.CreateHisDoctorAdviceOne(&s, tx)
  3133. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3135. if len(outInfoTwo) > 0 {
  3136. for _, item := range outInfoTwo {
  3137. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3138. }
  3139. }
  3140. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3141. if len(drugAutoDetail) > 0 {
  3142. for _, item := range drugAutoDetail {
  3143. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3144. }
  3145. }
  3146. }
  3147. }
  3148. }
  3149. //记录日志
  3150. byterequest, _ := json.Marshal(s)
  3151. adviceLog := models.XtDoctorAdviceLog{
  3152. UserOrgId: s.UserOrgId,
  3153. PatientId: s.PatientId,
  3154. AdminUserId: adminInfo.AdminUser.Id,
  3155. Module: 1,
  3156. ErrLog: string(byterequest),
  3157. Status: 1,
  3158. Ctime: time.Now().Unix(),
  3159. Mtime: 0,
  3160. Source: "电脑端新建his医嘱",
  3161. RecordDate: s.AdviceDate,
  3162. }
  3163. service.CreateDoctorAdviceLog(adviceLog)
  3164. //存储切片中
  3165. adviceList = append(adviceList, s)
  3166. redis := service.RedisClient()
  3167. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3168. redis.Set(key, "", time.Second)
  3169. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3170. redis.Set(keyOne, "", time.Second)
  3171. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3172. redis.Set(keySeven, "", time.Second)
  3173. var randNum int
  3174. randNum = rand.Intn(10000) + 1000
  3175. timestamp := time.Now().Unix()
  3176. tempTime := time.Unix(timestamp, 0)
  3177. timeFormat := tempTime.Format("20060102150405")
  3178. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3179. if s.UserOrgId != 10206 {
  3180. if s.ID == 0 {
  3181. //查询改药品是否已经停用
  3182. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3183. if base.ID > 0 {
  3184. tx.Rollback()
  3185. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3186. return
  3187. }
  3188. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3189. if drugMedical.SumCount == 0 {
  3190. tx.Rollback()
  3191. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3192. return
  3193. }
  3194. }
  3195. }
  3196. //赤峰
  3197. if adminInfo.CurrentOrgId == 10265 {
  3198. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3199. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3200. if info.RetailPrice > 0 {
  3201. if s.DeliveryWay == "口服" {
  3202. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3203. s.Price = drug.RetailPrice
  3204. }
  3205. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3206. s.Price = info.RetailPrice
  3207. }
  3208. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3209. s.Price = info.RetailPrice
  3210. }
  3211. }
  3212. }
  3213. }
  3214. service.CreateHisDoctorAdviceOne(&s, tx)
  3215. tx.Commit()
  3216. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3217. redis.Set(keySix, "", time.Second)
  3218. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3219. redis.Set(keyFive, "", time.Second)
  3220. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3221. redis.Set(keyEight, "", time.Second)
  3222. defer redis.Close()
  3223. }
  3224. }
  3225. }
  3226. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3227. projects := items["project"].([]interface{})
  3228. if len(projects) > 0 {
  3229. for _, project := range projects {
  3230. tx := db.Begin()
  3231. // 在函数结束时处理事务回滚
  3232. defer func() {
  3233. if r := recover(); r != nil {
  3234. tx.Rollback()
  3235. }
  3236. }()
  3237. var p models.HisPrescriptionProject
  3238. p.PrescriptionId = tempPrescription.ID
  3239. p.PatientId = patient_id
  3240. p.RecordDate = theTime3.Unix()
  3241. p.Doctor = doctor_id
  3242. p.UserOrgId = adminInfo.CurrentOrgId
  3243. p.HisPatientId = his_patient_id
  3244. p.Status = 1
  3245. p.StartTime = pTime
  3246. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3247. if errcode > 0 {
  3248. c.ServeFailJSONWithSGJErrorCode(errcode)
  3249. return
  3250. }
  3251. if p.ID == 0 {
  3252. p.IsOut = 2
  3253. }
  3254. if p.ID > 0 {
  3255. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3256. p.IsOut = projectDetail.IsOut
  3257. }
  3258. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3259. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3260. if p.Type == 3 {
  3261. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3262. if p.Price != lastWarehouse.PackingPrice {
  3263. p.Price = lastWarehouse.PackingPrice
  3264. }
  3265. if p.Price == 0 {
  3266. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3267. p.Price = lastWarehouseTwo.PackingPrice
  3268. }
  3269. if p.Unit == "" {
  3270. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3271. p.Unit = goodInfoOne.PackingUnit
  3272. }
  3273. }
  3274. }
  3275. if adminInfo.CurrentOrgId != 10206 {
  3276. if p.Type == 3 {
  3277. if p.ID == 0 {
  3278. //查询该耗材是否停用
  3279. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3280. //表示该耗材已经停用,不能保存
  3281. if goodInfoSeven.ID == 0 {
  3282. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3283. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3284. return
  3285. }
  3286. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3287. if goodInfoOne.SumCount == 0 {
  3288. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3289. return
  3290. }
  3291. }
  3292. }
  3293. }
  3294. //查询保存耗材出库开关是否打开
  3295. if p.PatientId != 30038 {
  3296. if goodOutConfig.IsOpen == 1 {
  3297. //耗材出库
  3298. if p.Type == 3 {
  3299. //对比当前数据和历史出库数据
  3300. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3301. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3302. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3303. //如果当前处方数量大于历史数据,则需要出库
  3304. if nowCount > historyCount {
  3305. var cha_count int64
  3306. cha_count = nowCount - historyCount
  3307. timeStr := time.Now().Format("2006-01-02")
  3308. timeArr := strings.Split(timeStr, "-")
  3309. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3310. total = total + 1
  3311. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3312. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3313. number = number + total
  3314. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3315. operation_time := time.Now().Unix()
  3316. creater := c.GetAdminUserInfo().AdminUser.Id
  3317. recordDateStr := time.Now().Format("2006-01-02")
  3318. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3319. nowtime := recordDate.Unix()
  3320. warehouseOut := models.WarehouseOut{
  3321. WarehouseOutOrderNumber: warehousing_out_order,
  3322. OperationTime: operation_time,
  3323. OrgId: adminInfo.CurrentOrgId,
  3324. Creater: creater,
  3325. Ctime: time.Now().Unix(),
  3326. Status: 1,
  3327. WarehouseOutTime: nowtime,
  3328. Type: 1,
  3329. StorehouseId: storeConfig.StorehouseOutInfo,
  3330. IsCheck: 1,
  3331. IsSys: 1,
  3332. }
  3333. //查询是否生成出库单
  3334. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3335. if out.ID == 0 {
  3336. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3337. }
  3338. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3339. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3340. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3341. dialyPrepareOne := models.DialysisBeforePrepare{
  3342. GoodTypeId: goodObj.GoodTypeId,
  3343. GoodId: p.ProjectId,
  3344. PatientId: p.PatientId,
  3345. RecordDate: p.RecordDate,
  3346. UserOrgId: adminInfo.CurrentOrgId,
  3347. Count: cha_count,
  3348. Ctime: time.Now().Unix(),
  3349. Creater: creater,
  3350. Status: 1,
  3351. StorehouseId: houseConfig.StorehouseOutInfo,
  3352. ProjectId: p.ID,
  3353. }
  3354. //出库
  3355. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3356. }
  3357. //如果当前处方数量小于历史数据,怎需要退库
  3358. if nowCount < historyCount {
  3359. var cha_count int64
  3360. cha_count = historyCount - nowCount
  3361. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3362. creater := c.GetAdminUserInfo().AdminUser.Id
  3363. newPrescriptionProject := &models.HisPrescriptionProject{
  3364. ID: p.ID,
  3365. ProjectId: p.ProjectId,
  3366. Price: p.Price,
  3367. UserOrgId: p.UserOrgId,
  3368. Status: 1,
  3369. Ctime: time.Now().Unix(),
  3370. Mtime: time.Now().Unix(),
  3371. PatientId: p.PatientId,
  3372. HisPatientId: p.HisPatientId,
  3373. RecordDate: p.RecordDate,
  3374. PrescriptionId: p.PrescriptionId,
  3375. Count: p.Count,
  3376. FeedetlSn: p.FeedetlSn,
  3377. MedListCodg: p.MedListCodg,
  3378. SingleDose: p.SingleDose,
  3379. DeliveryWay: p.DeliveryWay,
  3380. ExecutionFrequency: p.ExecutionFrequency,
  3381. Day: p.Day,
  3382. HisProject: models.HisProject{},
  3383. GoodInfo: models.GoodInfo{},
  3384. Remark: p.Remark,
  3385. Unit: p.Unit,
  3386. Type: p.Type,
  3387. Doctor: p.Doctor,
  3388. ExecutionTime: p.ExecutionTime,
  3389. ExecutionStaff: p.ExecutionStaff,
  3390. ExecutionState: p.ExecutionState,
  3391. CheckTime: p.CheckTime,
  3392. CheckState: p.CheckState,
  3393. Checker: p.Checker,
  3394. StartTime: p.StartTime,
  3395. TeamId: p.TeamId,
  3396. XtHisProjectTeam: models.XtHisProjectTeam{},
  3397. FrequencyType: p.FrequencyType,
  3398. DayCount: p.DayCount,
  3399. WeekDay: p.WeekDay,
  3400. IsCheckTeam: p.IsCheckTeam,
  3401. HisOrderInfo: models.HisOrderInfo{},
  3402. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3403. IsOut: p.IsOut,
  3404. YbSyncStatus: p.YbSyncStatus,
  3405. }
  3406. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3407. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3408. }
  3409. if nowCount == historyCount {
  3410. if historyCount == 0 {
  3411. recordDateStr := time.Now().Format("2006-01-02")
  3412. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3413. nowtime := recordDate.Unix()
  3414. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3415. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3416. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3417. creater := c.GetAdminUserInfo().AdminUser.Id
  3418. dialyPrepareOne := models.DialysisBeforePrepare{
  3419. GoodTypeId: goodObj.GoodTypeId,
  3420. GoodId: p.ProjectId,
  3421. PatientId: p.PatientId,
  3422. RecordDate: p.RecordDate,
  3423. UserOrgId: adminInfo.CurrentOrgId,
  3424. Count: nowCount,
  3425. Ctime: time.Now().Unix(),
  3426. Creater: creater,
  3427. Status: 1,
  3428. StorehouseId: houseConfig.StorehouseOutInfo,
  3429. ProjectId: p.ID,
  3430. }
  3431. //出库
  3432. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3433. }
  3434. }
  3435. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3436. ////查询历史出库数据
  3437. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3438. //
  3439. //var out_count_five int64
  3440. //for _, item := range flowGood {
  3441. // out_count_five += item.Count
  3442. //}
  3443. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3444. //
  3445. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3446. //if out_count_five != parseIntCount {
  3447. // //查询耗材最后一次出库记录
  3448. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3449. // //查询默认出库仓库库存
  3450. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3451. // if len(wareOut) > 0 {
  3452. //
  3453. // for _, it := range wareOut {
  3454. // //回退库存
  3455. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3456. //
  3457. // //删除出库记录
  3458. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3459. //
  3460. // }
  3461. // }
  3462. //
  3463. // timeStr := time.Now().Format("2006-01-02")
  3464. // timeArr := strings.Split(timeStr, "-")
  3465. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3466. //
  3467. // total = total + 1
  3468. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3469. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3470. // number = number + total
  3471. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3472. //
  3473. // operation_time := time.Now().Unix()
  3474. // creater := c.GetAdminUserInfo().AdminUser.Id
  3475. //
  3476. // recordDateStr := time.Now().Format("2006-01-02")
  3477. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3478. // nowtime := recordDate.Unix()
  3479. // warehouseOut := models.WarehouseOut{
  3480. // WarehouseOutOrderNumber: warehousing_out_order,
  3481. // OperationTime: operation_time,
  3482. // OrgId: adminInfo.CurrentOrgId,
  3483. // Creater: creater,
  3484. // Ctime: time.Now().Unix(),
  3485. // Status: 1,
  3486. // WarehouseOutTime: nowtime,
  3487. // Type: 1,
  3488. // StorehouseId: storeConfig.StorehouseOutInfo,
  3489. // IsCheck: 1,
  3490. // IsSys: 1,
  3491. // }
  3492. // //查询是否生成出库单
  3493. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3494. // if out.ID == 0 {
  3495. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3496. // }
  3497. //
  3498. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3499. //
  3500. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3501. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3502. //
  3503. // dialyPrepareOne := models.DialysisBeforePrepare{
  3504. // GoodTypeId: goodObj.GoodTypeId,
  3505. // GoodId: p.ProjectId,
  3506. // PatientId: p.PatientId,
  3507. // RecordDate: p.RecordDate,
  3508. // UserOrgId: adminInfo.CurrentOrgId,
  3509. // Count: parseIntCount,
  3510. // Ctime: time.Now().Unix(),
  3511. // Creater: creater,
  3512. // Status: 1,
  3513. // StorehouseId: houseConfig.StorehouseOutInfo,
  3514. // ProjectId: lastHisProject.ID,
  3515. // }
  3516. // //判断是否是零用耗材(非零用)
  3517. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3518. //
  3519. // //查询历史出库数据
  3520. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3521. // var out_count int64
  3522. // for _, item := range flowGood {
  3523. // out_count += item.Count
  3524. // }
  3525. // //如果历史数和当前数据不想等才进行退库出库
  3526. // if out_count != parseIntCount {
  3527. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3528. //
  3529. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3530. // detail := models.AutomaticReduceDetail{
  3531. // WarehouseOutId: 0,
  3532. // WarehouseOutOrderNumber: "",
  3533. // PatientId: p.PatientId,
  3534. // Ctime: time.Now().Unix(),
  3535. // Mtime: 0,
  3536. // Status: 1,
  3537. // RecordTime: p.RecordDate,
  3538. // OrgId: p.UserOrgId,
  3539. // GoodId: p.ProjectId,
  3540. // GoodTypeId: 0,
  3541. // Count: parseIntCount,
  3542. // Type: 0,
  3543. // ProjectId: lastHisProject.ID,
  3544. // StorehouseId: 0,
  3545. // }
  3546. //
  3547. // service.CreateNewAutoDetail(detail, tx)
  3548. //
  3549. // //查询剩余库存
  3550. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3551. // var sum_count int64
  3552. // for _, item := range goodList {
  3553. // sum_count += item.StockCount
  3554. // }
  3555. //
  3556. // //更新剩余库存
  3557. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3558. //
  3559. // //耗材
  3560. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3561. //
  3562. // }
  3563. // //判断是否是零用耗材(零用但是是出库耗材)
  3564. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3565. //
  3566. // //查询历史出库数据
  3567. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3568. // var out_count int64
  3569. // for _, item := range flowGood {
  3570. // out_count += item.Count
  3571. // }
  3572. // //如果历史数和当前数据不想等才进行退库出库
  3573. // if out_count != parseIntCount {
  3574. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3575. //
  3576. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3577. // detail := models.AutomaticReduceDetail{
  3578. // WarehouseOutId: 0,
  3579. // WarehouseOutOrderNumber: "",
  3580. // PatientId: p.PatientId,
  3581. // Ctime: time.Now().Unix(),
  3582. // Mtime: 0,
  3583. // Status: 1,
  3584. // RecordTime: p.RecordDate,
  3585. // OrgId: p.UserOrgId,
  3586. // GoodId: p.ProjectId,
  3587. // GoodTypeId: 0,
  3588. // Count: parseIntCount,
  3589. // Type: 0,
  3590. // ProjectId: p.ID,
  3591. // StorehouseId: 0,
  3592. // }
  3593. //
  3594. // service.CreateNewAutoDetail(detail, tx)
  3595. //
  3596. // //查询剩余库存
  3597. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3598. // var sum_count int64
  3599. // for _, item := range goodList {
  3600. // sum_count += item.StockCount
  3601. // }
  3602. //
  3603. // //更新剩余库存
  3604. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3605. //
  3606. // //耗材
  3607. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3608. // }
  3609. //
  3610. // }
  3611. //
  3612. // }
  3613. //
  3614. //}
  3615. //记录日志
  3616. byterequest, _ := json.Marshal(p)
  3617. adviceLog := models.XtDoctorAdviceLog{
  3618. UserOrgId: p.UserOrgId,
  3619. PatientId: p.PatientId,
  3620. AdminUserId: adminInfo.AdminUser.Id,
  3621. Module: 1,
  3622. ErrLog: string(byterequest),
  3623. Status: 1,
  3624. Ctime: time.Now().Unix(),
  3625. Mtime: 0,
  3626. Source: "电脑端新建his项目",
  3627. RecordDate: p.RecordDate,
  3628. }
  3629. service.CreateDoctorAdviceLog(adviceLog)
  3630. projectList = append(projectList, p)
  3631. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3632. //新增或者编辑项目,修改对应的标签数据
  3633. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3634. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3635. var label models.HisLabelPrintInfo
  3636. project, _ := service.GetProjectDetail(p.ProjectId)
  3637. if project.CostClassify == 3 { //类别为检验检查
  3638. if p.TeamId > 0 { //检验检查组套
  3639. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3640. if tempLabel.ID == 0 {
  3641. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3642. label.Number = tempPrescription.PrescriptionNumber
  3643. label.ProjectId = project.ID
  3644. label.Status = 1
  3645. label.IsPrint = 2
  3646. label.DoctorId = info.DoctorId
  3647. label.UserOrgId = p.UserOrgId
  3648. label.PatientId = patient_id
  3649. label.RecordDate = recordDateTime
  3650. label.Ctime = time.Now().Unix()
  3651. label.Mtime = time.Now().Unix()
  3652. label.ItemId = p.TeamId
  3653. label.FeedetlSn = p.FeedetlSn
  3654. label.PProjectId = p.ID
  3655. label.ProjectName = team.ProjectTeam
  3656. label.PatientName = patient.Name
  3657. service.CreateNewHisLabelRecord(&label, tx)
  3658. }
  3659. } else { //单条检验检查项目
  3660. label.Number = tempPrescription.PrescriptionNumber
  3661. label.ProjectId = project.ID
  3662. label.Status = 1
  3663. label.DoctorId = info.DoctorId
  3664. label.UserOrgId = p.UserOrgId
  3665. label.PatientId = patient_id
  3666. label.RecordDate = recordDateTime
  3667. label.IsPrint = 2
  3668. label.Ctime = time.Now().Unix()
  3669. label.Mtime = time.Now().Unix()
  3670. label.FeedetlSn = p.FeedetlSn
  3671. label.PProjectId = p.ID
  3672. label.ItemId = p.TeamId
  3673. label.ProjectName = project.ProjectName
  3674. label.PatientName = patient.Name
  3675. service.CreateNewHisLabelRecord(&label, tx)
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. }
  3682. }
  3683. service.CreateNewHisProjectTwo(&p, tx)
  3684. var randNum int
  3685. randNum = rand.Intn(10000) + 1000
  3686. timestamp := time.Now().Unix()
  3687. tempTime := time.Unix(timestamp, 0)
  3688. timeFormat := tempTime.Format("20060102150405")
  3689. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3690. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3691. if goodBase.ID > 0 {
  3692. tx.Rollback()
  3693. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3694. return
  3695. }
  3696. service.CreateNewHisProjectTwo(&p, tx)
  3697. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3698. //查询剩余库存
  3699. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3700. var sum_count int64
  3701. for _, item := range goodList {
  3702. sum_count += item.StockCount
  3703. }
  3704. //更新剩余库存
  3705. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3706. //耗材
  3707. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3708. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3709. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3710. if len(outInfoTwo) > 0 {
  3711. for _, item := range outInfoTwo {
  3712. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3713. }
  3714. }
  3715. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3716. if len(drugAutoDetail) > 0 {
  3717. for _, item := range drugAutoDetail {
  3718. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3719. }
  3720. }
  3721. tx.Commit()
  3722. }
  3723. }
  3724. }
  3725. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3726. // addition := items["addition"].([]interface{})
  3727. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3728. // ctime := time.Now().Unix()
  3729. // mtime := ctime
  3730. // if len(addition) > 0 {
  3731. // for _, item := range addition {
  3732. // var s models.HisAdditionalCharge
  3733. // s.PrescriptionId = tempPrescription.ID
  3734. // s.Status = 1
  3735. // s.UserOrgId = adminInfo.CurrentOrgId
  3736. // s.RecordDate = recordDateTime
  3737. // s.CreatedTime = ctime
  3738. // s.UpdatedTime = mtime
  3739. // s.PatientId = patient_id
  3740. // s.HisPatientId = his_patient_id
  3741. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3742. // if errcode > 0 {
  3743. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3744. // return
  3745. // }
  3746. // service.CreateAdditionalCharge(&s)
  3747. // var randNum int
  3748. // randNum = rand.Intn(10000) + 1000
  3749. // timestamp := time.Now().Unix()
  3750. // tempTime := time.Unix(timestamp, 0)
  3751. // timeFormat := tempTime.Format("20060102150405")
  3752. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3753. // service.CreateAdditionalCharge(&s)
  3754. //
  3755. // }
  3756. // }
  3757. //}
  3758. }
  3759. }
  3760. }
  3761. tx.Commit()
  3762. if err == nil {
  3763. c.ServeSuccessJSON(map[string]interface{}{
  3764. "msg": "保存成功",
  3765. })
  3766. return
  3767. } else {
  3768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3769. return
  3770. }
  3771. } else {
  3772. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3773. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3774. var tempPrescription *models.HisPrescription
  3775. if len(prescriptions) > 0 {
  3776. for _, item := range prescriptions {
  3777. items := item.(map[string]interface{})
  3778. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3779. utils.ErrorLog("id")
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3781. return
  3782. }
  3783. id := int64(items["id"].(float64))
  3784. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3785. tempPrescription = &new_prescription
  3786. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3787. utils.ErrorLog("type")
  3788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3789. return
  3790. }
  3791. types := int64(items["type"].(float64))
  3792. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3793. utils.ErrorLog("med_type")
  3794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3795. return
  3796. }
  3797. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3798. if med_type == "0" {
  3799. med_type = "14"
  3800. }
  3801. //if order_status == 0 {
  3802. // order_status = 1
  3803. //}
  3804. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3805. utils.ErrorLog("pre_time")
  3806. }
  3807. preTime, _ := items["pre_time"].(string)
  3808. timeLayout := "2006-01-02"
  3809. loc, _ := time.LoadLocation("Local")
  3810. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3811. result := strings.Split(preTime, " ")
  3812. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3813. if err != nil {
  3814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3815. return
  3816. }
  3817. pTime := theTime2.Unix()
  3818. ctime := time.Now().Unix()
  3819. if tempPrescription.ID == 0 {
  3820. prescription := &models.HisPrescription{
  3821. ID: 0,
  3822. PatientId: patient_id,
  3823. UserOrgId: adminInfo.CurrentOrgId,
  3824. RecordDate: recordDateTime,
  3825. Ctime: ctime,
  3826. Mtime: ctime,
  3827. Type: types,
  3828. Modifier: adminInfo.AdminUser.Id,
  3829. Creator: adminInfo.AdminUser.Id,
  3830. Status: 1,
  3831. Doctor: role.UserName,
  3832. HisPatientId: his_patient_id,
  3833. OrderStatus: 1,
  3834. BatchNumber: "",
  3835. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3836. PreTime: pTime,
  3837. PType: p_type,
  3838. MedType: med_type,
  3839. }
  3840. tempPrescription = prescription
  3841. service.SaveHisPrescription(tempPrescription)
  3842. redis := service.RedisClient()
  3843. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3844. redis.Set(key, "", time.Second)
  3845. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3846. redis.Set(keyOne, "", time.Second)
  3847. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3848. redis.Set(keySeven, "", time.Second)
  3849. defer redis.Close()
  3850. } else {
  3851. tempPrescription.ID = id
  3852. tempPrescription.Type = types
  3853. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3854. tempPrescription.Mtime = time.Now().Unix()
  3855. tempPrescription.Doctor = role.UserName
  3856. //tempPrescription.OrderStatus = order_status
  3857. tempPrescription.PreTime = pTime
  3858. tempPrescription.MedType = med_type
  3859. service.SaveHisPrescription(tempPrescription)
  3860. redis := service.RedisClient()
  3861. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3862. redis.Set(key, "", time.Second)
  3863. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3864. redis.Set(keyOne, "", time.Second)
  3865. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3866. redis.Set(keySeven, "", time.Second)
  3867. defer redis.Close()
  3868. }
  3869. //service.SaveHisPrescription(prescription)
  3870. //更改患者挂号状态
  3871. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3872. fmt.Println("更改失败", err2)
  3873. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3874. advices := items["advices"].([]interface{})
  3875. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3876. groupNo := int64(0)
  3877. if len(advices) > 0 {
  3878. for _, advice := range advices {
  3879. var s models.HisDoctorAdviceInfo
  3880. s.PrescriptionId = tempPrescription.ID
  3881. s.AdviceType = 2
  3882. s.AdviceDoctor = doctor_id
  3883. s.StopState = 2
  3884. s.ExecutionState = 2
  3885. s.AdviceDate = theTime3.Unix()
  3886. s.Status = 1
  3887. s.UserOrgId = adminInfo.CurrentOrgId
  3888. s.RecordDate = theTime3.Unix()
  3889. s.StartTime = tempPrescription.PreTime
  3890. s.Groupno = groupNo
  3891. s.PatientId = patient_id
  3892. s.HisPatientId = his_patient_id
  3893. s.StartTime = pTime
  3894. s.IsSettle = 2
  3895. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3896. if errcode > 0 {
  3897. c.ServeFailJSONWithSGJErrorCode(errcode)
  3898. return
  3899. }
  3900. s.StartTime = pTime
  3901. var total_count int64 //处方总库存
  3902. //查询改药品信息
  3903. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3904. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3905. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3906. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3907. total_count += prescribingNumberSeven * medical.MinNumber
  3908. }
  3909. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3910. total_count += prescribingNumberSeven
  3911. }
  3912. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3913. total_count += prescribingNumberSeven
  3914. }
  3915. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3916. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3917. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3918. if s.Price != lastWarehouse.RetailPrice {
  3919. s.Price = lastWarehouse.RetailPrice
  3920. }
  3921. if s.Price == 0 {
  3922. if lastWarehouse.ID == 0 {
  3923. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3924. s.Price = lastWarehouseTwo.RetailPrice
  3925. }
  3926. }
  3927. }
  3928. if adminInfo.CurrentOrgId != 10206 {
  3929. if s.ID == 0 {
  3930. //查询改药品是否已经停用
  3931. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3932. if base.ID > 0 {
  3933. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3934. return
  3935. }
  3936. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3937. if drugMedical.SumCount == 0 {
  3938. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3939. return
  3940. }
  3941. }
  3942. }
  3943. //赤峰
  3944. if s.UserOrgId == 10265 {
  3945. drug, _ := service.GetDrugByGoodId(s.DrugId)
  3946. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  3947. if info.RetailPrice > 0 {
  3948. if s.DeliveryWay == "口服" {
  3949. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3950. s.Price = drug.RetailPrice
  3951. }
  3952. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3953. s.Price = info.RetailPrice
  3954. }
  3955. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3956. s.Price = info.RetailPrice
  3957. }
  3958. }
  3959. }
  3960. }
  3961. service.CreateHisDoctorAdvice(&s)
  3962. //记录日志
  3963. byterequest, _ := json.Marshal(s)
  3964. adviceLog := models.XtDoctorAdviceLog{
  3965. UserOrgId: s.UserOrgId,
  3966. PatientId: s.PatientId,
  3967. AdminUserId: adminInfo.AdminUser.Id,
  3968. Module: 1,
  3969. ErrLog: string(byterequest),
  3970. Status: 1,
  3971. Ctime: time.Now().Unix(),
  3972. Mtime: 0,
  3973. Source: "电脑端新建his医嘱",
  3974. RecordDate: s.AdviceDate,
  3975. }
  3976. service.CreateDoctorAdviceLog(adviceLog)
  3977. //存储切片中
  3978. adviceList = append(adviceList, s)
  3979. redis := service.RedisClient()
  3980. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3981. redis.Set(key, "", time.Second)
  3982. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3983. redis.Set(keyOne, "", time.Second)
  3984. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3985. redis.Set(keySeven, "", time.Second)
  3986. var randNum int
  3987. randNum = rand.Intn(10000) + 1000
  3988. timestamp := time.Now().Unix()
  3989. tempTime := time.Unix(timestamp, 0)
  3990. timeFormat := tempTime.Format("20060102150405")
  3991. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3992. service.CreateHisDoctorAdvice(&s)
  3993. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3994. redis.Set(keySix, "", time.Second)
  3995. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3996. redis.Set(keyFive, "", time.Second)
  3997. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3998. redis.Set(keyEight, "", time.Second)
  3999. defer redis.Close()
  4000. }
  4001. }
  4002. }
  4003. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4004. projects := items["project"].([]interface{})
  4005. if len(projects) > 0 {
  4006. for _, project := range projects {
  4007. var p models.HisPrescriptionProject
  4008. p.PrescriptionId = tempPrescription.ID
  4009. p.PatientId = patient_id
  4010. p.RecordDate = theTime3.Unix()
  4011. p.Doctor = doctor_id
  4012. p.UserOrgId = adminInfo.CurrentOrgId
  4013. p.HisPatientId = his_patient_id
  4014. p.Status = 1
  4015. p.StartTime = pTime
  4016. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4017. if errcode > 0 {
  4018. c.ServeFailJSONWithSGJErrorCode(errcode)
  4019. return
  4020. }
  4021. if p.ID == 0 {
  4022. p.IsOut = 2
  4023. }
  4024. if p.ID > 0 {
  4025. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4026. p.IsOut = projectDetail.IsOut
  4027. }
  4028. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4029. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4030. if p.Type == 3 {
  4031. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4032. if p.Price != lastWarehouse.PackingPrice {
  4033. p.Price = lastWarehouse.PackingPrice
  4034. }
  4035. if p.Price == 0 {
  4036. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4037. p.Price = lastWarehouseTwo.PackingPrice
  4038. }
  4039. if p.Unit == "" {
  4040. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4041. p.Unit = goodInfoOne.PackingUnit
  4042. }
  4043. }
  4044. }
  4045. if adminInfo.CurrentOrgId != 10206 {
  4046. if p.Type == 3 {
  4047. if p.ID == 0 {
  4048. //查询该耗材是否停用
  4049. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4050. //表示该耗材已经停用,不能保存
  4051. if goodInfoSeven.ID == 0 {
  4052. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4053. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4054. return
  4055. }
  4056. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4057. if goodInfoOne.SumCount == 0 {
  4058. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4059. return
  4060. }
  4061. }
  4062. }
  4063. }
  4064. service.CreateHisProjectTwo(&p)
  4065. //记录日志
  4066. byterequest, _ := json.Marshal(p)
  4067. adviceLog := models.XtDoctorAdviceLog{
  4068. UserOrgId: p.UserOrgId,
  4069. PatientId: p.PatientId,
  4070. AdminUserId: adminInfo.AdminUser.Id,
  4071. Module: 1,
  4072. ErrLog: string(byterequest),
  4073. Status: 1,
  4074. Ctime: time.Now().Unix(),
  4075. Mtime: 0,
  4076. Source: "电脑端新建his项目",
  4077. RecordDate: p.RecordDate,
  4078. }
  4079. service.CreateDoctorAdviceLog(adviceLog)
  4080. projectList = append(projectList, p)
  4081. var randNum int
  4082. randNum = rand.Intn(10000) + 1000
  4083. timestamp := time.Now().Unix()
  4084. tempTime := time.Unix(timestamp, 0)
  4085. timeFormat := tempTime.Format("20060102150405")
  4086. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4087. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4088. //新增或者编辑项目,修改对应的标签数据
  4089. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4090. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4091. var label models.HisLabelPrintInfo
  4092. project, _ := service.GetProjectDetail(p.ProjectId)
  4093. if project.CostClassify == 3 { //类别为检验检查
  4094. if p.TeamId > 0 { //检验检查组套
  4095. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4096. if tempLabel.ID == 0 {
  4097. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4098. label.Number = tempPrescription.PrescriptionNumber
  4099. label.ProjectId = project.ID
  4100. label.Status = 1
  4101. label.IsPrint = 2
  4102. label.DoctorId = info.DoctorId
  4103. label.UserOrgId = p.UserOrgId
  4104. label.PatientId = patient_id
  4105. label.RecordDate = recordDateTime
  4106. label.Ctime = time.Now().Unix()
  4107. label.Mtime = time.Now().Unix()
  4108. label.ItemId = p.TeamId
  4109. label.FeedetlSn = p.FeedetlSn
  4110. label.PProjectId = p.ID
  4111. label.ProjectName = team.ProjectTeam
  4112. label.PatientName = patient.Name
  4113. service.CreateHisLabelRecord(&label)
  4114. }
  4115. } else { //单条检验检查项目
  4116. label.Number = tempPrescription.PrescriptionNumber
  4117. label.ProjectId = project.ID
  4118. label.Status = 1
  4119. label.DoctorId = info.DoctorId
  4120. label.UserOrgId = p.UserOrgId
  4121. label.PatientId = patient_id
  4122. label.RecordDate = recordDateTime
  4123. label.IsPrint = 2
  4124. label.Ctime = time.Now().Unix()
  4125. label.Mtime = time.Now().Unix()
  4126. label.FeedetlSn = p.FeedetlSn
  4127. label.PProjectId = p.ID
  4128. label.ItemId = p.TeamId
  4129. label.ProjectName = project.ProjectName
  4130. label.PatientName = patient.Name
  4131. service.CreateHisLabelRecord(&label)
  4132. }
  4133. }
  4134. }
  4135. }
  4136. service.SaveHisProjectTwo(&p)
  4137. }
  4138. }
  4139. }
  4140. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4141. // addition := items["addition"].([]interface{})
  4142. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4143. // ctime := time.Now().Unix()
  4144. // mtime := ctime
  4145. // if len(addition) > 0 {
  4146. // for _, item := range addition {
  4147. // var s models.HisAdditionalCharge
  4148. // s.PrescriptionId = tempPrescription.ID
  4149. // s.Status = 1
  4150. // s.UserOrgId = adminInfo.CurrentOrgId
  4151. // s.RecordDate = recordDateTime
  4152. // s.CreatedTime = ctime
  4153. // s.UpdatedTime = mtime
  4154. // s.PatientId = patient_id
  4155. // s.HisPatientId = his_patient_id
  4156. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4157. // if errcode > 0 {
  4158. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4159. // return
  4160. // }
  4161. // service.CreateAdditionalCharge(&s)
  4162. // var randNum int
  4163. // randNum = rand.Intn(10000) + 1000
  4164. // timestamp := time.Now().Unix()
  4165. // tempTime := time.Unix(timestamp, 0)
  4166. // timeFormat := tempTime.Format("20060102150405")
  4167. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4168. // service.CreateAdditionalCharge(&s)
  4169. //
  4170. // }
  4171. // }
  4172. //}
  4173. }
  4174. }
  4175. //查询今日该患者开的药品处方
  4176. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4177. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4178. //药品出库
  4179. if drugOutConfig.IsOpen == 1 {
  4180. for _, item := range hisdoctorlist {
  4181. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4182. // 查询该药品最后一次出库记录
  4183. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4184. if len(druginfo) > 0 {
  4185. //回退库存
  4186. for _, it := range druginfo {
  4187. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4188. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4189. }
  4190. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4191. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4192. }
  4193. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4194. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4195. }
  4196. }
  4197. }
  4198. //删除记录
  4199. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4200. //查询最后一次数据
  4201. if drugOutConfig.IsOpen == 1 {
  4202. //出库
  4203. if drug.IsUse == 2 {
  4204. creater := adminInfo.AdminUser.Id
  4205. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4206. }
  4207. //更新字典里面的库存
  4208. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4209. var sum_count int64
  4210. for _, its := range stockInfo {
  4211. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4212. if its.MaxUnit == baseDrug.MaxUnit {
  4213. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4214. }
  4215. sum_count += its.StockMaxNumber + its.StockMinNumber
  4216. }
  4217. //更新基础库存
  4218. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4219. //剩余库存
  4220. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4221. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4222. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4223. }
  4224. }
  4225. }
  4226. //耗材保存处方出库
  4227. if goodOutConfig.IsOpen == 1 {
  4228. //查询今日耗材出库数量
  4229. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4230. for _, item := range hisgoodlist {
  4231. //查询历史出库数据
  4232. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4233. var out_count_five int64
  4234. for _, item := range flowGood {
  4235. out_count_five += item.Count
  4236. }
  4237. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4238. if out_count_five != parseIntCount {
  4239. //查询耗材最后一次出库记录
  4240. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4241. //查询默认出库仓库库存
  4242. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4243. if len(wareOut) > 0 {
  4244. for _, it := range wareOut {
  4245. //回退库存
  4246. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4247. //删除出库记录
  4248. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4249. }
  4250. }
  4251. timeStr := time.Now().Format("2006-01-02")
  4252. timeArr := strings.Split(timeStr, "-")
  4253. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4254. total = total + 1
  4255. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4256. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4257. number = number + total
  4258. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4259. operation_time := time.Now().Unix()
  4260. creater := c.GetAdminUserInfo().AdminUser.Id
  4261. recordDateStr := time.Now().Format("2006-01-02")
  4262. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4263. nowtime := recordDate.Unix()
  4264. warehouseOut := models.WarehouseOut{
  4265. WarehouseOutOrderNumber: warehousing_out_order,
  4266. OperationTime: operation_time,
  4267. OrgId: adminInfo.CurrentOrgId,
  4268. Creater: creater,
  4269. Ctime: time.Now().Unix(),
  4270. Status: 1,
  4271. WarehouseOutTime: nowtime,
  4272. Type: 1,
  4273. StorehouseId: storeConfig.StorehouseOutInfo,
  4274. IsCheck: 1,
  4275. IsSys: 1,
  4276. }
  4277. //查询是否生成出库单
  4278. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4279. if out.ID == 0 {
  4280. service.AddSigleWarehouseOut(&warehouseOut)
  4281. }
  4282. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4283. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4284. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4285. dialyPrepareOne := models.DialysisBeforePrepare{
  4286. GoodTypeId: goodObj.GoodTypeId,
  4287. GoodId: item.ProjectId,
  4288. PatientId: item.PatientId,
  4289. RecordDate: item.RecordDate,
  4290. UserOrgId: adminInfo.CurrentOrgId,
  4291. Count: parseIntCount,
  4292. Ctime: time.Now().Unix(),
  4293. Creater: creater,
  4294. Status: 1,
  4295. StorehouseId: houseConfig.StorehouseOutInfo,
  4296. ProjectId: item.ID,
  4297. }
  4298. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4299. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4300. //查询历史出库数据
  4301. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4302. var out_count int64
  4303. for _, item := range flowGood {
  4304. out_count += item.Count
  4305. }
  4306. //如果历史数和当前数据不想等才进行退库出库
  4307. if out_count != parseIntCount {
  4308. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4309. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4310. detail := models.AutomaticReduceDetail{
  4311. WarehouseOutId: 0,
  4312. WarehouseOutOrderNumber: "",
  4313. PatientId: item.PatientId,
  4314. Ctime: time.Now().Unix(),
  4315. Mtime: 0,
  4316. Status: 1,
  4317. RecordTime: item.RecordDate,
  4318. OrgId: item.UserOrgId,
  4319. GoodId: item.ProjectId,
  4320. GoodTypeId: 0,
  4321. Count: parseIntCount,
  4322. Type: 0,
  4323. ProjectId: item.ID,
  4324. StorehouseId: 0,
  4325. }
  4326. service.CreateAutoDetail(detail)
  4327. //查询剩余库存
  4328. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4329. var sum_count int64
  4330. for _, item := range goodList {
  4331. sum_count += item.StockCount
  4332. }
  4333. //更新剩余库存
  4334. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4335. //耗材
  4336. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4337. }
  4338. }
  4339. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4340. //查询历史出库数据
  4341. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4342. var out_count int64
  4343. for _, item := range flowGood {
  4344. out_count += item.Count
  4345. }
  4346. //如果历史数和当前数据不想等才进行退库出库
  4347. if out_count != parseIntCount {
  4348. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4349. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4350. detail := models.AutomaticReduceDetail{
  4351. WarehouseOutId: 0,
  4352. WarehouseOutOrderNumber: "",
  4353. PatientId: item.PatientId,
  4354. Ctime: time.Now().Unix(),
  4355. Mtime: 0,
  4356. Status: 1,
  4357. RecordTime: item.RecordDate,
  4358. OrgId: item.UserOrgId,
  4359. GoodId: item.ProjectId,
  4360. GoodTypeId: 0,
  4361. Count: parseIntCount,
  4362. Type: 0,
  4363. ProjectId: item.ID,
  4364. StorehouseId: 0,
  4365. }
  4366. service.CreateAutoDetail(detail)
  4367. //查询剩余库存
  4368. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4369. var sum_count int64
  4370. for _, item := range goodList {
  4371. sum_count += item.StockCount
  4372. }
  4373. //更新剩余库存
  4374. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4375. //耗材
  4376. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4377. }
  4378. }
  4379. }
  4380. }
  4381. }
  4382. ////同步到自备药
  4383. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4384. if selfPrescriptionOpen.IsOpen == 1 {
  4385. timeStr := time.Now().Format("2006-01-02")
  4386. timeArr := strings.Split(timeStr, "-")
  4387. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4388. total = total + 1
  4389. operation_time := time.Now().Unix()
  4390. creater := adminInfo.AdminUser.Id
  4391. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4392. warehousing := models.XtSelfDrugWarehouse{
  4393. WarehousingOrder: warehousing_order,
  4394. OperationTime: operation_time,
  4395. OrgId: adminInfo.CurrentOrgId,
  4396. Creater: creater,
  4397. Ctime: time.Now().Unix(),
  4398. Status: 1,
  4399. WarehousingTime: recordDateTime,
  4400. Type: 0,
  4401. StorehouseId: 0,
  4402. IsCheck: 1,
  4403. PatientId: patient_id,
  4404. IsSys: 1,
  4405. }
  4406. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4407. if selfDrugWarehouse.ID == 0 {
  4408. service.AddSelfDrugWarehouse(&warehousing, tx)
  4409. }
  4410. if selfDrugWarehouse.ID > 0 {
  4411. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4412. }
  4413. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4414. fmt.Println(info)
  4415. for _, item := range hisdoctorlist {
  4416. //查询该病人的该药品是否已经入库
  4417. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4418. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4419. var in_count int64
  4420. if len(selfdruginfo) > 0 {
  4421. for _, item := range selfdruginfo {
  4422. var in_count_one int64
  4423. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4424. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4425. }
  4426. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4427. in_count_one = item.WarehousingCount
  4428. }
  4429. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4430. in_count_one = item.WarehousingCount
  4431. }
  4432. in_count += in_count_one
  4433. }
  4434. }
  4435. if selfBasedrug.IsSelfDrug == 1 {
  4436. var total_count int64
  4437. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4438. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4439. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4440. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4441. }
  4442. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4443. total_count += prescribingNumberSeven
  4444. }
  4445. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4446. total_count += prescribingNumberSeven
  4447. }
  4448. //入库
  4449. if total_count > in_count {
  4450. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4451. WarehousingOrder: warehousing_order,
  4452. WarehousingId: info.ID,
  4453. DrugId: item.DrugId,
  4454. Number: "",
  4455. ProductDate: 0,
  4456. ExpiryDate: 0,
  4457. WarehousingCount: total_count - in_count,
  4458. WarehouseingUnit: selfBasedrug.MinUnit,
  4459. Price: 0,
  4460. TotalPrice: 0,
  4461. Status: 1,
  4462. Ctime: time.Now().Unix(),
  4463. Remark: "",
  4464. OrgId: adminInfo.CurrentOrgId,
  4465. Type: 0,
  4466. Manufacturer: selfBasedrug.Manufacturer,
  4467. Dealer: selfBasedrug.Dealer,
  4468. StockMaxNumber: total_count - in_count,
  4469. RetailTotalPrice: 0,
  4470. BatchNumber: "",
  4471. MaxUnit: selfBasedrug.MinUnit,
  4472. MinUnit: selfBasedrug.MinUnit,
  4473. RetailPrice: 0,
  4474. StorehouseId: 0,
  4475. IsCheck: 1,
  4476. StockMinNumber: 0,
  4477. PatientId: patient_id,
  4478. IsSys: 1,
  4479. RecordDate: item.RecordDate,
  4480. AdviceId: item.ID,
  4481. }
  4482. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4483. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4484. Creator := adminInfo.AdminUser.Id
  4485. //查询默认仓库剩余多少库存
  4486. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4487. var sum_count int64
  4488. for _, it := range list {
  4489. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4490. if it.MaxUnit == baseDrug.MaxUnit {
  4491. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4492. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4493. }
  4494. sum_count += it.StockMaxNumber + it.StockMinNumber
  4495. }
  4496. flow := &models.XtSelfDrugFlow{
  4497. WarehousingId: info.ID,
  4498. DrugId: item.DrugId,
  4499. Number: "",
  4500. BatchNumber: "",
  4501. Count: total_count - in_count,
  4502. UserOrgId: adminInfo.CurrentOrgId,
  4503. PatientId: item.PatientId,
  4504. SystemTime: time.Now().Unix(),
  4505. ConsumableType: 1,
  4506. IsSys: 1,
  4507. WarehousingOrder: warehousing_order,
  4508. WarehouseOutId: 0,
  4509. WarehouseOutOrderNumber: "",
  4510. IsEdit: 0,
  4511. CancelStockId: 0,
  4512. CancelOrderNumber: "",
  4513. Manufacturer: selfBasedrug.Manufacturer,
  4514. Dealer: selfBasedrug.Dealer,
  4515. Creator: Creator,
  4516. UpdateCreator: Creator,
  4517. Status: 1,
  4518. Ctime: item.AdviceDate,
  4519. Mtime: 0,
  4520. Price: item.Price,
  4521. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4522. WarehouseOutDetailId: 0,
  4523. CancelOutDetailId: 0,
  4524. ExpireDate: 0,
  4525. ProductDate: 0,
  4526. MaxUnit: selfBasedrug.MinUnit,
  4527. MinUnit: selfBasedrug.MinUnit,
  4528. StorehouseId: 0,
  4529. OverCount: sum_count,
  4530. OperateTime: time.Now().Unix(),
  4531. AdviceId: item.ID,
  4532. }
  4533. service.CreateSelfDrugFlow(flow, tx)
  4534. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4535. var total_count int64 // 入库总数量
  4536. var over_count int64 //剩余库存
  4537. for _, it := range drugInfolist {
  4538. if it.MaxUnit == selfBasedrug.MaxUnit {
  4539. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4540. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4541. }
  4542. }
  4543. for _, it := range drugInfolist {
  4544. total_count += it.WarehousingCount
  4545. over_count += it.StockMaxNumber + it.StockMinNumber
  4546. }
  4547. //查询该仓库是否有默认数据
  4548. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4549. if selfDrugStock.ID == 0 {
  4550. drugStock := models.XtSelfDrugStockCount{
  4551. UserOrgId: item.UserOrgId,
  4552. PatientId: item.PatientId,
  4553. SumInCount: total_count,
  4554. SumOutCount: 0,
  4555. SumCancelCount: 0,
  4556. DrugId: item.DrugId,
  4557. Ctime: time.Now().Unix(),
  4558. Mtime: 0,
  4559. Status: 1,
  4560. FlushCount: over_count,
  4561. SumActOutCount: 0,
  4562. }
  4563. service.CreateSelfDrugStockSum(drugStock, tx)
  4564. }
  4565. if selfDrugStock.ID > 0 {
  4566. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4567. }
  4568. }
  4569. //查询这个单据的出库数量
  4570. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4571. var his_out_count int64
  4572. for _, item := range drugFlowList {
  4573. his_out_count += item.Count
  4574. }
  4575. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4576. if (total_count + his_out_count) <= in_count {
  4577. // 出库
  4578. if total_count < in_count {
  4579. var cha_count int64
  4580. cha_count = in_count - total_count
  4581. var stock_number int64 = 0
  4582. //查询库存是否充足
  4583. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4584. // 将该批次的剩余库存数量转换为拆零数量
  4585. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4586. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4587. }
  4588. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4589. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4590. }
  4591. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4592. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4593. }
  4594. if stock_number >= cha_count {
  4595. var maxNumber int64 = 0
  4596. var minNumber int64 = 0
  4597. maxNumber = cha_count / selfBasedrug.MinNumber
  4598. minNumber = cha_count % selfBasedrug.MinNumber
  4599. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4600. minNumber = maxNumber
  4601. }
  4602. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4603. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4605. return
  4606. }
  4607. }
  4608. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4609. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4610. }
  4611. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4612. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4613. }
  4614. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4615. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4616. }
  4617. if warehouse.StockMaxNumber < 0 {
  4618. warehouse.StockMaxNumber = 0
  4619. }
  4620. if warehouse.StockMinNumber < 0 {
  4621. warehouse.StockMinNumber = 0
  4622. }
  4623. warehouse.Mtime = time.Now().Unix()
  4624. if warehouse.StockMinNumber < minNumber {
  4625. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4626. if warehouse.MaxUnit != warehouse.MinUnit {
  4627. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4628. }
  4629. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4630. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4631. }
  4632. } else {
  4633. if minNumber > 0 {
  4634. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4635. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4636. }
  4637. }
  4638. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4639. if warehouse.StockMinNumber > 0 {
  4640. if warehouse.StockMinNumber-cha_count >= 0 {
  4641. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4642. }
  4643. }
  4644. }
  4645. }
  4646. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4647. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4648. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4649. }
  4650. }
  4651. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4652. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4654. return
  4655. }
  4656. }
  4657. if warehouse.StockMinNumber <= 0 {
  4658. warehouse.StockMinNumber = 0
  4659. }
  4660. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4661. //查询该药品剩余库存
  4662. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4663. var over_count int64
  4664. for _, its := range infolist {
  4665. if its.MaxUnit == selfBasedrug.MaxUnit {
  4666. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4667. }
  4668. over_count += its.StockMaxNumber + its.StockMinNumber
  4669. }
  4670. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4671. drugflow := models.XtSelfDrugFlow{
  4672. WarehouseOutId: 0,
  4673. WarehouseOutOrderNumber: warehousing_order,
  4674. WarehousingOrder: warehousing_order,
  4675. DrugId: item.DrugId,
  4676. Number: warehouse.Number,
  4677. ProductDate: warehouse.ProductDate,
  4678. ExpireDate: warehouse.ExpiryDate,
  4679. Count: cha_count,
  4680. Price: warehouse.RetailPrice,
  4681. Status: 1,
  4682. Ctime: item.AdviceDate,
  4683. Mtime: time.Now().Unix(),
  4684. UserOrgId: item.UserOrgId,
  4685. Manufacturer: warehouse.Manufacturer,
  4686. Dealer: warehouse.Dealer,
  4687. BatchNumber: warehouse.BatchNumber,
  4688. MaxUnit: selfBasedrug.MinUnit,
  4689. ConsumableType: 20,
  4690. IsEdit: 1,
  4691. Creator: 0,
  4692. IsSys: 3,
  4693. WarehouseOutDetailId: drugWareInfo.ID,
  4694. AdviceId: item.ID,
  4695. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4696. StorehouseId: 0,
  4697. AdminUserId: creater,
  4698. LastPrice: warehouse.Price,
  4699. StockCount: "",
  4700. WarehousingDetailId: 0,
  4701. OverCount: over_count,
  4702. RetailPrice: item.Price, //手动出库出库价格
  4703. WarehousingId: warehouse.ID,
  4704. SystemTime: item.AdviceDate,
  4705. PatientId: item.PatientId,
  4706. Remark: "保存处方入库数据差",
  4707. OperateTime: time.Now().Unix(),
  4708. }
  4709. if warehouse.RetailPrice == 0 {
  4710. drugflow.Price = item.Price
  4711. }
  4712. service.CreateSelfDrugFlowOne(drugflow, tx)
  4713. var out_count int64
  4714. out_count = in_count - total_count
  4715. //
  4716. //fmt.Println("in_count------------------", in_count)
  4717. //fmt.Println("total_count------------------", total_count)
  4718. //添加出库数量
  4719. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4720. //查询剩余库存
  4721. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4722. var sum_count int64
  4723. for _, its := range stockInfo {
  4724. if its.MaxUnit == selfBasedrug.MaxUnit {
  4725. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4726. }
  4727. sum_count += its.StockMaxNumber + its.StockMinNumber
  4728. }
  4729. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4730. } else {
  4731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4732. return
  4733. }
  4734. }
  4735. }
  4736. }
  4737. }
  4738. }
  4739. }
  4740. tx.Commit()
  4741. if err == nil {
  4742. c.ServeSuccessJSON(map[string]interface{}{
  4743. "msg": "保存成功",
  4744. })
  4745. return
  4746. } else {
  4747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4748. return
  4749. }
  4750. }
  4751. }
  4752. //func (c *HisApiController) EditHisPrescription() {
  4753. // record_date := c.GetString("record_date")
  4754. // patient_id, _ := c.GetInt64("patient_id")
  4755. // reg_type, _ := c.GetInt64("reg_type")
  4756. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4757. // diagnose := c.GetString("diagnose")
  4758. // sick_type, _ := c.GetInt64("sick_type")
  4759. // sick_history := c.GetString("sick_history")
  4760. // doctor_id, _ := c.GetInt64("doctor", 0)
  4761. // department, _ := c.GetInt64("department", 0)
  4762. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4763. // p_type, _ := c.GetInt64("p_type")
  4764. //
  4765. // dataBody := make(map[string]interface{}, 0)
  4766. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4767. // if err != nil {
  4768. // utils.ErrorLog(err.Error())
  4769. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4770. // return
  4771. // }
  4772. //
  4773. // timeLayout := "2006-01-02"
  4774. // loc, _ := time.LoadLocation("Local")
  4775. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4776. // if err != nil {
  4777. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4778. // return
  4779. // }
  4780. // adminInfo := c.GetAdminUserInfo()
  4781. // recordDateTime := theTime.Unix()
  4782. //
  4783. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4784. //
  4785. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4786. // var hpInfo models.HisPrescriptionInfo
  4787. // if info.ID == 0 {
  4788. // var randNum int
  4789. // randNum = rand.Intn(10000) + 1000
  4790. // timestamp := time.Now().Unix()
  4791. // tempTime := time.Unix(timestamp, 0)
  4792. // timeFormat := tempTime.Format("20060102150405")
  4793. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4794. //
  4795. // hpInfo = models.HisPrescriptionInfo{
  4796. // UserOrgId: adminInfo.CurrentOrgId,
  4797. // RecordDate: theTime.Unix(),
  4798. // PatientId: patient_id,
  4799. // Status: 1,
  4800. // Ctime: time.Now().Unix(),
  4801. // Mtime: time.Now().Unix(),
  4802. // Creator: adminInfo.AdminUser.Id,
  4803. // Modifier: adminInfo.AdminUser.Id,
  4804. // Diagnosis: diagnose,
  4805. // SickHistory: sick_history,
  4806. // Departments: department,
  4807. // RegisterType: reg_type,
  4808. // PrescriptionNumber: p_number,
  4809. // PrescriptionStatus: 1,
  4810. // Doctor: role.UserName,
  4811. // DoctorId: doctor_id,
  4812. // SickType: sick_type,
  4813. // PType: p_type,
  4814. // }
  4815. // service.SavePatientPrescriptionInfo(hpInfo)
  4816. //
  4817. // } else {
  4818. // hpInfo = models.HisPrescriptionInfo{
  4819. // ID: info.ID,
  4820. // UserOrgId: adminInfo.CurrentOrgId,
  4821. // RecordDate: info.RecordDate,
  4822. // PatientId: info.PatientId,
  4823. // Status: 1,
  4824. // Ctime: info.Ctime,
  4825. // Mtime: time.Now().Unix(),
  4826. // Creator: info.Creator,
  4827. // Modifier: adminInfo.AdminUser.Id,
  4828. // Diagnosis: diagnose,
  4829. // SickHistory: sick_history,
  4830. // Departments: department,
  4831. // RegisterType: reg_type,
  4832. // PrescriptionNumber: info.PrescriptionNumber,
  4833. // Doctor: role.UserName,
  4834. // PrescriptionStatus: info.PrescriptionStatus,
  4835. // DoctorId: doctor_id,
  4836. // SickType: sick_type,
  4837. // PType: info.PType,
  4838. // }
  4839. // service.SavePatientPrescriptionInfo(hpInfo)
  4840. // }
  4841. //
  4842. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4843. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4844. //
  4845. // if len(prescriptions) > 0 {
  4846. // for _, item := range prescriptions {
  4847. // items := item.(map[string]interface{})
  4848. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4849. // utils.ErrorLog("id")
  4850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4851. // return
  4852. // }
  4853. // id := int64(items["id"].(float64))
  4854. //
  4855. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4856. // utils.ErrorLog("type")
  4857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4858. // return
  4859. // }
  4860. // types := int64(items["type"].(float64))
  4861. //
  4862. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4863. // utils.ErrorLog("med_type")
  4864. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4865. // return
  4866. // }
  4867. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4868. //
  4869. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4870. //
  4871. // ctime := time.Now().Unix()
  4872. //
  4873. // prescription := &models.HisPrescription{
  4874. // ID: id,
  4875. // PatientId: patient_id,
  4876. // UserOrgId: adminInfo.CurrentOrgId,
  4877. // RecordDate: recordDateTime,
  4878. // Ctime: ctime,
  4879. // Mtime: ctime,
  4880. // Type: types,
  4881. // Modifier: adminInfo.AdminUser.Id,
  4882. // Creator: adminInfo.AdminUser.Id,
  4883. // Status: 1,
  4884. // Doctor: role.UserName,
  4885. // HisPatientId: his_patient_id,
  4886. // OrderStatus: 1,
  4887. // BatchNumber: "",
  4888. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4889. // PType: hpInfo.PType,
  4890. // MedType: med_type,
  4891. // }
  4892. //
  4893. // if historyPrescription.ID > 0 {
  4894. // prescription.PreTime = historyPrescription.PreTime
  4895. //
  4896. // }
  4897. //
  4898. // service.SaveHisPrescription(prescription)
  4899. //
  4900. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4901. // advices := items["advices"].([]interface{})
  4902. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4903. // groupNo := int64(0)
  4904. // ctime := time.Now().Unix()
  4905. // mtime := ctime
  4906. // if len(advices) > 0 {
  4907. // for _, advice := range advices {
  4908. // var s models.HisDoctorAdviceInfo
  4909. // s.PrescriptionId = prescription.ID
  4910. // s.AdviceType = 2
  4911. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4912. // s.StopState = 2
  4913. // s.ExecutionState = 2
  4914. // s.AdviceDate = recordDateTime
  4915. // s.Status = 1
  4916. // s.UserOrgId = adminInfo.CurrentOrgId
  4917. // s.RecordDate = recordDateTime
  4918. // s.StartTime = prescription.PreTime
  4919. // s.Groupno = groupNo
  4920. // s.CreatedTime = ctime
  4921. // s.UpdatedTime = mtime
  4922. // s.PatientId = patient_id
  4923. // s.HisPatientId = his_patient_id
  4924. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4925. // if errcode > 0 {
  4926. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4927. // return
  4928. // }
  4929. //
  4930. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4931. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4932. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4933. // if s.Price == 0 {
  4934. // s.Price = lastWarehouse.RetailPrice
  4935. // }
  4936. // }
  4937. //
  4938. // service.CreateHisDoctorAdvice(&s)
  4939. // //记录日志
  4940. // byterequest, _ := json.Marshal(s)
  4941. // adviceLog := models.XtDoctorAdviceLog{
  4942. // UserOrgId: s.UserOrgId,
  4943. // PatientId: s.PatientId,
  4944. // AdminUserId: adminInfo.AdminUser.Id,
  4945. // Module: 1,
  4946. // ErrLog: string(byterequest),
  4947. // Status: 1,
  4948. // Ctime: time.Now().Unix(),
  4949. // Mtime: 0,
  4950. // Source: "电脑端his医嘱修改",
  4951. // RecordDate: s.AdviceDate,
  4952. // }
  4953. // service.CreateDoctorAdviceLog(adviceLog)
  4954. // redis := service.RedisClient()
  4955. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4956. // redis.Set(key, "", time.Second)
  4957. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4958. // fmt.Println("keyOne", keyOne)
  4959. // redis.Set(keyOne, "", time.Second)
  4960. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4961. // redis.Set(keySeven, "", time.Second)
  4962. // redis.Close()
  4963. //
  4964. // }
  4965. // }
  4966. // }
  4967. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4968. // projects := items["project"].([]interface{})
  4969. // if len(projects) > 0 {
  4970. // for _, project := range projects {
  4971. // var p models.HisPrescriptionProject
  4972. // p.PrescriptionId = prescription.ID
  4973. // p.Ctime = time.Now().Unix()
  4974. // p.Mtime = time.Now().Unix()
  4975. // p.PatientId = patient_id
  4976. // p.RecordDate = recordDateTime
  4977. // p.UserOrgId = adminInfo.CurrentOrgId
  4978. // p.HisPatientId = his_patient_id
  4979. // p.Status = 1
  4980. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4981. // if errcode > 0 {
  4982. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4983. // return
  4984. // }
  4985. // service.CreateHisProjectTwo(&p)
  4986. //
  4987. // //记录日志
  4988. // byterequest, _ := json.Marshal(p)
  4989. // adviceLog := models.XtDoctorAdviceLog{
  4990. // UserOrgId: p.UserOrgId,
  4991. // PatientId: p.PatientId,
  4992. // AdminUserId: adminInfo.AdminUser.Id,
  4993. // Module: 1,
  4994. // ErrLog: string(byterequest),
  4995. // Status: 1,
  4996. // Ctime: time.Now().Unix(),
  4997. // Mtime: 0,
  4998. // Source: "电脑端his项目修改",
  4999. // RecordDate: p.RecordDate,
  5000. // }
  5001. // service.CreateDoctorAdviceLog(adviceLog)
  5002. // }
  5003. // }
  5004. // }
  5005. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5006. // addition := items["addition"].([]interface{})
  5007. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5008. // ctime := time.Now().Unix()
  5009. // mtime := ctime
  5010. // if len(addition) > 0 {
  5011. // for _, item := range addition {
  5012. // var s models.HisAdditionalCharge
  5013. // s.PrescriptionId = prescription.ID
  5014. // s.Status = 1
  5015. // s.UserOrgId = adminInfo.CurrentOrgId
  5016. // s.RecordDate = recordDateTime
  5017. // s.CreatedTime = ctime
  5018. // s.UpdatedTime = mtime
  5019. // s.PatientId = patient_id
  5020. // s.HisPatientId = his_patient_id
  5021. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5022. // if errcode > 0 {
  5023. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5024. // return
  5025. // }
  5026. // service.CreateAdditionalCharge(&s)
  5027. // }
  5028. // }
  5029. // }
  5030. //
  5031. // }
  5032. // }
  5033. // }
  5034. // if err == nil {
  5035. // c.ServeSuccessJSON(map[string]interface{}{
  5036. // "msg": "保存成功",
  5037. // })
  5038. // return
  5039. //
  5040. // } else {
  5041. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5042. // return
  5043. // }
  5044. //}
  5045. func (c *HisApiController) DeletePrescription() {
  5046. prescription_id, _ := c.GetInt64("id")
  5047. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5048. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5049. ////同步到自备药
  5050. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5051. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5052. if selfPrescriptionOpen.IsOpen == 1 {
  5053. // 在函数结束时处理事务回滚
  5054. db := service.XTWriteDB()
  5055. tx := db.Begin()
  5056. defer func() {
  5057. if r := recover(); r != nil {
  5058. tx.Rollback()
  5059. } else {
  5060. tx.Commit()
  5061. }
  5062. }()
  5063. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5064. for _, item := range advicesList {
  5065. timeStr := time.Now().Format("2006-01-02")
  5066. timeArr := strings.Split(timeStr, "-")
  5067. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5068. total = total + 1
  5069. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5070. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5071. number = number + total
  5072. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5073. operation_time := time.Now().Unix()
  5074. creater := c.GetAdminUserInfo().AdminUser.Id
  5075. //创建一个出库单
  5076. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5077. WarehouseOutOrderNumber: warehousing_out_order,
  5078. OperationTime: operation_time,
  5079. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5080. Creater: creater,
  5081. Ctime: time.Now().Unix(),
  5082. Status: 1,
  5083. WarehouseOutTime: item.AdviceDate,
  5084. Type: 0,
  5085. PatientId: item.PatientId,
  5086. IsCheck: 1,
  5087. }
  5088. //查询今日是否有出库数据
  5089. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5090. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5091. if lastWarehouseOut.ID == 0 {
  5092. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5093. }
  5094. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5095. var total_count int64
  5096. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5097. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5098. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5099. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5100. }
  5101. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5102. total_count += prescribingNumberSeven
  5103. }
  5104. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5105. total_count += prescribingNumberSeven
  5106. }
  5107. //出库
  5108. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5109. WarehouseOutOrderNumber: warehousing_out_order,
  5110. WarehouseOutId: lastWarehouseOut.ID,
  5111. DrugId: item.DrugId,
  5112. Count: total_count,
  5113. Price: 0,
  5114. TotalPrice: 0,
  5115. Status: 1,
  5116. Ctime: item.AdviceDate,
  5117. Mtime: item.AdviceDate,
  5118. Remark: "",
  5119. OrgId: item.UserOrgId,
  5120. Type: 0,
  5121. Manufacturer: selfBasedrug.Manufacturer,
  5122. Dealer: selfBasedrug.Dealer,
  5123. RetailPrice: 0,
  5124. RetailTotalPrice: 0,
  5125. CountUnit: selfBasedrug.MinUnit,
  5126. ExpiryDate: 0,
  5127. ProductDate: 0,
  5128. Number: "",
  5129. BatchNumber: "",
  5130. IsSys: 1,
  5131. WarehouseInfoId: 0,
  5132. AdminUserId: 0,
  5133. StockCount: "",
  5134. IsCheck: 1,
  5135. SysRecordTime: item.AdviceDate,
  5136. PatientId: item.PatientId,
  5137. ClassType: "",
  5138. AdviceId: item.ID,
  5139. }
  5140. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5141. }
  5142. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5143. for _, it := range warehousingOutInfo {
  5144. //查询今日是否有出库数据
  5145. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5146. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5147. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5148. //出库逻辑
  5149. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5150. //查询剩余库存
  5151. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5152. var sum_count int64
  5153. for _, its := range stockInfo {
  5154. if its.MaxUnit == medical.MaxUnit {
  5155. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5156. }
  5157. sum_count += its.StockMaxNumber + its.StockMinNumber
  5158. }
  5159. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5160. }
  5161. }
  5162. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5163. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5164. //耗材保存处方出库
  5165. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5166. //已收费和已发药限制逻辑
  5167. isCharge := false
  5168. isMedicine := false
  5169. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5170. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5171. if new_prescription.IsMedicine == 1 {
  5172. isMedicine = true
  5173. }
  5174. for _, item := range new_prescriptions {
  5175. if item.OrderStatus == 4 {
  5176. isCharge = true
  5177. }
  5178. }
  5179. if p_err != nil {
  5180. if new_prescription.ID > 0 {
  5181. if new_prescription.OrderStatus == 2 {
  5182. isCharge = true
  5183. }
  5184. }
  5185. }
  5186. for _, item := range advices {
  5187. if item.IsMedicine == 1 {
  5188. isMedicine = true
  5189. }
  5190. }
  5191. if isCharge {
  5192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5193. return
  5194. }
  5195. if isMedicine {
  5196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5197. return
  5198. }
  5199. //已收费和已发药限制逻辑
  5200. if len(projects) > 0 {
  5201. for _, item := range projects {
  5202. service.DeletePrintInfo(item.ID) //删除打印信息
  5203. if goodOutConfig.IsOpen != 1 {
  5204. if stockConfig.IsOpen == 1 {
  5205. if item.Type == 3 && item.IsOut == 1 {
  5206. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5207. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5208. good.Total = good.Total + f_count
  5209. service.UpdateGoodInfo(&good)
  5210. operation_time := time.Now().Unix()
  5211. creater := c.GetAdminUserInfo().AdminUser.Id
  5212. //创建退库单
  5213. timeStr := time.Now().Format("2006-01-02")
  5214. timeArr := strings.Split(timeStr, "-")
  5215. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5216. total = total + 1
  5217. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5218. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5219. cancelStock := models.CancelStock{
  5220. OrderNumber: orderNumber,
  5221. OperaTime: operation_time,
  5222. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5223. Creater: creater,
  5224. Ctime: time.Now().Unix(),
  5225. Status: 1,
  5226. ReturnTime: item.RecordDate,
  5227. Type: 1,
  5228. StorehouseId: houseConfig.StorehouseOutInfo,
  5229. IsCheck: 1,
  5230. }
  5231. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5232. if msgerrkonde == gorm.ErrRecordNotFound {
  5233. service.AddSigleCancelStock(&cancelStock)
  5234. }
  5235. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5236. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5237. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5238. //查询该耗材是否出库
  5239. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5240. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5241. deaerler, _ := service.GetDealerById(info.Dealer)
  5242. var total_count int64
  5243. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5244. total_count += count
  5245. if info.ID > 0 {
  5246. if info.Count >= total_count {
  5247. //回退库存
  5248. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5249. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5250. var flush_count int64
  5251. for _, it := range goodList {
  5252. flush_count += it.StockCount
  5253. }
  5254. cancelStockInfo := models.CancelStockInfo{
  5255. GoodId: item.ProjectId,
  5256. CancelStockId: cancel.ID,
  5257. GoodTypeId: good.GoodTypeId,
  5258. Count: prescribingNumber,
  5259. Price: info.Price,
  5260. Total: 0,
  5261. ProductDate: info.ProductDate,
  5262. ExpiryDate: info.ExpiryDate,
  5263. Ctime: time.Now().Unix(),
  5264. Status: 1,
  5265. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5266. OrderNumber: cancel.OrderNumber,
  5267. Type: 0,
  5268. Dealer: deaerler.DealerName,
  5269. Manufacturer: manufacturer.ManufacturerName,
  5270. Number: info.Number,
  5271. RegisterAccount: "",
  5272. Remark: "",
  5273. WarehouseInfoId: info.WarehouseInfotId,
  5274. PatientId: info.PatientId,
  5275. RecordDate: info.SysRecordTime,
  5276. StorehouseId: houseConfig.StorehouseOutInfo,
  5277. IsCheck: 1,
  5278. }
  5279. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5280. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5281. flow := models.VmStockFlow{
  5282. WarehousingId: info.WarehouseInfotId,
  5283. GoodId: item.ProjectId,
  5284. Number: info.Number,
  5285. LicenseNumber: info.LicenseNumber,
  5286. Count: prescribingNumber,
  5287. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5288. PatientId: item.PatientId,
  5289. SystemTime: info.SysRecordTime,
  5290. ConsumableType: 7,
  5291. IsSys: 0,
  5292. WarehousingOrder: "",
  5293. WarehouseOutId: info.WarehouseOutId,
  5294. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5295. IsEdit: 0,
  5296. CancelStockId: cancel.ID,
  5297. CancelOrderNumber: cancel.OrderNumber,
  5298. Manufacturer: manufacturer.ID,
  5299. Dealer: 0,
  5300. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5301. UpdateCreator: 0,
  5302. Status: 1,
  5303. Ctime: time.Now().Unix(),
  5304. Mtime: 0,
  5305. Price: info.Price,
  5306. WarehousingDetailId: info.WarehouseInfotId,
  5307. WarehouseOutDetailId: info.ID,
  5308. CancelOutDetailId: cancelInfo.ID,
  5309. ProductDate: info.ProductDate,
  5310. ExpireDate: info.ExpiryDate,
  5311. StorehouseId: houseConfig.StorehouseOutInfo,
  5312. OverCount: flush_count,
  5313. OperateTime: time.Now().Unix(),
  5314. }
  5315. service.CreateStockFlowOne(flow)
  5316. //退库数量增加
  5317. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5318. //出库数量减少
  5319. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5320. }
  5321. if info.Count < total_count {
  5322. //回退库存
  5323. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5324. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5325. var flush_count int64
  5326. for _, it := range goodList {
  5327. flush_count += it.StockCount
  5328. }
  5329. cancelStockInfo := models.CancelStockInfo{
  5330. GoodId: item.ProjectId,
  5331. CancelStockId: cancel.ID,
  5332. GoodTypeId: good.GoodTypeId,
  5333. Count: info.Count,
  5334. Price: info.Price,
  5335. Total: 0,
  5336. ProductDate: info.ProductDate,
  5337. ExpiryDate: info.ExpiryDate,
  5338. Ctime: time.Now().Unix(),
  5339. Status: 1,
  5340. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5341. OrderNumber: cancel.OrderNumber,
  5342. Type: 0,
  5343. Dealer: deaerler.DealerName,
  5344. Manufacturer: manufacturer.ManufacturerName,
  5345. Number: info.Number,
  5346. RegisterAccount: "",
  5347. Remark: "",
  5348. WarehouseInfoId: info.WarehouseInfotId,
  5349. PatientId: info.PatientId,
  5350. RecordDate: info.SysRecordTime,
  5351. StorehouseId: houseConfig.StorehouseOutInfo,
  5352. IsCheck: 1,
  5353. }
  5354. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5355. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5356. flow := models.VmStockFlow{
  5357. WarehousingId: info.WarehouseInfotId,
  5358. GoodId: item.ProjectId,
  5359. Number: info.Number,
  5360. LicenseNumber: info.LicenseNumber,
  5361. Count: info.Count,
  5362. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5363. PatientId: item.PatientId,
  5364. SystemTime: info.SysRecordTime,
  5365. ConsumableType: 7,
  5366. IsSys: 0,
  5367. WarehousingOrder: "",
  5368. WarehouseOutId: info.WarehouseOutId,
  5369. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5370. IsEdit: 0,
  5371. CancelStockId: cancel.ID,
  5372. CancelOrderNumber: cancel.OrderNumber,
  5373. Manufacturer: manufacturer.ID,
  5374. Dealer: 0,
  5375. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5376. UpdateCreator: 0,
  5377. Status: 1,
  5378. Ctime: time.Now().Unix(),
  5379. Mtime: 0,
  5380. Price: info.Price,
  5381. WarehousingDetailId: info.WarehouseInfotId,
  5382. WarehouseOutDetailId: info.ID,
  5383. CancelOutDetailId: cancelInfo.ID,
  5384. ProductDate: info.ProductDate,
  5385. ExpireDate: info.ExpiryDate,
  5386. StorehouseId: houseConfig.StorehouseOutInfo,
  5387. OverCount: flush_count,
  5388. OperateTime: time.Now().Unix(),
  5389. }
  5390. service.CreateStockFlowOne(flow)
  5391. //退库数量增加
  5392. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5393. //出库数量减少
  5394. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5395. }
  5396. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5397. var flush_count int64
  5398. for _, it := range goodList {
  5399. flush_count += it.StockCount
  5400. }
  5401. //查询已出库数量
  5402. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5403. if prescribingNumber < dialysisInfo.Count {
  5404. //改变数量
  5405. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5406. }
  5407. if prescribingNumber >= dialysisInfo.Count {
  5408. //删除出库表
  5409. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5410. }
  5411. //更新库存
  5412. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5413. //更新基础库库存
  5414. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5415. }
  5416. }
  5417. }
  5418. }
  5419. //保存耗材出库
  5420. if goodOutConfig.IsOpen == 1 {
  5421. if item.Type == 3 {
  5422. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5423. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5424. good.Total = good.Total + f_count
  5425. service.UpdateGoodInfo(&good)
  5426. operation_time := time.Now().Unix()
  5427. creater := c.GetAdminUserInfo().AdminUser.Id
  5428. //创建退库单
  5429. timeStr := time.Now().Format("2006-01-02")
  5430. timeArr := strings.Split(timeStr, "-")
  5431. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5432. total = total + 1
  5433. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5434. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5435. cancelStock := models.CancelStock{
  5436. OrderNumber: orderNumber,
  5437. OperaTime: operation_time,
  5438. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5439. Creater: creater,
  5440. Ctime: time.Now().Unix(),
  5441. Status: 1,
  5442. ReturnTime: item.RecordDate,
  5443. Type: 1,
  5444. StorehouseId: houseConfig.StorehouseOutInfo,
  5445. IsCheck: 1,
  5446. }
  5447. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5448. if msgerrkonde == gorm.ErrRecordNotFound {
  5449. service.AddSigleCancelStock(&cancelStock)
  5450. }
  5451. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5452. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5453. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5454. //查询该耗材是否出库
  5455. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5456. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5457. deaerler, _ := service.GetDealerById(info.Dealer)
  5458. var total_count int64
  5459. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5460. total_count += count
  5461. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5462. var flush_count int64
  5463. for _, it := range goodList {
  5464. flush_count += it.StockCount
  5465. }
  5466. fmt.Println("历史出库数据", info.Count)
  5467. fmt.Println("出库数量", total_count)
  5468. if info.ID > 0 {
  5469. cancelStockInfo := models.CancelStockInfo{
  5470. GoodId: item.ProjectId,
  5471. CancelStockId: cancel.ID,
  5472. GoodTypeId: good.GoodTypeId,
  5473. Count: prescribingNumber,
  5474. Price: info.Price,
  5475. Total: 0,
  5476. ProductDate: info.ProductDate,
  5477. ExpiryDate: info.ExpiryDate,
  5478. Ctime: time.Now().Unix(),
  5479. Status: 1,
  5480. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5481. OrderNumber: cancel.OrderNumber,
  5482. Type: 0,
  5483. Dealer: deaerler.DealerName,
  5484. Manufacturer: manufacturer.ManufacturerName,
  5485. Number: info.Number,
  5486. RegisterAccount: "",
  5487. Remark: "",
  5488. WarehouseInfoId: info.WarehouseInfotId,
  5489. PatientId: info.PatientId,
  5490. RecordDate: info.SysRecordTime,
  5491. StorehouseId: houseConfig.StorehouseOutInfo,
  5492. IsCheck: 1,
  5493. }
  5494. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5495. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5496. //查询出库数量
  5497. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5498. //出库数据 大于 退库数量
  5499. if len(list) > 0 {
  5500. for _, it := range list {
  5501. //回退库存
  5502. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5503. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5504. var flush_count_one int64
  5505. for _, it := range goodList {
  5506. flush_count_one += it.StockCount
  5507. }
  5508. //查询该批次是否有退库数据
  5509. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5510. creater := c.GetAdminUserInfo().AdminUser.Id
  5511. flow := models.VmStockFlow{
  5512. WarehousingId: it.WarehouseInfotId,
  5513. GoodId: it.GoodId,
  5514. Number: it.Number,
  5515. LicenseNumber: it.LicenseNumber,
  5516. Count: it.Count,
  5517. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5518. PatientId: it.PatientId,
  5519. SystemTime: it.SysRecordTime,
  5520. ConsumableType: 7,
  5521. IsSys: 0,
  5522. WarehousingOrder: "",
  5523. WarehouseOutId: it.WarehouseOutId,
  5524. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5525. IsEdit: 0,
  5526. CancelStockId: cancel.ID,
  5527. CancelOrderNumber: cancel.OrderNumber,
  5528. Manufacturer: manufacturer.ID,
  5529. Dealer: 0,
  5530. Creator: creater,
  5531. UpdateCreator: 0,
  5532. Status: 1,
  5533. Ctime: time.Now().Unix(),
  5534. Mtime: 0,
  5535. Price: it.Price,
  5536. WarehousingDetailId: it.WarehouseInfotId,
  5537. WarehouseOutDetailId: it.ID,
  5538. CancelOutDetailId: cancelInfo.ID,
  5539. ProductDate: it.ProductDate,
  5540. ExpireDate: it.ExpiryDate,
  5541. StorehouseId: houseConfig.StorehouseOutInfo,
  5542. OverCount: flush_count_one,
  5543. }
  5544. service.CreateStockFlowOne(flow)
  5545. //if flow.ID > 0 {
  5546. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5547. //}
  5548. }
  5549. }
  5550. //flow := models.VmStockFlow{
  5551. // WarehousingId: info.WarehouseInfotId,
  5552. // GoodId: item.ProjectId,
  5553. // Number: info.Number,
  5554. // LicenseNumber: info.LicenseNumber,
  5555. // Count: prescribingNumber,
  5556. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5557. // PatientId: item.PatientId,
  5558. // SystemTime: info.SysRecordTime,
  5559. // ConsumableType: 7,
  5560. // IsSys: 0,
  5561. // WarehousingOrder: "",
  5562. // WarehouseOutId: info.WarehouseOutId,
  5563. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5564. // IsEdit: 0,
  5565. // CancelStockId: cancel.ID,
  5566. // CancelOrderNumber: cancel.OrderNumber,
  5567. // Manufacturer: manufacturer.ID,
  5568. // Dealer: 0,
  5569. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5570. // UpdateCreator: 0,
  5571. // Status: 1,
  5572. // Ctime: time.Now().Unix(),
  5573. // Mtime: 0,
  5574. // Price: info.Price,
  5575. // WarehousingDetailId: info.WarehouseInfotId,
  5576. // WarehouseOutDetailId: info.ID,
  5577. // CancelOutDetailId: cancelInfo.ID,
  5578. // ProductDate: info.ProductDate,
  5579. // ExpireDate: info.ExpiryDate,
  5580. // StorehouseId: houseConfig.StorehouseOutInfo,
  5581. // OverCount: flush_count,
  5582. //}
  5583. //service.CreateStockFlowOne(flow)
  5584. //退库数量增加
  5585. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5586. //出库数量减少
  5587. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5588. //查询已出库数量
  5589. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5590. if prescribingNumber < dialysisInfo.Count {
  5591. //改变数量
  5592. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5593. }
  5594. if prescribingNumber >= dialysisInfo.Count {
  5595. //删除出库表
  5596. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5597. }
  5598. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5599. var flush_count_one int64
  5600. for _, it := range goodList {
  5601. flush_count_one += it.StockCount
  5602. }
  5603. //更新库存
  5604. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5605. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5606. //更新基础库库存
  5607. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5608. }
  5609. }
  5610. }
  5611. }
  5612. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5613. fmt.Println(err)
  5614. }
  5615. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5616. fmt.Println(err)
  5617. if len(advices) > 0 {
  5618. for _, item := range advices {
  5619. redis := service.RedisClient()
  5620. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5621. redis.Set(keyFive, "", time.Second)
  5622. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5623. redis.Set(keyOne, "", time.Second)
  5624. redis.Close()
  5625. }
  5626. }
  5627. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5628. if len(advices) > 0 {
  5629. for _, item := range advices {
  5630. creater := c.GetAdminUserInfo().AdminUser.Id
  5631. service.DrugAutoAddCancelInfo(item, creater)
  5632. }
  5633. }
  5634. } else {
  5635. if drugOutConfig.IsOpen == 1 {
  5636. if len(advices) > 0 {
  5637. for _, item := range advices {
  5638. creater := c.GetAdminUserInfo().AdminUser.Id
  5639. service.DrugAutoAddCancelInfo(item, creater)
  5640. }
  5641. }
  5642. } else {
  5643. if len(advices) > 0 {
  5644. for _, item := range advices {
  5645. creater := c.GetAdminUserInfo().AdminUser.Id
  5646. service.DrugAutoAddCancelInfo(item, creater)
  5647. }
  5648. }
  5649. }
  5650. }
  5651. c.ServeSuccessJSON(map[string]interface{}{
  5652. "msg": "删除成功",
  5653. })
  5654. return
  5655. }
  5656. func (c *HisApiController) DeleteDoctorAdvice() {
  5657. id, _ := c.GetInt64("id")
  5658. advice, _ := service.GetHisDoctorAdvicesById(id)
  5659. ////同步到自备药
  5660. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5661. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5662. if selfPrescriptionOpen.IsOpen == 1 {
  5663. db := service.XTWriteDB()
  5664. tx := db.Begin()
  5665. defer func() {
  5666. if r := recover(); r != nil {
  5667. tx.Rollback()
  5668. } else {
  5669. tx.Commit()
  5670. }
  5671. }()
  5672. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5673. var total_count int64
  5674. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5675. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5676. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5677. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5678. }
  5679. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5680. total_count += prescribingNumberSeven
  5681. }
  5682. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5683. total_count += prescribingNumberSeven
  5684. }
  5685. timeStr := time.Now().Format("2006-01-02")
  5686. timeArr := strings.Split(timeStr, "-")
  5687. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5688. total = total + 1
  5689. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5690. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5691. number = number + total
  5692. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5693. operation_time := time.Now().Unix()
  5694. creater := c.GetAdminUserInfo().AdminUser.Id
  5695. //创建一个出库单
  5696. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5697. WarehouseOutOrderNumber: warehousing_out_order,
  5698. OperationTime: operation_time,
  5699. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5700. Creater: creater,
  5701. Ctime: time.Now().Unix(),
  5702. Status: 1,
  5703. WarehouseOutTime: advice.AdviceDate,
  5704. Type: 0,
  5705. PatientId: advice.PatientId,
  5706. IsCheck: 1,
  5707. }
  5708. //查询今日是否有出库数据
  5709. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5710. if lastWarehouseOut.ID == 0 {
  5711. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5712. }
  5713. //出库
  5714. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5715. WarehouseOutId: lastWarehouseOut.ID,
  5716. WarehouseOutOrderNumber: warehousing_out_order,
  5717. DrugId: advice.DrugId,
  5718. Count: total_count,
  5719. Price: 0,
  5720. TotalPrice: 0,
  5721. Status: 1,
  5722. Ctime: advice.AdviceDate,
  5723. Mtime: advice.AdviceDate,
  5724. Remark: "",
  5725. OrgId: advice.UserOrgId,
  5726. Type: 0,
  5727. Manufacturer: selfBasedrug.Manufacturer,
  5728. Dealer: selfBasedrug.Dealer,
  5729. RetailPrice: 0,
  5730. RetailTotalPrice: 0,
  5731. CountUnit: advice.PrescribingNumberUnit,
  5732. ExpiryDate: 0,
  5733. ProductDate: 0,
  5734. Number: "",
  5735. BatchNumber: "",
  5736. IsSys: 0,
  5737. WarehouseInfoId: 0,
  5738. AdminUserId: 0,
  5739. StockCount: "",
  5740. IsCheck: 1,
  5741. SysRecordTime: advice.AdviceDate,
  5742. PatientId: advice.PatientId,
  5743. AdviceId: advice.ID,
  5744. ClassType: "",
  5745. }
  5746. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5747. for _, it := range warehousingOutInfo {
  5748. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5749. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5750. //出库逻辑
  5751. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5752. //查询剩余库存
  5753. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5754. var sum_count int64
  5755. for _, its := range stockInfo {
  5756. if its.MaxUnit == medical.MaxUnit {
  5757. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5758. }
  5759. sum_count += its.StockMaxNumber + its.StockMinNumber
  5760. }
  5761. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5762. }
  5763. }
  5764. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5765. //已收费和已发药的限制逻辑
  5766. isCharge := false
  5767. isMedicine := false
  5768. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5769. //获取今天该患者所有处方,判断是否发药或者收费
  5770. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5771. //for _, item := range new_prescriptions {
  5772. if new_prescription.IsMedicine == 1 {
  5773. isMedicine = true
  5774. }
  5775. //}
  5776. for _, item := range new_prescriptions {
  5777. if item.OrderStatus == 4 {
  5778. isCharge = true
  5779. }
  5780. }
  5781. if isMedicine {
  5782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5783. return
  5784. }
  5785. if isCharge {
  5786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5787. return
  5788. }
  5789. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5790. for _, item := range advices {
  5791. if item.IsMedicine == 1 {
  5792. isMedicine = true
  5793. }
  5794. }
  5795. if isMedicine {
  5796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5797. return
  5798. }
  5799. if new_prescription.ID > 0 {
  5800. if new_prescription.OrderStatus == 2 {
  5801. isCharge = true
  5802. }
  5803. }
  5804. if isCharge {
  5805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5806. return
  5807. }
  5808. //已收费和已发药的限制逻辑
  5809. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5810. redis := service.RedisClient()
  5811. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5812. redis.Set(keyFive, "", time.Second)
  5813. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5814. redis.Set(keyOne, "", time.Second)
  5815. defer redis.Close()
  5816. if err == nil {
  5817. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5818. //查询是否在处方中出库
  5819. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5820. if openConfig.IsOpen != 1 {
  5821. //判断该医嘱是否执行了
  5822. if advice.ExecutionState == 1 {
  5823. creater := c.GetAdminUserInfo().AdminUser.Id
  5824. service.DrugAutoAddCancelInfo(&advice, creater)
  5825. }
  5826. }
  5827. //开启保存处方扣减功能
  5828. if openConfig.IsOpen == 1 {
  5829. creater := c.GetAdminUserInfo().AdminUser.Id
  5830. service.DrugAutoAddCancelInfo(&advice, creater)
  5831. }
  5832. } else {
  5833. if drugOutConfig.IsOpen == 1 {
  5834. //查询是否在处方中出库
  5835. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5836. if openConfig.IsOpen != 1 {
  5837. //判断该医嘱是否执行了
  5838. if advice.ExecutionState == 1 {
  5839. creater := c.GetAdminUserInfo().AdminUser.Id
  5840. service.DrugAutoAddCancelInfo(&advice, creater)
  5841. }
  5842. }
  5843. //开启保存处方扣减功能
  5844. if openConfig.IsOpen == 1 {
  5845. creater := c.GetAdminUserInfo().AdminUser.Id
  5846. service.DrugAutoAddCancelInfo(&advice, creater)
  5847. }
  5848. } else {
  5849. //判断该医嘱是否执行了
  5850. if advice.ExecutionState == 1 {
  5851. creater := c.GetAdminUserInfo().AdminUser.Id
  5852. service.DrugAutoAddCancelInfo(&advice, creater)
  5853. }
  5854. }
  5855. }
  5856. c.ServeSuccessJSON(map[string]interface{}{
  5857. "msg": "删除成功",
  5858. })
  5859. return
  5860. } else {
  5861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5862. return
  5863. }
  5864. }
  5865. func (c *HisApiController) DeleteProject() {
  5866. id, _ := c.GetInt64("id")
  5867. adminInfo := c.GetAdminUserInfo()
  5868. project, _ := service.GetHisProjectByID(id)
  5869. // var consumable models.DialysisBeforePrepare
  5870. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5871. //耗材保存处方出库
  5872. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5873. isCharge := false
  5874. isMedicine := false
  5875. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5876. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5877. for _, item := range new_prescriptions {
  5878. if item.IsMedicine == 1 {
  5879. isMedicine = true
  5880. }
  5881. }
  5882. for _, item := range new_prescriptions {
  5883. if item.OrderStatus == 4 {
  5884. isCharge = true
  5885. }
  5886. }
  5887. if isMedicine {
  5888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5889. return
  5890. }
  5891. if isCharge {
  5892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5893. return
  5894. }
  5895. if new_prescription.ID > 0 {
  5896. if new_prescription.OrderStatus == 2 {
  5897. isCharge = true
  5898. }
  5899. }
  5900. if isCharge {
  5901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5902. return
  5903. }
  5904. service.DeletePrintInfo(id)
  5905. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5906. label.Status = 0
  5907. service.CreateHisLabelRecordTwo(&label)
  5908. fmt.Println(goodOutConfig.IsOpen)
  5909. if goodOutConfig.IsOpen != 1 {
  5910. if stockConfig.IsOpen == 1 {
  5911. if project.Type == 2 {
  5912. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5913. fmt.Println(err)
  5914. }
  5915. if project.Type == 3 && project.IsOut == 1 {
  5916. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5917. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5918. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5919. operation_time := time.Now().Unix()
  5920. creater := adminInfo.AdminUser.Id
  5921. //创建退库单
  5922. timeStr := time.Now().Format("2006-01-02")
  5923. timeArr := strings.Split(timeStr, "-")
  5924. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5925. total = total + 1
  5926. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5927. cancelStock := models.CancelStock{
  5928. OrderNumber: orderNumber,
  5929. OperaTime: operation_time,
  5930. OrgId: adminInfo.CurrentOrgId,
  5931. Creater: creater,
  5932. Ctime: time.Now().Unix(),
  5933. Status: 1,
  5934. ReturnTime: project.RecordDate,
  5935. Type: 1,
  5936. StorehouseId: houseConfig.StorehouseOutInfo,
  5937. IsCheck: 1,
  5938. }
  5939. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5940. if msgerrkonde == gorm.ErrRecordNotFound {
  5941. service.AddSigleCancelStock(&cancelStock)
  5942. }
  5943. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5944. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5945. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5946. //查询是否有出库
  5947. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5948. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5949. deaerler, _ := service.GetDealerById(info.Dealer)
  5950. if info.ID > 0 {
  5951. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5952. if info.Count >= prescribingNumber {
  5953. cancelStockInfo := models.CancelStockInfo{
  5954. GoodId: project.ProjectId,
  5955. CancelStockId: cancel.ID,
  5956. GoodTypeId: good.GoodTypeId,
  5957. Count: prescribingNumber,
  5958. Price: info.Price,
  5959. Total: 0,
  5960. ProductDate: info.ProductDate,
  5961. ExpiryDate: info.ExpiryDate,
  5962. Ctime: time.Now().Unix(),
  5963. Status: 1,
  5964. OrgId: adminInfo.CurrentOrgId,
  5965. OrderNumber: cancel.OrderNumber,
  5966. Type: 0,
  5967. Dealer: deaerler.DealerName,
  5968. Manufacturer: manufacturer.ManufacturerName,
  5969. Number: info.Number,
  5970. RegisterAccount: "",
  5971. Remark: "",
  5972. WarehouseInfoId: info.WarehouseInfotId,
  5973. PatientId: info.PatientId,
  5974. RecordDate: info.SysRecordTime,
  5975. StorehouseId: houseConfig.StorehouseOutInfo,
  5976. IsCheck: 1,
  5977. }
  5978. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5979. //回退库存
  5980. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5981. //退库数量增加
  5982. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5983. //出库数量减少
  5984. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5985. }
  5986. if info.Count < prescribingNumber {
  5987. cancelStockInfo := models.CancelStockInfo{
  5988. GoodId: project.ProjectId,
  5989. CancelStockId: cancel.ID,
  5990. GoodTypeId: good.GoodTypeId,
  5991. Count: info.Count,
  5992. Price: info.Price,
  5993. Total: 0,
  5994. ProductDate: info.ProductDate,
  5995. ExpiryDate: info.ExpiryDate,
  5996. Ctime: time.Now().Unix(),
  5997. Status: 1,
  5998. OrgId: adminInfo.CurrentOrgId,
  5999. OrderNumber: cancel.OrderNumber,
  6000. Type: 0,
  6001. Dealer: deaerler.DealerName,
  6002. Manufacturer: manufacturer.ManufacturerName,
  6003. Number: info.Number,
  6004. RegisterAccount: "",
  6005. Remark: "",
  6006. WarehouseInfoId: info.WarehouseInfotId,
  6007. PatientId: info.PatientId,
  6008. RecordDate: info.SysRecordTime,
  6009. StorehouseId: houseConfig.StorehouseOutInfo,
  6010. IsCheck: 1,
  6011. }
  6012. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6013. //回退库存
  6014. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6015. //退库数量增加
  6016. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6017. //出库数量减少
  6018. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6019. }
  6020. //查询剩余库存
  6021. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6022. var over_count int64
  6023. for _, it := range goodList {
  6024. over_count += it.StockCount
  6025. }
  6026. //出库数据 大于 退库数量
  6027. if info.Count >= prescribingNumber {
  6028. flow := models.VmStockFlow{
  6029. WarehousingId: info.WarehouseInfotId,
  6030. GoodId: project.ProjectId,
  6031. Number: info.Number,
  6032. LicenseNumber: info.LicenseNumber,
  6033. Count: prescribingNumber,
  6034. UserOrgId: adminInfo.CurrentOrgId,
  6035. PatientId: project.PatientId,
  6036. SystemTime: info.SysRecordTime,
  6037. ConsumableType: 7,
  6038. IsSys: 0,
  6039. WarehousingOrder: "",
  6040. WarehouseOutId: info.WarehouseOutId,
  6041. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6042. IsEdit: 0,
  6043. CancelStockId: cancel.ID,
  6044. CancelOrderNumber: cancel.OrderNumber,
  6045. Manufacturer: manufacturer.ID,
  6046. Dealer: 0,
  6047. Creator: adminInfo.AdminUser.Id,
  6048. UpdateCreator: 0,
  6049. Status: 1,
  6050. Ctime: time.Now().Unix(),
  6051. Mtime: 0,
  6052. Price: info.Price,
  6053. WarehousingDetailId: info.WarehouseInfotId,
  6054. WarehouseOutDetailId: info.ID,
  6055. CancelOutDetailId: cancelInfo.ID,
  6056. ProductDate: info.ProductDate,
  6057. ExpireDate: info.ExpiryDate,
  6058. StorehouseId: houseConfig.StorehouseOutInfo,
  6059. OverCount: over_count,
  6060. OperateTime: time.Now().Unix(),
  6061. }
  6062. service.CreateStockFlowOne(flow)
  6063. }
  6064. //出库数据小于退库数据
  6065. if info.Count < prescribingNumber {
  6066. flow := models.VmStockFlow{
  6067. WarehousingId: info.WarehouseInfotId,
  6068. GoodId: project.ProjectId,
  6069. Number: info.Number,
  6070. LicenseNumber: info.LicenseNumber,
  6071. Count: info.Count,
  6072. UserOrgId: adminInfo.CurrentOrgId,
  6073. PatientId: project.PatientId,
  6074. SystemTime: info.SysRecordTime,
  6075. ConsumableType: 7,
  6076. IsSys: 0,
  6077. WarehousingOrder: "",
  6078. WarehouseOutId: info.WarehouseOutId,
  6079. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6080. IsEdit: 0,
  6081. CancelStockId: cancel.ID,
  6082. CancelOrderNumber: cancel.OrderNumber,
  6083. Manufacturer: manufacturer.ID,
  6084. Dealer: 0,
  6085. Creator: adminInfo.AdminUser.Id,
  6086. UpdateCreator: 0,
  6087. Status: 1,
  6088. Ctime: time.Now().Unix(),
  6089. Mtime: 0,
  6090. Price: info.Price,
  6091. WarehousingDetailId: info.WarehouseInfotId,
  6092. WarehouseOutDetailId: info.ID,
  6093. CancelOutDetailId: cancelInfo.ID,
  6094. ProductDate: info.ProductDate,
  6095. ExpireDate: info.ExpiryDate,
  6096. StorehouseId: houseConfig.StorehouseOutInfo,
  6097. OverCount: over_count,
  6098. OperateTime: time.Now().Unix(),
  6099. }
  6100. service.CreateStockFlowOne(flow)
  6101. }
  6102. //查询已出库数量
  6103. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6104. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6105. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6106. if prescribingNumber < dialysisInfo.Count {
  6107. //改变数量
  6108. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6109. }
  6110. if prescribingNumber >= dialysisInfo.Count {
  6111. //删除出库表
  6112. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6113. }
  6114. //更新剩余库存
  6115. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6116. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6117. var total_count_one int64
  6118. for _, it := range stockList {
  6119. total_count_one += it.StockCount
  6120. }
  6121. //基础库插入数据
  6122. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6123. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6124. var flush_count int64
  6125. for _, it := range goodListOne {
  6126. flush_count += it.StockCount
  6127. }
  6128. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6129. if errs != nil {
  6130. goodErrcode := models.XtGoodErrcode{
  6131. UserOrgId: project.UserOrgId,
  6132. Errcode: "手动出库更新剩余出库失败",
  6133. GoodId: project.ProjectId,
  6134. Status: 1,
  6135. Ctime: time.Now().Unix(),
  6136. Mtime: 0,
  6137. Count: 0,
  6138. StockCount: 0,
  6139. Creater: creater,
  6140. BatchNumberId: 0,
  6141. WarehouseOutId: 0,
  6142. }
  6143. service.CreateGoodErrcode(goodErrcode)
  6144. }
  6145. }
  6146. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6147. fmt.Println(err)
  6148. } else {
  6149. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6150. fmt.Println(err)
  6151. }
  6152. } else {
  6153. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6154. fmt.Println(err)
  6155. }
  6156. }
  6157. //保存处方出库
  6158. if goodOutConfig.IsOpen == 1 {
  6159. if project.Type == 3 {
  6160. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6161. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6162. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6163. operation_time := time.Now().Unix()
  6164. creater := adminInfo.AdminUser.Id
  6165. //创建退库单
  6166. timeStr := time.Now().Format("2006-01-02")
  6167. timeArr := strings.Split(timeStr, "-")
  6168. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6169. total = total + 1
  6170. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6171. cancelStock := models.CancelStock{
  6172. OrderNumber: orderNumber,
  6173. OperaTime: operation_time,
  6174. OrgId: adminInfo.CurrentOrgId,
  6175. Creater: creater,
  6176. Ctime: time.Now().Unix(),
  6177. Status: 1,
  6178. ReturnTime: project.RecordDate,
  6179. Type: 1,
  6180. StorehouseId: houseConfig.StorehouseOutInfo,
  6181. IsCheck: 1,
  6182. }
  6183. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6184. if msgerrkonde == gorm.ErrRecordNotFound {
  6185. service.AddSigleCancelStock(&cancelStock)
  6186. }
  6187. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6188. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6189. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6190. //获取出库数据
  6191. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6192. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6193. deaerler, _ := service.GetDealerById(info.Dealer)
  6194. if info.ID > 0 {
  6195. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6196. if info.Count >= prescribingNumber {
  6197. cancelStockInfo := models.CancelStockInfo{
  6198. GoodId: project.ProjectId,
  6199. CancelStockId: cancel.ID,
  6200. GoodTypeId: good.GoodTypeId,
  6201. Count: prescribingNumber,
  6202. Price: info.Price,
  6203. Total: 0,
  6204. ProductDate: info.ProductDate,
  6205. ExpiryDate: info.ExpiryDate,
  6206. Ctime: time.Now().Unix(),
  6207. Status: 1,
  6208. OrgId: adminInfo.CurrentOrgId,
  6209. OrderNumber: cancel.OrderNumber,
  6210. Type: 0,
  6211. Dealer: deaerler.DealerName,
  6212. Manufacturer: manufacturer.ManufacturerName,
  6213. Number: info.Number,
  6214. RegisterAccount: "",
  6215. Remark: "",
  6216. WarehouseInfoId: info.WarehouseInfotId,
  6217. PatientId: info.PatientId,
  6218. RecordDate: info.SysRecordTime,
  6219. StorehouseId: houseConfig.StorehouseOutInfo,
  6220. IsCheck: 1,
  6221. }
  6222. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6223. //退库数量增加
  6224. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6225. //出库数量减少
  6226. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6227. }
  6228. if info.Count < prescribingNumber {
  6229. cancelStockInfo := models.CancelStockInfo{
  6230. GoodId: project.ProjectId,
  6231. CancelStockId: cancel.ID,
  6232. GoodTypeId: good.GoodTypeId,
  6233. Count: prescribingNumber,
  6234. Price: info.Price,
  6235. Total: 0,
  6236. ProductDate: info.ProductDate,
  6237. ExpiryDate: info.ExpiryDate,
  6238. Ctime: time.Now().Unix(),
  6239. Status: 1,
  6240. OrgId: adminInfo.CurrentOrgId,
  6241. OrderNumber: cancel.OrderNumber,
  6242. Type: 0,
  6243. Dealer: deaerler.DealerName,
  6244. Manufacturer: manufacturer.ManufacturerName,
  6245. Number: info.Number,
  6246. RegisterAccount: "",
  6247. Remark: "",
  6248. WarehouseInfoId: info.WarehouseInfotId,
  6249. PatientId: info.PatientId,
  6250. RecordDate: info.SysRecordTime,
  6251. StorehouseId: houseConfig.StorehouseOutInfo,
  6252. IsCheck: 1,
  6253. }
  6254. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6255. //回退库存
  6256. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6257. }
  6258. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6259. var over_count int64
  6260. for _, it := range goodList {
  6261. over_count += it.StockCount
  6262. }
  6263. //查询出库数量
  6264. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6265. //出库数据 大于 退库数量
  6266. if len(list) > 0 {
  6267. for _, it := range list {
  6268. //回退库存
  6269. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6270. //退库数量增加
  6271. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6272. //出库数量减少
  6273. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6274. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6275. var over_count_one int64
  6276. for _, it := range goodList {
  6277. over_count_one += it.StockCount
  6278. }
  6279. //查询该批次是否有退库数据
  6280. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6281. flow := models.VmStockFlow{
  6282. WarehousingId: it.WarehouseInfotId,
  6283. GoodId: it.GoodId,
  6284. Number: it.Number,
  6285. LicenseNumber: it.LicenseNumber,
  6286. Count: it.Count,
  6287. UserOrgId: adminInfo.CurrentOrgId,
  6288. PatientId: it.PatientId,
  6289. SystemTime: it.SysRecordTime,
  6290. ConsumableType: 7,
  6291. IsSys: 0,
  6292. WarehousingOrder: "",
  6293. WarehouseOutId: it.WarehouseOutId,
  6294. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6295. IsEdit: 0,
  6296. CancelStockId: cancel.ID,
  6297. CancelOrderNumber: cancel.OrderNumber,
  6298. Manufacturer: manufacturer.ID,
  6299. Dealer: 0,
  6300. Creator: adminInfo.AdminUser.Id,
  6301. UpdateCreator: 0,
  6302. Status: 1,
  6303. Ctime: time.Now().Unix(),
  6304. Mtime: 0,
  6305. Price: it.Price,
  6306. WarehousingDetailId: it.WarehouseInfotId,
  6307. WarehouseOutDetailId: it.ID,
  6308. CancelOutDetailId: cancelInfo.ID,
  6309. ProductDate: it.ProductDate,
  6310. ExpireDate: it.ExpiryDate,
  6311. StorehouseId: houseConfig.StorehouseOutInfo,
  6312. OverCount: over_count_one,
  6313. OperateTime: time.Now().Unix(),
  6314. }
  6315. service.CreateStockFlowOne(flow)
  6316. }
  6317. }
  6318. //查询已出库数量
  6319. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6320. if prescribingNumber < dialysisInfo.Count {
  6321. //改变数量
  6322. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6323. }
  6324. if prescribingNumber >= dialysisInfo.Count {
  6325. //删除出库表
  6326. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6327. }
  6328. //更新剩余库存
  6329. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6330. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6331. var total_count_one int64
  6332. for _, it := range stockList {
  6333. total_count_one += it.StockCount
  6334. }
  6335. //基础库插入数据
  6336. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6337. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6338. var flush_count int64
  6339. for _, it := range goodListOne {
  6340. flush_count += it.StockCount
  6341. }
  6342. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6343. if errs != nil {
  6344. goodErrcode := models.XtGoodErrcode{
  6345. UserOrgId: project.UserOrgId,
  6346. Errcode: "手动出库更新剩余出库失败",
  6347. GoodId: project.ProjectId,
  6348. Status: 1,
  6349. Ctime: time.Now().Unix(),
  6350. Mtime: 0,
  6351. Count: 0,
  6352. StockCount: 0,
  6353. Creater: creater,
  6354. BatchNumberId: 0,
  6355. WarehouseOutId: 0,
  6356. }
  6357. service.CreateGoodErrcode(goodErrcode)
  6358. }
  6359. }
  6360. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6361. fmt.Println(err)
  6362. } else {
  6363. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6364. fmt.Println(err)
  6365. }
  6366. }
  6367. c.ServeSuccessJSON(map[string]interface{}{
  6368. "msg": "删除成功",
  6369. })
  6370. return
  6371. }
  6372. func (c *HisApiController) CreateHisAdditionalCharge() {
  6373. his_patient_id, _ := c.GetInt64("his_patient_id")
  6374. patient_id, _ := c.GetInt64("patient_id")
  6375. record_date := c.GetString("record_date")
  6376. timeLayout := "2006-01-02"
  6377. loc, _ := time.LoadLocation("Local")
  6378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6379. if err != nil {
  6380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6381. return
  6382. }
  6383. adminInfo := c.GetAdminUserInfo()
  6384. recordDateTime := theTime.Unix()
  6385. dataBody := make(map[string]interface{}, 0)
  6386. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6387. if err != nil {
  6388. utils.ErrorLog(err.Error())
  6389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6390. return
  6391. }
  6392. var additions []*models.HisAdditionalCharge
  6393. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6394. additions, _ := dataBody["addition"].([]interface{})
  6395. if len(additions) > 0 {
  6396. for _, item := range additions {
  6397. items := item.(map[string]interface{})
  6398. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6399. utils.ErrorLog("item_id")
  6400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6401. return
  6402. }
  6403. item_id := int64(items["item_id"].(float64))
  6404. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6405. utils.ErrorLog("item_name")
  6406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6407. return
  6408. }
  6409. item_name := items["item_name"].(string)
  6410. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6411. utils.ErrorLog("price")
  6412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6413. return
  6414. }
  6415. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6416. ctime := time.Now().Unix()
  6417. additional := &models.HisAdditionalCharge{
  6418. PatientId: patient_id,
  6419. HisPatientId: his_patient_id,
  6420. UserOrgId: adminInfo.CurrentOrgId,
  6421. RecordDate: recordDateTime,
  6422. CreatedTime: ctime,
  6423. UpdatedTime: ctime,
  6424. Modifier: adminInfo.AdminUser.Id,
  6425. Creator: adminInfo.AdminUser.Id,
  6426. Price: price,
  6427. ItemName: item_name,
  6428. ItemId: item_id,
  6429. Status: 1,
  6430. }
  6431. additions = append(additions, additional)
  6432. }
  6433. }
  6434. }
  6435. for _, item := range additions {
  6436. service.CreateAddtionalCharge(item)
  6437. }
  6438. c.ServeSuccessJSON(map[string]interface{}{
  6439. "msg": "创建成功",
  6440. })
  6441. }
  6442. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6443. blood_fat := c.GetString("blood_fat")
  6444. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6445. blood_sugar := c.GetString("blood_sugar")
  6446. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6447. chief_conplaint := c.GetString("chief_conplaint")
  6448. dbp := c.GetString("dbp")
  6449. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6450. delivery_way, _ := c.GetInt64("delivery_way")
  6451. diagnostic := c.GetString("diagnostic")
  6452. family_history := c.GetString("family_history")
  6453. height := c.GetString("height")
  6454. history_of_present_illness := c.GetString("history_of_present_illness")
  6455. is_infect, _ := c.GetInt64("is_infect")
  6456. past_history := c.GetString("past_history")
  6457. patient_id, _ := c.GetInt64("patient_id")
  6458. his_patient_id, _ := c.GetInt64("his_patient_id")
  6459. personal_history := c.GetString("personal_history")
  6460. pulse := c.GetString("pulse")
  6461. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6462. sbp := c.GetString("sbp")
  6463. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6464. heightfloat, _ := strconv.ParseFloat(height, 64)
  6465. sicktype := c.GetString("sick_type")
  6466. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6467. symptom := c.GetString("symptom")
  6468. sick_date := c.GetString("sick_date")
  6469. temperatures := c.GetString("temperature")
  6470. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6471. record_date := c.GetString("record_date")
  6472. breathing := c.GetString("breathing")
  6473. doctor_advice := c.GetString("doctor_advice")
  6474. remark := c.GetString("remark")
  6475. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6476. sick, _ := c.GetInt64("sick")
  6477. diagnose, _ := c.GetInt64("diagnose")
  6478. //id, _ := c.GetInt64("id")
  6479. timeLayout := "2006-01-02"
  6480. loc, _ := time.LoadLocation("Local")
  6481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6482. allergic_history := c.GetString("allergic_history")
  6483. if err != nil {
  6484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6485. return
  6486. }
  6487. recordDateTime := theTime.Unix()
  6488. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6489. if err != nil {
  6490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6491. return
  6492. }
  6493. sickTimes := sickTime.Unix()
  6494. ctime := time.Now().Unix()
  6495. primary_disease := c.GetString("primary_disease")
  6496. confirm_failure_date := c.GetString("confirm_failure_date")
  6497. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6498. drug_allergy_history := c.GetString("drug_allergy_history")
  6499. physical_examination := c.GetString("physical_examination")
  6500. special_inspection := c.GetString("special_inspection")
  6501. lab_apparatus := c.GetString("lab_apparatus")
  6502. caseHistory := models.HisPatientCaseHistory{
  6503. HisPatientId: his_patient_id,
  6504. PatientId: patient_id,
  6505. Temperature: temperature,
  6506. BloodSugar: bloodsugarfloat,
  6507. Pulse: pulsefloat,
  6508. Sbp: sbpfloat,
  6509. Dbp: dbpfloat,
  6510. Height: heightfloat,
  6511. BloodFat: bloodfatfloat,
  6512. SickType: sick_type,
  6513. Symptom: symptom,
  6514. SickDate: sickTimes,
  6515. IsInfect: is_infect,
  6516. HistoryOfPresentIllness: history_of_present_illness,
  6517. PastHistory: past_history,
  6518. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6519. ChiefConplaint: chief_conplaint,
  6520. PersonalHistory: personal_history,
  6521. FamilyHistory: family_history,
  6522. Diagnostic: diagnostic,
  6523. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6524. Status: 1,
  6525. Ctime: ctime,
  6526. Mtime: ctime,
  6527. RecordDate: recordDateTime,
  6528. DeliveryWay: delivery_way,
  6529. Breathing: breathingfloat,
  6530. DoctorAdvice: doctor_advice,
  6531. Remark: remark,
  6532. Sick: sick,
  6533. Diagnose: diagnose,
  6534. AllergicHistory: allergic_history,
  6535. PrimaryDisease: primary_disease,
  6536. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6537. DrugAllergyHistory: drug_allergy_history,
  6538. PhysicalExamination: physical_examination,
  6539. SpecialInspection: special_inspection,
  6540. LabApparatus: lab_apparatus,
  6541. }
  6542. //查询该患者是否有病历
  6543. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6544. if errcodes == gorm.ErrRecordNotFound {
  6545. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6546. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6547. if err != nil {
  6548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6549. return
  6550. }
  6551. c.ServeSuccessJSON(map[string]interface{}{
  6552. "caseHistory": caseHistory,
  6553. "historyInfo": historyInfo,
  6554. })
  6555. return
  6556. } else if errcodes == nil {
  6557. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6558. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6559. if err != nil {
  6560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6561. return
  6562. }
  6563. c.ServeSuccessJSON(map[string]interface{}{
  6564. "caseHistory": caseHistory,
  6565. "historyInfo": historyInfo,
  6566. })
  6567. }
  6568. //查询该患者是否有病历
  6569. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6570. //if errcode == gorm.ErrRecordNotFound {
  6571. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6572. // if err != nil {
  6573. // c.ServeSuccessJSON(map[string]interface{}{
  6574. // "msg": "保存成功",
  6575. // })
  6576. // }
  6577. //} else if errcode == nil {
  6578. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6579. // return
  6580. //}
  6581. }
  6582. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6583. patient_id, _ := c.GetInt64("patient_id", 0)
  6584. adminUser := c.GetAdminUserInfo()
  6585. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6586. c.ServeSuccessJSON(map[string]interface{}{
  6587. "list": caseHistorys,
  6588. })
  6589. }
  6590. func (c *HisApiController) GetHisPatientCaseHistory() {
  6591. record_date, _ := c.GetInt64("record_date", 0)
  6592. patient_id, _ := c.GetInt64("patient_id", 0)
  6593. admin := c.GetAdminUserInfo()
  6594. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6595. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6596. c.ServeSuccessJSON(map[string]interface{}{
  6597. "info": info,
  6598. "case_history": case_history,
  6599. })
  6600. }
  6601. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6602. template_name := c.GetString("template_name")
  6603. template_remark := c.GetString("template_remark")
  6604. doctor := c.GetAdminUserInfo().AdminUser.Id
  6605. diagnostic := c.GetString("diagnostic")
  6606. chief_conplaint := c.GetString("chief_conplain")
  6607. history_of_present_illness := c.GetString("history_of_present_illness")
  6608. past_history := c.GetString("past_history")
  6609. personal_history := c.GetString("personal_history")
  6610. family_history := c.GetString("family_history")
  6611. user_name := c.GetString("user_name")
  6612. doctor_advice := c.GetString("doctor_advice")
  6613. remark := c.GetString("remark")
  6614. //record_date := c.GetString("record_date")
  6615. //fmt.Println("record_date--------",record_date)
  6616. //timeLayout := "2006-01-02"
  6617. //loc, _ := time.LoadLocation("Local")
  6618. //
  6619. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6620. //if err != nil {
  6621. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6622. // return
  6623. //}
  6624. //recordDateTime := theTime.Unix()
  6625. ctime := time.Now().Unix()
  6626. template := models.HisCaseHistoryTemplate{
  6627. HistoryOfPresentIllness: history_of_present_illness,
  6628. PastHistory: past_history,
  6629. ChiefConplaint: chief_conplaint,
  6630. PersonalHistory: personal_history,
  6631. FamilyHistory: family_history,
  6632. Diagnostic: diagnostic,
  6633. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6634. Status: 1,
  6635. Ctime: ctime,
  6636. Mtime: ctime,
  6637. RecordDate: time.Now().Unix(),
  6638. TemplateName: template_name,
  6639. TemplateRemark: template_remark,
  6640. Creator: doctor,
  6641. Modifier: doctor,
  6642. UserName: user_name,
  6643. DoctorAdvice: doctor_advice,
  6644. Remark: remark,
  6645. }
  6646. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6647. if err == nil {
  6648. c.ServeSuccessJSON(map[string]interface{}{
  6649. "msg": "保存成功",
  6650. })
  6651. } else {
  6652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6653. return
  6654. }
  6655. }
  6656. func (c *HisApiController) GetCaseHistoryTemplate() {
  6657. timeLayout := "2006-01-02"
  6658. loc, _ := time.LoadLocation("Local")
  6659. keyword := c.GetString("keyword")
  6660. start_time := c.GetString("start_time")
  6661. end_time := c.GetString("end_time")
  6662. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6663. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6664. admin := c.GetAdminUserInfo()
  6665. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6666. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6667. c.ServeSuccessJSON(map[string]interface{}{
  6668. "template": template,
  6669. //"history": history,
  6670. })
  6671. }
  6672. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6673. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6674. utils.ErrorLog("drug_name")
  6675. return enums.ErrorCodeParamWrong
  6676. }
  6677. adviceName, _ := json["drug_name"].(string)
  6678. if len(adviceName) == 0 {
  6679. utils.ErrorLog("len(advice_name) == 0")
  6680. return enums.ErrorCodeParamWrong
  6681. }
  6682. advice.AdviceName = adviceName
  6683. adviceDesc, _ := json["advice_desc"].(string)
  6684. advice.AdviceDesc = adviceDesc
  6685. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6686. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6687. advice.DrugSpec = drugSpec
  6688. }
  6689. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6690. remark, _ := json["remark"].(string)
  6691. advice.Remark = remark
  6692. }
  6693. if json["id"] == nil {
  6694. advice.DrugId = 0
  6695. } else {
  6696. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6697. drug_id := int64(json["id"].(float64))
  6698. advice.DrugId = drug_id
  6699. }
  6700. }
  6701. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6702. advice_id := int64(json["advice_id"].(float64))
  6703. advice.ID = advice_id
  6704. if advice.ID > 0 {
  6705. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6706. if err == nil {
  6707. if hisAdvice.ID > 0 {
  6708. advice.ExecutionTime = hisAdvice.ExecutionTime
  6709. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6710. advice.ExecutionState = hisAdvice.ExecutionState
  6711. advice.CheckTime = hisAdvice.CheckTime
  6712. advice.Checker = hisAdvice.Checker
  6713. advice.CheckState = hisAdvice.CheckState
  6714. advice.StartTime = hisAdvice.StartTime
  6715. advice.FeedetlSn = hisAdvice.FeedetlSn
  6716. }
  6717. }
  6718. }
  6719. }
  6720. //
  6721. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6722. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6723. // advice.ExecutionTime = execution_time
  6724. //}
  6725. //
  6726. //
  6727. //
  6728. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6729. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6730. // advice.ExecutionStaff = execution_staff
  6731. //}
  6732. //
  6733. //
  6734. //
  6735. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6736. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6737. // advice.ExecutionState = execution_state
  6738. //}
  6739. //
  6740. //
  6741. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6742. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6743. // advice.CheckTime = check_time
  6744. //}
  6745. //
  6746. //
  6747. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6748. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6749. // advice.CheckState = check_state
  6750. //}
  6751. //
  6752. //
  6753. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6754. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6755. // advice.Checker = checker
  6756. //}
  6757. //
  6758. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6759. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6760. // advice.StartTime = start_time
  6761. //}
  6762. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6763. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6764. advice.IsSelfDrug = is_self_drug
  6765. }
  6766. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6767. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6768. drug_way_count, _ := json["drug_way_count"].(string)
  6769. advice.DrugWayCount = drug_way_count
  6770. }
  6771. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6772. drugSpecUnit, _ := json["min_unit"].(string)
  6773. advice.DrugSpecUnit = drugSpecUnit
  6774. }
  6775. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6776. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6777. advice.SingleDose = singleDose
  6778. }
  6779. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6780. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6781. advice.SingleDoseUnit = singleDoseUnit
  6782. }
  6783. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6784. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6785. advice.PrescribingNumber = prescribingNumber
  6786. }
  6787. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6788. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6789. advice.PrescribingNumberUnit = prescribingNumberUnit
  6790. }
  6791. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6792. deliveryWay, _ := json["delivery_way"].(string)
  6793. advice.DeliveryWay = deliveryWay
  6794. }
  6795. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6796. executionFrequency, _ := json["execution_frequency"].(string)
  6797. advice.ExecutionFrequency = executionFrequency
  6798. }
  6799. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6800. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6801. advice.Price = price
  6802. }
  6803. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6804. med_list_codg, _ := json["medical_insurance_number"].(string)
  6805. advice.MedListCodg = med_list_codg
  6806. }
  6807. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6808. day := int64(json["day"].(float64))
  6809. advice.Day = day
  6810. }
  6811. return 0
  6812. }
  6813. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6814. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6815. id := int64(json["id"].(float64))
  6816. project.ID = id
  6817. historyProject, _ := service.GetHisProjectByID(id)
  6818. project.FeedetlSn = historyProject.FeedetlSn
  6819. }
  6820. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6821. project_id := int64(json["project_id"].(float64))
  6822. project.ProjectId = project_id
  6823. }
  6824. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6825. // price := int64(json["price"].(float64))
  6826. // formatInt_price := strconv.FormatInt(price, 10)
  6827. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6828. // project.Price = float_price
  6829. // }
  6830. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6831. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6832. project.Price = price
  6833. }
  6834. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6835. total, _ := json["total"].(string)
  6836. project.Count = total
  6837. }
  6838. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6839. medical_code, _ := json["medical_code"].(string)
  6840. project.MedListCodg = medical_code
  6841. }
  6842. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6843. single_dose, _ := json["single_dose"].(string)
  6844. project.SingleDose = single_dose
  6845. }
  6846. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6847. delivery_way, _ := json["delivery_way"].(string)
  6848. project.DeliveryWay = delivery_way
  6849. }
  6850. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6851. execution_frequency, _ := json["execution_frequency"].(string)
  6852. project.ExecutionFrequency = execution_frequency
  6853. }
  6854. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6855. remark, _ := json["remark"].(string)
  6856. project.Remark = remark
  6857. }
  6858. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6859. day, _ := json["number_days"].(string)
  6860. project.Day = day
  6861. }
  6862. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6863. unit, _ := json["unit"].(string)
  6864. project.Unit = unit
  6865. }
  6866. return 0
  6867. }
  6868. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6869. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6870. id := int64(json["id"].(float64))
  6871. historyAddtions, _ := service.GetHisAdditionByID(id)
  6872. additionalCharge.ID = id
  6873. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6874. }
  6875. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6876. item_id := int64(json["item_id"].(float64))
  6877. additionalCharge.ItemId = item_id
  6878. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6879. if config.ID > 0 {
  6880. if len(config.Code) > 0 {
  6881. additionalCharge.MedListCodg = config.Code
  6882. }
  6883. }
  6884. }
  6885. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6886. // price := int64(json["price"].(float64))
  6887. // formatInt_price := strconv.FormatInt(price, 10)
  6888. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6889. // additionalCharge.Price = float_price
  6890. // }
  6891. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6892. // price := int64(json["price"].(float64))
  6893. // formatInt_price := strconv.FormatInt(price, 10)
  6894. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6895. // additionalCharge.Price = float_price
  6896. //}
  6897. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6898. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6899. additionalCharge.Price = price
  6900. }
  6901. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6902. count, _ := json["count"].(string)
  6903. counts, _ := strconv.ParseInt(count, 10, 64)
  6904. additionalCharge.Count = counts
  6905. }
  6906. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6907. item_name, _ := json["item_name"].(string)
  6908. additionalCharge.ItemName = item_name
  6909. }
  6910. return 0
  6911. }
  6912. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6913. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6914. utils.ErrorLog("drug_name")
  6915. return enums.ErrorCodeParamWrong
  6916. }
  6917. adviceName, _ := json["drug_name"].(string)
  6918. if len(adviceName) == 0 {
  6919. utils.ErrorLog("len(advice_name) == 0")
  6920. return enums.ErrorCodeParamWrong
  6921. }
  6922. advice.AdviceName = adviceName
  6923. adviceDesc, _ := json["advice_desc"].(string)
  6924. advice.AdviceDesc = adviceDesc
  6925. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6926. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6927. advice.DrugSpec = drugSpec
  6928. }
  6929. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6930. remark, _ := json["remark"].(string)
  6931. advice.Remark = remark
  6932. }
  6933. if json["id"] == nil {
  6934. advice.DrugId = 0
  6935. } else {
  6936. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6937. drug_id := int64(json["id"].(float64))
  6938. advice.DrugId = drug_id
  6939. }
  6940. }
  6941. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6942. groupno := int64(json["groupno"].(float64))
  6943. advice.Groupno = groupno
  6944. }
  6945. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6946. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6947. advice.IsSelfDrug = is_self_drug
  6948. }
  6949. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6950. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6951. drug_way_count, _ := json["drug_way_count"].(string)
  6952. advice.DrugWayCount = drug_way_count
  6953. }
  6954. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6955. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6956. advice.HospApprFlag = hosp_appr_flag
  6957. }
  6958. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6959. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6960. advice.PrescribingNumber = prescribingNumber
  6961. }
  6962. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6963. // frequency_type := int64(json["frequency_type"].(float64))
  6964. // advice.FrequencyType = frequency_type
  6965. //}
  6966. //
  6967. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6968. // day_count := int64(json["day_count"].(float64))
  6969. // advice.DayCount = day_count
  6970. //}
  6971. //
  6972. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6973. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6974. // week_day, _ := json["week_day"].(string)
  6975. // advice.WeekDay = week_day
  6976. //}
  6977. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6978. drugSpecUnit, _ := json["min_unit"].(string)
  6979. advice.DrugSpecUnit = drugSpecUnit
  6980. }
  6981. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6982. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6983. advice.SingleDose = singleDose
  6984. }
  6985. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6986. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6987. advice.SingleDoseUnit = singleDoseUnit
  6988. }
  6989. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6990. deliveryWay, _ := json["delivery_way"].(string)
  6991. advice.DeliveryWay = deliveryWay
  6992. }
  6993. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6994. executionFrequency, _ := json["execution_frequency"].(string)
  6995. advice.ExecutionFrequency = executionFrequency
  6996. }
  6997. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6998. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6999. advice.Price = price
  7000. }
  7001. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7002. med_list_codg, _ := json["medical_insurance_number"].(string)
  7003. advice.MedListCodg = med_list_codg
  7004. }
  7005. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7006. day := int64(json["day"].(float64))
  7007. advice.Day = day
  7008. }
  7009. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7010. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7011. advice.PrescribingNumberUnit = prescribingNumberUnit
  7012. }
  7013. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7014. advice_id := int64(json["advice_id"].(float64))
  7015. advice.ID = advice_id
  7016. if advice.ID > 0 {
  7017. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7018. if err == nil {
  7019. if hisAdvice.ID > 0 {
  7020. advice.ExecutionTime = hisAdvice.ExecutionTime
  7021. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7022. advice.ExecutionState = hisAdvice.ExecutionState
  7023. advice.CheckTime = hisAdvice.CheckTime
  7024. advice.Checker = hisAdvice.Checker
  7025. advice.CheckState = hisAdvice.CheckState
  7026. advice.StartTime = hisAdvice.StartTime
  7027. advice.HospApprFlag = hisAdvice.HospApprFlag
  7028. advice.IsMedicine = hisAdvice.IsMedicine
  7029. if hisAdvice.UserOrgId == 10028 {
  7030. 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 {
  7031. advice.ExecutionTime = 0
  7032. advice.ExecutionStaff = 0
  7033. advice.ExecutionState = 2
  7034. advice.CheckTime = 0
  7035. advice.Checker = 0
  7036. advice.CheckState = 2
  7037. }
  7038. } else {
  7039. 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 {
  7040. advice.ExecutionTime = 0
  7041. advice.ExecutionStaff = 0
  7042. advice.ExecutionState = 2
  7043. advice.CheckTime = 0
  7044. advice.Checker = 0
  7045. advice.CheckState = 2
  7046. advice.UpdatedTime = time.Now().Unix()
  7047. }
  7048. }
  7049. //advice.Groupno = hisAdvice.Groupno
  7050. }
  7051. }
  7052. }
  7053. }
  7054. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7055. //
  7056. //if drugStockConfig.IsOpen == 1 {
  7057. //
  7058. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7059. // if advice.ID == 0 { //医嘱不存在
  7060. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7061. // drug.Total = drug.Total - advice.PrescribingNumber
  7062. // service.UpdateBaseDrugLib(&drug)
  7063. //
  7064. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7065. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7066. // drug.Total = drug.Total - num
  7067. // service.UpdateBaseDrugLib(&drug)
  7068. // }
  7069. //
  7070. // } else if advice.ID > 0 { //医嘱存在
  7071. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7072. // var num float64
  7073. //
  7074. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7075. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7076. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7077. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7078. // drug.Total = drug.Total + num
  7079. // service.UpdateBaseDrugLib(&drug)
  7080. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7081. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7082. // drug.Total = drug.Total - num
  7083. // service.UpdateBaseDrugLib(&drug)
  7084. // }
  7085. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7086. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7087. // if num2 > advice.PrescribingNumber {
  7088. // num = num2 - advice.PrescribingNumber
  7089. // drug.Total = drug.Total + num
  7090. // service.UpdateBaseDrugLib(&drug)
  7091. // } else if num2 < advice.PrescribingNumber {
  7092. // num = advice.PrescribingNumber - num2
  7093. // drug.Total = drug.Total - num
  7094. // service.UpdateBaseDrugLib(&drug)
  7095. // }
  7096. //
  7097. // }
  7098. //
  7099. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7100. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7101. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7102. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7103. // if num1 > num2 {
  7104. // num = num1 - num2
  7105. // drug.Total = drug.Total + num
  7106. // service.UpdateBaseDrugLib(&drug)
  7107. // } else if num1 < num2 {
  7108. // num = num2 - num1
  7109. // drug.Total = drug.Total - num
  7110. // service.UpdateBaseDrugLib(&drug)
  7111. // }
  7112. //
  7113. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7114. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7115. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7116. // if hisAdvice.PrescribingNumber > num2 {
  7117. // num = hisAdvice.PrescribingNumber - num2
  7118. // drug.Total = drug.Total + num
  7119. // service.UpdateBaseDrugLib(&drug)
  7120. // } else if num2 < advice.PrescribingNumber {
  7121. // num = num2 - hisAdvice.PrescribingNumber
  7122. // drug.Total = drug.Total - num
  7123. // service.UpdateBaseDrugLib(&drug)
  7124. // }
  7125. //
  7126. // }
  7127. // }
  7128. // }
  7129. //}
  7130. //
  7131. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7132. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7133. // advice.ExecutionTime = execution_time
  7134. //}
  7135. //
  7136. //
  7137. //
  7138. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7139. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7140. // advice.ExecutionStaff = execution_staff
  7141. //}
  7142. //
  7143. //
  7144. //
  7145. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7146. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7147. // advice.ExecutionState = execution_state
  7148. //}
  7149. //
  7150. //
  7151. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7152. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7153. // advice.CheckTime = check_time
  7154. //}
  7155. //
  7156. //
  7157. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7158. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7159. // advice.CheckState = check_state
  7160. //}
  7161. //
  7162. //
  7163. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7164. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7165. // advice.Checker = checker
  7166. //}
  7167. //
  7168. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7169. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7170. // advice.StartTime = start_time
  7171. //}
  7172. return 0
  7173. }
  7174. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7175. project.ExecutionStaff = 0
  7176. project.ExecutionState = 2
  7177. project.ExecutionTime = 0
  7178. project.Checker = 0
  7179. project.CheckState = 2
  7180. project.CheckTime = 0
  7181. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7182. id := int64(json["id"].(float64))
  7183. project.ID = id
  7184. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7185. project.ExecutionStaff = temp_project.ExecutionStaff
  7186. project.ExecutionState = temp_project.ExecutionState
  7187. project.ExecutionTime = temp_project.ExecutionTime
  7188. project.Checker = temp_project.Checker
  7189. project.CheckState = temp_project.CheckState
  7190. project.CheckTime = temp_project.CheckTime
  7191. project.TeamId = temp_project.TeamId
  7192. }
  7193. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7194. types := int64(json["type"].(float64))
  7195. project.Type = types
  7196. }
  7197. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7198. project_id := int64(json["project_id"].(float64))
  7199. project.ProjectId = project_id
  7200. }
  7201. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7202. team_id := int64(json["team_id"].(float64))
  7203. project.TeamId = team_id
  7204. }
  7205. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7206. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7207. project.Price = price
  7208. }
  7209. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7210. total, _ := json["total"].(string)
  7211. //totals, _ := strconv.ParseInt(total, 10, 64)
  7212. project.Count = total
  7213. }
  7214. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7215. medical_code, _ := json["medical_code"].(string)
  7216. project.MedListCodg = medical_code
  7217. }
  7218. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7219. single_dose, _ := json["single_dose"].(string)
  7220. project.SingleDose = single_dose
  7221. }
  7222. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7223. delivery_way, _ := json["delivery_way"].(string)
  7224. project.DeliveryWay = delivery_way
  7225. }
  7226. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7227. execution_frequency, _ := json["execution_frequency"].(string)
  7228. project.ExecutionFrequency = execution_frequency
  7229. }
  7230. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7231. remark, _ := json["remark"].(string)
  7232. project.Remark = remark
  7233. }
  7234. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7235. day, _ := json["number_days"].(string)
  7236. project.Day = day
  7237. }
  7238. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7239. unit, _ := json["unit"].(string)
  7240. project.Unit = unit
  7241. }
  7242. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7243. // frequency_type := int64(json["frequency_type"].(float64))
  7244. // project.FrequencyType = frequency_type
  7245. //}
  7246. //
  7247. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7248. // day_count := int64(json["day_count"].(float64))
  7249. // project.DayCount = day_count
  7250. //}
  7251. //
  7252. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7253. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7254. // week_day, _ := json["week_day"].(string)
  7255. // project.WeekDay = week_day
  7256. //}
  7257. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7258. //
  7259. //if project.ID == 0 {
  7260. // if stockConfig.IsOpen == 1 {
  7261. // if project.Type == 3 {
  7262. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7263. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7264. // good.Total = good.Total - f_count
  7265. // service.UpdateGoodInfo(&good)
  7266. // }
  7267. // }
  7268. //
  7269. //} else {
  7270. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7271. //
  7272. // if stockConfig.IsOpen == 1 {
  7273. // if project.Type == 3 {
  7274. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7275. // if project.Count < temp_project.Count {
  7276. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7277. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7278. //
  7279. // other_count := f_count_two - f_count_one
  7280. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7281. // good.Total = good.Total + other_count_two
  7282. // service.UpdateGoodInfo(&good)
  7283. // } else if project.Count > temp_project.Count {
  7284. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7285. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7286. //
  7287. // other_count := f_count_one - f_count_two
  7288. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7289. // good.Total = good.Total - other_count_two
  7290. // service.UpdateGoodInfo(&good)
  7291. // }
  7292. //
  7293. // }
  7294. // }
  7295. //
  7296. //}
  7297. return 0
  7298. }
  7299. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7300. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7301. utils.ErrorLog("drug_name")
  7302. return enums.ErrorCodeParamWrong
  7303. }
  7304. adviceName, _ := json["drug_name"].(string)
  7305. if len(adviceName) == 0 {
  7306. utils.ErrorLog("len(advice_name) == 0")
  7307. return enums.ErrorCodeParamWrong
  7308. }
  7309. advice.AdviceName = adviceName
  7310. adviceDesc, _ := json["advice_desc"].(string)
  7311. advice.AdviceDesc = adviceDesc
  7312. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7313. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7314. advice.DrugSpec = drugSpec
  7315. }
  7316. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7317. remark, _ := json["remark"].(string)
  7318. advice.Remark = remark
  7319. }
  7320. if json["id"] == nil {
  7321. advice.DrugId = 0
  7322. } else {
  7323. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7324. drug_id := int64(json["id"].(float64))
  7325. advice.DrugId = drug_id
  7326. }
  7327. }
  7328. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7329. groupno := int64(json["groupno"].(float64))
  7330. advice.Groupno = groupno
  7331. }
  7332. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7333. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7334. advice.IsSelfDrug = is_self_drug
  7335. }
  7336. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7337. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7338. drug_way_count, _ := json["drug_way_count"].(string)
  7339. advice.DrugWayCount = drug_way_count
  7340. }
  7341. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7342. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7343. advice.HospApprFlag = hosp_appr_flag
  7344. }
  7345. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7346. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7347. advice.PrescribingNumber = prescribingNumber
  7348. }
  7349. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7350. // frequency_type := int64(json["frequency_type"].(float64))
  7351. // advice.FrequencyType = frequency_type
  7352. //}
  7353. //
  7354. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7355. // day_count := int64(json["day_count"].(float64))
  7356. // advice.DayCount = day_count
  7357. //}
  7358. //
  7359. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7360. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7361. // week_day, _ := json["week_day"].(string)
  7362. // advice.WeekDay = week_day
  7363. //}
  7364. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7365. drugSpecUnit, _ := json["min_unit"].(string)
  7366. advice.DrugSpecUnit = drugSpecUnit
  7367. }
  7368. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7369. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7370. advice.SingleDose = singleDose
  7371. }
  7372. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7373. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7374. advice.SingleDoseUnit = singleDoseUnit
  7375. }
  7376. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7377. deliveryWay, _ := json["delivery_way"].(string)
  7378. advice.DeliveryWay = deliveryWay
  7379. }
  7380. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7381. executionFrequency, _ := json["execution_frequency"].(string)
  7382. advice.ExecutionFrequency = executionFrequency
  7383. }
  7384. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7385. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7386. advice.Price = price
  7387. }
  7388. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7389. med_list_codg, _ := json["medical_insurance_number"].(string)
  7390. advice.MedListCodg = med_list_codg
  7391. }
  7392. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7393. day := int64(json["day"].(float64))
  7394. advice.Day = day
  7395. }
  7396. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7397. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7398. advice.PrescribingNumberUnit = prescribingNumberUnit
  7399. }
  7400. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7401. advice_id := int64(json["advice_id"].(float64))
  7402. advice.ID = advice_id
  7403. if advice.ID > 0 {
  7404. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7405. if err == nil {
  7406. if hisAdvice.ID > 0 {
  7407. advice.ExecutionTime = hisAdvice.ExecutionTime
  7408. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7409. advice.ExecutionState = hisAdvice.ExecutionState
  7410. advice.CheckTime = hisAdvice.CheckTime
  7411. advice.Checker = hisAdvice.Checker
  7412. advice.CheckState = hisAdvice.CheckState
  7413. advice.StartTime = hisAdvice.StartTime
  7414. advice.HospApprFlag = hisAdvice.HospApprFlag
  7415. advice.IsMedicine = hisAdvice.IsMedicine
  7416. if hisAdvice.UserOrgId == 10028 {
  7417. 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 {
  7418. advice.ExecutionTime = 0
  7419. advice.ExecutionStaff = 0
  7420. advice.ExecutionState = 2
  7421. advice.CheckTime = 0
  7422. advice.Checker = 0
  7423. advice.CheckState = 2
  7424. }
  7425. } else {
  7426. 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 {
  7427. advice.ExecutionTime = 0
  7428. advice.ExecutionStaff = 0
  7429. advice.ExecutionState = 2
  7430. advice.CheckTime = 0
  7431. advice.Checker = 0
  7432. advice.CheckState = 2
  7433. //advice.UpdatedTime = time.Now().Unix()
  7434. advice.CreatedTime = hisAdvice.CreatedTime
  7435. advice.UpdatedTime = time.Now().Unix()
  7436. } else {
  7437. advice.CreatedTime = hisAdvice.CreatedTime
  7438. advice.UpdatedTime = hisAdvice.UpdatedTime
  7439. }
  7440. }
  7441. //advice.Groupno = hisAdvice.Groupno
  7442. } else {
  7443. advice.IsMedicine = 0
  7444. ctime := time.Now().Unix()
  7445. advice.CreatedTime = ctime
  7446. advice.UpdatedTime = ctime
  7447. }
  7448. }
  7449. } else {
  7450. advice.IsMedicine = 0
  7451. ctime := time.Now().Unix()
  7452. advice.CreatedTime = ctime
  7453. advice.UpdatedTime = ctime
  7454. }
  7455. }
  7456. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7457. //
  7458. //if drugStockConfig.IsOpen == 1 {
  7459. //
  7460. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7461. // if advice.ID == 0 { //医嘱不存在
  7462. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7463. // drug.Total = drug.Total - advice.PrescribingNumber
  7464. // service.UpdateBaseDrugLib(&drug)
  7465. //
  7466. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7467. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7468. // drug.Total = drug.Total - num
  7469. // service.UpdateBaseDrugLib(&drug)
  7470. // }
  7471. //
  7472. // } else if advice.ID > 0 { //医嘱存在
  7473. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7474. // var num float64
  7475. //
  7476. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7477. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7478. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7479. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7480. // drug.Total = drug.Total + num
  7481. // service.UpdateBaseDrugLib(&drug)
  7482. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7483. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7484. // drug.Total = drug.Total - num
  7485. // service.UpdateBaseDrugLib(&drug)
  7486. // }
  7487. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7488. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7489. // if num2 > advice.PrescribingNumber {
  7490. // num = num2 - advice.PrescribingNumber
  7491. // drug.Total = drug.Total + num
  7492. // service.UpdateBaseDrugLib(&drug)
  7493. // } else if num2 < advice.PrescribingNumber {
  7494. // num = advice.PrescribingNumber - num2
  7495. // drug.Total = drug.Total - num
  7496. // service.UpdateBaseDrugLib(&drug)
  7497. // }
  7498. //
  7499. // }
  7500. //
  7501. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7502. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7503. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7504. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7505. // if num1 > num2 {
  7506. // num = num1 - num2
  7507. // drug.Total = drug.Total + num
  7508. // service.UpdateBaseDrugLib(&drug)
  7509. // } else if num1 < num2 {
  7510. // num = num2 - num1
  7511. // drug.Total = drug.Total - num
  7512. // service.UpdateBaseDrugLib(&drug)
  7513. // }
  7514. //
  7515. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7516. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7517. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7518. // if hisAdvice.PrescribingNumber > num2 {
  7519. // num = hisAdvice.PrescribingNumber - num2
  7520. // drug.Total = drug.Total + num
  7521. // service.UpdateBaseDrugLib(&drug)
  7522. // } else if num2 < advice.PrescribingNumber {
  7523. // num = num2 - hisAdvice.PrescribingNumber
  7524. // drug.Total = drug.Total - num
  7525. // service.UpdateBaseDrugLib(&drug)
  7526. // }
  7527. //
  7528. // }
  7529. // }
  7530. // }
  7531. //}
  7532. //
  7533. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7534. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7535. // advice.ExecutionTime = execution_time
  7536. //}
  7537. //
  7538. //
  7539. //
  7540. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7541. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7542. // advice.ExecutionStaff = execution_staff
  7543. //}
  7544. //
  7545. //
  7546. //
  7547. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7548. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7549. // advice.ExecutionState = execution_state
  7550. //}
  7551. //
  7552. //
  7553. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7554. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7555. // advice.CheckTime = check_time
  7556. //}
  7557. //
  7558. //
  7559. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7560. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7561. // advice.CheckState = check_state
  7562. //}
  7563. //
  7564. //
  7565. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7566. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7567. // advice.Checker = checker
  7568. //}
  7569. //
  7570. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7571. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7572. // advice.StartTime = start_time
  7573. //}
  7574. return 0
  7575. }
  7576. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7577. project.ExecutionStaff = 0
  7578. project.ExecutionState = 2
  7579. project.ExecutionTime = 0
  7580. project.Checker = 0
  7581. project.CheckState = 2
  7582. project.CheckTime = 0
  7583. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7584. id := int64(json["id"].(float64))
  7585. project.ID = id
  7586. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7587. project.ExecutionStaff = temp_project.ExecutionStaff
  7588. project.ExecutionState = temp_project.ExecutionState
  7589. project.ExecutionTime = temp_project.ExecutionTime
  7590. project.Checker = temp_project.Checker
  7591. project.CheckState = temp_project.CheckState
  7592. project.CheckTime = temp_project.CheckTime
  7593. project.TeamId = temp_project.TeamId
  7594. }
  7595. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7596. types := int64(json["type"].(float64))
  7597. project.Type = types
  7598. }
  7599. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7600. project_id := int64(json["project_id"].(float64))
  7601. project.ProjectId = project_id
  7602. }
  7603. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7604. team_id := int64(json["team_id"].(float64))
  7605. project.TeamId = team_id
  7606. }
  7607. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7608. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7609. project.Price = price
  7610. }
  7611. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7612. total, _ := json["total"].(string)
  7613. //totals, _ := strconv.ParseInt(total, 10, 64)
  7614. project.Count = total
  7615. }
  7616. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7617. medical_code, _ := json["medical_code"].(string)
  7618. project.MedListCodg = medical_code
  7619. }
  7620. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7621. single_dose, _ := json["single_dose"].(string)
  7622. project.SingleDose = single_dose
  7623. }
  7624. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7625. delivery_way, _ := json["delivery_way"].(string)
  7626. project.DeliveryWay = delivery_way
  7627. }
  7628. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7629. execution_frequency, _ := json["execution_frequency"].(string)
  7630. project.ExecutionFrequency = execution_frequency
  7631. }
  7632. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7633. remark, _ := json["remark"].(string)
  7634. project.Remark = remark
  7635. }
  7636. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7637. day, _ := json["number_days"].(string)
  7638. project.Day = day
  7639. }
  7640. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7641. unit, _ := json["unit"].(string)
  7642. project.Unit = unit
  7643. }
  7644. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7645. // frequency_type := int64(json["frequency_type"].(float64))
  7646. // project.FrequencyType = frequency_type
  7647. //}
  7648. //
  7649. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7650. // day_count := int64(json["day_count"].(float64))
  7651. // project.DayCount = day_count
  7652. //}
  7653. //
  7654. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7655. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7656. // week_day, _ := json["week_day"].(string)
  7657. // project.WeekDay = week_day
  7658. //}
  7659. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7660. //
  7661. //if project.ID == 0 {
  7662. // if stockConfig.IsOpen == 1 {
  7663. // if project.Type == 3 {
  7664. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7665. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7666. // good.Total = good.Total - f_count
  7667. // service.UpdateGoodInfo(&good)
  7668. // }
  7669. // }
  7670. //
  7671. //} else {
  7672. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7673. //
  7674. // if stockConfig.IsOpen == 1 {
  7675. // if project.Type == 3 {
  7676. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7677. // if project.Count < temp_project.Count {
  7678. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7679. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7680. //
  7681. // other_count := f_count_two - f_count_one
  7682. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7683. // good.Total = good.Total + other_count_two
  7684. // service.UpdateGoodInfo(&good)
  7685. // } else if project.Count > temp_project.Count {
  7686. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7687. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7688. //
  7689. // other_count := f_count_one - f_count_two
  7690. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7691. // good.Total = good.Total - other_count_two
  7692. // service.UpdateGoodInfo(&good)
  7693. // }
  7694. //
  7695. // }
  7696. // }
  7697. //
  7698. //}
  7699. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7700. id := int64(json["id"].(float64))
  7701. if id > 0 {
  7702. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7703. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7704. fmt.Println("666666")
  7705. project.Mtime = time.Now().Unix()
  7706. project.Ctime = temp_project.Ctime
  7707. } else {
  7708. project.Mtime = temp_project.Mtime
  7709. project.Ctime = temp_project.Ctime
  7710. }
  7711. } else {
  7712. ctime := time.Now().Unix()
  7713. project.Mtime = ctime
  7714. project.Ctime = ctime
  7715. }
  7716. }
  7717. return 0
  7718. }
  7719. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7720. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7721. id := int64(json["id"].(float64))
  7722. additionalCharge.ID = id
  7723. }
  7724. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7725. item_id := int64(json["item_id"].(float64))
  7726. additionalCharge.ItemId = item_id
  7727. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7728. if config.ID > 0 {
  7729. if len(config.Code) > 0 {
  7730. additionalCharge.MedListCodg = config.Code
  7731. }
  7732. }
  7733. }
  7734. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7735. // price := int64(json["price"].(float64))
  7736. // formatInt_price := strconv.FormatInt(price, 10)
  7737. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7738. // additionalCharge.Price = float_price
  7739. // }
  7740. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7741. // price := int64(json["price"].(float64))
  7742. // formatInt_price := strconv.FormatInt(price, 10)
  7743. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7744. // additionalCharge.Price = float_price
  7745. //}
  7746. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7747. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7748. additionalCharge.Price = price
  7749. }
  7750. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7751. count, _ := json["count"].(string)
  7752. counts, _ := strconv.ParseInt(count, 10, 64)
  7753. additionalCharge.Count = counts
  7754. }
  7755. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7756. item_name, _ := json["item_name"].(string)
  7757. additionalCharge.ItemName = item_name
  7758. }
  7759. return 0
  7760. }
  7761. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7762. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7763. utils.ErrorLog("drug_name")
  7764. return enums.ErrorCodeParamWrong
  7765. }
  7766. adviceName, _ := json["drug_name"].(string)
  7767. if len(adviceName) == 0 {
  7768. utils.ErrorLog("len(advice_name) == 0")
  7769. return enums.ErrorCodeParamWrong
  7770. }
  7771. advice.AdviceName = adviceName
  7772. adviceDesc, _ := json["advice_desc"].(string)
  7773. advice.AdviceDesc = adviceDesc
  7774. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7775. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7776. advice.DrugSpec = drugSpec
  7777. }
  7778. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7779. remark, _ := json["remark"].(string)
  7780. advice.Remark = remark
  7781. }
  7782. if json["id"] == nil {
  7783. advice.DrugId = 0
  7784. } else {
  7785. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7786. drug_id := int64(json["id"].(float64))
  7787. advice.DrugId = drug_id
  7788. }
  7789. }
  7790. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7791. groupno := int64(json["groupno"].(float64))
  7792. advice.Groupno = groupno
  7793. }
  7794. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7795. drugSpecUnit, _ := json["min_unit"].(string)
  7796. advice.DrugSpecUnit = drugSpecUnit
  7797. }
  7798. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7799. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7800. advice.SingleDose = singleDose
  7801. }
  7802. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7803. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7804. advice.SingleDoseUnit = singleDoseUnit
  7805. }
  7806. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7807. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7808. advice.PrescribingNumber = prescribingNumber
  7809. }
  7810. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7811. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7812. advice.PrescribingNumberUnit = prescribingNumberUnit
  7813. }
  7814. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7815. deliveryWay, _ := json["delivery_way"].(string)
  7816. advice.DeliveryWay = deliveryWay
  7817. }
  7818. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7819. executionFrequency, _ := json["execution_frequency"].(string)
  7820. advice.ExecutionFrequency = executionFrequency
  7821. }
  7822. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7823. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7824. advice.Price = price
  7825. }
  7826. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7827. med_list_codg, _ := json["medical_insurance_number"].(string)
  7828. advice.MedListCodg = med_list_codg
  7829. }
  7830. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7831. day := int64(json["day"].(float64))
  7832. advice.Day = day
  7833. }
  7834. advice.FrequencyType = 1
  7835. return 0
  7836. }
  7837. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7838. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7839. types := int64(json["type"].(float64))
  7840. project.Type = types
  7841. }
  7842. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7843. project_id := int64(json["project_id"].(float64))
  7844. project.ProjectId = project_id
  7845. }
  7846. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7847. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7848. project.Price = price
  7849. }
  7850. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7851. total, _ := json["total"].(string)
  7852. //totals, _ := strconv.ParseInt(total, 10, 64)
  7853. project.Count = total
  7854. }
  7855. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7856. medical_code, _ := json["medical_code"].(string)
  7857. project.MedListCodg = medical_code
  7858. }
  7859. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7860. single_dose, _ := json["single_dose"].(string)
  7861. project.SingleDose = single_dose
  7862. }
  7863. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7864. delivery_way, _ := json["delivery_way"].(string)
  7865. project.DeliveryWay = delivery_way
  7866. }
  7867. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7868. execution_frequency, _ := json["execution_frequency"].(string)
  7869. project.ExecutionFrequency = execution_frequency
  7870. }
  7871. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7872. remark, _ := json["remark"].(string)
  7873. project.Remark = remark
  7874. }
  7875. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7876. day, _ := json["number_days"].(string)
  7877. project.Day = day
  7878. }
  7879. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7880. unit, _ := json["unit"].(string)
  7881. project.Unit = unit
  7882. }
  7883. project.FrequencyType = 1
  7884. return 0
  7885. }
  7886. func (c *HisApiController) GetHisOrderListTwo() {
  7887. start_time := c.GetString("start_time")
  7888. end_time := c.GetString("end_time")
  7889. timeLayout := "2006-01-02"
  7890. loc, _ := time.LoadLocation("Local")
  7891. var startTime int64
  7892. if len(start_time) > 0 {
  7893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7894. if err != nil {
  7895. //fmt.Println(err)
  7896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7897. return
  7898. }
  7899. startTime = theTime.Unix()
  7900. }
  7901. var endTime int64
  7902. if len(end_time) > 0 {
  7903. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7904. if err != nil {
  7905. utils.ErrorLog(err.Error())
  7906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7907. return
  7908. }
  7909. endTime = theTime.Unix()
  7910. }
  7911. adminUser := c.GetAdminUserInfo()
  7912. org_id := adminUser.CurrentOrgId
  7913. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7914. if err == nil {
  7915. c.ServeSuccessJSON(map[string]interface{}{
  7916. "order2": order,
  7917. })
  7918. } else {
  7919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7920. return
  7921. }
  7922. }
  7923. func (c *HisApiController) GetHisOrderList() {
  7924. page, _ := c.GetInt64("page", -1)
  7925. limit, _ := c.GetInt64("limit", -1)
  7926. start_time := c.GetString("start_time")
  7927. end_time := c.GetString("end_time")
  7928. types, _ := c.GetInt64("type", 0)
  7929. keywords := c.GetString("keywords")
  7930. p_type, _ := c.GetInt64("p_type", 0)
  7931. sort_type, _ := c.GetInt64("sort_type", 0)
  7932. charge_type, _ := c.GetInt64("charge_type", 0)
  7933. sch_type, _ := c.GetInt64("sch_type", 0)
  7934. zone_type, _ := c.GetInt64("zone_type", 0)
  7935. med_type, _ := c.GetInt64("med_type", 0)
  7936. timeLayout := "2006-01-02"
  7937. loc, _ := time.LoadLocation("Local")
  7938. var startTime int64
  7939. if len(start_time) > 0 {
  7940. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7941. if err != nil {
  7942. //fmt.Println(err)
  7943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7944. return
  7945. }
  7946. startTime = theTime.Unix()
  7947. }
  7948. var endTime int64
  7949. if len(end_time) > 0 {
  7950. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7951. if err != nil {
  7952. utils.ErrorLog(err.Error())
  7953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7954. return
  7955. }
  7956. endTime = theTime.Unix()
  7957. }
  7958. adminUser := c.GetAdminUserInfo()
  7959. org_id := adminUser.CurrentOrgId
  7960. 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)
  7961. for _, item := range order {
  7962. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7963. item.DoctorName = info.Doctor
  7964. item.DepartmentName = info.XtHisDepartment.Name
  7965. }
  7966. if err == nil {
  7967. c.ServeSuccessJSON(map[string]interface{}{
  7968. "order": order,
  7969. "total": total,
  7970. })
  7971. } else {
  7972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7973. return
  7974. }
  7975. }
  7976. func (c *HisApiController) GetHisOrder() {
  7977. patient_id, _ := c.GetInt64("patient_id", 0)
  7978. number := c.GetString("number")
  7979. adminInfo := c.GetAdminUserInfo()
  7980. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7981. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7982. if err == nil {
  7983. c.ServeSuccessJSON(map[string]interface{}{
  7984. "order": order,
  7985. "prescription": prescriptions,
  7986. })
  7987. } else {
  7988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7989. return
  7990. }
  7991. }
  7992. func (c *HisApiController) GetHisPrescriptionList() {
  7993. record_date := c.GetString("record_date")
  7994. keywords := c.GetString("keywords")
  7995. page, _ := c.GetInt64("page")
  7996. limit, _ := c.GetInt64("limit")
  7997. sch_type, _ := c.GetInt64("sch_type")
  7998. timeLayout := "2006-01-02"
  7999. loc, _ := time.LoadLocation("Local")
  8000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8001. if err != nil {
  8002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8003. return
  8004. }
  8005. recordDateTime := theTime.Unix()
  8006. adminInfo := c.GetAdminUserInfo()
  8007. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8008. //adminInfo := c.GetAdminUserInfo()
  8009. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8010. //fmt.Println(prescriptionOrder)
  8011. if err == nil {
  8012. c.ServeSuccessJSON(map[string]interface{}{
  8013. "order": prescriptionOrder,
  8014. "total": total,
  8015. })
  8016. } else {
  8017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8018. return
  8019. }
  8020. }
  8021. func (c *HisApiController) GetHisPrescriptionInfo() {
  8022. id, _ := c.GetInt64("id")
  8023. adminInfo := c.GetAdminUserInfo()
  8024. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8025. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8026. if err == nil {
  8027. c.ServeSuccessJSON(map[string]interface{}{
  8028. "order": prescriptionOrder,
  8029. "prescription": prescription,
  8030. })
  8031. } else {
  8032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8033. return
  8034. }
  8035. }
  8036. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8037. adminUser := c.GetAdminUserInfo()
  8038. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8039. c.ServeSuccessJSON(map[string]interface{}{
  8040. "config": config,
  8041. })
  8042. }
  8043. type ResultTwo struct {
  8044. ErrMsg interface{} `json:"err_msg"`
  8045. InfRefmsgid string `json:"inf_refmsgid"`
  8046. Infcode int64 `json:"infcode"`
  8047. Output struct {
  8048. Baseinfo struct {
  8049. Age float64 `json:"age"`
  8050. Brdy string `json:"brdy"`
  8051. Certno string `json:"certno"`
  8052. Gend string `json:"gend"`
  8053. Naty string `json:"naty"`
  8054. PsnCertType string `json:"psn_cert_type"`
  8055. PsnName string `json:"psn_name"`
  8056. PsnNo string `json:"psn_no"`
  8057. } `json:"baseinfo"`
  8058. Idetinfo []interface{} `json:"idetinfo"`
  8059. Iinfo []struct {
  8060. Balc float64 `json:"balc"`
  8061. CvlservFlag string `json:"cvlserv_flag"`
  8062. EmpName string `json:"emp_name"`
  8063. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8064. Insutype string `json:"insutype"`
  8065. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8066. PausInsuDate interface{} `json:"paus_insu_date"`
  8067. PsnInsuDate string `json:"psn_insu_date"`
  8068. PsnInsuStas string `json:"psn_insu_stas"`
  8069. PsnType string `json:"psn_type"`
  8070. } `json:"insuinfo"`
  8071. } `json:"output"`
  8072. RefmsgTime string `json:"refmsg_time"`
  8073. RespondTime string `json:"respond_time"`
  8074. Signtype interface{} `json:"signtype"`
  8075. WarnInfo interface{} `json:"warn_info"`
  8076. }
  8077. type ResultThree struct {
  8078. Cainfo interface{} `json:"cainfo"`
  8079. ErrMsg interface{} `json:"err_msg"`
  8080. InfRefmsgid string `json:"inf_refmsgid"`
  8081. Infcode int64 `json:"infcode"`
  8082. Output struct {
  8083. Data struct {
  8084. IptOtpNo string `json:"ipt_otp_no"`
  8085. MdtrtID string `json:"mdtrt_id"`
  8086. PsnNo string `json:"psn_no"`
  8087. } `json:"data"`
  8088. } `json:"output"`
  8089. RefmsgTime string `json:"refmsg_time"`
  8090. RespondTime string `json:"respond_time"`
  8091. Signtype interface{} `json:"signtype"`
  8092. WarnMsg interface{} `json:"warn_msg"`
  8093. }
  8094. type ResultFour struct {
  8095. Cainfo string `json:"cainfo"`
  8096. ErrMsg string `json:"err_msg"`
  8097. InfRefmsgid string `json:"inf_refmsgid"`
  8098. Infcode int64 `json:"infcode"`
  8099. Output struct {
  8100. Result []struct {
  8101. BasMednFlag string `json:"bas_medn_flag"`
  8102. ChldMedcFlag string `json:"chld_medc_flag"`
  8103. ChrgitmLv string `json:"chrgitm_lv"`
  8104. Cnt float64 `json:"cnt"`
  8105. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8106. DrtReimFlag string `json:"drt_reim_flag"`
  8107. FeedetlSn string `json:"feedetl_sn"`
  8108. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8109. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8110. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8111. ListSpItemFlag string `json:"list_sp_item_flag"`
  8112. LmtUsedFlag string `json:"lmt_used_flag"`
  8113. MedChrgitmType string `json:"med_chrgitm_type"`
  8114. Memo string `json:"memo"`
  8115. OverlmtAmt float64 `json:"overlmt_amt"`
  8116. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8117. Pric float64 `json:"pric"`
  8118. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8119. SelfpayProp float64 `json:"selfpay_prop"`
  8120. } `json:"result"`
  8121. } `json:"output"`
  8122. RefmsgTime string `json:"refmsg_time"`
  8123. RespondTime string `json:"respond_time"`
  8124. Signtype string `json:"signtype"`
  8125. WarnMsg string `json:"warn_msg"`
  8126. }
  8127. type ResultFive struct {
  8128. Insutype string `json:"insutype"`
  8129. }
  8130. type ResultSix struct {
  8131. Cainfo interface{} `json:"cainfo"`
  8132. ErrMsg interface{} `json:"err_msg"`
  8133. InfRefmsgid string `json:"inf_refmsgid"`
  8134. Infcode int64 `json:"infcode"`
  8135. Output struct {
  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 ResultSeven 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. Setldetail []interface{} `json:"setldetail"`
  8149. Setlinfo struct {
  8150. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8151. AcctPay float64 `json:"acct_pay"`
  8152. ActPayDedc float64 `json:"act_pay_dedc"`
  8153. Age float64 `json:"age"`
  8154. Balc float64 `json:"balc"`
  8155. Brdy string `json:"brdy"`
  8156. Certno string `json:"certno"`
  8157. ClrOptins string `json:"clr_optins"`
  8158. ClrType string `json:"clr_type"`
  8159. ClrWay string `json:"clr_way"`
  8160. CvlservFlag string `json:"cvlserv_flag"`
  8161. CvlservPay float64 `json:"cvlserv_pay"`
  8162. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8163. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8164. Gend string `json:"gend"`
  8165. HifesPay float64 `json:"hifes_pay"`
  8166. HifmiPay float64 `json:"hifmi_pay"`
  8167. HifobPay float64 `json:"hifob_pay"`
  8168. HifpPay float64 `json:"hifp_pay"`
  8169. HospPartAmt float64 `json:"hosp_part_amt"`
  8170. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8171. Insutype string `json:"insutype"`
  8172. MafPay float64 `json:"maf_pay"`
  8173. MdtrtCertType string `json:"mdtrt_cert_type"`
  8174. MdtrtID string `json:"mdtrt_id"`
  8175. MedType string `json:"med_type"`
  8176. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8177. MedinsSetlID string `json:"medins_setl_id"`
  8178. Naty string `json:"naty"`
  8179. OthPay float64 `json:"oth_pay"`
  8180. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8181. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8182. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8183. PsnCashPay float64 `json:"psn_cash_pay"`
  8184. PsnCertType string `json:"psn_cert_type"`
  8185. PsnName string `json:"psn_name"`
  8186. PsnNo string `json:"psn_no"`
  8187. PsnPartAmt float64 `json:"psn_part_amt"`
  8188. PsnType string `json:"psn_type"`
  8189. SetlID string `json:"setl_id"`
  8190. SetlTime string `json:"setl_time"`
  8191. } `json:"setlinfo"`
  8192. } `json:"output"`
  8193. RefmsgTime string `json:"refmsg_time"`
  8194. RespondTime string `json:"respond_time"`
  8195. Signtype interface{} `json:"signtype"`
  8196. WarnMsg interface{} `json:"warn_msg"`
  8197. }
  8198. type ResultEight struct {
  8199. Cainfo string `json:"cainfo"`
  8200. ErrMsg string `json:"err_msg"`
  8201. InfRefmsgid string `json:"inf_refmsgid"`
  8202. Infcode int64 `json:"infcode"`
  8203. Output struct {
  8204. Stmtinfo struct {
  8205. SetlOptins string `json:"setl_optins"`
  8206. StmtRslt string `json:"stmt_rslt"`
  8207. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8208. } `json:"stmtinfo"`
  8209. } `json:"output"`
  8210. RefmsgTime string `json:"refmsg_time"`
  8211. RespondTime string `json:"respond_time"`
  8212. Signtype interface{} `json:"signtype"`
  8213. WarnMsg interface{} `json:"warn_msg"`
  8214. }
  8215. type ResultNine struct {
  8216. Cainfo string `json:"cainfo"`
  8217. ErrMsg string `json:"err_msg"`
  8218. InfRefmsgid string `json:"inf_refmsgid"`
  8219. Infcode int64 `json:"infcode"`
  8220. Output struct {
  8221. FileQuryNo string `json:"file_qury_no"`
  8222. } `json:"output"`
  8223. RefmsgTime string `json:"refmsg_time"`
  8224. RespondTime string `json:"respond_time"`
  8225. Signtype interface{} `json:"signtype"`
  8226. WarnMsg interface{} `json:"warn_msg"`
  8227. }
  8228. type ResultTen struct {
  8229. Cainfo string `json:"cainfo"`
  8230. ErrMsg string `json:"err_msg"`
  8231. InfRefmsgid string `json:"inf_refmsgid"`
  8232. Infcode int64 `json:"infcode"`
  8233. Output struct {
  8234. DldEndtime string `json:"dld_endtime"`
  8235. FileQuryNo string `json:"file_qury_no"`
  8236. Filename string `json:"filename"`
  8237. } `json:"output"`
  8238. RefmsgTime string `json:"refmsg_time"`
  8239. RespondTime string `json:"respond_time"`
  8240. Signtype interface{} `json:"signtype"`
  8241. WarnMsg interface{} `json:"warn_msg"`
  8242. }
  8243. type ResultEleven struct {
  8244. Cainfo string `json:"cainfo"`
  8245. ErrMsg string `json:"err_msg"`
  8246. InfRefmsgid string `json:"inf_refmsgid"`
  8247. Infcode int64 `json:"infcode"`
  8248. Output struct {
  8249. Setlinfo struct {
  8250. FixmedinsName string `json:"fixmedins_name"`
  8251. FixmedinsCode string `json:"fixmedins_code"`
  8252. PsnNo string `json:"psn_no"`
  8253. PsnName string `json:"psn_name"`
  8254. HifobPay float64 `json:"hifob_pay"`
  8255. Gend string `json:"gend"`
  8256. Brdy string `json:"brdy"`
  8257. PsnCertType string `json:"psn_cert_type"`
  8258. PsnType string `json:"psn_type"`
  8259. EmpName string `json:"emp_name"`
  8260. Certno string `json:"certno"`
  8261. Insutype string `json:"insutype"`
  8262. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8263. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8264. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8265. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8266. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8267. ActPayDedc float64 `json:"act_pay_dedc"`
  8268. HifpPay float64 `json:"hifp_pay"`
  8269. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8270. CvlservPay float64 `json:"cvlserv_pay"`
  8271. HifesPay float64 `json:"hifes_pay"`
  8272. HifmiPay float64 `json:"hifmi_pay"`
  8273. MafPay float64 `json:"maf_pay"`
  8274. OthPay float64 `json:"oth_pay"`
  8275. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8276. PsnPay float64 `json:"psn_pay"`
  8277. AcctPay float64 `json:"acct_pay"`
  8278. CashPayamt float64 `json:"cash_payamt"`
  8279. Balc float64 `json:"balc"`
  8280. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8281. MedinsSetlId string `json:"medins_setl_id"`
  8282. RefdSetlFlag string `json:"refd_setl_flag"`
  8283. SetlTime string `json:"setl_time"`
  8284. MedType string `json:"med_type"`
  8285. } `json:"setlinfo"`
  8286. } `json:"output"`
  8287. RefmsgTime string `json:"refmsg_time"`
  8288. RespondTime string `json:"respond_time"`
  8289. Signtype interface{} `json:"signtype"`
  8290. WarnMsg interface{} `json:"warn_msg"`
  8291. }
  8292. type Custom struct {
  8293. DetItemFeeSumamt string
  8294. Cut string
  8295. FeedetlSn string
  8296. Price string
  8297. MedListCodg string
  8298. Type int64
  8299. AdviceId int64
  8300. ProjectId int64
  8301. ItemId int64
  8302. }
  8303. // 获取个人信息----挂号-----上传就诊信息
  8304. func (c *HisApiController) GetRegisterInfo() {
  8305. id, _ := c.GetInt64("id")
  8306. record_time := c.GetString("record_time")
  8307. settlementValue, _ := c.GetInt64("settlement_value")
  8308. medical_insurance_card := c.GetString("medical_insurance_card")
  8309. name := c.GetString("name")
  8310. id_card_type, _ := c.GetInt64("id_card_type")
  8311. certificates, _ := c.GetInt64("certificates")
  8312. medical_care, _ := c.GetInt64("medical_care")
  8313. birthday := c.GetString("birthday")
  8314. age, _ := c.GetInt64("age")
  8315. id_card := c.GetString("id_card")
  8316. register_type, _ := c.GetInt64("register")
  8317. doctor, _ := c.GetInt64("doctor")
  8318. department, _ := c.GetInt64("department")
  8319. gender, _ := c.GetInt64("sex")
  8320. phone := c.GetString("phone")
  8321. registration_fee, _ := c.GetFloat("registration_fee")
  8322. medical_expenses, _ := c.GetFloat("medical_expenses")
  8323. social_type, _ := c.GetInt64("social_type")
  8324. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8325. diagnosis_ids := c.GetString("diagnosis")
  8326. sick_type, _ := c.GetInt64("sick_type")
  8327. reg_type := c.GetString("p_type")
  8328. timeLayout := "2006-01-02"
  8329. loc, _ := time.LoadLocation("Local")
  8330. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8331. birthUnix := birthdays.Unix()
  8332. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8333. if err != nil {
  8334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8335. return
  8336. }
  8337. recordDateTime := theTime.Unix()
  8338. adminInfo := c.GetAdminUserInfo()
  8339. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8340. if tempPatient.ID == 0 {
  8341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8342. return
  8343. }
  8344. var patient service.Patients
  8345. if id == 0 {
  8346. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8347. } else {
  8348. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8349. }
  8350. if patient.ID == 0 {
  8351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8352. return
  8353. }
  8354. if len(patient.IdCardNo) == 0 {
  8355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8356. return
  8357. }
  8358. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8359. if len(his) >= 1 {
  8360. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8361. if len(his) >= 1 && order.ID == 0 {
  8362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8363. return
  8364. }
  8365. }
  8366. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8367. fmt.Println(timeStr)
  8368. timeArr := strings.Split(timeStr, " ")
  8369. fmt.Println(timeArr)
  8370. timeArrTwo := strings.Split(timeArr[0], "-")
  8371. timeArrThree := strings.Split(timeArr[1], ":")
  8372. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8373. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8374. if len(lists) == 0 {
  8375. var hisPatient models.XtHisPatient
  8376. hisPatient = models.XtHisPatient{
  8377. Name: name,
  8378. Age: age,
  8379. Gender: gender,
  8380. Birthday: birthUnix,
  8381. Phone: phone,
  8382. MedicalTreatmentType: medical_care,
  8383. IdType: certificates,
  8384. IdCardNo: id_card,
  8385. BalanceAccountsType: settlementValue,
  8386. SocialType: social_type,
  8387. MedicalInsuranceNumber: medical_insurance_card,
  8388. RegisterType: register_type,
  8389. RegisterCost: registration_fee,
  8390. TreatmentCost: medical_expenses,
  8391. AdminUserId: adminInfo.AdminUser.Id,
  8392. UserOrgId: adminInfo.CurrentOrgId,
  8393. Status: 1,
  8394. RecordDate: recordDateTime,
  8395. IsReturn: 1,
  8396. PatientId: patient.ID,
  8397. Ctime: time.Now().Unix(),
  8398. Mtime: time.Now().Unix(),
  8399. Number: str,
  8400. IdCardType: id_card_type,
  8401. Departments: department,
  8402. Doctor: doctor,
  8403. PType: reg_type,
  8404. Diagnosis: diagnosis_ids,
  8405. SickType: sick_type,
  8406. }
  8407. service.CreateHisPatient(&hisPatient)
  8408. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8409. c.ServeSuccessJSON(map[string]interface{}{
  8410. "his_info": hisPatient,
  8411. })
  8412. } else {
  8413. //chrgBchno := rand.Intn(1000000) + 10000
  8414. var hisPatient models.XtHisPatient
  8415. hisPatient = models.XtHisPatient{
  8416. Name: name,
  8417. Age: age,
  8418. Gender: gender,
  8419. Birthday: birthUnix,
  8420. Phone: phone,
  8421. MedicalTreatmentType: medical_care,
  8422. IdType: certificates,
  8423. IdCardNo: id_card,
  8424. BalanceAccountsType: settlementValue,
  8425. SocialType: social_type,
  8426. MedicalInsuranceNumber: medical_insurance_card,
  8427. RegisterType: register_type,
  8428. RegisterCost: registration_fee,
  8429. TreatmentCost: medical_expenses,
  8430. AdminUserId: adminInfo.AdminUser.Id,
  8431. UserOrgId: adminInfo.CurrentOrgId,
  8432. Status: 1,
  8433. RecordDate: recordDateTime,
  8434. IsReturn: 1,
  8435. PatientId: patient.ID,
  8436. Ctime: time.Now().Unix(),
  8437. Mtime: time.Now().Unix(),
  8438. Number: str,
  8439. IdCardType: id_card_type,
  8440. Departments: department,
  8441. Doctor: doctor,
  8442. PType: reg_type,
  8443. Diagnosis: diagnosis_ids,
  8444. SickType: sick_type,
  8445. }
  8446. service.CreateHisPatient(&hisPatient)
  8447. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8448. c.ServeSuccessJSON(map[string]interface{}{
  8449. "his_info": hisPatient,
  8450. })
  8451. }
  8452. }
  8453. // 上传明细----结算
  8454. func (c *HisApiController) GetUploadInfo() {
  8455. id, _ := c.GetInt64("id")
  8456. record_time := c.GetString("record_time")
  8457. his_patient_id, _ := c.GetInt64("his_patient_id")
  8458. oth_desc := c.GetString("oth_desc")
  8459. pay_way, _ := c.GetInt64("pay_way")
  8460. pay_ways := c.GetString("pay_ways")
  8461. pay_price, _ := c.GetFloat("pay_price")
  8462. pay_card_no := c.GetString("pay_card_no")
  8463. discount_price, _ := c.GetFloat("discount_price")
  8464. preferential_price, _ := c.GetFloat("preferential_price")
  8465. reality_price, _ := c.GetFloat("reality_price")
  8466. found_price, _ := c.GetFloat("found_price")
  8467. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8468. private_price, _ := c.GetFloat("private_price")
  8469. timeLayout := "2006-01-02"
  8470. loc, _ := time.LoadLocation("Local")
  8471. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8472. fapiao_code := c.GetString("fapiao_code")
  8473. fapiao_number := c.GetString("fapiao_number")
  8474. diagnosis_id := c.GetString("diagnosis")
  8475. sick_type, _ := c.GetInt64("sick_type")
  8476. reg_type, _ := c.GetInt64("p_type")
  8477. order_id, _ := c.GetInt64("order_id")
  8478. cash_pay := c.GetString("cash_pay")
  8479. wechat_pay := c.GetString("wechat_pay")
  8480. ali_pay := c.GetString("ali_pay")
  8481. jifen_pay := c.GetString("jifen_pay")
  8482. band_card_pay := c.GetString("band_card_pay")
  8483. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8484. tmp_decimal := c.GetString("tmp_decimal")
  8485. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8486. var decimal float64 //本次使用的押金
  8487. var errmsg error
  8488. tx := service.XTWriteDB().Begin() //开了事务
  8489. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8490. defer func() {
  8491. if errmsg != nil {
  8492. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8493. tx.Rollback()
  8494. } else {
  8495. tx.Commit()
  8496. }
  8497. }()
  8498. fmt.Println("dec_way", dec_way)
  8499. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8500. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8501. return
  8502. }
  8503. if len(tmp_decimal) > 0 {
  8504. if tmp_decimal[0] == 45 {
  8505. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8506. return
  8507. }
  8508. }
  8509. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8510. fmt.Println(errs)
  8511. decimal = tt
  8512. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8513. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8514. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8515. if err != nil {
  8516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8517. return
  8518. }
  8519. recordDateTime := theTime.Unix()
  8520. adminUser := c.GetAdminUserInfo()
  8521. var prescriptions []*models.HisPrescription
  8522. var prescriptionsOne []*models.HisPrescription
  8523. var start_time int64
  8524. var end_time int64
  8525. ids_str := c.GetString("ids")
  8526. ids_arr := strings.Split(ids_str, ",")
  8527. if tempOrder.ID == 0 {
  8528. if settle_accounts_type == 1 { //日结
  8529. fmt.Println(reg_type)
  8530. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8531. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8532. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8533. } else {
  8534. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8535. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8536. }
  8537. } else { //月结
  8538. start_time_str := c.GetString("start_time")
  8539. end_time_str := c.GetString("end_time")
  8540. timeLayout := "2006-01-02"
  8541. loc, _ := time.LoadLocation("Local")
  8542. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8543. if err != nil {
  8544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8545. return
  8546. }
  8547. recordStartTime := theStartTime.Unix()
  8548. start_time = recordStartTime
  8549. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8550. if err != nil {
  8551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8552. return
  8553. }
  8554. recordEndTime := theEndTime.Unix()
  8555. end_time = recordEndTime
  8556. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8557. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8558. }
  8559. var goods []*models.DialysisBeforePrepareGoods
  8560. var newGoods []*models.NewDialysisBeforePrepareGoods
  8561. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8562. var infos []*models.HisDoctorAdviceInfo
  8563. var infoList []*models.HisDoctorAdviceInfo
  8564. var hisAdvice []*models.HisDoctorAdviceInfo
  8565. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8566. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8567. //判断库存不足
  8568. //结算出库开关
  8569. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8570. if settConfig.IsOpen == 1 {
  8571. //判断库存的地方
  8572. for _, info := range prescriptions {
  8573. if info.Type == 1 {
  8574. infos = append(infos, info.HisDoctorAdviceInfo...)
  8575. }
  8576. if info.Type == 2 {
  8577. for _, sumItem := range info.HisPrescriptionProject {
  8578. if sumItem.Type == 3 {
  8579. var good models.DialysisBeforePrepareGoods
  8580. var newGood models.NewDialysisBeforePrepareGoods
  8581. good.GoodId = sumItem.GoodInfo.ID
  8582. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8583. count, _ := strconv.Atoi(sumItem.Count)
  8584. good.Count = int64(count)
  8585. good.StorehouseId = houseConfig.StorehouseOutInfo
  8586. good.ProjectId = sumItem.ID
  8587. goods = append(goods, &good)
  8588. newGood.GoodId = sumItem.GoodInfo.ID
  8589. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8590. count2, _ := strconv.Atoi(sumItem.Count)
  8591. newGood.Count = int64(count2)
  8592. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8593. newGood.ProjectId = sumItem.ID
  8594. newGoods = append(newGoods, &newGood)
  8595. }
  8596. }
  8597. }
  8598. }
  8599. for _, info := range prescriptionsOne {
  8600. if info.Type == 1 {
  8601. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8602. }
  8603. if info.Type == 2 {
  8604. for _, sumItem := range info.HisPrescriptionProject {
  8605. if sumItem.Type == 3 {
  8606. var newGood models.NewDialysisBeforePrepareGoods
  8607. newGood.GoodId = sumItem.GoodInfo.ID
  8608. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8609. count2, _ := strconv.Atoi(sumItem.Count)
  8610. newGood.Count = int64(count2)
  8611. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8612. newGood.ProjectId = sumItem.ID
  8613. newGoodOne = append(newGoodOne, &newGood)
  8614. }
  8615. }
  8616. }
  8617. }
  8618. //判断
  8619. for _, itemOne := range infos {
  8620. for _, itemTwo := range hisAdvice {
  8621. if itemOne.DrugId == itemTwo.DrugId {
  8622. itemTwo.Child = append(itemTwo.Child, itemOne)
  8623. }
  8624. }
  8625. }
  8626. for _, itemTwo := range hisAdvice {
  8627. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8628. var sum_out_count int64
  8629. for _, itemThree := range itemTwo.Child {
  8630. var prescribing_number int64
  8631. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8632. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8633. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8634. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8635. }
  8636. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8637. prescribing_number = parseIntPrescribingNumber
  8638. }
  8639. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8640. prescribing_number = parseIntPrescribingNumber
  8641. }
  8642. sum_out_count += prescribing_number
  8643. }
  8644. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8645. if sum_out_count > drugStockOut.FlushCount {
  8646. c.ServeSuccessJSON(map[string]interface{}{
  8647. "msg": "2",
  8648. "drug": medical,
  8649. })
  8650. return
  8651. }
  8652. }
  8653. for _, itemOne := range newGoods {
  8654. for _, item := range newGoodOne {
  8655. if itemOne.GoodId == item.GoodId {
  8656. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8657. }
  8658. }
  8659. }
  8660. for _, item := range newGoodOne {
  8661. var sum_out_count_one int64
  8662. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8663. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8664. sum_out_count_one += itemOne.Count
  8665. }
  8666. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8667. fmt.Println("sum_out_count_one", sum_out_count_one)
  8668. fmt.Println("list.FlushCount", list.FlushCount)
  8669. if sum_out_count_one > list.FlushCount {
  8670. c.ServeSuccessJSON(map[string]interface{}{
  8671. "msg": "3",
  8672. "good": good,
  8673. })
  8674. return
  8675. }
  8676. }
  8677. }
  8678. timestamp := time.Now().Unix()
  8679. tempTime := time.Unix(timestamp, 0)
  8680. timeFormat := tempTime.Format("20060102150405")
  8681. chrgBchno := rand.Intn(100000) + 10000
  8682. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8683. strconv.FormatInt(his.PatientId, 10)
  8684. var ids []int64
  8685. for _, item := range prescriptions {
  8686. ids = append(ids, item.ID)
  8687. }
  8688. var total float64
  8689. for _, item := range prescriptions {
  8690. fmt.Println(item)
  8691. if item.Type == 1 { //药品
  8692. for _, subItem := range item.HisDoctorAdviceInfo {
  8693. total = total + (subItem.Price * subItem.PrescribingNumber)
  8694. }
  8695. }
  8696. if item.Type == 2 { //项目
  8697. for _, subItem := range item.HisPrescriptionProject {
  8698. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8699. total = total + (subItem.Price * cnt)
  8700. }
  8701. }
  8702. for _, subItem := range item.HisAdditionalCharge {
  8703. total = total + (subItem.Price * float64(subItem.Count))
  8704. }
  8705. }
  8706. if reg_type == 1111 || reg_type == 1112 {
  8707. reg_type = 11
  8708. }
  8709. tm := time.Unix(time.Now().Unix(), 0)
  8710. allTotal := fmt.Sprintf("%.4f", total)
  8711. totals, _ := strconv.ParseFloat(allTotal, 64)
  8712. order := &models.HisOrder{
  8713. UserOrgId: adminUser.CurrentOrgId,
  8714. HisPatientId: his.ID,
  8715. PatientId: id,
  8716. SettleAccountsDate: recordDateTime,
  8717. Ctime: time.Now().Unix(),
  8718. Mtime: time.Now().Unix(),
  8719. Status: 1,
  8720. OrderStatus: 2,
  8721. MdtrtId: his.Number,
  8722. Number: chrg_bchno,
  8723. MedfeeSumamt: totals,
  8724. PayWay: pay_way,
  8725. PayWays: pay_ways,
  8726. PayPrice: pay_price,
  8727. MedType: strconv.Itoa(int(reg_type)),
  8728. PayCardNo: pay_card_no,
  8729. DiscountPrice: discount_price,
  8730. PreferentialPrice: preferential_price,
  8731. RealityPrice: reality_price,
  8732. FoundPrice: found_price,
  8733. MedicalInsurancePrice: medical_insurance_price,
  8734. PrivatePrice: private_price,
  8735. SettleEndTime: end_time,
  8736. SettleStartTime: start_time,
  8737. PsnPartAmt: totals,
  8738. PsnCashPay: totals,
  8739. SettleType: settle_accounts_type,
  8740. FaPiaoCode: fapiao_code,
  8741. FaPiaoNumber: fapiao_number,
  8742. Diagnosis: diagnosis_id,
  8743. PType: 2,
  8744. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8745. Decimal: decimal,
  8746. OthDesc: oth_desc,
  8747. CashPay: cash_pay,
  8748. WechatPay: wechat_pay,
  8749. AliPay: ali_pay,
  8750. JifenPay: jifen_pay,
  8751. BandCardPay: band_card_pay,
  8752. Creator: adminUser.AdminUser.Id,
  8753. }
  8754. err = service.CreateOrderTX(order, tx)
  8755. if err != nil {
  8756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8757. return
  8758. }
  8759. var customs []*Custom
  8760. for _, item := range prescriptions {
  8761. if item.Type == 1 { //药品a
  8762. for _, subItem := range item.HisDoctorAdviceInfo {
  8763. cus := &Custom{
  8764. AdviceId: subItem.ID,
  8765. ProjectId: 0,
  8766. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8767. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8768. FeedetlSn: subItem.FeedetlSn,
  8769. Price: fmt.Sprintf("%.4f", subItem.Price),
  8770. MedListCodg: subItem.MedListCodg,
  8771. Type: 1,
  8772. }
  8773. customs = append(customs, cus)
  8774. }
  8775. }
  8776. if item.Type == 2 { //项目
  8777. for _, subItem := range item.HisPrescriptionProject {
  8778. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8779. cus := &Custom{
  8780. AdviceId: 0,
  8781. ProjectId: subItem.ID,
  8782. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8783. Cut: fmt.Sprintf("%.4f", cnt),
  8784. FeedetlSn: subItem.FeedetlSn,
  8785. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8786. MedListCodg: subItem.MedListCodg,
  8787. Type: 2,
  8788. }
  8789. customs = append(customs, cus)
  8790. }
  8791. }
  8792. for _, item := range item.HisAdditionalCharge {
  8793. cus := &Custom{
  8794. ItemId: item.ID,
  8795. AdviceId: 0,
  8796. ProjectId: 0,
  8797. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8798. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8799. FeedetlSn: item.FeedetlSn,
  8800. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8801. MedListCodg: item.XtHisAddtionConfig.Code,
  8802. Type: 3,
  8803. }
  8804. customs = append(customs, cus)
  8805. }
  8806. }
  8807. for _, item := range customs {
  8808. var advice_id int64 = 0
  8809. var project_id int64 = 0
  8810. var item_id int64 = 0
  8811. var types int64 = 0
  8812. if item.Type == 1 {
  8813. advice_id = item.AdviceId
  8814. project_id = 0
  8815. item_id = 0
  8816. } else if item.Type == 2 {
  8817. advice_id = 0
  8818. item_id = 0
  8819. project_id = item.ProjectId
  8820. } else if item.Type == 3 {
  8821. advice_id = 0
  8822. item_id = item.ItemId
  8823. project_id = 0
  8824. }
  8825. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8826. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8827. pric, _ := strconv.ParseFloat(item.Price, 32)
  8828. info := &models.HisOrderInfo{
  8829. OrderNumber: order.Number,
  8830. UploadDate: time.Now().Unix(),
  8831. AdviceId: advice_id,
  8832. DetItemFeeSumamt: detItemFeeSumamt,
  8833. Cnt: cut,
  8834. Pric: pric,
  8835. PatientId: id,
  8836. Status: 1,
  8837. Mtime: time.Now().Unix(),
  8838. Ctime: time.Now().Unix(),
  8839. UserOrgId: adminUser.CurrentOrgId,
  8840. HisPatientId: his.ID,
  8841. OrderId: order.ID,
  8842. ProjectId: project_id,
  8843. Type: types,
  8844. ItemId: item_id,
  8845. }
  8846. service.CreateOrderInfoTX(info, tx)
  8847. }
  8848. his.Diagnosis = diagnosis_id
  8849. his.SickType = sick_type
  8850. his.RegisterType = reg_type
  8851. his.MedicalTreatmentType = reg_type
  8852. service.UpdataHisPateintTX(&his, tx)
  8853. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8854. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8855. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8856. //判断是否使用了押金
  8857. if dec_way == "true" {
  8858. tmpstring := strconv.FormatInt(order.ID, 10)
  8859. //扣押金
  8860. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8861. order.Decimal = decimal
  8862. service.UpDateOrderTwo(order, tx)
  8863. if errmsg != nil {
  8864. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8865. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8866. return
  8867. }
  8868. }
  8869. if err == nil {
  8870. for _, info := range prescriptions {
  8871. if info.Type == 1 {
  8872. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8873. }
  8874. if info.Type == 2 {
  8875. for _, sumItem := range info.HisPrescriptionProject {
  8876. if sumItem.Type == 3 {
  8877. var good models.DialysisBeforePrepareGoods
  8878. var newGood models.NewDialysisBeforePrepareGoods
  8879. var oldGood models.OldDialysisBeforePrepareGoods
  8880. good.GoodId = sumItem.GoodInfo.ID
  8881. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8882. count, _ := strconv.Atoi(sumItem.Count)
  8883. good.Count = int64(count)
  8884. good.StorehouseId = houseConfig.StorehouseOutInfo
  8885. good.ProjectId = sumItem.ID
  8886. good.PatientId = sumItem.PatientId
  8887. goods = append(goods, &good)
  8888. newGood.GoodId = sumItem.GoodInfo.ID
  8889. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8890. count2, _ := strconv.Atoi(sumItem.Count)
  8891. newGood.Count = int64(count2)
  8892. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8893. newGood.ProjectId = sumItem.ID
  8894. newGood.PatientId = sumItem.HisPatientId
  8895. newGoods = append(newGoods, &newGood)
  8896. oldGood.GoodId = sumItem.GoodInfo.ID
  8897. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8898. count3, _ := strconv.Atoi(sumItem.Count)
  8899. oldGood.Count = int64(count3)
  8900. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8901. oldGood.ProjectId = sumItem.ID
  8902. oldGood.RecordDate = sumItem.RecordDate
  8903. oldGood.PatientId = sumItem.HisPatientId
  8904. oldGoods = append(oldGoods, &oldGood)
  8905. }
  8906. }
  8907. }
  8908. }
  8909. if settConfig.IsOpen == 1 {
  8910. for _, item := range infoList {
  8911. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8912. if medical.IsUse == 2 {
  8913. //药品出库
  8914. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8915. //查询默认仓库
  8916. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8917. //查询默认仓库剩余多少库存
  8918. var sum_count int64
  8919. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8920. for _, its := range stockInfo {
  8921. if its.MaxUnit == medical.MaxUnit {
  8922. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8923. }
  8924. sum_count += its.StockMaxNumber + its.StockMinNumber
  8925. }
  8926. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8927. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8928. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8929. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8930. }
  8931. }
  8932. orgId := c.GetAdminUserInfo().CurrentOrgId
  8933. if len(oldGoods) > 0 {
  8934. timeStr := time.Now().Format("2006-01-02")
  8935. timeArr := strings.Split(timeStr, "-")
  8936. total, _ := service.FindAllWarehouseOut(orgId)
  8937. total = total + 1
  8938. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8939. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8940. number = number + total
  8941. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8942. operation_time := time.Now().Unix()
  8943. creater := c.GetAdminUserInfo().AdminUser.Id
  8944. //查询默认出库仓库库存
  8945. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8946. recordDateStr := time.Now().Format("2006-01-02")
  8947. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8948. nowtime := recordDate.Unix()
  8949. warehouseOut := models.WarehouseOut{
  8950. WarehouseOutOrderNumber: warehousing_out_order,
  8951. OperationTime: operation_time,
  8952. OrgId: orgId,
  8953. Creater: creater,
  8954. Ctime: time.Now().Unix(),
  8955. Status: 1,
  8956. WarehouseOutTime: nowtime,
  8957. Type: 1,
  8958. StorehouseId: storeConfig.StorehouseOutInfo,
  8959. IsCheck: 1,
  8960. OrderId: order.ID,
  8961. IsSys: 5,
  8962. }
  8963. //查询是否生成出库单
  8964. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8965. if out.ID == 0 {
  8966. service.AddSigleWarehouseOut(&warehouseOut)
  8967. }
  8968. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8969. for _, item := range oldGoods {
  8970. dialyPrepareOne := models.DialysisBeforePrepare{
  8971. GoodTypeId: item.GoodTypeId,
  8972. GoodId: item.GoodId,
  8973. PatientId: his.PatientId,
  8974. RecordDate: item.RecordDate,
  8975. UserOrgId: adminUser.CurrentOrgId,
  8976. Count: item.Count,
  8977. Ctime: time.Now().Unix(),
  8978. Creater: adminUser.AdminUser.Id,
  8979. CommdityCode: item.CommdityCode,
  8980. Status: 1,
  8981. StorehouseId: houseConfig.StorehouseOutInfo,
  8982. }
  8983. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8984. //非零用
  8985. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8986. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8987. //查询剩余库存
  8988. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8989. var sum_count int64
  8990. for _, item := range goodList {
  8991. sum_count += item.StockCount
  8992. }
  8993. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8994. //耗材
  8995. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8996. }
  8997. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8998. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8999. //查询剩余库存
  9000. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9001. var sum_count int64
  9002. for _, item := range goodList {
  9003. sum_count += item.StockCount
  9004. }
  9005. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9006. //耗材
  9007. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9008. }
  9009. }
  9010. }
  9011. }
  9012. c.ServeSuccessJSON(map[string]interface{}{
  9013. "msg": "结算成功",
  9014. })
  9015. }
  9016. }
  9017. }
  9018. // 退款
  9019. func (c *HisApiController) Refund() {
  9020. order_id, _ := c.GetInt64("order_id")
  9021. order, _ := service.GetHisOrderByID(order_id)
  9022. adminUser := c.GetAdminUserInfo()
  9023. orgid := c.GetAdminUserInfo().CurrentOrgId
  9024. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9025. if err != nil {
  9026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9027. return
  9028. }
  9029. tmp := strconv.FormatInt(order.ID, 10)
  9030. //当押金不为零时产生退费记录
  9031. if order.Decimal != 0 {
  9032. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9033. if err != nil {
  9034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9035. return
  9036. }
  9037. }
  9038. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9039. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9040. var goods []*models.DialysisBeforePrepareGoods
  9041. var newGoods []*models.NewDialysisBeforePrepareGoods
  9042. var infos []*models.HisDoctorAdviceInfo
  9043. for _, info := range orders {
  9044. if info.AdviceId > 0 && info.ProjectId == 0 {
  9045. infos = append(infos, &info.HisDoctorAdviceInfo)
  9046. }
  9047. if info.ProjectId > 0 && info.AdviceId == 0 {
  9048. if info.HisPrescriptionProject.Type == 3 {
  9049. var good models.DialysisBeforePrepareGoods
  9050. var newGood models.NewDialysisBeforePrepareGoods
  9051. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9052. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9053. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9054. good.Count = int64(count)
  9055. good.StorehouseId = houseConfig.StorehouseOutInfo
  9056. good.ProjectId = info.HisPrescriptionProject.ID
  9057. good.PatientId = info.PatientId
  9058. good.OrderId = order_id
  9059. goods = append(goods, &good)
  9060. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9061. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9062. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9063. newGood.Count = int64(count2)
  9064. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9065. newGood.ProjectId = info.HisPrescriptionProject.ID
  9066. newGood.RecordDate = order.SettleAccountsDate
  9067. newGood.UserOrgId = order.UserOrgId
  9068. newGood.PatientId = info.PatientId
  9069. newGood.OrderId = order_id
  9070. newGoods = append(newGoods, &newGood)
  9071. }
  9072. }
  9073. }
  9074. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9075. if settConfig.IsOpen == 1 {
  9076. for _, item := range infos {
  9077. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9078. }
  9079. for _, item := range newGoods {
  9080. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9081. }
  9082. }
  9083. c.ServeSuccessJSON(map[string]interface{}{
  9084. "msg": "退费成功",
  9085. })
  9086. }
  9087. func (c *HisApiController) RefundNumber() {
  9088. his_patient_id, _ := c.GetInt64("id")
  9089. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9090. info.Status = 0
  9091. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9092. if count > 0 {
  9093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9094. return
  9095. }
  9096. err := service.SaveHisPatient(info)
  9097. if err == nil {
  9098. c.ServeSuccessJSON(map[string]interface{}{
  9099. "msg": "退号成功",
  9100. })
  9101. } else {
  9102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9103. return
  9104. }
  9105. }
  9106. func (this *HisApiController) AdditionalCharge() {
  9107. dataBody := make(map[string]interface{}, 0)
  9108. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9109. fmt.Println(err)
  9110. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9111. patient_id := int64(dataBody["patient_id"].(float64))
  9112. medicineData, _ := dataBody["medicineData"].([]interface{})
  9113. adminUserInfo := this.GetAdminUserInfo()
  9114. orgId := adminUserInfo.CurrentOrgId
  9115. admin_user_id := adminUserInfo.AdminUser.Id
  9116. timeStr := time.Now().Format("2006-01-02")
  9117. timeLayout := "2006-01-02 15:04:05"
  9118. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9119. timenow := timeStringToTime.Unix()
  9120. var additionalCharges []*models.HisAdditionalCharge
  9121. for _, item := range medicineData {
  9122. var randNum int
  9123. randNum = rand.Intn(10000) + 1000
  9124. timestamp := time.Now().Unix()
  9125. tempTime := time.Unix(timestamp, 0)
  9126. timeFormat := tempTime.Format("20060102150405")
  9127. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9128. items := item.(map[string]interface{})
  9129. money := items["price"].(string)
  9130. item_id_str := items["item_id"].(string)
  9131. name := items["name"].(string)
  9132. id_str := items["id"].(string)
  9133. moneys, _ := strconv.ParseInt(money, 10, 64)
  9134. monStr := strconv.FormatInt(moneys, 10)
  9135. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9136. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9137. id, _ := strconv.ParseInt(id_str, 10, 64)
  9138. additionalCharge := &models.HisAdditionalCharge{
  9139. ID: id,
  9140. HisPatientId: his_patient_id,
  9141. UserOrgId: orgId,
  9142. PatientId: patient_id,
  9143. RecordDate: timenow,
  9144. Price: monneyStr,
  9145. Status: 1,
  9146. ItemName: name,
  9147. ItemId: item_id,
  9148. AdminUserId: admin_user_id,
  9149. CreatedTime: time.Now().Unix(),
  9150. OrderStatus: 0,
  9151. PrescriptionNumber: "",
  9152. BatchNumber: "",
  9153. FeedetlSn: p_number,
  9154. }
  9155. service.CreateAdditionalCharge(additionalCharge)
  9156. additionalCharges = append(additionalCharges, additionalCharge)
  9157. }
  9158. this.ServeSuccessJSON(map[string]interface{}{
  9159. "msg": "添加成功",
  9160. "additional_charges": additionalCharges,
  9161. })
  9162. }
  9163. func (this *HisApiController) DeleteAddition() {
  9164. id, _ := this.GetInt64("id")
  9165. //TODO 需要判断是否已经结算
  9166. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9167. if err == nil {
  9168. this.ServeSuccessJSON(map[string]interface{}{
  9169. "msg": "删除成功",
  9170. })
  9171. return
  9172. } else {
  9173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9174. return
  9175. }
  9176. }
  9177. func (this *HisApiController) GetAdminUsers() {
  9178. adminUser := this.GetAdminUserInfo()
  9179. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9180. this.ServeSuccessJSON(map[string]interface{}{
  9181. "doctors": doctors,
  9182. })
  9183. }
  9184. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9185. change_type, _ := this.GetInt64("type", 0)
  9186. record_date := this.GetString("record_time")
  9187. patient_id, _ := this.GetInt64("patient_id", 0)
  9188. p_type, _ := this.GetInt64("p_type", 0)
  9189. timeLayout := "2006-01-02"
  9190. loc, _ := time.LoadLocation("Local")
  9191. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9192. record_time := theAdviceRecordTime.Unix()
  9193. adminUserInfo := this.GetAdminUserInfo()
  9194. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9195. if adminUserInfo.CurrentOrgId == 10265 {
  9196. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9197. if config.ID > 0 && config.IsOpen == 1 {
  9198. for _, subitems := range prescriptions {
  9199. for _, item := range subitems.VMHisPrescription {
  9200. for _, subItem := range item.HisDoctorAdviceInfo {
  9201. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9202. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9203. if info.RetailPrice > 0 {
  9204. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9205. subItem.Drug.RetailPrice = drug.RetailPrice
  9206. }
  9207. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9208. subItem.Drug.MinPrice = info.RetailPrice
  9209. subItem.Drug.RetailPrice = info.RetailPrice
  9210. }
  9211. }
  9212. }
  9213. }
  9214. }
  9215. }
  9216. if config.ID > 0 && config.IsOpen == 1 {
  9217. for _, subitems := range prescriptions {
  9218. for _, item := range subitems.VMHisPrescription {
  9219. for _, subItem := range item.HisPrescriptionProject {
  9220. if subItem.Type == 3 {
  9221. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9222. if info.Price > 0 {
  9223. subItem.GoodInfo.PackingPrice = info.Price
  9224. }
  9225. }
  9226. }
  9227. }
  9228. }
  9229. }
  9230. }
  9231. if err == nil {
  9232. if len(prescriptions) == 0 {
  9233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9234. return
  9235. } else {
  9236. this.ServeSuccessJSON(map[string]interface{}{
  9237. "prescriptions": prescriptions,
  9238. })
  9239. return
  9240. }
  9241. } else {
  9242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9243. return
  9244. }
  9245. }
  9246. func (this *HisApiController) GetCallHisPrescription() {
  9247. patient_id, _ := this.GetInt64("patient_id", 0)
  9248. timeLayout := "2006-01-02"
  9249. loc, _ := time.LoadLocation("Local")
  9250. start_time := this.GetString("start_time")
  9251. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9252. end_time := this.GetString("end_time")
  9253. p_type, _ := this.GetInt64("p_type")
  9254. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9255. adminUserInfo := this.GetAdminUserInfo()
  9256. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9257. //if
  9258. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9259. //
  9260. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9261. if adminUserInfo.CurrentOrgId == 10265 {
  9262. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9263. if config.ID > 0 && config.IsOpen == 1 {
  9264. for _, subitems := range prescriptions {
  9265. for _, item := range subitems.VMHisPrescription {
  9266. for _, subItem := range item.HisDoctorAdviceInfo {
  9267. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9268. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9269. if info.RetailPrice > 0 {
  9270. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9271. subItem.Drug.RetailPrice = drug.RetailPrice
  9272. }
  9273. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9274. subItem.Drug.MinPrice = info.RetailPrice
  9275. subItem.Drug.RetailPrice = info.RetailPrice
  9276. }
  9277. }
  9278. }
  9279. }
  9280. }
  9281. }
  9282. if config.ID > 0 && config.IsOpen == 1 {
  9283. for _, subitems := range prescriptions {
  9284. for _, item := range subitems.VMHisPrescription {
  9285. for _, subItem := range item.HisPrescriptionProject {
  9286. if subItem.Type == 3 {
  9287. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9288. if info.Price > 0 {
  9289. subItem.GoodInfo.PackingPrice = info.Price
  9290. }
  9291. }
  9292. }
  9293. }
  9294. }
  9295. }
  9296. }
  9297. if err == nil {
  9298. this.ServeSuccessJSON(map[string]interface{}{
  9299. "prescriptions": prescriptions,
  9300. })
  9301. return
  9302. } else {
  9303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9304. return
  9305. }
  9306. }
  9307. func (this *HisApiController) GetHisDayPrescription() {
  9308. timeLayout := "2006-01-02"
  9309. loc, _ := time.LoadLocation("Local")
  9310. start_time := this.GetString("start_time")
  9311. patient_id, _ := this.GetInt64("patient_id", 0)
  9312. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9313. end_time := this.GetString("end_time")
  9314. p_type, _ := this.GetInt64("p_type")
  9315. order_status, _ := this.GetInt64("type")
  9316. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9317. adminUserInfo := this.GetAdminUserInfo()
  9318. var dayHisPrescription []*models.HisPrescription
  9319. var err error
  9320. if order_status == 1 || order_status == 0 {
  9321. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9322. } else if order_status == 2 {
  9323. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9324. }
  9325. var settle_total float64
  9326. for _, item := range dayHisPrescription {
  9327. if len(item.HisPrescriptionProject) > 0 {
  9328. for _, subItem := range item.HisPrescriptionProject {
  9329. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9330. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9331. settle_total = settle_total + total
  9332. }
  9333. }
  9334. if len(item.HisDoctorAdviceInfo) > 0 {
  9335. for _, subItem := range item.HisDoctorAdviceInfo {
  9336. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9337. settle_total = settle_total + total
  9338. }
  9339. }
  9340. }
  9341. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9342. if err == nil {
  9343. this.ServeSuccessJSON(map[string]interface{}{
  9344. "day_prescription": dayHisPrescription,
  9345. "settle_total": settle_total,
  9346. })
  9347. return
  9348. } else {
  9349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9350. return
  9351. }
  9352. }
  9353. func (c *HisApiController) GetHisChargePatientList() {
  9354. record_date := c.GetString("record_date")
  9355. order_status, _ := c.GetInt64("type")
  9356. sch_type, _ := c.GetInt64("sch_type")
  9357. timeLayout := "2006-01-02"
  9358. loc, _ := time.LoadLocation("Local")
  9359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9360. if err != nil {
  9361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9362. return
  9363. }
  9364. recordDateTime := theTime.Unix()
  9365. adminInfo := c.GetAdminUserInfo()
  9366. var tempPatients []*service.NewTempPatients
  9367. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9368. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9369. if order_status != 2 {
  9370. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9371. } else {
  9372. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9373. }
  9374. } else {
  9375. if order_status != 2 {
  9376. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9377. } else {
  9378. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9379. }
  9380. }
  9381. var patients []*service.NewTempPatients
  9382. var patients_two []*service.NewTempPatients
  9383. for _, item := range tempPatients {
  9384. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9385. //过滤掉没挂号的和没开处方的
  9386. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9387. patients = append(patients, item)
  9388. }
  9389. //过滤掉没挂号的
  9390. if len(item.HisPatient) > 0 {
  9391. patients_two = append(patients_two, item)
  9392. }
  9393. } else {
  9394. if len(item.HisPrescription) > 0 {
  9395. patients = append(patients, item)
  9396. }
  9397. }
  9398. }
  9399. c.ServeSuccessJSON(map[string]interface{}{
  9400. "list": patients,
  9401. "list_two": patients_two,
  9402. })
  9403. }
  9404. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9405. record_date := c.GetString("record_date")
  9406. timeLayout := "2006-01-02"
  9407. loc, _ := time.LoadLocation("Local")
  9408. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9409. if err != nil {
  9410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9411. return
  9412. }
  9413. recordDateTime := theTime.Unix()
  9414. adminUser := c.GetAdminUserInfo()
  9415. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9416. var patients []*service.Patients
  9417. for _, item := range tempPatients {
  9418. if item.HisPatient.ID == 0 {
  9419. patients = append(patients, item)
  9420. }
  9421. }
  9422. c.ServeSuccessJSON(map[string]interface{}{
  9423. "list": patients,
  9424. //"list_two": patients_two,
  9425. })
  9426. }
  9427. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9428. newArr = make([]*service.Patients, 0)
  9429. for i := 0; i < len(patient); i++ {
  9430. repeat := false
  9431. for j := i + 1; j < len(patient); j++ {
  9432. if patient[i].ID == patient[j].ID {
  9433. repeat = true
  9434. break
  9435. }
  9436. }
  9437. if !repeat {
  9438. newArr = append(newArr, patient[i])
  9439. }
  9440. }
  9441. return
  9442. }
  9443. func (c *HisApiController) GetHisChargePatientInfo() {
  9444. patient_id, _ := c.GetInt64("patient_id")
  9445. his_patient_id, _ := c.GetInt64("his_patient_id")
  9446. record_date := c.GetString("record_date")
  9447. //start_time := c.GetString("start_time")
  9448. //end_time := c.GetString("end_time")
  9449. order_status, _ := c.GetInt64("type", 0)
  9450. p_type, _ := c.GetInt64("p_type", 0)
  9451. order_id, _ := c.GetInt64("order_id", 0)
  9452. timeLayout := "2006-01-02"
  9453. loc, _ := time.LoadLocation("Local")
  9454. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9455. if err != nil {
  9456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9457. return
  9458. }
  9459. recordDateTime := theTime.Unix()
  9460. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9461. //if err != nil {
  9462. //
  9463. //}
  9464. //startRecordDateTime := startTime.Unix()
  9465. //
  9466. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9467. //if err != nil {
  9468. //
  9469. //}
  9470. //endRecordDateTime := endTime.Unix()
  9471. admin := c.GetAdminUserInfo()
  9472. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9473. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9474. var prescriptions []*models.HisPrescription
  9475. //var unChargeMonthPrescriptions []*models.HisPrescription
  9476. order, _ := service.GetHisOrderByID(order_id)
  9477. if order_status == 1 || order_status == 0 {
  9478. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9479. } else if order_status == 2 {
  9480. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9481. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9482. }
  9483. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9484. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9485. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9486. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9487. //获取所有科室信息
  9488. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9489. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9490. c.ServeSuccessJSON(map[string]interface{}{
  9491. "his_info": his_patient_info,
  9492. "xt_info": xt_patient_info,
  9493. "prescription": prescriptions,
  9494. "case_history": case_history,
  9495. "info": patientPrescriptionInfo,
  9496. "last_info": lastPatientPrescriptionInfo,
  9497. "order": order,
  9498. "doctors": doctors,
  9499. "department": department,
  9500. "sch": sch,
  9501. })
  9502. return
  9503. }
  9504. func (c *HisApiController) GetAllOrderDetail() {
  9505. order_id, _ := c.GetInt64("id", 0)
  9506. order, _ := service.GetHisOrderByID(order_id)
  9507. if order.ID == 0 {
  9508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9509. return
  9510. }
  9511. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9512. org_id := c.GetAdminUserInfo().CurrentOrgId
  9513. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9514. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9515. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9516. c.ServeSuccessJSON(map[string]interface{}{
  9517. "order": order,
  9518. "order_info": order_info,
  9519. "patient": patient,
  9520. "admin_info": adminInfo,
  9521. "hospital_record": record,
  9522. })
  9523. return
  9524. }
  9525. func (c *HisApiController) GetAllOrderDetailCollect() {
  9526. order_id, _ := c.GetInt64("id", 0)
  9527. order, _ := service.GetHisOrderByID(order_id)
  9528. if order.ID == 0 {
  9529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9530. return
  9531. }
  9532. org_id := c.GetAdminUserInfo().CurrentOrgId
  9533. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9534. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9535. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9536. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9537. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9538. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9539. var bedCostTotal float64 = 0 //床位总费
  9540. //var bedCostSelfTotal float64 = 0 //床位自费
  9541. var operationCostTotal float64 = 0 //手术费
  9542. //var operationCostSelfTotal float64 = 0 //手术费
  9543. var otherCostTotal float64 = 0 //其他费用
  9544. //var otherCostSelfTotal float64 = 0 //其他费用
  9545. var materialCostTotal float64 = 0 //材料费
  9546. //var materialCostSelfTotal float64 = 0 //材料费
  9547. var westernMedicineCostTotal float64 = 0 //西药费
  9548. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9549. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9550. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9551. var checkCostTotal float64 = 0 //检查费
  9552. //var checkCostSelfTotal float64 = 0 //检查费
  9553. var laboratoryCostTotal float64 = 0 //化验费
  9554. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9555. var treatCostTotal float64 = 0 //治疗费用
  9556. //var treatCostSelfTotal float64 = 0 //治疗费用
  9557. var zhenChaCostTotal float64 = 0 //其他费用
  9558. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9559. decimal.DivisionPrecision = 2
  9560. var BalanceAccountsType int64
  9561. if his.ID > 0 {
  9562. BalanceAccountsType = his.BalanceAccountsType
  9563. } else {
  9564. BalanceAccountsType = record.BalanceAccountsType
  9565. }
  9566. if BalanceAccountsType != 2 {
  9567. for _, item := range order_info {
  9568. if org_id == 10215 {
  9569. if item.MedChrgitmType == "01" { //床位费
  9570. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9571. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9572. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9573. }
  9574. if item.MedChrgitmType == "02" { //诊察费
  9575. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9576. //zhenChaCostSelfTotal = zhenChaCostTotal
  9577. }
  9578. if item.MedChrgitmType == "03" { //检查费
  9579. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9580. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9581. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9582. }
  9583. //if item.MedChrgitmType == "02" { //检查费
  9584. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9585. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9586. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9587. //}
  9588. if item.MedChrgitmType == "04" { //化验费
  9589. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9590. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9591. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9592. }
  9593. if item.MedChrgitmType == "05" { //治疗费
  9594. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9595. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9596. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9597. }
  9598. if item.MedChrgitmType == "06" { //手术费
  9599. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9600. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9601. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9602. }
  9603. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9604. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9605. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9606. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9607. }
  9608. if item.MedChrgitmType == "09" { //西药费
  9609. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9610. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9611. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9612. }
  9613. if item.MedChrgitmType == "11" { //中成费
  9614. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9615. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9616. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9617. }
  9618. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9619. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9620. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9621. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9622. }
  9623. } else if org_id == 10188 || org_id == 10217 {
  9624. if item.MedChrgitmType == "01" { //床位费
  9625. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9626. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9627. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9628. }
  9629. if item.MedChrgitmType == "02" { //诊察费
  9630. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9631. //zhenChaCostSelfTotal = zhenChaCostTotal
  9632. }
  9633. if item.MedChrgitmType == "03" { //检查费
  9634. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9635. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9636. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9637. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9638. }
  9639. //if item.MedChrgitmType == "02" { //检查费
  9640. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9641. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9642. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9643. //}
  9644. if item.MedChrgitmType == "04" { //化验费
  9645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9646. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9647. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9648. }
  9649. if item.MedChrgitmType == "05" { //治疗费
  9650. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9651. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9652. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9653. }
  9654. if item.MedChrgitmType == "06" { //手术费
  9655. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9656. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9657. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9658. }
  9659. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9660. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9661. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9662. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9663. }
  9664. if item.MedChrgitmType == "09" { //西药费
  9665. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9666. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9667. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9668. }
  9669. if item.MedChrgitmType == "11" { //中成费
  9670. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9671. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9672. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9673. }
  9674. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9675. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9676. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9677. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9678. }
  9679. } else {
  9680. if item.MedChrgitmType == "01" { //床位费
  9681. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9682. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9683. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9684. }
  9685. //if item.MedChrgitmType == "02" { //诊察费
  9686. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9687. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9688. //}
  9689. if item.MedChrgitmType == "03" { //检查费
  9690. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9691. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9692. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9693. }
  9694. //if item.MedChrgitmType == "02" { //检查费
  9695. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9696. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9697. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9698. //}
  9699. if item.MedChrgitmType == "04" { //化验费
  9700. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9701. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9702. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9703. }
  9704. if item.MedChrgitmType == "05" { //治疗费
  9705. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9706. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9707. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9708. }
  9709. if item.MedChrgitmType == "06" { //手术费
  9710. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9711. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9712. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9713. }
  9714. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9715. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9716. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9717. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9718. }
  9719. if item.MedChrgitmType == "09" { //西药费
  9720. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9721. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9722. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9723. }
  9724. if item.MedChrgitmType == "11" { //中成费
  9725. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9726. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9727. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9728. }
  9729. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9730. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9731. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9732. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9733. }
  9734. }
  9735. }
  9736. c.ServeSuccessJSON(map[string]interface{}{
  9737. "order": order,
  9738. "order_info": order_info,
  9739. "patient": patient,
  9740. "admin_info": adminInfo,
  9741. "his_hospital": record,
  9742. "bedCostTotal": bedCostTotal,
  9743. "operationCostTotal": operationCostTotal,
  9744. "otherCostTotal": otherCostTotal,
  9745. "materialCostTotal": materialCostTotal,
  9746. "westernMedicineCostTotal": westernMedicineCostTotal,
  9747. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9748. "checkCostTotal": checkCostTotal,
  9749. "zhenChaCostTotal": zhenChaCostTotal,
  9750. "laboratoryCostTotal": laboratoryCostTotal,
  9751. "treatCostTotal": treatCostTotal,
  9752. })
  9753. } else {
  9754. for _, item := range order_info {
  9755. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9756. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9757. item.MedChrgitmType = "09"
  9758. }
  9759. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9760. if item.HisPrescriptionProject.Type == 2 {
  9761. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9762. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9763. case 0:
  9764. item.MedChrgitmType = "0"
  9765. break
  9766. case 1:
  9767. item.MedChrgitmType = "14"
  9768. break
  9769. case 2:
  9770. item.MedChrgitmType = "05"
  9771. break
  9772. case 3:
  9773. item.MedChrgitmType = "03"
  9774. break
  9775. case 4:
  9776. item.MedChrgitmType = "03"
  9777. break
  9778. case 5:
  9779. item.MedChrgitmType = "08"
  9780. break
  9781. case 6:
  9782. item.MedChrgitmType = "14"
  9783. break
  9784. case 7:
  9785. item.MedChrgitmType = "14"
  9786. break
  9787. case 8:
  9788. item.MedChrgitmType = "03"
  9789. break
  9790. case 9:
  9791. item.MedChrgitmType = "14"
  9792. break
  9793. case 10:
  9794. item.MedChrgitmType = "14"
  9795. break
  9796. case 11:
  9797. item.MedChrgitmType = "06"
  9798. break
  9799. case 12:
  9800. item.MedChrgitmType = "12"
  9801. break
  9802. case 13:
  9803. item.MedChrgitmType = "01"
  9804. break
  9805. case 14:
  9806. item.MedChrgitmType = "04"
  9807. break
  9808. case 15:
  9809. item.MedChrgitmType = "14"
  9810. break
  9811. }
  9812. } else {
  9813. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9814. case 1:
  9815. item.MedChrgitmType = "14"
  9816. break
  9817. case 2:
  9818. item.MedChrgitmType = "05"
  9819. break
  9820. case 3:
  9821. item.MedChrgitmType = "04"
  9822. break
  9823. case 4:
  9824. item.MedChrgitmType = "14"
  9825. break
  9826. case 5:
  9827. item.MedChrgitmType = "08"
  9828. break
  9829. case 6:
  9830. item.MedChrgitmType = "14"
  9831. break
  9832. case 7:
  9833. item.MedChrgitmType = "14"
  9834. break
  9835. case 8:
  9836. item.MedChrgitmType = "03"
  9837. break
  9838. case 9:
  9839. item.MedChrgitmType = "14"
  9840. break
  9841. }
  9842. }
  9843. } else if item.HisPrescriptionProject.Type == 3 {
  9844. item.MedChrgitmType = "08"
  9845. }
  9846. }
  9847. }
  9848. for _, item := range order_info {
  9849. if org_id == 10215 {
  9850. if item.MedChrgitmType == "01" { //床位费
  9851. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9852. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9853. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9854. }
  9855. if item.MedChrgitmType == "02" { //诊察费
  9856. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9857. //zhenChaCostSelfTotal = zhenChaCostTotal
  9858. }
  9859. if item.MedChrgitmType == "03" { //检查费
  9860. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9861. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9862. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9863. }
  9864. //if item.MedChrgitmType == "02" { //检查费
  9865. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9866. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9867. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9868. //}
  9869. if item.MedChrgitmType == "04" { //化验费
  9870. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9871. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9872. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9873. }
  9874. if item.MedChrgitmType == "05" { //治疗费
  9875. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9876. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9877. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9878. }
  9879. if item.MedChrgitmType == "06" { //手术费
  9880. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9881. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9882. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9883. }
  9884. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9885. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9886. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9887. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9888. }
  9889. if item.MedChrgitmType == "09" { //西药费
  9890. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9891. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9892. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9893. }
  9894. if item.MedChrgitmType == "11" { //中成费
  9895. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9896. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9897. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9898. }
  9899. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9900. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9901. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9902. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9903. }
  9904. } else {
  9905. if item.MedChrgitmType == "01" { //床位费
  9906. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9907. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9908. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9909. }
  9910. //if item.MedChrgitmType == "02" { //诊察费
  9911. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9912. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9913. //}
  9914. if item.MedChrgitmType == "03" { //检查费
  9915. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9916. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9917. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9918. }
  9919. //if item.MedChrgitmType == "02" { //检查费
  9920. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9921. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9922. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9923. //}
  9924. if item.MedChrgitmType == "04" { //化验费
  9925. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9926. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9927. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9928. }
  9929. if item.MedChrgitmType == "05" { //治疗费
  9930. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9931. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9932. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9933. }
  9934. if item.MedChrgitmType == "06" { //手术费
  9935. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9936. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9937. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9938. }
  9939. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9940. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9941. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9942. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9943. }
  9944. if item.MedChrgitmType == "09" { //西药费
  9945. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9946. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9947. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9948. }
  9949. if item.MedChrgitmType == "11" { //中成费
  9950. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9951. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9952. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9953. }
  9954. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9955. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9956. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9957. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9958. }
  9959. }
  9960. }
  9961. c.ServeSuccessJSON(map[string]interface{}{
  9962. "order": order,
  9963. "order_info": order_info,
  9964. "patient": patient,
  9965. "admin_info": adminInfo,
  9966. "his_hospital": record,
  9967. "bedCostTotal": bedCostTotal,
  9968. "operationCostTotal": operationCostTotal,
  9969. "otherCostTotal": otherCostTotal,
  9970. "materialCostTotal": materialCostTotal,
  9971. "westernMedicineCostTotal": westernMedicineCostTotal,
  9972. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9973. "checkCostTotal": checkCostTotal,
  9974. "zhenChaCostTotal": zhenChaCostTotal,
  9975. "laboratoryCostTotal": laboratoryCostTotal,
  9976. "treatCostTotal": treatCostTotal,
  9977. })
  9978. }
  9979. }
  9980. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9981. page, _ := c.GetInt64("page")
  9982. limit, _ := c.GetInt64("limit")
  9983. keywords := c.GetString("keywords")
  9984. start_time := c.GetString("start_time")
  9985. end_time := c.GetString("end_time")
  9986. //clr_type := c.GetString("clr_type")
  9987. insutype := c.GetString("insutype")
  9988. timeLayout := "2006-01-02"
  9989. loc, _ := time.LoadLocation("Local")
  9990. var theStartTIme int64
  9991. if len(start_time) > 0 {
  9992. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9993. theStartTIme = theTime.Unix()
  9994. }
  9995. var theEndtTIme int64
  9996. if len(end_time) > 0 {
  9997. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9998. theEndtTIme = theTime.Unix()
  9999. }
  10000. if page <= 0 {
  10001. page = 1
  10002. }
  10003. if limit <= 0 {
  10004. limit = 10
  10005. }
  10006. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10007. c.ServeSuccessJSON(map[string]interface{}{
  10008. "total": total,
  10009. "list": list,
  10010. })
  10011. return
  10012. }
  10013. func (c *HisApiController) GetPutOnRecordList() {
  10014. page, _ := c.GetInt64("page")
  10015. limit, _ := c.GetInt64("limit")
  10016. keywords := c.GetString("keywords")
  10017. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10018. if page <= 0 {
  10019. page = 1
  10020. }
  10021. if limit <= 0 {
  10022. limit = 10
  10023. }
  10024. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10025. c.ServeSuccessJSON(map[string]interface{}{
  10026. "total": total,
  10027. "list": list,
  10028. })
  10029. return
  10030. }
  10031. func (c *HisApiController) GetCompareData() {
  10032. start_time := c.GetString("start_time")
  10033. end_time := c.GetString("end_time")
  10034. insutype := c.GetString("insutype")
  10035. clr_type := c.GetString("clr_type")
  10036. timeLayout := "2006-01-02"
  10037. loc, _ := time.LoadLocation("Local")
  10038. var theStartTIme int64
  10039. if len(start_time) > 0 {
  10040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10041. if err != nil {
  10042. theStartTIme = 0
  10043. }
  10044. theStartTIme = theTime.Unix()
  10045. }
  10046. var theEndtTIme int64
  10047. if len(end_time) > 0 {
  10048. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10049. if err != nil {
  10050. theEndtTIme = 0
  10051. }
  10052. theEndtTIme = theTime.Unix()
  10053. }
  10054. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10055. fmt.Println(err)
  10056. if err == nil {
  10057. c.ServeSuccessJSON(map[string]interface{}{
  10058. "list": formData,
  10059. })
  10060. } else {
  10061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10062. return
  10063. }
  10064. }
  10065. func (c *HisApiController) GetFaPiaoData() {
  10066. order_id, _ := c.GetInt64("order_id")
  10067. patient_id, _ := c.GetInt64("patient_id")
  10068. //number := c.GetString("number")
  10069. adminUser := c.GetAdminUserInfo()
  10070. order, _ := service.GetHisOrderByID(order_id)
  10071. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10072. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10073. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10074. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10075. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10076. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10077. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10078. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10079. var bedCostTotal float64 = 0 //床位总费
  10080. var bedCostSelfTotal float64 = 0 //床位自费
  10081. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10082. var operationCostTotal float64 = 0 //手术费
  10083. var operationCostSelfTotal float64 = 0 //手术费
  10084. var operationCostPartSelfTotal float64 = 0 //手术费
  10085. var otherCostTotal float64 = 0 //其他费用
  10086. var otherCostSelfTotal float64 = 0 //其他费用
  10087. var otherCostPartSelfTotal float64 = 0 //其他费用
  10088. var materialCostTotal float64 = 0 //材料费
  10089. var materialCostSelfTotal float64 = 0 //材料费
  10090. var materialCostPartSelfTotal float64 = 0 //材料费
  10091. var westernMedicineCostTotal float64 = 0 //西药费
  10092. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10093. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10094. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10095. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10096. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10097. var checkCostTotal float64 = 0 //检查费
  10098. var checkCostSelfTotal float64 = 0 //检查费
  10099. var checkCostPartSelfTotal float64 = 0 //检查费
  10100. var hiliCostTotal float64 = 0 //护理费
  10101. var hiliCostSelfTotal float64 = 0 //护理费
  10102. var hiliCostPartSelfTotal float64 = 0 //护理费
  10103. var laboratoryCostTotal float64 = 0 //化验费
  10104. var laboratoryCostSelfTotal float64 = 0 //化验费
  10105. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10106. var treatCostTotal float64 = 0 //治疗费用
  10107. var treatCostSelfTotal float64 = 0 //治疗费用
  10108. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10109. var zhenChaCostTotal float64 = 0 //其他费用
  10110. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10111. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10112. decimal.DivisionPrecision = 2
  10113. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10114. var balanceAccountsType int64
  10115. if his.ID > 0 {
  10116. balanceAccountsType = his.BalanceAccountsType
  10117. } else {
  10118. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10119. }
  10120. if balanceAccountsType == 2 {
  10121. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10122. for _, item := range orderInfos_two {
  10123. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10124. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10125. item.MedChrgitmType = "09"
  10126. }
  10127. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10128. if item.HisPrescriptionProject.Type == 2 {
  10129. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10130. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10131. case 0:
  10132. item.MedChrgitmType = "0"
  10133. break
  10134. case 1:
  10135. item.MedChrgitmType = "14"
  10136. break
  10137. case 2:
  10138. item.MedChrgitmType = "05"
  10139. break
  10140. case 3:
  10141. item.MedChrgitmType = "03"
  10142. break
  10143. case 4:
  10144. item.MedChrgitmType = "03"
  10145. break
  10146. case 5:
  10147. item.MedChrgitmType = "08"
  10148. break
  10149. case 6:
  10150. item.MedChrgitmType = "14"
  10151. break
  10152. case 7:
  10153. item.MedChrgitmType = "14"
  10154. break
  10155. case 8:
  10156. item.MedChrgitmType = "03"
  10157. break
  10158. case 9:
  10159. item.MedChrgitmType = "14"
  10160. break
  10161. case 10:
  10162. item.MedChrgitmType = "14"
  10163. break
  10164. case 11:
  10165. item.MedChrgitmType = "06"
  10166. break
  10167. case 12:
  10168. item.MedChrgitmType = "12"
  10169. break
  10170. case 13:
  10171. item.MedChrgitmType = "01"
  10172. break
  10173. case 14:
  10174. item.MedChrgitmType = "04"
  10175. break
  10176. case 15:
  10177. item.MedChrgitmType = "02"
  10178. break
  10179. }
  10180. } else {
  10181. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10182. case 1:
  10183. item.MedChrgitmType = "14"
  10184. break
  10185. case 2:
  10186. item.MedChrgitmType = "05"
  10187. break
  10188. case 3:
  10189. item.MedChrgitmType = "04"
  10190. break
  10191. case 4:
  10192. item.MedChrgitmType = "03"
  10193. break
  10194. case 5:
  10195. item.MedChrgitmType = "08"
  10196. break
  10197. case 6:
  10198. item.MedChrgitmType = "14"
  10199. break
  10200. case 7:
  10201. item.MedChrgitmType = "14"
  10202. break
  10203. case 8:
  10204. item.MedChrgitmType = "03"
  10205. break
  10206. case 9:
  10207. item.MedChrgitmType = "14"
  10208. break
  10209. }
  10210. }
  10211. } else if item.HisPrescriptionProject.Type == 3 {
  10212. item.MedChrgitmType = "08"
  10213. }
  10214. }
  10215. }
  10216. for _, item := range orderInfos_two {
  10217. fmt.Println(item.MedChrgitmType)
  10218. if item.MedChrgitmType == "07" { //床位费
  10219. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10220. hiliCostSelfTotal = hiliCostTotal
  10221. }
  10222. if item.MedChrgitmType == "01" { //床位费
  10223. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10224. bedCostSelfTotal = bedCostTotal
  10225. }
  10226. if item.MedChrgitmType == "02" { //诊察费
  10227. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10228. zhenChaCostSelfTotal = zhenChaCostTotal
  10229. }
  10230. if item.MedChrgitmType == "03" { //检查费
  10231. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10232. checkCostSelfTotal = checkCostTotal
  10233. }
  10234. if item.MedChrgitmType == "04" { //化验费
  10235. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10236. laboratoryCostSelfTotal = laboratoryCostTotal
  10237. }
  10238. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10239. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10240. treatCostSelfTotal = treatCostTotal
  10241. }
  10242. if item.MedChrgitmType == "06" { //手术费
  10243. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10244. operationCostSelfTotal = treatCostTotal
  10245. }
  10246. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10247. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10248. materialCostSelfTotal = materialCostTotal
  10249. }
  10250. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10251. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10252. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10253. }
  10254. if item.MedChrgitmType == "11" { //中成费
  10255. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10256. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10257. }
  10258. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10259. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10260. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10261. otherCostSelfTotal = otherCostTotal
  10262. }
  10263. } else {
  10264. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10265. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10266. otherCostSelfTotal = otherCostTotal
  10267. }
  10268. }
  10269. }
  10270. } else {
  10271. for _, item := range orderInfos {
  10272. if item.MedChrgitmType == "01" { //床位费
  10273. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10274. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10275. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10276. }
  10277. if item.MedChrgitmType == "02" { //诊察费
  10278. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10279. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10280. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10281. }
  10282. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10283. if item.MedChrgitmType == "03" { //检查费
  10284. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10285. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10286. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10287. }
  10288. } else {
  10289. if item.MedChrgitmType == "03" { //检查费
  10290. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10291. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10292. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10293. }
  10294. }
  10295. if item.MedChrgitmType == "04" { //化验费
  10296. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10297. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10298. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10299. }
  10300. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10301. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10302. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10303. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10304. }
  10305. if item.MedChrgitmType == "06" { //手术费
  10306. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10307. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10308. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10309. }
  10310. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10311. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10312. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10313. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10314. }
  10315. if item.MedChrgitmType == "07" { //护理
  10316. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10317. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10318. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10319. }
  10320. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10321. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10322. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10323. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10324. }
  10325. if item.MedChrgitmType == "11" { //中成费
  10326. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10327. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10328. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10329. }
  10330. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10331. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10332. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10333. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10334. }
  10335. }
  10336. }
  10337. timeLayout := "2006-01-02"
  10338. loc, _ := time.LoadLocation("Local")
  10339. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10340. if err != nil {
  10341. }
  10342. startRecordDateTime := startTime.Unix()
  10343. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10344. if err != nil {
  10345. }
  10346. endRecordDateTime := endTime.Unix()
  10347. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10348. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10349. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10350. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10351. c.ServeSuccessJSON(map[string]interface{}{
  10352. "charge_admin_name": charge_admin.UserName,
  10353. "order_number": order.Number, //业务流水号
  10354. "id_card_no": his.IdCardNo, //社会保障号
  10355. "patient": patient,
  10356. "department_name": department.Name, //科室
  10357. "number": his.Number, //门诊号
  10358. "date": order.SettleAccountsDate, //结算日期
  10359. "name": order.PsnName, //姓名
  10360. "gender": patient.Gender, //性别
  10361. "psn_cash_money": order.PsnCashPay, //个人支付
  10362. "pay_way": "门诊", //结算方式
  10363. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10364. "admin_user_name": admin.UserName, //收款员
  10365. "order": order,
  10366. "order_info": orderInfos_two,
  10367. "his": his,
  10368. "bedCostTotal": bedCostTotal,
  10369. "bedCostSelfTotal": bedCostSelfTotal,
  10370. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10371. "operationCostTotal": operationCostTotal,
  10372. "operationCostSelfTotal": operationCostSelfTotal,
  10373. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10374. "otherCostTotal": otherCostTotal,
  10375. "otherCostSelfTotal": otherCostSelfTotal,
  10376. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10377. "materialCostTotal": materialCostTotal,
  10378. "materialCostSelfTotal": materialCostSelfTotal,
  10379. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10380. "westernMedicineCostTotal": westernMedicineCostTotal,
  10381. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10382. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10383. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10384. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10385. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10386. "checkCostTotal": checkCostTotal,
  10387. "checkCostSelfTotal": checkCostSelfTotal,
  10388. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10389. "laboratoryCostTotal": laboratoryCostTotal,
  10390. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10391. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10392. "treatCostTotal": treatCostTotal,
  10393. "treatCostSelfTotal": treatCostSelfTotal,
  10394. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10395. "zhenChaCostTotal": zhenChaCostTotal,
  10396. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10397. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10398. "his_hospital_record": his_hospital_record,
  10399. "pre_pay_money": pre_pay_money,
  10400. "refund_sum": sum,
  10401. "doctor_info": doctor_info,
  10402. "hiliCostTotal": hiliCostTotal,
  10403. "hiliCostSelfTotal": hiliCostSelfTotal,
  10404. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10405. })
  10406. }
  10407. //func (c *HisApiController) GetFaPiaoDatas() {
  10408. // order_ids := c.GetString("order_ids")
  10409. // patient_id, _ := c.GetInt64("patient_id")
  10410. // adminUser := c.GetAdminUserInfo()
  10411. //
  10412. // orders := strings.Split(order_ids, ",")
  10413. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10414. //
  10415. // for _, item := range orders {
  10416. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10417. // order, _ := service.GetHisOrderByID(order_id)
  10418. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10419. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10420. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10421. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10422. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10423. //
  10424. // }
  10425. //
  10426. // var bedCostTotal float64 = 0 //床位总费
  10427. // var bedCostSelfTotal float64 = 0 //床位自费
  10428. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10429. //
  10430. // var operationCostTotal float64 = 0 //手术费
  10431. // var operationCostSelfTotal float64 = 0 //手术费
  10432. // var operationCostPartSelfTotal float64 = 0 //手术费
  10433. //
  10434. // var otherCostTotal float64 = 0 //其他费用
  10435. // var otherCostSelfTotal float64 = 0 //其他费用
  10436. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10437. //
  10438. // var materialCostTotal float64 = 0 //材料费
  10439. // var materialCostSelfTotal float64 = 0 //材料费
  10440. // var materialCostPartSelfTotal float64 = 0 //材料费
  10441. //
  10442. // var westernMedicineCostTotal float64 = 0 //西药费
  10443. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10444. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10445. //
  10446. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10447. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10448. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10449. //
  10450. // var checkCostTotal float64 = 0 //检查费
  10451. // var checkCostSelfTotal float64 = 0 //检查费
  10452. // var checkCostPartSelfTotal float64 = 0 //检查费
  10453. //
  10454. // var laboratoryCostTotal float64 = 0 //化验费
  10455. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10456. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10457. //
  10458. // var treatCostTotal float64 = 0 //治疗费用
  10459. // var treatCostSelfTotal float64 = 0 //治疗费用
  10460. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10461. //
  10462. // var zhenChaCostTotal float64 = 0 //其他费用
  10463. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10464. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10465. //
  10466. // decimal.DivisionPrecision = 2
  10467. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10468. //
  10469. // var balanceAccountsType int64
  10470. // if his.ID > 0 {
  10471. // balanceAccountsType = his.BalanceAccountsType
  10472. // } else {
  10473. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10474. // }
  10475. // if balanceAccountsType == 2 {
  10476. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10477. // for _, item := range orderInfos_two {
  10478. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10479. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10480. // item.MedChrgitmType = "09"
  10481. // }
  10482. //
  10483. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10484. // if item.HisPrescriptionProject.Type == 2 {
  10485. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10486. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10487. // case 0:
  10488. // item.MedChrgitmType = "0"
  10489. // break
  10490. // case 1:
  10491. // item.MedChrgitmType = "14"
  10492. // break
  10493. // case 2:
  10494. // item.MedChrgitmType = "05"
  10495. //
  10496. // break
  10497. // case 3:
  10498. // item.MedChrgitmType = "03"
  10499. //
  10500. // break
  10501. // case 4:
  10502. // item.MedChrgitmType = "03"
  10503. //
  10504. // break
  10505. // case 5:
  10506. // item.MedChrgitmType = "08"
  10507. //
  10508. // break
  10509. // case 6:
  10510. // item.MedChrgitmType = "14"
  10511. //
  10512. // break
  10513. // case 7:
  10514. // item.MedChrgitmType = "14"
  10515. //
  10516. // break
  10517. // case 8:
  10518. // item.MedChrgitmType = "03"
  10519. // break
  10520. // case 9:
  10521. // item.MedChrgitmType = "14"
  10522. // break
  10523. // case 10:
  10524. // item.MedChrgitmType = "14"
  10525. // break
  10526. // case 11:
  10527. // item.MedChrgitmType = "06"
  10528. // break
  10529. // case 12:
  10530. // item.MedChrgitmType = "12"
  10531. // break
  10532. // case 13:
  10533. // item.MedChrgitmType = "01"
  10534. // break
  10535. // case 14:
  10536. // item.MedChrgitmType = "04"
  10537. // break
  10538. // case 15:
  10539. // item.MedChrgitmType = "02"
  10540. // break
  10541. //
  10542. // }
  10543. //
  10544. // } else {
  10545. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10546. //
  10547. // case 1:
  10548. // item.MedChrgitmType = "14"
  10549. // break
  10550. // case 2:
  10551. // item.MedChrgitmType = "05"
  10552. //
  10553. // break
  10554. // case 3:
  10555. // item.MedChrgitmType = "03"
  10556. //
  10557. // break
  10558. // case 4:
  10559. // item.MedChrgitmType = "03"
  10560. //
  10561. // break
  10562. // case 5:
  10563. // item.MedChrgitmType = "08"
  10564. //
  10565. // break
  10566. // case 6:
  10567. // item.MedChrgitmType = "14"
  10568. //
  10569. // break
  10570. // case 7:
  10571. // item.MedChrgitmType = "14"
  10572. //
  10573. // break
  10574. // case 8:
  10575. // item.MedChrgitmType = "03"
  10576. // break
  10577. // case 9:
  10578. // item.MedChrgitmType = "14"
  10579. // break
  10580. //
  10581. // }
  10582. //
  10583. // }
  10584. //
  10585. // } else if item.HisPrescriptionProject.Type == 3 {
  10586. // item.MedChrgitmType = "08"
  10587. // }
  10588. // }
  10589. // }
  10590. //
  10591. // for _, item := range orderInfos_two {
  10592. // fmt.Println(item.MedChrgitmType)
  10593. // if item.MedChrgitmType == "01" { //床位费
  10594. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10595. // bedCostSelfTotal = bedCostTotal
  10596. // }
  10597. //
  10598. // if item.MedChrgitmType == "02" { //诊察费
  10599. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10600. // zhenChaCostSelfTotal = zhenChaCostTotal
  10601. // }
  10602. //
  10603. // if item.MedChrgitmType == "03" { //检查费
  10604. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10605. // checkCostSelfTotal = checkCostTotal
  10606. // }
  10607. //
  10608. // if item.MedChrgitmType == "04" { //化验费
  10609. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10610. // laboratoryCostSelfTotal = laboratoryCostTotal
  10611. // }
  10612. //
  10613. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10614. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10615. // treatCostSelfTotal = treatCostTotal
  10616. // }
  10617. //
  10618. // if item.MedChrgitmType == "06" { //手术费
  10619. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10620. // operationCostSelfTotal = treatCostTotal
  10621. // }
  10622. //
  10623. // if item.MedChrgitmType == "08" { //材料费
  10624. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10625. // materialCostSelfTotal = materialCostTotal
  10626. // }
  10627. //
  10628. // if item.MedChrgitmType == "09" { //西药费
  10629. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10630. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10631. // }
  10632. //
  10633. // if item.MedChrgitmType == "11" { //中成费
  10634. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10635. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10636. // }
  10637. //
  10638. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10639. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10640. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10641. // otherCostSelfTotal = otherCostTotal
  10642. // }
  10643. // } else {
  10644. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10645. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10646. // otherCostSelfTotal = otherCostTotal
  10647. // }
  10648. //
  10649. // }
  10650. //
  10651. // }
  10652. //
  10653. // } else {
  10654. // for _, item := range orderInfos {
  10655. // if item.MedChrgitmType == "01" { //床位费
  10656. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10657. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10658. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10659. // }
  10660. //
  10661. // if item.MedChrgitmType == "02" { //诊察费
  10662. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10663. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10664. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10665. // }
  10666. //
  10667. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10668. // if item.MedChrgitmType == "03" { //检查费
  10669. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10670. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10671. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10672. //
  10673. // }
  10674. // } else {
  10675. // if item.MedChrgitmType == "03" { //检查费
  10676. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10677. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10678. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10679. // }
  10680. //
  10681. // }
  10682. //
  10683. // if item.MedChrgitmType == "04" { //化验费
  10684. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10685. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10686. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10687. //
  10688. // }
  10689. //
  10690. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10691. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10692. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10693. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10694. //
  10695. // }
  10696. //
  10697. // if item.MedChrgitmType == "06" { //手术费
  10698. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10699. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10700. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10701. // }
  10702. //
  10703. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10704. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10705. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10706. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10707. // }
  10708. //
  10709. // if item.MedChrgitmType == "09" { //西药费
  10710. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10711. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10712. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10713. // }
  10714. //
  10715. // if item.MedChrgitmType == "11" { //中成费
  10716. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10717. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10718. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10719. // }
  10720. //
  10721. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10722. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10723. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10724. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10725. // }
  10726. //
  10727. // }
  10728. // }
  10729. // timeLayout := "2006-01-02"
  10730. // loc, _ := time.LoadLocation("Local")
  10731. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10732. // if err != nil {
  10733. // }
  10734. // startRecordDateTime := startTime.Unix()
  10735. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10736. // if err != nil {
  10737. // }
  10738. // endRecordDateTime := endTime.Unix()
  10739. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10740. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10741. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10742. //
  10743. // c.ServeSuccessJSON(map[string]interface{}{
  10744. // "order_number": order.Number, //业务流水号
  10745. // "id_card_no": his.IdCardNo, //社会保障号
  10746. // "department_name": department.Name, //科室
  10747. // "number": his.Number, //门诊号
  10748. // "date": order.SettleAccountsDate, //结算日期
  10749. // "name": order.PsnName, //姓名
  10750. // "gender": patient.Gender, //性别
  10751. // "psn_cash_money": order.PsnCashPay, //个人支付
  10752. // "pay_way": "门诊", //结算方式
  10753. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10754. // "admin_user_name": admin.UserName, //收款员
  10755. // "order": order,
  10756. // "order_info": orderInfos_two,
  10757. // "his": his,
  10758. // "bedCostTotal": bedCostTotal,
  10759. // "bedCostSelfTotal": bedCostSelfTotal,
  10760. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10761. // "operationCostTotal": operationCostTotal,
  10762. // "operationCostSelfTotal": operationCostSelfTotal,
  10763. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10764. // "otherCostTotal": otherCostTotal,
  10765. // "otherCostSelfTotal": otherCostSelfTotal,
  10766. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10767. // "materialCostTotal": materialCostTotal,
  10768. // "materialCostSelfTotal": materialCostSelfTotal,
  10769. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10770. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10771. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10772. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10773. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10774. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10775. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10776. // "checkCostTotal": checkCostTotal,
  10777. // "checkCostSelfTotal": checkCostSelfTotal,
  10778. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10779. // "laboratoryCostTotal": laboratoryCostTotal,
  10780. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10781. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10782. // "treatCostTotal": treatCostTotal,
  10783. // "treatCostSelfTotal": treatCostSelfTotal,
  10784. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10785. // "zhenChaCostTotal": zhenChaCostTotal,
  10786. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10787. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10788. // "his_hospital_record": his_hospital_record,
  10789. // "pre_pay_money": pre_pay_money,
  10790. // "refund_sum": sum,
  10791. // })
  10792. //
  10793. //}
  10794. func (this *HisApiController) GetIncomeStatisticsData() {
  10795. start_time := this.GetString("start_time")
  10796. end_time := this.GetString("end_time")
  10797. key_words := this.GetString("key_words")
  10798. limit, _ := this.GetInt64("limit")
  10799. page, _ := this.GetInt64("page")
  10800. if page <= 0 {
  10801. page = 1
  10802. }
  10803. if limit <= 0 {
  10804. limit = 10
  10805. }
  10806. statistics_type, _ := this.GetInt64("statistics_type")
  10807. admin := this.GetAdminUserInfo()
  10808. timeLayout := "2006-01-02"
  10809. loc, _ := time.LoadLocation("Local")
  10810. var theStartTIme int64
  10811. if len(start_time) > 0 {
  10812. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10813. if err != nil {
  10814. theStartTIme = 0
  10815. }
  10816. theStartTIme = theTime.Unix()
  10817. }
  10818. var theEndtTIme int64
  10819. if len(end_time) > 0 {
  10820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10821. if err != nil {
  10822. theEndtTIme = 0
  10823. }
  10824. theEndtTIme = theTime.Unix()
  10825. }
  10826. if statistics_type == 1 {
  10827. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10828. this.ServeSuccessJSON(map[string]interface{}{
  10829. "list": list,
  10830. "total": total,
  10831. })
  10832. } else {
  10833. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10834. this.ServeSuccessJSON(map[string]interface{}{
  10835. "list": list,
  10836. "total": total,
  10837. })
  10838. }
  10839. }
  10840. func (c *HisApiController) PostProjectInformation() {
  10841. adminUser := c.GetAdminUserInfo()
  10842. orgId := adminUser.CurrentOrgId
  10843. dataBody := make(map[string]interface{}, 0)
  10844. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10845. if err != nil {
  10846. utils.ErrorLog(err.Error())
  10847. return
  10848. }
  10849. utils.ErrorLog("%v", dataBody)
  10850. var projectList []*models.HisProject
  10851. var total_goods []interface{}
  10852. tempProjects := dataBody["projects"].([]interface{})
  10853. total_goods = tempProjects
  10854. for index, projectMap := range tempProjects {
  10855. projectM := projectMap.(map[string]interface{})
  10856. var project models.HisProject
  10857. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10858. utils.ErrorLog("project_name")
  10859. return
  10860. }
  10861. project_name, _ := projectM["project_name"].(string)
  10862. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10863. err_log := models.ExportErrLog{
  10864. LogType: 6,
  10865. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10866. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10867. Status: 1,
  10868. CreateTime: time.Now().Unix(),
  10869. UpdateTime: time.Now().Unix(),
  10870. ExportTime: time.Now().Unix(),
  10871. }
  10872. service.CreateExportErrLog(&err_log)
  10873. continue
  10874. }
  10875. project.ProjectName = project_name
  10876. prices := projectM["price"].(string)
  10877. price, _ := strconv.ParseFloat(prices, 64)
  10878. if price <= 0 { //名字为空则生成一条导入错误日志
  10879. err_log := models.ExportErrLog{
  10880. LogType: 6,
  10881. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10882. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10883. Status: 1,
  10884. CreateTime: time.Now().Unix(),
  10885. UpdateTime: time.Now().Unix(),
  10886. ExportTime: time.Now().Unix(),
  10887. }
  10888. service.CreateExportErrLog(&err_log)
  10889. continue
  10890. }
  10891. project.Price = price
  10892. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10893. utils.ErrorLog("unit_id")
  10894. return
  10895. }
  10896. unit := projectM["unit"].(string)
  10897. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10898. err_log := models.ExportErrLog{
  10899. LogType: 6,
  10900. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10901. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10902. Status: 1,
  10903. CreateTime: time.Now().Unix(),
  10904. UpdateTime: time.Now().Unix(),
  10905. ExportTime: time.Now().Unix(),
  10906. }
  10907. service.CreateExportErrLog(&err_log)
  10908. continue
  10909. }
  10910. project.Unit = unit
  10911. cost_classify := projectM["cost_classify"].(string)
  10912. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10913. err_log := models.ExportErrLog{
  10914. LogType: 6,
  10915. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10916. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10917. Status: 1,
  10918. CreateTime: time.Now().Unix(),
  10919. UpdateTime: time.Now().Unix(),
  10920. ExportTime: time.Now().Unix(),
  10921. }
  10922. service.CreateExportErrLog(&err_log)
  10923. continue
  10924. }
  10925. var costClassify = "费用类别"
  10926. var cost_classify_id int64
  10927. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10928. if len(cost_classify) != 0 {
  10929. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10930. if errcode == gorm.ErrRecordNotFound {
  10931. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10932. dataconfig := models.DictDataconfig{
  10933. ParentId: costClassifyConfig.ID,
  10934. Module: "system",
  10935. OrgId: orgId,
  10936. Name: cost_classify,
  10937. FieldName: "",
  10938. Value: costConfig.Value + 1,
  10939. CreatedTime: "",
  10940. UpdatedTime: "",
  10941. CreateUserId: adminUser.AdminUser.Id,
  10942. Status: 1,
  10943. Remark: "",
  10944. DeleteIdSystem: 0,
  10945. Title: "",
  10946. Content: "",
  10947. Order: 0,
  10948. Code: "",
  10949. }
  10950. service.CreatedDicConfig(&dataconfig)
  10951. }
  10952. }
  10953. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10954. for _, it := range costClassList {
  10955. if cost_classify == it.Name {
  10956. cost_classify_id = int64(it.Value)
  10957. }
  10958. }
  10959. project.CostClassify = cost_classify_id
  10960. executive_section := projectM["executive_section"].(string)
  10961. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10962. err_log := models.ExportErrLog{
  10963. LogType: 6,
  10964. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10965. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10966. Status: 1,
  10967. CreateTime: time.Now().Unix(),
  10968. UpdateTime: time.Now().Unix(),
  10969. ExportTime: time.Now().Unix(),
  10970. }
  10971. service.CreateExportErrLog(&err_log)
  10972. continue
  10973. }
  10974. if len(executive_section) != 0 {
  10975. //查找科室是否有内容
  10976. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10977. if errcodedepart == gorm.ErrRecordNotFound {
  10978. department := models.XtHisDepartment{
  10979. Name: executive_section,
  10980. Status: 1,
  10981. UserOrgId: adminUser.CurrentOrgId,
  10982. CreatedTime: time.Now().Unix(),
  10983. }
  10984. service.CreateDePartment(&department)
  10985. }
  10986. }
  10987. var executive_section_id int64
  10988. departMentList, _ := service.GetAllDepartMent(orgId)
  10989. for _, it := range departMentList {
  10990. if executive_section == it.Name {
  10991. executive_section_id = it.ID
  10992. }
  10993. }
  10994. project.ExecutiveSection = executive_section_id
  10995. medical_coverage := projectM["medical_coverage"].(string)
  10996. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10997. err_log := models.ExportErrLog{
  10998. LogType: 6,
  10999. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11000. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11001. Status: 1,
  11002. CreateTime: time.Now().Unix(),
  11003. UpdateTime: time.Now().Unix(),
  11004. ExportTime: time.Now().Unix(),
  11005. }
  11006. service.CreateExportErrLog(&err_log)
  11007. continue
  11008. }
  11009. var medicalCoverage = "医保等级"
  11010. var medical_coverage_id int64
  11011. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11012. if len(medical_coverage) != 0 {
  11013. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11014. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11015. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11016. dataconfig := models.DictDataconfig{
  11017. ParentId: medicalCoverageConfig.ID,
  11018. Module: "system",
  11019. OrgId: orgId,
  11020. Name: medical_coverage,
  11021. FieldName: "",
  11022. Value: medicalCoverageConfig.Value + 1,
  11023. CreatedTime: "",
  11024. UpdatedTime: "",
  11025. CreateUserId: adminUser.AdminUser.Id,
  11026. Status: 1,
  11027. Remark: "",
  11028. DeleteIdSystem: 0,
  11029. Title: "",
  11030. Content: "",
  11031. Order: 0,
  11032. Code: "",
  11033. }
  11034. service.CreatedDicConfig(&dataconfig)
  11035. }
  11036. }
  11037. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11038. for _, it := range medicalCoverageList {
  11039. if medical_coverage == it.Name {
  11040. medical_coverage_id = int64(it.Value)
  11041. }
  11042. }
  11043. project.MedicalCoverage = medical_coverage_id
  11044. pinyin := projectM["pinyin"].(string)
  11045. project.Pinyin = pinyin
  11046. wubi := projectM["wubi"].(string)
  11047. project.Wubi = wubi
  11048. statistical_classification := projectM["statistical_classification"].(string)
  11049. var statisticalClassification = "统计分类"
  11050. var statistical_classification_id int64
  11051. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11052. if len(statistical_classification) != 0 {
  11053. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11054. if classificationerrcodes == gorm.ErrRecordNotFound {
  11055. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11056. dataconfig := models.DictDataconfig{
  11057. ParentId: classiFication.ID,
  11058. Module: "system",
  11059. OrgId: orgId,
  11060. Name: statistical_classification,
  11061. FieldName: "",
  11062. Value: classiFicationConfig.Value + 1,
  11063. CreatedTime: "",
  11064. UpdatedTime: "",
  11065. CreateUserId: adminUser.AdminUser.Id,
  11066. Status: 1,
  11067. Remark: "",
  11068. DeleteIdSystem: 0,
  11069. Title: "",
  11070. Content: "",
  11071. Order: 0,
  11072. Code: "",
  11073. }
  11074. service.CreatedDicConfig(&dataconfig)
  11075. }
  11076. }
  11077. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11078. for _, it := range classiFicationList {
  11079. if statistical_classification == it.Name {
  11080. statistical_classification_id = int64(it.Value)
  11081. }
  11082. }
  11083. project.StatisticalClassification = statistical_classification_id
  11084. disease_directory := int64(projectM["disease_directory"].(float64))
  11085. project.DiseaseDirectory = disease_directory
  11086. is_record := int64(projectM["is_record"].(float64))
  11087. project.IsRecord = is_record
  11088. medical_code := projectM["medical_code"].(string)
  11089. project.MedicalCode = medical_code
  11090. tube_color := projectM["tube_color"].(string)
  11091. var tubeColor = "试管颜色"
  11092. var tube_color_id int64
  11093. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11094. if len(tube_color) != 0 {
  11095. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11096. if errcodetube == gorm.ErrRecordNotFound {
  11097. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11098. dataconfig := models.DictDataconfig{
  11099. ParentId: tubeColorConfig.ID,
  11100. Module: "system",
  11101. OrgId: orgId,
  11102. Name: tube_color,
  11103. FieldName: "",
  11104. Value: tubeConfig.Value + 1,
  11105. CreatedTime: "",
  11106. UpdatedTime: "",
  11107. CreateUserId: adminUser.AdminUser.Id,
  11108. Status: 1,
  11109. Remark: "",
  11110. DeleteIdSystem: 0,
  11111. Title: "",
  11112. Content: "",
  11113. Order: 0,
  11114. Code: "",
  11115. }
  11116. service.CreatedDicConfig(&dataconfig)
  11117. }
  11118. }
  11119. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11120. for _, it := range tubeColorList {
  11121. if tube_color == it.Name {
  11122. tube_color_id = int64(it.Value)
  11123. }
  11124. }
  11125. project.TubeColor = tube_color_id
  11126. single_dose := projectM["single_dose"].(string)
  11127. project.SingleDose = single_dose
  11128. execution_frequency := projectM["execution_frequency"].(string)
  11129. project.ExecutionFrequency = execution_frequency
  11130. delivery_way := projectM["delivery_way"].(string)
  11131. project.DeliveryWay = delivery_way
  11132. number_days := projectM["number_days"].(string)
  11133. project.NumberDays = number_days
  11134. total := projectM["total"].(string)
  11135. project.Total = total
  11136. medical_status := int64(projectM["medical_status"].(float64))
  11137. project.MedicalStatus = medical_status
  11138. category := int64(projectM["category"].(float64))
  11139. project.Category = category
  11140. specail_project := int64(projectM["specail_project"].(float64))
  11141. project.SpecailProject = specail_project
  11142. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11143. project.SocialSecurityDirectoryCode = social_security_directory_code
  11144. remark := projectM["remark"].(string)
  11145. project.Remark = remark
  11146. record_date := projectM["record_date"].(string)
  11147. timeLayout := "2006-01-02"
  11148. loc, _ := time.LoadLocation("Local")
  11149. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11150. project.RecordDate = theTime.Unix()
  11151. projectList = append(projectList, &project)
  11152. }
  11153. export_time := time.Now().Unix()
  11154. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11155. if len(projectList) > 0 {
  11156. for _, item := range projectList {
  11157. hans := item.ProjectName // 要转换的汉字字符串
  11158. // 创建一个拼音转换器
  11159. p := pinyin.NewArgs()
  11160. // 将汉字转为拼音
  11161. pinyinSlice := pinyin.Pinyin(hans, p)
  11162. // 输出拼音
  11163. fmt.Println("Pinyin:", pinyinSlice)
  11164. // 获取首字母
  11165. firstLetter := ""
  11166. for _, py := range pinyinSlice {
  11167. if len(py) > 0 {
  11168. firstLetter += string(py[0][0])
  11169. }
  11170. }
  11171. item.FirstLetter = firstLetter
  11172. project := models.HisProject{
  11173. ProjectName: item.ProjectName,
  11174. Price: item.Price,
  11175. Unit: item.Unit,
  11176. CostClassify: item.CostClassify,
  11177. ExecutiveSection: item.ExecutiveSection,
  11178. MedicalCoverage: item.MedicalCoverage,
  11179. UserOrgId: orgId,
  11180. Status: 1,
  11181. CreatedTime: time.Now().Unix(),
  11182. Pinyin: item.Pinyin,
  11183. Wubi: item.Wubi,
  11184. StatisticalClassification: item.StatisticalClassification,
  11185. DiseaseDirectory: item.DiseaseDirectory,
  11186. IsRecord: item.IsRecord,
  11187. MedicalCode: item.MedicalCode,
  11188. TubeColor: item.TubeColor,
  11189. SingleDose: item.SingleDose,
  11190. DeliveryWay: item.DeliveryWay,
  11191. NumberDays: item.NumberDays,
  11192. Total: item.Total,
  11193. Category: item.Category,
  11194. MedicalStatus: item.MedicalStatus,
  11195. SpecailProject: item.SpecailProject,
  11196. RecordDate: item.RecordDate,
  11197. Remark: item.Remark,
  11198. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11199. ExecutionFrequency: item.ExecutionFrequency,
  11200. FirstLetter: item.FirstLetter,
  11201. }
  11202. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11203. if errcodeproject == gorm.ErrRecordNotFound {
  11204. service.CreateProjectInfomation(&project)
  11205. } else if errcodeproject == nil {
  11206. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11207. }
  11208. log := models.ExportLog{
  11209. LogType: 6,
  11210. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11211. TotalNum: int64(len(total_goods)),
  11212. FailNum: int64(len(errLogs)),
  11213. SuccessNum: int64(len(projectList)),
  11214. CreateTime: time.Now().Unix(),
  11215. UpdateTime: time.Now().Unix(),
  11216. ExportTime: export_time,
  11217. Status: 1,
  11218. }
  11219. service.CreateExportLog(&log)
  11220. c.ServeSuccessJSON(map[string]interface{}{
  11221. "msg": "导入成功",
  11222. "total_num": len(total_goods),
  11223. "success_num": len(projectList),
  11224. "fail_num": int64(len(errLogs)),
  11225. })
  11226. }
  11227. } else {
  11228. log := models.ExportLog{
  11229. LogType: 6,
  11230. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11231. TotalNum: int64(len(total_goods)),
  11232. FailNum: int64(len(errLogs)),
  11233. SuccessNum: int64(len(projectList)),
  11234. CreateTime: time.Now().Unix(),
  11235. UpdateTime: time.Now().Unix(),
  11236. ExportTime: export_time,
  11237. Status: 1,
  11238. }
  11239. service.CreateExportLog(&log)
  11240. c.ServeSuccessJSON(map[string]interface{}{
  11241. "msg": "导入成功",
  11242. "total_num": len(total_goods),
  11243. "success_num": len(projectList),
  11244. "fail_num": int64(len(errLogs)),
  11245. })
  11246. }
  11247. }
  11248. //func (this *HisApiController) EditProjectInformation(){
  11249. //
  11250. // id, _ := this.GetInt64("id")
  11251. // project_team := this.GetString("project_team")
  11252. // price := this.GetString("price")
  11253. // price_float, _ := strconv.ParseFloat(price, 64)
  11254. // pinyin := this.GetString("pinyin")
  11255. // wubi := this.GetString("wubi")
  11256. // tube_color, _ := this.GetInt64("tube_color")
  11257. // team_type, _ := this.GetInt64("team_type")
  11258. // remark := this.GetString("remark")
  11259. // ids := this.GetString("ids")
  11260. // item_id := this.GetString("item_id")
  11261. // projectTeam := models.XtHisProjectTeam{
  11262. // ProjectTeam: project_team,
  11263. // Price: price_float,
  11264. // Pinyin: pinyin,
  11265. // Wubi: wubi,
  11266. // TubeColor: tube_color,
  11267. // TeamType: team_type,
  11268. // Remark: remark,
  11269. // ProjectId: ids,
  11270. // ItemId: item_id,
  11271. // }
  11272. //
  11273. //
  11274. // dataBody := make(map[string]interface{}, 0)
  11275. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11276. // if err != nil {
  11277. // utils.ErrorLog(err.Error())
  11278. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11279. // return
  11280. // }
  11281. //
  11282. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11283. //
  11284. //
  11285. // if err != nil {
  11286. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11287. // return
  11288. // }
  11289. //
  11290. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11291. // infos, _ := dataBody["info"].([]interface{})
  11292. // if len(infos) > 0 {
  11293. // var ids []string
  11294. //
  11295. // for _, item := range infos {
  11296. // items := item.(map[string]interface{})
  11297. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11298. // utils.ErrorLog("id")
  11299. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11300. // return
  11301. // }
  11302. // id := int64(items["id"].(float64))
  11303. //
  11304. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11305. // utils.ErrorLog("type")
  11306. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11307. // return
  11308. // }
  11309. // types := int64(items["type"].(float64))
  11310. //
  11311. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11312. // utils.ErrorLog("number")
  11313. // }
  11314. //
  11315. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11316. //
  11317. // projectList := models.XtHisProjectList{
  11318. // Number: number,
  11319. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11320. // ProjectId: id,
  11321. // Status: 1,
  11322. // CreatedTime: time.Now().Unix(),
  11323. // UpdatedTime: time.Now().Unix(),
  11324. // TeamId: projectTeam.ID,
  11325. // Type: types,
  11326. // }
  11327. // list := projectList
  11328. //
  11329. // service.CreateProjectList(&list)
  11330. //
  11331. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11332. //
  11333. // }
  11334. // ids_str := strings.Join(ids, ",")
  11335. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11336. // service.SaveProjectTeam(&projectTeam)
  11337. // this.ServeSuccessJSON(map[string]interface{}{
  11338. // "projectTeam": projectTeam,
  11339. // })
  11340. // }
  11341. // }
  11342. //}
  11343. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11344. name := c.GetString("name")
  11345. mode_id, _ := c.GetInt64("mode", 0)
  11346. types, _ := c.GetInt64("type", 0)
  11347. patient_id, _ := c.GetInt64("patient_id", 0)
  11348. types = 1
  11349. adminInfo := c.GetAdminUserInfo()
  11350. template := &models.HisPrescriptionTemplate{
  11351. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11352. PatientId: patient_id,
  11353. Type: types,
  11354. Status: 1,
  11355. Ctime: time.Now().Unix(),
  11356. Mtime: time.Now().Unix(),
  11357. Name: name,
  11358. Mode: mode_id,
  11359. }
  11360. dataBody := make(map[string]interface{}, 0)
  11361. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11362. if err != nil {
  11363. utils.ErrorLog(err.Error())
  11364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11365. return
  11366. }
  11367. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11368. //如果已经存在记录则删除处方
  11369. if template_one.ID > 0 {
  11370. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11371. var ids []int64
  11372. var org_id int64
  11373. for _, item := range ps {
  11374. org_id = c.GetAdminUserInfo().CurrentOrgId
  11375. ids = append(ids, item.ID)
  11376. }
  11377. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11378. if err2 == nil {
  11379. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11380. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11381. if len(prescriptions) > 0 {
  11382. for _, item := range prescriptions {
  11383. items := item.(map[string]interface{})
  11384. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11385. utils.ErrorLog("type")
  11386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11387. return
  11388. }
  11389. types := int64(items["type"].(float64))
  11390. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11391. utils.ErrorLog("med_type")
  11392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11393. return
  11394. }
  11395. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11396. ctime := time.Now().Unix()
  11397. prescription := &models.HisPrescriptionInfoTemplate{
  11398. PatientId: patient_id,
  11399. UserOrgId: adminInfo.CurrentOrgId,
  11400. Ctime: ctime,
  11401. Mtime: ctime,
  11402. Type: types,
  11403. Modifier: adminInfo.AdminUser.Id,
  11404. Creator: adminInfo.AdminUser.Id,
  11405. Status: 1,
  11406. PTemplateId: template_one.ID,
  11407. MedType: med_type,
  11408. }
  11409. service.CreateHisPrescriptionInfoTemplate(prescription)
  11410. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11411. advices := items["advices"].([]interface{})
  11412. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11413. ctime := time.Now().Unix()
  11414. mtime := ctime
  11415. if len(advices) > 0 {
  11416. for _, advice := range advices {
  11417. var s models.HisPrescriptionAdviceTemplate
  11418. s.PrescriptionId = prescription.ID
  11419. s.AdviceType = 2
  11420. s.StopState = 2
  11421. s.ExecutionState = 2
  11422. s.Status = 1
  11423. s.UserOrgId = adminInfo.CurrentOrgId
  11424. s.CreatedTime = ctime
  11425. s.UpdatedTime = mtime
  11426. s.PatientId = patient_id
  11427. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11428. if errcode > 0 {
  11429. c.ServeFailJSONWithSGJErrorCode(errcode)
  11430. return
  11431. }
  11432. service.CreateHisPrescriptionAdviceTemplate(&s)
  11433. }
  11434. }
  11435. }
  11436. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11437. projects := items["project"].([]interface{})
  11438. if len(projects) > 0 {
  11439. for _, project := range projects {
  11440. var p models.HisPrescriptionProjectTemplate
  11441. p.PrescriptionId = prescription.ID
  11442. p.Ctime = time.Now().Unix()
  11443. p.Mtime = time.Now().Unix()
  11444. p.PatientId = patient_id
  11445. p.UserOrgId = adminInfo.CurrentOrgId
  11446. p.Status = 1
  11447. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11448. if errcode > 0 {
  11449. c.ServeFailJSONWithSGJErrorCode(errcode)
  11450. return
  11451. }
  11452. service.CreateHisPrescriptionProjectTemplate(&p)
  11453. }
  11454. }
  11455. }
  11456. }
  11457. c.ServeSuccessJSON(map[string]interface{}{
  11458. "msg": "创建成功",
  11459. })
  11460. }
  11461. }
  11462. } else {
  11463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11464. return
  11465. }
  11466. } else {
  11467. err3 := service.CreateHisPrescriptionTemplate(template)
  11468. if err3 == nil {
  11469. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11470. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11471. if len(prescriptions) > 0 {
  11472. for _, item := range prescriptions {
  11473. items := item.(map[string]interface{})
  11474. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11475. utils.ErrorLog("type")
  11476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11477. return
  11478. }
  11479. types := int64(items["type"].(float64))
  11480. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11481. utils.ErrorLog("med_type")
  11482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11483. return
  11484. }
  11485. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11486. ctime := time.Now().Unix()
  11487. prescription := &models.HisPrescriptionInfoTemplate{
  11488. PatientId: patient_id,
  11489. UserOrgId: adminInfo.CurrentOrgId,
  11490. Ctime: ctime,
  11491. Mtime: ctime,
  11492. Type: types,
  11493. Modifier: adminInfo.AdminUser.Id,
  11494. Creator: adminInfo.AdminUser.Id,
  11495. Status: 1,
  11496. PTemplateId: template.ID,
  11497. MedType: med_type,
  11498. }
  11499. service.CreateHisPrescriptionInfoTemplate(prescription)
  11500. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11501. advices := items["advices"].([]interface{})
  11502. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11503. ctime := time.Now().Unix()
  11504. mtime := ctime
  11505. if len(advices) > 0 {
  11506. for _, advice := range advices {
  11507. var s models.HisPrescriptionAdviceTemplate
  11508. s.PrescriptionId = prescription.ID
  11509. s.AdviceType = 2
  11510. s.StopState = 2
  11511. s.ExecutionState = 2
  11512. s.Status = 1
  11513. s.UserOrgId = adminInfo.CurrentOrgId
  11514. s.CreatedTime = ctime
  11515. s.UpdatedTime = mtime
  11516. s.PatientId = patient_id
  11517. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11518. if errcode > 0 {
  11519. c.ServeFailJSONWithSGJErrorCode(errcode)
  11520. return
  11521. }
  11522. service.CreateHisPrescriptionAdviceTemplate(&s)
  11523. }
  11524. }
  11525. }
  11526. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11527. projects := items["project"].([]interface{})
  11528. if len(projects) > 0 {
  11529. for _, project := range projects {
  11530. var p models.HisPrescriptionProjectTemplate
  11531. p.PrescriptionId = prescription.ID
  11532. p.Ctime = time.Now().Unix()
  11533. p.Mtime = time.Now().Unix()
  11534. p.PatientId = patient_id
  11535. p.UserOrgId = adminInfo.CurrentOrgId
  11536. p.Status = 1
  11537. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11538. if errcode > 0 {
  11539. c.ServeFailJSONWithSGJErrorCode(errcode)
  11540. return
  11541. }
  11542. service.CreateHisPrescriptionProjectTemplate(&p)
  11543. }
  11544. }
  11545. }
  11546. }
  11547. c.ServeSuccessJSON(map[string]interface{}{
  11548. "msg": "创建成功",
  11549. })
  11550. }
  11551. }
  11552. } else {
  11553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11554. return
  11555. }
  11556. }
  11557. }
  11558. func (c *HisApiController) PreSettle() {
  11559. id, _ := c.GetInt64("id")
  11560. record_time := c.GetString("record_time")
  11561. his_patient_id, _ := c.GetInt64("his_patient_id")
  11562. timeLayout := "2006-01-02"
  11563. loc, _ := time.LoadLocation("Local")
  11564. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11565. diagnosis_id := c.GetString("diagnosis")
  11566. sick_type, _ := c.GetInt64("sick_type")
  11567. reg_type, _ := c.GetInt64("p_type")
  11568. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11569. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11570. if err != nil {
  11571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11572. return
  11573. }
  11574. recordDateTime := theTime.Unix()
  11575. adminUser := c.GetAdminUserInfo()
  11576. var prescriptions []*models.HisPrescription
  11577. var start_time int64
  11578. var end_time int64
  11579. ids_str := c.GetString("ids")
  11580. ids_arr := strings.Split(ids_str, ",")
  11581. fmt.Println(reg_type)
  11582. if settle_accounts_type == 1 { //日结
  11583. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11584. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11585. } else {
  11586. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11587. }
  11588. fmt.Println(prescriptions)
  11589. } else { //月结
  11590. start_time_str := c.GetString("start_time")
  11591. end_time_str := c.GetString("end_time")
  11592. timeLayout := "2006-01-02"
  11593. loc, _ := time.LoadLocation("Local")
  11594. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11595. if err != nil {
  11596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11597. return
  11598. }
  11599. recordStartTime := theStartTime.Unix()
  11600. start_time = recordStartTime
  11601. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11602. if err != nil {
  11603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11604. return
  11605. }
  11606. recordEndTime := theEndTime.Unix()
  11607. end_time = recordEndTime
  11608. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11609. }
  11610. if reg_type == 1111 || reg_type == 1112 {
  11611. reg_type = 11
  11612. }
  11613. timestamp := time.Now().Unix()
  11614. tempTime := time.Unix(timestamp, 0)
  11615. timeFormat := tempTime.Format("20060102150405")
  11616. chrgBchno := rand.Intn(100000) + 10000
  11617. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11618. strconv.FormatInt(his.PatientId, 10)
  11619. var ids []int64
  11620. for _, item := range prescriptions {
  11621. ids = append(ids, item.ID)
  11622. }
  11623. fmt.Println(ids)
  11624. var total float64
  11625. for _, item := range prescriptions {
  11626. fmt.Println(item)
  11627. if item.Type == 1 { //药品
  11628. for _, subItem := range item.HisDoctorAdviceInfo {
  11629. total = total + (subItem.Price * subItem.PrescribingNumber)
  11630. }
  11631. }
  11632. if item.Type == 2 { //项目
  11633. for _, subItem := range item.HisPrescriptionProject {
  11634. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11635. total = total + (subItem.Price * cnt)
  11636. }
  11637. }
  11638. for _, subItem := range item.HisAdditionalCharge {
  11639. total = total + (subItem.Price * float64(subItem.Count))
  11640. }
  11641. }
  11642. allTotal := fmt.Sprintf("%.2f", total)
  11643. totals, _ := strconv.ParseFloat(allTotal, 64)
  11644. order := &models.HisOrder{
  11645. UserOrgId: adminUser.CurrentOrgId,
  11646. HisPatientId: his.ID,
  11647. PatientId: id,
  11648. SettleAccountsDate: recordDateTime,
  11649. Ctime: time.Now().Unix(),
  11650. Mtime: time.Now().Unix(),
  11651. Status: 1,
  11652. OrderStatus: 1,
  11653. MdtrtId: his.Number,
  11654. Number: chrg_bchno,
  11655. MedfeeSumamt: totals,
  11656. SettleEndTime: end_time,
  11657. SettleStartTime: start_time,
  11658. SettleType: settle_accounts_type,
  11659. PsnPartAmt: totals,
  11660. PsnCashPay: totals,
  11661. PType: 2,
  11662. IsPre: 1,
  11663. MedType: strconv.Itoa(int(reg_type)),
  11664. Diagnosis: diagnosis_id,
  11665. }
  11666. err = service.CreateOrder(order)
  11667. if err != nil {
  11668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11669. return
  11670. }
  11671. var customs []*Custom
  11672. for _, item := range prescriptions {
  11673. fmt.Println(item.Type)
  11674. if item.Type == 1 { //药品
  11675. for _, subItem := range item.HisDoctorAdviceInfo {
  11676. cus := &Custom{
  11677. AdviceId: subItem.ID,
  11678. ProjectId: 0,
  11679. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11680. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11681. FeedetlSn: subItem.FeedetlSn,
  11682. Price: fmt.Sprintf("%.2f", subItem.Price),
  11683. MedListCodg: subItem.MedListCodg,
  11684. Type: 1,
  11685. }
  11686. customs = append(customs, cus)
  11687. }
  11688. }
  11689. if item.Type == 2 { //项目
  11690. for _, subItem := range item.HisPrescriptionProject {
  11691. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11692. cus := &Custom{
  11693. AdviceId: 0,
  11694. ProjectId: subItem.ID,
  11695. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11696. Cut: fmt.Sprintf("%.2f", cnt),
  11697. FeedetlSn: subItem.FeedetlSn,
  11698. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11699. MedListCodg: subItem.MedListCodg,
  11700. Type: 2,
  11701. }
  11702. customs = append(customs, cus)
  11703. }
  11704. }
  11705. for _, item := range item.HisAdditionalCharge {
  11706. cus := &Custom{
  11707. ItemId: item.ID,
  11708. AdviceId: 0,
  11709. ProjectId: 0,
  11710. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11711. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11712. FeedetlSn: item.FeedetlSn,
  11713. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11714. MedListCodg: item.XtHisAddtionConfig.Code,
  11715. Type: 3,
  11716. }
  11717. customs = append(customs, cus)
  11718. }
  11719. }
  11720. fmt.Println(customs)
  11721. for _, item := range customs {
  11722. var advice_id int64 = 0
  11723. var project_id int64 = 0
  11724. var item_id int64 = 0
  11725. var types int64 = 0
  11726. if item.Type == 1 {
  11727. advice_id = item.AdviceId
  11728. project_id = 0
  11729. item_id = 0
  11730. } else if item.Type == 2 {
  11731. advice_id = 0
  11732. item_id = 0
  11733. project_id = item.ProjectId
  11734. } else if item.Type == 3 {
  11735. advice_id = 0
  11736. item_id = item.ItemId
  11737. project_id = 0
  11738. }
  11739. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11740. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11741. pric, _ := strconv.ParseFloat(item.Price, 32)
  11742. info := &models.HisOrderInfo{
  11743. OrderNumber: order.Number,
  11744. UploadDate: time.Now().Unix(),
  11745. AdviceId: advice_id,
  11746. DetItemFeeSumamt: detItemFeeSumamt,
  11747. Cnt: cut,
  11748. Pric: pric,
  11749. PatientId: id,
  11750. Status: 1,
  11751. Mtime: time.Now().Unix(),
  11752. Ctime: time.Now().Unix(),
  11753. UserOrgId: adminUser.CurrentOrgId,
  11754. HisPatientId: his.ID,
  11755. OrderId: order.ID,
  11756. ProjectId: project_id,
  11757. Type: types,
  11758. ItemId: item_id,
  11759. }
  11760. service.CreateOrderInfo(info)
  11761. }
  11762. his.SickType = sick_type
  11763. service.UpdataHisPateint(&his)
  11764. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11765. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11766. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11767. if err == nil {
  11768. c.ServeSuccessJSON(map[string]interface{}{
  11769. "msg": "结算成功",
  11770. })
  11771. }
  11772. }
  11773. type CustomOrderInfo struct {
  11774. Name string
  11775. Spec string
  11776. Unit string
  11777. Count float64
  11778. Price float64
  11779. Total float64
  11780. }
  11781. func (c *HisApiController) GetPrivateExpensesInfo() {
  11782. order_id, _ := c.GetInt64("id", 0)
  11783. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11784. order, _ := service.GetHisOrderByID(order_id)
  11785. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11786. if order.ID == 0 {
  11787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11788. return
  11789. }
  11790. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11791. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11792. org_id := c.GetAdminUserInfo().CurrentOrgId
  11793. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11794. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11795. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11796. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11797. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11798. //var orderInfos_four []*models.HisOrderInfoTwo
  11799. //for _, item := range orderInfos_three {
  11800. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11801. // item.HisPrescriptionProject.IsCheckTeam = 1
  11802. // orderInfos_four = append(orderInfos_four, item)
  11803. //
  11804. // }
  11805. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11806. // item.HisPrescriptionProject.IsCheckTeam = 2
  11807. // orderInfos_two = append(orderInfos_two, item)
  11808. // }
  11809. //}
  11810. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11811. //var cus_slice []CustomOrderInfo
  11812. //for _, item := range new_order_info {
  11813. // var cus CustomOrderInfo
  11814. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11815. // cus.Unit = ""
  11816. // cus.Spec = ""
  11817. // var total float64
  11818. // for _, subItem := range orderInfos_four {
  11819. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11820. // total = total + subItem.DetItemFeeSumamt
  11821. // fmt.Println(subItem.DetItemFeeSumamt)
  11822. // }
  11823. // }
  11824. // cus.Count = 1
  11825. // cus.Total = total
  11826. // cus_slice = append(cus_slice, cus)
  11827. //}
  11828. orderInfos = append(orderInfos, orderInfos_two...)
  11829. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11830. //orderInfos = append(orderInfos, orderInfos_three...)
  11831. //}/**/
  11832. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11833. c.ServeSuccessJSON(map[string]interface{}{
  11834. "order": order,
  11835. "order_info": orderInfos,
  11836. "patient": patient,
  11837. "admin_info": adminInfo,
  11838. "his": his,
  11839. "current_admin": role,
  11840. "org_config": miConfig,
  11841. //"new_order_info": cus_slice,
  11842. })
  11843. }
  11844. func (this *HisApiController) ChangeMedType() {
  11845. med_type := this.GetString("med_type")
  11846. old_med_type := this.GetString("old_med_type")
  11847. ids := this.GetString("ids")
  11848. settle_type, _ := this.GetInt64("settle_type")
  11849. start_time := this.GetString("start_time")
  11850. end_time := this.GetString("end_time")
  11851. ids_arr := strings.Split(ids, ",")
  11852. if settle_type == 1 { //日结
  11853. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11854. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11855. prescription.MedType = med_type
  11856. err := service.SaveHisPrescriptionTwo(&prescription)
  11857. if err == nil {
  11858. this.ServeSuccessJSON(map[string]interface{}{
  11859. "msg": "修改成功",
  11860. })
  11861. } else {
  11862. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11863. return
  11864. }
  11865. } else if settle_type == 2 {
  11866. timeLayout := "2006-01-02"
  11867. loc, _ := time.LoadLocation("Local")
  11868. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11869. if err != nil {
  11870. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11871. return
  11872. }
  11873. recordStartTime := theStartTime.Unix()
  11874. start_time_timestamp := recordStartTime
  11875. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11876. if err != nil {
  11877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11878. return
  11879. }
  11880. recordEndTime := theEndTime.Unix()
  11881. end_time_timestamp := recordEndTime
  11882. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11883. if updateErr == nil {
  11884. this.ServeSuccessJSON(map[string]interface{}{
  11885. "msg": "修改成功",
  11886. })
  11887. } else {
  11888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11889. return
  11890. }
  11891. }
  11892. }
  11893. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11894. patient_id, _ := c.GetInt64("patient_id")
  11895. his_patient_id, _ := c.GetInt64("his_patient_id")
  11896. record_date := c.GetString("record_date")
  11897. start_time := c.GetString("start_time")
  11898. end_time := c.GetString("end_time")
  11899. order_status, _ := c.GetInt64("type", 0)
  11900. p_type, _ := c.GetInt64("p_type", 0)
  11901. order_id, _ := c.GetInt64("order_id", 0)
  11902. timeLayout := "2006-01-02"
  11903. loc, _ := time.LoadLocation("Local")
  11904. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11905. if err != nil {
  11906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11907. return
  11908. }
  11909. recordDateTime := theTime.Unix()
  11910. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11911. if err != nil {
  11912. }
  11913. startRecordDateTime := startTime.Unix()
  11914. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11915. if err != nil {
  11916. }
  11917. endRecordDateTime := endTime.Unix()
  11918. admin := c.GetAdminUserInfo()
  11919. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11920. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11921. order, _ := service.GetHisOrderByID(order_id)
  11922. var monthPrescriptions []*models.HisPrescription
  11923. if order_status == 1 || order_status == 0 {
  11924. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11925. } else if order_status == 2 {
  11926. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11927. }
  11928. var settle_total float64
  11929. for _, item := range monthPrescriptions {
  11930. if len(item.HisPrescriptionProject) > 0 {
  11931. for _, subItem := range item.HisPrescriptionProject {
  11932. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11933. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11934. settle_total = settle_total + total
  11935. }
  11936. }
  11937. if len(item.HisDoctorAdviceInfo) > 0 {
  11938. for _, subItem := range item.HisDoctorAdviceInfo {
  11939. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11940. settle_total = settle_total + total
  11941. }
  11942. }
  11943. }
  11944. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11945. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11946. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11947. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11948. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11949. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11950. //获取所有科室信息
  11951. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11952. var dia string
  11953. for _, item := range month_p_info {
  11954. if len(dia) == 0 {
  11955. dia = item.Diagnosis
  11956. } else {
  11957. dia = dia + "," + item.Diagnosis
  11958. }
  11959. }
  11960. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11961. dia_arr = removeEmptyStrings(dia_arr)
  11962. c.ServeSuccessJSON(map[string]interface{}{
  11963. "his_info": his_patient_info,
  11964. "xt_info": xt_patient_info,
  11965. "case_history": case_history,
  11966. "info": patientPrescriptionInfo,
  11967. "last_info": lastPatientPrescriptionInfo,
  11968. "month_prescriptions": monthPrescriptions,
  11969. "order": order,
  11970. "doctors": doctors,
  11971. "department": department,
  11972. "settle_total": settle_total,
  11973. "dia_arr": dia_arr,
  11974. })
  11975. return
  11976. }
  11977. func removeEmptyStrings(input []string) []string {
  11978. var output []string
  11979. for _, s := range input {
  11980. if s != "" {
  11981. output = append(output, s)
  11982. }
  11983. }
  11984. return output
  11985. }
  11986. func removeDuplicates(input []string) []string {
  11987. seen := make(map[string]bool)
  11988. output := []string{}
  11989. for _, s := range input {
  11990. if _, exists := seen[s]; !exists {
  11991. seen[s] = true
  11992. output = append(output, s)
  11993. }
  11994. }
  11995. return output
  11996. }
  11997. func (c *HisApiController) GetHisMonthPatientInfo() {
  11998. patient_id, _ := c.GetInt64("patient_id")
  11999. his_patient_id, _ := c.GetInt64("his_patient_id")
  12000. record_date := c.GetString("record_date")
  12001. number := c.GetString("number")
  12002. start_time := c.GetString("start_time")
  12003. end_time := c.GetString("end_time")
  12004. p_type, _ := c.GetInt64("p_type")
  12005. timeLayout := "2006-01-02"
  12006. loc, _ := time.LoadLocation("Local")
  12007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12008. if err != nil {
  12009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12010. return
  12011. }
  12012. recordDateTime := theTime.Unix()
  12013. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12014. if err != nil {
  12015. }
  12016. startRecordDateTime := startTime.Unix()
  12017. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12018. if err != nil {
  12019. }
  12020. endRecordDateTime := endTime.Unix()
  12021. admin := c.GetAdminUserInfo()
  12022. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12023. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12024. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12025. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12026. var settle_total float64
  12027. for _, item := range monthPrescriptions {
  12028. if len(item.HisPrescriptionProject) > 0 {
  12029. for _, subItem := range item.HisPrescriptionProject {
  12030. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12031. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12032. settle_total = settle_total + total
  12033. }
  12034. }
  12035. if len(item.HisDoctorAdviceInfo) > 0 {
  12036. for _, subItem := range item.HisDoctorAdviceInfo {
  12037. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12038. settle_total = settle_total + total
  12039. }
  12040. }
  12041. }
  12042. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12043. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12044. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12045. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12046. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12047. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12048. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12049. //获取所有科室信息
  12050. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12051. c.ServeSuccessJSON(map[string]interface{}{
  12052. "his_info": his_patient_info,
  12053. "xt_info": xt_patient_info,
  12054. "case_history": case_history,
  12055. "info": patientPrescriptionInfo,
  12056. "month_prescriptions": monthPrescriptions,
  12057. "order": order,
  12058. "doctors": doctors,
  12059. "department": department,
  12060. "count": count,
  12061. "drugStockConfig": drugStockConfig,
  12062. "last_info": lastPatientPrescriptionInfo,
  12063. "settle_total": settle_total,
  12064. })
  12065. return
  12066. }
  12067. func (c *HisApiController) GetAllOrder() {
  12068. org_id := c.GetAdminUserInfo().CurrentOrgId
  12069. orders, _ := service.GetNewHisOrderList(org_id)
  12070. c.ServeSuccessJSON(map[string]interface{}{
  12071. "order": orders,
  12072. })
  12073. return
  12074. }
  12075. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12076. newArr = make([]*models.HisOrderInfoTwo, 0)
  12077. for i := 0; i < len(arr); i++ {
  12078. repeat := false
  12079. for j := i + 1; j < len(arr); j++ {
  12080. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12081. repeat = true
  12082. break
  12083. }
  12084. }
  12085. if !repeat {
  12086. newArr = append(newArr, arr[i])
  12087. }
  12088. }
  12089. return
  12090. }
  12091. // 修改处方退库操作 参数传修改之前的处方数据
  12092. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12093. if advice.ExecutionState == 1 {
  12094. //查询该病人该药品是否有库存记录
  12095. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12096. if errcode == gorm.ErrRecordNotFound {
  12097. } else {
  12098. //退库
  12099. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12100. if advice.PrescribingNumberUnit == drug.MinUnit {
  12101. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12102. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12103. //退库
  12104. warehouseInfo := models.DrugWarehouseInfo{
  12105. StockMinNumber: prescribingNumber,
  12106. }
  12107. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12108. operation_time := time.Now().Unix()
  12109. creater := advice.AdviceDoctor
  12110. ctime := time.Now().Unix()
  12111. timeStr := time.Now().Format("2006-01-02")
  12112. timeArr := strings.Split(timeStr, "-")
  12113. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12114. total = total + 1
  12115. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12116. cancelStock := models.DrugCancelStock{
  12117. OrderNumber: orderNumber,
  12118. OperaTime: operation_time,
  12119. OrgId: advice.UserOrgId,
  12120. Creater: creater,
  12121. Ctime: ctime,
  12122. Status: 1,
  12123. ReturnTime: advice.AdviceDate,
  12124. Dealer: info.Dealer,
  12125. Manufacturer: info.Manufacturer,
  12126. Type: 1,
  12127. }
  12128. service.AddSigleDrugCancelStock(&cancelStock)
  12129. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12130. dealer, _ := service.GetDealerById(info.Dealer)
  12131. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12132. cancelStockInfo := models.DrugCancelStockInfo{
  12133. OrderNumber: cancelInfo.OrderNumber,
  12134. CancelStockId: cancelInfo.ID,
  12135. DrugId: info.DrugId,
  12136. Count: info.Count,
  12137. Status: 1,
  12138. Ctime: ctime,
  12139. OrgId: advice.UserOrgId,
  12140. Type: 1,
  12141. Manufacturer: manufactureName.ManufacturerName,
  12142. Dealer: dealer.DealerName,
  12143. Total: 0,
  12144. RetailPrice: info.RetailPrice,
  12145. RetailTotalPrice: info.RetailTotalPrice,
  12146. Price: info.Price,
  12147. RegisterAccount: "",
  12148. Remark: info.Remark,
  12149. BatchNumber: info.BatchNumber,
  12150. MaxUnit: info.CountUnit,
  12151. ProductDate: info.ProductDate,
  12152. ExpiryDate: info.ExpiryDate,
  12153. BatchNumberId: info.WarehouseInfoId,
  12154. }
  12155. flow := models.DrugFlow{
  12156. WarehousingId: 0,
  12157. DrugId: info.DrugId,
  12158. Number: "",
  12159. BatchNumber: info.BatchNumber,
  12160. Count: info.Count,
  12161. UserOrgId: advice.UserOrgId,
  12162. PatientId: 0,
  12163. SystemTime: ctime,
  12164. ConsumableType: 4,
  12165. IsSys: 0,
  12166. WarehousingOrder: "",
  12167. WarehouseOutId: 0,
  12168. WarehouseOutOrderNumber: "",
  12169. IsEdit: 0,
  12170. CancelStockId: cancelStock.ID,
  12171. CancelOrderNumber: cancelStock.OrderNumber,
  12172. Manufacturer: info.Manufacturer,
  12173. Dealer: info.Dealer,
  12174. Creator: advice.UserOrgId,
  12175. UpdateCreator: 0,
  12176. Status: 1,
  12177. Ctime: time.Now().Unix(),
  12178. Mtime: 0,
  12179. Price: info.Price,
  12180. WarehousingDetailId: 0,
  12181. WarehouseOutDetailId: 0,
  12182. CancelOutDetailId: 0,
  12183. ExpireDate: info.ExpiryDate,
  12184. ProductDate: info.ProductDate,
  12185. MaxUnit: info.CountUnit,
  12186. MinUnit: "",
  12187. }
  12188. service.CreatedCancelStock(cancelStockInfo)
  12189. service.CreateDrugFlowOne(flow)
  12190. } else {
  12191. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12192. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12193. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12194. warehouseInfo := models.DrugWarehouseInfo{
  12195. StockMinNumber: prescribingNumber,
  12196. }
  12197. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12198. }
  12199. operation_time := time.Now().Unix()
  12200. creater := advice.AdviceDoctor
  12201. ctime := time.Now().Unix()
  12202. timeStr := time.Now().Format("2006-01-02")
  12203. timeArr := strings.Split(timeStr, "-")
  12204. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12205. total = total + 1
  12206. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12207. cancelStock := models.DrugCancelStock{
  12208. OrderNumber: orderNumber,
  12209. OperaTime: operation_time,
  12210. OrgId: advice.UserOrgId,
  12211. Creater: creater,
  12212. Ctime: ctime,
  12213. Status: 1,
  12214. ReturnTime: advice.AdviceDate,
  12215. Dealer: info.Dealer,
  12216. Manufacturer: info.Manufacturer,
  12217. Type: 1,
  12218. }
  12219. service.AddSigleDrugCancelStock(&cancelStock)
  12220. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12221. dealer, _ := service.GetDealerById(info.Dealer)
  12222. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12223. cancelStockInfo := models.DrugCancelStockInfo{
  12224. OrderNumber: cancelInfo.OrderNumber,
  12225. CancelStockId: cancelInfo.ID,
  12226. DrugId: info.DrugId,
  12227. Count: info.Count,
  12228. Status: 1,
  12229. Ctime: ctime,
  12230. OrgId: advice.UserOrgId,
  12231. Type: 1,
  12232. Manufacturer: manufactureName.ManufacturerName,
  12233. Dealer: dealer.DealerName,
  12234. Total: 0,
  12235. RetailPrice: info.RetailPrice,
  12236. RetailTotalPrice: info.RetailTotalPrice,
  12237. Price: info.Price,
  12238. RegisterAccount: "",
  12239. Remark: info.Remark,
  12240. BatchNumber: info.BatchNumber,
  12241. MaxUnit: info.CountUnit,
  12242. ProductDate: info.ProductDate,
  12243. ExpiryDate: info.ExpiryDate,
  12244. BatchNumberId: info.WarehouseInfoId,
  12245. }
  12246. flow := models.DrugFlow{
  12247. WarehousingId: 0,
  12248. DrugId: info.DrugId,
  12249. Number: "",
  12250. BatchNumber: info.BatchNumber,
  12251. Count: info.Count,
  12252. UserOrgId: advice.UserOrgId,
  12253. PatientId: 0,
  12254. SystemTime: ctime,
  12255. ConsumableType: 4,
  12256. IsSys: 0,
  12257. WarehousingOrder: "",
  12258. WarehouseOutId: 0,
  12259. WarehouseOutOrderNumber: "",
  12260. IsEdit: 0,
  12261. CancelStockId: cancelStock.ID,
  12262. CancelOrderNumber: cancelStock.OrderNumber,
  12263. Manufacturer: info.Manufacturer,
  12264. Dealer: info.Dealer,
  12265. Creator: advice.AdviceDoctor,
  12266. UpdateCreator: 0,
  12267. Status: 1,
  12268. Ctime: time.Now().Unix(),
  12269. Mtime: 0,
  12270. Price: info.Price,
  12271. WarehousingDetailId: 0,
  12272. WarehouseOutDetailId: 0,
  12273. CancelOutDetailId: 0,
  12274. ExpireDate: info.ExpiryDate,
  12275. ProductDate: info.ProductDate,
  12276. MaxUnit: info.CountUnit,
  12277. MinUnit: "",
  12278. }
  12279. service.CreatedCancelStock(cancelStockInfo)
  12280. service.CreateDrugFlowOne(flow)
  12281. }
  12282. }
  12283. }
  12284. return err
  12285. }
  12286. func (this *HisApiController) DeleteNCDS() {
  12287. id, _ := this.GetInt64("id", 0)
  12288. if id > 0 {
  12289. service.DeletePsnNCDSRecordById(id)
  12290. this.ServeSuccessJSON(map[string]interface{}{
  12291. "msg": "删除成功",
  12292. })
  12293. } else {
  12294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12295. return
  12296. }
  12297. }
  12298. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12299. id, _ := c.GetInt64("id")
  12300. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12301. c.ServeSuccessJSON(map[string]interface{}{
  12302. "advice": advice,
  12303. })
  12304. return
  12305. }
  12306. func (c *HisApiController) GetHisMonthChargePatientList() {
  12307. record_date := c.GetString("record_date")
  12308. start_time := c.GetString("start_time")
  12309. end_time := c.GetString("end_time")
  12310. timeLayout := "2006-01-02"
  12311. loc, _ := time.LoadLocation("Local")
  12312. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12313. if err != nil {
  12314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12315. return
  12316. }
  12317. if err != nil {
  12318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12319. return
  12320. }
  12321. recordDateTime := theTime.Unix()
  12322. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12323. if err != nil {
  12324. }
  12325. startRecordDateTime := startTime.Unix()
  12326. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12327. if err != nil {
  12328. }
  12329. endRecordDateTime := endTime.Unix()
  12330. adminInfo := c.GetAdminUserInfo()
  12331. var tempMonthChargePatients []*service.MonthChargePatients
  12332. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12333. for _, item := range tempPatients {
  12334. //过滤没有处方的
  12335. if len(item.HisPrescription) == 0 {
  12336. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12337. }
  12338. }
  12339. c.ServeSuccessJSON(map[string]interface{}{
  12340. "list": tempMonthChargePatients,
  12341. })
  12342. }
  12343. // PrescriptionDifference 医嘱数量差值结构体
  12344. type PrescriptionDrugDifference struct {
  12345. DrugID int64 //基础库药品id
  12346. ID int64 //医嘱id
  12347. Difference float64 //差值
  12348. Unit string //单位
  12349. }
  12350. type PrescriptionGoodDifference struct {
  12351. GoodID int64 //基础库项目耗材id
  12352. ID int64 //医嘱id
  12353. Difference int64 //差值
  12354. Unit string //单位
  12355. Type int64 //类型
  12356. }
  12357. type EditCustomData struct {
  12358. adviceList []*models.HisDoctorAdviceInfo
  12359. projectList []*models.HisPrescriptionProject
  12360. }
  12361. type SrcCustomData struct {
  12362. adviceList []*models.HisDoctorAdviceInfo
  12363. projectList []*models.HisPrescriptionProject
  12364. }
  12365. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12366. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12367. differences := make([]*PrescriptionDrugDifference, 0)
  12368. // 创建一个 map 来存储第一个切片中的药品信息
  12369. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12370. for _, advice := range firstPrescription {
  12371. firstMap[advice.DrugId] = advice
  12372. }
  12373. // 遍历第二个切片中的药品信息,并比较数量差值
  12374. for _, advice := range secondPrescription {
  12375. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12376. diff := &PrescriptionDrugDifference{
  12377. DrugID: advice.DrugId,
  12378. ID: firstAdvice.ID,
  12379. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12380. Unit: firstAdvice.PrescribingNumberUnit,
  12381. }
  12382. differences = append(differences, diff)
  12383. }
  12384. }
  12385. return differences
  12386. }
  12387. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12388. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12389. differences := make([]*PrescriptionGoodDifference, 0)
  12390. // 创建一个 map 来存储第一个切片中的耗材信息
  12391. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12392. for _, good := range firstPrescription {
  12393. firstMap[good.ProjectId] = good
  12394. }
  12395. // 遍历第二个切片中的耗材信息,并比较数量差值
  12396. for _, good := range secondPrescription {
  12397. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12398. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12399. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12400. diff := &PrescriptionGoodDifference{
  12401. GoodID: good.ProjectId,
  12402. ID: firstGood.ID,
  12403. Difference: count - firstCount,
  12404. Unit: firstGood.Unit,
  12405. Type: firstGood.Type,
  12406. }
  12407. differences = append(differences, diff)
  12408. }
  12409. }
  12410. return differences
  12411. }
  12412. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12413. var adviceList []*models.HisDoctorAdviceInfo
  12414. var projectList []*models.HisPrescriptionProject
  12415. var advice_ids []int64
  12416. var project_ids []int64
  12417. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12418. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12419. //var tempPrescription *models.HisPrescriptionProjectscription
  12420. if len(prescriptions) > 0 {
  12421. for _, item := range prescriptions {
  12422. items := item.(map[string]interface{})
  12423. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12424. advices := items["advices"].([]interface{})
  12425. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12426. groupNo := int64(0)
  12427. ctime := time.Now().Unix()
  12428. mtime := ctime
  12429. if len(advices) > 0 {
  12430. for _, advice := range advices {
  12431. var s models.HisDoctorAdviceInfo
  12432. s.AdviceType = 2
  12433. s.StopState = 2
  12434. s.ExecutionState = 2
  12435. s.Status = 1
  12436. s.Groupno = groupNo
  12437. s.CreatedTime = ctime
  12438. s.UpdatedTime = mtime
  12439. s.IsSettle = 2
  12440. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12441. //存储切片中
  12442. if s.ID > 0 {
  12443. advice_ids = append(advice_ids, s.ID)
  12444. adviceList = append(adviceList, &s)
  12445. }
  12446. }
  12447. }
  12448. }
  12449. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12450. projects := items["project"].([]interface{})
  12451. if len(projects) > 0 {
  12452. for _, project := range projects {
  12453. var p models.HisPrescriptionProject
  12454. p.Ctime = time.Now().Unix()
  12455. p.Mtime = time.Now().Unix()
  12456. p.Status = 1
  12457. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12458. if p.ID > 0 {
  12459. project_ids = append(project_ids, p.ID)
  12460. projectList = append(projectList, &p)
  12461. }
  12462. }
  12463. }
  12464. }
  12465. }
  12466. }
  12467. }
  12468. editCustomData.projectList = projectList
  12469. editCustomData.adviceList = adviceList
  12470. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12471. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12472. srcCustomData.adviceList = list
  12473. srcCustomData.projectList = list2
  12474. return
  12475. }