his_api_controller.go 543KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1214. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1215. //获取当前用户的信息
  1216. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1217. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1218. //获取所有科室信息
  1219. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1220. //var aa []service.PatientThree
  1221. noElementsSlice := make([]service.PatientThree, 0)
  1222. c.ServeSuccessJSON(map[string]interface{}{
  1223. "list": patients,
  1224. "list_two": patients_two,
  1225. "list_three": noElementsSlice,
  1226. "info": adminUserInfo,
  1227. "doctors": doctors,
  1228. "department": department,
  1229. })
  1230. }
  1231. type CustomTemplate struct {
  1232. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1233. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1234. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1235. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1236. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1237. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1238. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1239. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1240. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1241. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1242. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1243. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1244. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1245. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1246. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1247. }
  1248. func (c *HisApiController) GetHisPatientInfo() {
  1249. patient_id, _ := c.GetInt64("patient_id")
  1250. his_patient_id, _ := c.GetInt64("his_patient_id")
  1251. record_date := c.GetString("record_date")
  1252. number := c.GetString("number")
  1253. //start_time := c.GetString("start_time")
  1254. //end_time := c.GetString("end_time")
  1255. p_type, _ := c.GetInt64("p_type")
  1256. timeLayout := "2006-01-02"
  1257. loc, _ := time.LoadLocation("Local")
  1258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1259. if err != nil {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. recordDateTime := theTime.Unix()
  1264. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //startRecordDateTime := startTime.Unix()
  1269. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1270. //if err != nil {
  1271. //
  1272. //}
  1273. //endRecordDateTime := endTime.Unix()
  1274. admin := c.GetAdminUserInfo()
  1275. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1277. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1278. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1279. var prescriptions []*models.HisPrescription
  1280. var last_prescriptions []*models.HisPrescription
  1281. var sch_prescriptions []CustomTemplate
  1282. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1283. if p_type == 1 { //住院
  1284. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1285. for _, item := range prescriptions {
  1286. for _, subItem := range item.HisDoctorAdviceInfo {
  1287. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1288. if info.RetailPrice > 0 {
  1289. subItem.Drug.MinPrice = info.RetailPrice
  1290. }
  1291. }
  1292. }
  1293. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1294. } else { //门诊
  1295. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1296. for _, item := range prescriptions {
  1297. for _, subItem := range item.HisDoctorAdviceInfo {
  1298. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1299. if info.RetailPrice > 0 {
  1300. subItem.Drug.MinPrice = info.RetailPrice
  1301. }
  1302. }
  1303. }
  1304. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1305. }
  1306. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1307. if sch.ID > 0 {
  1308. var week string
  1309. t := time.Now()
  1310. switch t.Weekday().String() {
  1311. case "Monday":
  1312. week = "周一"
  1313. break
  1314. case "Tuesday":
  1315. week = "周二"
  1316. break
  1317. case "Wednesday":
  1318. week = "周三"
  1319. break
  1320. case "Thursday":
  1321. week = "周四"
  1322. break
  1323. case "Friday":
  1324. week = "周五"
  1325. break
  1326. case "Saturday":
  1327. week = "周六"
  1328. break
  1329. case "Sunday":
  1330. week = "周日"
  1331. break
  1332. }
  1333. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1334. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1335. //根据推送频率组装新的数组
  1336. for _, item := range temp_sch_prescriptions {
  1337. var cus CustomTemplate
  1338. cus.ID = item.ID
  1339. cus.UserOrgId = item.UserOrgId
  1340. cus.PatientId = item.PatientId
  1341. cus.MedType = item.MedType
  1342. cus.RecordDate = item.RecordDate
  1343. cus.Type = item.Type
  1344. cus.PType = item.PType
  1345. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1346. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1347. if subItem.FrequencyType == 1 { //每次必推
  1348. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1349. }
  1350. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1351. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1352. }
  1353. if subItem.FrequencyType == 2 { //按照天数频率
  1354. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1355. now := p.Unix()
  1356. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1357. dayStr2 := "-" + dayStr
  1358. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1359. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1360. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1361. if len(advices) == 0 {
  1362. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1363. }
  1364. }
  1365. }
  1366. }
  1367. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1368. if subItem.Type == 2 {
  1369. if subItem.XtHisProject.MedicalStatus != 1 {
  1370. if subItem.FrequencyType == 1 {
  1371. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1372. }
  1373. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1374. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1375. }
  1376. if subItem.FrequencyType == 2 {
  1377. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1378. now := p.Unix()
  1379. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1380. dayStr2 := "-" + dayStr
  1381. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1382. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1383. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1384. if len(projects) == 0 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. }
  1388. }
  1389. } else if subItem.Type == 3 {
  1390. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1391. if subItem.FrequencyType == 1 {
  1392. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1393. }
  1394. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1395. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1396. }
  1397. if subItem.FrequencyType == 2 {
  1398. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1399. now := p.Unix()
  1400. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1401. dayStr2 := "-" + dayStr
  1402. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1403. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1404. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1405. if len(projects) == 0 {
  1406. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. sch_prescriptions = append(sch_prescriptions, cus)
  1413. }
  1414. for _, item := range sch_prescriptions {
  1415. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1416. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1417. }
  1418. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1419. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1420. }
  1421. }
  1422. }
  1423. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1424. if config.ID > 0 && config.IsOpen == 1 {
  1425. for _, item := range sch_prescriptions {
  1426. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1427. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1428. if info.RetailPrice > 0 {
  1429. subItem.Drug.MinPrice = info.RetailPrice
  1430. if admin.CurrentOrgId != 10598 {
  1431. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1432. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if config.ID > 0 && config.IsOpen == 1 {
  1439. for _, item := range sch_prescriptions {
  1440. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1441. if subItem.Type == 3 {
  1442. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1443. if info.Price > 0 {
  1444. subItem.GoodInfo.PackingPrice = info.Price
  1445. if admin.CurrentOrgId != 10598 {
  1446. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1447. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1455. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1456. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1457. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1458. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1459. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1460. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1461. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1462. //获取所有科室信息
  1463. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1464. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1465. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1466. c.ServeSuccessJSON(map[string]interface{}{
  1467. "his_info": his_patient_info,
  1468. "xt_info": xt_patient_info,
  1469. "prescription": prescriptions,
  1470. "case_history": case_history,
  1471. "info": patientPrescriptionInfo,
  1472. //"month_prescriptions": monthPrescriptions,
  1473. "order": order,
  1474. "doctors": doctors,
  1475. "department": department,
  1476. "sch_prescriptions": sch_prescriptions,
  1477. "last_prescriptions": last_prescriptions,
  1478. "schedule": sch,
  1479. "count": count,
  1480. "drugStockConfig": drugStockConfig,
  1481. "last_info": lastPatientPrescriptionInfo,
  1482. "befor": beforThrity,
  1483. "LastCaseHistory": LastCaseHistory,
  1484. })
  1485. return
  1486. }
  1487. func (c *HisApiController) GetHisPrescriptionConfig() {
  1488. adminInfo := c.GetAdminUserInfo()
  1489. //获取医嘱模版
  1490. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1491. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1492. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1493. //获取所有基础药
  1494. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1495. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1496. if config.ID > 0 && config.IsOpen == 1 {
  1497. for _, item := range drugs {
  1498. var index = 0
  1499. for _, subItem := range item.OtherDrugWarehouseInfo {
  1500. if index == 0 {
  1501. index = index + 1
  1502. if subItem.RetailPrice > 0 {
  1503. item.MinPrice = subItem.RetailPrice
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1510. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1511. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1512. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1513. //获取所有科室信息
  1514. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1515. //获取诊断信息
  1516. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1517. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1518. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1519. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1520. //获取是否开启保存耗材出库的开关
  1521. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1522. c.ServeSuccessJSON(map[string]interface{}{
  1523. "drugs": drugs,
  1524. "advices_template": advices,
  1525. "drugways": drugways,
  1526. "efs": efs,
  1527. "doctors": doctors,
  1528. "department": department,
  1529. "sick": sick,
  1530. "additions": additions,
  1531. "diagnose": diagnose,
  1532. "manufacturers": manufacturers,
  1533. "goodOutOpen": goodOutOpen,
  1534. "patientDiagnose": patientDiagnose,
  1535. })
  1536. }
  1537. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1538. //获取所有基础药
  1539. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1540. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1541. if config.ID > 0 && config.IsOpen == 1 {
  1542. for _, item := range drugs {
  1543. var index = 0
  1544. for _, subItem := range item.OtherDrugWarehouseInfo {
  1545. if index == 0 {
  1546. index = index + 1
  1547. if subItem.RetailPrice > 0 {
  1548. item.MinPrice = subItem.RetailPrice
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1555. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1556. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1557. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1558. //获取所有科室信息
  1559. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1560. //获取诊断信息
  1561. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1562. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1563. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1564. //获取是否开启保存耗材出库的开关
  1565. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1566. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1567. c.ServeSuccessJSON(map[string]interface{}{
  1568. "drugs": drugs,
  1569. "advices_template": advices,
  1570. "drugways": drugways,
  1571. "efs": efs,
  1572. "doctors": doctors,
  1573. "department": department,
  1574. "sick": sick,
  1575. "additions": additions,
  1576. "diagnose": diagnose,
  1577. "manufacturers": manufacturers,
  1578. "goodOutOpen": goodOutOpen,
  1579. "patientDiagnose": patientDiagnose,
  1580. })
  1581. }
  1582. }
  1583. func (c *HisApiController) CreateHisPrescription() {
  1584. record_date := c.GetString("record_date")
  1585. patient_id, _ := c.GetInt64("patient_id")
  1586. reg_type, _ := c.GetInt64("reg_type")
  1587. diagnose := c.GetString("diagnose")
  1588. sick_type, _ := c.GetInt64("sick_type")
  1589. sick_history := c.GetString("sick_history")
  1590. doctor_id, _ := c.GetInt64("doctor", 0)
  1591. department, _ := c.GetInt64("department", 0)
  1592. his_patient_id, _ := c.GetInt64("his_patient_id")
  1593. p_type, _ := c.GetInt64("p_type")
  1594. patient_diagnose := c.GetString("patient_diagnose")
  1595. dataBody := make(map[string]interface{}, 0)
  1596. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1597. if err != nil {
  1598. utils.ErrorLog(err.Error())
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. //edit, src := GetCompareData(dataBody)
  1603. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1604. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1605. //fmt.Println(drugResult)
  1606. //fmt.Println(goodResult)
  1607. timeLayout := "2006-01-02"
  1608. loc, _ := time.LoadLocation("Local")
  1609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1610. if err != nil {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1612. return
  1613. }
  1614. adminInfo := c.GetAdminUserInfo()
  1615. recordDateTime := theTime.Unix()
  1616. //查询默认出库仓库库存
  1617. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1618. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1619. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1620. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1621. if len(lists) == 1 {
  1622. his_patient_id = lists[0].ID
  1623. }
  1624. }
  1625. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1626. //自动出库的开关开启
  1627. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1628. //自动出库
  1629. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1630. //耗材保存处方出库
  1631. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1633. //已发药和已收费限制逻辑
  1634. isMidicine := false
  1635. isCharge := false
  1636. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1637. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1638. if len(prescriptions) > 0 {
  1639. for _, item := range prescriptions {
  1640. items := item.(map[string]interface{})
  1641. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1642. utils.ErrorLog("id")
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. id := int64(items["id"].(float64))
  1647. if id > 0 {
  1648. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1649. if err != nil {
  1650. if new_prescription.OrderStatus == 4 {
  1651. isCharge = true
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. if isMidicine == true {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1660. return
  1661. }
  1662. if isCharge == true {
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1664. return
  1665. }
  1666. // 开始主事务
  1667. db := service.XTWriteDB()
  1668. tx := db.Begin()
  1669. // 在函数结束时处理事务回滚
  1670. defer func() {
  1671. if r := recover(); r != nil {
  1672. tx.Rollback()
  1673. }
  1674. }()
  1675. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1676. //药品发药出库
  1677. if pharmacyConfig.IsOpen == 1 {
  1678. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1679. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1680. if len(prescriptions) > 0 {
  1681. for _, item := range prescriptions {
  1682. items := item.(map[string]interface{})
  1683. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1684. advices := items["advices"].([]interface{})
  1685. if len(advices) > 0 {
  1686. for _, advice := range advices {
  1687. var drug_id int64
  1688. var prescribing_number float64
  1689. var prescribingNumberUnit string
  1690. var adviceId int64
  1691. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1692. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1693. }
  1694. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1695. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1696. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1697. }
  1698. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1699. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1700. }
  1701. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1702. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1703. }
  1704. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1705. if drug.ID == 0 {
  1706. tx.Rollback()
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. return
  1709. }
  1710. //查询药品的所有库存
  1711. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1712. var total_count int64
  1713. for _, it := range list {
  1714. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1715. }
  1716. totals := strconv.FormatInt(total_count, 10)
  1717. //查询该药品是否存在开药记录
  1718. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1719. //新增处方盘点库存是否充足
  1720. if advicelist.ID == 0 {
  1721. all_count, _ := strconv.ParseFloat(totals, 64)
  1722. if prescribingNumberUnit == drug.MinUnit {
  1723. if drug.IsUse != 1 {
  1724. if drug.IsProject == 0 || drug.IsProject == 2 {
  1725. if all_count == 0 {
  1726. tx.Rollback()
  1727. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1728. return
  1729. }
  1730. if prescribing_number > all_count {
  1731. tx.Rollback()
  1732. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1733. return
  1734. }
  1735. }
  1736. }
  1737. }
  1738. if prescribingNumberUnit == drug.MaxUnit {
  1739. num := prescribing_number * float64(drug.MinNumber)
  1740. if drug.IsUse != 1 {
  1741. if drug.IsProject == 0 || drug.IsProject == 2 {
  1742. if all_count == 0 {
  1743. tx.Rollback()
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1745. return
  1746. }
  1747. if num > all_count {
  1748. tx.Rollback()
  1749. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1750. return
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }
  1756. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1757. //不使用保存处方出库
  1758. if drugOutConfig.IsOpen != 1 {
  1759. //修改处方
  1760. for _, advice := range advices {
  1761. var drug_id int64
  1762. var prescribing_number float64
  1763. var prescribingNumberUnit string
  1764. var prescribingNumber string
  1765. var adviceId int64
  1766. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1767. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1768. }
  1769. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1770. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1771. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1772. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1773. }
  1774. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1775. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1776. }
  1777. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1778. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1779. }
  1780. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1781. if drug.ID == 0 {
  1782. tx.Rollback()
  1783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1784. return
  1785. }
  1786. //查询药品的所有库存
  1787. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1788. var total_count int64
  1789. for _, it := range list {
  1790. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1791. }
  1792. totals := strconv.FormatInt(total_count, 10)
  1793. //查询该药品是否存在开药记录
  1794. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1795. //新增处方
  1796. if advicelist.ID == 0 {
  1797. all_count, _ := strconv.ParseFloat(totals, 64)
  1798. if prescribingNumberUnit == drug.MinUnit {
  1799. if drug.IsUse != 1 {
  1800. if drug.IsProject == 0 || drug.IsProject == 2 {
  1801. if all_count == 0 {
  1802. tx.Rollback()
  1803. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1804. return
  1805. }
  1806. if prescribing_number > all_count {
  1807. tx.Rollback()
  1808. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1809. return
  1810. }
  1811. }
  1812. }
  1813. } else {
  1814. if prescribingNumberUnit == drug.MaxUnit {
  1815. num := prescribing_number * float64(drug.MinNumber)
  1816. if drug.IsUse != 1 {
  1817. if drug.IsProject == 0 || drug.IsProject == 2 {
  1818. if all_count == 0 {
  1819. tx.Rollback()
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. if num > all_count {
  1824. tx.Rollback()
  1825. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1826. return
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. //修改处方
  1834. if advicelist.ID > 0 {
  1835. var device_number int64
  1836. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1837. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1838. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1839. device_number = prescribingNumberInt * drug.MinNumber
  1840. }
  1841. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1842. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1843. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1844. device_number = prescribingNumberInt
  1845. }
  1846. var number_count int64
  1847. if prescribingNumberUnit == drug.MaxUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if prescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1853. number_count = prescribingNumberInt
  1854. }
  1855. //如果修改的数量大于之前修改的数量
  1856. if (number_count - device_number) > 0 {
  1857. //如果修改的差数量 大于库存数量
  1858. if drug.IsUse != 1 {
  1859. if (number_count - device_number) > total_count {
  1860. tx.Rollback()
  1861. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1862. return
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. //已发药和已收费限制逻辑
  1877. //执行出库的逻辑
  1878. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1879. //校验库存总量
  1880. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1881. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1882. if len(prescriptions) > 0 {
  1883. for _, item := range prescriptions {
  1884. items := item.(map[string]interface{})
  1885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1886. advices := items["advices"].([]interface{})
  1887. if len(advices) > 0 {
  1888. for _, advice := range advices {
  1889. var drug_id int64
  1890. var prescribing_number float64
  1891. var prescribingNumberUnit string
  1892. var adviceId int64
  1893. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1894. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1895. }
  1896. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1897. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1898. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1899. }
  1900. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1901. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1902. }
  1903. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1904. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1905. }
  1906. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1907. if drug.ID == 0 {
  1908. tx.Rollback()
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1910. return
  1911. }
  1912. //查询药品的所有库存
  1913. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1914. var total_count int64
  1915. for _, it := range list {
  1916. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1917. }
  1918. totals := strconv.FormatInt(total_count, 10)
  1919. //查询该药品是否存在开药记录
  1920. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1921. //查询最新批次库存
  1922. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1923. var batch_number_count int64
  1924. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1925. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1926. //新增处方
  1927. if advicelist.ID == 0 {
  1928. all_count, _ := strconv.ParseFloat(totals, 64)
  1929. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1930. if prescribingNumberUnit == drug.MinUnit {
  1931. if drug.IsUse != 1 {
  1932. if drug.IsProject == 0 || drug.IsProject == 2 {
  1933. if all_count == 0 {
  1934. tx.Rollback()
  1935. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1936. return
  1937. }
  1938. if prescribing_number > all_count {
  1939. tx.Rollback()
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1941. return
  1942. }
  1943. }
  1944. if adminInfo.CurrentOrgId == 10215 {
  1945. if prescribing_number > batch_number_all_count {
  1946. tx.Rollback()
  1947. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1948. return
  1949. }
  1950. }
  1951. }
  1952. }
  1953. if prescribingNumberUnit == drug.MaxUnit {
  1954. num := prescribing_number * float64(drug.MinNumber)
  1955. if drug.IsUse != 1 {
  1956. if drug.IsProject == 0 || drug.IsProject == 2 {
  1957. if all_count == 0 {
  1958. tx.Rollback()
  1959. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1960. return
  1961. }
  1962. if num > all_count {
  1963. tx.Rollback()
  1964. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1965. return
  1966. }
  1967. }
  1968. if adminInfo.CurrentOrgId == 10215 {
  1969. if num > batch_number_all_count {
  1970. tx.Rollback()
  1971. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1972. return
  1973. }
  1974. }
  1975. }
  1976. }
  1977. }
  1978. //不是保存处方出库
  1979. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1980. if drugOutConfig.IsOpen != 1 {
  1981. //修改处方
  1982. for _, advice := range advices {
  1983. var drug_id int64
  1984. var prescribing_number float64
  1985. var prescribingNumberUnit string
  1986. var prescribingNumber string
  1987. var adviceId int64
  1988. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1989. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1990. }
  1991. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1992. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1993. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1994. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1995. }
  1996. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1997. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1998. }
  1999. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2000. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2001. }
  2002. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2003. if drug.ID == 0 {
  2004. tx.Rollback()
  2005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2006. return
  2007. }
  2008. //查询药品的所有库存
  2009. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2010. var total_count int64
  2011. for _, it := range list {
  2012. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2013. }
  2014. totals := strconv.FormatInt(total_count, 10)
  2015. //查询该药品是否存在开药记录
  2016. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2017. //新增处方
  2018. if advicelist.ID == 0 {
  2019. //查询最新批次库存
  2020. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2021. var batch_number_count int64
  2022. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2023. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2024. all_count, _ := strconv.ParseFloat(totals, 64)
  2025. if all_count == 0 {
  2026. tx.Rollback()
  2027. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2028. return
  2029. }
  2030. if prescribingNumberUnit == drug.MinUnit {
  2031. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2032. if drug.IsUse != 1 {
  2033. if drug.IsProject == 0 || drug.IsProject == 2 {
  2034. if all_count == 0 {
  2035. tx.Rollback()
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2037. return
  2038. }
  2039. if prescribing_number > all_count {
  2040. tx.Rollback()
  2041. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2042. return
  2043. }
  2044. }
  2045. if adminInfo.CurrentOrgId == 10215 {
  2046. if prescribing_number > batch_number_all_count {
  2047. tx.Rollback()
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2049. return
  2050. }
  2051. }
  2052. }
  2053. } else {
  2054. if prescribingNumberUnit == drug.MaxUnit {
  2055. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2056. num := prescribing_number * float64(drug.MinNumber)
  2057. if drug.IsUse != 1 {
  2058. if drug.IsProject == 0 || drug.IsProject == 2 {
  2059. if all_count == 0 {
  2060. tx.Rollback()
  2061. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2062. return
  2063. }
  2064. if num > all_count {
  2065. tx.Rollback()
  2066. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2067. return
  2068. }
  2069. }
  2070. if adminInfo.CurrentOrgId == 10215 {
  2071. if prescribing_number > batch_number_all_count {
  2072. tx.Rollback()
  2073. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2074. return
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. //修改处方
  2082. if advicelist.ID > 0 {
  2083. //查询最新批次库存
  2084. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2085. var batch_number_count int64
  2086. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2087. var device_number int64
  2088. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2089. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2090. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2091. device_number = prescribingNumberInt * drug.MinNumber
  2092. }
  2093. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2094. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2095. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2096. device_number = prescribingNumberInt
  2097. //回退库存
  2098. }
  2099. var number_count int64
  2100. if prescribingNumberUnit == drug.MaxUnit {
  2101. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2102. number_count = prescribingNumberInt * drug.MinNumber
  2103. //回退库存
  2104. }
  2105. if prescribingNumberUnit == drug.MinUnit {
  2106. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2107. number_count = prescribingNumberInt
  2108. //回退库存
  2109. }
  2110. //如果修改的数量大于之前修改的数量
  2111. if (number_count - device_number) > 0 {
  2112. //如果修改的差数量 大于库存数量
  2113. if drug.IsUse != 1 {
  2114. if drug.IsProject == 0 || drug.IsProject == 2 {
  2115. if total_count == 0 {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if (number_count - device_number) > total_count {
  2121. tx.Rollback()
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2123. return
  2124. }
  2125. if (number_count - device_number) > batch_number_count {
  2126. tx.Rollback()
  2127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2128. return
  2129. }
  2130. }
  2131. if adminInfo.CurrentOrgId == 10215 {
  2132. // 查询该药品最后一次出库记录
  2133. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2134. var out_count int64
  2135. var in_count int64
  2136. var stock_max_number int64
  2137. var stock_min_number int64
  2138. for _, it := range outInfo {
  2139. if it.CountUnit == drug.MaxUnit {
  2140. it.Count = it.Count * drug.MinNumber
  2141. }
  2142. out_count += it.Count
  2143. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2144. stock_max_number = warehouseInfoList.StockMaxNumber
  2145. stock_min_number = warehouseInfoList.StockMinNumber
  2146. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2147. }
  2148. if out_count > 0 {
  2149. if (number_count - device_number) > in_count {
  2150. tx.Rollback()
  2151. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2152. return
  2153. }
  2154. }
  2155. // 未出库
  2156. if out_count == 0 {
  2157. var sum_in_count int64
  2158. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2159. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2160. //如果修改的数量大于有库存的第一个批次
  2161. if number_count > sum_in_count {
  2162. tx.Rollback()
  2163. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2164. return
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //药品发药
  2171. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. //不使用药品发药的功能
  2173. //if pharmacyConfig.IsOpen != 1 {
  2174. // if device_number != number_count {
  2175. //
  2176. // //查询该药品的出库记录
  2177. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2178. // if len(outListExport) > 0 {
  2179. // //
  2180. // for _, item := range outListExport {
  2181. // //回退库存
  2182. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2183. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2184. // }
  2185. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2186. // var stock_max_number int64
  2187. // var stock_min_number int64
  2188. //
  2189. // if number_count >= drug.MinNumber {
  2190. //
  2191. // stock_max_number = device_number / drug.MinNumber
  2192. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2193. //
  2194. // stock_min_number = device_number % drug.MinNumber
  2195. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2196. //
  2197. // } else {
  2198. //
  2199. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2200. //
  2201. // }
  2202. // }
  2203. //
  2204. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2205. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2206. // }
  2207. // }
  2208. // }
  2209. //
  2210. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2211. // var sum_count int64
  2212. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2213. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2214. // for _, its := range stockInfo {
  2215. // if its.MaxUnit == drug.MaxUnit {
  2216. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2217. // }
  2218. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2219. // }
  2220. // //更新字典里面的库存
  2221. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2222. //
  2223. // //剩余库存
  2224. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2225. //
  2226. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2227. // //减少出库数量
  2228. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2229. //
  2230. // }
  2231. //}
  2232. }
  2233. }
  2234. }
  2235. //保存处方开药
  2236. if drugOutConfig.IsOpen == 1 {
  2237. //修改处方
  2238. for _, advice := range advices {
  2239. var drug_id int64
  2240. var prescribing_number float64
  2241. var prescribingNumberUnit string
  2242. var prescribingNumber string
  2243. var adviceId int64
  2244. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2245. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2246. }
  2247. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2248. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2249. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2250. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2251. }
  2252. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2253. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2254. }
  2255. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2256. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2257. }
  2258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2259. if drug.ID == 0 {
  2260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2261. return
  2262. }
  2263. //查询药品的所有库存
  2264. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2265. var total_count int64
  2266. for _, it := range list {
  2267. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2268. }
  2269. totals := strconv.FormatInt(total_count, 10)
  2270. //查询该药品是否存在开药记录
  2271. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2272. //新增处方
  2273. if advicelist.ID == 0 {
  2274. //查询最新批次库存
  2275. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2276. var batch_number_count int64
  2277. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2278. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2279. all_count, _ := strconv.ParseFloat(totals, 64)
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. }
  2348. var number_count int64
  2349. if prescribingNumberUnit == drug.MaxUnit {
  2350. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2351. number_count = prescribingNumberInt * drug.MinNumber
  2352. }
  2353. if prescribingNumberUnit == drug.MinUnit {
  2354. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2355. number_count = prescribingNumberInt
  2356. }
  2357. //如果修改的数量大于之前修改的数量
  2358. if (number_count - device_number) > 0 {
  2359. //如果修改的差数量 大于库存数量
  2360. if drug.IsUse != 1 {
  2361. if drug.IsProject == 0 || drug.IsProject == 2 {
  2362. if total_count == 0 {
  2363. tx.Rollback()
  2364. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2365. return
  2366. }
  2367. if (number_count - device_number) > total_count {
  2368. tx.Rollback()
  2369. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2370. return
  2371. }
  2372. }
  2373. if adminInfo.CurrentOrgId == 10215 {
  2374. if (number_count - device_number) > batch_number_count {
  2375. tx.Rollback()
  2376. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2377. return
  2378. }
  2379. }
  2380. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2381. //查询历史出库数据总批次
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. if sum_in_count == 0 {
  2411. tx.Rollback()
  2412. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2413. return
  2414. }
  2415. //如果修改的数量大于有库存的第一个批次
  2416. if number_count > sum_in_count {
  2417. tx.Rollback()
  2418. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2419. return
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. //校验耗材库存
  2436. if goodOutConfig.IsOpen == 1 {
  2437. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2438. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2439. if len(prescriptions) > 0 {
  2440. for _, item := range prescriptions {
  2441. items := item.(map[string]interface{})
  2442. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2443. projects := items["project"].([]interface{})
  2444. if len(projects) > 0 {
  2445. for _, project := range projects {
  2446. var project_id int64
  2447. var project_type int64
  2448. var totals float64
  2449. var project_name string
  2450. var parsetotal int64
  2451. var id int64
  2452. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2453. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2454. }
  2455. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2456. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2457. }
  2458. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2459. total, _ := project.(map[string]interface{})["total"].(string)
  2460. totals, _ = strconv.ParseFloat(total, 64)
  2461. }
  2462. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2463. project_name = project.(map[string]interface{})["project_name"].(string)
  2464. }
  2465. if project_type == 3 {
  2466. //查找该耗材的出库记录
  2467. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2468. if len(goodWarehouseInfo) == 0 {
  2469. //查询耗材库存
  2470. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2471. var stock_count int64
  2472. for _, it := range list {
  2473. stock_count += it.StockCount
  2474. }
  2475. stock_counts := strconv.FormatInt(stock_count, 10)
  2476. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2477. if stock_total_count == 0 {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2480. return
  2481. }
  2482. if totals > stock_total_count {
  2483. tx.Rollback()
  2484. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2485. return
  2486. }
  2487. }
  2488. if len(goodWarehouseInfo) > 0 {
  2489. //查询该患者耗材的历史数据
  2490. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2491. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2492. //数量发生改变
  2493. if parsetotal != count {
  2494. //如果现在的数量大于历史数量,就要看库存是否足够
  2495. if parsetotal > count {
  2496. //查询耗材所有库存
  2497. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2498. var stock_count int64
  2499. for _, it := range list {
  2500. stock_count += it.StockCount
  2501. }
  2502. //库存不足
  2503. if stock_count == 0 {
  2504. tx.Rollback()
  2505. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2506. return
  2507. }
  2508. if (parsetotal - count) > stock_count {
  2509. tx.Rollback()
  2510. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2511. return
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. //不使用耗材保存处方出库
  2525. if goodOutConfig.IsOpen != 1 {
  2526. if stockConfig.IsOpen == 1 {
  2527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2529. if len(prescriptions) > 0 {
  2530. for _, item := range prescriptions {
  2531. items := item.(map[string]interface{})
  2532. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2533. projects := items["project"].([]interface{})
  2534. if len(projects) > 0 {
  2535. for _, project := range projects {
  2536. var project_id int64
  2537. var project_type int64
  2538. var totals float64
  2539. var project_name string
  2540. var parsetotal int64
  2541. var id int64
  2542. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2543. id = int64(project.(map[string]interface{})["id"].(float64))
  2544. }
  2545. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2546. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2547. }
  2548. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2549. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2550. }
  2551. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2552. total, _ := project.(map[string]interface{})["total"].(string)
  2553. totals, _ = strconv.ParseFloat(total, 64)
  2554. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2555. }
  2556. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2557. project_name = project.(map[string]interface{})["project_name"].(string)
  2558. }
  2559. if project_type == 3 {
  2560. //查找该耗材的出库记录
  2561. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2562. //没有出库记录
  2563. if len(goodWarehouseInfo) == 0 {
  2564. //查询耗材库存
  2565. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2566. var stock_count int64
  2567. for _, it := range list {
  2568. stock_count += it.StockCount
  2569. }
  2570. stock_counts := strconv.FormatInt(stock_count, 10)
  2571. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2572. if stock_total_count == 0 {
  2573. tx.Rollback()
  2574. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2575. return
  2576. }
  2577. if totals > stock_total_count {
  2578. tx.Rollback()
  2579. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2580. return
  2581. }
  2582. //查找今日该患者已经出库的所有耗材
  2583. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2584. for _, item := range goodList {
  2585. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2586. var flush_count int64
  2587. for _, it := range goodListSix {
  2588. flush_count += it.StockCount
  2589. }
  2590. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2591. creater := adminInfo.AdminUser.Id
  2592. if errs != nil {
  2593. goodErrcode := models.XtGoodErrcode{
  2594. UserOrgId: item.OrgId,
  2595. Errcode: "手动出库更新剩余出库失败",
  2596. GoodId: item.GoodId,
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: 0,
  2600. Count: 0,
  2601. StockCount: 0,
  2602. Creater: creater,
  2603. BatchNumberId: 0,
  2604. WarehouseOutId: 0,
  2605. }
  2606. service.CreateGoodErrcode(goodErrcode)
  2607. }
  2608. }
  2609. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2610. }
  2611. //有出库记录
  2612. if len(goodWarehouseInfo) > 0 {
  2613. //查询该患者耗材的历史数据
  2614. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2615. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2616. //数量发生改变
  2617. if parsetotal != count {
  2618. //查找今日该患者已经出库的所有耗材
  2619. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2620. for _, item := range goodList {
  2621. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2622. var flush_count int64
  2623. for _, it := range goodListSix {
  2624. flush_count += it.StockCount
  2625. }
  2626. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2627. //减少出库数量
  2628. creater := adminInfo.AdminUser.Id
  2629. if errs != nil {
  2630. goodErrcode := models.XtGoodErrcode{
  2631. UserOrgId: item.OrgId,
  2632. Errcode: "手动出库更新剩余出库失败",
  2633. GoodId: item.GoodId,
  2634. Status: 1,
  2635. Ctime: time.Now().Unix(),
  2636. Mtime: 0,
  2637. Count: 0,
  2638. StockCount: 0,
  2639. Creater: creater,
  2640. BatchNumberId: 0,
  2641. WarehouseOutId: 0,
  2642. }
  2643. service.CreateGoodErrcode(goodErrcode)
  2644. }
  2645. //查询默认仓库
  2646. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2647. var total_count int64
  2648. for _, it := range stockList {
  2649. total_count += it.StockCount
  2650. }
  2651. //基础库插入数据
  2652. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2653. }
  2654. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2667. var hpInfo models.HisPrescriptionInfo
  2668. if info.ID == 0 {
  2669. var randNum int
  2670. randNum = rand.Intn(10000) + 1000
  2671. timestamp := time.Now().Unix()
  2672. tempTime := time.Unix(timestamp, 0)
  2673. timeFormat := tempTime.Format("20060102150405")
  2674. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2675. hpInfo = models.HisPrescriptionInfo{
  2676. HisPatientId: his_patient_id,
  2677. UserOrgId: adminInfo.CurrentOrgId,
  2678. RecordDate: theTime.Unix(),
  2679. PatientId: patient_id,
  2680. Status: 1,
  2681. Ctime: time.Now().Unix(),
  2682. Mtime: time.Now().Unix(),
  2683. Creator: adminInfo.AdminUser.Id,
  2684. Modifier: adminInfo.AdminUser.Id,
  2685. Diagnosis: diagnose,
  2686. SickHistory: sick_history,
  2687. Departments: department,
  2688. RegisterType: reg_type,
  2689. PrescriptionNumber: p_number,
  2690. PrescriptionStatus: 1,
  2691. Doctor: role.UserName,
  2692. DoctorId: doctor_id,
  2693. SickType: sick_type,
  2694. PType: p_type,
  2695. PatientDiagnosis: patient_diagnose,
  2696. }
  2697. service.SavePatientPrescriptionInfo(hpInfo)
  2698. //创建步骤表
  2699. finish := models.XtDialysisFinish{
  2700. IsFinish: 1,
  2701. UserOrgId: adminInfo.CurrentOrgId,
  2702. Status: 1,
  2703. Ctime: time.Now().Unix(),
  2704. Mtime: 0,
  2705. Module: 4,
  2706. RecordDate: theTime.Unix(),
  2707. Sourse: 1,
  2708. PatientId: patient_id,
  2709. }
  2710. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2711. if dialysisFinish.ID == 0 {
  2712. service.CreateDialysisFinish(finish)
  2713. }
  2714. redis := service.RedisClient()
  2715. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2716. redis.Set(key, "", time.Second)
  2717. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2718. redis.Set(keyOne, "", time.Second)
  2719. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2720. redis.Set(keySeven, "", time.Second)
  2721. defer redis.Close()
  2722. } else {
  2723. hpInfo = models.HisPrescriptionInfo{
  2724. ID: info.ID,
  2725. UserOrgId: adminInfo.CurrentOrgId,
  2726. RecordDate: info.RecordDate,
  2727. PatientId: info.PatientId,
  2728. Status: 1,
  2729. Ctime: info.Ctime,
  2730. Mtime: time.Now().Unix(),
  2731. Creator: info.Creator,
  2732. Modifier: adminInfo.AdminUser.Id,
  2733. Diagnosis: diagnose,
  2734. SickHistory: sick_history,
  2735. Departments: department,
  2736. RegisterType: reg_type,
  2737. PrescriptionNumber: info.PrescriptionNumber,
  2738. Doctor: role.UserName,
  2739. PrescriptionStatus: info.PrescriptionStatus,
  2740. DoctorId: doctor_id,
  2741. SickType: sick_type,
  2742. PType: info.PType,
  2743. HisPatientId: info.HisPatientId,
  2744. PatientDiagnosis: patient_diagnose,
  2745. }
  2746. service.SavePatientPrescriptionInfo(hpInfo)
  2747. //创建步骤表
  2748. finish := models.XtDialysisFinish{
  2749. IsFinish: 1,
  2750. UserOrgId: adminInfo.CurrentOrgId,
  2751. Status: 1,
  2752. Ctime: time.Now().Unix(),
  2753. Mtime: 0,
  2754. Module: 4,
  2755. RecordDate: info.RecordDate,
  2756. Sourse: 1,
  2757. PatientId: info.PatientId,
  2758. }
  2759. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2760. if dialysisFinish.ID == 0 {
  2761. service.CreateDialysisFinish(finish)
  2762. }
  2763. redis := service.RedisClient()
  2764. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2765. redis.Set(key, "", time.Second)
  2766. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2767. redis.Set(keyOne, "", time.Second)
  2768. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2769. redis.Set(keySeven, "", time.Second)
  2770. defer redis.Close()
  2771. }
  2772. //定义切片
  2773. var adviceList []models.HisDoctorAdviceInfo
  2774. var projectList []models.HisPrescriptionProject
  2775. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 {
  2776. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2777. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2778. var tempPrescription *models.HisPrescription
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. // 开始外部循环的事务
  2782. tx := db.Begin()
  2783. // 在函数结束时处理事务回滚
  2784. defer func() {
  2785. if r := recover(); r != nil {
  2786. tx.Rollback()
  2787. }
  2788. }()
  2789. items := item.(map[string]interface{})
  2790. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2791. utils.ErrorLog("id")
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. id := int64(items["id"].(float64))
  2796. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2797. tempPrescription = &new_prescription
  2798. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2799. utils.ErrorLog("type")
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. types := int64(items["type"].(float64))
  2804. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2805. utils.ErrorLog("med_type")
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2810. if med_type == "0" {
  2811. med_type = "14"
  2812. }
  2813. //if order_status == 0 {
  2814. // order_status = 1
  2815. //}
  2816. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2817. utils.ErrorLog("pre_time")
  2818. }
  2819. preTime, _ := items["pre_time"].(string)
  2820. fmt.Println("preTime", preTime)
  2821. timeLayout := "2006-01-02"
  2822. loc, _ := time.LoadLocation("Local")
  2823. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2824. result := strings.Split(preTime, " ")
  2825. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2826. if err != nil {
  2827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2828. return
  2829. }
  2830. pTime := theTime2.Unix()
  2831. ctime := time.Now().Unix()
  2832. if tempPrescription.ID == 0 {
  2833. prescription := &models.HisPrescription{
  2834. ID: 0,
  2835. PatientId: patient_id,
  2836. UserOrgId: adminInfo.CurrentOrgId,
  2837. RecordDate: recordDateTime,
  2838. Ctime: ctime,
  2839. Mtime: ctime,
  2840. Type: types,
  2841. Modifier: adminInfo.AdminUser.Id,
  2842. Creator: adminInfo.AdminUser.Id,
  2843. Status: 1,
  2844. Doctor: role.UserName,
  2845. HisPatientId: his_patient_id,
  2846. OrderStatus: 1,
  2847. BatchNumber: "",
  2848. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2849. PreTime: pTime,
  2850. PType: p_type,
  2851. MedType: med_type,
  2852. }
  2853. tempPrescription = prescription
  2854. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2855. redis := service.RedisClient()
  2856. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2857. redis.Set(key, "", time.Second)
  2858. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2859. redis.Set(keyOne, "", time.Second)
  2860. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2861. redis.Set(keySeven, "", time.Second)
  2862. defer redis.Close()
  2863. } else {
  2864. tempPrescription.ID = id
  2865. tempPrescription.Type = types
  2866. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2867. tempPrescription.Mtime = time.Now().Unix()
  2868. tempPrescription.Doctor = role.UserName
  2869. //tempPrescription.OrderStatus = order_status
  2870. tempPrescription.PreTime = pTime
  2871. tempPrescription.MedType = med_type
  2872. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2873. redis := service.RedisClient()
  2874. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2875. redis.Set(key, "", time.Second)
  2876. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2877. redis.Set(keyOne, "", time.Second)
  2878. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2879. redis.Set(keySeven, "", time.Second)
  2880. defer redis.Close()
  2881. }
  2882. //service.SaveHisPrescription(prescription)
  2883. //更改患者挂号状态
  2884. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2885. fmt.Println("更改失败", err2)
  2886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2887. advices := items["advices"].([]interface{})
  2888. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2889. groupNo := int64(0)
  2890. if len(advices) > 0 {
  2891. for _, advice := range advices {
  2892. tx := db.Begin()
  2893. // 在函数结束时处理事务回滚
  2894. defer func() {
  2895. if r := recover(); r != nil {
  2896. tx.Rollback()
  2897. }
  2898. }()
  2899. var s models.HisDoctorAdviceInfo
  2900. s.PrescriptionId = tempPrescription.ID
  2901. s.AdviceType = 2
  2902. s.AdviceDoctor = doctor_id
  2903. s.StopState = 2
  2904. s.ExecutionState = 2
  2905. s.AdviceDate = theTime3.Unix()
  2906. s.Status = 1
  2907. s.UserOrgId = adminInfo.CurrentOrgId
  2908. s.RecordDate = theTime3.Unix()
  2909. s.StartTime = tempPrescription.PreTime
  2910. s.Groupno = groupNo
  2911. s.PatientId = patient_id
  2912. s.HisPatientId = his_patient_id
  2913. s.StartTime = pTime
  2914. s.IsSettle = 2
  2915. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2916. if errcode > 0 {
  2917. c.ServeFailJSONWithSGJErrorCode(errcode)
  2918. return
  2919. }
  2920. s.StartTime = pTime
  2921. var total_count int64 //处方总库存
  2922. //查询改药品信息
  2923. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2924. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2925. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2926. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2927. total_count += prescribingNumberSeven * medical.MinNumber
  2928. }
  2929. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2930. total_count += prescribingNumberSeven
  2931. }
  2932. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2933. total_count += prescribingNumberSeven
  2934. }
  2935. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2936. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2937. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2938. if s.Price != lastWarehouse.RetailPrice {
  2939. s.Price = lastWarehouse.RetailPrice
  2940. }
  2941. if s.Price == 0 {
  2942. if lastWarehouse.ID == 0 {
  2943. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2944. s.Price = lastWarehouseTwo.RetailPrice
  2945. }
  2946. }
  2947. }
  2948. //查询保存处方出库开关是否打开
  2949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2950. if s.PatientId != 30038 {
  2951. if drugOutConfig.IsOpen == 1 {
  2952. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2953. // 查询该药品最后一次出库记录
  2954. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2955. var is_user_total int64
  2956. var no_user_total int64
  2957. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2958. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2959. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2960. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2961. }
  2962. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2963. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2964. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2965. no_user_total += prescribingNumberSevenTy
  2966. }
  2967. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2968. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2969. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2970. no_user_total += prescribingNumberSevenTy
  2971. }
  2972. if len(druginfo) > 0 {
  2973. for _, it := range druginfo {
  2974. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2975. it.Count = it.Count * drug.MinNumber
  2976. is_user_total += it.Count
  2977. }
  2978. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2979. is_user_total += it.Count
  2980. }
  2981. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2982. is_user_total += it.Count
  2983. }
  2984. }
  2985. }
  2986. //fmt.Println("药品名称----------------------", drug.DrugName)
  2987. //fmt.Println("药品名称----------------------", drug.IsUse)
  2988. //fmt.Println("is_user_total-------------------------", is_user_total)
  2989. //fmt.Println("no_user_total-------------------------", no_user_total)
  2990. if is_user_total != no_user_total {
  2991. //出库
  2992. if drug.IsUse == 2 {
  2993. creater := adminInfo.AdminUser.Id
  2994. newadviceInfo := &models.HisDoctorAdviceInfo{
  2995. ID: s.ID,
  2996. UserOrgId: s.UserOrgId,
  2997. PatientId: s.PatientId,
  2998. HisPatientId: s.HisPatientId,
  2999. AdviceType: s.AdviceType,
  3000. AdviceDate: s.AdviceDate,
  3001. StartTime: s.StartTime,
  3002. AdviceName: s.AdviceName,
  3003. AdviceDesc: s.AdviceDesc,
  3004. ReminderDate: s.ReminderDate,
  3005. SingleDose: s.SingleDose,
  3006. SingleDoseUnit: s.SingleDoseUnit,
  3007. PrescribingNumber: s.PrescribingNumber,
  3008. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3009. DeliveryWay: s.DeliveryWay,
  3010. ExecutionFrequency: s.ExecutionFrequency,
  3011. AdviceDoctor: s.AdviceDoctor,
  3012. Status: s.Status,
  3013. CreatedTime: s.CreatedTime,
  3014. UpdatedTime: s.UpdatedTime,
  3015. AdviceAffirm: s.AdviceAffirm,
  3016. Remark: s.Remark,
  3017. StopTime: s.StopTime,
  3018. StopReason: s.StopReason,
  3019. StopDoctor: s.StopDoctor,
  3020. StopState: s.StopState,
  3021. ParentId: s.ParentId,
  3022. ExecutionTime: s.ExecutionTime,
  3023. ExecutionStaff: s.ExecutionStaff,
  3024. ExecutionState: s.ExecutionState,
  3025. Checker: s.Checker,
  3026. RecordDate: s.RecordDate,
  3027. DialysisOrderId: s.DialysisOrderId,
  3028. CheckTime: s.CheckTime,
  3029. CheckState: s.CheckState,
  3030. DrugSpec: s.DrugSpec,
  3031. DrugSpecUnit: s.DrugSpecUnit,
  3032. Groupno: s.Groupno,
  3033. RemindType: s.RemindType,
  3034. FrequencyType: s.FrequencyType,
  3035. DayCount: s.DayCount,
  3036. WeekDay: s.WeekDay,
  3037. TemplateId: s.TemplateId,
  3038. Modifier: s.Modifier,
  3039. DrugId: s.DrugId,
  3040. Price: s.Price,
  3041. PrescriptionId: s.PrescriptionId,
  3042. MedListCodg: s.MedListCodg,
  3043. FeedetlSn: s.FeedetlSn,
  3044. Day: s.DayCount,
  3045. ChildDoctorAdvice: nil,
  3046. Drug: models.Drug{},
  3047. Diagnosis: s.Diagnosis,
  3048. Way: s.Way,
  3049. HospApprFlag: s.HospApprFlag,
  3050. LmtUsedFlag: s.LmtUsedFlag,
  3051. HisOrderInfo: models.HisOrderInfo{},
  3052. IsMedicine: s.IsMedicine,
  3053. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3054. Child: nil,
  3055. IsSettle: s.IsSettle,
  3056. IsMobile: s.IsMobile,
  3057. IsSelfDrug: s.IsSelfDrug,
  3058. DrugWayCount: s.DrugWayCount,
  3059. }
  3060. var history_count int64
  3061. var local_count int64
  3062. //查找已经开过的医嘱信息
  3063. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3064. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. local_count += prescribingNumberSevenTy * drug.MinNumber
  3068. }
  3069. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. local_count += prescribingNumberSevenTy
  3073. }
  3074. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3075. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3076. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3077. local_count += prescribingNumberSevenTy
  3078. }
  3079. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3080. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3081. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3082. history_count += prescribingNumberSevenTy * drug.MinNumber
  3083. }
  3084. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3085. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3086. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3087. history_count += prescribingNumberSevenTy
  3088. }
  3089. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3090. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3091. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3092. history_count += prescribingNumberSevenTy
  3093. }
  3094. //如果当前出库数量大于历史出库数量则需要出库
  3095. if local_count > history_count {
  3096. //按最小单位出库
  3097. var cha_count = local_count - history_count
  3098. newadviceInfo.PrescribingNumber = float64(cha_count)
  3099. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3100. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3101. }
  3102. //如果当前出库数量小于历史出库数量则需要退库
  3103. if local_count < history_count {
  3104. var cha_count = history_count - local_count
  3105. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. }
  3108. if local_count == history_count {
  3109. if is_user_total == 0 {
  3110. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3111. }
  3112. }
  3113. }
  3114. //更新字典里面的库存
  3115. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3116. var sum_count int64
  3117. for _, its := range stockInfo {
  3118. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3119. if its.MaxUnit == baseDrug.MaxUnit {
  3120. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3121. }
  3122. sum_count += its.StockMaxNumber + its.StockMinNumber
  3123. }
  3124. //更新基础库存
  3125. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3126. //剩余库存
  3127. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3128. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3129. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3130. //创建医嘱
  3131. service.CreateHisDoctorAdviceOne(&s, tx)
  3132. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. if len(outInfoTwo) > 0 {
  3135. for _, item := range outInfoTwo {
  3136. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3137. }
  3138. }
  3139. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3140. if len(drugAutoDetail) > 0 {
  3141. for _, item := range drugAutoDetail {
  3142. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. //记录日志
  3149. byterequest, _ := json.Marshal(s)
  3150. adviceLog := models.XtDoctorAdviceLog{
  3151. UserOrgId: s.UserOrgId,
  3152. PatientId: s.PatientId,
  3153. AdminUserId: adminInfo.AdminUser.Id,
  3154. Module: 1,
  3155. ErrLog: string(byterequest),
  3156. Status: 1,
  3157. Ctime: time.Now().Unix(),
  3158. Mtime: 0,
  3159. Source: "电脑端新建his医嘱",
  3160. RecordDate: s.AdviceDate,
  3161. }
  3162. service.CreateDoctorAdviceLog(adviceLog)
  3163. //存储切片中
  3164. adviceList = append(adviceList, s)
  3165. redis := service.RedisClient()
  3166. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3167. redis.Set(key, "", time.Second)
  3168. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3169. redis.Set(keyOne, "", time.Second)
  3170. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3171. redis.Set(keySeven, "", time.Second)
  3172. var randNum int
  3173. randNum = rand.Intn(10000) + 1000
  3174. timestamp := time.Now().Unix()
  3175. tempTime := time.Unix(timestamp, 0)
  3176. timeFormat := tempTime.Format("20060102150405")
  3177. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3178. //查询改药品是否已经停用
  3179. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3180. if base.ID > 0 {
  3181. tx.Rollback()
  3182. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3183. return
  3184. }
  3185. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3186. if drugMedical.SumCount == 0 {
  3187. tx.Rollback()
  3188. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3189. return
  3190. }
  3191. service.CreateHisDoctorAdviceOne(&s, tx)
  3192. tx.Commit()
  3193. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3194. redis.Set(keySix, "", time.Second)
  3195. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3196. redis.Set(keyFive, "", time.Second)
  3197. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3198. redis.Set(keyEight, "", time.Second)
  3199. defer redis.Close()
  3200. }
  3201. }
  3202. }
  3203. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3204. projects := items["project"].([]interface{})
  3205. if len(projects) > 0 {
  3206. for _, project := range projects {
  3207. tx := db.Begin()
  3208. // 在函数结束时处理事务回滚
  3209. defer func() {
  3210. if r := recover(); r != nil {
  3211. tx.Rollback()
  3212. }
  3213. }()
  3214. var p models.HisPrescriptionProject
  3215. p.PrescriptionId = tempPrescription.ID
  3216. p.PatientId = patient_id
  3217. p.RecordDate = theTime3.Unix()
  3218. p.Doctor = doctor_id
  3219. p.UserOrgId = adminInfo.CurrentOrgId
  3220. p.HisPatientId = his_patient_id
  3221. p.Status = 1
  3222. p.StartTime = pTime
  3223. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3224. if errcode > 0 {
  3225. c.ServeFailJSONWithSGJErrorCode(errcode)
  3226. return
  3227. }
  3228. if p.ID == 0 {
  3229. p.IsOut = 2
  3230. }
  3231. if p.ID > 0 {
  3232. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3233. p.IsOut = projectDetail.IsOut
  3234. }
  3235. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3236. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3237. if p.Type == 3 {
  3238. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3239. if p.Price != lastWarehouse.PackingPrice {
  3240. p.Price = lastWarehouse.PackingPrice
  3241. }
  3242. if p.Price == 0 {
  3243. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3244. p.Price = lastWarehouseTwo.PackingPrice
  3245. }
  3246. if p.Unit == "" {
  3247. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3248. p.Unit = goodInfoOne.PackingUnit
  3249. }
  3250. }
  3251. }
  3252. if p.Type == 3 {
  3253. //查询该耗材是否停用
  3254. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3255. //表示该耗材已经停用,不能保存
  3256. if goodInfoSeven.ID == 0 {
  3257. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3258. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3259. return
  3260. }
  3261. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3262. if goodInfoOne.SumCount == 0 {
  3263. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3264. return
  3265. }
  3266. }
  3267. //查询保存耗材出库开关是否打开
  3268. if p.PatientId != 30038 {
  3269. if goodOutConfig.IsOpen == 1 {
  3270. //耗材出库
  3271. if p.Type == 3 {
  3272. //对比当前数据和历史出库数据
  3273. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3274. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3275. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3276. //如果当前处方数量大于历史数据,则需要出库
  3277. if nowCount > historyCount {
  3278. var cha_count int64
  3279. cha_count = nowCount - historyCount
  3280. timeStr := time.Now().Format("2006-01-02")
  3281. timeArr := strings.Split(timeStr, "-")
  3282. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3283. total = total + 1
  3284. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3285. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3286. number = number + total
  3287. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3288. operation_time := time.Now().Unix()
  3289. creater := c.GetAdminUserInfo().AdminUser.Id
  3290. recordDateStr := time.Now().Format("2006-01-02")
  3291. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3292. nowtime := recordDate.Unix()
  3293. warehouseOut := models.WarehouseOut{
  3294. WarehouseOutOrderNumber: warehousing_out_order,
  3295. OperationTime: operation_time,
  3296. OrgId: adminInfo.CurrentOrgId,
  3297. Creater: creater,
  3298. Ctime: time.Now().Unix(),
  3299. Status: 1,
  3300. WarehouseOutTime: nowtime,
  3301. Type: 1,
  3302. StorehouseId: storeConfig.StorehouseOutInfo,
  3303. IsCheck: 1,
  3304. IsSys: 1,
  3305. }
  3306. //查询是否生成出库单
  3307. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3308. if out.ID == 0 {
  3309. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3310. }
  3311. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3312. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3313. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3314. dialyPrepareOne := models.DialysisBeforePrepare{
  3315. GoodTypeId: goodObj.GoodTypeId,
  3316. GoodId: p.ProjectId,
  3317. PatientId: p.PatientId,
  3318. RecordDate: p.RecordDate,
  3319. UserOrgId: adminInfo.CurrentOrgId,
  3320. Count: cha_count,
  3321. Ctime: time.Now().Unix(),
  3322. Creater: creater,
  3323. Status: 1,
  3324. StorehouseId: houseConfig.StorehouseOutInfo,
  3325. ProjectId: p.ID,
  3326. }
  3327. //出库
  3328. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3329. }
  3330. //如果当前处方数量小于历史数据,怎需要退库
  3331. if nowCount < historyCount {
  3332. var cha_count int64
  3333. cha_count = historyCount - nowCount
  3334. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3335. creater := c.GetAdminUserInfo().AdminUser.Id
  3336. newPrescriptionProject := &models.HisPrescriptionProject{
  3337. ID: p.ID,
  3338. ProjectId: p.ProjectId,
  3339. Price: p.Price,
  3340. UserOrgId: p.UserOrgId,
  3341. Status: 1,
  3342. Ctime: time.Now().Unix(),
  3343. Mtime: time.Now().Unix(),
  3344. PatientId: p.PatientId,
  3345. HisPatientId: p.HisPatientId,
  3346. RecordDate: p.RecordDate,
  3347. PrescriptionId: p.PrescriptionId,
  3348. Count: p.Count,
  3349. FeedetlSn: p.FeedetlSn,
  3350. MedListCodg: p.MedListCodg,
  3351. SingleDose: p.SingleDose,
  3352. DeliveryWay: p.DeliveryWay,
  3353. ExecutionFrequency: p.ExecutionFrequency,
  3354. Day: p.Day,
  3355. HisProject: models.HisProject{},
  3356. GoodInfo: models.GoodInfo{},
  3357. Remark: p.Remark,
  3358. Unit: p.Unit,
  3359. Type: p.Type,
  3360. Doctor: p.Doctor,
  3361. ExecutionTime: p.ExecutionTime,
  3362. ExecutionStaff: p.ExecutionStaff,
  3363. ExecutionState: p.ExecutionState,
  3364. CheckTime: p.CheckTime,
  3365. CheckState: p.CheckState,
  3366. Checker: p.Checker,
  3367. StartTime: p.StartTime,
  3368. TeamId: p.TeamId,
  3369. XtHisProjectTeam: models.XtHisProjectTeam{},
  3370. FrequencyType: p.FrequencyType,
  3371. DayCount: p.DayCount,
  3372. WeekDay: p.WeekDay,
  3373. IsCheckTeam: p.IsCheckTeam,
  3374. HisOrderInfo: models.HisOrderInfo{},
  3375. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3376. IsOut: p.IsOut,
  3377. YbSyncStatus: p.YbSyncStatus,
  3378. }
  3379. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3380. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3381. }
  3382. if nowCount == historyCount {
  3383. if historyCount == 0 {
  3384. recordDateStr := time.Now().Format("2006-01-02")
  3385. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3386. nowtime := recordDate.Unix()
  3387. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3388. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3389. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3390. creater := c.GetAdminUserInfo().AdminUser.Id
  3391. dialyPrepareOne := models.DialysisBeforePrepare{
  3392. GoodTypeId: goodObj.GoodTypeId,
  3393. GoodId: p.ProjectId,
  3394. PatientId: p.PatientId,
  3395. RecordDate: p.RecordDate,
  3396. UserOrgId: adminInfo.CurrentOrgId,
  3397. Count: nowCount,
  3398. Ctime: time.Now().Unix(),
  3399. Creater: creater,
  3400. Status: 1,
  3401. StorehouseId: houseConfig.StorehouseOutInfo,
  3402. ProjectId: p.ID,
  3403. }
  3404. //出库
  3405. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3406. }
  3407. }
  3408. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3409. ////查询历史出库数据
  3410. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3411. //
  3412. //var out_count_five int64
  3413. //for _, item := range flowGood {
  3414. // out_count_five += item.Count
  3415. //}
  3416. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3417. //
  3418. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3419. //if out_count_five != parseIntCount {
  3420. // //查询耗材最后一次出库记录
  3421. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3422. // //查询默认出库仓库库存
  3423. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3424. // if len(wareOut) > 0 {
  3425. //
  3426. // for _, it := range wareOut {
  3427. // //回退库存
  3428. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3429. //
  3430. // //删除出库记录
  3431. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3432. //
  3433. // }
  3434. // }
  3435. //
  3436. // timeStr := time.Now().Format("2006-01-02")
  3437. // timeArr := strings.Split(timeStr, "-")
  3438. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3439. //
  3440. // total = total + 1
  3441. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3442. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3443. // number = number + total
  3444. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3445. //
  3446. // operation_time := time.Now().Unix()
  3447. // creater := c.GetAdminUserInfo().AdminUser.Id
  3448. //
  3449. // recordDateStr := time.Now().Format("2006-01-02")
  3450. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3451. // nowtime := recordDate.Unix()
  3452. // warehouseOut := models.WarehouseOut{
  3453. // WarehouseOutOrderNumber: warehousing_out_order,
  3454. // OperationTime: operation_time,
  3455. // OrgId: adminInfo.CurrentOrgId,
  3456. // Creater: creater,
  3457. // Ctime: time.Now().Unix(),
  3458. // Status: 1,
  3459. // WarehouseOutTime: nowtime,
  3460. // Type: 1,
  3461. // StorehouseId: storeConfig.StorehouseOutInfo,
  3462. // IsCheck: 1,
  3463. // IsSys: 1,
  3464. // }
  3465. // //查询是否生成出库单
  3466. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3467. // if out.ID == 0 {
  3468. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3469. // }
  3470. //
  3471. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3472. //
  3473. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3474. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3475. //
  3476. // dialyPrepareOne := models.DialysisBeforePrepare{
  3477. // GoodTypeId: goodObj.GoodTypeId,
  3478. // GoodId: p.ProjectId,
  3479. // PatientId: p.PatientId,
  3480. // RecordDate: p.RecordDate,
  3481. // UserOrgId: adminInfo.CurrentOrgId,
  3482. // Count: parseIntCount,
  3483. // Ctime: time.Now().Unix(),
  3484. // Creater: creater,
  3485. // Status: 1,
  3486. // StorehouseId: houseConfig.StorehouseOutInfo,
  3487. // ProjectId: lastHisProject.ID,
  3488. // }
  3489. // //判断是否是零用耗材(非零用)
  3490. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3491. //
  3492. // //查询历史出库数据
  3493. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3494. // var out_count int64
  3495. // for _, item := range flowGood {
  3496. // out_count += item.Count
  3497. // }
  3498. // //如果历史数和当前数据不想等才进行退库出库
  3499. // if out_count != parseIntCount {
  3500. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3501. //
  3502. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3503. // detail := models.AutomaticReduceDetail{
  3504. // WarehouseOutId: 0,
  3505. // WarehouseOutOrderNumber: "",
  3506. // PatientId: p.PatientId,
  3507. // Ctime: time.Now().Unix(),
  3508. // Mtime: 0,
  3509. // Status: 1,
  3510. // RecordTime: p.RecordDate,
  3511. // OrgId: p.UserOrgId,
  3512. // GoodId: p.ProjectId,
  3513. // GoodTypeId: 0,
  3514. // Count: parseIntCount,
  3515. // Type: 0,
  3516. // ProjectId: lastHisProject.ID,
  3517. // StorehouseId: 0,
  3518. // }
  3519. //
  3520. // service.CreateNewAutoDetail(detail, tx)
  3521. //
  3522. // //查询剩余库存
  3523. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3524. // var sum_count int64
  3525. // for _, item := range goodList {
  3526. // sum_count += item.StockCount
  3527. // }
  3528. //
  3529. // //更新剩余库存
  3530. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3531. //
  3532. // //耗材
  3533. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3534. //
  3535. // }
  3536. // //判断是否是零用耗材(零用但是是出库耗材)
  3537. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3538. //
  3539. // //查询历史出库数据
  3540. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3541. // var out_count int64
  3542. // for _, item := range flowGood {
  3543. // out_count += item.Count
  3544. // }
  3545. // //如果历史数和当前数据不想等才进行退库出库
  3546. // if out_count != parseIntCount {
  3547. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3548. //
  3549. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3550. // detail := models.AutomaticReduceDetail{
  3551. // WarehouseOutId: 0,
  3552. // WarehouseOutOrderNumber: "",
  3553. // PatientId: p.PatientId,
  3554. // Ctime: time.Now().Unix(),
  3555. // Mtime: 0,
  3556. // Status: 1,
  3557. // RecordTime: p.RecordDate,
  3558. // OrgId: p.UserOrgId,
  3559. // GoodId: p.ProjectId,
  3560. // GoodTypeId: 0,
  3561. // Count: parseIntCount,
  3562. // Type: 0,
  3563. // ProjectId: p.ID,
  3564. // StorehouseId: 0,
  3565. // }
  3566. //
  3567. // service.CreateNewAutoDetail(detail, tx)
  3568. //
  3569. // //查询剩余库存
  3570. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3571. // var sum_count int64
  3572. // for _, item := range goodList {
  3573. // sum_count += item.StockCount
  3574. // }
  3575. //
  3576. // //更新剩余库存
  3577. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3578. //
  3579. // //耗材
  3580. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3581. // }
  3582. //
  3583. // }
  3584. //
  3585. // }
  3586. //
  3587. //}
  3588. //记录日志
  3589. byterequest, _ := json.Marshal(p)
  3590. adviceLog := models.XtDoctorAdviceLog{
  3591. UserOrgId: p.UserOrgId,
  3592. PatientId: p.PatientId,
  3593. AdminUserId: adminInfo.AdminUser.Id,
  3594. Module: 1,
  3595. ErrLog: string(byterequest),
  3596. Status: 1,
  3597. Ctime: time.Now().Unix(),
  3598. Mtime: 0,
  3599. Source: "电脑端新建his项目",
  3600. RecordDate: p.RecordDate,
  3601. }
  3602. service.CreateDoctorAdviceLog(adviceLog)
  3603. projectList = append(projectList, p)
  3604. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3605. //新增或者编辑项目,修改对应的标签数据
  3606. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3607. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3608. var label models.HisLabelPrintInfo
  3609. project, _ := service.GetProjectDetail(p.ProjectId)
  3610. if project.CostClassify == 3 { //类别为检验检查
  3611. if p.TeamId > 0 { //检验检查组套
  3612. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3613. if tempLabel.ID == 0 {
  3614. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3615. label.Number = tempPrescription.PrescriptionNumber
  3616. label.ProjectId = project.ID
  3617. label.Status = 1
  3618. label.IsPrint = 2
  3619. label.DoctorId = info.DoctorId
  3620. label.UserOrgId = p.UserOrgId
  3621. label.PatientId = patient_id
  3622. label.RecordDate = recordDateTime
  3623. label.Ctime = time.Now().Unix()
  3624. label.Mtime = time.Now().Unix()
  3625. label.ItemId = p.TeamId
  3626. label.FeedetlSn = p.FeedetlSn
  3627. label.PProjectId = p.ID
  3628. label.ProjectName = team.ProjectTeam
  3629. label.PatientName = patient.Name
  3630. service.CreateNewHisLabelRecord(&label, tx)
  3631. }
  3632. } else { //单条检验检查项目
  3633. label.Number = tempPrescription.PrescriptionNumber
  3634. label.ProjectId = project.ID
  3635. label.Status = 1
  3636. label.DoctorId = info.DoctorId
  3637. label.UserOrgId = p.UserOrgId
  3638. label.PatientId = patient_id
  3639. label.RecordDate = recordDateTime
  3640. label.IsPrint = 2
  3641. label.Ctime = time.Now().Unix()
  3642. label.Mtime = time.Now().Unix()
  3643. label.FeedetlSn = p.FeedetlSn
  3644. label.PProjectId = p.ID
  3645. label.ItemId = p.TeamId
  3646. label.ProjectName = project.ProjectName
  3647. label.PatientName = patient.Name
  3648. service.CreateNewHisLabelRecord(&label, tx)
  3649. }
  3650. }
  3651. }
  3652. }
  3653. }
  3654. }
  3655. }
  3656. service.CreateNewHisProjectTwo(&p, tx)
  3657. var randNum int
  3658. randNum = rand.Intn(10000) + 1000
  3659. timestamp := time.Now().Unix()
  3660. tempTime := time.Unix(timestamp, 0)
  3661. timeFormat := tempTime.Format("20060102150405")
  3662. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3663. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3664. if goodBase.ID > 0 {
  3665. tx.Rollback()
  3666. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3667. return
  3668. }
  3669. service.CreateNewHisProjectTwo(&p, tx)
  3670. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3671. //查询剩余库存
  3672. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3673. var sum_count int64
  3674. for _, item := range goodList {
  3675. sum_count += item.StockCount
  3676. }
  3677. //更新剩余库存
  3678. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3679. //耗材
  3680. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3681. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3682. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3683. if len(outInfoTwo) > 0 {
  3684. for _, item := range outInfoTwo {
  3685. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3686. }
  3687. }
  3688. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3689. if len(drugAutoDetail) > 0 {
  3690. for _, item := range drugAutoDetail {
  3691. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3692. }
  3693. }
  3694. tx.Commit()
  3695. }
  3696. }
  3697. }
  3698. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3699. // addition := items["addition"].([]interface{})
  3700. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3701. // ctime := time.Now().Unix()
  3702. // mtime := ctime
  3703. // if len(addition) > 0 {
  3704. // for _, item := range addition {
  3705. // var s models.HisAdditionalCharge
  3706. // s.PrescriptionId = tempPrescription.ID
  3707. // s.Status = 1
  3708. // s.UserOrgId = adminInfo.CurrentOrgId
  3709. // s.RecordDate = recordDateTime
  3710. // s.CreatedTime = ctime
  3711. // s.UpdatedTime = mtime
  3712. // s.PatientId = patient_id
  3713. // s.HisPatientId = his_patient_id
  3714. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3715. // if errcode > 0 {
  3716. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3717. // return
  3718. // }
  3719. // service.CreateAdditionalCharge(&s)
  3720. // var randNum int
  3721. // randNum = rand.Intn(10000) + 1000
  3722. // timestamp := time.Now().Unix()
  3723. // tempTime := time.Unix(timestamp, 0)
  3724. // timeFormat := tempTime.Format("20060102150405")
  3725. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3726. // service.CreateAdditionalCharge(&s)
  3727. //
  3728. // }
  3729. // }
  3730. //}
  3731. }
  3732. }
  3733. }
  3734. tx.Commit()
  3735. if err == nil {
  3736. c.ServeSuccessJSON(map[string]interface{}{
  3737. "msg": "保存成功",
  3738. })
  3739. return
  3740. } else {
  3741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3742. return
  3743. }
  3744. } else {
  3745. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3746. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3747. var tempPrescription *models.HisPrescription
  3748. if len(prescriptions) > 0 {
  3749. for _, item := range prescriptions {
  3750. items := item.(map[string]interface{})
  3751. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3752. utils.ErrorLog("id")
  3753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3754. return
  3755. }
  3756. id := int64(items["id"].(float64))
  3757. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3758. tempPrescription = &new_prescription
  3759. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3760. utils.ErrorLog("type")
  3761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3762. return
  3763. }
  3764. types := int64(items["type"].(float64))
  3765. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3766. utils.ErrorLog("med_type")
  3767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3768. return
  3769. }
  3770. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3771. if med_type == "0" {
  3772. med_type = "14"
  3773. }
  3774. //if order_status == 0 {
  3775. // order_status = 1
  3776. //}
  3777. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3778. utils.ErrorLog("pre_time")
  3779. }
  3780. preTime, _ := items["pre_time"].(string)
  3781. timeLayout := "2006-01-02"
  3782. loc, _ := time.LoadLocation("Local")
  3783. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3784. result := strings.Split(preTime, " ")
  3785. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3786. if err != nil {
  3787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3788. return
  3789. }
  3790. pTime := theTime2.Unix()
  3791. ctime := time.Now().Unix()
  3792. if tempPrescription.ID == 0 {
  3793. prescription := &models.HisPrescription{
  3794. ID: 0,
  3795. PatientId: patient_id,
  3796. UserOrgId: adminInfo.CurrentOrgId,
  3797. RecordDate: recordDateTime,
  3798. Ctime: ctime,
  3799. Mtime: ctime,
  3800. Type: types,
  3801. Modifier: adminInfo.AdminUser.Id,
  3802. Creator: adminInfo.AdminUser.Id,
  3803. Status: 1,
  3804. Doctor: role.UserName,
  3805. HisPatientId: his_patient_id,
  3806. OrderStatus: 1,
  3807. BatchNumber: "",
  3808. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3809. PreTime: pTime,
  3810. PType: p_type,
  3811. MedType: med_type,
  3812. }
  3813. tempPrescription = prescription
  3814. service.SaveHisPrescription(tempPrescription)
  3815. redis := service.RedisClient()
  3816. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3817. redis.Set(key, "", time.Second)
  3818. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3819. redis.Set(keyOne, "", time.Second)
  3820. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3821. redis.Set(keySeven, "", time.Second)
  3822. defer redis.Close()
  3823. } else {
  3824. tempPrescription.ID = id
  3825. tempPrescription.Type = types
  3826. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3827. tempPrescription.Mtime = time.Now().Unix()
  3828. tempPrescription.Doctor = role.UserName
  3829. //tempPrescription.OrderStatus = order_status
  3830. tempPrescription.PreTime = pTime
  3831. tempPrescription.MedType = med_type
  3832. service.SaveHisPrescription(tempPrescription)
  3833. redis := service.RedisClient()
  3834. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3835. redis.Set(key, "", time.Second)
  3836. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3837. redis.Set(keyOne, "", time.Second)
  3838. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3839. redis.Set(keySeven, "", time.Second)
  3840. defer redis.Close()
  3841. }
  3842. //service.SaveHisPrescription(prescription)
  3843. //更改患者挂号状态
  3844. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3845. fmt.Println("更改失败", err2)
  3846. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3847. advices := items["advices"].([]interface{})
  3848. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3849. groupNo := int64(0)
  3850. if len(advices) > 0 {
  3851. for _, advice := range advices {
  3852. var s models.HisDoctorAdviceInfo
  3853. s.PrescriptionId = tempPrescription.ID
  3854. s.AdviceType = 2
  3855. s.AdviceDoctor = doctor_id
  3856. s.StopState = 2
  3857. s.ExecutionState = 2
  3858. s.AdviceDate = theTime3.Unix()
  3859. s.Status = 1
  3860. s.UserOrgId = adminInfo.CurrentOrgId
  3861. s.RecordDate = theTime3.Unix()
  3862. s.StartTime = tempPrescription.PreTime
  3863. s.Groupno = groupNo
  3864. s.PatientId = patient_id
  3865. s.HisPatientId = his_patient_id
  3866. s.StartTime = pTime
  3867. s.IsSettle = 2
  3868. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3869. if errcode > 0 {
  3870. c.ServeFailJSONWithSGJErrorCode(errcode)
  3871. return
  3872. }
  3873. s.StartTime = pTime
  3874. var total_count int64 //处方总库存
  3875. //查询改药品信息
  3876. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3877. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3878. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3879. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3880. total_count += prescribingNumberSeven * medical.MinNumber
  3881. }
  3882. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3883. total_count += prescribingNumberSeven
  3884. }
  3885. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3886. total_count += prescribingNumberSeven
  3887. }
  3888. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3889. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3890. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3891. if s.Price != lastWarehouse.RetailPrice {
  3892. s.Price = lastWarehouse.RetailPrice
  3893. }
  3894. if s.Price == 0 {
  3895. if lastWarehouse.ID == 0 {
  3896. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3897. s.Price = lastWarehouseTwo.RetailPrice
  3898. }
  3899. }
  3900. }
  3901. //查询改药品是否已经停用
  3902. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3903. if base.ID > 0 {
  3904. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3905. return
  3906. }
  3907. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3908. if drugMedical.SumCount == 0 {
  3909. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3910. return
  3911. }
  3912. service.CreateHisDoctorAdvice(&s)
  3913. //记录日志
  3914. byterequest, _ := json.Marshal(s)
  3915. adviceLog := models.XtDoctorAdviceLog{
  3916. UserOrgId: s.UserOrgId,
  3917. PatientId: s.PatientId,
  3918. AdminUserId: adminInfo.AdminUser.Id,
  3919. Module: 1,
  3920. ErrLog: string(byterequest),
  3921. Status: 1,
  3922. Ctime: time.Now().Unix(),
  3923. Mtime: 0,
  3924. Source: "电脑端新建his医嘱",
  3925. RecordDate: s.AdviceDate,
  3926. }
  3927. service.CreateDoctorAdviceLog(adviceLog)
  3928. //存储切片中
  3929. adviceList = append(adviceList, s)
  3930. redis := service.RedisClient()
  3931. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3932. redis.Set(key, "", time.Second)
  3933. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3934. redis.Set(keyOne, "", time.Second)
  3935. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3936. redis.Set(keySeven, "", time.Second)
  3937. var randNum int
  3938. randNum = rand.Intn(10000) + 1000
  3939. timestamp := time.Now().Unix()
  3940. tempTime := time.Unix(timestamp, 0)
  3941. timeFormat := tempTime.Format("20060102150405")
  3942. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3943. service.CreateHisDoctorAdvice(&s)
  3944. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3945. redis.Set(keySix, "", time.Second)
  3946. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3947. redis.Set(keyFive, "", time.Second)
  3948. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3949. redis.Set(keyEight, "", time.Second)
  3950. defer redis.Close()
  3951. }
  3952. }
  3953. }
  3954. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3955. projects := items["project"].([]interface{})
  3956. if len(projects) > 0 {
  3957. for _, project := range projects {
  3958. var p models.HisPrescriptionProject
  3959. p.PrescriptionId = tempPrescription.ID
  3960. p.PatientId = patient_id
  3961. p.RecordDate = theTime3.Unix()
  3962. p.Doctor = doctor_id
  3963. p.UserOrgId = adminInfo.CurrentOrgId
  3964. p.HisPatientId = his_patient_id
  3965. p.Status = 1
  3966. p.StartTime = pTime
  3967. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3968. if errcode > 0 {
  3969. c.ServeFailJSONWithSGJErrorCode(errcode)
  3970. return
  3971. }
  3972. if p.ID == 0 {
  3973. p.IsOut = 2
  3974. }
  3975. if p.ID > 0 {
  3976. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3977. p.IsOut = projectDetail.IsOut
  3978. }
  3979. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3980. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3981. if p.Type == 3 {
  3982. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3983. if p.Price != lastWarehouse.PackingPrice {
  3984. p.Price = lastWarehouse.PackingPrice
  3985. }
  3986. if p.Price == 0 {
  3987. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3988. p.Price = lastWarehouseTwo.PackingPrice
  3989. }
  3990. if p.Unit == "" {
  3991. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3992. p.Unit = goodInfoOne.PackingUnit
  3993. }
  3994. }
  3995. }
  3996. if p.Type == 3 {
  3997. //查询该耗材是否停用
  3998. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3999. //表示该耗材已经停用,不能保存
  4000. if goodInfoSeven.ID == 0 {
  4001. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4002. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4003. return
  4004. }
  4005. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4006. if goodInfoOne.SumCount == 0 {
  4007. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4008. return
  4009. }
  4010. }
  4011. service.CreateHisProjectTwo(&p)
  4012. //记录日志
  4013. byterequest, _ := json.Marshal(p)
  4014. adviceLog := models.XtDoctorAdviceLog{
  4015. UserOrgId: p.UserOrgId,
  4016. PatientId: p.PatientId,
  4017. AdminUserId: adminInfo.AdminUser.Id,
  4018. Module: 1,
  4019. ErrLog: string(byterequest),
  4020. Status: 1,
  4021. Ctime: time.Now().Unix(),
  4022. Mtime: 0,
  4023. Source: "电脑端新建his项目",
  4024. RecordDate: p.RecordDate,
  4025. }
  4026. service.CreateDoctorAdviceLog(adviceLog)
  4027. projectList = append(projectList, p)
  4028. var randNum int
  4029. randNum = rand.Intn(10000) + 1000
  4030. timestamp := time.Now().Unix()
  4031. tempTime := time.Unix(timestamp, 0)
  4032. timeFormat := tempTime.Format("20060102150405")
  4033. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4034. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4035. //新增或者编辑项目,修改对应的标签数据
  4036. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4037. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4038. var label models.HisLabelPrintInfo
  4039. project, _ := service.GetProjectDetail(p.ProjectId)
  4040. if project.CostClassify == 3 { //类别为检验检查
  4041. if p.TeamId > 0 { //检验检查组套
  4042. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4043. if tempLabel.ID == 0 {
  4044. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4045. label.Number = tempPrescription.PrescriptionNumber
  4046. label.ProjectId = project.ID
  4047. label.Status = 1
  4048. label.IsPrint = 2
  4049. label.DoctorId = info.DoctorId
  4050. label.UserOrgId = p.UserOrgId
  4051. label.PatientId = patient_id
  4052. label.RecordDate = recordDateTime
  4053. label.Ctime = time.Now().Unix()
  4054. label.Mtime = time.Now().Unix()
  4055. label.ItemId = p.TeamId
  4056. label.FeedetlSn = p.FeedetlSn
  4057. label.PProjectId = p.ID
  4058. label.ProjectName = team.ProjectTeam
  4059. label.PatientName = patient.Name
  4060. service.CreateHisLabelRecord(&label)
  4061. }
  4062. } else { //单条检验检查项目
  4063. label.Number = tempPrescription.PrescriptionNumber
  4064. label.ProjectId = project.ID
  4065. label.Status = 1
  4066. label.DoctorId = info.DoctorId
  4067. label.UserOrgId = p.UserOrgId
  4068. label.PatientId = patient_id
  4069. label.RecordDate = recordDateTime
  4070. label.IsPrint = 2
  4071. label.Ctime = time.Now().Unix()
  4072. label.Mtime = time.Now().Unix()
  4073. label.FeedetlSn = p.FeedetlSn
  4074. label.PProjectId = p.ID
  4075. label.ItemId = p.TeamId
  4076. label.ProjectName = project.ProjectName
  4077. label.PatientName = patient.Name
  4078. service.CreateHisLabelRecord(&label)
  4079. }
  4080. }
  4081. }
  4082. }
  4083. service.SaveHisProjectTwo(&p)
  4084. }
  4085. }
  4086. }
  4087. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4088. // addition := items["addition"].([]interface{})
  4089. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4090. // ctime := time.Now().Unix()
  4091. // mtime := ctime
  4092. // if len(addition) > 0 {
  4093. // for _, item := range addition {
  4094. // var s models.HisAdditionalCharge
  4095. // s.PrescriptionId = tempPrescription.ID
  4096. // s.Status = 1
  4097. // s.UserOrgId = adminInfo.CurrentOrgId
  4098. // s.RecordDate = recordDateTime
  4099. // s.CreatedTime = ctime
  4100. // s.UpdatedTime = mtime
  4101. // s.PatientId = patient_id
  4102. // s.HisPatientId = his_patient_id
  4103. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4104. // if errcode > 0 {
  4105. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4106. // return
  4107. // }
  4108. // service.CreateAdditionalCharge(&s)
  4109. // var randNum int
  4110. // randNum = rand.Intn(10000) + 1000
  4111. // timestamp := time.Now().Unix()
  4112. // tempTime := time.Unix(timestamp, 0)
  4113. // timeFormat := tempTime.Format("20060102150405")
  4114. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4115. // service.CreateAdditionalCharge(&s)
  4116. //
  4117. // }
  4118. // }
  4119. //}
  4120. }
  4121. }
  4122. //查询今日该患者开的药品处方
  4123. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4124. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4125. //药品出库
  4126. if drugOutConfig.IsOpen == 1 {
  4127. for _, item := range hisdoctorlist {
  4128. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4129. // 查询该药品最后一次出库记录
  4130. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4131. if len(druginfo) > 0 {
  4132. //回退库存
  4133. for _, it := range druginfo {
  4134. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4135. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4136. }
  4137. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4138. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4139. }
  4140. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4141. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4142. }
  4143. }
  4144. }
  4145. //删除记录
  4146. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4147. //查询最后一次数据
  4148. if drugOutConfig.IsOpen == 1 {
  4149. //出库
  4150. if drug.IsUse == 2 {
  4151. creater := adminInfo.AdminUser.Id
  4152. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4153. }
  4154. //更新字典里面的库存
  4155. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4156. var sum_count int64
  4157. for _, its := range stockInfo {
  4158. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4159. if its.MaxUnit == baseDrug.MaxUnit {
  4160. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4161. }
  4162. sum_count += its.StockMaxNumber + its.StockMinNumber
  4163. }
  4164. //更新基础库存
  4165. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4166. //剩余库存
  4167. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4168. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4169. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4170. }
  4171. }
  4172. }
  4173. //耗材保存处方出库
  4174. if goodOutConfig.IsOpen == 1 {
  4175. //查询今日耗材出库数量
  4176. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4177. for _, item := range hisgoodlist {
  4178. //查询历史出库数据
  4179. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4180. var out_count_five int64
  4181. for _, item := range flowGood {
  4182. out_count_five += item.Count
  4183. }
  4184. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4185. if out_count_five != parseIntCount {
  4186. //查询耗材最后一次出库记录
  4187. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4188. //查询默认出库仓库库存
  4189. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4190. if len(wareOut) > 0 {
  4191. for _, it := range wareOut {
  4192. //回退库存
  4193. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4194. //删除出库记录
  4195. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4196. }
  4197. }
  4198. timeStr := time.Now().Format("2006-01-02")
  4199. timeArr := strings.Split(timeStr, "-")
  4200. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4201. total = total + 1
  4202. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4203. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4204. number = number + total
  4205. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4206. operation_time := time.Now().Unix()
  4207. creater := c.GetAdminUserInfo().AdminUser.Id
  4208. recordDateStr := time.Now().Format("2006-01-02")
  4209. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4210. nowtime := recordDate.Unix()
  4211. warehouseOut := models.WarehouseOut{
  4212. WarehouseOutOrderNumber: warehousing_out_order,
  4213. OperationTime: operation_time,
  4214. OrgId: adminInfo.CurrentOrgId,
  4215. Creater: creater,
  4216. Ctime: time.Now().Unix(),
  4217. Status: 1,
  4218. WarehouseOutTime: nowtime,
  4219. Type: 1,
  4220. StorehouseId: storeConfig.StorehouseOutInfo,
  4221. IsCheck: 1,
  4222. IsSys: 1,
  4223. }
  4224. //查询是否生成出库单
  4225. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4226. if out.ID == 0 {
  4227. service.AddSigleWarehouseOut(&warehouseOut)
  4228. }
  4229. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4230. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4231. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4232. dialyPrepareOne := models.DialysisBeforePrepare{
  4233. GoodTypeId: goodObj.GoodTypeId,
  4234. GoodId: item.ProjectId,
  4235. PatientId: item.PatientId,
  4236. RecordDate: item.RecordDate,
  4237. UserOrgId: adminInfo.CurrentOrgId,
  4238. Count: parseIntCount,
  4239. Ctime: time.Now().Unix(),
  4240. Creater: creater,
  4241. Status: 1,
  4242. StorehouseId: houseConfig.StorehouseOutInfo,
  4243. ProjectId: item.ID,
  4244. }
  4245. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4246. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4247. //查询历史出库数据
  4248. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4249. var out_count int64
  4250. for _, item := range flowGood {
  4251. out_count += item.Count
  4252. }
  4253. //如果历史数和当前数据不想等才进行退库出库
  4254. if out_count != parseIntCount {
  4255. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4256. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4257. detail := models.AutomaticReduceDetail{
  4258. WarehouseOutId: 0,
  4259. WarehouseOutOrderNumber: "",
  4260. PatientId: item.PatientId,
  4261. Ctime: time.Now().Unix(),
  4262. Mtime: 0,
  4263. Status: 1,
  4264. RecordTime: item.RecordDate,
  4265. OrgId: item.UserOrgId,
  4266. GoodId: item.ProjectId,
  4267. GoodTypeId: 0,
  4268. Count: parseIntCount,
  4269. Type: 0,
  4270. ProjectId: item.ID,
  4271. StorehouseId: 0,
  4272. }
  4273. service.CreateAutoDetail(detail)
  4274. //查询剩余库存
  4275. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4276. var sum_count int64
  4277. for _, item := range goodList {
  4278. sum_count += item.StockCount
  4279. }
  4280. //更新剩余库存
  4281. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4282. //耗材
  4283. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4284. }
  4285. }
  4286. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4287. //查询历史出库数据
  4288. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4289. var out_count int64
  4290. for _, item := range flowGood {
  4291. out_count += item.Count
  4292. }
  4293. //如果历史数和当前数据不想等才进行退库出库
  4294. if out_count != parseIntCount {
  4295. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4296. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4297. detail := models.AutomaticReduceDetail{
  4298. WarehouseOutId: 0,
  4299. WarehouseOutOrderNumber: "",
  4300. PatientId: item.PatientId,
  4301. Ctime: time.Now().Unix(),
  4302. Mtime: 0,
  4303. Status: 1,
  4304. RecordTime: item.RecordDate,
  4305. OrgId: item.UserOrgId,
  4306. GoodId: item.ProjectId,
  4307. GoodTypeId: 0,
  4308. Count: parseIntCount,
  4309. Type: 0,
  4310. ProjectId: item.ID,
  4311. StorehouseId: 0,
  4312. }
  4313. service.CreateAutoDetail(detail)
  4314. //查询剩余库存
  4315. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4316. var sum_count int64
  4317. for _, item := range goodList {
  4318. sum_count += item.StockCount
  4319. }
  4320. //更新剩余库存
  4321. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4322. //耗材
  4323. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4324. }
  4325. }
  4326. }
  4327. }
  4328. }
  4329. ////同步到自备药
  4330. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4331. if selfPrescriptionOpen.IsOpen == 1 {
  4332. timeStr := time.Now().Format("2006-01-02")
  4333. timeArr := strings.Split(timeStr, "-")
  4334. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4335. total = total + 1
  4336. operation_time := time.Now().Unix()
  4337. creater := adminInfo.AdminUser.Id
  4338. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4339. warehousing := models.XtSelfDrugWarehouse{
  4340. WarehousingOrder: warehousing_order,
  4341. OperationTime: operation_time,
  4342. OrgId: adminInfo.CurrentOrgId,
  4343. Creater: creater,
  4344. Ctime: time.Now().Unix(),
  4345. Status: 1,
  4346. WarehousingTime: recordDateTime,
  4347. Type: 0,
  4348. StorehouseId: 0,
  4349. IsCheck: 1,
  4350. PatientId: patient_id,
  4351. IsSys: 1,
  4352. }
  4353. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4354. if selfDrugWarehouse.ID == 0 {
  4355. service.AddSelfDrugWarehouse(&warehousing, tx)
  4356. }
  4357. if selfDrugWarehouse.ID > 0 {
  4358. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4359. }
  4360. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4361. fmt.Println(info)
  4362. for _, item := range hisdoctorlist {
  4363. //查询该病人的该药品是否已经入库
  4364. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4365. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4366. var in_count int64
  4367. if len(selfdruginfo) > 0 {
  4368. for _, item := range selfdruginfo {
  4369. var in_count_one int64
  4370. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4371. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4372. }
  4373. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4374. in_count_one = item.WarehousingCount
  4375. }
  4376. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4377. in_count_one = item.WarehousingCount
  4378. }
  4379. in_count += in_count_one
  4380. }
  4381. }
  4382. if selfBasedrug.IsSelfDrug == 1 {
  4383. var total_count int64
  4384. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4385. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4386. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4387. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4388. }
  4389. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4390. total_count += prescribingNumberSeven
  4391. }
  4392. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4393. total_count += prescribingNumberSeven
  4394. }
  4395. //入库
  4396. if total_count > in_count {
  4397. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4398. WarehousingOrder: warehousing_order,
  4399. WarehousingId: info.ID,
  4400. DrugId: item.DrugId,
  4401. Number: "",
  4402. ProductDate: 0,
  4403. ExpiryDate: 0,
  4404. WarehousingCount: total_count - in_count,
  4405. WarehouseingUnit: selfBasedrug.MinUnit,
  4406. Price: 0,
  4407. TotalPrice: 0,
  4408. Status: 1,
  4409. Ctime: time.Now().Unix(),
  4410. Remark: "",
  4411. OrgId: adminInfo.CurrentOrgId,
  4412. Type: 0,
  4413. Manufacturer: selfBasedrug.Manufacturer,
  4414. Dealer: selfBasedrug.Dealer,
  4415. StockMaxNumber: total_count - in_count,
  4416. RetailTotalPrice: 0,
  4417. BatchNumber: "",
  4418. MaxUnit: selfBasedrug.MinUnit,
  4419. MinUnit: selfBasedrug.MinUnit,
  4420. RetailPrice: 0,
  4421. StorehouseId: 0,
  4422. IsCheck: 1,
  4423. StockMinNumber: 0,
  4424. PatientId: patient_id,
  4425. IsSys: 1,
  4426. RecordDate: item.RecordDate,
  4427. AdviceId: item.ID,
  4428. }
  4429. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4430. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4431. Creator := adminInfo.AdminUser.Id
  4432. //查询默认仓库剩余多少库存
  4433. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4434. var sum_count int64
  4435. for _, it := range list {
  4436. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4437. if it.MaxUnit == baseDrug.MaxUnit {
  4438. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4439. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4440. }
  4441. sum_count += it.StockMaxNumber + it.StockMinNumber
  4442. }
  4443. flow := &models.XtSelfDrugFlow{
  4444. WarehousingId: info.ID,
  4445. DrugId: item.DrugId,
  4446. Number: "",
  4447. BatchNumber: "",
  4448. Count: total_count - in_count,
  4449. UserOrgId: adminInfo.CurrentOrgId,
  4450. PatientId: item.PatientId,
  4451. SystemTime: time.Now().Unix(),
  4452. ConsumableType: 1,
  4453. IsSys: 1,
  4454. WarehousingOrder: warehousing_order,
  4455. WarehouseOutId: 0,
  4456. WarehouseOutOrderNumber: "",
  4457. IsEdit: 0,
  4458. CancelStockId: 0,
  4459. CancelOrderNumber: "",
  4460. Manufacturer: selfBasedrug.Manufacturer,
  4461. Dealer: selfBasedrug.Dealer,
  4462. Creator: Creator,
  4463. UpdateCreator: Creator,
  4464. Status: 1,
  4465. Ctime: item.AdviceDate,
  4466. Mtime: 0,
  4467. Price: item.Price,
  4468. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4469. WarehouseOutDetailId: 0,
  4470. CancelOutDetailId: 0,
  4471. ExpireDate: 0,
  4472. ProductDate: 0,
  4473. MaxUnit: selfBasedrug.MinUnit,
  4474. MinUnit: selfBasedrug.MinUnit,
  4475. StorehouseId: 0,
  4476. OverCount: sum_count,
  4477. OperateTime: time.Now().Unix(),
  4478. AdviceId: item.ID,
  4479. }
  4480. service.CreateSelfDrugFlow(flow, tx)
  4481. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4482. var total_count int64 // 入库总数量
  4483. var over_count int64 //剩余库存
  4484. for _, it := range drugInfolist {
  4485. if it.MaxUnit == selfBasedrug.MaxUnit {
  4486. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4487. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4488. }
  4489. }
  4490. for _, it := range drugInfolist {
  4491. total_count += it.WarehousingCount
  4492. over_count += it.StockMaxNumber + it.StockMinNumber
  4493. }
  4494. //查询该仓库是否有默认数据
  4495. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4496. if selfDrugStock.ID == 0 {
  4497. drugStock := models.XtSelfDrugStockCount{
  4498. UserOrgId: item.UserOrgId,
  4499. PatientId: item.PatientId,
  4500. SumInCount: total_count,
  4501. SumOutCount: 0,
  4502. SumCancelCount: 0,
  4503. DrugId: item.DrugId,
  4504. Ctime: time.Now().Unix(),
  4505. Mtime: 0,
  4506. Status: 1,
  4507. FlushCount: over_count,
  4508. SumActOutCount: 0,
  4509. }
  4510. service.CreateSelfDrugStockSum(drugStock, tx)
  4511. }
  4512. if selfDrugStock.ID > 0 {
  4513. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4514. }
  4515. }
  4516. //查询这个单据的出库数量
  4517. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4518. var his_out_count int64
  4519. for _, item := range drugFlowList {
  4520. his_out_count += item.Count
  4521. }
  4522. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4523. if (total_count + his_out_count) <= in_count {
  4524. // 出库
  4525. if total_count < in_count {
  4526. var cha_count int64
  4527. cha_count = in_count - total_count
  4528. var stock_number int64 = 0
  4529. //查询库存是否充足
  4530. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4531. // 将该批次的剩余库存数量转换为拆零数量
  4532. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4533. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4534. }
  4535. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4536. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4537. }
  4538. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4539. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4540. }
  4541. if stock_number >= cha_count {
  4542. var maxNumber int64 = 0
  4543. var minNumber int64 = 0
  4544. maxNumber = cha_count / selfBasedrug.MinNumber
  4545. minNumber = cha_count % selfBasedrug.MinNumber
  4546. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4547. minNumber = maxNumber
  4548. }
  4549. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4550. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4552. return
  4553. }
  4554. }
  4555. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4556. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4557. }
  4558. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4559. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4560. }
  4561. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4562. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4563. }
  4564. if warehouse.StockMaxNumber < 0 {
  4565. warehouse.StockMaxNumber = 0
  4566. }
  4567. if warehouse.StockMinNumber < 0 {
  4568. warehouse.StockMinNumber = 0
  4569. }
  4570. warehouse.Mtime = time.Now().Unix()
  4571. if warehouse.StockMinNumber < minNumber {
  4572. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4573. if warehouse.MaxUnit != warehouse.MinUnit {
  4574. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4575. }
  4576. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4577. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4578. }
  4579. } else {
  4580. if minNumber > 0 {
  4581. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4582. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4583. }
  4584. }
  4585. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4586. if warehouse.StockMinNumber > 0 {
  4587. if warehouse.StockMinNumber-cha_count >= 0 {
  4588. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4589. }
  4590. }
  4591. }
  4592. }
  4593. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4594. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4595. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4596. }
  4597. }
  4598. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4599. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4601. return
  4602. }
  4603. }
  4604. if warehouse.StockMinNumber <= 0 {
  4605. warehouse.StockMinNumber = 0
  4606. }
  4607. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4608. //查询该药品剩余库存
  4609. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4610. var over_count int64
  4611. for _, its := range infolist {
  4612. if its.MaxUnit == selfBasedrug.MaxUnit {
  4613. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4614. }
  4615. over_count += its.StockMaxNumber + its.StockMinNumber
  4616. }
  4617. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4618. drugflow := models.XtSelfDrugFlow{
  4619. WarehouseOutId: 0,
  4620. WarehouseOutOrderNumber: warehousing_order,
  4621. WarehousingOrder: warehousing_order,
  4622. DrugId: item.DrugId,
  4623. Number: warehouse.Number,
  4624. ProductDate: warehouse.ProductDate,
  4625. ExpireDate: warehouse.ExpiryDate,
  4626. Count: cha_count,
  4627. Price: warehouse.RetailPrice,
  4628. Status: 1,
  4629. Ctime: item.AdviceDate,
  4630. Mtime: time.Now().Unix(),
  4631. UserOrgId: item.UserOrgId,
  4632. Manufacturer: warehouse.Manufacturer,
  4633. Dealer: warehouse.Dealer,
  4634. BatchNumber: warehouse.BatchNumber,
  4635. MaxUnit: selfBasedrug.MinUnit,
  4636. ConsumableType: 20,
  4637. IsEdit: 1,
  4638. Creator: 0,
  4639. IsSys: 3,
  4640. WarehouseOutDetailId: drugWareInfo.ID,
  4641. AdviceId: item.ID,
  4642. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4643. StorehouseId: 0,
  4644. AdminUserId: creater,
  4645. LastPrice: warehouse.Price,
  4646. StockCount: "",
  4647. WarehousingDetailId: 0,
  4648. OverCount: over_count,
  4649. RetailPrice: item.Price, //手动出库出库价格
  4650. WarehousingId: warehouse.ID,
  4651. SystemTime: item.AdviceDate,
  4652. PatientId: item.PatientId,
  4653. Remark: "保存处方入库数据差",
  4654. OperateTime: time.Now().Unix(),
  4655. }
  4656. if warehouse.RetailPrice == 0 {
  4657. drugflow.Price = item.Price
  4658. }
  4659. service.CreateSelfDrugFlowOne(drugflow, tx)
  4660. var out_count int64
  4661. out_count = in_count - total_count
  4662. fmt.Println("in_count------------------", in_count)
  4663. fmt.Println("total_count------------------", total_count)
  4664. //添加出库数量
  4665. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4666. //查询剩余库存
  4667. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4668. var sum_count int64
  4669. for _, its := range stockInfo {
  4670. if its.MaxUnit == selfBasedrug.MaxUnit {
  4671. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4672. }
  4673. sum_count += its.StockMaxNumber + its.StockMinNumber
  4674. }
  4675. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4676. } else {
  4677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4678. return
  4679. }
  4680. }
  4681. }
  4682. }
  4683. }
  4684. }
  4685. }
  4686. tx.Commit()
  4687. if err == nil {
  4688. c.ServeSuccessJSON(map[string]interface{}{
  4689. "msg": "保存成功",
  4690. })
  4691. return
  4692. } else {
  4693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4694. return
  4695. }
  4696. }
  4697. }
  4698. //func (c *HisApiController) EditHisPrescription() {
  4699. // record_date := c.GetString("record_date")
  4700. // patient_id, _ := c.GetInt64("patient_id")
  4701. // reg_type, _ := c.GetInt64("reg_type")
  4702. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4703. // diagnose := c.GetString("diagnose")
  4704. // sick_type, _ := c.GetInt64("sick_type")
  4705. // sick_history := c.GetString("sick_history")
  4706. // doctor_id, _ := c.GetInt64("doctor", 0)
  4707. // department, _ := c.GetInt64("department", 0)
  4708. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4709. // p_type, _ := c.GetInt64("p_type")
  4710. //
  4711. // dataBody := make(map[string]interface{}, 0)
  4712. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4713. // if err != nil {
  4714. // utils.ErrorLog(err.Error())
  4715. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4716. // return
  4717. // }
  4718. //
  4719. // timeLayout := "2006-01-02"
  4720. // loc, _ := time.LoadLocation("Local")
  4721. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4722. // if err != nil {
  4723. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4724. // return
  4725. // }
  4726. // adminInfo := c.GetAdminUserInfo()
  4727. // recordDateTime := theTime.Unix()
  4728. //
  4729. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4730. //
  4731. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4732. // var hpInfo models.HisPrescriptionInfo
  4733. // if info.ID == 0 {
  4734. // var randNum int
  4735. // randNum = rand.Intn(10000) + 1000
  4736. // timestamp := time.Now().Unix()
  4737. // tempTime := time.Unix(timestamp, 0)
  4738. // timeFormat := tempTime.Format("20060102150405")
  4739. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4740. //
  4741. // hpInfo = models.HisPrescriptionInfo{
  4742. // UserOrgId: adminInfo.CurrentOrgId,
  4743. // RecordDate: theTime.Unix(),
  4744. // PatientId: patient_id,
  4745. // Status: 1,
  4746. // Ctime: time.Now().Unix(),
  4747. // Mtime: time.Now().Unix(),
  4748. // Creator: adminInfo.AdminUser.Id,
  4749. // Modifier: adminInfo.AdminUser.Id,
  4750. // Diagnosis: diagnose,
  4751. // SickHistory: sick_history,
  4752. // Departments: department,
  4753. // RegisterType: reg_type,
  4754. // PrescriptionNumber: p_number,
  4755. // PrescriptionStatus: 1,
  4756. // Doctor: role.UserName,
  4757. // DoctorId: doctor_id,
  4758. // SickType: sick_type,
  4759. // PType: p_type,
  4760. // }
  4761. // service.SavePatientPrescriptionInfo(hpInfo)
  4762. //
  4763. // } else {
  4764. // hpInfo = models.HisPrescriptionInfo{
  4765. // ID: info.ID,
  4766. // UserOrgId: adminInfo.CurrentOrgId,
  4767. // RecordDate: info.RecordDate,
  4768. // PatientId: info.PatientId,
  4769. // Status: 1,
  4770. // Ctime: info.Ctime,
  4771. // Mtime: time.Now().Unix(),
  4772. // Creator: info.Creator,
  4773. // Modifier: adminInfo.AdminUser.Id,
  4774. // Diagnosis: diagnose,
  4775. // SickHistory: sick_history,
  4776. // Departments: department,
  4777. // RegisterType: reg_type,
  4778. // PrescriptionNumber: info.PrescriptionNumber,
  4779. // Doctor: role.UserName,
  4780. // PrescriptionStatus: info.PrescriptionStatus,
  4781. // DoctorId: doctor_id,
  4782. // SickType: sick_type,
  4783. // PType: info.PType,
  4784. // }
  4785. // service.SavePatientPrescriptionInfo(hpInfo)
  4786. // }
  4787. //
  4788. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4789. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4790. //
  4791. // if len(prescriptions) > 0 {
  4792. // for _, item := range prescriptions {
  4793. // items := item.(map[string]interface{})
  4794. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4795. // utils.ErrorLog("id")
  4796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4797. // return
  4798. // }
  4799. // id := int64(items["id"].(float64))
  4800. //
  4801. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4802. // utils.ErrorLog("type")
  4803. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4804. // return
  4805. // }
  4806. // types := int64(items["type"].(float64))
  4807. //
  4808. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4809. // utils.ErrorLog("med_type")
  4810. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4811. // return
  4812. // }
  4813. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4814. //
  4815. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4816. //
  4817. // ctime := time.Now().Unix()
  4818. //
  4819. // prescription := &models.HisPrescription{
  4820. // ID: id,
  4821. // PatientId: patient_id,
  4822. // UserOrgId: adminInfo.CurrentOrgId,
  4823. // RecordDate: recordDateTime,
  4824. // Ctime: ctime,
  4825. // Mtime: ctime,
  4826. // Type: types,
  4827. // Modifier: adminInfo.AdminUser.Id,
  4828. // Creator: adminInfo.AdminUser.Id,
  4829. // Status: 1,
  4830. // Doctor: role.UserName,
  4831. // HisPatientId: his_patient_id,
  4832. // OrderStatus: 1,
  4833. // BatchNumber: "",
  4834. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4835. // PType: hpInfo.PType,
  4836. // MedType: med_type,
  4837. // }
  4838. //
  4839. // if historyPrescription.ID > 0 {
  4840. // prescription.PreTime = historyPrescription.PreTime
  4841. //
  4842. // }
  4843. //
  4844. // service.SaveHisPrescription(prescription)
  4845. //
  4846. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4847. // advices := items["advices"].([]interface{})
  4848. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4849. // groupNo := int64(0)
  4850. // ctime := time.Now().Unix()
  4851. // mtime := ctime
  4852. // if len(advices) > 0 {
  4853. // for _, advice := range advices {
  4854. // var s models.HisDoctorAdviceInfo
  4855. // s.PrescriptionId = prescription.ID
  4856. // s.AdviceType = 2
  4857. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4858. // s.StopState = 2
  4859. // s.ExecutionState = 2
  4860. // s.AdviceDate = recordDateTime
  4861. // s.Status = 1
  4862. // s.UserOrgId = adminInfo.CurrentOrgId
  4863. // s.RecordDate = recordDateTime
  4864. // s.StartTime = prescription.PreTime
  4865. // s.Groupno = groupNo
  4866. // s.CreatedTime = ctime
  4867. // s.UpdatedTime = mtime
  4868. // s.PatientId = patient_id
  4869. // s.HisPatientId = his_patient_id
  4870. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4871. // if errcode > 0 {
  4872. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4873. // return
  4874. // }
  4875. //
  4876. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4877. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4878. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4879. // if s.Price == 0 {
  4880. // s.Price = lastWarehouse.RetailPrice
  4881. // }
  4882. // }
  4883. //
  4884. // service.CreateHisDoctorAdvice(&s)
  4885. // //记录日志
  4886. // byterequest, _ := json.Marshal(s)
  4887. // adviceLog := models.XtDoctorAdviceLog{
  4888. // UserOrgId: s.UserOrgId,
  4889. // PatientId: s.PatientId,
  4890. // AdminUserId: adminInfo.AdminUser.Id,
  4891. // Module: 1,
  4892. // ErrLog: string(byterequest),
  4893. // Status: 1,
  4894. // Ctime: time.Now().Unix(),
  4895. // Mtime: 0,
  4896. // Source: "电脑端his医嘱修改",
  4897. // RecordDate: s.AdviceDate,
  4898. // }
  4899. // service.CreateDoctorAdviceLog(adviceLog)
  4900. // redis := service.RedisClient()
  4901. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4902. // redis.Set(key, "", time.Second)
  4903. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4904. // fmt.Println("keyOne", keyOne)
  4905. // redis.Set(keyOne, "", time.Second)
  4906. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4907. // redis.Set(keySeven, "", time.Second)
  4908. // redis.Close()
  4909. //
  4910. // }
  4911. // }
  4912. // }
  4913. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4914. // projects := items["project"].([]interface{})
  4915. // if len(projects) > 0 {
  4916. // for _, project := range projects {
  4917. // var p models.HisPrescriptionProject
  4918. // p.PrescriptionId = prescription.ID
  4919. // p.Ctime = time.Now().Unix()
  4920. // p.Mtime = time.Now().Unix()
  4921. // p.PatientId = patient_id
  4922. // p.RecordDate = recordDateTime
  4923. // p.UserOrgId = adminInfo.CurrentOrgId
  4924. // p.HisPatientId = his_patient_id
  4925. // p.Status = 1
  4926. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4927. // if errcode > 0 {
  4928. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4929. // return
  4930. // }
  4931. // service.CreateHisProjectTwo(&p)
  4932. //
  4933. // //记录日志
  4934. // byterequest, _ := json.Marshal(p)
  4935. // adviceLog := models.XtDoctorAdviceLog{
  4936. // UserOrgId: p.UserOrgId,
  4937. // PatientId: p.PatientId,
  4938. // AdminUserId: adminInfo.AdminUser.Id,
  4939. // Module: 1,
  4940. // ErrLog: string(byterequest),
  4941. // Status: 1,
  4942. // Ctime: time.Now().Unix(),
  4943. // Mtime: 0,
  4944. // Source: "电脑端his项目修改",
  4945. // RecordDate: p.RecordDate,
  4946. // }
  4947. // service.CreateDoctorAdviceLog(adviceLog)
  4948. // }
  4949. // }
  4950. // }
  4951. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4952. // addition := items["addition"].([]interface{})
  4953. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4954. // ctime := time.Now().Unix()
  4955. // mtime := ctime
  4956. // if len(addition) > 0 {
  4957. // for _, item := range addition {
  4958. // var s models.HisAdditionalCharge
  4959. // s.PrescriptionId = prescription.ID
  4960. // s.Status = 1
  4961. // s.UserOrgId = adminInfo.CurrentOrgId
  4962. // s.RecordDate = recordDateTime
  4963. // s.CreatedTime = ctime
  4964. // s.UpdatedTime = mtime
  4965. // s.PatientId = patient_id
  4966. // s.HisPatientId = his_patient_id
  4967. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4968. // if errcode > 0 {
  4969. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4970. // return
  4971. // }
  4972. // service.CreateAdditionalCharge(&s)
  4973. // }
  4974. // }
  4975. // }
  4976. //
  4977. // }
  4978. // }
  4979. // }
  4980. // if err == nil {
  4981. // c.ServeSuccessJSON(map[string]interface{}{
  4982. // "msg": "保存成功",
  4983. // })
  4984. // return
  4985. //
  4986. // } else {
  4987. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4988. // return
  4989. // }
  4990. //}
  4991. func (c *HisApiController) DeletePrescription() {
  4992. prescription_id, _ := c.GetInt64("id")
  4993. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4994. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4995. ////同步到自备药
  4996. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  4997. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  4998. if selfPrescriptionOpen.IsOpen == 1 {
  4999. // 在函数结束时处理事务回滚
  5000. db := service.XTWriteDB()
  5001. tx := db.Begin()
  5002. defer func() {
  5003. if r := recover(); r != nil {
  5004. tx.Rollback()
  5005. } else {
  5006. tx.Commit()
  5007. }
  5008. }()
  5009. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5010. for _, item := range advicesList {
  5011. timeStr := time.Now().Format("2006-01-02")
  5012. timeArr := strings.Split(timeStr, "-")
  5013. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5014. total = total + 1
  5015. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5016. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5017. number = number + total
  5018. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5019. operation_time := time.Now().Unix()
  5020. creater := c.GetAdminUserInfo().AdminUser.Id
  5021. //创建一个出库单
  5022. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5023. WarehouseOutOrderNumber: warehousing_out_order,
  5024. OperationTime: operation_time,
  5025. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5026. Creater: creater,
  5027. Ctime: time.Now().Unix(),
  5028. Status: 1,
  5029. WarehouseOutTime: item.AdviceDate,
  5030. Type: 0,
  5031. PatientId: item.PatientId,
  5032. IsCheck: 1,
  5033. }
  5034. //查询今日是否有出库数据
  5035. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5036. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5037. if lastWarehouseOut.ID == 0 {
  5038. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5039. }
  5040. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5041. var total_count int64
  5042. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5043. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5044. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5045. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5046. }
  5047. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5048. total_count += prescribingNumberSeven
  5049. }
  5050. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5051. total_count += prescribingNumberSeven
  5052. }
  5053. //出库
  5054. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5055. WarehouseOutOrderNumber: warehousing_out_order,
  5056. WarehouseOutId: lastWarehouseOut.ID,
  5057. DrugId: item.DrugId,
  5058. Count: total_count,
  5059. Price: 0,
  5060. TotalPrice: 0,
  5061. Status: 1,
  5062. Ctime: item.AdviceDate,
  5063. Mtime: item.AdviceDate,
  5064. Remark: "",
  5065. OrgId: item.UserOrgId,
  5066. Type: 0,
  5067. Manufacturer: selfBasedrug.Manufacturer,
  5068. Dealer: selfBasedrug.Dealer,
  5069. RetailPrice: 0,
  5070. RetailTotalPrice: 0,
  5071. CountUnit: selfBasedrug.MinUnit,
  5072. ExpiryDate: 0,
  5073. ProductDate: 0,
  5074. Number: "",
  5075. BatchNumber: "",
  5076. IsSys: 1,
  5077. WarehouseInfoId: 0,
  5078. AdminUserId: 0,
  5079. StockCount: "",
  5080. IsCheck: 1,
  5081. SysRecordTime: item.AdviceDate,
  5082. PatientId: item.PatientId,
  5083. ClassType: "",
  5084. AdviceId: item.ID,
  5085. }
  5086. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5087. }
  5088. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5089. for _, it := range warehousingOutInfo {
  5090. //查询今日是否有出库数据
  5091. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5092. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5093. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5094. //出库逻辑
  5095. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5096. //查询剩余库存
  5097. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5098. var sum_count int64
  5099. for _, its := range stockInfo {
  5100. if its.MaxUnit == medical.MaxUnit {
  5101. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5102. }
  5103. sum_count += its.StockMaxNumber + its.StockMinNumber
  5104. }
  5105. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5106. }
  5107. }
  5108. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5109. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5110. //耗材保存处方出库
  5111. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5112. //已收费和已发药限制逻辑
  5113. isCharge := false
  5114. isMedicine := false
  5115. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5116. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5117. if new_prescription.IsMedicine == 1 {
  5118. isMedicine = true
  5119. }
  5120. for _, item := range new_prescriptions {
  5121. if item.OrderStatus == 4 {
  5122. isCharge = true
  5123. }
  5124. }
  5125. if p_err != nil {
  5126. if new_prescription.ID > 0 {
  5127. if new_prescription.OrderStatus == 2 {
  5128. isCharge = true
  5129. }
  5130. }
  5131. }
  5132. for _, item := range advices {
  5133. if item.IsMedicine == 1 {
  5134. isMedicine = true
  5135. }
  5136. }
  5137. if isCharge {
  5138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5139. return
  5140. }
  5141. if isMedicine {
  5142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5143. return
  5144. }
  5145. //已收费和已发药限制逻辑
  5146. if len(projects) > 0 {
  5147. for _, item := range projects {
  5148. service.DeletePrintInfo(item.ID) //删除打印信息
  5149. if goodOutConfig.IsOpen != 1 {
  5150. if stockConfig.IsOpen == 1 {
  5151. if item.Type == 3 && item.IsOut == 1 {
  5152. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5153. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5154. good.Total = good.Total + f_count
  5155. service.UpdateGoodInfo(&good)
  5156. operation_time := time.Now().Unix()
  5157. creater := c.GetAdminUserInfo().AdminUser.Id
  5158. //创建退库单
  5159. timeStr := time.Now().Format("2006-01-02")
  5160. timeArr := strings.Split(timeStr, "-")
  5161. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5162. total = total + 1
  5163. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5164. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5165. cancelStock := models.CancelStock{
  5166. OrderNumber: orderNumber,
  5167. OperaTime: operation_time,
  5168. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5169. Creater: creater,
  5170. Ctime: time.Now().Unix(),
  5171. Status: 1,
  5172. ReturnTime: item.RecordDate,
  5173. Type: 1,
  5174. StorehouseId: houseConfig.StorehouseOutInfo,
  5175. IsCheck: 1,
  5176. }
  5177. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5178. if msgerrkonde == gorm.ErrRecordNotFound {
  5179. service.AddSigleCancelStock(&cancelStock)
  5180. }
  5181. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5182. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5183. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5184. //查询该耗材是否出库
  5185. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5186. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5187. deaerler, _ := service.GetDealerById(info.Dealer)
  5188. var total_count int64
  5189. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5190. total_count += count
  5191. if info.ID > 0 {
  5192. if info.Count >= total_count {
  5193. //回退库存
  5194. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5195. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5196. var flush_count int64
  5197. for _, it := range goodList {
  5198. flush_count += it.StockCount
  5199. }
  5200. cancelStockInfo := models.CancelStockInfo{
  5201. GoodId: item.ProjectId,
  5202. CancelStockId: cancel.ID,
  5203. GoodTypeId: good.GoodTypeId,
  5204. Count: prescribingNumber,
  5205. Price: info.Price,
  5206. Total: 0,
  5207. ProductDate: info.ProductDate,
  5208. ExpiryDate: info.ExpiryDate,
  5209. Ctime: time.Now().Unix(),
  5210. Status: 1,
  5211. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5212. OrderNumber: cancel.OrderNumber,
  5213. Type: 0,
  5214. Dealer: deaerler.DealerName,
  5215. Manufacturer: manufacturer.ManufacturerName,
  5216. Number: info.Number,
  5217. RegisterAccount: "",
  5218. Remark: "",
  5219. WarehouseInfoId: info.WarehouseInfotId,
  5220. PatientId: info.PatientId,
  5221. RecordDate: info.SysRecordTime,
  5222. StorehouseId: houseConfig.StorehouseOutInfo,
  5223. IsCheck: 1,
  5224. }
  5225. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5226. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5227. flow := models.VmStockFlow{
  5228. WarehousingId: info.WarehouseInfotId,
  5229. GoodId: item.ProjectId,
  5230. Number: info.Number,
  5231. LicenseNumber: info.LicenseNumber,
  5232. Count: prescribingNumber,
  5233. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5234. PatientId: item.PatientId,
  5235. SystemTime: info.SysRecordTime,
  5236. ConsumableType: 7,
  5237. IsSys: 0,
  5238. WarehousingOrder: "",
  5239. WarehouseOutId: info.WarehouseOutId,
  5240. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5241. IsEdit: 0,
  5242. CancelStockId: cancel.ID,
  5243. CancelOrderNumber: cancel.OrderNumber,
  5244. Manufacturer: manufacturer.ID,
  5245. Dealer: 0,
  5246. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5247. UpdateCreator: 0,
  5248. Status: 1,
  5249. Ctime: time.Now().Unix(),
  5250. Mtime: 0,
  5251. Price: info.Price,
  5252. WarehousingDetailId: info.WarehouseInfotId,
  5253. WarehouseOutDetailId: info.ID,
  5254. CancelOutDetailId: cancelInfo.ID,
  5255. ProductDate: info.ProductDate,
  5256. ExpireDate: info.ExpiryDate,
  5257. StorehouseId: houseConfig.StorehouseOutInfo,
  5258. OverCount: flush_count,
  5259. OperateTime: time.Now().Unix(),
  5260. }
  5261. service.CreateStockFlowOne(flow)
  5262. //退库数量增加
  5263. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5264. //出库数量减少
  5265. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5266. }
  5267. if info.Count < total_count {
  5268. //回退库存
  5269. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5270. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5271. var flush_count int64
  5272. for _, it := range goodList {
  5273. flush_count += it.StockCount
  5274. }
  5275. cancelStockInfo := models.CancelStockInfo{
  5276. GoodId: item.ProjectId,
  5277. CancelStockId: cancel.ID,
  5278. GoodTypeId: good.GoodTypeId,
  5279. Count: info.Count,
  5280. Price: info.Price,
  5281. Total: 0,
  5282. ProductDate: info.ProductDate,
  5283. ExpiryDate: info.ExpiryDate,
  5284. Ctime: time.Now().Unix(),
  5285. Status: 1,
  5286. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5287. OrderNumber: cancel.OrderNumber,
  5288. Type: 0,
  5289. Dealer: deaerler.DealerName,
  5290. Manufacturer: manufacturer.ManufacturerName,
  5291. Number: info.Number,
  5292. RegisterAccount: "",
  5293. Remark: "",
  5294. WarehouseInfoId: info.WarehouseInfotId,
  5295. PatientId: info.PatientId,
  5296. RecordDate: info.SysRecordTime,
  5297. StorehouseId: houseConfig.StorehouseOutInfo,
  5298. IsCheck: 1,
  5299. }
  5300. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5301. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5302. flow := models.VmStockFlow{
  5303. WarehousingId: info.WarehouseInfotId,
  5304. GoodId: item.ProjectId,
  5305. Number: info.Number,
  5306. LicenseNumber: info.LicenseNumber,
  5307. Count: info.Count,
  5308. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5309. PatientId: item.PatientId,
  5310. SystemTime: info.SysRecordTime,
  5311. ConsumableType: 7,
  5312. IsSys: 0,
  5313. WarehousingOrder: "",
  5314. WarehouseOutId: info.WarehouseOutId,
  5315. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5316. IsEdit: 0,
  5317. CancelStockId: cancel.ID,
  5318. CancelOrderNumber: cancel.OrderNumber,
  5319. Manufacturer: manufacturer.ID,
  5320. Dealer: 0,
  5321. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5322. UpdateCreator: 0,
  5323. Status: 1,
  5324. Ctime: time.Now().Unix(),
  5325. Mtime: 0,
  5326. Price: info.Price,
  5327. WarehousingDetailId: info.WarehouseInfotId,
  5328. WarehouseOutDetailId: info.ID,
  5329. CancelOutDetailId: cancelInfo.ID,
  5330. ProductDate: info.ProductDate,
  5331. ExpireDate: info.ExpiryDate,
  5332. StorehouseId: houseConfig.StorehouseOutInfo,
  5333. OverCount: flush_count,
  5334. OperateTime: time.Now().Unix(),
  5335. }
  5336. service.CreateStockFlowOne(flow)
  5337. //退库数量增加
  5338. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5339. //出库数量减少
  5340. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5341. }
  5342. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5343. var flush_count int64
  5344. for _, it := range goodList {
  5345. flush_count += it.StockCount
  5346. }
  5347. //查询已出库数量
  5348. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5349. if prescribingNumber < dialysisInfo.Count {
  5350. //改变数量
  5351. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5352. }
  5353. if prescribingNumber >= dialysisInfo.Count {
  5354. //删除出库表
  5355. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5356. }
  5357. //更新库存
  5358. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5359. //更新基础库库存
  5360. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5361. }
  5362. }
  5363. }
  5364. }
  5365. //保存耗材出库
  5366. if goodOutConfig.IsOpen == 1 {
  5367. if item.Type == 3 {
  5368. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5369. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5370. good.Total = good.Total + f_count
  5371. service.UpdateGoodInfo(&good)
  5372. operation_time := time.Now().Unix()
  5373. creater := c.GetAdminUserInfo().AdminUser.Id
  5374. //创建退库单
  5375. timeStr := time.Now().Format("2006-01-02")
  5376. timeArr := strings.Split(timeStr, "-")
  5377. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5378. total = total + 1
  5379. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5380. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5381. cancelStock := models.CancelStock{
  5382. OrderNumber: orderNumber,
  5383. OperaTime: operation_time,
  5384. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5385. Creater: creater,
  5386. Ctime: time.Now().Unix(),
  5387. Status: 1,
  5388. ReturnTime: item.RecordDate,
  5389. Type: 1,
  5390. StorehouseId: houseConfig.StorehouseOutInfo,
  5391. IsCheck: 1,
  5392. }
  5393. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5394. if msgerrkonde == gorm.ErrRecordNotFound {
  5395. service.AddSigleCancelStock(&cancelStock)
  5396. }
  5397. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5398. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5399. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5400. //查询该耗材是否出库
  5401. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5402. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5403. deaerler, _ := service.GetDealerById(info.Dealer)
  5404. var total_count int64
  5405. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5406. total_count += count
  5407. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5408. var flush_count int64
  5409. for _, it := range goodList {
  5410. flush_count += it.StockCount
  5411. }
  5412. fmt.Println("历史出库数据", info.Count)
  5413. fmt.Println("出库数量", total_count)
  5414. if info.ID > 0 {
  5415. cancelStockInfo := models.CancelStockInfo{
  5416. GoodId: item.ProjectId,
  5417. CancelStockId: cancel.ID,
  5418. GoodTypeId: good.GoodTypeId,
  5419. Count: prescribingNumber,
  5420. Price: info.Price,
  5421. Total: 0,
  5422. ProductDate: info.ProductDate,
  5423. ExpiryDate: info.ExpiryDate,
  5424. Ctime: time.Now().Unix(),
  5425. Status: 1,
  5426. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5427. OrderNumber: cancel.OrderNumber,
  5428. Type: 0,
  5429. Dealer: deaerler.DealerName,
  5430. Manufacturer: manufacturer.ManufacturerName,
  5431. Number: info.Number,
  5432. RegisterAccount: "",
  5433. Remark: "",
  5434. WarehouseInfoId: info.WarehouseInfotId,
  5435. PatientId: info.PatientId,
  5436. RecordDate: info.SysRecordTime,
  5437. StorehouseId: houseConfig.StorehouseOutInfo,
  5438. IsCheck: 1,
  5439. }
  5440. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5441. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5442. //查询出库数量
  5443. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5444. //出库数据 大于 退库数量
  5445. if len(list) > 0 {
  5446. for _, it := range list {
  5447. //回退库存
  5448. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5449. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5450. var flush_count_one int64
  5451. for _, it := range goodList {
  5452. flush_count_one += it.StockCount
  5453. }
  5454. //查询该批次是否有退库数据
  5455. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5456. creater := c.GetAdminUserInfo().AdminUser.Id
  5457. flow := models.VmStockFlow{
  5458. WarehousingId: it.WarehouseInfotId,
  5459. GoodId: it.GoodId,
  5460. Number: it.Number,
  5461. LicenseNumber: it.LicenseNumber,
  5462. Count: it.Count,
  5463. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5464. PatientId: it.PatientId,
  5465. SystemTime: it.SysRecordTime,
  5466. ConsumableType: 7,
  5467. IsSys: 0,
  5468. WarehousingOrder: "",
  5469. WarehouseOutId: it.WarehouseOutId,
  5470. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5471. IsEdit: 0,
  5472. CancelStockId: cancel.ID,
  5473. CancelOrderNumber: cancel.OrderNumber,
  5474. Manufacturer: manufacturer.ID,
  5475. Dealer: 0,
  5476. Creator: creater,
  5477. UpdateCreator: 0,
  5478. Status: 1,
  5479. Ctime: time.Now().Unix(),
  5480. Mtime: 0,
  5481. Price: it.Price,
  5482. WarehousingDetailId: it.WarehouseInfotId,
  5483. WarehouseOutDetailId: it.ID,
  5484. CancelOutDetailId: cancelInfo.ID,
  5485. ProductDate: it.ProductDate,
  5486. ExpireDate: it.ExpiryDate,
  5487. StorehouseId: houseConfig.StorehouseOutInfo,
  5488. OverCount: flush_count_one,
  5489. }
  5490. service.CreateStockFlowOne(flow)
  5491. //if flow.ID > 0 {
  5492. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5493. //}
  5494. }
  5495. }
  5496. //flow := models.VmStockFlow{
  5497. // WarehousingId: info.WarehouseInfotId,
  5498. // GoodId: item.ProjectId,
  5499. // Number: info.Number,
  5500. // LicenseNumber: info.LicenseNumber,
  5501. // Count: prescribingNumber,
  5502. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5503. // PatientId: item.PatientId,
  5504. // SystemTime: info.SysRecordTime,
  5505. // ConsumableType: 7,
  5506. // IsSys: 0,
  5507. // WarehousingOrder: "",
  5508. // WarehouseOutId: info.WarehouseOutId,
  5509. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5510. // IsEdit: 0,
  5511. // CancelStockId: cancel.ID,
  5512. // CancelOrderNumber: cancel.OrderNumber,
  5513. // Manufacturer: manufacturer.ID,
  5514. // Dealer: 0,
  5515. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5516. // UpdateCreator: 0,
  5517. // Status: 1,
  5518. // Ctime: time.Now().Unix(),
  5519. // Mtime: 0,
  5520. // Price: info.Price,
  5521. // WarehousingDetailId: info.WarehouseInfotId,
  5522. // WarehouseOutDetailId: info.ID,
  5523. // CancelOutDetailId: cancelInfo.ID,
  5524. // ProductDate: info.ProductDate,
  5525. // ExpireDate: info.ExpiryDate,
  5526. // StorehouseId: houseConfig.StorehouseOutInfo,
  5527. // OverCount: flush_count,
  5528. //}
  5529. //service.CreateStockFlowOne(flow)
  5530. //退库数量增加
  5531. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5532. //出库数量减少
  5533. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5534. //查询已出库数量
  5535. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5536. if prescribingNumber < dialysisInfo.Count {
  5537. //改变数量
  5538. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5539. }
  5540. if prescribingNumber >= dialysisInfo.Count {
  5541. //删除出库表
  5542. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5543. }
  5544. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5545. var flush_count_one int64
  5546. for _, it := range goodList {
  5547. flush_count_one += it.StockCount
  5548. }
  5549. //更新库存
  5550. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5551. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5552. //更新基础库库存
  5553. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5554. }
  5555. }
  5556. }
  5557. }
  5558. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5559. fmt.Println(err)
  5560. }
  5561. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5562. fmt.Println(err)
  5563. if len(advices) > 0 {
  5564. for _, item := range advices {
  5565. redis := service.RedisClient()
  5566. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5567. redis.Set(keyFive, "", time.Second)
  5568. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5569. redis.Set(keyOne, "", time.Second)
  5570. redis.Close()
  5571. }
  5572. }
  5573. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5574. if len(advices) > 0 {
  5575. for _, item := range advices {
  5576. creater := c.GetAdminUserInfo().AdminUser.Id
  5577. service.DrugAutoAddCancelInfo(item, creater)
  5578. }
  5579. }
  5580. } else {
  5581. if drugOutConfig.IsOpen == 1 {
  5582. if len(advices) > 0 {
  5583. for _, item := range advices {
  5584. creater := c.GetAdminUserInfo().AdminUser.Id
  5585. service.DrugAutoAddCancelInfo(item, creater)
  5586. }
  5587. }
  5588. } else {
  5589. if len(advices) > 0 {
  5590. for _, item := range advices {
  5591. creater := c.GetAdminUserInfo().AdminUser.Id
  5592. service.DrugAutoAddCancelInfo(item, creater)
  5593. }
  5594. }
  5595. }
  5596. }
  5597. c.ServeSuccessJSON(map[string]interface{}{
  5598. "msg": "删除成功",
  5599. })
  5600. return
  5601. }
  5602. func (c *HisApiController) DeleteDoctorAdvice() {
  5603. id, _ := c.GetInt64("id")
  5604. advice, _ := service.GetHisDoctorAdvicesById(id)
  5605. ////同步到自备药
  5606. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5607. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5608. if selfPrescriptionOpen.IsOpen == 1 {
  5609. db := service.XTWriteDB()
  5610. tx := db.Begin()
  5611. defer func() {
  5612. if r := recover(); r != nil {
  5613. tx.Rollback()
  5614. } else {
  5615. tx.Commit()
  5616. }
  5617. }()
  5618. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5619. var total_count int64
  5620. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5621. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5622. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5623. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5624. }
  5625. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5626. total_count += prescribingNumberSeven
  5627. }
  5628. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5629. total_count += prescribingNumberSeven
  5630. }
  5631. timeStr := time.Now().Format("2006-01-02")
  5632. timeArr := strings.Split(timeStr, "-")
  5633. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5634. total = total + 1
  5635. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5636. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5637. number = number + total
  5638. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5639. operation_time := time.Now().Unix()
  5640. creater := c.GetAdminUserInfo().AdminUser.Id
  5641. //创建一个出库单
  5642. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5643. WarehouseOutOrderNumber: warehousing_out_order,
  5644. OperationTime: operation_time,
  5645. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5646. Creater: creater,
  5647. Ctime: time.Now().Unix(),
  5648. Status: 1,
  5649. WarehouseOutTime: advice.AdviceDate,
  5650. Type: 0,
  5651. PatientId: advice.PatientId,
  5652. IsCheck: 1,
  5653. }
  5654. //查询今日是否有出库数据
  5655. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5656. if lastWarehouseOut.ID == 0 {
  5657. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5658. }
  5659. //出库
  5660. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5661. WarehouseOutId: lastWarehouseOut.ID,
  5662. WarehouseOutOrderNumber: warehousing_out_order,
  5663. DrugId: advice.DrugId,
  5664. Count: total_count,
  5665. Price: 0,
  5666. TotalPrice: 0,
  5667. Status: 1,
  5668. Ctime: advice.AdviceDate,
  5669. Mtime: advice.AdviceDate,
  5670. Remark: "",
  5671. OrgId: advice.UserOrgId,
  5672. Type: 0,
  5673. Manufacturer: selfBasedrug.Manufacturer,
  5674. Dealer: selfBasedrug.Dealer,
  5675. RetailPrice: 0,
  5676. RetailTotalPrice: 0,
  5677. CountUnit: advice.PrescribingNumberUnit,
  5678. ExpiryDate: 0,
  5679. ProductDate: 0,
  5680. Number: "",
  5681. BatchNumber: "",
  5682. IsSys: 0,
  5683. WarehouseInfoId: 0,
  5684. AdminUserId: 0,
  5685. StockCount: "",
  5686. IsCheck: 1,
  5687. SysRecordTime: advice.AdviceDate,
  5688. PatientId: advice.PatientId,
  5689. AdviceId: advice.ID,
  5690. ClassType: "",
  5691. }
  5692. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5693. for _, it := range warehousingOutInfo {
  5694. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5695. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5696. //出库逻辑
  5697. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5698. //查询剩余库存
  5699. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5700. var sum_count int64
  5701. for _, its := range stockInfo {
  5702. if its.MaxUnit == medical.MaxUnit {
  5703. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5704. }
  5705. sum_count += its.StockMaxNumber + its.StockMinNumber
  5706. }
  5707. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5708. }
  5709. }
  5710. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5711. //已收费和已发药的限制逻辑
  5712. isCharge := false
  5713. isMedicine := false
  5714. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5715. //获取今天该患者所有处方,判断是否发药或者收费
  5716. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5717. //for _, item := range new_prescriptions {
  5718. if new_prescription.IsMedicine == 1 {
  5719. isMedicine = true
  5720. }
  5721. //}
  5722. for _, item := range new_prescriptions {
  5723. if item.OrderStatus == 4 {
  5724. isCharge = true
  5725. }
  5726. }
  5727. if isMedicine {
  5728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5729. return
  5730. }
  5731. if isCharge {
  5732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5733. return
  5734. }
  5735. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5736. for _, item := range advices {
  5737. if item.IsMedicine == 1 {
  5738. isMedicine = true
  5739. }
  5740. }
  5741. if isMedicine {
  5742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5743. return
  5744. }
  5745. if new_prescription.ID > 0 {
  5746. if new_prescription.OrderStatus == 2 {
  5747. isCharge = true
  5748. }
  5749. }
  5750. if isCharge {
  5751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5752. return
  5753. }
  5754. //已收费和已发药的限制逻辑
  5755. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5756. redis := service.RedisClient()
  5757. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5758. redis.Set(keyFive, "", time.Second)
  5759. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5760. redis.Set(keyOne, "", time.Second)
  5761. defer redis.Close()
  5762. if err == nil {
  5763. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5764. //查询是否在处方中出库
  5765. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5766. if openConfig.IsOpen != 1 {
  5767. //判断该医嘱是否执行了
  5768. if advice.ExecutionState == 1 {
  5769. creater := c.GetAdminUserInfo().AdminUser.Id
  5770. service.DrugAutoAddCancelInfo(&advice, creater)
  5771. }
  5772. }
  5773. //开启保存处方扣减功能
  5774. if openConfig.IsOpen == 1 {
  5775. creater := c.GetAdminUserInfo().AdminUser.Id
  5776. service.DrugAutoAddCancelInfo(&advice, creater)
  5777. }
  5778. } else {
  5779. if drugOutConfig.IsOpen == 1 {
  5780. //查询是否在处方中出库
  5781. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5782. if openConfig.IsOpen != 1 {
  5783. //判断该医嘱是否执行了
  5784. if advice.ExecutionState == 1 {
  5785. creater := c.GetAdminUserInfo().AdminUser.Id
  5786. service.DrugAutoAddCancelInfo(&advice, creater)
  5787. }
  5788. }
  5789. //开启保存处方扣减功能
  5790. if openConfig.IsOpen == 1 {
  5791. creater := c.GetAdminUserInfo().AdminUser.Id
  5792. service.DrugAutoAddCancelInfo(&advice, creater)
  5793. }
  5794. } else {
  5795. //判断该医嘱是否执行了
  5796. if advice.ExecutionState == 1 {
  5797. creater := c.GetAdminUserInfo().AdminUser.Id
  5798. service.DrugAutoAddCancelInfo(&advice, creater)
  5799. }
  5800. }
  5801. }
  5802. c.ServeSuccessJSON(map[string]interface{}{
  5803. "msg": "删除成功",
  5804. })
  5805. return
  5806. } else {
  5807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5808. return
  5809. }
  5810. }
  5811. func (c *HisApiController) DeleteProject() {
  5812. id, _ := c.GetInt64("id")
  5813. adminInfo := c.GetAdminUserInfo()
  5814. project, _ := service.GetHisProjectByID(id)
  5815. // var consumable models.DialysisBeforePrepare
  5816. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5817. //耗材保存处方出库
  5818. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5819. isCharge := false
  5820. isMedicine := false
  5821. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5822. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5823. for _, item := range new_prescriptions {
  5824. if item.IsMedicine == 1 {
  5825. isMedicine = true
  5826. }
  5827. }
  5828. for _, item := range new_prescriptions {
  5829. if item.OrderStatus == 4 {
  5830. isCharge = true
  5831. }
  5832. }
  5833. if isMedicine {
  5834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5835. return
  5836. }
  5837. if isCharge {
  5838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5839. return
  5840. }
  5841. if new_prescription.ID > 0 {
  5842. if new_prescription.OrderStatus == 2 {
  5843. isCharge = true
  5844. }
  5845. }
  5846. if isCharge {
  5847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5848. return
  5849. }
  5850. service.DeletePrintInfo(id)
  5851. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5852. label.Status = 0
  5853. service.CreateHisLabelRecordTwo(&label)
  5854. fmt.Println(goodOutConfig.IsOpen)
  5855. if goodOutConfig.IsOpen != 1 {
  5856. if stockConfig.IsOpen == 1 {
  5857. if project.Type == 2 {
  5858. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5859. fmt.Println(err)
  5860. }
  5861. if project.Type == 3 && project.IsOut == 1 {
  5862. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5863. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5864. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5865. operation_time := time.Now().Unix()
  5866. creater := adminInfo.AdminUser.Id
  5867. //创建退库单
  5868. timeStr := time.Now().Format("2006-01-02")
  5869. timeArr := strings.Split(timeStr, "-")
  5870. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5871. total = total + 1
  5872. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5873. cancelStock := models.CancelStock{
  5874. OrderNumber: orderNumber,
  5875. OperaTime: operation_time,
  5876. OrgId: adminInfo.CurrentOrgId,
  5877. Creater: creater,
  5878. Ctime: time.Now().Unix(),
  5879. Status: 1,
  5880. ReturnTime: project.RecordDate,
  5881. Type: 1,
  5882. StorehouseId: houseConfig.StorehouseOutInfo,
  5883. IsCheck: 1,
  5884. }
  5885. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5886. if msgerrkonde == gorm.ErrRecordNotFound {
  5887. service.AddSigleCancelStock(&cancelStock)
  5888. }
  5889. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5890. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5891. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5892. //查询是否有出库
  5893. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5894. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5895. deaerler, _ := service.GetDealerById(info.Dealer)
  5896. if info.ID > 0 {
  5897. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5898. if info.Count >= prescribingNumber {
  5899. cancelStockInfo := models.CancelStockInfo{
  5900. GoodId: project.ProjectId,
  5901. CancelStockId: cancel.ID,
  5902. GoodTypeId: good.GoodTypeId,
  5903. Count: prescribingNumber,
  5904. Price: info.Price,
  5905. Total: 0,
  5906. ProductDate: info.ProductDate,
  5907. ExpiryDate: info.ExpiryDate,
  5908. Ctime: time.Now().Unix(),
  5909. Status: 1,
  5910. OrgId: adminInfo.CurrentOrgId,
  5911. OrderNumber: cancel.OrderNumber,
  5912. Type: 0,
  5913. Dealer: deaerler.DealerName,
  5914. Manufacturer: manufacturer.ManufacturerName,
  5915. Number: info.Number,
  5916. RegisterAccount: "",
  5917. Remark: "",
  5918. WarehouseInfoId: info.WarehouseInfotId,
  5919. PatientId: info.PatientId,
  5920. RecordDate: info.SysRecordTime,
  5921. StorehouseId: houseConfig.StorehouseOutInfo,
  5922. IsCheck: 1,
  5923. }
  5924. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5925. //回退库存
  5926. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5927. //退库数量增加
  5928. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5929. //出库数量减少
  5930. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5931. }
  5932. if info.Count < prescribingNumber {
  5933. cancelStockInfo := models.CancelStockInfo{
  5934. GoodId: project.ProjectId,
  5935. CancelStockId: cancel.ID,
  5936. GoodTypeId: good.GoodTypeId,
  5937. Count: info.Count,
  5938. Price: info.Price,
  5939. Total: 0,
  5940. ProductDate: info.ProductDate,
  5941. ExpiryDate: info.ExpiryDate,
  5942. Ctime: time.Now().Unix(),
  5943. Status: 1,
  5944. OrgId: adminInfo.CurrentOrgId,
  5945. OrderNumber: cancel.OrderNumber,
  5946. Type: 0,
  5947. Dealer: deaerler.DealerName,
  5948. Manufacturer: manufacturer.ManufacturerName,
  5949. Number: info.Number,
  5950. RegisterAccount: "",
  5951. Remark: "",
  5952. WarehouseInfoId: info.WarehouseInfotId,
  5953. PatientId: info.PatientId,
  5954. RecordDate: info.SysRecordTime,
  5955. StorehouseId: houseConfig.StorehouseOutInfo,
  5956. IsCheck: 1,
  5957. }
  5958. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5959. //回退库存
  5960. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5961. //退库数量增加
  5962. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5963. //出库数量减少
  5964. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5965. }
  5966. //查询剩余库存
  5967. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5968. var over_count int64
  5969. for _, it := range goodList {
  5970. over_count += it.StockCount
  5971. }
  5972. //出库数据 大于 退库数量
  5973. if info.Count >= prescribingNumber {
  5974. flow := models.VmStockFlow{
  5975. WarehousingId: info.WarehouseInfotId,
  5976. GoodId: project.ProjectId,
  5977. Number: info.Number,
  5978. LicenseNumber: info.LicenseNumber,
  5979. Count: prescribingNumber,
  5980. UserOrgId: adminInfo.CurrentOrgId,
  5981. PatientId: project.PatientId,
  5982. SystemTime: info.SysRecordTime,
  5983. ConsumableType: 7,
  5984. IsSys: 0,
  5985. WarehousingOrder: "",
  5986. WarehouseOutId: info.WarehouseOutId,
  5987. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5988. IsEdit: 0,
  5989. CancelStockId: cancel.ID,
  5990. CancelOrderNumber: cancel.OrderNumber,
  5991. Manufacturer: manufacturer.ID,
  5992. Dealer: 0,
  5993. Creator: adminInfo.AdminUser.Id,
  5994. UpdateCreator: 0,
  5995. Status: 1,
  5996. Ctime: time.Now().Unix(),
  5997. Mtime: 0,
  5998. Price: info.Price,
  5999. WarehousingDetailId: info.WarehouseInfotId,
  6000. WarehouseOutDetailId: info.ID,
  6001. CancelOutDetailId: cancelInfo.ID,
  6002. ProductDate: info.ProductDate,
  6003. ExpireDate: info.ExpiryDate,
  6004. StorehouseId: houseConfig.StorehouseOutInfo,
  6005. OverCount: over_count,
  6006. OperateTime: time.Now().Unix(),
  6007. }
  6008. service.CreateStockFlowOne(flow)
  6009. }
  6010. //出库数据小于退库数据
  6011. if info.Count < prescribingNumber {
  6012. flow := models.VmStockFlow{
  6013. WarehousingId: info.WarehouseInfotId,
  6014. GoodId: project.ProjectId,
  6015. Number: info.Number,
  6016. LicenseNumber: info.LicenseNumber,
  6017. Count: info.Count,
  6018. UserOrgId: adminInfo.CurrentOrgId,
  6019. PatientId: project.PatientId,
  6020. SystemTime: info.SysRecordTime,
  6021. ConsumableType: 7,
  6022. IsSys: 0,
  6023. WarehousingOrder: "",
  6024. WarehouseOutId: info.WarehouseOutId,
  6025. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6026. IsEdit: 0,
  6027. CancelStockId: cancel.ID,
  6028. CancelOrderNumber: cancel.OrderNumber,
  6029. Manufacturer: manufacturer.ID,
  6030. Dealer: 0,
  6031. Creator: adminInfo.AdminUser.Id,
  6032. UpdateCreator: 0,
  6033. Status: 1,
  6034. Ctime: time.Now().Unix(),
  6035. Mtime: 0,
  6036. Price: info.Price,
  6037. WarehousingDetailId: info.WarehouseInfotId,
  6038. WarehouseOutDetailId: info.ID,
  6039. CancelOutDetailId: cancelInfo.ID,
  6040. ProductDate: info.ProductDate,
  6041. ExpireDate: info.ExpiryDate,
  6042. StorehouseId: houseConfig.StorehouseOutInfo,
  6043. OverCount: over_count,
  6044. OperateTime: time.Now().Unix(),
  6045. }
  6046. service.CreateStockFlowOne(flow)
  6047. }
  6048. //查询已出库数量
  6049. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6050. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6051. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6052. if prescribingNumber < dialysisInfo.Count {
  6053. //改变数量
  6054. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6055. }
  6056. if prescribingNumber >= dialysisInfo.Count {
  6057. //删除出库表
  6058. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6059. }
  6060. //更新剩余库存
  6061. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6062. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6063. var total_count_one int64
  6064. for _, it := range stockList {
  6065. total_count_one += it.StockCount
  6066. }
  6067. //基础库插入数据
  6068. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6069. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6070. var flush_count int64
  6071. for _, it := range goodListOne {
  6072. flush_count += it.StockCount
  6073. }
  6074. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6075. if errs != nil {
  6076. goodErrcode := models.XtGoodErrcode{
  6077. UserOrgId: project.UserOrgId,
  6078. Errcode: "手动出库更新剩余出库失败",
  6079. GoodId: project.ProjectId,
  6080. Status: 1,
  6081. Ctime: time.Now().Unix(),
  6082. Mtime: 0,
  6083. Count: 0,
  6084. StockCount: 0,
  6085. Creater: creater,
  6086. BatchNumberId: 0,
  6087. WarehouseOutId: 0,
  6088. }
  6089. service.CreateGoodErrcode(goodErrcode)
  6090. }
  6091. }
  6092. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6093. fmt.Println(err)
  6094. } else {
  6095. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6096. fmt.Println(err)
  6097. }
  6098. } else {
  6099. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6100. fmt.Println(err)
  6101. }
  6102. }
  6103. //保存处方出库
  6104. if goodOutConfig.IsOpen == 1 {
  6105. if project.Type == 3 {
  6106. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6107. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6108. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6109. operation_time := time.Now().Unix()
  6110. creater := adminInfo.AdminUser.Id
  6111. //创建退库单
  6112. timeStr := time.Now().Format("2006-01-02")
  6113. timeArr := strings.Split(timeStr, "-")
  6114. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6115. total = total + 1
  6116. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6117. cancelStock := models.CancelStock{
  6118. OrderNumber: orderNumber,
  6119. OperaTime: operation_time,
  6120. OrgId: adminInfo.CurrentOrgId,
  6121. Creater: creater,
  6122. Ctime: time.Now().Unix(),
  6123. Status: 1,
  6124. ReturnTime: project.RecordDate,
  6125. Type: 1,
  6126. StorehouseId: houseConfig.StorehouseOutInfo,
  6127. IsCheck: 1,
  6128. }
  6129. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6130. if msgerrkonde == gorm.ErrRecordNotFound {
  6131. service.AddSigleCancelStock(&cancelStock)
  6132. }
  6133. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6134. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6135. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6136. //获取出库数据
  6137. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6138. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6139. deaerler, _ := service.GetDealerById(info.Dealer)
  6140. if info.ID > 0 {
  6141. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6142. if info.Count >= prescribingNumber {
  6143. cancelStockInfo := models.CancelStockInfo{
  6144. GoodId: project.ProjectId,
  6145. CancelStockId: cancel.ID,
  6146. GoodTypeId: good.GoodTypeId,
  6147. Count: prescribingNumber,
  6148. Price: info.Price,
  6149. Total: 0,
  6150. ProductDate: info.ProductDate,
  6151. ExpiryDate: info.ExpiryDate,
  6152. Ctime: time.Now().Unix(),
  6153. Status: 1,
  6154. OrgId: adminInfo.CurrentOrgId,
  6155. OrderNumber: cancel.OrderNumber,
  6156. Type: 0,
  6157. Dealer: deaerler.DealerName,
  6158. Manufacturer: manufacturer.ManufacturerName,
  6159. Number: info.Number,
  6160. RegisterAccount: "",
  6161. Remark: "",
  6162. WarehouseInfoId: info.WarehouseInfotId,
  6163. PatientId: info.PatientId,
  6164. RecordDate: info.SysRecordTime,
  6165. StorehouseId: houseConfig.StorehouseOutInfo,
  6166. IsCheck: 1,
  6167. }
  6168. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6169. //退库数量增加
  6170. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6171. //出库数量减少
  6172. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6173. }
  6174. if info.Count < prescribingNumber {
  6175. cancelStockInfo := models.CancelStockInfo{
  6176. GoodId: project.ProjectId,
  6177. CancelStockId: cancel.ID,
  6178. GoodTypeId: good.GoodTypeId,
  6179. Count: prescribingNumber,
  6180. Price: info.Price,
  6181. Total: 0,
  6182. ProductDate: info.ProductDate,
  6183. ExpiryDate: info.ExpiryDate,
  6184. Ctime: time.Now().Unix(),
  6185. Status: 1,
  6186. OrgId: adminInfo.CurrentOrgId,
  6187. OrderNumber: cancel.OrderNumber,
  6188. Type: 0,
  6189. Dealer: deaerler.DealerName,
  6190. Manufacturer: manufacturer.ManufacturerName,
  6191. Number: info.Number,
  6192. RegisterAccount: "",
  6193. Remark: "",
  6194. WarehouseInfoId: info.WarehouseInfotId,
  6195. PatientId: info.PatientId,
  6196. RecordDate: info.SysRecordTime,
  6197. StorehouseId: houseConfig.StorehouseOutInfo,
  6198. IsCheck: 1,
  6199. }
  6200. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6201. //回退库存
  6202. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6203. }
  6204. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6205. var over_count int64
  6206. for _, it := range goodList {
  6207. over_count += it.StockCount
  6208. }
  6209. //查询出库数量
  6210. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6211. //出库数据 大于 退库数量
  6212. if len(list) > 0 {
  6213. for _, it := range list {
  6214. //回退库存
  6215. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6216. //退库数量增加
  6217. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6218. //出库数量减少
  6219. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6220. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6221. var over_count_one int64
  6222. for _, it := range goodList {
  6223. over_count_one += it.StockCount
  6224. }
  6225. //查询该批次是否有退库数据
  6226. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6227. flow := models.VmStockFlow{
  6228. WarehousingId: it.WarehouseInfotId,
  6229. GoodId: it.GoodId,
  6230. Number: it.Number,
  6231. LicenseNumber: it.LicenseNumber,
  6232. Count: it.Count,
  6233. UserOrgId: adminInfo.CurrentOrgId,
  6234. PatientId: it.PatientId,
  6235. SystemTime: it.SysRecordTime,
  6236. ConsumableType: 7,
  6237. IsSys: 0,
  6238. WarehousingOrder: "",
  6239. WarehouseOutId: it.WarehouseOutId,
  6240. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6241. IsEdit: 0,
  6242. CancelStockId: cancel.ID,
  6243. CancelOrderNumber: cancel.OrderNumber,
  6244. Manufacturer: manufacturer.ID,
  6245. Dealer: 0,
  6246. Creator: adminInfo.AdminUser.Id,
  6247. UpdateCreator: 0,
  6248. Status: 1,
  6249. Ctime: time.Now().Unix(),
  6250. Mtime: 0,
  6251. Price: it.Price,
  6252. WarehousingDetailId: it.WarehouseInfotId,
  6253. WarehouseOutDetailId: it.ID,
  6254. CancelOutDetailId: cancelInfo.ID,
  6255. ProductDate: it.ProductDate,
  6256. ExpireDate: it.ExpiryDate,
  6257. StorehouseId: houseConfig.StorehouseOutInfo,
  6258. OverCount: over_count_one,
  6259. OperateTime: time.Now().Unix(),
  6260. }
  6261. service.CreateStockFlowOne(flow)
  6262. }
  6263. }
  6264. //查询已出库数量
  6265. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6266. if prescribingNumber < dialysisInfo.Count {
  6267. //改变数量
  6268. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6269. }
  6270. if prescribingNumber >= dialysisInfo.Count {
  6271. //删除出库表
  6272. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6273. }
  6274. //更新剩余库存
  6275. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6276. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6277. var total_count_one int64
  6278. for _, it := range stockList {
  6279. total_count_one += it.StockCount
  6280. }
  6281. //基础库插入数据
  6282. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6283. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6284. var flush_count int64
  6285. for _, it := range goodListOne {
  6286. flush_count += it.StockCount
  6287. }
  6288. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6289. if errs != nil {
  6290. goodErrcode := models.XtGoodErrcode{
  6291. UserOrgId: project.UserOrgId,
  6292. Errcode: "手动出库更新剩余出库失败",
  6293. GoodId: project.ProjectId,
  6294. Status: 1,
  6295. Ctime: time.Now().Unix(),
  6296. Mtime: 0,
  6297. Count: 0,
  6298. StockCount: 0,
  6299. Creater: creater,
  6300. BatchNumberId: 0,
  6301. WarehouseOutId: 0,
  6302. }
  6303. service.CreateGoodErrcode(goodErrcode)
  6304. }
  6305. }
  6306. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6307. fmt.Println(err)
  6308. } else {
  6309. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6310. fmt.Println(err)
  6311. }
  6312. }
  6313. c.ServeSuccessJSON(map[string]interface{}{
  6314. "msg": "删除成功",
  6315. })
  6316. return
  6317. }
  6318. func (c *HisApiController) CreateHisAdditionalCharge() {
  6319. his_patient_id, _ := c.GetInt64("his_patient_id")
  6320. patient_id, _ := c.GetInt64("patient_id")
  6321. record_date := c.GetString("record_date")
  6322. timeLayout := "2006-01-02"
  6323. loc, _ := time.LoadLocation("Local")
  6324. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6325. if err != nil {
  6326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6327. return
  6328. }
  6329. adminInfo := c.GetAdminUserInfo()
  6330. recordDateTime := theTime.Unix()
  6331. dataBody := make(map[string]interface{}, 0)
  6332. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6333. if err != nil {
  6334. utils.ErrorLog(err.Error())
  6335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6336. return
  6337. }
  6338. var additions []*models.HisAdditionalCharge
  6339. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6340. additions, _ := dataBody["addition"].([]interface{})
  6341. if len(additions) > 0 {
  6342. for _, item := range additions {
  6343. items := item.(map[string]interface{})
  6344. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6345. utils.ErrorLog("item_id")
  6346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6347. return
  6348. }
  6349. item_id := int64(items["item_id"].(float64))
  6350. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6351. utils.ErrorLog("item_name")
  6352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6353. return
  6354. }
  6355. item_name := items["item_name"].(string)
  6356. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6357. utils.ErrorLog("price")
  6358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6359. return
  6360. }
  6361. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6362. ctime := time.Now().Unix()
  6363. additional := &models.HisAdditionalCharge{
  6364. PatientId: patient_id,
  6365. HisPatientId: his_patient_id,
  6366. UserOrgId: adminInfo.CurrentOrgId,
  6367. RecordDate: recordDateTime,
  6368. CreatedTime: ctime,
  6369. UpdatedTime: ctime,
  6370. Modifier: adminInfo.AdminUser.Id,
  6371. Creator: adminInfo.AdminUser.Id,
  6372. Price: price,
  6373. ItemName: item_name,
  6374. ItemId: item_id,
  6375. Status: 1,
  6376. }
  6377. additions = append(additions, additional)
  6378. }
  6379. }
  6380. }
  6381. for _, item := range additions {
  6382. service.CreateAddtionalCharge(item)
  6383. }
  6384. c.ServeSuccessJSON(map[string]interface{}{
  6385. "msg": "创建成功",
  6386. })
  6387. }
  6388. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6389. blood_fat := c.GetString("blood_fat")
  6390. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6391. blood_sugar := c.GetString("blood_sugar")
  6392. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6393. chief_conplaint := c.GetString("chief_conplaint")
  6394. dbp := c.GetString("dbp")
  6395. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6396. delivery_way, _ := c.GetInt64("delivery_way")
  6397. diagnostic := c.GetString("diagnostic")
  6398. family_history := c.GetString("family_history")
  6399. height := c.GetString("height")
  6400. history_of_present_illness := c.GetString("history_of_present_illness")
  6401. is_infect, _ := c.GetInt64("is_infect")
  6402. past_history := c.GetString("past_history")
  6403. patient_id, _ := c.GetInt64("patient_id")
  6404. his_patient_id, _ := c.GetInt64("his_patient_id")
  6405. personal_history := c.GetString("personal_history")
  6406. pulse := c.GetString("pulse")
  6407. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6408. sbp := c.GetString("sbp")
  6409. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6410. heightfloat, _ := strconv.ParseFloat(height, 64)
  6411. sicktype := c.GetString("sick_type")
  6412. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6413. symptom := c.GetString("symptom")
  6414. sick_date := c.GetString("sick_date")
  6415. temperatures := c.GetString("temperature")
  6416. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6417. record_date := c.GetString("record_date")
  6418. breathing := c.GetString("breathing")
  6419. doctor_advice := c.GetString("doctor_advice")
  6420. remark := c.GetString("remark")
  6421. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6422. sick, _ := c.GetInt64("sick")
  6423. diagnose, _ := c.GetInt64("diagnose")
  6424. //id, _ := c.GetInt64("id")
  6425. timeLayout := "2006-01-02"
  6426. loc, _ := time.LoadLocation("Local")
  6427. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6428. allergic_history := c.GetString("allergic_history")
  6429. if err != nil {
  6430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6431. return
  6432. }
  6433. recordDateTime := theTime.Unix()
  6434. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6435. if err != nil {
  6436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6437. return
  6438. }
  6439. sickTimes := sickTime.Unix()
  6440. ctime := time.Now().Unix()
  6441. primary_disease := c.GetString("primary_disease")
  6442. confirm_failure_date := c.GetString("confirm_failure_date")
  6443. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6444. drug_allergy_history := c.GetString("drug_allergy_history")
  6445. physical_examination := c.GetString("physical_examination")
  6446. special_inspection := c.GetString("special_inspection")
  6447. lab_apparatus := c.GetString("lab_apparatus")
  6448. caseHistory := models.HisPatientCaseHistory{
  6449. HisPatientId: his_patient_id,
  6450. PatientId: patient_id,
  6451. Temperature: temperature,
  6452. BloodSugar: bloodsugarfloat,
  6453. Pulse: pulsefloat,
  6454. Sbp: sbpfloat,
  6455. Dbp: dbpfloat,
  6456. Height: heightfloat,
  6457. BloodFat: bloodfatfloat,
  6458. SickType: sick_type,
  6459. Symptom: symptom,
  6460. SickDate: sickTimes,
  6461. IsInfect: is_infect,
  6462. HistoryOfPresentIllness: history_of_present_illness,
  6463. PastHistory: past_history,
  6464. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6465. ChiefConplaint: chief_conplaint,
  6466. PersonalHistory: personal_history,
  6467. FamilyHistory: family_history,
  6468. Diagnostic: diagnostic,
  6469. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6470. Status: 1,
  6471. Ctime: ctime,
  6472. Mtime: ctime,
  6473. RecordDate: recordDateTime,
  6474. DeliveryWay: delivery_way,
  6475. Breathing: breathingfloat,
  6476. DoctorAdvice: doctor_advice,
  6477. Remark: remark,
  6478. Sick: sick,
  6479. Diagnose: diagnose,
  6480. AllergicHistory: allergic_history,
  6481. PrimaryDisease: primary_disease,
  6482. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6483. DrugAllergyHistory: drug_allergy_history,
  6484. PhysicalExamination: physical_examination,
  6485. SpecialInspection: special_inspection,
  6486. LabApparatus: lab_apparatus,
  6487. }
  6488. //查询该患者是否有病历
  6489. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6490. if errcodes == gorm.ErrRecordNotFound {
  6491. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6492. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6493. if err != nil {
  6494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6495. return
  6496. }
  6497. c.ServeSuccessJSON(map[string]interface{}{
  6498. "caseHistory": caseHistory,
  6499. "historyInfo": historyInfo,
  6500. })
  6501. return
  6502. } else if errcodes == nil {
  6503. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6504. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6505. if err != nil {
  6506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6507. return
  6508. }
  6509. c.ServeSuccessJSON(map[string]interface{}{
  6510. "caseHistory": caseHistory,
  6511. "historyInfo": historyInfo,
  6512. })
  6513. }
  6514. //查询该患者是否有病历
  6515. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6516. //if errcode == gorm.ErrRecordNotFound {
  6517. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6518. // if err != nil {
  6519. // c.ServeSuccessJSON(map[string]interface{}{
  6520. // "msg": "保存成功",
  6521. // })
  6522. // }
  6523. //} else if errcode == nil {
  6524. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6525. // return
  6526. //}
  6527. }
  6528. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6529. patient_id, _ := c.GetInt64("patient_id", 0)
  6530. adminUser := c.GetAdminUserInfo()
  6531. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6532. c.ServeSuccessJSON(map[string]interface{}{
  6533. "list": caseHistorys,
  6534. })
  6535. }
  6536. func (c *HisApiController) GetHisPatientCaseHistory() {
  6537. record_date, _ := c.GetInt64("record_date", 0)
  6538. patient_id, _ := c.GetInt64("patient_id", 0)
  6539. admin := c.GetAdminUserInfo()
  6540. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6541. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6542. c.ServeSuccessJSON(map[string]interface{}{
  6543. "info": info,
  6544. "case_history": case_history,
  6545. })
  6546. }
  6547. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6548. template_name := c.GetString("template_name")
  6549. template_remark := c.GetString("template_remark")
  6550. doctor := c.GetAdminUserInfo().AdminUser.Id
  6551. diagnostic := c.GetString("diagnostic")
  6552. chief_conplaint := c.GetString("chief_conplain")
  6553. history_of_present_illness := c.GetString("history_of_present_illness")
  6554. past_history := c.GetString("past_history")
  6555. personal_history := c.GetString("personal_history")
  6556. family_history := c.GetString("family_history")
  6557. user_name := c.GetString("user_name")
  6558. doctor_advice := c.GetString("doctor_advice")
  6559. remark := c.GetString("remark")
  6560. //record_date := c.GetString("record_date")
  6561. //fmt.Println("record_date--------",record_date)
  6562. //timeLayout := "2006-01-02"
  6563. //loc, _ := time.LoadLocation("Local")
  6564. //
  6565. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6566. //if err != nil {
  6567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6568. // return
  6569. //}
  6570. //recordDateTime := theTime.Unix()
  6571. ctime := time.Now().Unix()
  6572. template := models.HisCaseHistoryTemplate{
  6573. HistoryOfPresentIllness: history_of_present_illness,
  6574. PastHistory: past_history,
  6575. ChiefConplaint: chief_conplaint,
  6576. PersonalHistory: personal_history,
  6577. FamilyHistory: family_history,
  6578. Diagnostic: diagnostic,
  6579. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6580. Status: 1,
  6581. Ctime: ctime,
  6582. Mtime: ctime,
  6583. RecordDate: time.Now().Unix(),
  6584. TemplateName: template_name,
  6585. TemplateRemark: template_remark,
  6586. Creator: doctor,
  6587. Modifier: doctor,
  6588. UserName: user_name,
  6589. DoctorAdvice: doctor_advice,
  6590. Remark: remark,
  6591. }
  6592. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6593. if err == nil {
  6594. c.ServeSuccessJSON(map[string]interface{}{
  6595. "msg": "保存成功",
  6596. })
  6597. } else {
  6598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6599. return
  6600. }
  6601. }
  6602. func (c *HisApiController) GetCaseHistoryTemplate() {
  6603. timeLayout := "2006-01-02"
  6604. loc, _ := time.LoadLocation("Local")
  6605. keyword := c.GetString("keyword")
  6606. start_time := c.GetString("start_time")
  6607. end_time := c.GetString("end_time")
  6608. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6609. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6610. admin := c.GetAdminUserInfo()
  6611. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6612. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6613. c.ServeSuccessJSON(map[string]interface{}{
  6614. "template": template,
  6615. //"history": history,
  6616. })
  6617. }
  6618. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6619. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6620. utils.ErrorLog("drug_name")
  6621. return enums.ErrorCodeParamWrong
  6622. }
  6623. adviceName, _ := json["drug_name"].(string)
  6624. if len(adviceName) == 0 {
  6625. utils.ErrorLog("len(advice_name) == 0")
  6626. return enums.ErrorCodeParamWrong
  6627. }
  6628. advice.AdviceName = adviceName
  6629. adviceDesc, _ := json["advice_desc"].(string)
  6630. advice.AdviceDesc = adviceDesc
  6631. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6632. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6633. advice.DrugSpec = drugSpec
  6634. }
  6635. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6636. remark, _ := json["remark"].(string)
  6637. advice.Remark = remark
  6638. }
  6639. if json["id"] == nil {
  6640. advice.DrugId = 0
  6641. } else {
  6642. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6643. drug_id := int64(json["id"].(float64))
  6644. advice.DrugId = drug_id
  6645. }
  6646. }
  6647. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6648. advice_id := int64(json["advice_id"].(float64))
  6649. advice.ID = advice_id
  6650. if advice.ID > 0 {
  6651. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6652. if err == nil {
  6653. if hisAdvice.ID > 0 {
  6654. advice.ExecutionTime = hisAdvice.ExecutionTime
  6655. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6656. advice.ExecutionState = hisAdvice.ExecutionState
  6657. advice.CheckTime = hisAdvice.CheckTime
  6658. advice.Checker = hisAdvice.Checker
  6659. advice.CheckState = hisAdvice.CheckState
  6660. advice.StartTime = hisAdvice.StartTime
  6661. advice.FeedetlSn = hisAdvice.FeedetlSn
  6662. }
  6663. }
  6664. }
  6665. }
  6666. //
  6667. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6668. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6669. // advice.ExecutionTime = execution_time
  6670. //}
  6671. //
  6672. //
  6673. //
  6674. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6675. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6676. // advice.ExecutionStaff = execution_staff
  6677. //}
  6678. //
  6679. //
  6680. //
  6681. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6682. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6683. // advice.ExecutionState = execution_state
  6684. //}
  6685. //
  6686. //
  6687. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6688. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6689. // advice.CheckTime = check_time
  6690. //}
  6691. //
  6692. //
  6693. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6694. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6695. // advice.CheckState = check_state
  6696. //}
  6697. //
  6698. //
  6699. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6700. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6701. // advice.Checker = checker
  6702. //}
  6703. //
  6704. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6705. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6706. // advice.StartTime = start_time
  6707. //}
  6708. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6709. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6710. advice.IsSelfDrug = is_self_drug
  6711. }
  6712. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6713. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6714. drug_way_count, _ := json["drug_way_count"].(string)
  6715. advice.DrugWayCount = drug_way_count
  6716. }
  6717. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6718. drugSpecUnit, _ := json["min_unit"].(string)
  6719. advice.DrugSpecUnit = drugSpecUnit
  6720. }
  6721. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6722. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6723. advice.SingleDose = singleDose
  6724. }
  6725. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6726. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6727. advice.SingleDoseUnit = singleDoseUnit
  6728. }
  6729. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6730. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6731. advice.PrescribingNumber = prescribingNumber
  6732. }
  6733. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6734. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6735. advice.PrescribingNumberUnit = prescribingNumberUnit
  6736. }
  6737. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6738. deliveryWay, _ := json["delivery_way"].(string)
  6739. advice.DeliveryWay = deliveryWay
  6740. }
  6741. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6742. executionFrequency, _ := json["execution_frequency"].(string)
  6743. advice.ExecutionFrequency = executionFrequency
  6744. }
  6745. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6746. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6747. advice.Price = price
  6748. }
  6749. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6750. med_list_codg, _ := json["medical_insurance_number"].(string)
  6751. advice.MedListCodg = med_list_codg
  6752. }
  6753. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6754. day := int64(json["day"].(float64))
  6755. advice.Day = day
  6756. }
  6757. return 0
  6758. }
  6759. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6760. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6761. id := int64(json["id"].(float64))
  6762. project.ID = id
  6763. historyProject, _ := service.GetHisProjectByID(id)
  6764. project.FeedetlSn = historyProject.FeedetlSn
  6765. }
  6766. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6767. project_id := int64(json["project_id"].(float64))
  6768. project.ProjectId = project_id
  6769. }
  6770. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6771. // price := int64(json["price"].(float64))
  6772. // formatInt_price := strconv.FormatInt(price, 10)
  6773. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6774. // project.Price = float_price
  6775. // }
  6776. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6777. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6778. project.Price = price
  6779. }
  6780. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6781. total, _ := json["total"].(string)
  6782. project.Count = total
  6783. }
  6784. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6785. medical_code, _ := json["medical_code"].(string)
  6786. project.MedListCodg = medical_code
  6787. }
  6788. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6789. single_dose, _ := json["single_dose"].(string)
  6790. project.SingleDose = single_dose
  6791. }
  6792. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6793. delivery_way, _ := json["delivery_way"].(string)
  6794. project.DeliveryWay = delivery_way
  6795. }
  6796. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6797. execution_frequency, _ := json["execution_frequency"].(string)
  6798. project.ExecutionFrequency = execution_frequency
  6799. }
  6800. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6801. remark, _ := json["remark"].(string)
  6802. project.Remark = remark
  6803. }
  6804. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6805. day, _ := json["number_days"].(string)
  6806. project.Day = day
  6807. }
  6808. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6809. unit, _ := json["unit"].(string)
  6810. project.Unit = unit
  6811. }
  6812. return 0
  6813. }
  6814. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6815. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6816. id := int64(json["id"].(float64))
  6817. historyAddtions, _ := service.GetHisAdditionByID(id)
  6818. additionalCharge.ID = id
  6819. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6820. }
  6821. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6822. item_id := int64(json["item_id"].(float64))
  6823. additionalCharge.ItemId = item_id
  6824. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6825. if config.ID > 0 {
  6826. if len(config.Code) > 0 {
  6827. additionalCharge.MedListCodg = config.Code
  6828. }
  6829. }
  6830. }
  6831. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6832. // price := int64(json["price"].(float64))
  6833. // formatInt_price := strconv.FormatInt(price, 10)
  6834. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6835. // additionalCharge.Price = float_price
  6836. // }
  6837. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6838. // price := int64(json["price"].(float64))
  6839. // formatInt_price := strconv.FormatInt(price, 10)
  6840. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6841. // additionalCharge.Price = float_price
  6842. //}
  6843. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6844. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6845. additionalCharge.Price = price
  6846. }
  6847. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6848. count, _ := json["count"].(string)
  6849. counts, _ := strconv.ParseInt(count, 10, 64)
  6850. additionalCharge.Count = counts
  6851. }
  6852. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6853. item_name, _ := json["item_name"].(string)
  6854. additionalCharge.ItemName = item_name
  6855. }
  6856. return 0
  6857. }
  6858. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6859. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6860. utils.ErrorLog("drug_name")
  6861. return enums.ErrorCodeParamWrong
  6862. }
  6863. adviceName, _ := json["drug_name"].(string)
  6864. if len(adviceName) == 0 {
  6865. utils.ErrorLog("len(advice_name) == 0")
  6866. return enums.ErrorCodeParamWrong
  6867. }
  6868. advice.AdviceName = adviceName
  6869. adviceDesc, _ := json["advice_desc"].(string)
  6870. advice.AdviceDesc = adviceDesc
  6871. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6872. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6873. advice.DrugSpec = drugSpec
  6874. }
  6875. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6876. remark, _ := json["remark"].(string)
  6877. advice.Remark = remark
  6878. }
  6879. if json["id"] == nil {
  6880. advice.DrugId = 0
  6881. } else {
  6882. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6883. drug_id := int64(json["id"].(float64))
  6884. advice.DrugId = drug_id
  6885. }
  6886. }
  6887. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6888. groupno := int64(json["groupno"].(float64))
  6889. advice.Groupno = groupno
  6890. }
  6891. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6892. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6893. advice.IsSelfDrug = is_self_drug
  6894. }
  6895. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6896. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6897. drug_way_count, _ := json["drug_way_count"].(string)
  6898. advice.DrugWayCount = drug_way_count
  6899. }
  6900. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6901. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6902. advice.HospApprFlag = hosp_appr_flag
  6903. }
  6904. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6905. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6906. advice.PrescribingNumber = prescribingNumber
  6907. }
  6908. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6909. // frequency_type := int64(json["frequency_type"].(float64))
  6910. // advice.FrequencyType = frequency_type
  6911. //}
  6912. //
  6913. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6914. // day_count := int64(json["day_count"].(float64))
  6915. // advice.DayCount = day_count
  6916. //}
  6917. //
  6918. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6919. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6920. // week_day, _ := json["week_day"].(string)
  6921. // advice.WeekDay = week_day
  6922. //}
  6923. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6924. drugSpecUnit, _ := json["min_unit"].(string)
  6925. advice.DrugSpecUnit = drugSpecUnit
  6926. }
  6927. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6928. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6929. advice.SingleDose = singleDose
  6930. }
  6931. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6932. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6933. advice.SingleDoseUnit = singleDoseUnit
  6934. }
  6935. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6936. deliveryWay, _ := json["delivery_way"].(string)
  6937. advice.DeliveryWay = deliveryWay
  6938. }
  6939. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6940. executionFrequency, _ := json["execution_frequency"].(string)
  6941. advice.ExecutionFrequency = executionFrequency
  6942. }
  6943. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6944. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6945. advice.Price = price
  6946. }
  6947. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6948. med_list_codg, _ := json["medical_insurance_number"].(string)
  6949. advice.MedListCodg = med_list_codg
  6950. }
  6951. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6952. day := int64(json["day"].(float64))
  6953. advice.Day = day
  6954. }
  6955. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6956. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6957. advice.PrescribingNumberUnit = prescribingNumberUnit
  6958. }
  6959. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6960. advice_id := int64(json["advice_id"].(float64))
  6961. advice.ID = advice_id
  6962. if advice.ID > 0 {
  6963. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6964. if err == nil {
  6965. if hisAdvice.ID > 0 {
  6966. advice.ExecutionTime = hisAdvice.ExecutionTime
  6967. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6968. advice.ExecutionState = hisAdvice.ExecutionState
  6969. advice.CheckTime = hisAdvice.CheckTime
  6970. advice.Checker = hisAdvice.Checker
  6971. advice.CheckState = hisAdvice.CheckState
  6972. advice.StartTime = hisAdvice.StartTime
  6973. advice.HospApprFlag = hisAdvice.HospApprFlag
  6974. advice.IsMedicine = hisAdvice.IsMedicine
  6975. if hisAdvice.UserOrgId == 10028 {
  6976. 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 {
  6977. advice.ExecutionTime = 0
  6978. advice.ExecutionStaff = 0
  6979. advice.ExecutionState = 2
  6980. advice.CheckTime = 0
  6981. advice.Checker = 0
  6982. advice.CheckState = 2
  6983. }
  6984. } else {
  6985. 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 {
  6986. advice.ExecutionTime = 0
  6987. advice.ExecutionStaff = 0
  6988. advice.ExecutionState = 2
  6989. advice.CheckTime = 0
  6990. advice.Checker = 0
  6991. advice.CheckState = 2
  6992. advice.UpdatedTime = time.Now().Unix()
  6993. }
  6994. }
  6995. //advice.Groupno = hisAdvice.Groupno
  6996. }
  6997. }
  6998. }
  6999. }
  7000. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7001. //
  7002. //if drugStockConfig.IsOpen == 1 {
  7003. //
  7004. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7005. // if advice.ID == 0 { //医嘱不存在
  7006. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7007. // drug.Total = drug.Total - advice.PrescribingNumber
  7008. // service.UpdateBaseDrugLib(&drug)
  7009. //
  7010. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7011. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7012. // drug.Total = drug.Total - num
  7013. // service.UpdateBaseDrugLib(&drug)
  7014. // }
  7015. //
  7016. // } else if advice.ID > 0 { //医嘱存在
  7017. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7018. // var num float64
  7019. //
  7020. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7021. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7022. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7023. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7024. // drug.Total = drug.Total + num
  7025. // service.UpdateBaseDrugLib(&drug)
  7026. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7027. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7028. // drug.Total = drug.Total - num
  7029. // service.UpdateBaseDrugLib(&drug)
  7030. // }
  7031. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7032. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7033. // if num2 > advice.PrescribingNumber {
  7034. // num = num2 - advice.PrescribingNumber
  7035. // drug.Total = drug.Total + num
  7036. // service.UpdateBaseDrugLib(&drug)
  7037. // } else if num2 < advice.PrescribingNumber {
  7038. // num = advice.PrescribingNumber - num2
  7039. // drug.Total = drug.Total - num
  7040. // service.UpdateBaseDrugLib(&drug)
  7041. // }
  7042. //
  7043. // }
  7044. //
  7045. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7046. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7047. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7048. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7049. // if num1 > num2 {
  7050. // num = num1 - num2
  7051. // drug.Total = drug.Total + num
  7052. // service.UpdateBaseDrugLib(&drug)
  7053. // } else if num1 < num2 {
  7054. // num = num2 - num1
  7055. // drug.Total = drug.Total - num
  7056. // service.UpdateBaseDrugLib(&drug)
  7057. // }
  7058. //
  7059. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7060. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7061. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7062. // if hisAdvice.PrescribingNumber > num2 {
  7063. // num = hisAdvice.PrescribingNumber - num2
  7064. // drug.Total = drug.Total + num
  7065. // service.UpdateBaseDrugLib(&drug)
  7066. // } else if num2 < advice.PrescribingNumber {
  7067. // num = num2 - hisAdvice.PrescribingNumber
  7068. // drug.Total = drug.Total - num
  7069. // service.UpdateBaseDrugLib(&drug)
  7070. // }
  7071. //
  7072. // }
  7073. // }
  7074. // }
  7075. //}
  7076. //
  7077. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7078. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7079. // advice.ExecutionTime = execution_time
  7080. //}
  7081. //
  7082. //
  7083. //
  7084. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7085. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7086. // advice.ExecutionStaff = execution_staff
  7087. //}
  7088. //
  7089. //
  7090. //
  7091. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7092. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7093. // advice.ExecutionState = execution_state
  7094. //}
  7095. //
  7096. //
  7097. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7098. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7099. // advice.CheckTime = check_time
  7100. //}
  7101. //
  7102. //
  7103. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7104. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7105. // advice.CheckState = check_state
  7106. //}
  7107. //
  7108. //
  7109. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7110. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7111. // advice.Checker = checker
  7112. //}
  7113. //
  7114. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7115. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7116. // advice.StartTime = start_time
  7117. //}
  7118. return 0
  7119. }
  7120. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7121. project.ExecutionStaff = 0
  7122. project.ExecutionState = 2
  7123. project.ExecutionTime = 0
  7124. project.Checker = 0
  7125. project.CheckState = 2
  7126. project.CheckTime = 0
  7127. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7128. id := int64(json["id"].(float64))
  7129. project.ID = id
  7130. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7131. project.ExecutionStaff = temp_project.ExecutionStaff
  7132. project.ExecutionState = temp_project.ExecutionState
  7133. project.ExecutionTime = temp_project.ExecutionTime
  7134. project.Checker = temp_project.Checker
  7135. project.CheckState = temp_project.CheckState
  7136. project.CheckTime = temp_project.CheckTime
  7137. project.TeamId = temp_project.TeamId
  7138. }
  7139. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7140. types := int64(json["type"].(float64))
  7141. project.Type = types
  7142. }
  7143. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7144. project_id := int64(json["project_id"].(float64))
  7145. project.ProjectId = project_id
  7146. }
  7147. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7148. team_id := int64(json["team_id"].(float64))
  7149. project.TeamId = team_id
  7150. }
  7151. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7152. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7153. project.Price = price
  7154. }
  7155. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7156. total, _ := json["total"].(string)
  7157. //totals, _ := strconv.ParseInt(total, 10, 64)
  7158. project.Count = total
  7159. }
  7160. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7161. medical_code, _ := json["medical_code"].(string)
  7162. project.MedListCodg = medical_code
  7163. }
  7164. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7165. single_dose, _ := json["single_dose"].(string)
  7166. project.SingleDose = single_dose
  7167. }
  7168. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7169. delivery_way, _ := json["delivery_way"].(string)
  7170. project.DeliveryWay = delivery_way
  7171. }
  7172. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7173. execution_frequency, _ := json["execution_frequency"].(string)
  7174. project.ExecutionFrequency = execution_frequency
  7175. }
  7176. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7177. remark, _ := json["remark"].(string)
  7178. project.Remark = remark
  7179. }
  7180. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7181. day, _ := json["number_days"].(string)
  7182. project.Day = day
  7183. }
  7184. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7185. unit, _ := json["unit"].(string)
  7186. project.Unit = unit
  7187. }
  7188. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7189. // frequency_type := int64(json["frequency_type"].(float64))
  7190. // project.FrequencyType = frequency_type
  7191. //}
  7192. //
  7193. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7194. // day_count := int64(json["day_count"].(float64))
  7195. // project.DayCount = day_count
  7196. //}
  7197. //
  7198. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7199. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7200. // week_day, _ := json["week_day"].(string)
  7201. // project.WeekDay = week_day
  7202. //}
  7203. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7204. //
  7205. //if project.ID == 0 {
  7206. // if stockConfig.IsOpen == 1 {
  7207. // if project.Type == 3 {
  7208. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7209. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7210. // good.Total = good.Total - f_count
  7211. // service.UpdateGoodInfo(&good)
  7212. // }
  7213. // }
  7214. //
  7215. //} else {
  7216. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7217. //
  7218. // if stockConfig.IsOpen == 1 {
  7219. // if project.Type == 3 {
  7220. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7221. // if project.Count < temp_project.Count {
  7222. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7223. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7224. //
  7225. // other_count := f_count_two - f_count_one
  7226. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7227. // good.Total = good.Total + other_count_two
  7228. // service.UpdateGoodInfo(&good)
  7229. // } else if project.Count > temp_project.Count {
  7230. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7231. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7232. //
  7233. // other_count := f_count_one - f_count_two
  7234. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7235. // good.Total = good.Total - other_count_two
  7236. // service.UpdateGoodInfo(&good)
  7237. // }
  7238. //
  7239. // }
  7240. // }
  7241. //
  7242. //}
  7243. return 0
  7244. }
  7245. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7246. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7247. utils.ErrorLog("drug_name")
  7248. return enums.ErrorCodeParamWrong
  7249. }
  7250. adviceName, _ := json["drug_name"].(string)
  7251. if len(adviceName) == 0 {
  7252. utils.ErrorLog("len(advice_name) == 0")
  7253. return enums.ErrorCodeParamWrong
  7254. }
  7255. advice.AdviceName = adviceName
  7256. adviceDesc, _ := json["advice_desc"].(string)
  7257. advice.AdviceDesc = adviceDesc
  7258. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7259. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7260. advice.DrugSpec = drugSpec
  7261. }
  7262. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7263. remark, _ := json["remark"].(string)
  7264. advice.Remark = remark
  7265. }
  7266. if json["id"] == nil {
  7267. advice.DrugId = 0
  7268. } else {
  7269. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7270. drug_id := int64(json["id"].(float64))
  7271. advice.DrugId = drug_id
  7272. }
  7273. }
  7274. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7275. groupno := int64(json["groupno"].(float64))
  7276. advice.Groupno = groupno
  7277. }
  7278. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7279. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7280. advice.IsSelfDrug = is_self_drug
  7281. }
  7282. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7283. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7284. drug_way_count, _ := json["drug_way_count"].(string)
  7285. advice.DrugWayCount = drug_way_count
  7286. }
  7287. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7288. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7289. advice.HospApprFlag = hosp_appr_flag
  7290. }
  7291. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7292. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7293. advice.PrescribingNumber = prescribingNumber
  7294. }
  7295. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7296. // frequency_type := int64(json["frequency_type"].(float64))
  7297. // advice.FrequencyType = frequency_type
  7298. //}
  7299. //
  7300. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7301. // day_count := int64(json["day_count"].(float64))
  7302. // advice.DayCount = day_count
  7303. //}
  7304. //
  7305. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7306. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7307. // week_day, _ := json["week_day"].(string)
  7308. // advice.WeekDay = week_day
  7309. //}
  7310. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7311. drugSpecUnit, _ := json["min_unit"].(string)
  7312. advice.DrugSpecUnit = drugSpecUnit
  7313. }
  7314. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7315. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7316. advice.SingleDose = singleDose
  7317. }
  7318. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7319. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7320. advice.SingleDoseUnit = singleDoseUnit
  7321. }
  7322. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7323. deliveryWay, _ := json["delivery_way"].(string)
  7324. advice.DeliveryWay = deliveryWay
  7325. }
  7326. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7327. executionFrequency, _ := json["execution_frequency"].(string)
  7328. advice.ExecutionFrequency = executionFrequency
  7329. }
  7330. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7331. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7332. advice.Price = price
  7333. }
  7334. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7335. med_list_codg, _ := json["medical_insurance_number"].(string)
  7336. advice.MedListCodg = med_list_codg
  7337. }
  7338. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7339. day := int64(json["day"].(float64))
  7340. advice.Day = day
  7341. }
  7342. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7343. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7344. advice.PrescribingNumberUnit = prescribingNumberUnit
  7345. }
  7346. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7347. advice_id := int64(json["advice_id"].(float64))
  7348. advice.ID = advice_id
  7349. if advice.ID > 0 {
  7350. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7351. if err == nil {
  7352. if hisAdvice.ID > 0 {
  7353. advice.ExecutionTime = hisAdvice.ExecutionTime
  7354. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7355. advice.ExecutionState = hisAdvice.ExecutionState
  7356. advice.CheckTime = hisAdvice.CheckTime
  7357. advice.Checker = hisAdvice.Checker
  7358. advice.CheckState = hisAdvice.CheckState
  7359. advice.StartTime = hisAdvice.StartTime
  7360. advice.HospApprFlag = hisAdvice.HospApprFlag
  7361. advice.IsMedicine = hisAdvice.IsMedicine
  7362. if hisAdvice.UserOrgId == 10028 {
  7363. 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 {
  7364. advice.ExecutionTime = 0
  7365. advice.ExecutionStaff = 0
  7366. advice.ExecutionState = 2
  7367. advice.CheckTime = 0
  7368. advice.Checker = 0
  7369. advice.CheckState = 2
  7370. }
  7371. } else {
  7372. 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 {
  7373. advice.ExecutionTime = 0
  7374. advice.ExecutionStaff = 0
  7375. advice.ExecutionState = 2
  7376. advice.CheckTime = 0
  7377. advice.Checker = 0
  7378. advice.CheckState = 2
  7379. //advice.UpdatedTime = time.Now().Unix()
  7380. advice.CreatedTime = hisAdvice.CreatedTime
  7381. advice.UpdatedTime = time.Now().Unix()
  7382. } else {
  7383. advice.CreatedTime = hisAdvice.CreatedTime
  7384. advice.UpdatedTime = hisAdvice.UpdatedTime
  7385. }
  7386. }
  7387. //advice.Groupno = hisAdvice.Groupno
  7388. } else {
  7389. advice.IsMedicine = 0
  7390. ctime := time.Now().Unix()
  7391. advice.CreatedTime = ctime
  7392. advice.UpdatedTime = ctime
  7393. }
  7394. }
  7395. } else {
  7396. advice.IsMedicine = 0
  7397. ctime := time.Now().Unix()
  7398. advice.CreatedTime = ctime
  7399. advice.UpdatedTime = ctime
  7400. }
  7401. }
  7402. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7403. //
  7404. //if drugStockConfig.IsOpen == 1 {
  7405. //
  7406. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7407. // if advice.ID == 0 { //医嘱不存在
  7408. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7409. // drug.Total = drug.Total - advice.PrescribingNumber
  7410. // service.UpdateBaseDrugLib(&drug)
  7411. //
  7412. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7413. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7414. // drug.Total = drug.Total - num
  7415. // service.UpdateBaseDrugLib(&drug)
  7416. // }
  7417. //
  7418. // } else if advice.ID > 0 { //医嘱存在
  7419. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7420. // var num float64
  7421. //
  7422. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7423. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7424. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7425. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7426. // drug.Total = drug.Total + num
  7427. // service.UpdateBaseDrugLib(&drug)
  7428. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7429. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7430. // drug.Total = drug.Total - num
  7431. // service.UpdateBaseDrugLib(&drug)
  7432. // }
  7433. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7434. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7435. // if num2 > advice.PrescribingNumber {
  7436. // num = num2 - advice.PrescribingNumber
  7437. // drug.Total = drug.Total + num
  7438. // service.UpdateBaseDrugLib(&drug)
  7439. // } else if num2 < advice.PrescribingNumber {
  7440. // num = advice.PrescribingNumber - num2
  7441. // drug.Total = drug.Total - num
  7442. // service.UpdateBaseDrugLib(&drug)
  7443. // }
  7444. //
  7445. // }
  7446. //
  7447. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7448. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7449. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7450. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7451. // if num1 > num2 {
  7452. // num = num1 - num2
  7453. // drug.Total = drug.Total + num
  7454. // service.UpdateBaseDrugLib(&drug)
  7455. // } else if num1 < num2 {
  7456. // num = num2 - num1
  7457. // drug.Total = drug.Total - num
  7458. // service.UpdateBaseDrugLib(&drug)
  7459. // }
  7460. //
  7461. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7462. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7463. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7464. // if hisAdvice.PrescribingNumber > num2 {
  7465. // num = hisAdvice.PrescribingNumber - num2
  7466. // drug.Total = drug.Total + num
  7467. // service.UpdateBaseDrugLib(&drug)
  7468. // } else if num2 < advice.PrescribingNumber {
  7469. // num = num2 - hisAdvice.PrescribingNumber
  7470. // drug.Total = drug.Total - num
  7471. // service.UpdateBaseDrugLib(&drug)
  7472. // }
  7473. //
  7474. // }
  7475. // }
  7476. // }
  7477. //}
  7478. //
  7479. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7480. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7481. // advice.ExecutionTime = execution_time
  7482. //}
  7483. //
  7484. //
  7485. //
  7486. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7487. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7488. // advice.ExecutionStaff = execution_staff
  7489. //}
  7490. //
  7491. //
  7492. //
  7493. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7494. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7495. // advice.ExecutionState = execution_state
  7496. //}
  7497. //
  7498. //
  7499. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7500. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7501. // advice.CheckTime = check_time
  7502. //}
  7503. //
  7504. //
  7505. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7506. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7507. // advice.CheckState = check_state
  7508. //}
  7509. //
  7510. //
  7511. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7512. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7513. // advice.Checker = checker
  7514. //}
  7515. //
  7516. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7517. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7518. // advice.StartTime = start_time
  7519. //}
  7520. return 0
  7521. }
  7522. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7523. project.ExecutionStaff = 0
  7524. project.ExecutionState = 2
  7525. project.ExecutionTime = 0
  7526. project.Checker = 0
  7527. project.CheckState = 2
  7528. project.CheckTime = 0
  7529. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7530. id := int64(json["id"].(float64))
  7531. project.ID = id
  7532. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7533. project.ExecutionStaff = temp_project.ExecutionStaff
  7534. project.ExecutionState = temp_project.ExecutionState
  7535. project.ExecutionTime = temp_project.ExecutionTime
  7536. project.Checker = temp_project.Checker
  7537. project.CheckState = temp_project.CheckState
  7538. project.CheckTime = temp_project.CheckTime
  7539. project.TeamId = temp_project.TeamId
  7540. }
  7541. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7542. types := int64(json["type"].(float64))
  7543. project.Type = types
  7544. }
  7545. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7546. project_id := int64(json["project_id"].(float64))
  7547. project.ProjectId = project_id
  7548. }
  7549. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7550. team_id := int64(json["team_id"].(float64))
  7551. project.TeamId = team_id
  7552. }
  7553. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7554. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7555. project.Price = price
  7556. }
  7557. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7558. total, _ := json["total"].(string)
  7559. //totals, _ := strconv.ParseInt(total, 10, 64)
  7560. project.Count = total
  7561. }
  7562. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7563. medical_code, _ := json["medical_code"].(string)
  7564. project.MedListCodg = medical_code
  7565. }
  7566. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7567. single_dose, _ := json["single_dose"].(string)
  7568. project.SingleDose = single_dose
  7569. }
  7570. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7571. delivery_way, _ := json["delivery_way"].(string)
  7572. project.DeliveryWay = delivery_way
  7573. }
  7574. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7575. execution_frequency, _ := json["execution_frequency"].(string)
  7576. project.ExecutionFrequency = execution_frequency
  7577. }
  7578. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7579. remark, _ := json["remark"].(string)
  7580. project.Remark = remark
  7581. }
  7582. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7583. day, _ := json["number_days"].(string)
  7584. project.Day = day
  7585. }
  7586. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7587. unit, _ := json["unit"].(string)
  7588. project.Unit = unit
  7589. }
  7590. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7591. // frequency_type := int64(json["frequency_type"].(float64))
  7592. // project.FrequencyType = frequency_type
  7593. //}
  7594. //
  7595. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7596. // day_count := int64(json["day_count"].(float64))
  7597. // project.DayCount = day_count
  7598. //}
  7599. //
  7600. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7601. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7602. // week_day, _ := json["week_day"].(string)
  7603. // project.WeekDay = week_day
  7604. //}
  7605. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7606. //
  7607. //if project.ID == 0 {
  7608. // if stockConfig.IsOpen == 1 {
  7609. // if project.Type == 3 {
  7610. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7611. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7612. // good.Total = good.Total - f_count
  7613. // service.UpdateGoodInfo(&good)
  7614. // }
  7615. // }
  7616. //
  7617. //} else {
  7618. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7619. //
  7620. // if stockConfig.IsOpen == 1 {
  7621. // if project.Type == 3 {
  7622. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7623. // if project.Count < temp_project.Count {
  7624. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7625. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7626. //
  7627. // other_count := f_count_two - f_count_one
  7628. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7629. // good.Total = good.Total + other_count_two
  7630. // service.UpdateGoodInfo(&good)
  7631. // } else if project.Count > temp_project.Count {
  7632. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7633. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7634. //
  7635. // other_count := f_count_one - f_count_two
  7636. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7637. // good.Total = good.Total - other_count_two
  7638. // service.UpdateGoodInfo(&good)
  7639. // }
  7640. //
  7641. // }
  7642. // }
  7643. //
  7644. //}
  7645. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7646. id := int64(json["id"].(float64))
  7647. if id > 0 {
  7648. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7649. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7650. fmt.Println("666666")
  7651. project.Mtime = time.Now().Unix()
  7652. project.Ctime = temp_project.Ctime
  7653. } else {
  7654. project.Mtime = temp_project.Mtime
  7655. project.Ctime = temp_project.Ctime
  7656. }
  7657. } else {
  7658. ctime := time.Now().Unix()
  7659. project.Mtime = ctime
  7660. project.Ctime = ctime
  7661. }
  7662. }
  7663. return 0
  7664. }
  7665. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7666. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7667. id := int64(json["id"].(float64))
  7668. additionalCharge.ID = id
  7669. }
  7670. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7671. item_id := int64(json["item_id"].(float64))
  7672. additionalCharge.ItemId = item_id
  7673. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7674. if config.ID > 0 {
  7675. if len(config.Code) > 0 {
  7676. additionalCharge.MedListCodg = config.Code
  7677. }
  7678. }
  7679. }
  7680. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7681. // price := int64(json["price"].(float64))
  7682. // formatInt_price := strconv.FormatInt(price, 10)
  7683. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7684. // additionalCharge.Price = float_price
  7685. // }
  7686. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7687. // price := int64(json["price"].(float64))
  7688. // formatInt_price := strconv.FormatInt(price, 10)
  7689. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7690. // additionalCharge.Price = float_price
  7691. //}
  7692. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7693. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7694. additionalCharge.Price = price
  7695. }
  7696. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7697. count, _ := json["count"].(string)
  7698. counts, _ := strconv.ParseInt(count, 10, 64)
  7699. additionalCharge.Count = counts
  7700. }
  7701. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7702. item_name, _ := json["item_name"].(string)
  7703. additionalCharge.ItemName = item_name
  7704. }
  7705. return 0
  7706. }
  7707. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7708. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7709. utils.ErrorLog("drug_name")
  7710. return enums.ErrorCodeParamWrong
  7711. }
  7712. adviceName, _ := json["drug_name"].(string)
  7713. if len(adviceName) == 0 {
  7714. utils.ErrorLog("len(advice_name) == 0")
  7715. return enums.ErrorCodeParamWrong
  7716. }
  7717. advice.AdviceName = adviceName
  7718. adviceDesc, _ := json["advice_desc"].(string)
  7719. advice.AdviceDesc = adviceDesc
  7720. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7721. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7722. advice.DrugSpec = drugSpec
  7723. }
  7724. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7725. remark, _ := json["remark"].(string)
  7726. advice.Remark = remark
  7727. }
  7728. if json["id"] == nil {
  7729. advice.DrugId = 0
  7730. } else {
  7731. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7732. drug_id := int64(json["id"].(float64))
  7733. advice.DrugId = drug_id
  7734. }
  7735. }
  7736. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7737. groupno := int64(json["groupno"].(float64))
  7738. advice.Groupno = groupno
  7739. }
  7740. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7741. drugSpecUnit, _ := json["min_unit"].(string)
  7742. advice.DrugSpecUnit = drugSpecUnit
  7743. }
  7744. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7745. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7746. advice.SingleDose = singleDose
  7747. }
  7748. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7749. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7750. advice.SingleDoseUnit = singleDoseUnit
  7751. }
  7752. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7753. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7754. advice.PrescribingNumber = prescribingNumber
  7755. }
  7756. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7757. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7758. advice.PrescribingNumberUnit = prescribingNumberUnit
  7759. }
  7760. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7761. deliveryWay, _ := json["delivery_way"].(string)
  7762. advice.DeliveryWay = deliveryWay
  7763. }
  7764. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7765. executionFrequency, _ := json["execution_frequency"].(string)
  7766. advice.ExecutionFrequency = executionFrequency
  7767. }
  7768. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7769. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7770. advice.Price = price
  7771. }
  7772. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7773. med_list_codg, _ := json["medical_insurance_number"].(string)
  7774. advice.MedListCodg = med_list_codg
  7775. }
  7776. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7777. day := int64(json["day"].(float64))
  7778. advice.Day = day
  7779. }
  7780. advice.FrequencyType = 1
  7781. return 0
  7782. }
  7783. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7784. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7785. types := int64(json["type"].(float64))
  7786. project.Type = types
  7787. }
  7788. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7789. project_id := int64(json["project_id"].(float64))
  7790. project.ProjectId = project_id
  7791. }
  7792. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7793. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7794. project.Price = price
  7795. }
  7796. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7797. total, _ := json["total"].(string)
  7798. //totals, _ := strconv.ParseInt(total, 10, 64)
  7799. project.Count = total
  7800. }
  7801. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7802. medical_code, _ := json["medical_code"].(string)
  7803. project.MedListCodg = medical_code
  7804. }
  7805. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7806. single_dose, _ := json["single_dose"].(string)
  7807. project.SingleDose = single_dose
  7808. }
  7809. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7810. delivery_way, _ := json["delivery_way"].(string)
  7811. project.DeliveryWay = delivery_way
  7812. }
  7813. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7814. execution_frequency, _ := json["execution_frequency"].(string)
  7815. project.ExecutionFrequency = execution_frequency
  7816. }
  7817. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7818. remark, _ := json["remark"].(string)
  7819. project.Remark = remark
  7820. }
  7821. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7822. day, _ := json["number_days"].(string)
  7823. project.Day = day
  7824. }
  7825. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7826. unit, _ := json["unit"].(string)
  7827. project.Unit = unit
  7828. }
  7829. project.FrequencyType = 1
  7830. return 0
  7831. }
  7832. func (c *HisApiController) GetHisOrderListTwo() {
  7833. start_time := c.GetString("start_time")
  7834. end_time := c.GetString("end_time")
  7835. timeLayout := "2006-01-02"
  7836. loc, _ := time.LoadLocation("Local")
  7837. var startTime int64
  7838. if len(start_time) > 0 {
  7839. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7840. if err != nil {
  7841. //fmt.Println(err)
  7842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7843. return
  7844. }
  7845. startTime = theTime.Unix()
  7846. }
  7847. var endTime int64
  7848. if len(end_time) > 0 {
  7849. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7850. if err != nil {
  7851. utils.ErrorLog(err.Error())
  7852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7853. return
  7854. }
  7855. endTime = theTime.Unix()
  7856. }
  7857. adminUser := c.GetAdminUserInfo()
  7858. org_id := adminUser.CurrentOrgId
  7859. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7860. if err == nil {
  7861. c.ServeSuccessJSON(map[string]interface{}{
  7862. "order2": order,
  7863. })
  7864. } else {
  7865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7866. return
  7867. }
  7868. }
  7869. func (c *HisApiController) GetHisOrderList() {
  7870. page, _ := c.GetInt64("page", -1)
  7871. limit, _ := c.GetInt64("limit", -1)
  7872. start_time := c.GetString("start_time")
  7873. end_time := c.GetString("end_time")
  7874. types, _ := c.GetInt64("type", 0)
  7875. keywords := c.GetString("keywords")
  7876. p_type, _ := c.GetInt64("p_type", 0)
  7877. sort_type, _ := c.GetInt64("sort_type", 0)
  7878. charge_type, _ := c.GetInt64("charge_type", 0)
  7879. sch_type, _ := c.GetInt64("sch_type", 0)
  7880. zone_type, _ := c.GetInt64("zone_type", 0)
  7881. med_type, _ := c.GetInt64("med_type", 0)
  7882. timeLayout := "2006-01-02"
  7883. loc, _ := time.LoadLocation("Local")
  7884. var startTime int64
  7885. if len(start_time) > 0 {
  7886. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7887. if err != nil {
  7888. //fmt.Println(err)
  7889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7890. return
  7891. }
  7892. startTime = theTime.Unix()
  7893. }
  7894. var endTime int64
  7895. if len(end_time) > 0 {
  7896. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7897. if err != nil {
  7898. utils.ErrorLog(err.Error())
  7899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7900. return
  7901. }
  7902. endTime = theTime.Unix()
  7903. }
  7904. adminUser := c.GetAdminUserInfo()
  7905. org_id := adminUser.CurrentOrgId
  7906. 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)
  7907. for _, item := range order {
  7908. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7909. item.DoctorName = info.Doctor
  7910. item.DepartmentName = info.XtHisDepartment.Name
  7911. }
  7912. if err == nil {
  7913. c.ServeSuccessJSON(map[string]interface{}{
  7914. "order": order,
  7915. "total": total,
  7916. })
  7917. } else {
  7918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7919. return
  7920. }
  7921. }
  7922. func (c *HisApiController) GetHisOrder() {
  7923. patient_id, _ := c.GetInt64("patient_id", 0)
  7924. number := c.GetString("number")
  7925. adminInfo := c.GetAdminUserInfo()
  7926. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7927. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7928. if err == nil {
  7929. c.ServeSuccessJSON(map[string]interface{}{
  7930. "order": order,
  7931. "prescription": prescriptions,
  7932. })
  7933. } else {
  7934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7935. return
  7936. }
  7937. }
  7938. func (c *HisApiController) GetHisPrescriptionList() {
  7939. record_date := c.GetString("record_date")
  7940. keywords := c.GetString("keywords")
  7941. page, _ := c.GetInt64("page")
  7942. limit, _ := c.GetInt64("limit")
  7943. sch_type, _ := c.GetInt64("sch_type")
  7944. timeLayout := "2006-01-02"
  7945. loc, _ := time.LoadLocation("Local")
  7946. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7947. if err != nil {
  7948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7949. return
  7950. }
  7951. recordDateTime := theTime.Unix()
  7952. adminInfo := c.GetAdminUserInfo()
  7953. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7954. //adminInfo := c.GetAdminUserInfo()
  7955. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7956. //fmt.Println(prescriptionOrder)
  7957. if err == nil {
  7958. c.ServeSuccessJSON(map[string]interface{}{
  7959. "order": prescriptionOrder,
  7960. "total": total,
  7961. })
  7962. } else {
  7963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7964. return
  7965. }
  7966. }
  7967. func (c *HisApiController) GetHisPrescriptionInfo() {
  7968. id, _ := c.GetInt64("id")
  7969. adminInfo := c.GetAdminUserInfo()
  7970. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7971. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7972. if err == nil {
  7973. c.ServeSuccessJSON(map[string]interface{}{
  7974. "order": prescriptionOrder,
  7975. "prescription": prescription,
  7976. })
  7977. } else {
  7978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7979. return
  7980. }
  7981. }
  7982. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7983. adminUser := c.GetAdminUserInfo()
  7984. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7985. c.ServeSuccessJSON(map[string]interface{}{
  7986. "config": config,
  7987. })
  7988. }
  7989. type ResultTwo struct {
  7990. ErrMsg interface{} `json:"err_msg"`
  7991. InfRefmsgid string `json:"inf_refmsgid"`
  7992. Infcode int64 `json:"infcode"`
  7993. Output struct {
  7994. Baseinfo struct {
  7995. Age float64 `json:"age"`
  7996. Brdy string `json:"brdy"`
  7997. Certno string `json:"certno"`
  7998. Gend string `json:"gend"`
  7999. Naty string `json:"naty"`
  8000. PsnCertType string `json:"psn_cert_type"`
  8001. PsnName string `json:"psn_name"`
  8002. PsnNo string `json:"psn_no"`
  8003. } `json:"baseinfo"`
  8004. Idetinfo []interface{} `json:"idetinfo"`
  8005. Iinfo []struct {
  8006. Balc float64 `json:"balc"`
  8007. CvlservFlag string `json:"cvlserv_flag"`
  8008. EmpName string `json:"emp_name"`
  8009. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8010. Insutype string `json:"insutype"`
  8011. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8012. PausInsuDate interface{} `json:"paus_insu_date"`
  8013. PsnInsuDate string `json:"psn_insu_date"`
  8014. PsnInsuStas string `json:"psn_insu_stas"`
  8015. PsnType string `json:"psn_type"`
  8016. } `json:"insuinfo"`
  8017. } `json:"output"`
  8018. RefmsgTime string `json:"refmsg_time"`
  8019. RespondTime string `json:"respond_time"`
  8020. Signtype interface{} `json:"signtype"`
  8021. WarnInfo interface{} `json:"warn_info"`
  8022. }
  8023. type ResultThree struct {
  8024. Cainfo interface{} `json:"cainfo"`
  8025. ErrMsg interface{} `json:"err_msg"`
  8026. InfRefmsgid string `json:"inf_refmsgid"`
  8027. Infcode int64 `json:"infcode"`
  8028. Output struct {
  8029. Data struct {
  8030. IptOtpNo string `json:"ipt_otp_no"`
  8031. MdtrtID string `json:"mdtrt_id"`
  8032. PsnNo string `json:"psn_no"`
  8033. } `json:"data"`
  8034. } `json:"output"`
  8035. RefmsgTime string `json:"refmsg_time"`
  8036. RespondTime string `json:"respond_time"`
  8037. Signtype interface{} `json:"signtype"`
  8038. WarnMsg interface{} `json:"warn_msg"`
  8039. }
  8040. type ResultFour struct {
  8041. Cainfo string `json:"cainfo"`
  8042. ErrMsg string `json:"err_msg"`
  8043. InfRefmsgid string `json:"inf_refmsgid"`
  8044. Infcode int64 `json:"infcode"`
  8045. Output struct {
  8046. Result []struct {
  8047. BasMednFlag string `json:"bas_medn_flag"`
  8048. ChldMedcFlag string `json:"chld_medc_flag"`
  8049. ChrgitmLv string `json:"chrgitm_lv"`
  8050. Cnt float64 `json:"cnt"`
  8051. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8052. DrtReimFlag string `json:"drt_reim_flag"`
  8053. FeedetlSn string `json:"feedetl_sn"`
  8054. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8055. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8056. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8057. ListSpItemFlag string `json:"list_sp_item_flag"`
  8058. LmtUsedFlag string `json:"lmt_used_flag"`
  8059. MedChrgitmType string `json:"med_chrgitm_type"`
  8060. Memo string `json:"memo"`
  8061. OverlmtAmt float64 `json:"overlmt_amt"`
  8062. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8063. Pric float64 `json:"pric"`
  8064. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8065. SelfpayProp float64 `json:"selfpay_prop"`
  8066. } `json:"result"`
  8067. } `json:"output"`
  8068. RefmsgTime string `json:"refmsg_time"`
  8069. RespondTime string `json:"respond_time"`
  8070. Signtype string `json:"signtype"`
  8071. WarnMsg string `json:"warn_msg"`
  8072. }
  8073. type ResultFive struct {
  8074. Insutype string `json:"insutype"`
  8075. }
  8076. type ResultSix struct {
  8077. Cainfo interface{} `json:"cainfo"`
  8078. ErrMsg interface{} `json:"err_msg"`
  8079. InfRefmsgid string `json:"inf_refmsgid"`
  8080. Infcode int64 `json:"infcode"`
  8081. Output struct {
  8082. } `json:"output"`
  8083. RefmsgTime string `json:"refmsg_time"`
  8084. RespondTime string `json:"respond_time"`
  8085. Signtype interface{} `json:"signtype"`
  8086. WarnMsg interface{} `json:"warn_msg"`
  8087. }
  8088. type ResultSeven struct {
  8089. Cainfo string `json:"cainfo"`
  8090. ErrMsg string `json:"err_msg"`
  8091. InfRefmsgid string `json:"inf_refmsgid"`
  8092. Infcode int64 `json:"infcode"`
  8093. Output struct {
  8094. Setldetail []interface{} `json:"setldetail"`
  8095. Setlinfo struct {
  8096. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8097. AcctPay float64 `json:"acct_pay"`
  8098. ActPayDedc float64 `json:"act_pay_dedc"`
  8099. Age float64 `json:"age"`
  8100. Balc float64 `json:"balc"`
  8101. Brdy string `json:"brdy"`
  8102. Certno string `json:"certno"`
  8103. ClrOptins string `json:"clr_optins"`
  8104. ClrType string `json:"clr_type"`
  8105. ClrWay string `json:"clr_way"`
  8106. CvlservFlag string `json:"cvlserv_flag"`
  8107. CvlservPay float64 `json:"cvlserv_pay"`
  8108. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8109. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8110. Gend string `json:"gend"`
  8111. HifesPay float64 `json:"hifes_pay"`
  8112. HifmiPay float64 `json:"hifmi_pay"`
  8113. HifobPay float64 `json:"hifob_pay"`
  8114. HifpPay float64 `json:"hifp_pay"`
  8115. HospPartAmt float64 `json:"hosp_part_amt"`
  8116. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8117. Insutype string `json:"insutype"`
  8118. MafPay float64 `json:"maf_pay"`
  8119. MdtrtCertType string `json:"mdtrt_cert_type"`
  8120. MdtrtID string `json:"mdtrt_id"`
  8121. MedType string `json:"med_type"`
  8122. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8123. MedinsSetlID string `json:"medins_setl_id"`
  8124. Naty string `json:"naty"`
  8125. OthPay float64 `json:"oth_pay"`
  8126. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8127. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8128. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8129. PsnCashPay float64 `json:"psn_cash_pay"`
  8130. PsnCertType string `json:"psn_cert_type"`
  8131. PsnName string `json:"psn_name"`
  8132. PsnNo string `json:"psn_no"`
  8133. PsnPartAmt float64 `json:"psn_part_amt"`
  8134. PsnType string `json:"psn_type"`
  8135. SetlID string `json:"setl_id"`
  8136. SetlTime string `json:"setl_time"`
  8137. } `json:"setlinfo"`
  8138. } `json:"output"`
  8139. RefmsgTime string `json:"refmsg_time"`
  8140. RespondTime string `json:"respond_time"`
  8141. Signtype interface{} `json:"signtype"`
  8142. WarnMsg interface{} `json:"warn_msg"`
  8143. }
  8144. type ResultEight struct {
  8145. Cainfo string `json:"cainfo"`
  8146. ErrMsg string `json:"err_msg"`
  8147. InfRefmsgid string `json:"inf_refmsgid"`
  8148. Infcode int64 `json:"infcode"`
  8149. Output struct {
  8150. Stmtinfo struct {
  8151. SetlOptins string `json:"setl_optins"`
  8152. StmtRslt string `json:"stmt_rslt"`
  8153. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8154. } `json:"stmtinfo"`
  8155. } `json:"output"`
  8156. RefmsgTime string `json:"refmsg_time"`
  8157. RespondTime string `json:"respond_time"`
  8158. Signtype interface{} `json:"signtype"`
  8159. WarnMsg interface{} `json:"warn_msg"`
  8160. }
  8161. type ResultNine struct {
  8162. Cainfo string `json:"cainfo"`
  8163. ErrMsg string `json:"err_msg"`
  8164. InfRefmsgid string `json:"inf_refmsgid"`
  8165. Infcode int64 `json:"infcode"`
  8166. Output struct {
  8167. FileQuryNo string `json:"file_qury_no"`
  8168. } `json:"output"`
  8169. RefmsgTime string `json:"refmsg_time"`
  8170. RespondTime string `json:"respond_time"`
  8171. Signtype interface{} `json:"signtype"`
  8172. WarnMsg interface{} `json:"warn_msg"`
  8173. }
  8174. type ResultTen struct {
  8175. Cainfo string `json:"cainfo"`
  8176. ErrMsg string `json:"err_msg"`
  8177. InfRefmsgid string `json:"inf_refmsgid"`
  8178. Infcode int64 `json:"infcode"`
  8179. Output struct {
  8180. DldEndtime string `json:"dld_endtime"`
  8181. FileQuryNo string `json:"file_qury_no"`
  8182. Filename string `json:"filename"`
  8183. } `json:"output"`
  8184. RefmsgTime string `json:"refmsg_time"`
  8185. RespondTime string `json:"respond_time"`
  8186. Signtype interface{} `json:"signtype"`
  8187. WarnMsg interface{} `json:"warn_msg"`
  8188. }
  8189. type ResultEleven struct {
  8190. Cainfo string `json:"cainfo"`
  8191. ErrMsg string `json:"err_msg"`
  8192. InfRefmsgid string `json:"inf_refmsgid"`
  8193. Infcode int64 `json:"infcode"`
  8194. Output struct {
  8195. Setlinfo struct {
  8196. FixmedinsName string `json:"fixmedins_name"`
  8197. FixmedinsCode string `json:"fixmedins_code"`
  8198. PsnNo string `json:"psn_no"`
  8199. PsnName string `json:"psn_name"`
  8200. HifobPay float64 `json:"hifob_pay"`
  8201. Gend string `json:"gend"`
  8202. Brdy string `json:"brdy"`
  8203. PsnCertType string `json:"psn_cert_type"`
  8204. PsnType string `json:"psn_type"`
  8205. EmpName string `json:"emp_name"`
  8206. Certno string `json:"certno"`
  8207. Insutype string `json:"insutype"`
  8208. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8209. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8210. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8211. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8212. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8213. ActPayDedc float64 `json:"act_pay_dedc"`
  8214. HifpPay float64 `json:"hifp_pay"`
  8215. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8216. CvlservPay float64 `json:"cvlserv_pay"`
  8217. HifesPay float64 `json:"hifes_pay"`
  8218. HifmiPay float64 `json:"hifmi_pay"`
  8219. MafPay float64 `json:"maf_pay"`
  8220. OthPay float64 `json:"oth_pay"`
  8221. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8222. PsnPay float64 `json:"psn_pay"`
  8223. AcctPay float64 `json:"acct_pay"`
  8224. CashPayamt float64 `json:"cash_payamt"`
  8225. Balc float64 `json:"balc"`
  8226. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8227. MedinsSetlId string `json:"medins_setl_id"`
  8228. RefdSetlFlag string `json:"refd_setl_flag"`
  8229. SetlTime string `json:"setl_time"`
  8230. MedType string `json:"med_type"`
  8231. } `json:"setlinfo"`
  8232. } `json:"output"`
  8233. RefmsgTime string `json:"refmsg_time"`
  8234. RespondTime string `json:"respond_time"`
  8235. Signtype interface{} `json:"signtype"`
  8236. WarnMsg interface{} `json:"warn_msg"`
  8237. }
  8238. type Custom struct {
  8239. DetItemFeeSumamt string
  8240. Cut string
  8241. FeedetlSn string
  8242. Price string
  8243. MedListCodg string
  8244. Type int64
  8245. AdviceId int64
  8246. ProjectId int64
  8247. ItemId int64
  8248. }
  8249. // 获取个人信息----挂号-----上传就诊信息
  8250. func (c *HisApiController) GetRegisterInfo() {
  8251. id, _ := c.GetInt64("id")
  8252. record_time := c.GetString("record_time")
  8253. settlementValue, _ := c.GetInt64("settlement_value")
  8254. medical_insurance_card := c.GetString("medical_insurance_card")
  8255. name := c.GetString("name")
  8256. id_card_type, _ := c.GetInt64("id_card_type")
  8257. certificates, _ := c.GetInt64("certificates")
  8258. medical_care, _ := c.GetInt64("medical_care")
  8259. birthday := c.GetString("birthday")
  8260. age, _ := c.GetInt64("age")
  8261. id_card := c.GetString("id_card")
  8262. register_type, _ := c.GetInt64("register")
  8263. doctor, _ := c.GetInt64("doctor")
  8264. department, _ := c.GetInt64("department")
  8265. gender, _ := c.GetInt64("sex")
  8266. phone := c.GetString("phone")
  8267. registration_fee, _ := c.GetFloat("registration_fee")
  8268. medical_expenses, _ := c.GetFloat("medical_expenses")
  8269. social_type, _ := c.GetInt64("social_type")
  8270. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8271. diagnosis_ids := c.GetString("diagnosis")
  8272. sick_type, _ := c.GetInt64("sick_type")
  8273. reg_type := c.GetString("p_type")
  8274. timeLayout := "2006-01-02"
  8275. loc, _ := time.LoadLocation("Local")
  8276. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8277. birthUnix := birthdays.Unix()
  8278. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8279. if err != nil {
  8280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8281. return
  8282. }
  8283. recordDateTime := theTime.Unix()
  8284. adminInfo := c.GetAdminUserInfo()
  8285. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8286. if tempPatient.ID == 0 {
  8287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8288. return
  8289. }
  8290. var patient service.Patients
  8291. if id == 0 {
  8292. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8293. } else {
  8294. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8295. }
  8296. if patient.ID == 0 {
  8297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8298. return
  8299. }
  8300. if len(patient.IdCardNo) == 0 {
  8301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8302. return
  8303. }
  8304. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8305. if len(his) >= 1 {
  8306. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8307. if len(his) >= 1 && order.ID == 0 {
  8308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8309. return
  8310. }
  8311. }
  8312. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8313. fmt.Println(timeStr)
  8314. timeArr := strings.Split(timeStr, " ")
  8315. fmt.Println(timeArr)
  8316. timeArrTwo := strings.Split(timeArr[0], "-")
  8317. timeArrThree := strings.Split(timeArr[1], ":")
  8318. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8319. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8320. if len(lists) == 0 {
  8321. var hisPatient models.XtHisPatient
  8322. hisPatient = models.XtHisPatient{
  8323. Name: name,
  8324. Age: age,
  8325. Gender: gender,
  8326. Birthday: birthUnix,
  8327. Phone: phone,
  8328. MedicalTreatmentType: medical_care,
  8329. IdType: certificates,
  8330. IdCardNo: id_card,
  8331. BalanceAccountsType: settlementValue,
  8332. SocialType: social_type,
  8333. MedicalInsuranceNumber: medical_insurance_card,
  8334. RegisterType: register_type,
  8335. RegisterCost: registration_fee,
  8336. TreatmentCost: medical_expenses,
  8337. AdminUserId: adminInfo.AdminUser.Id,
  8338. UserOrgId: adminInfo.CurrentOrgId,
  8339. Status: 1,
  8340. RecordDate: recordDateTime,
  8341. IsReturn: 1,
  8342. PatientId: patient.ID,
  8343. Ctime: time.Now().Unix(),
  8344. Mtime: time.Now().Unix(),
  8345. Number: str,
  8346. IdCardType: id_card_type,
  8347. Departments: department,
  8348. Doctor: doctor,
  8349. PType: reg_type,
  8350. Diagnosis: diagnosis_ids,
  8351. SickType: sick_type,
  8352. }
  8353. service.CreateHisPatient(&hisPatient)
  8354. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8355. c.ServeSuccessJSON(map[string]interface{}{
  8356. "his_info": hisPatient,
  8357. })
  8358. } else {
  8359. //chrgBchno := rand.Intn(1000000) + 10000
  8360. var hisPatient models.XtHisPatient
  8361. hisPatient = models.XtHisPatient{
  8362. Name: name,
  8363. Age: age,
  8364. Gender: gender,
  8365. Birthday: birthUnix,
  8366. Phone: phone,
  8367. MedicalTreatmentType: medical_care,
  8368. IdType: certificates,
  8369. IdCardNo: id_card,
  8370. BalanceAccountsType: settlementValue,
  8371. SocialType: social_type,
  8372. MedicalInsuranceNumber: medical_insurance_card,
  8373. RegisterType: register_type,
  8374. RegisterCost: registration_fee,
  8375. TreatmentCost: medical_expenses,
  8376. AdminUserId: adminInfo.AdminUser.Id,
  8377. UserOrgId: adminInfo.CurrentOrgId,
  8378. Status: 1,
  8379. RecordDate: recordDateTime,
  8380. IsReturn: 1,
  8381. PatientId: patient.ID,
  8382. Ctime: time.Now().Unix(),
  8383. Mtime: time.Now().Unix(),
  8384. Number: str,
  8385. IdCardType: id_card_type,
  8386. Departments: department,
  8387. Doctor: doctor,
  8388. PType: reg_type,
  8389. Diagnosis: diagnosis_ids,
  8390. SickType: sick_type,
  8391. }
  8392. service.CreateHisPatient(&hisPatient)
  8393. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8394. c.ServeSuccessJSON(map[string]interface{}{
  8395. "his_info": hisPatient,
  8396. })
  8397. }
  8398. }
  8399. // 上传明细----结算
  8400. func (c *HisApiController) GetUploadInfo() {
  8401. id, _ := c.GetInt64("id")
  8402. record_time := c.GetString("record_time")
  8403. his_patient_id, _ := c.GetInt64("his_patient_id")
  8404. oth_desc := c.GetString("oth_desc")
  8405. pay_way, _ := c.GetInt64("pay_way")
  8406. pay_ways := c.GetString("pay_ways")
  8407. pay_price, _ := c.GetFloat("pay_price")
  8408. pay_card_no := c.GetString("pay_card_no")
  8409. discount_price, _ := c.GetFloat("discount_price")
  8410. preferential_price, _ := c.GetFloat("preferential_price")
  8411. reality_price, _ := c.GetFloat("reality_price")
  8412. found_price, _ := c.GetFloat("found_price")
  8413. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8414. private_price, _ := c.GetFloat("private_price")
  8415. timeLayout := "2006-01-02"
  8416. loc, _ := time.LoadLocation("Local")
  8417. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8418. fapiao_code := c.GetString("fapiao_code")
  8419. fapiao_number := c.GetString("fapiao_number")
  8420. diagnosis_id := c.GetString("diagnosis")
  8421. sick_type, _ := c.GetInt64("sick_type")
  8422. reg_type, _ := c.GetInt64("p_type")
  8423. order_id, _ := c.GetInt64("order_id")
  8424. cash_pay := c.GetString("cash_pay")
  8425. wechat_pay := c.GetString("wechat_pay")
  8426. ali_pay := c.GetString("ali_pay")
  8427. jifen_pay := c.GetString("jifen_pay")
  8428. band_card_pay := c.GetString("band_card_pay")
  8429. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8430. tmp_decimal := c.GetString("tmp_decimal")
  8431. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8432. var decimal float64 //本次使用的押金
  8433. var errmsg error
  8434. tx := service.XTWriteDB().Begin() //开了事务
  8435. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8436. defer func() {
  8437. if errmsg != nil {
  8438. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8439. tx.Rollback()
  8440. } else {
  8441. tx.Commit()
  8442. }
  8443. }()
  8444. fmt.Println("dec_way", dec_way)
  8445. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8446. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8447. return
  8448. }
  8449. if len(tmp_decimal) > 0 {
  8450. if tmp_decimal[0] == 45 {
  8451. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8452. return
  8453. }
  8454. }
  8455. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8456. fmt.Println(errs)
  8457. decimal = tt
  8458. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8459. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8461. if err != nil {
  8462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8463. return
  8464. }
  8465. recordDateTime := theTime.Unix()
  8466. adminUser := c.GetAdminUserInfo()
  8467. var prescriptions []*models.HisPrescription
  8468. var prescriptionsOne []*models.HisPrescription
  8469. var start_time int64
  8470. var end_time int64
  8471. ids_str := c.GetString("ids")
  8472. ids_arr := strings.Split(ids_str, ",")
  8473. if tempOrder.ID == 0 {
  8474. if settle_accounts_type == 1 { //日结
  8475. fmt.Println(reg_type)
  8476. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8477. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8478. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8479. } else {
  8480. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8481. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8482. }
  8483. } else { //月结
  8484. start_time_str := c.GetString("start_time")
  8485. end_time_str := c.GetString("end_time")
  8486. timeLayout := "2006-01-02"
  8487. loc, _ := time.LoadLocation("Local")
  8488. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8489. if err != nil {
  8490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8491. return
  8492. }
  8493. recordStartTime := theStartTime.Unix()
  8494. start_time = recordStartTime
  8495. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8496. if err != nil {
  8497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8498. return
  8499. }
  8500. recordEndTime := theEndTime.Unix()
  8501. end_time = recordEndTime
  8502. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8503. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8504. }
  8505. var goods []*models.DialysisBeforePrepareGoods
  8506. var newGoods []*models.NewDialysisBeforePrepareGoods
  8507. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8508. var infos []*models.HisDoctorAdviceInfo
  8509. var infoList []*models.HisDoctorAdviceInfo
  8510. var hisAdvice []*models.HisDoctorAdviceInfo
  8511. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8512. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8513. //判断库存不足
  8514. //结算出库开关
  8515. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8516. if settConfig.IsOpen == 1 {
  8517. //判断库存的地方
  8518. for _, info := range prescriptions {
  8519. if info.Type == 1 {
  8520. infos = append(infos, info.HisDoctorAdviceInfo...)
  8521. }
  8522. if info.Type == 2 {
  8523. for _, sumItem := range info.HisPrescriptionProject {
  8524. if sumItem.Type == 3 {
  8525. var good models.DialysisBeforePrepareGoods
  8526. var newGood models.NewDialysisBeforePrepareGoods
  8527. good.GoodId = sumItem.GoodInfo.ID
  8528. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8529. count, _ := strconv.Atoi(sumItem.Count)
  8530. good.Count = int64(count)
  8531. good.StorehouseId = houseConfig.StorehouseOutInfo
  8532. good.ProjectId = sumItem.ID
  8533. goods = append(goods, &good)
  8534. newGood.GoodId = sumItem.GoodInfo.ID
  8535. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8536. count2, _ := strconv.Atoi(sumItem.Count)
  8537. newGood.Count = int64(count2)
  8538. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8539. newGood.ProjectId = sumItem.ID
  8540. newGoods = append(newGoods, &newGood)
  8541. }
  8542. }
  8543. }
  8544. }
  8545. for _, info := range prescriptionsOne {
  8546. if info.Type == 1 {
  8547. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8548. }
  8549. if info.Type == 2 {
  8550. for _, sumItem := range info.HisPrescriptionProject {
  8551. if sumItem.Type == 3 {
  8552. var newGood models.NewDialysisBeforePrepareGoods
  8553. newGood.GoodId = sumItem.GoodInfo.ID
  8554. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8555. count2, _ := strconv.Atoi(sumItem.Count)
  8556. newGood.Count = int64(count2)
  8557. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8558. newGood.ProjectId = sumItem.ID
  8559. newGoodOne = append(newGoodOne, &newGood)
  8560. }
  8561. }
  8562. }
  8563. }
  8564. //判断
  8565. for _, itemOne := range infos {
  8566. for _, itemTwo := range hisAdvice {
  8567. if itemOne.DrugId == itemTwo.DrugId {
  8568. itemTwo.Child = append(itemTwo.Child, itemOne)
  8569. }
  8570. }
  8571. }
  8572. for _, itemTwo := range hisAdvice {
  8573. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8574. var sum_out_count int64
  8575. for _, itemThree := range itemTwo.Child {
  8576. var prescribing_number int64
  8577. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8578. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8579. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8580. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8581. }
  8582. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8583. prescribing_number = parseIntPrescribingNumber
  8584. }
  8585. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8586. prescribing_number = parseIntPrescribingNumber
  8587. }
  8588. sum_out_count += prescribing_number
  8589. }
  8590. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8591. if sum_out_count > drugStockOut.FlushCount {
  8592. c.ServeSuccessJSON(map[string]interface{}{
  8593. "msg": "2",
  8594. "drug": medical,
  8595. })
  8596. return
  8597. }
  8598. }
  8599. for _, itemOne := range newGoods {
  8600. for _, item := range newGoodOne {
  8601. if itemOne.GoodId == item.GoodId {
  8602. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8603. }
  8604. }
  8605. }
  8606. for _, item := range newGoodOne {
  8607. var sum_out_count_one int64
  8608. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8609. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8610. sum_out_count_one += itemOne.Count
  8611. }
  8612. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8613. fmt.Println("sum_out_count_one", sum_out_count_one)
  8614. fmt.Println("list.FlushCount", list.FlushCount)
  8615. if sum_out_count_one > list.FlushCount {
  8616. c.ServeSuccessJSON(map[string]interface{}{
  8617. "msg": "3",
  8618. "good": good,
  8619. })
  8620. return
  8621. }
  8622. }
  8623. }
  8624. timestamp := time.Now().Unix()
  8625. tempTime := time.Unix(timestamp, 0)
  8626. timeFormat := tempTime.Format("20060102150405")
  8627. chrgBchno := rand.Intn(100000) + 10000
  8628. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8629. strconv.FormatInt(his.PatientId, 10)
  8630. var ids []int64
  8631. for _, item := range prescriptions {
  8632. ids = append(ids, item.ID)
  8633. }
  8634. var total float64
  8635. for _, item := range prescriptions {
  8636. fmt.Println(item)
  8637. if item.Type == 1 { //药品
  8638. for _, subItem := range item.HisDoctorAdviceInfo {
  8639. total = total + (subItem.Price * subItem.PrescribingNumber)
  8640. }
  8641. }
  8642. if item.Type == 2 { //项目
  8643. for _, subItem := range item.HisPrescriptionProject {
  8644. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8645. total = total + (subItem.Price * cnt)
  8646. }
  8647. }
  8648. for _, subItem := range item.HisAdditionalCharge {
  8649. total = total + (subItem.Price * float64(subItem.Count))
  8650. }
  8651. }
  8652. if reg_type == 1111 || reg_type == 1112 {
  8653. reg_type = 11
  8654. }
  8655. tm := time.Unix(time.Now().Unix(), 0)
  8656. allTotal := fmt.Sprintf("%.4f", total)
  8657. totals, _ := strconv.ParseFloat(allTotal, 64)
  8658. order := &models.HisOrder{
  8659. UserOrgId: adminUser.CurrentOrgId,
  8660. HisPatientId: his.ID,
  8661. PatientId: id,
  8662. SettleAccountsDate: recordDateTime,
  8663. Ctime: time.Now().Unix(),
  8664. Mtime: time.Now().Unix(),
  8665. Status: 1,
  8666. OrderStatus: 2,
  8667. MdtrtId: his.Number,
  8668. Number: chrg_bchno,
  8669. MedfeeSumamt: totals,
  8670. PayWay: pay_way,
  8671. PayWays: pay_ways,
  8672. PayPrice: pay_price,
  8673. MedType: strconv.Itoa(int(reg_type)),
  8674. PayCardNo: pay_card_no,
  8675. DiscountPrice: discount_price,
  8676. PreferentialPrice: preferential_price,
  8677. RealityPrice: reality_price,
  8678. FoundPrice: found_price,
  8679. MedicalInsurancePrice: medical_insurance_price,
  8680. PrivatePrice: private_price,
  8681. SettleEndTime: end_time,
  8682. SettleStartTime: start_time,
  8683. PsnPartAmt: totals,
  8684. PsnCashPay: totals,
  8685. SettleType: settle_accounts_type,
  8686. FaPiaoCode: fapiao_code,
  8687. FaPiaoNumber: fapiao_number,
  8688. Diagnosis: diagnosis_id,
  8689. PType: 2,
  8690. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8691. Decimal: decimal,
  8692. OthDesc: oth_desc,
  8693. CashPay: cash_pay,
  8694. WechatPay: wechat_pay,
  8695. AliPay: ali_pay,
  8696. JifenPay: jifen_pay,
  8697. BandCardPay: band_card_pay,
  8698. Creator: adminUser.AdminUser.Id,
  8699. }
  8700. err = service.CreateOrderTX(order, tx)
  8701. if err != nil {
  8702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8703. return
  8704. }
  8705. var customs []*Custom
  8706. for _, item := range prescriptions {
  8707. if item.Type == 1 { //药品a
  8708. for _, subItem := range item.HisDoctorAdviceInfo {
  8709. cus := &Custom{
  8710. AdviceId: subItem.ID,
  8711. ProjectId: 0,
  8712. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8713. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8714. FeedetlSn: subItem.FeedetlSn,
  8715. Price: fmt.Sprintf("%.4f", subItem.Price),
  8716. MedListCodg: subItem.MedListCodg,
  8717. Type: 1,
  8718. }
  8719. customs = append(customs, cus)
  8720. }
  8721. }
  8722. if item.Type == 2 { //项目
  8723. for _, subItem := range item.HisPrescriptionProject {
  8724. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8725. cus := &Custom{
  8726. AdviceId: 0,
  8727. ProjectId: subItem.ID,
  8728. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8729. Cut: fmt.Sprintf("%.4f", cnt),
  8730. FeedetlSn: subItem.FeedetlSn,
  8731. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8732. MedListCodg: subItem.MedListCodg,
  8733. Type: 2,
  8734. }
  8735. customs = append(customs, cus)
  8736. }
  8737. }
  8738. for _, item := range item.HisAdditionalCharge {
  8739. cus := &Custom{
  8740. ItemId: item.ID,
  8741. AdviceId: 0,
  8742. ProjectId: 0,
  8743. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8744. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8745. FeedetlSn: item.FeedetlSn,
  8746. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8747. MedListCodg: item.XtHisAddtionConfig.Code,
  8748. Type: 3,
  8749. }
  8750. customs = append(customs, cus)
  8751. }
  8752. }
  8753. for _, item := range customs {
  8754. var advice_id int64 = 0
  8755. var project_id int64 = 0
  8756. var item_id int64 = 0
  8757. var types int64 = 0
  8758. if item.Type == 1 {
  8759. advice_id = item.AdviceId
  8760. project_id = 0
  8761. item_id = 0
  8762. } else if item.Type == 2 {
  8763. advice_id = 0
  8764. item_id = 0
  8765. project_id = item.ProjectId
  8766. } else if item.Type == 3 {
  8767. advice_id = 0
  8768. item_id = item.ItemId
  8769. project_id = 0
  8770. }
  8771. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8772. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8773. pric, _ := strconv.ParseFloat(item.Price, 32)
  8774. info := &models.HisOrderInfo{
  8775. OrderNumber: order.Number,
  8776. UploadDate: time.Now().Unix(),
  8777. AdviceId: advice_id,
  8778. DetItemFeeSumamt: detItemFeeSumamt,
  8779. Cnt: cut,
  8780. Pric: pric,
  8781. PatientId: id,
  8782. Status: 1,
  8783. Mtime: time.Now().Unix(),
  8784. Ctime: time.Now().Unix(),
  8785. UserOrgId: adminUser.CurrentOrgId,
  8786. HisPatientId: his.ID,
  8787. OrderId: order.ID,
  8788. ProjectId: project_id,
  8789. Type: types,
  8790. ItemId: item_id,
  8791. }
  8792. service.CreateOrderInfoTX(info, tx)
  8793. }
  8794. his.Diagnosis = diagnosis_id
  8795. his.SickType = sick_type
  8796. his.RegisterType = reg_type
  8797. his.MedicalTreatmentType = reg_type
  8798. service.UpdataHisPateintTX(&his, tx)
  8799. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8800. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8801. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8802. //判断是否使用了押金
  8803. if dec_way == "true" {
  8804. tmpstring := strconv.FormatInt(order.ID, 10)
  8805. //扣押金
  8806. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8807. order.Decimal = decimal
  8808. service.UpDateOrderTwo(order, tx)
  8809. if errmsg != nil {
  8810. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8811. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8812. return
  8813. }
  8814. }
  8815. if err == nil {
  8816. for _, info := range prescriptions {
  8817. if info.Type == 1 {
  8818. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8819. }
  8820. if info.Type == 2 {
  8821. for _, sumItem := range info.HisPrescriptionProject {
  8822. if sumItem.Type == 3 {
  8823. var good models.DialysisBeforePrepareGoods
  8824. var newGood models.NewDialysisBeforePrepareGoods
  8825. var oldGood models.OldDialysisBeforePrepareGoods
  8826. good.GoodId = sumItem.GoodInfo.ID
  8827. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8828. count, _ := strconv.Atoi(sumItem.Count)
  8829. good.Count = int64(count)
  8830. good.StorehouseId = houseConfig.StorehouseOutInfo
  8831. good.ProjectId = sumItem.ID
  8832. good.PatientId = sumItem.PatientId
  8833. goods = append(goods, &good)
  8834. newGood.GoodId = sumItem.GoodInfo.ID
  8835. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8836. count2, _ := strconv.Atoi(sumItem.Count)
  8837. newGood.Count = int64(count2)
  8838. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8839. newGood.ProjectId = sumItem.ID
  8840. newGood.PatientId = sumItem.HisPatientId
  8841. newGoods = append(newGoods, &newGood)
  8842. oldGood.GoodId = sumItem.GoodInfo.ID
  8843. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8844. count3, _ := strconv.Atoi(sumItem.Count)
  8845. oldGood.Count = int64(count3)
  8846. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8847. oldGood.ProjectId = sumItem.ID
  8848. oldGood.RecordDate = sumItem.RecordDate
  8849. oldGood.PatientId = sumItem.HisPatientId
  8850. oldGoods = append(oldGoods, &oldGood)
  8851. }
  8852. }
  8853. }
  8854. }
  8855. if settConfig.IsOpen == 1 {
  8856. for _, item := range infoList {
  8857. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8858. if medical.IsUse == 2 {
  8859. //药品出库
  8860. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8861. //查询默认仓库
  8862. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8863. //查询默认仓库剩余多少库存
  8864. var sum_count int64
  8865. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8866. for _, its := range stockInfo {
  8867. if its.MaxUnit == medical.MaxUnit {
  8868. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8869. }
  8870. sum_count += its.StockMaxNumber + its.StockMinNumber
  8871. }
  8872. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8873. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8874. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8875. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8876. }
  8877. }
  8878. orgId := c.GetAdminUserInfo().CurrentOrgId
  8879. if len(oldGoods) > 0 {
  8880. timeStr := time.Now().Format("2006-01-02")
  8881. timeArr := strings.Split(timeStr, "-")
  8882. total, _ := service.FindAllWarehouseOut(orgId)
  8883. total = total + 1
  8884. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8885. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8886. number = number + total
  8887. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8888. operation_time := time.Now().Unix()
  8889. creater := c.GetAdminUserInfo().AdminUser.Id
  8890. //查询默认出库仓库库存
  8891. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8892. recordDateStr := time.Now().Format("2006-01-02")
  8893. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8894. nowtime := recordDate.Unix()
  8895. warehouseOut := models.WarehouseOut{
  8896. WarehouseOutOrderNumber: warehousing_out_order,
  8897. OperationTime: operation_time,
  8898. OrgId: orgId,
  8899. Creater: creater,
  8900. Ctime: time.Now().Unix(),
  8901. Status: 1,
  8902. WarehouseOutTime: nowtime,
  8903. Type: 1,
  8904. StorehouseId: storeConfig.StorehouseOutInfo,
  8905. IsCheck: 1,
  8906. OrderId: order.ID,
  8907. IsSys: 5,
  8908. }
  8909. //查询是否生成出库单
  8910. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8911. if out.ID == 0 {
  8912. service.AddSigleWarehouseOut(&warehouseOut)
  8913. }
  8914. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8915. for _, item := range oldGoods {
  8916. dialyPrepareOne := models.DialysisBeforePrepare{
  8917. GoodTypeId: item.GoodTypeId,
  8918. GoodId: item.GoodId,
  8919. PatientId: his.PatientId,
  8920. RecordDate: item.RecordDate,
  8921. UserOrgId: adminUser.CurrentOrgId,
  8922. Count: item.Count,
  8923. Ctime: time.Now().Unix(),
  8924. Creater: adminUser.AdminUser.Id,
  8925. CommdityCode: item.CommdityCode,
  8926. Status: 1,
  8927. StorehouseId: houseConfig.StorehouseOutInfo,
  8928. }
  8929. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8930. //非零用
  8931. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8932. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8933. //查询剩余库存
  8934. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8935. var sum_count int64
  8936. for _, item := range goodList {
  8937. sum_count += item.StockCount
  8938. }
  8939. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8940. //耗材
  8941. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8942. }
  8943. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8944. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8945. //查询剩余库存
  8946. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8947. var sum_count int64
  8948. for _, item := range goodList {
  8949. sum_count += item.StockCount
  8950. }
  8951. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8952. //耗材
  8953. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8954. }
  8955. }
  8956. }
  8957. }
  8958. c.ServeSuccessJSON(map[string]interface{}{
  8959. "msg": "结算成功",
  8960. })
  8961. }
  8962. }
  8963. }
  8964. // 退款
  8965. func (c *HisApiController) Refund() {
  8966. order_id, _ := c.GetInt64("order_id")
  8967. order, _ := service.GetHisOrderByID(order_id)
  8968. adminUser := c.GetAdminUserInfo()
  8969. orgid := c.GetAdminUserInfo().CurrentOrgId
  8970. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8971. if err != nil {
  8972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8973. return
  8974. }
  8975. tmp := strconv.FormatInt(order.ID, 10)
  8976. //当押金不为零时产生退费记录
  8977. if order.Decimal != 0 {
  8978. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8979. if err != nil {
  8980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8981. return
  8982. }
  8983. }
  8984. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8985. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8986. var goods []*models.DialysisBeforePrepareGoods
  8987. var newGoods []*models.NewDialysisBeforePrepareGoods
  8988. var infos []*models.HisDoctorAdviceInfo
  8989. for _, info := range orders {
  8990. if info.AdviceId > 0 && info.ProjectId == 0 {
  8991. infos = append(infos, &info.HisDoctorAdviceInfo)
  8992. }
  8993. if info.ProjectId > 0 && info.AdviceId == 0 {
  8994. if info.HisPrescriptionProject.Type == 3 {
  8995. var good models.DialysisBeforePrepareGoods
  8996. var newGood models.NewDialysisBeforePrepareGoods
  8997. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8998. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8999. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9000. good.Count = int64(count)
  9001. good.StorehouseId = houseConfig.StorehouseOutInfo
  9002. good.ProjectId = info.HisPrescriptionProject.ID
  9003. good.PatientId = info.PatientId
  9004. good.OrderId = order_id
  9005. goods = append(goods, &good)
  9006. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9007. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9008. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9009. newGood.Count = int64(count2)
  9010. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9011. newGood.ProjectId = info.HisPrescriptionProject.ID
  9012. newGood.RecordDate = order.SettleAccountsDate
  9013. newGood.UserOrgId = order.UserOrgId
  9014. newGood.PatientId = info.PatientId
  9015. newGood.OrderId = order_id
  9016. newGoods = append(newGoods, &newGood)
  9017. }
  9018. }
  9019. }
  9020. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9021. if settConfig.IsOpen == 1 {
  9022. for _, item := range infos {
  9023. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9024. }
  9025. for _, item := range newGoods {
  9026. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9027. }
  9028. }
  9029. c.ServeSuccessJSON(map[string]interface{}{
  9030. "msg": "退费成功",
  9031. })
  9032. }
  9033. func (c *HisApiController) RefundNumber() {
  9034. his_patient_id, _ := c.GetInt64("id")
  9035. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9036. info.Status = 0
  9037. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9038. if count > 0 {
  9039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9040. return
  9041. }
  9042. err := service.SaveHisPatient(info)
  9043. if err == nil {
  9044. c.ServeSuccessJSON(map[string]interface{}{
  9045. "msg": "退号成功",
  9046. })
  9047. } else {
  9048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9049. return
  9050. }
  9051. }
  9052. func (this *HisApiController) AdditionalCharge() {
  9053. dataBody := make(map[string]interface{}, 0)
  9054. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9055. fmt.Println(err)
  9056. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9057. patient_id := int64(dataBody["patient_id"].(float64))
  9058. medicineData, _ := dataBody["medicineData"].([]interface{})
  9059. adminUserInfo := this.GetAdminUserInfo()
  9060. orgId := adminUserInfo.CurrentOrgId
  9061. admin_user_id := adminUserInfo.AdminUser.Id
  9062. timeStr := time.Now().Format("2006-01-02")
  9063. timeLayout := "2006-01-02 15:04:05"
  9064. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9065. timenow := timeStringToTime.Unix()
  9066. var additionalCharges []*models.HisAdditionalCharge
  9067. for _, item := range medicineData {
  9068. var randNum int
  9069. randNum = rand.Intn(10000) + 1000
  9070. timestamp := time.Now().Unix()
  9071. tempTime := time.Unix(timestamp, 0)
  9072. timeFormat := tempTime.Format("20060102150405")
  9073. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9074. items := item.(map[string]interface{})
  9075. money := items["price"].(string)
  9076. item_id_str := items["item_id"].(string)
  9077. name := items["name"].(string)
  9078. id_str := items["id"].(string)
  9079. moneys, _ := strconv.ParseInt(money, 10, 64)
  9080. monStr := strconv.FormatInt(moneys, 10)
  9081. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9082. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9083. id, _ := strconv.ParseInt(id_str, 10, 64)
  9084. additionalCharge := &models.HisAdditionalCharge{
  9085. ID: id,
  9086. HisPatientId: his_patient_id,
  9087. UserOrgId: orgId,
  9088. PatientId: patient_id,
  9089. RecordDate: timenow,
  9090. Price: monneyStr,
  9091. Status: 1,
  9092. ItemName: name,
  9093. ItemId: item_id,
  9094. AdminUserId: admin_user_id,
  9095. CreatedTime: time.Now().Unix(),
  9096. OrderStatus: 0,
  9097. PrescriptionNumber: "",
  9098. BatchNumber: "",
  9099. FeedetlSn: p_number,
  9100. }
  9101. service.CreateAdditionalCharge(additionalCharge)
  9102. additionalCharges = append(additionalCharges, additionalCharge)
  9103. }
  9104. this.ServeSuccessJSON(map[string]interface{}{
  9105. "msg": "添加成功",
  9106. "additional_charges": additionalCharges,
  9107. })
  9108. }
  9109. func (this *HisApiController) DeleteAddition() {
  9110. id, _ := this.GetInt64("id")
  9111. //TODO 需要判断是否已经结算
  9112. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9113. if err == nil {
  9114. this.ServeSuccessJSON(map[string]interface{}{
  9115. "msg": "删除成功",
  9116. })
  9117. return
  9118. } else {
  9119. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9120. return
  9121. }
  9122. }
  9123. func (this *HisApiController) GetAdminUsers() {
  9124. adminUser := this.GetAdminUserInfo()
  9125. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9126. this.ServeSuccessJSON(map[string]interface{}{
  9127. "doctors": doctors,
  9128. })
  9129. }
  9130. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9131. change_type, _ := this.GetInt64("type", 0)
  9132. record_date := this.GetString("record_time")
  9133. patient_id, _ := this.GetInt64("patient_id", 0)
  9134. p_type, _ := this.GetInt64("p_type", 0)
  9135. timeLayout := "2006-01-02"
  9136. loc, _ := time.LoadLocation("Local")
  9137. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9138. record_time := theAdviceRecordTime.Unix()
  9139. adminUserInfo := this.GetAdminUserInfo()
  9140. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9141. if err == nil {
  9142. if len(prescriptions) == 0 {
  9143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9144. return
  9145. } else {
  9146. this.ServeSuccessJSON(map[string]interface{}{
  9147. "prescriptions": prescriptions,
  9148. })
  9149. return
  9150. }
  9151. } else {
  9152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9153. return
  9154. }
  9155. }
  9156. func (this *HisApiController) GetCallHisPrescription() {
  9157. patient_id, _ := this.GetInt64("patient_id", 0)
  9158. timeLayout := "2006-01-02"
  9159. loc, _ := time.LoadLocation("Local")
  9160. start_time := this.GetString("start_time")
  9161. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9162. end_time := this.GetString("end_time")
  9163. p_type, _ := this.GetInt64("p_type")
  9164. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9165. adminUserInfo := this.GetAdminUserInfo()
  9166. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9167. //if
  9168. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9169. //
  9170. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9171. if adminUserInfo.CurrentOrgId == 10265 {
  9172. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9173. if config.ID > 0 && config.IsOpen == 1 {
  9174. for _, subitems := range prescriptions {
  9175. for _, item := range subitems.VMHisPrescription {
  9176. for _, subItem := range item.HisDoctorAdviceInfo {
  9177. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9178. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9179. if info.RetailPrice > 0 {
  9180. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9181. subItem.Drug.RetailPrice = drug.RetailPrice
  9182. }
  9183. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9184. subItem.Drug.MinPrice = info.RetailPrice
  9185. subItem.Drug.RetailPrice = info.RetailPrice
  9186. }
  9187. }
  9188. }
  9189. }
  9190. }
  9191. }
  9192. if config.ID > 0 && config.IsOpen == 1 {
  9193. for _, subitems := range prescriptions {
  9194. for _, item := range subitems.VMHisPrescription {
  9195. for _, subItem := range item.HisPrescriptionProject {
  9196. if subItem.Type == 3 {
  9197. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9198. if info.Price > 0 {
  9199. subItem.GoodInfo.PackingPrice = info.Price
  9200. }
  9201. }
  9202. }
  9203. }
  9204. }
  9205. }
  9206. }
  9207. if err == nil {
  9208. this.ServeSuccessJSON(map[string]interface{}{
  9209. "prescriptions": prescriptions,
  9210. })
  9211. return
  9212. } else {
  9213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9214. return
  9215. }
  9216. }
  9217. func (this *HisApiController) GetHisDayPrescription() {
  9218. timeLayout := "2006-01-02"
  9219. loc, _ := time.LoadLocation("Local")
  9220. start_time := this.GetString("start_time")
  9221. patient_id, _ := this.GetInt64("patient_id", 0)
  9222. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9223. end_time := this.GetString("end_time")
  9224. p_type, _ := this.GetInt64("p_type")
  9225. order_status, _ := this.GetInt64("type")
  9226. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9227. adminUserInfo := this.GetAdminUserInfo()
  9228. var dayHisPrescription []*models.HisPrescription
  9229. var err error
  9230. if order_status == 1 || order_status == 0 {
  9231. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9232. } else if order_status == 2 {
  9233. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9234. }
  9235. var settle_total float64
  9236. for _, item := range dayHisPrescription {
  9237. if len(item.HisPrescriptionProject) > 0 {
  9238. for _, subItem := range item.HisPrescriptionProject {
  9239. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9240. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9241. settle_total = settle_total + total
  9242. }
  9243. }
  9244. if len(item.HisDoctorAdviceInfo) > 0 {
  9245. for _, subItem := range item.HisDoctorAdviceInfo {
  9246. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9247. settle_total = settle_total + total
  9248. }
  9249. }
  9250. }
  9251. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9252. if err == nil {
  9253. this.ServeSuccessJSON(map[string]interface{}{
  9254. "day_prescription": dayHisPrescription,
  9255. "settle_total": settle_total,
  9256. })
  9257. return
  9258. } else {
  9259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9260. return
  9261. }
  9262. }
  9263. func (c *HisApiController) GetHisChargePatientList() {
  9264. record_date := c.GetString("record_date")
  9265. order_status, _ := c.GetInt64("type")
  9266. sch_type, _ := c.GetInt64("sch_type")
  9267. timeLayout := "2006-01-02"
  9268. loc, _ := time.LoadLocation("Local")
  9269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9270. if err != nil {
  9271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9272. return
  9273. }
  9274. recordDateTime := theTime.Unix()
  9275. adminInfo := c.GetAdminUserInfo()
  9276. var tempPatients []*service.NewTempPatients
  9277. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9278. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9279. if order_status != 2 {
  9280. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9281. } else {
  9282. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9283. }
  9284. } else {
  9285. if order_status != 2 {
  9286. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9287. } else {
  9288. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9289. }
  9290. }
  9291. var patients []*service.NewTempPatients
  9292. var patients_two []*service.NewTempPatients
  9293. for _, item := range tempPatients {
  9294. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9295. //过滤掉没挂号的和没开处方的
  9296. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9297. patients = append(patients, item)
  9298. }
  9299. //过滤掉没挂号的
  9300. if len(item.HisPatient) > 0 {
  9301. patients_two = append(patients_two, item)
  9302. }
  9303. } else {
  9304. if len(item.HisPrescription) > 0 {
  9305. patients = append(patients, item)
  9306. }
  9307. }
  9308. }
  9309. c.ServeSuccessJSON(map[string]interface{}{
  9310. "list": patients,
  9311. "list_two": patients_two,
  9312. })
  9313. }
  9314. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9315. record_date := c.GetString("record_date")
  9316. timeLayout := "2006-01-02"
  9317. loc, _ := time.LoadLocation("Local")
  9318. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9319. if err != nil {
  9320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9321. return
  9322. }
  9323. recordDateTime := theTime.Unix()
  9324. adminUser := c.GetAdminUserInfo()
  9325. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9326. var patients []*service.Patients
  9327. for _, item := range tempPatients {
  9328. if item.HisPatient.ID == 0 {
  9329. patients = append(patients, item)
  9330. }
  9331. }
  9332. c.ServeSuccessJSON(map[string]interface{}{
  9333. "list": patients,
  9334. //"list_two": patients_two,
  9335. })
  9336. }
  9337. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9338. newArr = make([]*service.Patients, 0)
  9339. for i := 0; i < len(patient); i++ {
  9340. repeat := false
  9341. for j := i + 1; j < len(patient); j++ {
  9342. if patient[i].ID == patient[j].ID {
  9343. repeat = true
  9344. break
  9345. }
  9346. }
  9347. if !repeat {
  9348. newArr = append(newArr, patient[i])
  9349. }
  9350. }
  9351. return
  9352. }
  9353. func (c *HisApiController) GetHisChargePatientInfo() {
  9354. patient_id, _ := c.GetInt64("patient_id")
  9355. his_patient_id, _ := c.GetInt64("his_patient_id")
  9356. record_date := c.GetString("record_date")
  9357. //start_time := c.GetString("start_time")
  9358. //end_time := c.GetString("end_time")
  9359. order_status, _ := c.GetInt64("type", 0)
  9360. p_type, _ := c.GetInt64("p_type", 0)
  9361. order_id, _ := c.GetInt64("order_id", 0)
  9362. timeLayout := "2006-01-02"
  9363. loc, _ := time.LoadLocation("Local")
  9364. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9365. if err != nil {
  9366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9367. return
  9368. }
  9369. recordDateTime := theTime.Unix()
  9370. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9371. //if err != nil {
  9372. //
  9373. //}
  9374. //startRecordDateTime := startTime.Unix()
  9375. //
  9376. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9377. //if err != nil {
  9378. //
  9379. //}
  9380. //endRecordDateTime := endTime.Unix()
  9381. admin := c.GetAdminUserInfo()
  9382. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9383. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9384. var prescriptions []*models.HisPrescription
  9385. //var unChargeMonthPrescriptions []*models.HisPrescription
  9386. order, _ := service.GetHisOrderByID(order_id)
  9387. if order_status == 1 || order_status == 0 {
  9388. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9389. } else if order_status == 2 {
  9390. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9391. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9392. }
  9393. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9394. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9395. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9396. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9397. //获取所有科室信息
  9398. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9399. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9400. c.ServeSuccessJSON(map[string]interface{}{
  9401. "his_info": his_patient_info,
  9402. "xt_info": xt_patient_info,
  9403. "prescription": prescriptions,
  9404. "case_history": case_history,
  9405. "info": patientPrescriptionInfo,
  9406. "last_info": lastPatientPrescriptionInfo,
  9407. "order": order,
  9408. "doctors": doctors,
  9409. "department": department,
  9410. "sch": sch,
  9411. })
  9412. return
  9413. }
  9414. func (c *HisApiController) GetAllOrderDetail() {
  9415. order_id, _ := c.GetInt64("id", 0)
  9416. order, _ := service.GetHisOrderByID(order_id)
  9417. if order.ID == 0 {
  9418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9419. return
  9420. }
  9421. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9422. org_id := c.GetAdminUserInfo().CurrentOrgId
  9423. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9424. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9425. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9426. c.ServeSuccessJSON(map[string]interface{}{
  9427. "order": order,
  9428. "order_info": order_info,
  9429. "patient": patient,
  9430. "admin_info": adminInfo,
  9431. "hospital_record": record,
  9432. })
  9433. return
  9434. }
  9435. func (c *HisApiController) GetAllOrderDetailCollect() {
  9436. order_id, _ := c.GetInt64("id", 0)
  9437. order, _ := service.GetHisOrderByID(order_id)
  9438. if order.ID == 0 {
  9439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9440. return
  9441. }
  9442. org_id := c.GetAdminUserInfo().CurrentOrgId
  9443. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9444. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9445. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9446. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9447. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9448. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9449. var bedCostTotal float64 = 0 //床位总费
  9450. //var bedCostSelfTotal float64 = 0 //床位自费
  9451. var operationCostTotal float64 = 0 //手术费
  9452. //var operationCostSelfTotal float64 = 0 //手术费
  9453. var otherCostTotal float64 = 0 //其他费用
  9454. //var otherCostSelfTotal float64 = 0 //其他费用
  9455. var materialCostTotal float64 = 0 //材料费
  9456. //var materialCostSelfTotal float64 = 0 //材料费
  9457. var westernMedicineCostTotal float64 = 0 //西药费
  9458. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9459. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9460. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9461. var checkCostTotal float64 = 0 //检查费
  9462. //var checkCostSelfTotal float64 = 0 //检查费
  9463. var laboratoryCostTotal float64 = 0 //化验费
  9464. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9465. var treatCostTotal float64 = 0 //治疗费用
  9466. //var treatCostSelfTotal float64 = 0 //治疗费用
  9467. var zhenChaCostTotal float64 = 0 //其他费用
  9468. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9469. decimal.DivisionPrecision = 2
  9470. var BalanceAccountsType int64
  9471. if his.ID > 0 {
  9472. BalanceAccountsType = his.BalanceAccountsType
  9473. } else {
  9474. BalanceAccountsType = record.BalanceAccountsType
  9475. }
  9476. if BalanceAccountsType != 2 {
  9477. for _, item := range order_info {
  9478. if org_id == 10215 {
  9479. if item.MedChrgitmType == "01" { //床位费
  9480. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9481. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9482. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9483. }
  9484. if item.MedChrgitmType == "02" { //诊察费
  9485. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9486. //zhenChaCostSelfTotal = zhenChaCostTotal
  9487. }
  9488. if item.MedChrgitmType == "03" { //检查费
  9489. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9490. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9491. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9492. }
  9493. //if item.MedChrgitmType == "02" { //检查费
  9494. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9495. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9496. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9497. //}
  9498. if item.MedChrgitmType == "04" { //化验费
  9499. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9500. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9501. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9502. }
  9503. if item.MedChrgitmType == "05" { //治疗费
  9504. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9505. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9506. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9507. }
  9508. if item.MedChrgitmType == "06" { //手术费
  9509. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9510. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9511. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9512. }
  9513. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9514. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9515. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9516. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9517. }
  9518. if item.MedChrgitmType == "09" { //西药费
  9519. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9520. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9521. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9522. }
  9523. if item.MedChrgitmType == "11" { //中成费
  9524. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9525. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9526. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9527. }
  9528. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9529. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9530. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9531. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9532. }
  9533. } else if org_id == 10188 || org_id == 10217 {
  9534. if item.MedChrgitmType == "01" { //床位费
  9535. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9536. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9537. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9538. }
  9539. if item.MedChrgitmType == "02" { //诊察费
  9540. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9541. //zhenChaCostSelfTotal = zhenChaCostTotal
  9542. }
  9543. if item.MedChrgitmType == "03" { //检查费
  9544. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9545. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9546. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9547. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9548. }
  9549. //if item.MedChrgitmType == "02" { //检查费
  9550. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9551. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9552. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9553. //}
  9554. if item.MedChrgitmType == "04" { //化验费
  9555. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9556. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9557. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9558. }
  9559. if item.MedChrgitmType == "05" { //治疗费
  9560. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9561. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9562. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9563. }
  9564. if item.MedChrgitmType == "06" { //手术费
  9565. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9566. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9567. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9568. }
  9569. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9570. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9571. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9572. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9573. }
  9574. if item.MedChrgitmType == "09" { //西药费
  9575. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9576. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9577. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9578. }
  9579. if item.MedChrgitmType == "11" { //中成费
  9580. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9581. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9582. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9583. }
  9584. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9585. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9586. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9587. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9588. }
  9589. } else {
  9590. if item.MedChrgitmType == "01" { //床位费
  9591. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9592. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9593. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9594. }
  9595. //if item.MedChrgitmType == "02" { //诊察费
  9596. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9597. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9598. //}
  9599. if item.MedChrgitmType == "03" { //检查费
  9600. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9601. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9602. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9603. }
  9604. //if item.MedChrgitmType == "02" { //检查费
  9605. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9606. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9607. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9608. //}
  9609. if item.MedChrgitmType == "04" { //化验费
  9610. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9611. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9612. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9613. }
  9614. if item.MedChrgitmType == "05" { //治疗费
  9615. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9616. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9617. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9618. }
  9619. if item.MedChrgitmType == "06" { //手术费
  9620. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9621. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9622. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9623. }
  9624. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9625. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9626. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9627. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9628. }
  9629. if item.MedChrgitmType == "09" { //西药费
  9630. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9631. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9632. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9633. }
  9634. if item.MedChrgitmType == "11" { //中成费
  9635. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9636. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9637. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9638. }
  9639. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9640. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9641. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9642. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9643. }
  9644. }
  9645. }
  9646. c.ServeSuccessJSON(map[string]interface{}{
  9647. "order": order,
  9648. "order_info": order_info,
  9649. "patient": patient,
  9650. "admin_info": adminInfo,
  9651. "his_hospital": record,
  9652. "bedCostTotal": bedCostTotal,
  9653. "operationCostTotal": operationCostTotal,
  9654. "otherCostTotal": otherCostTotal,
  9655. "materialCostTotal": materialCostTotal,
  9656. "westernMedicineCostTotal": westernMedicineCostTotal,
  9657. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9658. "checkCostTotal": checkCostTotal,
  9659. "zhenChaCostTotal": zhenChaCostTotal,
  9660. "laboratoryCostTotal": laboratoryCostTotal,
  9661. "treatCostTotal": treatCostTotal,
  9662. })
  9663. } else {
  9664. for _, item := range order_info {
  9665. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9666. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9667. item.MedChrgitmType = "09"
  9668. }
  9669. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9670. if item.HisPrescriptionProject.Type == 2 {
  9671. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9672. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9673. case 0:
  9674. item.MedChrgitmType = "0"
  9675. break
  9676. case 1:
  9677. item.MedChrgitmType = "14"
  9678. break
  9679. case 2:
  9680. item.MedChrgitmType = "05"
  9681. break
  9682. case 3:
  9683. item.MedChrgitmType = "03"
  9684. break
  9685. case 4:
  9686. item.MedChrgitmType = "03"
  9687. break
  9688. case 5:
  9689. item.MedChrgitmType = "08"
  9690. break
  9691. case 6:
  9692. item.MedChrgitmType = "14"
  9693. break
  9694. case 7:
  9695. item.MedChrgitmType = "14"
  9696. break
  9697. case 8:
  9698. item.MedChrgitmType = "03"
  9699. break
  9700. case 9:
  9701. item.MedChrgitmType = "14"
  9702. break
  9703. case 10:
  9704. item.MedChrgitmType = "14"
  9705. break
  9706. case 11:
  9707. item.MedChrgitmType = "06"
  9708. break
  9709. case 12:
  9710. item.MedChrgitmType = "12"
  9711. break
  9712. case 13:
  9713. item.MedChrgitmType = "01"
  9714. break
  9715. case 14:
  9716. item.MedChrgitmType = "04"
  9717. break
  9718. case 15:
  9719. item.MedChrgitmType = "14"
  9720. break
  9721. }
  9722. } else {
  9723. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9724. case 1:
  9725. item.MedChrgitmType = "14"
  9726. break
  9727. case 2:
  9728. item.MedChrgitmType = "05"
  9729. break
  9730. case 3:
  9731. item.MedChrgitmType = "04"
  9732. break
  9733. case 4:
  9734. item.MedChrgitmType = "14"
  9735. break
  9736. case 5:
  9737. item.MedChrgitmType = "08"
  9738. break
  9739. case 6:
  9740. item.MedChrgitmType = "14"
  9741. break
  9742. case 7:
  9743. item.MedChrgitmType = "14"
  9744. break
  9745. case 8:
  9746. item.MedChrgitmType = "03"
  9747. break
  9748. case 9:
  9749. item.MedChrgitmType = "14"
  9750. break
  9751. }
  9752. }
  9753. } else if item.HisPrescriptionProject.Type == 3 {
  9754. item.MedChrgitmType = "08"
  9755. }
  9756. }
  9757. }
  9758. for _, item := range order_info {
  9759. if org_id == 10215 {
  9760. if item.MedChrgitmType == "01" { //床位费
  9761. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9762. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9763. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9764. }
  9765. if item.MedChrgitmType == "02" { //诊察费
  9766. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9767. //zhenChaCostSelfTotal = zhenChaCostTotal
  9768. }
  9769. if item.MedChrgitmType == "03" { //检查费
  9770. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9771. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9772. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9773. }
  9774. //if item.MedChrgitmType == "02" { //检查费
  9775. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9776. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9777. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9778. //}
  9779. if item.MedChrgitmType == "04" { //化验费
  9780. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9782. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9783. }
  9784. if item.MedChrgitmType == "05" { //治疗费
  9785. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9786. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9787. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9788. }
  9789. if item.MedChrgitmType == "06" { //手术费
  9790. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9791. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9792. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9793. }
  9794. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9795. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9796. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9797. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9798. }
  9799. if item.MedChrgitmType == "09" { //西药费
  9800. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9801. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9802. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9803. }
  9804. if item.MedChrgitmType == "11" { //中成费
  9805. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9806. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9807. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9808. }
  9809. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9810. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9811. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9812. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9813. }
  9814. } else {
  9815. if item.MedChrgitmType == "01" { //床位费
  9816. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9817. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9818. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9819. }
  9820. //if item.MedChrgitmType == "02" { //诊察费
  9821. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9822. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9823. //}
  9824. if item.MedChrgitmType == "03" { //检查费
  9825. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9826. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9827. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9828. }
  9829. //if item.MedChrgitmType == "02" { //检查费
  9830. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9831. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9832. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9833. //}
  9834. if item.MedChrgitmType == "04" { //化验费
  9835. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9836. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9837. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9838. }
  9839. if item.MedChrgitmType == "05" { //治疗费
  9840. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9841. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9842. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9843. }
  9844. if item.MedChrgitmType == "06" { //手术费
  9845. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9846. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9847. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9848. }
  9849. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9850. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9851. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9852. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9853. }
  9854. if item.MedChrgitmType == "09" { //西药费
  9855. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9856. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9857. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9858. }
  9859. if item.MedChrgitmType == "11" { //中成费
  9860. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9861. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9862. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9863. }
  9864. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9865. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9866. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9867. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9868. }
  9869. }
  9870. }
  9871. c.ServeSuccessJSON(map[string]interface{}{
  9872. "order": order,
  9873. "order_info": order_info,
  9874. "patient": patient,
  9875. "admin_info": adminInfo,
  9876. "his_hospital": record,
  9877. "bedCostTotal": bedCostTotal,
  9878. "operationCostTotal": operationCostTotal,
  9879. "otherCostTotal": otherCostTotal,
  9880. "materialCostTotal": materialCostTotal,
  9881. "westernMedicineCostTotal": westernMedicineCostTotal,
  9882. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9883. "checkCostTotal": checkCostTotal,
  9884. "zhenChaCostTotal": zhenChaCostTotal,
  9885. "laboratoryCostTotal": laboratoryCostTotal,
  9886. "treatCostTotal": treatCostTotal,
  9887. })
  9888. }
  9889. }
  9890. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9891. page, _ := c.GetInt64("page")
  9892. limit, _ := c.GetInt64("limit")
  9893. keywords := c.GetString("keywords")
  9894. start_time := c.GetString("start_time")
  9895. end_time := c.GetString("end_time")
  9896. //clr_type := c.GetString("clr_type")
  9897. insutype := c.GetString("insutype")
  9898. timeLayout := "2006-01-02"
  9899. loc, _ := time.LoadLocation("Local")
  9900. var theStartTIme int64
  9901. if len(start_time) > 0 {
  9902. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9903. theStartTIme = theTime.Unix()
  9904. }
  9905. var theEndtTIme int64
  9906. if len(end_time) > 0 {
  9907. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9908. theEndtTIme = theTime.Unix()
  9909. }
  9910. if page <= 0 {
  9911. page = 1
  9912. }
  9913. if limit <= 0 {
  9914. limit = 10
  9915. }
  9916. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9917. c.ServeSuccessJSON(map[string]interface{}{
  9918. "total": total,
  9919. "list": list,
  9920. })
  9921. return
  9922. }
  9923. func (c *HisApiController) GetPutOnRecordList() {
  9924. page, _ := c.GetInt64("page")
  9925. limit, _ := c.GetInt64("limit")
  9926. keywords := c.GetString("keywords")
  9927. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9928. if page <= 0 {
  9929. page = 1
  9930. }
  9931. if limit <= 0 {
  9932. limit = 10
  9933. }
  9934. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9935. c.ServeSuccessJSON(map[string]interface{}{
  9936. "total": total,
  9937. "list": list,
  9938. })
  9939. return
  9940. }
  9941. func (c *HisApiController) GetCompareData() {
  9942. start_time := c.GetString("start_time")
  9943. end_time := c.GetString("end_time")
  9944. insutype := c.GetString("insutype")
  9945. clr_type := c.GetString("clr_type")
  9946. timeLayout := "2006-01-02"
  9947. loc, _ := time.LoadLocation("Local")
  9948. var theStartTIme int64
  9949. if len(start_time) > 0 {
  9950. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9951. if err != nil {
  9952. theStartTIme = 0
  9953. }
  9954. theStartTIme = theTime.Unix()
  9955. }
  9956. var theEndtTIme int64
  9957. if len(end_time) > 0 {
  9958. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9959. if err != nil {
  9960. theEndtTIme = 0
  9961. }
  9962. theEndtTIme = theTime.Unix()
  9963. }
  9964. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9965. fmt.Println(err)
  9966. if err == nil {
  9967. c.ServeSuccessJSON(map[string]interface{}{
  9968. "list": formData,
  9969. })
  9970. } else {
  9971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9972. return
  9973. }
  9974. }
  9975. func (c *HisApiController) GetFaPiaoData() {
  9976. order_id, _ := c.GetInt64("order_id")
  9977. patient_id, _ := c.GetInt64("patient_id")
  9978. //number := c.GetString("number")
  9979. adminUser := c.GetAdminUserInfo()
  9980. order, _ := service.GetHisOrderByID(order_id)
  9981. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9982. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9983. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9984. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9985. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9986. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9987. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9988. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9989. var bedCostTotal float64 = 0 //床位总费
  9990. var bedCostSelfTotal float64 = 0 //床位自费
  9991. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9992. var operationCostTotal float64 = 0 //手术费
  9993. var operationCostSelfTotal float64 = 0 //手术费
  9994. var operationCostPartSelfTotal float64 = 0 //手术费
  9995. var otherCostTotal float64 = 0 //其他费用
  9996. var otherCostSelfTotal float64 = 0 //其他费用
  9997. var otherCostPartSelfTotal float64 = 0 //其他费用
  9998. var materialCostTotal float64 = 0 //材料费
  9999. var materialCostSelfTotal float64 = 0 //材料费
  10000. var materialCostPartSelfTotal float64 = 0 //材料费
  10001. var westernMedicineCostTotal float64 = 0 //西药费
  10002. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10003. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10004. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10005. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10006. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10007. var checkCostTotal float64 = 0 //检查费
  10008. var checkCostSelfTotal float64 = 0 //检查费
  10009. var checkCostPartSelfTotal float64 = 0 //检查费
  10010. var hiliCostTotal float64 = 0 //护理费
  10011. var hiliCostSelfTotal float64 = 0 //护理费
  10012. var hiliCostPartSelfTotal float64 = 0 //护理费
  10013. var laboratoryCostTotal float64 = 0 //化验费
  10014. var laboratoryCostSelfTotal float64 = 0 //化验费
  10015. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10016. var treatCostTotal float64 = 0 //治疗费用
  10017. var treatCostSelfTotal float64 = 0 //治疗费用
  10018. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10019. var zhenChaCostTotal float64 = 0 //其他费用
  10020. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10021. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10022. decimal.DivisionPrecision = 2
  10023. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10024. var balanceAccountsType int64
  10025. if his.ID > 0 {
  10026. balanceAccountsType = his.BalanceAccountsType
  10027. } else {
  10028. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10029. }
  10030. if balanceAccountsType == 2 {
  10031. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10032. for _, item := range orderInfos_two {
  10033. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10034. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10035. item.MedChrgitmType = "09"
  10036. }
  10037. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10038. if item.HisPrescriptionProject.Type == 2 {
  10039. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10040. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10041. case 0:
  10042. item.MedChrgitmType = "0"
  10043. break
  10044. case 1:
  10045. item.MedChrgitmType = "14"
  10046. break
  10047. case 2:
  10048. item.MedChrgitmType = "05"
  10049. break
  10050. case 3:
  10051. item.MedChrgitmType = "03"
  10052. break
  10053. case 4:
  10054. item.MedChrgitmType = "03"
  10055. break
  10056. case 5:
  10057. item.MedChrgitmType = "08"
  10058. break
  10059. case 6:
  10060. item.MedChrgitmType = "14"
  10061. break
  10062. case 7:
  10063. item.MedChrgitmType = "14"
  10064. break
  10065. case 8:
  10066. item.MedChrgitmType = "03"
  10067. break
  10068. case 9:
  10069. item.MedChrgitmType = "14"
  10070. break
  10071. case 10:
  10072. item.MedChrgitmType = "14"
  10073. break
  10074. case 11:
  10075. item.MedChrgitmType = "06"
  10076. break
  10077. case 12:
  10078. item.MedChrgitmType = "12"
  10079. break
  10080. case 13:
  10081. item.MedChrgitmType = "01"
  10082. break
  10083. case 14:
  10084. item.MedChrgitmType = "04"
  10085. break
  10086. case 15:
  10087. item.MedChrgitmType = "02"
  10088. break
  10089. }
  10090. } else {
  10091. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10092. case 1:
  10093. item.MedChrgitmType = "14"
  10094. break
  10095. case 2:
  10096. item.MedChrgitmType = "05"
  10097. break
  10098. case 3:
  10099. item.MedChrgitmType = "04"
  10100. break
  10101. case 4:
  10102. item.MedChrgitmType = "03"
  10103. break
  10104. case 5:
  10105. item.MedChrgitmType = "08"
  10106. break
  10107. case 6:
  10108. item.MedChrgitmType = "14"
  10109. break
  10110. case 7:
  10111. item.MedChrgitmType = "14"
  10112. break
  10113. case 8:
  10114. item.MedChrgitmType = "03"
  10115. break
  10116. case 9:
  10117. item.MedChrgitmType = "14"
  10118. break
  10119. }
  10120. }
  10121. } else if item.HisPrescriptionProject.Type == 3 {
  10122. item.MedChrgitmType = "08"
  10123. }
  10124. }
  10125. }
  10126. for _, item := range orderInfos_two {
  10127. fmt.Println(item.MedChrgitmType)
  10128. if item.MedChrgitmType == "07" { //床位费
  10129. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10130. hiliCostSelfTotal = hiliCostTotal
  10131. }
  10132. if item.MedChrgitmType == "01" { //床位费
  10133. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10134. bedCostSelfTotal = bedCostTotal
  10135. }
  10136. if item.MedChrgitmType == "02" { //诊察费
  10137. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10138. zhenChaCostSelfTotal = zhenChaCostTotal
  10139. }
  10140. if item.MedChrgitmType == "03" { //检查费
  10141. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10142. checkCostSelfTotal = checkCostTotal
  10143. }
  10144. if item.MedChrgitmType == "04" { //化验费
  10145. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10146. laboratoryCostSelfTotal = laboratoryCostTotal
  10147. }
  10148. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10149. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10150. treatCostSelfTotal = treatCostTotal
  10151. }
  10152. if item.MedChrgitmType == "06" { //手术费
  10153. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10154. operationCostSelfTotal = treatCostTotal
  10155. }
  10156. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10157. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10158. materialCostSelfTotal = materialCostTotal
  10159. }
  10160. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10161. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10162. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10163. }
  10164. if item.MedChrgitmType == "11" { //中成费
  10165. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10166. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10167. }
  10168. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10169. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10170. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10171. otherCostSelfTotal = otherCostTotal
  10172. }
  10173. } else {
  10174. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10175. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10176. otherCostSelfTotal = otherCostTotal
  10177. }
  10178. }
  10179. }
  10180. } else {
  10181. for _, item := range orderInfos {
  10182. if item.MedChrgitmType == "01" { //床位费
  10183. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10184. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10185. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10186. }
  10187. if item.MedChrgitmType == "02" { //诊察费
  10188. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10189. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10190. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10191. }
  10192. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10193. if item.MedChrgitmType == "03" { //检查费
  10194. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10195. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10196. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10197. }
  10198. } else {
  10199. if item.MedChrgitmType == "03" { //检查费
  10200. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10201. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10202. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10203. }
  10204. }
  10205. if item.MedChrgitmType == "04" { //化验费
  10206. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10207. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10208. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10209. }
  10210. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10211. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10212. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10213. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10214. }
  10215. if item.MedChrgitmType == "06" { //手术费
  10216. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10217. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10218. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10219. }
  10220. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10221. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10222. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10223. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10224. }
  10225. if item.MedChrgitmType == "07" { //护理
  10226. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10227. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10228. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10229. }
  10230. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10231. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10232. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10233. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10234. }
  10235. if item.MedChrgitmType == "11" { //中成费
  10236. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10237. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10238. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10239. }
  10240. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10241. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10242. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10243. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10244. }
  10245. }
  10246. }
  10247. timeLayout := "2006-01-02"
  10248. loc, _ := time.LoadLocation("Local")
  10249. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10250. if err != nil {
  10251. }
  10252. startRecordDateTime := startTime.Unix()
  10253. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10254. if err != nil {
  10255. }
  10256. endRecordDateTime := endTime.Unix()
  10257. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10258. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10259. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10260. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10261. c.ServeSuccessJSON(map[string]interface{}{
  10262. "charge_admin_name": charge_admin.UserName,
  10263. "order_number": order.Number, //业务流水号
  10264. "id_card_no": his.IdCardNo, //社会保障号
  10265. "patient": patient,
  10266. "department_name": department.Name, //科室
  10267. "number": his.Number, //门诊号
  10268. "date": order.SettleAccountsDate, //结算日期
  10269. "name": order.PsnName, //姓名
  10270. "gender": patient.Gender, //性别
  10271. "psn_cash_money": order.PsnCashPay, //个人支付
  10272. "pay_way": "门诊", //结算方式
  10273. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10274. "admin_user_name": admin.UserName, //收款员
  10275. "order": order,
  10276. "order_info": orderInfos_two,
  10277. "his": his,
  10278. "bedCostTotal": bedCostTotal,
  10279. "bedCostSelfTotal": bedCostSelfTotal,
  10280. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10281. "operationCostTotal": operationCostTotal,
  10282. "operationCostSelfTotal": operationCostSelfTotal,
  10283. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10284. "otherCostTotal": otherCostTotal,
  10285. "otherCostSelfTotal": otherCostSelfTotal,
  10286. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10287. "materialCostTotal": materialCostTotal,
  10288. "materialCostSelfTotal": materialCostSelfTotal,
  10289. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10290. "westernMedicineCostTotal": westernMedicineCostTotal,
  10291. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10292. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10293. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10294. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10295. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10296. "checkCostTotal": checkCostTotal,
  10297. "checkCostSelfTotal": checkCostSelfTotal,
  10298. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10299. "laboratoryCostTotal": laboratoryCostTotal,
  10300. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10301. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10302. "treatCostTotal": treatCostTotal,
  10303. "treatCostSelfTotal": treatCostSelfTotal,
  10304. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10305. "zhenChaCostTotal": zhenChaCostTotal,
  10306. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10307. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10308. "his_hospital_record": his_hospital_record,
  10309. "pre_pay_money": pre_pay_money,
  10310. "refund_sum": sum,
  10311. "doctor_info": doctor_info,
  10312. "hiliCostTotal": hiliCostTotal,
  10313. "hiliCostSelfTotal": hiliCostSelfTotal,
  10314. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10315. })
  10316. }
  10317. //func (c *HisApiController) GetFaPiaoDatas() {
  10318. // order_ids := c.GetString("order_ids")
  10319. // patient_id, _ := c.GetInt64("patient_id")
  10320. // adminUser := c.GetAdminUserInfo()
  10321. //
  10322. // orders := strings.Split(order_ids, ",")
  10323. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10324. //
  10325. // for _, item := range orders {
  10326. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10327. // order, _ := service.GetHisOrderByID(order_id)
  10328. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10329. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10330. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10331. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10332. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10333. //
  10334. // }
  10335. //
  10336. // var bedCostTotal float64 = 0 //床位总费
  10337. // var bedCostSelfTotal float64 = 0 //床位自费
  10338. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10339. //
  10340. // var operationCostTotal float64 = 0 //手术费
  10341. // var operationCostSelfTotal float64 = 0 //手术费
  10342. // var operationCostPartSelfTotal float64 = 0 //手术费
  10343. //
  10344. // var otherCostTotal float64 = 0 //其他费用
  10345. // var otherCostSelfTotal float64 = 0 //其他费用
  10346. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10347. //
  10348. // var materialCostTotal float64 = 0 //材料费
  10349. // var materialCostSelfTotal float64 = 0 //材料费
  10350. // var materialCostPartSelfTotal float64 = 0 //材料费
  10351. //
  10352. // var westernMedicineCostTotal float64 = 0 //西药费
  10353. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10354. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10355. //
  10356. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10357. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10358. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10359. //
  10360. // var checkCostTotal float64 = 0 //检查费
  10361. // var checkCostSelfTotal float64 = 0 //检查费
  10362. // var checkCostPartSelfTotal float64 = 0 //检查费
  10363. //
  10364. // var laboratoryCostTotal float64 = 0 //化验费
  10365. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10366. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10367. //
  10368. // var treatCostTotal float64 = 0 //治疗费用
  10369. // var treatCostSelfTotal float64 = 0 //治疗费用
  10370. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10371. //
  10372. // var zhenChaCostTotal float64 = 0 //其他费用
  10373. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10374. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10375. //
  10376. // decimal.DivisionPrecision = 2
  10377. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10378. //
  10379. // var balanceAccountsType int64
  10380. // if his.ID > 0 {
  10381. // balanceAccountsType = his.BalanceAccountsType
  10382. // } else {
  10383. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10384. // }
  10385. // if balanceAccountsType == 2 {
  10386. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10387. // for _, item := range orderInfos_two {
  10388. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10389. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10390. // item.MedChrgitmType = "09"
  10391. // }
  10392. //
  10393. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10394. // if item.HisPrescriptionProject.Type == 2 {
  10395. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10396. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10397. // case 0:
  10398. // item.MedChrgitmType = "0"
  10399. // break
  10400. // case 1:
  10401. // item.MedChrgitmType = "14"
  10402. // break
  10403. // case 2:
  10404. // item.MedChrgitmType = "05"
  10405. //
  10406. // break
  10407. // case 3:
  10408. // item.MedChrgitmType = "03"
  10409. //
  10410. // break
  10411. // case 4:
  10412. // item.MedChrgitmType = "03"
  10413. //
  10414. // break
  10415. // case 5:
  10416. // item.MedChrgitmType = "08"
  10417. //
  10418. // break
  10419. // case 6:
  10420. // item.MedChrgitmType = "14"
  10421. //
  10422. // break
  10423. // case 7:
  10424. // item.MedChrgitmType = "14"
  10425. //
  10426. // break
  10427. // case 8:
  10428. // item.MedChrgitmType = "03"
  10429. // break
  10430. // case 9:
  10431. // item.MedChrgitmType = "14"
  10432. // break
  10433. // case 10:
  10434. // item.MedChrgitmType = "14"
  10435. // break
  10436. // case 11:
  10437. // item.MedChrgitmType = "06"
  10438. // break
  10439. // case 12:
  10440. // item.MedChrgitmType = "12"
  10441. // break
  10442. // case 13:
  10443. // item.MedChrgitmType = "01"
  10444. // break
  10445. // case 14:
  10446. // item.MedChrgitmType = "04"
  10447. // break
  10448. // case 15:
  10449. // item.MedChrgitmType = "02"
  10450. // break
  10451. //
  10452. // }
  10453. //
  10454. // } else {
  10455. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10456. //
  10457. // case 1:
  10458. // item.MedChrgitmType = "14"
  10459. // break
  10460. // case 2:
  10461. // item.MedChrgitmType = "05"
  10462. //
  10463. // break
  10464. // case 3:
  10465. // item.MedChrgitmType = "03"
  10466. //
  10467. // break
  10468. // case 4:
  10469. // item.MedChrgitmType = "03"
  10470. //
  10471. // break
  10472. // case 5:
  10473. // item.MedChrgitmType = "08"
  10474. //
  10475. // break
  10476. // case 6:
  10477. // item.MedChrgitmType = "14"
  10478. //
  10479. // break
  10480. // case 7:
  10481. // item.MedChrgitmType = "14"
  10482. //
  10483. // break
  10484. // case 8:
  10485. // item.MedChrgitmType = "03"
  10486. // break
  10487. // case 9:
  10488. // item.MedChrgitmType = "14"
  10489. // break
  10490. //
  10491. // }
  10492. //
  10493. // }
  10494. //
  10495. // } else if item.HisPrescriptionProject.Type == 3 {
  10496. // item.MedChrgitmType = "08"
  10497. // }
  10498. // }
  10499. // }
  10500. //
  10501. // for _, item := range orderInfos_two {
  10502. // fmt.Println(item.MedChrgitmType)
  10503. // if item.MedChrgitmType == "01" { //床位费
  10504. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10505. // bedCostSelfTotal = bedCostTotal
  10506. // }
  10507. //
  10508. // if item.MedChrgitmType == "02" { //诊察费
  10509. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10510. // zhenChaCostSelfTotal = zhenChaCostTotal
  10511. // }
  10512. //
  10513. // if item.MedChrgitmType == "03" { //检查费
  10514. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10515. // checkCostSelfTotal = checkCostTotal
  10516. // }
  10517. //
  10518. // if item.MedChrgitmType == "04" { //化验费
  10519. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10520. // laboratoryCostSelfTotal = laboratoryCostTotal
  10521. // }
  10522. //
  10523. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10524. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10525. // treatCostSelfTotal = treatCostTotal
  10526. // }
  10527. //
  10528. // if item.MedChrgitmType == "06" { //手术费
  10529. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10530. // operationCostSelfTotal = treatCostTotal
  10531. // }
  10532. //
  10533. // if item.MedChrgitmType == "08" { //材料费
  10534. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10535. // materialCostSelfTotal = materialCostTotal
  10536. // }
  10537. //
  10538. // if item.MedChrgitmType == "09" { //西药费
  10539. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10540. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10541. // }
  10542. //
  10543. // if item.MedChrgitmType == "11" { //中成费
  10544. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10545. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10546. // }
  10547. //
  10548. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10549. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10550. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10551. // otherCostSelfTotal = otherCostTotal
  10552. // }
  10553. // } else {
  10554. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10555. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10556. // otherCostSelfTotal = otherCostTotal
  10557. // }
  10558. //
  10559. // }
  10560. //
  10561. // }
  10562. //
  10563. // } else {
  10564. // for _, item := range orderInfos {
  10565. // if item.MedChrgitmType == "01" { //床位费
  10566. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10567. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10568. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10569. // }
  10570. //
  10571. // if item.MedChrgitmType == "02" { //诊察费
  10572. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10573. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10574. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10575. // }
  10576. //
  10577. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10578. // if item.MedChrgitmType == "03" { //检查费
  10579. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10580. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10581. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10582. //
  10583. // }
  10584. // } else {
  10585. // if item.MedChrgitmType == "03" { //检查费
  10586. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10587. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10588. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10589. // }
  10590. //
  10591. // }
  10592. //
  10593. // if item.MedChrgitmType == "04" { //化验费
  10594. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10595. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10596. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10597. //
  10598. // }
  10599. //
  10600. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10601. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10602. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10603. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10604. //
  10605. // }
  10606. //
  10607. // if item.MedChrgitmType == "06" { //手术费
  10608. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10609. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10610. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10611. // }
  10612. //
  10613. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10614. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10615. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10616. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10617. // }
  10618. //
  10619. // if item.MedChrgitmType == "09" { //西药费
  10620. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10621. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10622. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10623. // }
  10624. //
  10625. // if item.MedChrgitmType == "11" { //中成费
  10626. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10627. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10628. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10629. // }
  10630. //
  10631. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10632. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10633. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10634. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10635. // }
  10636. //
  10637. // }
  10638. // }
  10639. // timeLayout := "2006-01-02"
  10640. // loc, _ := time.LoadLocation("Local")
  10641. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10642. // if err != nil {
  10643. // }
  10644. // startRecordDateTime := startTime.Unix()
  10645. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10646. // if err != nil {
  10647. // }
  10648. // endRecordDateTime := endTime.Unix()
  10649. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10650. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10651. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10652. //
  10653. // c.ServeSuccessJSON(map[string]interface{}{
  10654. // "order_number": order.Number, //业务流水号
  10655. // "id_card_no": his.IdCardNo, //社会保障号
  10656. // "department_name": department.Name, //科室
  10657. // "number": his.Number, //门诊号
  10658. // "date": order.SettleAccountsDate, //结算日期
  10659. // "name": order.PsnName, //姓名
  10660. // "gender": patient.Gender, //性别
  10661. // "psn_cash_money": order.PsnCashPay, //个人支付
  10662. // "pay_way": "门诊", //结算方式
  10663. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10664. // "admin_user_name": admin.UserName, //收款员
  10665. // "order": order,
  10666. // "order_info": orderInfos_two,
  10667. // "his": his,
  10668. // "bedCostTotal": bedCostTotal,
  10669. // "bedCostSelfTotal": bedCostSelfTotal,
  10670. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10671. // "operationCostTotal": operationCostTotal,
  10672. // "operationCostSelfTotal": operationCostSelfTotal,
  10673. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10674. // "otherCostTotal": otherCostTotal,
  10675. // "otherCostSelfTotal": otherCostSelfTotal,
  10676. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10677. // "materialCostTotal": materialCostTotal,
  10678. // "materialCostSelfTotal": materialCostSelfTotal,
  10679. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10680. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10681. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10682. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10683. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10684. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10685. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10686. // "checkCostTotal": checkCostTotal,
  10687. // "checkCostSelfTotal": checkCostSelfTotal,
  10688. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10689. // "laboratoryCostTotal": laboratoryCostTotal,
  10690. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10691. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10692. // "treatCostTotal": treatCostTotal,
  10693. // "treatCostSelfTotal": treatCostSelfTotal,
  10694. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10695. // "zhenChaCostTotal": zhenChaCostTotal,
  10696. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10697. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10698. // "his_hospital_record": his_hospital_record,
  10699. // "pre_pay_money": pre_pay_money,
  10700. // "refund_sum": sum,
  10701. // })
  10702. //
  10703. //}
  10704. func (this *HisApiController) GetIncomeStatisticsData() {
  10705. start_time := this.GetString("start_time")
  10706. end_time := this.GetString("end_time")
  10707. key_words := this.GetString("key_words")
  10708. limit, _ := this.GetInt64("limit")
  10709. page, _ := this.GetInt64("page")
  10710. if page <= 0 {
  10711. page = 1
  10712. }
  10713. if limit <= 0 {
  10714. limit = 10
  10715. }
  10716. statistics_type, _ := this.GetInt64("statistics_type")
  10717. admin := this.GetAdminUserInfo()
  10718. timeLayout := "2006-01-02"
  10719. loc, _ := time.LoadLocation("Local")
  10720. var theStartTIme int64
  10721. if len(start_time) > 0 {
  10722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10723. if err != nil {
  10724. theStartTIme = 0
  10725. }
  10726. theStartTIme = theTime.Unix()
  10727. }
  10728. var theEndtTIme int64
  10729. if len(end_time) > 0 {
  10730. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10731. if err != nil {
  10732. theEndtTIme = 0
  10733. }
  10734. theEndtTIme = theTime.Unix()
  10735. }
  10736. if statistics_type == 1 {
  10737. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10738. this.ServeSuccessJSON(map[string]interface{}{
  10739. "list": list,
  10740. "total": total,
  10741. })
  10742. } else {
  10743. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10744. this.ServeSuccessJSON(map[string]interface{}{
  10745. "list": list,
  10746. "total": total,
  10747. })
  10748. }
  10749. }
  10750. func (c *HisApiController) PostProjectInformation() {
  10751. adminUser := c.GetAdminUserInfo()
  10752. orgId := adminUser.CurrentOrgId
  10753. dataBody := make(map[string]interface{}, 0)
  10754. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10755. if err != nil {
  10756. utils.ErrorLog(err.Error())
  10757. return
  10758. }
  10759. utils.ErrorLog("%v", dataBody)
  10760. var projectList []*models.HisProject
  10761. var total_goods []interface{}
  10762. tempProjects := dataBody["projects"].([]interface{})
  10763. total_goods = tempProjects
  10764. for index, projectMap := range tempProjects {
  10765. projectM := projectMap.(map[string]interface{})
  10766. var project models.HisProject
  10767. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10768. utils.ErrorLog("project_name")
  10769. return
  10770. }
  10771. project_name, _ := projectM["project_name"].(string)
  10772. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10773. err_log := models.ExportErrLog{
  10774. LogType: 6,
  10775. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10776. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10777. Status: 1,
  10778. CreateTime: time.Now().Unix(),
  10779. UpdateTime: time.Now().Unix(),
  10780. ExportTime: time.Now().Unix(),
  10781. }
  10782. service.CreateExportErrLog(&err_log)
  10783. continue
  10784. }
  10785. project.ProjectName = project_name
  10786. prices := projectM["price"].(string)
  10787. price, _ := strconv.ParseFloat(prices, 64)
  10788. if price <= 0 { //名字为空则生成一条导入错误日志
  10789. err_log := models.ExportErrLog{
  10790. LogType: 6,
  10791. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10792. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10793. Status: 1,
  10794. CreateTime: time.Now().Unix(),
  10795. UpdateTime: time.Now().Unix(),
  10796. ExportTime: time.Now().Unix(),
  10797. }
  10798. service.CreateExportErrLog(&err_log)
  10799. continue
  10800. }
  10801. project.Price = price
  10802. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10803. utils.ErrorLog("unit_id")
  10804. return
  10805. }
  10806. unit := projectM["unit"].(string)
  10807. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10808. err_log := models.ExportErrLog{
  10809. LogType: 6,
  10810. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10811. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10812. Status: 1,
  10813. CreateTime: time.Now().Unix(),
  10814. UpdateTime: time.Now().Unix(),
  10815. ExportTime: time.Now().Unix(),
  10816. }
  10817. service.CreateExportErrLog(&err_log)
  10818. continue
  10819. }
  10820. project.Unit = unit
  10821. cost_classify := projectM["cost_classify"].(string)
  10822. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10823. err_log := models.ExportErrLog{
  10824. LogType: 6,
  10825. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10826. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10827. Status: 1,
  10828. CreateTime: time.Now().Unix(),
  10829. UpdateTime: time.Now().Unix(),
  10830. ExportTime: time.Now().Unix(),
  10831. }
  10832. service.CreateExportErrLog(&err_log)
  10833. continue
  10834. }
  10835. var costClassify = "费用类别"
  10836. var cost_classify_id int64
  10837. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10838. if len(cost_classify) != 0 {
  10839. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10840. if errcode == gorm.ErrRecordNotFound {
  10841. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10842. dataconfig := models.DictDataconfig{
  10843. ParentId: costClassifyConfig.ID,
  10844. Module: "system",
  10845. OrgId: orgId,
  10846. Name: cost_classify,
  10847. FieldName: "",
  10848. Value: costConfig.Value + 1,
  10849. CreatedTime: "",
  10850. UpdatedTime: "",
  10851. CreateUserId: adminUser.AdminUser.Id,
  10852. Status: 1,
  10853. Remark: "",
  10854. DeleteIdSystem: 0,
  10855. Title: "",
  10856. Content: "",
  10857. Order: 0,
  10858. Code: "",
  10859. }
  10860. service.CreatedDicConfig(&dataconfig)
  10861. }
  10862. }
  10863. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10864. for _, it := range costClassList {
  10865. if cost_classify == it.Name {
  10866. cost_classify_id = int64(it.Value)
  10867. }
  10868. }
  10869. project.CostClassify = cost_classify_id
  10870. executive_section := projectM["executive_section"].(string)
  10871. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10872. err_log := models.ExportErrLog{
  10873. LogType: 6,
  10874. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10875. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10876. Status: 1,
  10877. CreateTime: time.Now().Unix(),
  10878. UpdateTime: time.Now().Unix(),
  10879. ExportTime: time.Now().Unix(),
  10880. }
  10881. service.CreateExportErrLog(&err_log)
  10882. continue
  10883. }
  10884. if len(executive_section) != 0 {
  10885. //查找科室是否有内容
  10886. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10887. if errcodedepart == gorm.ErrRecordNotFound {
  10888. department := models.XtHisDepartment{
  10889. Name: executive_section,
  10890. Status: 1,
  10891. UserOrgId: adminUser.CurrentOrgId,
  10892. CreatedTime: time.Now().Unix(),
  10893. }
  10894. service.CreateDePartment(&department)
  10895. }
  10896. }
  10897. var executive_section_id int64
  10898. departMentList, _ := service.GetAllDepartMent(orgId)
  10899. for _, it := range departMentList {
  10900. if executive_section == it.Name {
  10901. executive_section_id = it.ID
  10902. }
  10903. }
  10904. project.ExecutiveSection = executive_section_id
  10905. medical_coverage := projectM["medical_coverage"].(string)
  10906. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10907. err_log := models.ExportErrLog{
  10908. LogType: 6,
  10909. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10910. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10911. Status: 1,
  10912. CreateTime: time.Now().Unix(),
  10913. UpdateTime: time.Now().Unix(),
  10914. ExportTime: time.Now().Unix(),
  10915. }
  10916. service.CreateExportErrLog(&err_log)
  10917. continue
  10918. }
  10919. var medicalCoverage = "医保等级"
  10920. var medical_coverage_id int64
  10921. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10922. if len(medical_coverage) != 0 {
  10923. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10924. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10925. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10926. dataconfig := models.DictDataconfig{
  10927. ParentId: medicalCoverageConfig.ID,
  10928. Module: "system",
  10929. OrgId: orgId,
  10930. Name: medical_coverage,
  10931. FieldName: "",
  10932. Value: medicalCoverageConfig.Value + 1,
  10933. CreatedTime: "",
  10934. UpdatedTime: "",
  10935. CreateUserId: adminUser.AdminUser.Id,
  10936. Status: 1,
  10937. Remark: "",
  10938. DeleteIdSystem: 0,
  10939. Title: "",
  10940. Content: "",
  10941. Order: 0,
  10942. Code: "",
  10943. }
  10944. service.CreatedDicConfig(&dataconfig)
  10945. }
  10946. }
  10947. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10948. for _, it := range medicalCoverageList {
  10949. if medical_coverage == it.Name {
  10950. medical_coverage_id = int64(it.Value)
  10951. }
  10952. }
  10953. project.MedicalCoverage = medical_coverage_id
  10954. pinyin := projectM["pinyin"].(string)
  10955. project.Pinyin = pinyin
  10956. wubi := projectM["wubi"].(string)
  10957. project.Wubi = wubi
  10958. statistical_classification := projectM["statistical_classification"].(string)
  10959. var statisticalClassification = "统计分类"
  10960. var statistical_classification_id int64
  10961. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10962. if len(statistical_classification) != 0 {
  10963. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10964. if classificationerrcodes == gorm.ErrRecordNotFound {
  10965. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10966. dataconfig := models.DictDataconfig{
  10967. ParentId: classiFication.ID,
  10968. Module: "system",
  10969. OrgId: orgId,
  10970. Name: statistical_classification,
  10971. FieldName: "",
  10972. Value: classiFicationConfig.Value + 1,
  10973. CreatedTime: "",
  10974. UpdatedTime: "",
  10975. CreateUserId: adminUser.AdminUser.Id,
  10976. Status: 1,
  10977. Remark: "",
  10978. DeleteIdSystem: 0,
  10979. Title: "",
  10980. Content: "",
  10981. Order: 0,
  10982. Code: "",
  10983. }
  10984. service.CreatedDicConfig(&dataconfig)
  10985. }
  10986. }
  10987. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10988. for _, it := range classiFicationList {
  10989. if statistical_classification == it.Name {
  10990. statistical_classification_id = int64(it.Value)
  10991. }
  10992. }
  10993. project.StatisticalClassification = statistical_classification_id
  10994. disease_directory := int64(projectM["disease_directory"].(float64))
  10995. project.DiseaseDirectory = disease_directory
  10996. is_record := int64(projectM["is_record"].(float64))
  10997. project.IsRecord = is_record
  10998. medical_code := projectM["medical_code"].(string)
  10999. project.MedicalCode = medical_code
  11000. tube_color := projectM["tube_color"].(string)
  11001. var tubeColor = "试管颜色"
  11002. var tube_color_id int64
  11003. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11004. if len(tube_color) != 0 {
  11005. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11006. if errcodetube == gorm.ErrRecordNotFound {
  11007. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11008. dataconfig := models.DictDataconfig{
  11009. ParentId: tubeColorConfig.ID,
  11010. Module: "system",
  11011. OrgId: orgId,
  11012. Name: tube_color,
  11013. FieldName: "",
  11014. Value: tubeConfig.Value + 1,
  11015. CreatedTime: "",
  11016. UpdatedTime: "",
  11017. CreateUserId: adminUser.AdminUser.Id,
  11018. Status: 1,
  11019. Remark: "",
  11020. DeleteIdSystem: 0,
  11021. Title: "",
  11022. Content: "",
  11023. Order: 0,
  11024. Code: "",
  11025. }
  11026. service.CreatedDicConfig(&dataconfig)
  11027. }
  11028. }
  11029. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11030. for _, it := range tubeColorList {
  11031. if tube_color == it.Name {
  11032. tube_color_id = int64(it.Value)
  11033. }
  11034. }
  11035. project.TubeColor = tube_color_id
  11036. single_dose := projectM["single_dose"].(string)
  11037. project.SingleDose = single_dose
  11038. execution_frequency := projectM["execution_frequency"].(string)
  11039. project.ExecutionFrequency = execution_frequency
  11040. delivery_way := projectM["delivery_way"].(string)
  11041. project.DeliveryWay = delivery_way
  11042. number_days := projectM["number_days"].(string)
  11043. project.NumberDays = number_days
  11044. total := projectM["total"].(string)
  11045. project.Total = total
  11046. medical_status := int64(projectM["medical_status"].(float64))
  11047. project.MedicalStatus = medical_status
  11048. category := int64(projectM["category"].(float64))
  11049. project.Category = category
  11050. specail_project := int64(projectM["specail_project"].(float64))
  11051. project.SpecailProject = specail_project
  11052. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11053. project.SocialSecurityDirectoryCode = social_security_directory_code
  11054. remark := projectM["remark"].(string)
  11055. project.Remark = remark
  11056. record_date := projectM["record_date"].(string)
  11057. timeLayout := "2006-01-02"
  11058. loc, _ := time.LoadLocation("Local")
  11059. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11060. project.RecordDate = theTime.Unix()
  11061. projectList = append(projectList, &project)
  11062. }
  11063. export_time := time.Now().Unix()
  11064. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11065. if len(projectList) > 0 {
  11066. for _, item := range projectList {
  11067. hans := item.ProjectName // 要转换的汉字字符串
  11068. // 创建一个拼音转换器
  11069. p := pinyin.NewArgs()
  11070. // 将汉字转为拼音
  11071. pinyinSlice := pinyin.Pinyin(hans, p)
  11072. // 输出拼音
  11073. fmt.Println("Pinyin:", pinyinSlice)
  11074. // 获取首字母
  11075. firstLetter := ""
  11076. for _, py := range pinyinSlice {
  11077. if len(py) > 0 {
  11078. firstLetter += string(py[0][0])
  11079. }
  11080. }
  11081. item.FirstLetter = firstLetter
  11082. project := models.HisProject{
  11083. ProjectName: item.ProjectName,
  11084. Price: item.Price,
  11085. Unit: item.Unit,
  11086. CostClassify: item.CostClassify,
  11087. ExecutiveSection: item.ExecutiveSection,
  11088. MedicalCoverage: item.MedicalCoverage,
  11089. UserOrgId: orgId,
  11090. Status: 1,
  11091. CreatedTime: time.Now().Unix(),
  11092. Pinyin: item.Pinyin,
  11093. Wubi: item.Wubi,
  11094. StatisticalClassification: item.StatisticalClassification,
  11095. DiseaseDirectory: item.DiseaseDirectory,
  11096. IsRecord: item.IsRecord,
  11097. MedicalCode: item.MedicalCode,
  11098. TubeColor: item.TubeColor,
  11099. SingleDose: item.SingleDose,
  11100. DeliveryWay: item.DeliveryWay,
  11101. NumberDays: item.NumberDays,
  11102. Total: item.Total,
  11103. Category: item.Category,
  11104. MedicalStatus: item.MedicalStatus,
  11105. SpecailProject: item.SpecailProject,
  11106. RecordDate: item.RecordDate,
  11107. Remark: item.Remark,
  11108. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11109. ExecutionFrequency: item.ExecutionFrequency,
  11110. FirstLetter: item.FirstLetter,
  11111. }
  11112. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11113. if errcodeproject == gorm.ErrRecordNotFound {
  11114. service.CreateProjectInfomation(&project)
  11115. } else if errcodeproject == nil {
  11116. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11117. }
  11118. log := models.ExportLog{
  11119. LogType: 6,
  11120. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11121. TotalNum: int64(len(total_goods)),
  11122. FailNum: int64(len(errLogs)),
  11123. SuccessNum: int64(len(projectList)),
  11124. CreateTime: time.Now().Unix(),
  11125. UpdateTime: time.Now().Unix(),
  11126. ExportTime: export_time,
  11127. Status: 1,
  11128. }
  11129. service.CreateExportLog(&log)
  11130. c.ServeSuccessJSON(map[string]interface{}{
  11131. "msg": "导入成功",
  11132. "total_num": len(total_goods),
  11133. "success_num": len(projectList),
  11134. "fail_num": int64(len(errLogs)),
  11135. })
  11136. }
  11137. } else {
  11138. log := models.ExportLog{
  11139. LogType: 6,
  11140. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11141. TotalNum: int64(len(total_goods)),
  11142. FailNum: int64(len(errLogs)),
  11143. SuccessNum: int64(len(projectList)),
  11144. CreateTime: time.Now().Unix(),
  11145. UpdateTime: time.Now().Unix(),
  11146. ExportTime: export_time,
  11147. Status: 1,
  11148. }
  11149. service.CreateExportLog(&log)
  11150. c.ServeSuccessJSON(map[string]interface{}{
  11151. "msg": "导入成功",
  11152. "total_num": len(total_goods),
  11153. "success_num": len(projectList),
  11154. "fail_num": int64(len(errLogs)),
  11155. })
  11156. }
  11157. }
  11158. //func (this *HisApiController) EditProjectInformation(){
  11159. //
  11160. // id, _ := this.GetInt64("id")
  11161. // project_team := this.GetString("project_team")
  11162. // price := this.GetString("price")
  11163. // price_float, _ := strconv.ParseFloat(price, 64)
  11164. // pinyin := this.GetString("pinyin")
  11165. // wubi := this.GetString("wubi")
  11166. // tube_color, _ := this.GetInt64("tube_color")
  11167. // team_type, _ := this.GetInt64("team_type")
  11168. // remark := this.GetString("remark")
  11169. // ids := this.GetString("ids")
  11170. // item_id := this.GetString("item_id")
  11171. // projectTeam := models.XtHisProjectTeam{
  11172. // ProjectTeam: project_team,
  11173. // Price: price_float,
  11174. // Pinyin: pinyin,
  11175. // Wubi: wubi,
  11176. // TubeColor: tube_color,
  11177. // TeamType: team_type,
  11178. // Remark: remark,
  11179. // ProjectId: ids,
  11180. // ItemId: item_id,
  11181. // }
  11182. //
  11183. //
  11184. // dataBody := make(map[string]interface{}, 0)
  11185. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11186. // if err != nil {
  11187. // utils.ErrorLog(err.Error())
  11188. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11189. // return
  11190. // }
  11191. //
  11192. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11193. //
  11194. //
  11195. // if err != nil {
  11196. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11197. // return
  11198. // }
  11199. //
  11200. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11201. // infos, _ := dataBody["info"].([]interface{})
  11202. // if len(infos) > 0 {
  11203. // var ids []string
  11204. //
  11205. // for _, item := range infos {
  11206. // items := item.(map[string]interface{})
  11207. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11208. // utils.ErrorLog("id")
  11209. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11210. // return
  11211. // }
  11212. // id := int64(items["id"].(float64))
  11213. //
  11214. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11215. // utils.ErrorLog("type")
  11216. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11217. // return
  11218. // }
  11219. // types := int64(items["type"].(float64))
  11220. //
  11221. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11222. // utils.ErrorLog("number")
  11223. // }
  11224. //
  11225. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11226. //
  11227. // projectList := models.XtHisProjectList{
  11228. // Number: number,
  11229. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11230. // ProjectId: id,
  11231. // Status: 1,
  11232. // CreatedTime: time.Now().Unix(),
  11233. // UpdatedTime: time.Now().Unix(),
  11234. // TeamId: projectTeam.ID,
  11235. // Type: types,
  11236. // }
  11237. // list := projectList
  11238. //
  11239. // service.CreateProjectList(&list)
  11240. //
  11241. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11242. //
  11243. // }
  11244. // ids_str := strings.Join(ids, ",")
  11245. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11246. // service.SaveProjectTeam(&projectTeam)
  11247. // this.ServeSuccessJSON(map[string]interface{}{
  11248. // "projectTeam": projectTeam,
  11249. // })
  11250. // }
  11251. // }
  11252. //}
  11253. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11254. name := c.GetString("name")
  11255. mode_id, _ := c.GetInt64("mode", 0)
  11256. types, _ := c.GetInt64("type", 0)
  11257. patient_id, _ := c.GetInt64("patient_id", 0)
  11258. types = 1
  11259. adminInfo := c.GetAdminUserInfo()
  11260. template := &models.HisPrescriptionTemplate{
  11261. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11262. PatientId: patient_id,
  11263. Type: types,
  11264. Status: 1,
  11265. Ctime: time.Now().Unix(),
  11266. Mtime: time.Now().Unix(),
  11267. Name: name,
  11268. Mode: mode_id,
  11269. }
  11270. dataBody := make(map[string]interface{}, 0)
  11271. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11272. if err != nil {
  11273. utils.ErrorLog(err.Error())
  11274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11275. return
  11276. }
  11277. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11278. //如果已经存在记录则删除处方
  11279. if template_one.ID > 0 {
  11280. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11281. var ids []int64
  11282. var org_id int64
  11283. for _, item := range ps {
  11284. org_id = c.GetAdminUserInfo().CurrentOrgId
  11285. ids = append(ids, item.ID)
  11286. }
  11287. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11288. if err2 == nil {
  11289. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11290. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11291. if len(prescriptions) > 0 {
  11292. for _, item := range prescriptions {
  11293. items := item.(map[string]interface{})
  11294. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11295. utils.ErrorLog("type")
  11296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11297. return
  11298. }
  11299. types := int64(items["type"].(float64))
  11300. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11301. utils.ErrorLog("med_type")
  11302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11303. return
  11304. }
  11305. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11306. ctime := time.Now().Unix()
  11307. prescription := &models.HisPrescriptionInfoTemplate{
  11308. PatientId: patient_id,
  11309. UserOrgId: adminInfo.CurrentOrgId,
  11310. Ctime: ctime,
  11311. Mtime: ctime,
  11312. Type: types,
  11313. Modifier: adminInfo.AdminUser.Id,
  11314. Creator: adminInfo.AdminUser.Id,
  11315. Status: 1,
  11316. PTemplateId: template_one.ID,
  11317. MedType: med_type,
  11318. }
  11319. service.CreateHisPrescriptionInfoTemplate(prescription)
  11320. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11321. advices := items["advices"].([]interface{})
  11322. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11323. ctime := time.Now().Unix()
  11324. mtime := ctime
  11325. if len(advices) > 0 {
  11326. for _, advice := range advices {
  11327. var s models.HisPrescriptionAdviceTemplate
  11328. s.PrescriptionId = prescription.ID
  11329. s.AdviceType = 2
  11330. s.StopState = 2
  11331. s.ExecutionState = 2
  11332. s.Status = 1
  11333. s.UserOrgId = adminInfo.CurrentOrgId
  11334. s.CreatedTime = ctime
  11335. s.UpdatedTime = mtime
  11336. s.PatientId = patient_id
  11337. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11338. if errcode > 0 {
  11339. c.ServeFailJSONWithSGJErrorCode(errcode)
  11340. return
  11341. }
  11342. service.CreateHisPrescriptionAdviceTemplate(&s)
  11343. }
  11344. }
  11345. }
  11346. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11347. projects := items["project"].([]interface{})
  11348. if len(projects) > 0 {
  11349. for _, project := range projects {
  11350. var p models.HisPrescriptionProjectTemplate
  11351. p.PrescriptionId = prescription.ID
  11352. p.Ctime = time.Now().Unix()
  11353. p.Mtime = time.Now().Unix()
  11354. p.PatientId = patient_id
  11355. p.UserOrgId = adminInfo.CurrentOrgId
  11356. p.Status = 1
  11357. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11358. if errcode > 0 {
  11359. c.ServeFailJSONWithSGJErrorCode(errcode)
  11360. return
  11361. }
  11362. service.CreateHisPrescriptionProjectTemplate(&p)
  11363. }
  11364. }
  11365. }
  11366. }
  11367. c.ServeSuccessJSON(map[string]interface{}{
  11368. "msg": "创建成功",
  11369. })
  11370. }
  11371. }
  11372. } else {
  11373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11374. return
  11375. }
  11376. } else {
  11377. err3 := service.CreateHisPrescriptionTemplate(template)
  11378. if err3 == 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.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. }
  11467. }
  11468. func (c *HisApiController) PreSettle() {
  11469. id, _ := c.GetInt64("id")
  11470. record_time := c.GetString("record_time")
  11471. his_patient_id, _ := c.GetInt64("his_patient_id")
  11472. timeLayout := "2006-01-02"
  11473. loc, _ := time.LoadLocation("Local")
  11474. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11475. diagnosis_id := c.GetString("diagnosis")
  11476. sick_type, _ := c.GetInt64("sick_type")
  11477. reg_type, _ := c.GetInt64("p_type")
  11478. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11479. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11480. if err != nil {
  11481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11482. return
  11483. }
  11484. recordDateTime := theTime.Unix()
  11485. adminUser := c.GetAdminUserInfo()
  11486. var prescriptions []*models.HisPrescription
  11487. var start_time int64
  11488. var end_time int64
  11489. ids_str := c.GetString("ids")
  11490. ids_arr := strings.Split(ids_str, ",")
  11491. fmt.Println(reg_type)
  11492. if settle_accounts_type == 1 { //日结
  11493. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11494. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11495. } else {
  11496. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11497. }
  11498. fmt.Println(prescriptions)
  11499. } else { //月结
  11500. start_time_str := c.GetString("start_time")
  11501. end_time_str := c.GetString("end_time")
  11502. timeLayout := "2006-01-02"
  11503. loc, _ := time.LoadLocation("Local")
  11504. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11505. if err != nil {
  11506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11507. return
  11508. }
  11509. recordStartTime := theStartTime.Unix()
  11510. start_time = recordStartTime
  11511. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11512. if err != nil {
  11513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11514. return
  11515. }
  11516. recordEndTime := theEndTime.Unix()
  11517. end_time = recordEndTime
  11518. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11519. }
  11520. if reg_type == 1111 || reg_type == 1112 {
  11521. reg_type = 11
  11522. }
  11523. timestamp := time.Now().Unix()
  11524. tempTime := time.Unix(timestamp, 0)
  11525. timeFormat := tempTime.Format("20060102150405")
  11526. chrgBchno := rand.Intn(100000) + 10000
  11527. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11528. strconv.FormatInt(his.PatientId, 10)
  11529. var ids []int64
  11530. for _, item := range prescriptions {
  11531. ids = append(ids, item.ID)
  11532. }
  11533. fmt.Println(ids)
  11534. var total float64
  11535. for _, item := range prescriptions {
  11536. fmt.Println(item)
  11537. if item.Type == 1 { //药品
  11538. for _, subItem := range item.HisDoctorAdviceInfo {
  11539. total = total + (subItem.Price * subItem.PrescribingNumber)
  11540. }
  11541. }
  11542. if item.Type == 2 { //项目
  11543. for _, subItem := range item.HisPrescriptionProject {
  11544. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11545. total = total + (subItem.Price * cnt)
  11546. }
  11547. }
  11548. for _, subItem := range item.HisAdditionalCharge {
  11549. total = total + (subItem.Price * float64(subItem.Count))
  11550. }
  11551. }
  11552. allTotal := fmt.Sprintf("%.2f", total)
  11553. totals, _ := strconv.ParseFloat(allTotal, 64)
  11554. order := &models.HisOrder{
  11555. UserOrgId: adminUser.CurrentOrgId,
  11556. HisPatientId: his.ID,
  11557. PatientId: id,
  11558. SettleAccountsDate: recordDateTime,
  11559. Ctime: time.Now().Unix(),
  11560. Mtime: time.Now().Unix(),
  11561. Status: 1,
  11562. OrderStatus: 1,
  11563. MdtrtId: his.Number,
  11564. Number: chrg_bchno,
  11565. MedfeeSumamt: totals,
  11566. SettleEndTime: end_time,
  11567. SettleStartTime: start_time,
  11568. SettleType: settle_accounts_type,
  11569. PsnPartAmt: totals,
  11570. PsnCashPay: totals,
  11571. PType: 2,
  11572. IsPre: 1,
  11573. MedType: strconv.Itoa(int(reg_type)),
  11574. Diagnosis: diagnosis_id,
  11575. }
  11576. err = service.CreateOrder(order)
  11577. if err != nil {
  11578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11579. return
  11580. }
  11581. var customs []*Custom
  11582. for _, item := range prescriptions {
  11583. fmt.Println(item.Type)
  11584. if item.Type == 1 { //药品
  11585. for _, subItem := range item.HisDoctorAdviceInfo {
  11586. cus := &Custom{
  11587. AdviceId: subItem.ID,
  11588. ProjectId: 0,
  11589. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11590. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11591. FeedetlSn: subItem.FeedetlSn,
  11592. Price: fmt.Sprintf("%.2f", subItem.Price),
  11593. MedListCodg: subItem.MedListCodg,
  11594. Type: 1,
  11595. }
  11596. customs = append(customs, cus)
  11597. }
  11598. }
  11599. if item.Type == 2 { //项目
  11600. for _, subItem := range item.HisPrescriptionProject {
  11601. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11602. cus := &Custom{
  11603. AdviceId: 0,
  11604. ProjectId: subItem.ID,
  11605. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11606. Cut: fmt.Sprintf("%.2f", cnt),
  11607. FeedetlSn: subItem.FeedetlSn,
  11608. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11609. MedListCodg: subItem.MedListCodg,
  11610. Type: 2,
  11611. }
  11612. customs = append(customs, cus)
  11613. }
  11614. }
  11615. for _, item := range item.HisAdditionalCharge {
  11616. cus := &Custom{
  11617. ItemId: item.ID,
  11618. AdviceId: 0,
  11619. ProjectId: 0,
  11620. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11621. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11622. FeedetlSn: item.FeedetlSn,
  11623. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11624. MedListCodg: item.XtHisAddtionConfig.Code,
  11625. Type: 3,
  11626. }
  11627. customs = append(customs, cus)
  11628. }
  11629. }
  11630. fmt.Println(customs)
  11631. for _, item := range customs {
  11632. var advice_id int64 = 0
  11633. var project_id int64 = 0
  11634. var item_id int64 = 0
  11635. var types int64 = 0
  11636. if item.Type == 1 {
  11637. advice_id = item.AdviceId
  11638. project_id = 0
  11639. item_id = 0
  11640. } else if item.Type == 2 {
  11641. advice_id = 0
  11642. item_id = 0
  11643. project_id = item.ProjectId
  11644. } else if item.Type == 3 {
  11645. advice_id = 0
  11646. item_id = item.ItemId
  11647. project_id = 0
  11648. }
  11649. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11650. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11651. pric, _ := strconv.ParseFloat(item.Price, 32)
  11652. info := &models.HisOrderInfo{
  11653. OrderNumber: order.Number,
  11654. UploadDate: time.Now().Unix(),
  11655. AdviceId: advice_id,
  11656. DetItemFeeSumamt: detItemFeeSumamt,
  11657. Cnt: cut,
  11658. Pric: pric,
  11659. PatientId: id,
  11660. Status: 1,
  11661. Mtime: time.Now().Unix(),
  11662. Ctime: time.Now().Unix(),
  11663. UserOrgId: adminUser.CurrentOrgId,
  11664. HisPatientId: his.ID,
  11665. OrderId: order.ID,
  11666. ProjectId: project_id,
  11667. Type: types,
  11668. ItemId: item_id,
  11669. }
  11670. service.CreateOrderInfo(info)
  11671. }
  11672. his.SickType = sick_type
  11673. service.UpdataHisPateint(&his)
  11674. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11675. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11676. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11677. if err == nil {
  11678. c.ServeSuccessJSON(map[string]interface{}{
  11679. "msg": "结算成功",
  11680. })
  11681. }
  11682. }
  11683. type CustomOrderInfo struct {
  11684. Name string
  11685. Spec string
  11686. Unit string
  11687. Count float64
  11688. Price float64
  11689. Total float64
  11690. }
  11691. func (c *HisApiController) GetPrivateExpensesInfo() {
  11692. order_id, _ := c.GetInt64("id", 0)
  11693. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11694. order, _ := service.GetHisOrderByID(order_id)
  11695. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11696. if order.ID == 0 {
  11697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11698. return
  11699. }
  11700. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11701. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11702. org_id := c.GetAdminUserInfo().CurrentOrgId
  11703. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11704. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11705. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11706. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11707. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11708. //var orderInfos_four []*models.HisOrderInfoTwo
  11709. //for _, item := range orderInfos_three {
  11710. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11711. // item.HisPrescriptionProject.IsCheckTeam = 1
  11712. // orderInfos_four = append(orderInfos_four, item)
  11713. //
  11714. // }
  11715. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11716. // item.HisPrescriptionProject.IsCheckTeam = 2
  11717. // orderInfos_two = append(orderInfos_two, item)
  11718. // }
  11719. //}
  11720. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11721. //var cus_slice []CustomOrderInfo
  11722. //for _, item := range new_order_info {
  11723. // var cus CustomOrderInfo
  11724. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11725. // cus.Unit = ""
  11726. // cus.Spec = ""
  11727. // var total float64
  11728. // for _, subItem := range orderInfos_four {
  11729. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11730. // total = total + subItem.DetItemFeeSumamt
  11731. // fmt.Println(subItem.DetItemFeeSumamt)
  11732. // }
  11733. // }
  11734. // cus.Count = 1
  11735. // cus.Total = total
  11736. // cus_slice = append(cus_slice, cus)
  11737. //}
  11738. orderInfos = append(orderInfos, orderInfos_two...)
  11739. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11740. //orderInfos = append(orderInfos, orderInfos_three...)
  11741. //}/**/
  11742. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11743. c.ServeSuccessJSON(map[string]interface{}{
  11744. "order": order,
  11745. "order_info": orderInfos,
  11746. "patient": patient,
  11747. "admin_info": adminInfo,
  11748. "his": his,
  11749. "current_admin": role,
  11750. "org_config": miConfig,
  11751. //"new_order_info": cus_slice,
  11752. })
  11753. }
  11754. func (this *HisApiController) ChangeMedType() {
  11755. med_type := this.GetString("med_type")
  11756. old_med_type := this.GetString("old_med_type")
  11757. ids := this.GetString("ids")
  11758. settle_type, _ := this.GetInt64("settle_type")
  11759. start_time := this.GetString("start_time")
  11760. end_time := this.GetString("end_time")
  11761. ids_arr := strings.Split(ids, ",")
  11762. if settle_type == 1 { //日结
  11763. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11764. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11765. prescription.MedType = med_type
  11766. err := service.SaveHisPrescriptionTwo(&prescription)
  11767. if err == nil {
  11768. this.ServeSuccessJSON(map[string]interface{}{
  11769. "msg": "修改成功",
  11770. })
  11771. } else {
  11772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11773. return
  11774. }
  11775. } else if settle_type == 2 {
  11776. timeLayout := "2006-01-02"
  11777. loc, _ := time.LoadLocation("Local")
  11778. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11779. if err != nil {
  11780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11781. return
  11782. }
  11783. recordStartTime := theStartTime.Unix()
  11784. start_time_timestamp := recordStartTime
  11785. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11786. if err != nil {
  11787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11788. return
  11789. }
  11790. recordEndTime := theEndTime.Unix()
  11791. end_time_timestamp := recordEndTime
  11792. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11793. if updateErr == nil {
  11794. this.ServeSuccessJSON(map[string]interface{}{
  11795. "msg": "修改成功",
  11796. })
  11797. } else {
  11798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11799. return
  11800. }
  11801. }
  11802. }
  11803. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11804. patient_id, _ := c.GetInt64("patient_id")
  11805. his_patient_id, _ := c.GetInt64("his_patient_id")
  11806. record_date := c.GetString("record_date")
  11807. start_time := c.GetString("start_time")
  11808. end_time := c.GetString("end_time")
  11809. order_status, _ := c.GetInt64("type", 0)
  11810. p_type, _ := c.GetInt64("p_type", 0)
  11811. order_id, _ := c.GetInt64("order_id", 0)
  11812. timeLayout := "2006-01-02"
  11813. loc, _ := time.LoadLocation("Local")
  11814. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11815. if err != nil {
  11816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11817. return
  11818. }
  11819. recordDateTime := theTime.Unix()
  11820. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11821. if err != nil {
  11822. }
  11823. startRecordDateTime := startTime.Unix()
  11824. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11825. if err != nil {
  11826. }
  11827. endRecordDateTime := endTime.Unix()
  11828. admin := c.GetAdminUserInfo()
  11829. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11830. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11831. order, _ := service.GetHisOrderByID(order_id)
  11832. var monthPrescriptions []*models.HisPrescription
  11833. if order_status == 1 || order_status == 0 {
  11834. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11835. } else if order_status == 2 {
  11836. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11837. }
  11838. var settle_total float64
  11839. for _, item := range monthPrescriptions {
  11840. if len(item.HisPrescriptionProject) > 0 {
  11841. for _, subItem := range item.HisPrescriptionProject {
  11842. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11843. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11844. settle_total = settle_total + total
  11845. }
  11846. }
  11847. if len(item.HisDoctorAdviceInfo) > 0 {
  11848. for _, subItem := range item.HisDoctorAdviceInfo {
  11849. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11850. settle_total = settle_total + total
  11851. }
  11852. }
  11853. }
  11854. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11855. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11856. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11857. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11858. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11859. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11860. //获取所有科室信息
  11861. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11862. var dia string
  11863. for _, item := range month_p_info {
  11864. if len(dia) == 0 {
  11865. dia = item.Diagnosis
  11866. } else {
  11867. dia = dia + "," + item.Diagnosis
  11868. }
  11869. }
  11870. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11871. dia_arr = removeEmptyStrings(dia_arr)
  11872. c.ServeSuccessJSON(map[string]interface{}{
  11873. "his_info": his_patient_info,
  11874. "xt_info": xt_patient_info,
  11875. "case_history": case_history,
  11876. "info": patientPrescriptionInfo,
  11877. "last_info": lastPatientPrescriptionInfo,
  11878. "month_prescriptions": monthPrescriptions,
  11879. "order": order,
  11880. "doctors": doctors,
  11881. "department": department,
  11882. "settle_total": settle_total,
  11883. "dia_arr": dia_arr,
  11884. })
  11885. return
  11886. }
  11887. func removeEmptyStrings(input []string) []string {
  11888. var output []string
  11889. for _, s := range input {
  11890. if s != "" {
  11891. output = append(output, s)
  11892. }
  11893. }
  11894. return output
  11895. }
  11896. func removeDuplicates(input []string) []string {
  11897. seen := make(map[string]bool)
  11898. output := []string{}
  11899. for _, s := range input {
  11900. if _, exists := seen[s]; !exists {
  11901. seen[s] = true
  11902. output = append(output, s)
  11903. }
  11904. }
  11905. return output
  11906. }
  11907. func (c *HisApiController) GetHisMonthPatientInfo() {
  11908. patient_id, _ := c.GetInt64("patient_id")
  11909. his_patient_id, _ := c.GetInt64("his_patient_id")
  11910. record_date := c.GetString("record_date")
  11911. number := c.GetString("number")
  11912. start_time := c.GetString("start_time")
  11913. end_time := c.GetString("end_time")
  11914. p_type, _ := c.GetInt64("p_type")
  11915. timeLayout := "2006-01-02"
  11916. loc, _ := time.LoadLocation("Local")
  11917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11918. if err != nil {
  11919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11920. return
  11921. }
  11922. recordDateTime := theTime.Unix()
  11923. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11924. if err != nil {
  11925. }
  11926. startRecordDateTime := startTime.Unix()
  11927. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11928. if err != nil {
  11929. }
  11930. endRecordDateTime := endTime.Unix()
  11931. admin := c.GetAdminUserInfo()
  11932. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11933. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11934. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11935. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11936. var settle_total float64
  11937. for _, item := range monthPrescriptions {
  11938. if len(item.HisPrescriptionProject) > 0 {
  11939. for _, subItem := range item.HisPrescriptionProject {
  11940. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11941. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11942. settle_total = settle_total + total
  11943. }
  11944. }
  11945. if len(item.HisDoctorAdviceInfo) > 0 {
  11946. for _, subItem := range item.HisDoctorAdviceInfo {
  11947. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11948. settle_total = settle_total + total
  11949. }
  11950. }
  11951. }
  11952. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11953. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11954. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11955. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11956. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11957. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11958. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11959. //获取所有科室信息
  11960. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11961. c.ServeSuccessJSON(map[string]interface{}{
  11962. "his_info": his_patient_info,
  11963. "xt_info": xt_patient_info,
  11964. "case_history": case_history,
  11965. "info": patientPrescriptionInfo,
  11966. "month_prescriptions": monthPrescriptions,
  11967. "order": order,
  11968. "doctors": doctors,
  11969. "department": department,
  11970. "count": count,
  11971. "drugStockConfig": drugStockConfig,
  11972. "last_info": lastPatientPrescriptionInfo,
  11973. "settle_total": settle_total,
  11974. })
  11975. return
  11976. }
  11977. func (c *HisApiController) GetAllOrder() {
  11978. org_id := c.GetAdminUserInfo().CurrentOrgId
  11979. orders, _ := service.GetNewHisOrderList(org_id)
  11980. c.ServeSuccessJSON(map[string]interface{}{
  11981. "order": orders,
  11982. })
  11983. return
  11984. }
  11985. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11986. newArr = make([]*models.HisOrderInfoTwo, 0)
  11987. for i := 0; i < len(arr); i++ {
  11988. repeat := false
  11989. for j := i + 1; j < len(arr); j++ {
  11990. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11991. repeat = true
  11992. break
  11993. }
  11994. }
  11995. if !repeat {
  11996. newArr = append(newArr, arr[i])
  11997. }
  11998. }
  11999. return
  12000. }
  12001. // 修改处方退库操作 参数传修改之前的处方数据
  12002. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12003. if advice.ExecutionState == 1 {
  12004. //查询该病人该药品是否有库存记录
  12005. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12006. if errcode == gorm.ErrRecordNotFound {
  12007. } else {
  12008. //退库
  12009. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12010. if advice.PrescribingNumberUnit == drug.MinUnit {
  12011. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12012. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12013. //退库
  12014. warehouseInfo := models.DrugWarehouseInfo{
  12015. StockMinNumber: prescribingNumber,
  12016. }
  12017. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12018. operation_time := time.Now().Unix()
  12019. creater := advice.AdviceDoctor
  12020. ctime := time.Now().Unix()
  12021. timeStr := time.Now().Format("2006-01-02")
  12022. timeArr := strings.Split(timeStr, "-")
  12023. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12024. total = total + 1
  12025. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12026. cancelStock := models.DrugCancelStock{
  12027. OrderNumber: orderNumber,
  12028. OperaTime: operation_time,
  12029. OrgId: advice.UserOrgId,
  12030. Creater: creater,
  12031. Ctime: ctime,
  12032. Status: 1,
  12033. ReturnTime: advice.AdviceDate,
  12034. Dealer: info.Dealer,
  12035. Manufacturer: info.Manufacturer,
  12036. Type: 1,
  12037. }
  12038. service.AddSigleDrugCancelStock(&cancelStock)
  12039. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12040. dealer, _ := service.GetDealerById(info.Dealer)
  12041. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12042. cancelStockInfo := models.DrugCancelStockInfo{
  12043. OrderNumber: cancelInfo.OrderNumber,
  12044. CancelStockId: cancelInfo.ID,
  12045. DrugId: info.DrugId,
  12046. Count: info.Count,
  12047. Status: 1,
  12048. Ctime: ctime,
  12049. OrgId: advice.UserOrgId,
  12050. Type: 1,
  12051. Manufacturer: manufactureName.ManufacturerName,
  12052. Dealer: dealer.DealerName,
  12053. Total: 0,
  12054. RetailPrice: info.RetailPrice,
  12055. RetailTotalPrice: info.RetailTotalPrice,
  12056. Price: info.Price,
  12057. RegisterAccount: "",
  12058. Remark: info.Remark,
  12059. BatchNumber: info.BatchNumber,
  12060. MaxUnit: info.CountUnit,
  12061. ProductDate: info.ProductDate,
  12062. ExpiryDate: info.ExpiryDate,
  12063. BatchNumberId: info.WarehouseInfoId,
  12064. }
  12065. flow := models.DrugFlow{
  12066. WarehousingId: 0,
  12067. DrugId: info.DrugId,
  12068. Number: "",
  12069. BatchNumber: info.BatchNumber,
  12070. Count: info.Count,
  12071. UserOrgId: advice.UserOrgId,
  12072. PatientId: 0,
  12073. SystemTime: ctime,
  12074. ConsumableType: 4,
  12075. IsSys: 0,
  12076. WarehousingOrder: "",
  12077. WarehouseOutId: 0,
  12078. WarehouseOutOrderNumber: "",
  12079. IsEdit: 0,
  12080. CancelStockId: cancelStock.ID,
  12081. CancelOrderNumber: cancelStock.OrderNumber,
  12082. Manufacturer: info.Manufacturer,
  12083. Dealer: info.Dealer,
  12084. Creator: advice.UserOrgId,
  12085. UpdateCreator: 0,
  12086. Status: 1,
  12087. Ctime: time.Now().Unix(),
  12088. Mtime: 0,
  12089. Price: info.Price,
  12090. WarehousingDetailId: 0,
  12091. WarehouseOutDetailId: 0,
  12092. CancelOutDetailId: 0,
  12093. ExpireDate: info.ExpiryDate,
  12094. ProductDate: info.ProductDate,
  12095. MaxUnit: info.CountUnit,
  12096. MinUnit: "",
  12097. }
  12098. service.CreatedCancelStock(cancelStockInfo)
  12099. service.CreateDrugFlowOne(flow)
  12100. } else {
  12101. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12102. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12103. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12104. warehouseInfo := models.DrugWarehouseInfo{
  12105. StockMinNumber: prescribingNumber,
  12106. }
  12107. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12108. }
  12109. operation_time := time.Now().Unix()
  12110. creater := advice.AdviceDoctor
  12111. ctime := time.Now().Unix()
  12112. timeStr := time.Now().Format("2006-01-02")
  12113. timeArr := strings.Split(timeStr, "-")
  12114. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12115. total = total + 1
  12116. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12117. cancelStock := models.DrugCancelStock{
  12118. OrderNumber: orderNumber,
  12119. OperaTime: operation_time,
  12120. OrgId: advice.UserOrgId,
  12121. Creater: creater,
  12122. Ctime: ctime,
  12123. Status: 1,
  12124. ReturnTime: advice.AdviceDate,
  12125. Dealer: info.Dealer,
  12126. Manufacturer: info.Manufacturer,
  12127. Type: 1,
  12128. }
  12129. service.AddSigleDrugCancelStock(&cancelStock)
  12130. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12131. dealer, _ := service.GetDealerById(info.Dealer)
  12132. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12133. cancelStockInfo := models.DrugCancelStockInfo{
  12134. OrderNumber: cancelInfo.OrderNumber,
  12135. CancelStockId: cancelInfo.ID,
  12136. DrugId: info.DrugId,
  12137. Count: info.Count,
  12138. Status: 1,
  12139. Ctime: ctime,
  12140. OrgId: advice.UserOrgId,
  12141. Type: 1,
  12142. Manufacturer: manufactureName.ManufacturerName,
  12143. Dealer: dealer.DealerName,
  12144. Total: 0,
  12145. RetailPrice: info.RetailPrice,
  12146. RetailTotalPrice: info.RetailTotalPrice,
  12147. Price: info.Price,
  12148. RegisterAccount: "",
  12149. Remark: info.Remark,
  12150. BatchNumber: info.BatchNumber,
  12151. MaxUnit: info.CountUnit,
  12152. ProductDate: info.ProductDate,
  12153. ExpiryDate: info.ExpiryDate,
  12154. BatchNumberId: info.WarehouseInfoId,
  12155. }
  12156. flow := models.DrugFlow{
  12157. WarehousingId: 0,
  12158. DrugId: info.DrugId,
  12159. Number: "",
  12160. BatchNumber: info.BatchNumber,
  12161. Count: info.Count,
  12162. UserOrgId: advice.UserOrgId,
  12163. PatientId: 0,
  12164. SystemTime: ctime,
  12165. ConsumableType: 4,
  12166. IsSys: 0,
  12167. WarehousingOrder: "",
  12168. WarehouseOutId: 0,
  12169. WarehouseOutOrderNumber: "",
  12170. IsEdit: 0,
  12171. CancelStockId: cancelStock.ID,
  12172. CancelOrderNumber: cancelStock.OrderNumber,
  12173. Manufacturer: info.Manufacturer,
  12174. Dealer: info.Dealer,
  12175. Creator: advice.AdviceDoctor,
  12176. UpdateCreator: 0,
  12177. Status: 1,
  12178. Ctime: time.Now().Unix(),
  12179. Mtime: 0,
  12180. Price: info.Price,
  12181. WarehousingDetailId: 0,
  12182. WarehouseOutDetailId: 0,
  12183. CancelOutDetailId: 0,
  12184. ExpireDate: info.ExpiryDate,
  12185. ProductDate: info.ProductDate,
  12186. MaxUnit: info.CountUnit,
  12187. MinUnit: "",
  12188. }
  12189. service.CreatedCancelStock(cancelStockInfo)
  12190. service.CreateDrugFlowOne(flow)
  12191. }
  12192. }
  12193. }
  12194. return err
  12195. }
  12196. func (this *HisApiController) DeleteNCDS() {
  12197. id, _ := this.GetInt64("id", 0)
  12198. if id > 0 {
  12199. service.DeletePsnNCDSRecordById(id)
  12200. this.ServeSuccessJSON(map[string]interface{}{
  12201. "msg": "删除成功",
  12202. })
  12203. } else {
  12204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12205. return
  12206. }
  12207. }
  12208. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12209. id, _ := c.GetInt64("id")
  12210. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12211. c.ServeSuccessJSON(map[string]interface{}{
  12212. "advice": advice,
  12213. })
  12214. return
  12215. }
  12216. func (c *HisApiController) GetHisMonthChargePatientList() {
  12217. record_date := c.GetString("record_date")
  12218. start_time := c.GetString("start_time")
  12219. end_time := c.GetString("end_time")
  12220. timeLayout := "2006-01-02"
  12221. loc, _ := time.LoadLocation("Local")
  12222. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12223. if err != nil {
  12224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12225. return
  12226. }
  12227. if err != nil {
  12228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12229. return
  12230. }
  12231. recordDateTime := theTime.Unix()
  12232. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12233. if err != nil {
  12234. }
  12235. startRecordDateTime := startTime.Unix()
  12236. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12237. if err != nil {
  12238. }
  12239. endRecordDateTime := endTime.Unix()
  12240. adminInfo := c.GetAdminUserInfo()
  12241. var tempMonthChargePatients []*service.MonthChargePatients
  12242. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12243. for _, item := range tempPatients {
  12244. //过滤没有处方的
  12245. if len(item.HisPrescription) == 0 {
  12246. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12247. }
  12248. }
  12249. c.ServeSuccessJSON(map[string]interface{}{
  12250. "list": tempMonthChargePatients,
  12251. })
  12252. }
  12253. // PrescriptionDifference 医嘱数量差值结构体
  12254. type PrescriptionDrugDifference struct {
  12255. DrugID int64 //基础库药品id
  12256. ID int64 //医嘱id
  12257. Difference float64 //差值
  12258. Unit string //单位
  12259. }
  12260. type PrescriptionGoodDifference struct {
  12261. GoodID int64 //基础库项目耗材id
  12262. ID int64 //医嘱id
  12263. Difference int64 //差值
  12264. Unit string //单位
  12265. Type int64 //类型
  12266. }
  12267. type EditCustomData struct {
  12268. adviceList []*models.HisDoctorAdviceInfo
  12269. projectList []*models.HisPrescriptionProject
  12270. }
  12271. type SrcCustomData struct {
  12272. adviceList []*models.HisDoctorAdviceInfo
  12273. projectList []*models.HisPrescriptionProject
  12274. }
  12275. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12276. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12277. differences := make([]*PrescriptionDrugDifference, 0)
  12278. // 创建一个 map 来存储第一个切片中的药品信息
  12279. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12280. for _, advice := range firstPrescription {
  12281. firstMap[advice.DrugId] = advice
  12282. }
  12283. // 遍历第二个切片中的药品信息,并比较数量差值
  12284. for _, advice := range secondPrescription {
  12285. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12286. diff := &PrescriptionDrugDifference{
  12287. DrugID: advice.DrugId,
  12288. ID: firstAdvice.ID,
  12289. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12290. Unit: firstAdvice.PrescribingNumberUnit,
  12291. }
  12292. differences = append(differences, diff)
  12293. }
  12294. }
  12295. return differences
  12296. }
  12297. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12298. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12299. differences := make([]*PrescriptionGoodDifference, 0)
  12300. // 创建一个 map 来存储第一个切片中的耗材信息
  12301. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12302. for _, good := range firstPrescription {
  12303. firstMap[good.ProjectId] = good
  12304. }
  12305. // 遍历第二个切片中的耗材信息,并比较数量差值
  12306. for _, good := range secondPrescription {
  12307. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12308. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12309. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12310. diff := &PrescriptionGoodDifference{
  12311. GoodID: good.ProjectId,
  12312. ID: firstGood.ID,
  12313. Difference: count - firstCount,
  12314. Unit: firstGood.Unit,
  12315. Type: firstGood.Type,
  12316. }
  12317. differences = append(differences, diff)
  12318. }
  12319. }
  12320. return differences
  12321. }
  12322. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12323. var adviceList []*models.HisDoctorAdviceInfo
  12324. var projectList []*models.HisPrescriptionProject
  12325. var advice_ids []int64
  12326. var project_ids []int64
  12327. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12328. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12329. //var tempPrescription *models.HisPrescriptionProjectscription
  12330. if len(prescriptions) > 0 {
  12331. for _, item := range prescriptions {
  12332. items := item.(map[string]interface{})
  12333. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12334. advices := items["advices"].([]interface{})
  12335. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12336. groupNo := int64(0)
  12337. ctime := time.Now().Unix()
  12338. mtime := ctime
  12339. if len(advices) > 0 {
  12340. for _, advice := range advices {
  12341. var s models.HisDoctorAdviceInfo
  12342. s.AdviceType = 2
  12343. s.StopState = 2
  12344. s.ExecutionState = 2
  12345. s.Status = 1
  12346. s.Groupno = groupNo
  12347. s.CreatedTime = ctime
  12348. s.UpdatedTime = mtime
  12349. s.IsSettle = 2
  12350. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12351. //存储切片中
  12352. if s.ID > 0 {
  12353. advice_ids = append(advice_ids, s.ID)
  12354. adviceList = append(adviceList, &s)
  12355. }
  12356. }
  12357. }
  12358. }
  12359. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12360. projects := items["project"].([]interface{})
  12361. if len(projects) > 0 {
  12362. for _, project := range projects {
  12363. var p models.HisPrescriptionProject
  12364. p.Ctime = time.Now().Unix()
  12365. p.Mtime = time.Now().Unix()
  12366. p.Status = 1
  12367. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12368. if p.ID > 0 {
  12369. project_ids = append(project_ids, p.ID)
  12370. projectList = append(projectList, &p)
  12371. }
  12372. }
  12373. }
  12374. }
  12375. }
  12376. }
  12377. }
  12378. editCustomData.projectList = projectList
  12379. editCustomData.adviceList = adviceList
  12380. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12381. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12382. srcCustomData.adviceList = list
  12383. srcCustomData.projectList = list2
  12384. return
  12385. }