his_api_controller.go 516KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224
  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 == 10666 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 9675 {
  2776. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2777. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2778. var tempPrescription *models.HisPrescription
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. // 开始外部循环的事务
  2782. tx := db.Begin()
  2783. // 在函数结束时处理事务回滚
  2784. defer func() {
  2785. if r := recover(); r != nil {
  2786. tx.Rollback()
  2787. }
  2788. }()
  2789. items := item.(map[string]interface{})
  2790. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2791. utils.ErrorLog("id")
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. id := int64(items["id"].(float64))
  2796. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2797. tempPrescription = &new_prescription
  2798. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2799. utils.ErrorLog("type")
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. types := int64(items["type"].(float64))
  2804. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2805. utils.ErrorLog("med_type")
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2810. if med_type == "0" {
  2811. med_type = "14"
  2812. }
  2813. //if order_status == 0 {
  2814. // order_status = 1
  2815. //}
  2816. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2817. utils.ErrorLog("pre_time")
  2818. }
  2819. preTime, _ := items["pre_time"].(string)
  2820. fmt.Println("preTime", preTime)
  2821. timeLayout := "2006-01-02"
  2822. loc, _ := time.LoadLocation("Local")
  2823. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2824. result := strings.Split(preTime, " ")
  2825. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2826. if err != nil {
  2827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2828. return
  2829. }
  2830. pTime := theTime2.Unix()
  2831. ctime := time.Now().Unix()
  2832. if tempPrescription.ID == 0 {
  2833. prescription := &models.HisPrescription{
  2834. ID: 0,
  2835. PatientId: patient_id,
  2836. UserOrgId: adminInfo.CurrentOrgId,
  2837. RecordDate: recordDateTime,
  2838. Ctime: ctime,
  2839. Mtime: ctime,
  2840. Type: types,
  2841. Modifier: adminInfo.AdminUser.Id,
  2842. Creator: adminInfo.AdminUser.Id,
  2843. Status: 1,
  2844. Doctor: role.UserName,
  2845. HisPatientId: his_patient_id,
  2846. OrderStatus: 1,
  2847. BatchNumber: "",
  2848. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2849. PreTime: pTime,
  2850. PType: p_type,
  2851. MedType: med_type,
  2852. }
  2853. tempPrescription = prescription
  2854. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2855. redis := service.RedisClient()
  2856. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2857. redis.Set(key, "", time.Second)
  2858. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2859. redis.Set(keyOne, "", time.Second)
  2860. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2861. redis.Set(keySeven, "", time.Second)
  2862. defer redis.Close()
  2863. } else {
  2864. tempPrescription.ID = id
  2865. tempPrescription.Type = types
  2866. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2867. tempPrescription.Mtime = time.Now().Unix()
  2868. tempPrescription.Doctor = role.UserName
  2869. //tempPrescription.OrderStatus = order_status
  2870. tempPrescription.PreTime = pTime
  2871. tempPrescription.MedType = med_type
  2872. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2873. redis := service.RedisClient()
  2874. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2875. redis.Set(key, "", time.Second)
  2876. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2877. redis.Set(keyOne, "", time.Second)
  2878. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2879. redis.Set(keySeven, "", time.Second)
  2880. defer redis.Close()
  2881. }
  2882. //service.SaveHisPrescription(prescription)
  2883. //更改患者挂号状态
  2884. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2885. fmt.Println("更改失败", err2)
  2886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2887. advices := items["advices"].([]interface{})
  2888. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2889. groupNo := int64(0)
  2890. if len(advices) > 0 {
  2891. for _, advice := range advices {
  2892. tx := db.Begin()
  2893. // 在函数结束时处理事务回滚
  2894. defer func() {
  2895. if r := recover(); r != nil {
  2896. tx.Rollback()
  2897. }
  2898. }()
  2899. var s models.HisDoctorAdviceInfo
  2900. s.PrescriptionId = tempPrescription.ID
  2901. s.AdviceType = 2
  2902. s.AdviceDoctor = doctor_id
  2903. s.StopState = 2
  2904. s.ExecutionState = 2
  2905. s.AdviceDate = theTime3.Unix()
  2906. s.Status = 1
  2907. s.UserOrgId = adminInfo.CurrentOrgId
  2908. s.RecordDate = theTime3.Unix()
  2909. s.StartTime = tempPrescription.PreTime
  2910. s.Groupno = groupNo
  2911. s.PatientId = patient_id
  2912. s.HisPatientId = his_patient_id
  2913. s.StartTime = pTime
  2914. s.IsSettle = 2
  2915. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2916. if errcode > 0 {
  2917. c.ServeFailJSONWithSGJErrorCode(errcode)
  2918. return
  2919. }
  2920. s.StartTime = pTime
  2921. var total_count int64 //处方总库存
  2922. //查询改药品信息
  2923. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2924. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2925. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2926. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2927. total_count += prescribingNumberSeven * medical.MinNumber
  2928. }
  2929. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2930. total_count += prescribingNumberSeven
  2931. }
  2932. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2933. total_count += prescribingNumberSeven
  2934. }
  2935. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2936. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2937. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2938. if s.Price != lastWarehouse.RetailPrice {
  2939. s.Price = lastWarehouse.RetailPrice
  2940. }
  2941. if s.Price == 0 {
  2942. if lastWarehouse.ID == 0 {
  2943. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2944. s.Price = lastWarehouseTwo.RetailPrice
  2945. }
  2946. }
  2947. }
  2948. //查询保存处方出库开关是否打开
  2949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2950. if s.PatientId != 30038 {
  2951. if drugOutConfig.IsOpen == 1 {
  2952. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2953. // 查询该药品最后一次出库记录
  2954. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2955. var is_user_total int64
  2956. var no_user_total int64
  2957. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2958. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2959. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2960. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2961. }
  2962. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2963. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2964. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2965. no_user_total += prescribingNumberSevenTy
  2966. }
  2967. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2968. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2969. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2970. no_user_total += prescribingNumberSevenTy
  2971. }
  2972. if len(druginfo) > 0 {
  2973. for _, it := range druginfo {
  2974. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2975. it.Count = it.Count * drug.MinNumber
  2976. is_user_total += it.Count
  2977. }
  2978. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2979. is_user_total += it.Count
  2980. }
  2981. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2982. is_user_total += it.Count
  2983. }
  2984. }
  2985. }
  2986. //fmt.Println("药品名称----------------------", drug.DrugName)
  2987. //fmt.Println("药品名称----------------------", drug.IsUse)
  2988. //fmt.Println("is_user_total-------------------------", is_user_total)
  2989. //fmt.Println("no_user_total-------------------------", no_user_total)
  2990. if is_user_total != no_user_total {
  2991. //出库
  2992. if drug.IsUse == 2 {
  2993. creater := adminInfo.AdminUser.Id
  2994. newadviceInfo := &models.HisDoctorAdviceInfo{
  2995. ID: s.ID,
  2996. UserOrgId: s.UserOrgId,
  2997. PatientId: s.PatientId,
  2998. HisPatientId: s.HisPatientId,
  2999. AdviceType: s.AdviceType,
  3000. AdviceDate: s.AdviceDate,
  3001. StartTime: s.StartTime,
  3002. AdviceName: s.AdviceName,
  3003. AdviceDesc: s.AdviceDesc,
  3004. ReminderDate: s.ReminderDate,
  3005. SingleDose: s.SingleDose,
  3006. SingleDoseUnit: s.SingleDoseUnit,
  3007. PrescribingNumber: s.PrescribingNumber,
  3008. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3009. DeliveryWay: s.DeliveryWay,
  3010. ExecutionFrequency: s.ExecutionFrequency,
  3011. AdviceDoctor: s.AdviceDoctor,
  3012. Status: s.Status,
  3013. CreatedTime: s.CreatedTime,
  3014. UpdatedTime: s.UpdatedTime,
  3015. AdviceAffirm: s.AdviceAffirm,
  3016. Remark: s.Remark,
  3017. StopTime: s.StopTime,
  3018. StopReason: s.StopReason,
  3019. StopDoctor: s.StopDoctor,
  3020. StopState: s.StopState,
  3021. ParentId: s.ParentId,
  3022. ExecutionTime: s.ExecutionTime,
  3023. ExecutionStaff: s.ExecutionStaff,
  3024. ExecutionState: s.ExecutionState,
  3025. Checker: s.Checker,
  3026. RecordDate: s.RecordDate,
  3027. DialysisOrderId: s.DialysisOrderId,
  3028. CheckTime: s.CheckTime,
  3029. CheckState: s.CheckState,
  3030. DrugSpec: s.DrugSpec,
  3031. DrugSpecUnit: s.DrugSpecUnit,
  3032. Groupno: s.Groupno,
  3033. RemindType: s.RemindType,
  3034. FrequencyType: s.FrequencyType,
  3035. DayCount: s.DayCount,
  3036. WeekDay: s.WeekDay,
  3037. TemplateId: s.TemplateId,
  3038. Modifier: s.Modifier,
  3039. DrugId: s.DrugId,
  3040. Price: s.Price,
  3041. PrescriptionId: s.PrescriptionId,
  3042. MedListCodg: s.MedListCodg,
  3043. FeedetlSn: s.FeedetlSn,
  3044. Day: s.DayCount,
  3045. ChildDoctorAdvice: nil,
  3046. Drug: models.Drug{},
  3047. Diagnosis: s.Diagnosis,
  3048. Way: s.Way,
  3049. HospApprFlag: s.HospApprFlag,
  3050. LmtUsedFlag: s.LmtUsedFlag,
  3051. HisOrderInfo: models.HisOrderInfo{},
  3052. IsMedicine: s.IsMedicine,
  3053. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3054. Child: nil,
  3055. IsSettle: s.IsSettle,
  3056. IsMobile: s.IsMobile,
  3057. IsSelfDrug: s.IsSelfDrug,
  3058. DrugWayCount: s.DrugWayCount,
  3059. }
  3060. var history_count int64
  3061. var local_count int64
  3062. //查找已经开过的医嘱信息
  3063. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3064. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. local_count += prescribingNumberSevenTy * drug.MinNumber
  3068. }
  3069. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. local_count += prescribingNumberSevenTy
  3073. }
  3074. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3075. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3076. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3077. local_count += prescribingNumberSevenTy
  3078. }
  3079. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3080. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3081. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3082. history_count += prescribingNumberSevenTy * drug.MinNumber
  3083. }
  3084. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3085. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3086. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3087. history_count += prescribingNumberSevenTy
  3088. }
  3089. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3090. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3091. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3092. history_count += prescribingNumberSevenTy
  3093. }
  3094. //如果当前出库数量大于历史出库数量则需要出库
  3095. if local_count > history_count {
  3096. //按最小单位出库
  3097. var cha_count = local_count - history_count
  3098. newadviceInfo.PrescribingNumber = float64(cha_count)
  3099. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3100. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3101. }
  3102. //如果当前出库数量小于历史出库数量则需要退库
  3103. if local_count < history_count {
  3104. var cha_count = history_count - local_count
  3105. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. }
  3108. if local_count == history_count {
  3109. if is_user_total == 0 {
  3110. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3111. }
  3112. }
  3113. }
  3114. //更新字典里面的库存
  3115. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3116. var sum_count int64
  3117. for _, its := range stockInfo {
  3118. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3119. if its.MaxUnit == baseDrug.MaxUnit {
  3120. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3121. }
  3122. sum_count += its.StockMaxNumber + its.StockMinNumber
  3123. }
  3124. //更新基础库存
  3125. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3126. //剩余库存
  3127. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3128. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3129. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3130. //创建医嘱
  3131. service.CreateHisDoctorAdviceOne(&s, tx)
  3132. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. if len(outInfoTwo) > 0 {
  3135. for _, item := range outInfoTwo {
  3136. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3137. }
  3138. }
  3139. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3140. if len(drugAutoDetail) > 0 {
  3141. for _, item := range drugAutoDetail {
  3142. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. //记录日志
  3149. byterequest, _ := json.Marshal(s)
  3150. adviceLog := models.XtDoctorAdviceLog{
  3151. UserOrgId: s.UserOrgId,
  3152. PatientId: s.PatientId,
  3153. AdminUserId: adminInfo.AdminUser.Id,
  3154. Module: 1,
  3155. ErrLog: string(byterequest),
  3156. Status: 1,
  3157. Ctime: time.Now().Unix(),
  3158. Mtime: 0,
  3159. Source: "电脑端新建his医嘱",
  3160. RecordDate: s.AdviceDate,
  3161. }
  3162. service.CreateDoctorAdviceLog(adviceLog)
  3163. //存储切片中
  3164. adviceList = append(adviceList, s)
  3165. redis := service.RedisClient()
  3166. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3167. redis.Set(key, "", time.Second)
  3168. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3169. redis.Set(keyOne, "", time.Second)
  3170. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3171. redis.Set(keySeven, "", time.Second)
  3172. var randNum int
  3173. randNum = rand.Intn(10000) + 1000
  3174. timestamp := time.Now().Unix()
  3175. tempTime := time.Unix(timestamp, 0)
  3176. timeFormat := tempTime.Format("20060102150405")
  3177. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3178. //查询改药品是否已经停用
  3179. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3180. if base.ID > 0 {
  3181. tx.Rollback()
  3182. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3183. return
  3184. }
  3185. service.CreateHisDoctorAdviceOne(&s, tx)
  3186. tx.Commit()
  3187. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3188. redis.Set(keySix, "", time.Second)
  3189. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3190. redis.Set(keyFive, "", time.Second)
  3191. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3192. redis.Set(keyEight, "", time.Second)
  3193. defer redis.Close()
  3194. }
  3195. }
  3196. }
  3197. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3198. projects := items["project"].([]interface{})
  3199. if len(projects) > 0 {
  3200. for _, project := range projects {
  3201. tx := db.Begin()
  3202. // 在函数结束时处理事务回滚
  3203. defer func() {
  3204. if r := recover(); r != nil {
  3205. tx.Rollback()
  3206. }
  3207. }()
  3208. var p models.HisPrescriptionProject
  3209. p.PrescriptionId = tempPrescription.ID
  3210. p.PatientId = patient_id
  3211. p.RecordDate = theTime3.Unix()
  3212. p.Doctor = doctor_id
  3213. p.UserOrgId = adminInfo.CurrentOrgId
  3214. p.HisPatientId = his_patient_id
  3215. p.Status = 1
  3216. p.StartTime = pTime
  3217. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3218. if errcode > 0 {
  3219. c.ServeFailJSONWithSGJErrorCode(errcode)
  3220. return
  3221. }
  3222. if p.ID == 0 {
  3223. p.IsOut = 2
  3224. }
  3225. if p.ID > 0 {
  3226. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3227. p.IsOut = projectDetail.IsOut
  3228. }
  3229. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3230. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3231. if p.Type == 3 {
  3232. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3233. if p.Price != lastWarehouse.PackingPrice {
  3234. p.Price = lastWarehouse.PackingPrice
  3235. }
  3236. if p.Price == 0 {
  3237. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3238. p.Price = lastWarehouseTwo.PackingPrice
  3239. }
  3240. if p.Unit == "" {
  3241. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3242. p.Unit = goodInfoOne.PackingUnit
  3243. }
  3244. }
  3245. }
  3246. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3247. //
  3248. // if p.Type == 3 {
  3249. // //查询该耗材是否停用
  3250. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3251. // //表示该耗材已经停用,不能保存
  3252. // if goodInfoSeven.ID == 0 {
  3253. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3254. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3255. // return
  3256. // }
  3257. // }
  3258. //
  3259. //}
  3260. //查询保存耗材出库开关是否打开
  3261. if p.PatientId != 30038 {
  3262. if goodOutConfig.IsOpen == 1 {
  3263. //耗材出库
  3264. if p.Type == 3 {
  3265. //对比当前数据和历史出库数据
  3266. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3267. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3268. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3269. //如果当前处方数量大于历史数据,则需要出库
  3270. if nowCount > historyCount {
  3271. var cha_count int64
  3272. cha_count = nowCount - historyCount
  3273. timeStr := time.Now().Format("2006-01-02")
  3274. timeArr := strings.Split(timeStr, "-")
  3275. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3276. total = total + 1
  3277. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3278. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3279. number = number + total
  3280. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3281. operation_time := time.Now().Unix()
  3282. creater := c.GetAdminUserInfo().AdminUser.Id
  3283. recordDateStr := time.Now().Format("2006-01-02")
  3284. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3285. nowtime := recordDate.Unix()
  3286. warehouseOut := models.WarehouseOut{
  3287. WarehouseOutOrderNumber: warehousing_out_order,
  3288. OperationTime: operation_time,
  3289. OrgId: adminInfo.CurrentOrgId,
  3290. Creater: creater,
  3291. Ctime: time.Now().Unix(),
  3292. Status: 1,
  3293. WarehouseOutTime: nowtime,
  3294. Type: 1,
  3295. StorehouseId: storeConfig.StorehouseOutInfo,
  3296. IsCheck: 1,
  3297. IsSys: 1,
  3298. }
  3299. //查询是否生成出库单
  3300. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3301. if out.ID == 0 {
  3302. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3303. }
  3304. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3305. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3306. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3307. dialyPrepareOne := models.DialysisBeforePrepare{
  3308. GoodTypeId: goodObj.GoodTypeId,
  3309. GoodId: p.ProjectId,
  3310. PatientId: p.PatientId,
  3311. RecordDate: p.RecordDate,
  3312. UserOrgId: adminInfo.CurrentOrgId,
  3313. Count: cha_count,
  3314. Ctime: time.Now().Unix(),
  3315. Creater: creater,
  3316. Status: 1,
  3317. StorehouseId: houseConfig.StorehouseOutInfo,
  3318. ProjectId: p.ID,
  3319. }
  3320. //出库
  3321. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3322. }
  3323. //如果当前处方数量小于历史数据,怎需要退库
  3324. if nowCount < historyCount {
  3325. var cha_count int64
  3326. cha_count = historyCount - nowCount
  3327. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3328. creater := c.GetAdminUserInfo().AdminUser.Id
  3329. newPrescriptionProject := &models.HisPrescriptionProject{
  3330. ID: p.ID,
  3331. ProjectId: p.ProjectId,
  3332. Price: p.Price,
  3333. UserOrgId: p.UserOrgId,
  3334. Status: 1,
  3335. Ctime: time.Now().Unix(),
  3336. Mtime: time.Now().Unix(),
  3337. PatientId: p.PatientId,
  3338. HisPatientId: p.HisPatientId,
  3339. RecordDate: p.RecordDate,
  3340. PrescriptionId: p.PrescriptionId,
  3341. Count: p.Count,
  3342. FeedetlSn: p.FeedetlSn,
  3343. MedListCodg: p.MedListCodg,
  3344. SingleDose: p.SingleDose,
  3345. DeliveryWay: p.DeliveryWay,
  3346. ExecutionFrequency: p.ExecutionFrequency,
  3347. Day: p.Day,
  3348. HisProject: models.HisProject{},
  3349. GoodInfo: models.GoodInfo{},
  3350. Remark: p.Remark,
  3351. Unit: p.Unit,
  3352. Type: p.Type,
  3353. Doctor: p.Doctor,
  3354. ExecutionTime: p.ExecutionTime,
  3355. ExecutionStaff: p.ExecutionStaff,
  3356. ExecutionState: p.ExecutionState,
  3357. CheckTime: p.CheckTime,
  3358. CheckState: p.CheckState,
  3359. Checker: p.Checker,
  3360. StartTime: p.StartTime,
  3361. TeamId: p.TeamId,
  3362. XtHisProjectTeam: models.XtHisProjectTeam{},
  3363. FrequencyType: p.FrequencyType,
  3364. DayCount: p.DayCount,
  3365. WeekDay: p.WeekDay,
  3366. IsCheckTeam: p.IsCheckTeam,
  3367. HisOrderInfo: models.HisOrderInfo{},
  3368. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3369. IsOut: p.IsOut,
  3370. YbSyncStatus: p.YbSyncStatus,
  3371. }
  3372. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3373. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3374. }
  3375. if nowCount == historyCount {
  3376. if historyCount == 0 {
  3377. recordDateStr := time.Now().Format("2006-01-02")
  3378. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3379. nowtime := recordDate.Unix()
  3380. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3381. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3382. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3383. creater := c.GetAdminUserInfo().AdminUser.Id
  3384. dialyPrepareOne := models.DialysisBeforePrepare{
  3385. GoodTypeId: goodObj.GoodTypeId,
  3386. GoodId: p.ProjectId,
  3387. PatientId: p.PatientId,
  3388. RecordDate: p.RecordDate,
  3389. UserOrgId: adminInfo.CurrentOrgId,
  3390. Count: nowCount,
  3391. Ctime: time.Now().Unix(),
  3392. Creater: creater,
  3393. Status: 1,
  3394. StorehouseId: houseConfig.StorehouseOutInfo,
  3395. ProjectId: p.ID,
  3396. }
  3397. //出库
  3398. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3399. }
  3400. }
  3401. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3402. ////查询历史出库数据
  3403. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3404. //
  3405. //var out_count_five int64
  3406. //for _, item := range flowGood {
  3407. // out_count_five += item.Count
  3408. //}
  3409. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3410. //
  3411. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3412. //if out_count_five != parseIntCount {
  3413. // //查询耗材最后一次出库记录
  3414. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3415. // //查询默认出库仓库库存
  3416. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3417. // if len(wareOut) > 0 {
  3418. //
  3419. // for _, it := range wareOut {
  3420. // //回退库存
  3421. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3422. //
  3423. // //删除出库记录
  3424. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3425. //
  3426. // }
  3427. // }
  3428. //
  3429. // timeStr := time.Now().Format("2006-01-02")
  3430. // timeArr := strings.Split(timeStr, "-")
  3431. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3432. //
  3433. // total = total + 1
  3434. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3435. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3436. // number = number + total
  3437. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3438. //
  3439. // operation_time := time.Now().Unix()
  3440. // creater := c.GetAdminUserInfo().AdminUser.Id
  3441. //
  3442. // recordDateStr := time.Now().Format("2006-01-02")
  3443. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3444. // nowtime := recordDate.Unix()
  3445. // warehouseOut := models.WarehouseOut{
  3446. // WarehouseOutOrderNumber: warehousing_out_order,
  3447. // OperationTime: operation_time,
  3448. // OrgId: adminInfo.CurrentOrgId,
  3449. // Creater: creater,
  3450. // Ctime: time.Now().Unix(),
  3451. // Status: 1,
  3452. // WarehouseOutTime: nowtime,
  3453. // Type: 1,
  3454. // StorehouseId: storeConfig.StorehouseOutInfo,
  3455. // IsCheck: 1,
  3456. // IsSys: 1,
  3457. // }
  3458. // //查询是否生成出库单
  3459. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3460. // if out.ID == 0 {
  3461. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3462. // }
  3463. //
  3464. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3465. //
  3466. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3467. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3468. //
  3469. // dialyPrepareOne := models.DialysisBeforePrepare{
  3470. // GoodTypeId: goodObj.GoodTypeId,
  3471. // GoodId: p.ProjectId,
  3472. // PatientId: p.PatientId,
  3473. // RecordDate: p.RecordDate,
  3474. // UserOrgId: adminInfo.CurrentOrgId,
  3475. // Count: parseIntCount,
  3476. // Ctime: time.Now().Unix(),
  3477. // Creater: creater,
  3478. // Status: 1,
  3479. // StorehouseId: houseConfig.StorehouseOutInfo,
  3480. // ProjectId: lastHisProject.ID,
  3481. // }
  3482. // //判断是否是零用耗材(非零用)
  3483. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3484. //
  3485. // //查询历史出库数据
  3486. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3487. // var out_count int64
  3488. // for _, item := range flowGood {
  3489. // out_count += item.Count
  3490. // }
  3491. // //如果历史数和当前数据不想等才进行退库出库
  3492. // if out_count != parseIntCount {
  3493. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3494. //
  3495. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3496. // detail := models.AutomaticReduceDetail{
  3497. // WarehouseOutId: 0,
  3498. // WarehouseOutOrderNumber: "",
  3499. // PatientId: p.PatientId,
  3500. // Ctime: time.Now().Unix(),
  3501. // Mtime: 0,
  3502. // Status: 1,
  3503. // RecordTime: p.RecordDate,
  3504. // OrgId: p.UserOrgId,
  3505. // GoodId: p.ProjectId,
  3506. // GoodTypeId: 0,
  3507. // Count: parseIntCount,
  3508. // Type: 0,
  3509. // ProjectId: lastHisProject.ID,
  3510. // StorehouseId: 0,
  3511. // }
  3512. //
  3513. // service.CreateNewAutoDetail(detail, tx)
  3514. //
  3515. // //查询剩余库存
  3516. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3517. // var sum_count int64
  3518. // for _, item := range goodList {
  3519. // sum_count += item.StockCount
  3520. // }
  3521. //
  3522. // //更新剩余库存
  3523. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3524. //
  3525. // //耗材
  3526. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3527. //
  3528. // }
  3529. // //判断是否是零用耗材(零用但是是出库耗材)
  3530. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3531. //
  3532. // //查询历史出库数据
  3533. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3534. // var out_count int64
  3535. // for _, item := range flowGood {
  3536. // out_count += item.Count
  3537. // }
  3538. // //如果历史数和当前数据不想等才进行退库出库
  3539. // if out_count != parseIntCount {
  3540. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3541. //
  3542. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3543. // detail := models.AutomaticReduceDetail{
  3544. // WarehouseOutId: 0,
  3545. // WarehouseOutOrderNumber: "",
  3546. // PatientId: p.PatientId,
  3547. // Ctime: time.Now().Unix(),
  3548. // Mtime: 0,
  3549. // Status: 1,
  3550. // RecordTime: p.RecordDate,
  3551. // OrgId: p.UserOrgId,
  3552. // GoodId: p.ProjectId,
  3553. // GoodTypeId: 0,
  3554. // Count: parseIntCount,
  3555. // Type: 0,
  3556. // ProjectId: p.ID,
  3557. // StorehouseId: 0,
  3558. // }
  3559. //
  3560. // service.CreateNewAutoDetail(detail, tx)
  3561. //
  3562. // //查询剩余库存
  3563. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3564. // var sum_count int64
  3565. // for _, item := range goodList {
  3566. // sum_count += item.StockCount
  3567. // }
  3568. //
  3569. // //更新剩余库存
  3570. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3571. //
  3572. // //耗材
  3573. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3574. // }
  3575. //
  3576. // }
  3577. //
  3578. // }
  3579. //
  3580. //}
  3581. //记录日志
  3582. byterequest, _ := json.Marshal(p)
  3583. adviceLog := models.XtDoctorAdviceLog{
  3584. UserOrgId: p.UserOrgId,
  3585. PatientId: p.PatientId,
  3586. AdminUserId: adminInfo.AdminUser.Id,
  3587. Module: 1,
  3588. ErrLog: string(byterequest),
  3589. Status: 1,
  3590. Ctime: time.Now().Unix(),
  3591. Mtime: 0,
  3592. Source: "电脑端新建his项目",
  3593. RecordDate: p.RecordDate,
  3594. }
  3595. service.CreateDoctorAdviceLog(adviceLog)
  3596. projectList = append(projectList, p)
  3597. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3598. //新增或者编辑项目,修改对应的标签数据
  3599. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3600. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3601. var label models.HisLabelPrintInfo
  3602. project, _ := service.GetProjectDetail(p.ProjectId)
  3603. if project.CostClassify == 3 { //类别为检验检查
  3604. if p.TeamId > 0 { //检验检查组套
  3605. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3606. if tempLabel.ID == 0 {
  3607. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3608. label.Number = tempPrescription.PrescriptionNumber
  3609. label.ProjectId = project.ID
  3610. label.Status = 1
  3611. label.IsPrint = 2
  3612. label.DoctorId = info.DoctorId
  3613. label.UserOrgId = p.UserOrgId
  3614. label.PatientId = patient_id
  3615. label.RecordDate = recordDateTime
  3616. label.Ctime = time.Now().Unix()
  3617. label.Mtime = time.Now().Unix()
  3618. label.ItemId = p.TeamId
  3619. label.FeedetlSn = p.FeedetlSn
  3620. label.PProjectId = p.ID
  3621. label.ProjectName = team.ProjectTeam
  3622. label.PatientName = patient.Name
  3623. service.CreateNewHisLabelRecord(&label, tx)
  3624. }
  3625. } else { //单条检验检查项目
  3626. label.Number = tempPrescription.PrescriptionNumber
  3627. label.ProjectId = project.ID
  3628. label.Status = 1
  3629. label.DoctorId = info.DoctorId
  3630. label.UserOrgId = p.UserOrgId
  3631. label.PatientId = patient_id
  3632. label.RecordDate = recordDateTime
  3633. label.IsPrint = 2
  3634. label.Ctime = time.Now().Unix()
  3635. label.Mtime = time.Now().Unix()
  3636. label.FeedetlSn = p.FeedetlSn
  3637. label.PProjectId = p.ID
  3638. label.ItemId = p.TeamId
  3639. label.ProjectName = project.ProjectName
  3640. label.PatientName = patient.Name
  3641. service.CreateNewHisLabelRecord(&label, tx)
  3642. }
  3643. }
  3644. }
  3645. }
  3646. }
  3647. }
  3648. }
  3649. service.CreateNewHisProjectTwo(&p, tx)
  3650. var randNum int
  3651. randNum = rand.Intn(10000) + 1000
  3652. timestamp := time.Now().Unix()
  3653. tempTime := time.Unix(timestamp, 0)
  3654. timeFormat := tempTime.Format("20060102150405")
  3655. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3656. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3657. if goodBase.ID > 0 {
  3658. tx.Rollback()
  3659. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3660. return
  3661. }
  3662. service.CreateNewHisProjectTwo(&p, tx)
  3663. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3664. //查询剩余库存
  3665. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3666. var sum_count int64
  3667. for _, item := range goodList {
  3668. sum_count += item.StockCount
  3669. }
  3670. //更新剩余库存
  3671. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3672. //耗材
  3673. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3674. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3675. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3676. if len(outInfoTwo) > 0 {
  3677. for _, item := range outInfoTwo {
  3678. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3679. }
  3680. }
  3681. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3682. if len(drugAutoDetail) > 0 {
  3683. for _, item := range drugAutoDetail {
  3684. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3685. }
  3686. }
  3687. tx.Commit()
  3688. }
  3689. }
  3690. }
  3691. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3692. // addition := items["addition"].([]interface{})
  3693. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3694. // ctime := time.Now().Unix()
  3695. // mtime := ctime
  3696. // if len(addition) > 0 {
  3697. // for _, item := range addition {
  3698. // var s models.HisAdditionalCharge
  3699. // s.PrescriptionId = tempPrescription.ID
  3700. // s.Status = 1
  3701. // s.UserOrgId = adminInfo.CurrentOrgId
  3702. // s.RecordDate = recordDateTime
  3703. // s.CreatedTime = ctime
  3704. // s.UpdatedTime = mtime
  3705. // s.PatientId = patient_id
  3706. // s.HisPatientId = his_patient_id
  3707. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3708. // if errcode > 0 {
  3709. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3710. // return
  3711. // }
  3712. // service.CreateAdditionalCharge(&s)
  3713. // var randNum int
  3714. // randNum = rand.Intn(10000) + 1000
  3715. // timestamp := time.Now().Unix()
  3716. // tempTime := time.Unix(timestamp, 0)
  3717. // timeFormat := tempTime.Format("20060102150405")
  3718. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3719. // service.CreateAdditionalCharge(&s)
  3720. //
  3721. // }
  3722. // }
  3723. //}
  3724. }
  3725. }
  3726. }
  3727. tx.Commit()
  3728. if err == nil {
  3729. c.ServeSuccessJSON(map[string]interface{}{
  3730. "msg": "保存成功",
  3731. })
  3732. return
  3733. } else {
  3734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3735. return
  3736. }
  3737. } else {
  3738. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3739. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3740. var tempPrescription *models.HisPrescription
  3741. if len(prescriptions) > 0 {
  3742. for _, item := range prescriptions {
  3743. items := item.(map[string]interface{})
  3744. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3745. utils.ErrorLog("id")
  3746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3747. return
  3748. }
  3749. id := int64(items["id"].(float64))
  3750. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3751. tempPrescription = &new_prescription
  3752. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3753. utils.ErrorLog("type")
  3754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3755. return
  3756. }
  3757. types := int64(items["type"].(float64))
  3758. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3759. utils.ErrorLog("med_type")
  3760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3764. if med_type == "0" {
  3765. med_type = "14"
  3766. }
  3767. //if order_status == 0 {
  3768. // order_status = 1
  3769. //}
  3770. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3771. utils.ErrorLog("pre_time")
  3772. }
  3773. preTime, _ := items["pre_time"].(string)
  3774. timeLayout := "2006-01-02"
  3775. loc, _ := time.LoadLocation("Local")
  3776. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3777. result := strings.Split(preTime, " ")
  3778. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3779. if err != nil {
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3781. return
  3782. }
  3783. pTime := theTime2.Unix()
  3784. ctime := time.Now().Unix()
  3785. if tempPrescription.ID == 0 {
  3786. prescription := &models.HisPrescription{
  3787. ID: 0,
  3788. PatientId: patient_id,
  3789. UserOrgId: adminInfo.CurrentOrgId,
  3790. RecordDate: recordDateTime,
  3791. Ctime: ctime,
  3792. Mtime: ctime,
  3793. Type: types,
  3794. Modifier: adminInfo.AdminUser.Id,
  3795. Creator: adminInfo.AdminUser.Id,
  3796. Status: 1,
  3797. Doctor: role.UserName,
  3798. HisPatientId: his_patient_id,
  3799. OrderStatus: 1,
  3800. BatchNumber: "",
  3801. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3802. PreTime: pTime,
  3803. PType: p_type,
  3804. MedType: med_type,
  3805. }
  3806. tempPrescription = prescription
  3807. service.SaveHisPrescription(tempPrescription)
  3808. redis := service.RedisClient()
  3809. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3810. redis.Set(key, "", time.Second)
  3811. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3812. redis.Set(keyOne, "", time.Second)
  3813. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3814. redis.Set(keySeven, "", time.Second)
  3815. defer redis.Close()
  3816. } else {
  3817. tempPrescription.ID = id
  3818. tempPrescription.Type = types
  3819. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3820. tempPrescription.Mtime = time.Now().Unix()
  3821. tempPrescription.Doctor = role.UserName
  3822. //tempPrescription.OrderStatus = order_status
  3823. tempPrescription.PreTime = pTime
  3824. tempPrescription.MedType = med_type
  3825. service.SaveHisPrescription(tempPrescription)
  3826. redis := service.RedisClient()
  3827. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3828. redis.Set(key, "", time.Second)
  3829. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3830. redis.Set(keyOne, "", time.Second)
  3831. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3832. redis.Set(keySeven, "", time.Second)
  3833. defer redis.Close()
  3834. }
  3835. //service.SaveHisPrescription(prescription)
  3836. //更改患者挂号状态
  3837. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3838. fmt.Println("更改失败", err2)
  3839. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3840. advices := items["advices"].([]interface{})
  3841. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3842. groupNo := int64(0)
  3843. if len(advices) > 0 {
  3844. for _, advice := range advices {
  3845. var s models.HisDoctorAdviceInfo
  3846. s.PrescriptionId = tempPrescription.ID
  3847. s.AdviceType = 2
  3848. s.AdviceDoctor = doctor_id
  3849. s.StopState = 2
  3850. s.ExecutionState = 2
  3851. s.AdviceDate = theTime3.Unix()
  3852. s.Status = 1
  3853. s.UserOrgId = adminInfo.CurrentOrgId
  3854. s.RecordDate = theTime3.Unix()
  3855. s.StartTime = tempPrescription.PreTime
  3856. s.Groupno = groupNo
  3857. s.PatientId = patient_id
  3858. s.HisPatientId = his_patient_id
  3859. s.StartTime = pTime
  3860. s.IsSettle = 2
  3861. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3862. if errcode > 0 {
  3863. c.ServeFailJSONWithSGJErrorCode(errcode)
  3864. return
  3865. }
  3866. s.StartTime = pTime
  3867. var total_count int64 //处方总库存
  3868. //查询改药品信息
  3869. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3870. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3871. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3872. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3873. total_count += prescribingNumberSeven * medical.MinNumber
  3874. }
  3875. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3876. total_count += prescribingNumberSeven
  3877. }
  3878. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3879. total_count += prescribingNumberSeven
  3880. }
  3881. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3882. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3883. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3884. if s.Price != lastWarehouse.RetailPrice {
  3885. s.Price = lastWarehouse.RetailPrice
  3886. }
  3887. if s.Price == 0 {
  3888. if lastWarehouse.ID == 0 {
  3889. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3890. s.Price = lastWarehouseTwo.RetailPrice
  3891. }
  3892. }
  3893. }
  3894. service.CreateHisDoctorAdvice(&s)
  3895. //记录日志
  3896. byterequest, _ := json.Marshal(s)
  3897. adviceLog := models.XtDoctorAdviceLog{
  3898. UserOrgId: s.UserOrgId,
  3899. PatientId: s.PatientId,
  3900. AdminUserId: adminInfo.AdminUser.Id,
  3901. Module: 1,
  3902. ErrLog: string(byterequest),
  3903. Status: 1,
  3904. Ctime: time.Now().Unix(),
  3905. Mtime: 0,
  3906. Source: "电脑端新建his医嘱",
  3907. RecordDate: s.AdviceDate,
  3908. }
  3909. service.CreateDoctorAdviceLog(adviceLog)
  3910. //存储切片中
  3911. adviceList = append(adviceList, s)
  3912. redis := service.RedisClient()
  3913. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3914. redis.Set(key, "", time.Second)
  3915. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3916. redis.Set(keyOne, "", time.Second)
  3917. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3918. redis.Set(keySeven, "", time.Second)
  3919. var randNum int
  3920. randNum = rand.Intn(10000) + 1000
  3921. timestamp := time.Now().Unix()
  3922. tempTime := time.Unix(timestamp, 0)
  3923. timeFormat := tempTime.Format("20060102150405")
  3924. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3925. service.CreateHisDoctorAdvice(&s)
  3926. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3927. redis.Set(keySix, "", time.Second)
  3928. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3929. redis.Set(keyFive, "", time.Second)
  3930. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3931. redis.Set(keyEight, "", time.Second)
  3932. defer redis.Close()
  3933. }
  3934. }
  3935. }
  3936. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3937. projects := items["project"].([]interface{})
  3938. if len(projects) > 0 {
  3939. for _, project := range projects {
  3940. var p models.HisPrescriptionProject
  3941. p.PrescriptionId = tempPrescription.ID
  3942. p.PatientId = patient_id
  3943. p.RecordDate = theTime3.Unix()
  3944. p.Doctor = doctor_id
  3945. p.UserOrgId = adminInfo.CurrentOrgId
  3946. p.HisPatientId = his_patient_id
  3947. p.Status = 1
  3948. p.StartTime = pTime
  3949. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3950. if errcode > 0 {
  3951. c.ServeFailJSONWithSGJErrorCode(errcode)
  3952. return
  3953. }
  3954. if p.ID == 0 {
  3955. p.IsOut = 2
  3956. }
  3957. if p.ID > 0 {
  3958. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3959. p.IsOut = projectDetail.IsOut
  3960. }
  3961. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3962. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3963. if p.Type == 3 {
  3964. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3965. if p.Price != lastWarehouse.PackingPrice {
  3966. p.Price = lastWarehouse.PackingPrice
  3967. }
  3968. if p.Price == 0 {
  3969. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3970. p.Price = lastWarehouseTwo.PackingPrice
  3971. }
  3972. if p.Unit == "" {
  3973. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3974. p.Unit = goodInfoOne.PackingUnit
  3975. }
  3976. }
  3977. }
  3978. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3979. //
  3980. // if p.Type == 3 {
  3981. // //查询该耗材是否停用
  3982. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3983. // //表示该耗材已经停用,不能保存
  3984. // if goodInfoSeven.ID == 0 {
  3985. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3986. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3987. // return
  3988. // }
  3989. // }
  3990. //
  3991. //}
  3992. service.CreateHisProjectTwo(&p)
  3993. //记录日志
  3994. byterequest, _ := json.Marshal(p)
  3995. adviceLog := models.XtDoctorAdviceLog{
  3996. UserOrgId: p.UserOrgId,
  3997. PatientId: p.PatientId,
  3998. AdminUserId: adminInfo.AdminUser.Id,
  3999. Module: 1,
  4000. ErrLog: string(byterequest),
  4001. Status: 1,
  4002. Ctime: time.Now().Unix(),
  4003. Mtime: 0,
  4004. Source: "电脑端新建his项目",
  4005. RecordDate: p.RecordDate,
  4006. }
  4007. service.CreateDoctorAdviceLog(adviceLog)
  4008. projectList = append(projectList, p)
  4009. var randNum int
  4010. randNum = rand.Intn(10000) + 1000
  4011. timestamp := time.Now().Unix()
  4012. tempTime := time.Unix(timestamp, 0)
  4013. timeFormat := tempTime.Format("20060102150405")
  4014. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4015. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4016. //新增或者编辑项目,修改对应的标签数据
  4017. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4018. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4019. var label models.HisLabelPrintInfo
  4020. project, _ := service.GetProjectDetail(p.ProjectId)
  4021. if project.CostClassify == 3 { //类别为检验检查
  4022. if p.TeamId > 0 { //检验检查组套
  4023. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4024. if tempLabel.ID == 0 {
  4025. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4026. label.Number = tempPrescription.PrescriptionNumber
  4027. label.ProjectId = project.ID
  4028. label.Status = 1
  4029. label.IsPrint = 2
  4030. label.DoctorId = info.DoctorId
  4031. label.UserOrgId = p.UserOrgId
  4032. label.PatientId = patient_id
  4033. label.RecordDate = recordDateTime
  4034. label.Ctime = time.Now().Unix()
  4035. label.Mtime = time.Now().Unix()
  4036. label.ItemId = p.TeamId
  4037. label.FeedetlSn = p.FeedetlSn
  4038. label.PProjectId = p.ID
  4039. label.ProjectName = team.ProjectTeam
  4040. label.PatientName = patient.Name
  4041. service.CreateHisLabelRecord(&label)
  4042. }
  4043. } else { //单条检验检查项目
  4044. label.Number = tempPrescription.PrescriptionNumber
  4045. label.ProjectId = project.ID
  4046. label.Status = 1
  4047. label.DoctorId = info.DoctorId
  4048. label.UserOrgId = p.UserOrgId
  4049. label.PatientId = patient_id
  4050. label.RecordDate = recordDateTime
  4051. label.IsPrint = 2
  4052. label.Ctime = time.Now().Unix()
  4053. label.Mtime = time.Now().Unix()
  4054. label.FeedetlSn = p.FeedetlSn
  4055. label.PProjectId = p.ID
  4056. label.ItemId = p.TeamId
  4057. label.ProjectName = project.ProjectName
  4058. label.PatientName = patient.Name
  4059. service.CreateHisLabelRecord(&label)
  4060. }
  4061. }
  4062. }
  4063. }
  4064. service.SaveHisProjectTwo(&p)
  4065. }
  4066. }
  4067. }
  4068. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4069. // addition := items["addition"].([]interface{})
  4070. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4071. // ctime := time.Now().Unix()
  4072. // mtime := ctime
  4073. // if len(addition) > 0 {
  4074. // for _, item := range addition {
  4075. // var s models.HisAdditionalCharge
  4076. // s.PrescriptionId = tempPrescription.ID
  4077. // s.Status = 1
  4078. // s.UserOrgId = adminInfo.CurrentOrgId
  4079. // s.RecordDate = recordDateTime
  4080. // s.CreatedTime = ctime
  4081. // s.UpdatedTime = mtime
  4082. // s.PatientId = patient_id
  4083. // s.HisPatientId = his_patient_id
  4084. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4085. // if errcode > 0 {
  4086. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4087. // return
  4088. // }
  4089. // service.CreateAdditionalCharge(&s)
  4090. // var randNum int
  4091. // randNum = rand.Intn(10000) + 1000
  4092. // timestamp := time.Now().Unix()
  4093. // tempTime := time.Unix(timestamp, 0)
  4094. // timeFormat := tempTime.Format("20060102150405")
  4095. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4096. // service.CreateAdditionalCharge(&s)
  4097. //
  4098. // }
  4099. // }
  4100. //}
  4101. }
  4102. }
  4103. //查询今日该患者开的药品处方
  4104. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4105. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4106. //药品出库
  4107. if drugOutConfig.IsOpen == 1 {
  4108. for _, item := range hisdoctorlist {
  4109. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4110. // 查询该药品最后一次出库记录
  4111. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4112. if len(druginfo) > 0 {
  4113. //回退库存
  4114. for _, it := range druginfo {
  4115. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4116. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4117. }
  4118. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4119. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4120. }
  4121. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4122. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4123. }
  4124. }
  4125. }
  4126. //删除记录
  4127. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4128. //查询最后一次数据
  4129. if drugOutConfig.IsOpen == 1 {
  4130. //出库
  4131. if drug.IsUse == 2 {
  4132. creater := adminInfo.AdminUser.Id
  4133. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4134. }
  4135. //更新字典里面的库存
  4136. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4137. var sum_count int64
  4138. for _, its := range stockInfo {
  4139. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4140. if its.MaxUnit == baseDrug.MaxUnit {
  4141. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4142. }
  4143. sum_count += its.StockMaxNumber + its.StockMinNumber
  4144. }
  4145. //更新基础库存
  4146. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4147. //剩余库存
  4148. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4149. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4150. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4151. }
  4152. }
  4153. }
  4154. //耗材保存处方出库
  4155. if goodOutConfig.IsOpen == 1 {
  4156. //查询今日耗材出库数量
  4157. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4158. for _, item := range hisgoodlist {
  4159. //查询历史出库数据
  4160. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4161. var out_count_five int64
  4162. for _, item := range flowGood {
  4163. out_count_five += item.Count
  4164. }
  4165. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4166. if out_count_five != parseIntCount {
  4167. //查询耗材最后一次出库记录
  4168. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4169. //查询默认出库仓库库存
  4170. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4171. if len(wareOut) > 0 {
  4172. for _, it := range wareOut {
  4173. //回退库存
  4174. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4175. //删除出库记录
  4176. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4177. }
  4178. }
  4179. timeStr := time.Now().Format("2006-01-02")
  4180. timeArr := strings.Split(timeStr, "-")
  4181. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4182. total = total + 1
  4183. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4184. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4185. number = number + total
  4186. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4187. operation_time := time.Now().Unix()
  4188. creater := c.GetAdminUserInfo().AdminUser.Id
  4189. recordDateStr := time.Now().Format("2006-01-02")
  4190. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4191. nowtime := recordDate.Unix()
  4192. warehouseOut := models.WarehouseOut{
  4193. WarehouseOutOrderNumber: warehousing_out_order,
  4194. OperationTime: operation_time,
  4195. OrgId: adminInfo.CurrentOrgId,
  4196. Creater: creater,
  4197. Ctime: time.Now().Unix(),
  4198. Status: 1,
  4199. WarehouseOutTime: nowtime,
  4200. Type: 1,
  4201. StorehouseId: storeConfig.StorehouseOutInfo,
  4202. IsCheck: 1,
  4203. IsSys: 1,
  4204. }
  4205. //查询是否生成出库单
  4206. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4207. if out.ID == 0 {
  4208. service.AddSigleWarehouseOut(&warehouseOut)
  4209. }
  4210. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4211. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4212. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4213. dialyPrepareOne := models.DialysisBeforePrepare{
  4214. GoodTypeId: goodObj.GoodTypeId,
  4215. GoodId: item.ProjectId,
  4216. PatientId: item.PatientId,
  4217. RecordDate: item.RecordDate,
  4218. UserOrgId: adminInfo.CurrentOrgId,
  4219. Count: parseIntCount,
  4220. Ctime: time.Now().Unix(),
  4221. Creater: creater,
  4222. Status: 1,
  4223. StorehouseId: houseConfig.StorehouseOutInfo,
  4224. ProjectId: item.ID,
  4225. }
  4226. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4227. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4228. //查询历史出库数据
  4229. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4230. var out_count int64
  4231. for _, item := range flowGood {
  4232. out_count += item.Count
  4233. }
  4234. //如果历史数和当前数据不想等才进行退库出库
  4235. if out_count != parseIntCount {
  4236. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4237. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4238. detail := models.AutomaticReduceDetail{
  4239. WarehouseOutId: 0,
  4240. WarehouseOutOrderNumber: "",
  4241. PatientId: item.PatientId,
  4242. Ctime: time.Now().Unix(),
  4243. Mtime: 0,
  4244. Status: 1,
  4245. RecordTime: item.RecordDate,
  4246. OrgId: item.UserOrgId,
  4247. GoodId: item.ProjectId,
  4248. GoodTypeId: 0,
  4249. Count: parseIntCount,
  4250. Type: 0,
  4251. ProjectId: item.ID,
  4252. StorehouseId: 0,
  4253. }
  4254. service.CreateAutoDetail(detail)
  4255. //查询剩余库存
  4256. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4257. var sum_count int64
  4258. for _, item := range goodList {
  4259. sum_count += item.StockCount
  4260. }
  4261. //更新剩余库存
  4262. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4263. //耗材
  4264. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4265. }
  4266. }
  4267. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4268. //查询历史出库数据
  4269. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4270. var out_count int64
  4271. for _, item := range flowGood {
  4272. out_count += item.Count
  4273. }
  4274. //如果历史数和当前数据不想等才进行退库出库
  4275. if out_count != parseIntCount {
  4276. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4277. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4278. detail := models.AutomaticReduceDetail{
  4279. WarehouseOutId: 0,
  4280. WarehouseOutOrderNumber: "",
  4281. PatientId: item.PatientId,
  4282. Ctime: time.Now().Unix(),
  4283. Mtime: 0,
  4284. Status: 1,
  4285. RecordTime: item.RecordDate,
  4286. OrgId: item.UserOrgId,
  4287. GoodId: item.ProjectId,
  4288. GoodTypeId: 0,
  4289. Count: parseIntCount,
  4290. Type: 0,
  4291. ProjectId: item.ID,
  4292. StorehouseId: 0,
  4293. }
  4294. service.CreateAutoDetail(detail)
  4295. //查询剩余库存
  4296. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4297. var sum_count int64
  4298. for _, item := range goodList {
  4299. sum_count += item.StockCount
  4300. }
  4301. //更新剩余库存
  4302. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4303. //耗材
  4304. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4305. }
  4306. }
  4307. }
  4308. }
  4309. }
  4310. }
  4311. tx.Commit()
  4312. if err == nil {
  4313. c.ServeSuccessJSON(map[string]interface{}{
  4314. "msg": "保存成功",
  4315. })
  4316. return
  4317. } else {
  4318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4319. return
  4320. }
  4321. }
  4322. }
  4323. //func (c *HisApiController) EditHisPrescription() {
  4324. // record_date := c.GetString("record_date")
  4325. // patient_id, _ := c.GetInt64("patient_id")
  4326. // reg_type, _ := c.GetInt64("reg_type")
  4327. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4328. // diagnose := c.GetString("diagnose")
  4329. // sick_type, _ := c.GetInt64("sick_type")
  4330. // sick_history := c.GetString("sick_history")
  4331. // doctor_id, _ := c.GetInt64("doctor", 0)
  4332. // department, _ := c.GetInt64("department", 0)
  4333. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4334. // p_type, _ := c.GetInt64("p_type")
  4335. //
  4336. // dataBody := make(map[string]interface{}, 0)
  4337. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4338. // if err != nil {
  4339. // utils.ErrorLog(err.Error())
  4340. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4341. // return
  4342. // }
  4343. //
  4344. // timeLayout := "2006-01-02"
  4345. // loc, _ := time.LoadLocation("Local")
  4346. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4347. // if err != nil {
  4348. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4349. // return
  4350. // }
  4351. // adminInfo := c.GetAdminUserInfo()
  4352. // recordDateTime := theTime.Unix()
  4353. //
  4354. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4355. //
  4356. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4357. // var hpInfo models.HisPrescriptionInfo
  4358. // if info.ID == 0 {
  4359. // var randNum int
  4360. // randNum = rand.Intn(10000) + 1000
  4361. // timestamp := time.Now().Unix()
  4362. // tempTime := time.Unix(timestamp, 0)
  4363. // timeFormat := tempTime.Format("20060102150405")
  4364. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4365. //
  4366. // hpInfo = models.HisPrescriptionInfo{
  4367. // UserOrgId: adminInfo.CurrentOrgId,
  4368. // RecordDate: theTime.Unix(),
  4369. // PatientId: patient_id,
  4370. // Status: 1,
  4371. // Ctime: time.Now().Unix(),
  4372. // Mtime: time.Now().Unix(),
  4373. // Creator: adminInfo.AdminUser.Id,
  4374. // Modifier: adminInfo.AdminUser.Id,
  4375. // Diagnosis: diagnose,
  4376. // SickHistory: sick_history,
  4377. // Departments: department,
  4378. // RegisterType: reg_type,
  4379. // PrescriptionNumber: p_number,
  4380. // PrescriptionStatus: 1,
  4381. // Doctor: role.UserName,
  4382. // DoctorId: doctor_id,
  4383. // SickType: sick_type,
  4384. // PType: p_type,
  4385. // }
  4386. // service.SavePatientPrescriptionInfo(hpInfo)
  4387. //
  4388. // } else {
  4389. // hpInfo = models.HisPrescriptionInfo{
  4390. // ID: info.ID,
  4391. // UserOrgId: adminInfo.CurrentOrgId,
  4392. // RecordDate: info.RecordDate,
  4393. // PatientId: info.PatientId,
  4394. // Status: 1,
  4395. // Ctime: info.Ctime,
  4396. // Mtime: time.Now().Unix(),
  4397. // Creator: info.Creator,
  4398. // Modifier: adminInfo.AdminUser.Id,
  4399. // Diagnosis: diagnose,
  4400. // SickHistory: sick_history,
  4401. // Departments: department,
  4402. // RegisterType: reg_type,
  4403. // PrescriptionNumber: info.PrescriptionNumber,
  4404. // Doctor: role.UserName,
  4405. // PrescriptionStatus: info.PrescriptionStatus,
  4406. // DoctorId: doctor_id,
  4407. // SickType: sick_type,
  4408. // PType: info.PType,
  4409. // }
  4410. // service.SavePatientPrescriptionInfo(hpInfo)
  4411. // }
  4412. //
  4413. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4414. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4415. //
  4416. // if len(prescriptions) > 0 {
  4417. // for _, item := range prescriptions {
  4418. // items := item.(map[string]interface{})
  4419. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4420. // utils.ErrorLog("id")
  4421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4422. // return
  4423. // }
  4424. // id := int64(items["id"].(float64))
  4425. //
  4426. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4427. // utils.ErrorLog("type")
  4428. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4429. // return
  4430. // }
  4431. // types := int64(items["type"].(float64))
  4432. //
  4433. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4434. // utils.ErrorLog("med_type")
  4435. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4436. // return
  4437. // }
  4438. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4439. //
  4440. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4441. //
  4442. // ctime := time.Now().Unix()
  4443. //
  4444. // prescription := &models.HisPrescription{
  4445. // ID: id,
  4446. // PatientId: patient_id,
  4447. // UserOrgId: adminInfo.CurrentOrgId,
  4448. // RecordDate: recordDateTime,
  4449. // Ctime: ctime,
  4450. // Mtime: ctime,
  4451. // Type: types,
  4452. // Modifier: adminInfo.AdminUser.Id,
  4453. // Creator: adminInfo.AdminUser.Id,
  4454. // Status: 1,
  4455. // Doctor: role.UserName,
  4456. // HisPatientId: his_patient_id,
  4457. // OrderStatus: 1,
  4458. // BatchNumber: "",
  4459. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4460. // PType: hpInfo.PType,
  4461. // MedType: med_type,
  4462. // }
  4463. //
  4464. // if historyPrescription.ID > 0 {
  4465. // prescription.PreTime = historyPrescription.PreTime
  4466. //
  4467. // }
  4468. //
  4469. // service.SaveHisPrescription(prescription)
  4470. //
  4471. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4472. // advices := items["advices"].([]interface{})
  4473. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4474. // groupNo := int64(0)
  4475. // ctime := time.Now().Unix()
  4476. // mtime := ctime
  4477. // if len(advices) > 0 {
  4478. // for _, advice := range advices {
  4479. // var s models.HisDoctorAdviceInfo
  4480. // s.PrescriptionId = prescription.ID
  4481. // s.AdviceType = 2
  4482. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4483. // s.StopState = 2
  4484. // s.ExecutionState = 2
  4485. // s.AdviceDate = recordDateTime
  4486. // s.Status = 1
  4487. // s.UserOrgId = adminInfo.CurrentOrgId
  4488. // s.RecordDate = recordDateTime
  4489. // s.StartTime = prescription.PreTime
  4490. // s.Groupno = groupNo
  4491. // s.CreatedTime = ctime
  4492. // s.UpdatedTime = mtime
  4493. // s.PatientId = patient_id
  4494. // s.HisPatientId = his_patient_id
  4495. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4496. // if errcode > 0 {
  4497. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4498. // return
  4499. // }
  4500. //
  4501. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4502. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4503. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4504. // if s.Price == 0 {
  4505. // s.Price = lastWarehouse.RetailPrice
  4506. // }
  4507. // }
  4508. //
  4509. // service.CreateHisDoctorAdvice(&s)
  4510. // //记录日志
  4511. // byterequest, _ := json.Marshal(s)
  4512. // adviceLog := models.XtDoctorAdviceLog{
  4513. // UserOrgId: s.UserOrgId,
  4514. // PatientId: s.PatientId,
  4515. // AdminUserId: adminInfo.AdminUser.Id,
  4516. // Module: 1,
  4517. // ErrLog: string(byterequest),
  4518. // Status: 1,
  4519. // Ctime: time.Now().Unix(),
  4520. // Mtime: 0,
  4521. // Source: "电脑端his医嘱修改",
  4522. // RecordDate: s.AdviceDate,
  4523. // }
  4524. // service.CreateDoctorAdviceLog(adviceLog)
  4525. // redis := service.RedisClient()
  4526. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4527. // redis.Set(key, "", time.Second)
  4528. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4529. // fmt.Println("keyOne", keyOne)
  4530. // redis.Set(keyOne, "", time.Second)
  4531. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4532. // redis.Set(keySeven, "", time.Second)
  4533. // redis.Close()
  4534. //
  4535. // }
  4536. // }
  4537. // }
  4538. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4539. // projects := items["project"].([]interface{})
  4540. // if len(projects) > 0 {
  4541. // for _, project := range projects {
  4542. // var p models.HisPrescriptionProject
  4543. // p.PrescriptionId = prescription.ID
  4544. // p.Ctime = time.Now().Unix()
  4545. // p.Mtime = time.Now().Unix()
  4546. // p.PatientId = patient_id
  4547. // p.RecordDate = recordDateTime
  4548. // p.UserOrgId = adminInfo.CurrentOrgId
  4549. // p.HisPatientId = his_patient_id
  4550. // p.Status = 1
  4551. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4552. // if errcode > 0 {
  4553. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4554. // return
  4555. // }
  4556. // service.CreateHisProjectTwo(&p)
  4557. //
  4558. // //记录日志
  4559. // byterequest, _ := json.Marshal(p)
  4560. // adviceLog := models.XtDoctorAdviceLog{
  4561. // UserOrgId: p.UserOrgId,
  4562. // PatientId: p.PatientId,
  4563. // AdminUserId: adminInfo.AdminUser.Id,
  4564. // Module: 1,
  4565. // ErrLog: string(byterequest),
  4566. // Status: 1,
  4567. // Ctime: time.Now().Unix(),
  4568. // Mtime: 0,
  4569. // Source: "电脑端his项目修改",
  4570. // RecordDate: p.RecordDate,
  4571. // }
  4572. // service.CreateDoctorAdviceLog(adviceLog)
  4573. // }
  4574. // }
  4575. // }
  4576. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4577. // addition := items["addition"].([]interface{})
  4578. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4579. // ctime := time.Now().Unix()
  4580. // mtime := ctime
  4581. // if len(addition) > 0 {
  4582. // for _, item := range addition {
  4583. // var s models.HisAdditionalCharge
  4584. // s.PrescriptionId = prescription.ID
  4585. // s.Status = 1
  4586. // s.UserOrgId = adminInfo.CurrentOrgId
  4587. // s.RecordDate = recordDateTime
  4588. // s.CreatedTime = ctime
  4589. // s.UpdatedTime = mtime
  4590. // s.PatientId = patient_id
  4591. // s.HisPatientId = his_patient_id
  4592. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4593. // if errcode > 0 {
  4594. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4595. // return
  4596. // }
  4597. // service.CreateAdditionalCharge(&s)
  4598. // }
  4599. // }
  4600. // }
  4601. //
  4602. // }
  4603. // }
  4604. // }
  4605. // if err == nil {
  4606. // c.ServeSuccessJSON(map[string]interface{}{
  4607. // "msg": "保存成功",
  4608. // })
  4609. // return
  4610. //
  4611. // } else {
  4612. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4613. // return
  4614. // }
  4615. //}
  4616. func (c *HisApiController) DeletePrescription() {
  4617. prescription_id, _ := c.GetInt64("id")
  4618. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4619. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4620. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4621. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4622. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4623. //耗材保存处方出库
  4624. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4625. //已收费和已发药限制逻辑
  4626. isCharge := false
  4627. isMedicine := false
  4628. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4629. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4630. //for _, item := range new_prescriptions {
  4631. if new_prescription.IsMedicine == 1 {
  4632. isMedicine = true
  4633. }
  4634. //}
  4635. for _, item := range new_prescriptions {
  4636. if item.OrderStatus == 4 {
  4637. isCharge = true
  4638. }
  4639. }
  4640. if p_err != nil {
  4641. if new_prescription.ID > 0 {
  4642. if new_prescription.OrderStatus == 2 {
  4643. isCharge = true
  4644. }
  4645. }
  4646. }
  4647. for _, item := range advices {
  4648. if item.IsMedicine == 1 {
  4649. isMedicine = true
  4650. }
  4651. }
  4652. if isCharge {
  4653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4654. return
  4655. }
  4656. if isMedicine {
  4657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4658. return
  4659. }
  4660. //已收费和已发药限制逻辑
  4661. if len(projects) > 0 {
  4662. for _, item := range projects {
  4663. service.DeletePrintInfo(item.ID) //删除打印信息
  4664. if goodOutConfig.IsOpen != 1 {
  4665. if stockConfig.IsOpen == 1 {
  4666. if item.Type == 3 && item.IsOut == 1 {
  4667. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4668. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4669. good.Total = good.Total + f_count
  4670. service.UpdateGoodInfo(&good)
  4671. operation_time := time.Now().Unix()
  4672. creater := c.GetAdminUserInfo().AdminUser.Id
  4673. //创建退库单
  4674. timeStr := time.Now().Format("2006-01-02")
  4675. timeArr := strings.Split(timeStr, "-")
  4676. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4677. total = total + 1
  4678. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4679. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4680. cancelStock := models.CancelStock{
  4681. OrderNumber: orderNumber,
  4682. OperaTime: operation_time,
  4683. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4684. Creater: creater,
  4685. Ctime: time.Now().Unix(),
  4686. Status: 1,
  4687. ReturnTime: item.RecordDate,
  4688. Type: 1,
  4689. StorehouseId: houseConfig.StorehouseOutInfo,
  4690. IsCheck: 1,
  4691. }
  4692. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4693. if msgerrkonde == gorm.ErrRecordNotFound {
  4694. service.AddSigleCancelStock(&cancelStock)
  4695. }
  4696. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4697. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4698. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4699. //查询该耗材是否出库
  4700. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4701. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4702. deaerler, _ := service.GetDealerById(info.Dealer)
  4703. var total_count int64
  4704. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4705. total_count += count
  4706. if info.ID > 0 {
  4707. if info.Count >= total_count {
  4708. //回退库存
  4709. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4710. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4711. var flush_count int64
  4712. for _, it := range goodList {
  4713. flush_count += it.StockCount
  4714. }
  4715. cancelStockInfo := models.CancelStockInfo{
  4716. GoodId: item.ProjectId,
  4717. CancelStockId: cancel.ID,
  4718. GoodTypeId: good.GoodTypeId,
  4719. Count: prescribingNumber,
  4720. Price: info.Price,
  4721. Total: 0,
  4722. ProductDate: info.ProductDate,
  4723. ExpiryDate: info.ExpiryDate,
  4724. Ctime: time.Now().Unix(),
  4725. Status: 1,
  4726. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4727. OrderNumber: cancel.OrderNumber,
  4728. Type: 0,
  4729. Dealer: deaerler.DealerName,
  4730. Manufacturer: manufacturer.ManufacturerName,
  4731. Number: info.Number,
  4732. RegisterAccount: "",
  4733. Remark: "",
  4734. WarehouseInfoId: info.WarehouseInfotId,
  4735. PatientId: info.PatientId,
  4736. RecordDate: info.SysRecordTime,
  4737. StorehouseId: houseConfig.StorehouseOutInfo,
  4738. IsCheck: 1,
  4739. }
  4740. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4741. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4742. flow := models.VmStockFlow{
  4743. WarehousingId: info.WarehouseInfotId,
  4744. GoodId: item.ProjectId,
  4745. Number: info.Number,
  4746. LicenseNumber: info.LicenseNumber,
  4747. Count: prescribingNumber,
  4748. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4749. PatientId: item.PatientId,
  4750. SystemTime: info.SysRecordTime,
  4751. ConsumableType: 7,
  4752. IsSys: 0,
  4753. WarehousingOrder: "",
  4754. WarehouseOutId: info.WarehouseOutId,
  4755. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4756. IsEdit: 0,
  4757. CancelStockId: cancel.ID,
  4758. CancelOrderNumber: cancel.OrderNumber,
  4759. Manufacturer: manufacturer.ID,
  4760. Dealer: 0,
  4761. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4762. UpdateCreator: 0,
  4763. Status: 1,
  4764. Ctime: time.Now().Unix(),
  4765. Mtime: 0,
  4766. Price: info.Price,
  4767. WarehousingDetailId: info.WarehouseInfotId,
  4768. WarehouseOutDetailId: info.ID,
  4769. CancelOutDetailId: cancelInfo.ID,
  4770. ProductDate: info.ProductDate,
  4771. ExpireDate: info.ExpiryDate,
  4772. StorehouseId: houseConfig.StorehouseOutInfo,
  4773. OverCount: flush_count,
  4774. OperateTime: time.Now().Unix(),
  4775. }
  4776. service.CreateStockFlowOne(flow)
  4777. //退库数量增加
  4778. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4779. //出库数量减少
  4780. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4781. }
  4782. if info.Count < total_count {
  4783. //回退库存
  4784. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4785. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4786. var flush_count int64
  4787. for _, it := range goodList {
  4788. flush_count += it.StockCount
  4789. }
  4790. cancelStockInfo := models.CancelStockInfo{
  4791. GoodId: item.ProjectId,
  4792. CancelStockId: cancel.ID,
  4793. GoodTypeId: good.GoodTypeId,
  4794. Count: info.Count,
  4795. Price: info.Price,
  4796. Total: 0,
  4797. ProductDate: info.ProductDate,
  4798. ExpiryDate: info.ExpiryDate,
  4799. Ctime: time.Now().Unix(),
  4800. Status: 1,
  4801. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4802. OrderNumber: cancel.OrderNumber,
  4803. Type: 0,
  4804. Dealer: deaerler.DealerName,
  4805. Manufacturer: manufacturer.ManufacturerName,
  4806. Number: info.Number,
  4807. RegisterAccount: "",
  4808. Remark: "",
  4809. WarehouseInfoId: info.WarehouseInfotId,
  4810. PatientId: info.PatientId,
  4811. RecordDate: info.SysRecordTime,
  4812. StorehouseId: houseConfig.StorehouseOutInfo,
  4813. IsCheck: 1,
  4814. }
  4815. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4816. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4817. flow := models.VmStockFlow{
  4818. WarehousingId: info.WarehouseInfotId,
  4819. GoodId: item.ProjectId,
  4820. Number: info.Number,
  4821. LicenseNumber: info.LicenseNumber,
  4822. Count: info.Count,
  4823. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4824. PatientId: item.PatientId,
  4825. SystemTime: info.SysRecordTime,
  4826. ConsumableType: 7,
  4827. IsSys: 0,
  4828. WarehousingOrder: "",
  4829. WarehouseOutId: info.WarehouseOutId,
  4830. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4831. IsEdit: 0,
  4832. CancelStockId: cancel.ID,
  4833. CancelOrderNumber: cancel.OrderNumber,
  4834. Manufacturer: manufacturer.ID,
  4835. Dealer: 0,
  4836. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4837. UpdateCreator: 0,
  4838. Status: 1,
  4839. Ctime: time.Now().Unix(),
  4840. Mtime: 0,
  4841. Price: info.Price,
  4842. WarehousingDetailId: info.WarehouseInfotId,
  4843. WarehouseOutDetailId: info.ID,
  4844. CancelOutDetailId: cancelInfo.ID,
  4845. ProductDate: info.ProductDate,
  4846. ExpireDate: info.ExpiryDate,
  4847. StorehouseId: houseConfig.StorehouseOutInfo,
  4848. OverCount: flush_count,
  4849. OperateTime: time.Now().Unix(),
  4850. }
  4851. service.CreateStockFlowOne(flow)
  4852. //退库数量增加
  4853. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4854. //出库数量减少
  4855. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4856. }
  4857. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4858. var flush_count int64
  4859. for _, it := range goodList {
  4860. flush_count += it.StockCount
  4861. }
  4862. //查询已出库数量
  4863. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4864. if prescribingNumber < dialysisInfo.Count {
  4865. //改变数量
  4866. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4867. }
  4868. if prescribingNumber >= dialysisInfo.Count {
  4869. //删除出库表
  4870. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4871. }
  4872. //更新库存
  4873. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4874. //更新基础库库存
  4875. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4876. }
  4877. }
  4878. }
  4879. }
  4880. //保存耗材出库
  4881. if goodOutConfig.IsOpen == 1 {
  4882. if item.Type == 3 {
  4883. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4884. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4885. good.Total = good.Total + f_count
  4886. service.UpdateGoodInfo(&good)
  4887. operation_time := time.Now().Unix()
  4888. creater := c.GetAdminUserInfo().AdminUser.Id
  4889. //创建退库单
  4890. timeStr := time.Now().Format("2006-01-02")
  4891. timeArr := strings.Split(timeStr, "-")
  4892. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4893. total = total + 1
  4894. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4895. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4896. cancelStock := models.CancelStock{
  4897. OrderNumber: orderNumber,
  4898. OperaTime: operation_time,
  4899. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4900. Creater: creater,
  4901. Ctime: time.Now().Unix(),
  4902. Status: 1,
  4903. ReturnTime: item.RecordDate,
  4904. Type: 1,
  4905. StorehouseId: houseConfig.StorehouseOutInfo,
  4906. IsCheck: 1,
  4907. }
  4908. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4909. if msgerrkonde == gorm.ErrRecordNotFound {
  4910. service.AddSigleCancelStock(&cancelStock)
  4911. }
  4912. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4913. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4914. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4915. //查询该耗材是否出库
  4916. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4917. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4918. deaerler, _ := service.GetDealerById(info.Dealer)
  4919. var total_count int64
  4920. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4921. total_count += count
  4922. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4923. var flush_count int64
  4924. for _, it := range goodList {
  4925. flush_count += it.StockCount
  4926. }
  4927. fmt.Println("历史出库数据", info.Count)
  4928. fmt.Println("出库数量", total_count)
  4929. if info.ID > 0 {
  4930. cancelStockInfo := models.CancelStockInfo{
  4931. GoodId: item.ProjectId,
  4932. CancelStockId: cancel.ID,
  4933. GoodTypeId: good.GoodTypeId,
  4934. Count: prescribingNumber,
  4935. Price: info.Price,
  4936. Total: 0,
  4937. ProductDate: info.ProductDate,
  4938. ExpiryDate: info.ExpiryDate,
  4939. Ctime: time.Now().Unix(),
  4940. Status: 1,
  4941. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4942. OrderNumber: cancel.OrderNumber,
  4943. Type: 0,
  4944. Dealer: deaerler.DealerName,
  4945. Manufacturer: manufacturer.ManufacturerName,
  4946. Number: info.Number,
  4947. RegisterAccount: "",
  4948. Remark: "",
  4949. WarehouseInfoId: info.WarehouseInfotId,
  4950. PatientId: info.PatientId,
  4951. RecordDate: info.SysRecordTime,
  4952. StorehouseId: houseConfig.StorehouseOutInfo,
  4953. IsCheck: 1,
  4954. }
  4955. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4956. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4957. //查询出库数量
  4958. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4959. //出库数据 大于 退库数量
  4960. if len(list) > 0 {
  4961. for _, it := range list {
  4962. //回退库存
  4963. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4964. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4965. var flush_count_one int64
  4966. for _, it := range goodList {
  4967. flush_count_one += it.StockCount
  4968. }
  4969. //查询该批次是否有退库数据
  4970. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4971. creater := c.GetAdminUserInfo().AdminUser.Id
  4972. flow := models.VmStockFlow{
  4973. WarehousingId: it.WarehouseInfotId,
  4974. GoodId: it.GoodId,
  4975. Number: it.Number,
  4976. LicenseNumber: it.LicenseNumber,
  4977. Count: it.Count,
  4978. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4979. PatientId: it.PatientId,
  4980. SystemTime: it.SysRecordTime,
  4981. ConsumableType: 7,
  4982. IsSys: 0,
  4983. WarehousingOrder: "",
  4984. WarehouseOutId: it.WarehouseOutId,
  4985. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4986. IsEdit: 0,
  4987. CancelStockId: cancel.ID,
  4988. CancelOrderNumber: cancel.OrderNumber,
  4989. Manufacturer: manufacturer.ID,
  4990. Dealer: 0,
  4991. Creator: creater,
  4992. UpdateCreator: 0,
  4993. Status: 1,
  4994. Ctime: time.Now().Unix(),
  4995. Mtime: 0,
  4996. Price: it.Price,
  4997. WarehousingDetailId: it.WarehouseInfotId,
  4998. WarehouseOutDetailId: it.ID,
  4999. CancelOutDetailId: cancelInfo.ID,
  5000. ProductDate: it.ProductDate,
  5001. ExpireDate: it.ExpiryDate,
  5002. StorehouseId: houseConfig.StorehouseOutInfo,
  5003. OverCount: flush_count_one,
  5004. }
  5005. service.CreateStockFlowOne(flow)
  5006. //if flow.ID > 0 {
  5007. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5008. //}
  5009. }
  5010. }
  5011. //flow := models.VmStockFlow{
  5012. // WarehousingId: info.WarehouseInfotId,
  5013. // GoodId: item.ProjectId,
  5014. // Number: info.Number,
  5015. // LicenseNumber: info.LicenseNumber,
  5016. // Count: prescribingNumber,
  5017. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5018. // PatientId: item.PatientId,
  5019. // SystemTime: info.SysRecordTime,
  5020. // ConsumableType: 7,
  5021. // IsSys: 0,
  5022. // WarehousingOrder: "",
  5023. // WarehouseOutId: info.WarehouseOutId,
  5024. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5025. // IsEdit: 0,
  5026. // CancelStockId: cancel.ID,
  5027. // CancelOrderNumber: cancel.OrderNumber,
  5028. // Manufacturer: manufacturer.ID,
  5029. // Dealer: 0,
  5030. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5031. // UpdateCreator: 0,
  5032. // Status: 1,
  5033. // Ctime: time.Now().Unix(),
  5034. // Mtime: 0,
  5035. // Price: info.Price,
  5036. // WarehousingDetailId: info.WarehouseInfotId,
  5037. // WarehouseOutDetailId: info.ID,
  5038. // CancelOutDetailId: cancelInfo.ID,
  5039. // ProductDate: info.ProductDate,
  5040. // ExpireDate: info.ExpiryDate,
  5041. // StorehouseId: houseConfig.StorehouseOutInfo,
  5042. // OverCount: flush_count,
  5043. //}
  5044. //service.CreateStockFlowOne(flow)
  5045. //退库数量增加
  5046. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5047. //出库数量减少
  5048. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5049. //查询已出库数量
  5050. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5051. if prescribingNumber < dialysisInfo.Count {
  5052. //改变数量
  5053. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5054. }
  5055. if prescribingNumber >= dialysisInfo.Count {
  5056. //删除出库表
  5057. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5058. }
  5059. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5060. var flush_count_one int64
  5061. for _, it := range goodList {
  5062. flush_count_one += it.StockCount
  5063. }
  5064. //更新库存
  5065. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5066. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5067. //更新基础库库存
  5068. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5069. }
  5070. }
  5071. }
  5072. }
  5073. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5074. fmt.Println(err)
  5075. }
  5076. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5077. fmt.Println(err)
  5078. if len(advices) > 0 {
  5079. for _, item := range advices {
  5080. redis := service.RedisClient()
  5081. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5082. redis.Set(keyFive, "", time.Second)
  5083. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5084. redis.Set(keyOne, "", time.Second)
  5085. redis.Close()
  5086. }
  5087. }
  5088. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5089. if len(advices) > 0 {
  5090. for _, item := range advices {
  5091. creater := c.GetAdminUserInfo().AdminUser.Id
  5092. service.DrugAutoAddCancelInfo(item, creater)
  5093. }
  5094. }
  5095. } else {
  5096. if drugOutConfig.IsOpen == 1 {
  5097. if len(advices) > 0 {
  5098. for _, item := range advices {
  5099. creater := c.GetAdminUserInfo().AdminUser.Id
  5100. service.DrugAutoAddCancelInfo(item, creater)
  5101. }
  5102. }
  5103. } else {
  5104. if len(advices) > 0 {
  5105. for _, item := range advices {
  5106. creater := c.GetAdminUserInfo().AdminUser.Id
  5107. service.DrugAutoAddCancelInfo(item, creater)
  5108. }
  5109. }
  5110. }
  5111. }
  5112. c.ServeSuccessJSON(map[string]interface{}{
  5113. "msg": "删除成功",
  5114. })
  5115. return
  5116. }
  5117. func (c *HisApiController) DeleteDoctorAdvice() {
  5118. id, _ := c.GetInt64("id")
  5119. advice, _ := service.GetHisDoctorAdvicesById(id)
  5120. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5121. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5122. //已收费和已发药的限制逻辑
  5123. isCharge := false
  5124. isMedicine := false
  5125. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5126. //获取今天该患者所有处方,判断是否发药或者收费
  5127. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5128. //for _, item := range new_prescriptions {
  5129. if new_prescription.IsMedicine == 1 {
  5130. isMedicine = true
  5131. }
  5132. //}
  5133. for _, item := range new_prescriptions {
  5134. if item.OrderStatus == 4 {
  5135. isCharge = true
  5136. }
  5137. }
  5138. if isMedicine {
  5139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5140. return
  5141. }
  5142. if isCharge {
  5143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5144. return
  5145. }
  5146. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5147. for _, item := range advices {
  5148. if item.IsMedicine == 1 {
  5149. isMedicine = true
  5150. }
  5151. }
  5152. if isMedicine {
  5153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5154. return
  5155. }
  5156. if new_prescription.ID > 0 {
  5157. if new_prescription.OrderStatus == 2 {
  5158. isCharge = true
  5159. }
  5160. }
  5161. if isCharge {
  5162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5163. return
  5164. }
  5165. //已收费和已发药的限制逻辑
  5166. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5167. redis := service.RedisClient()
  5168. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5169. redis.Set(keyFive, "", time.Second)
  5170. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5171. redis.Set(keyOne, "", time.Second)
  5172. defer redis.Close()
  5173. if err == nil {
  5174. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5175. //查询是否在处方中出库
  5176. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5177. if openConfig.IsOpen != 1 {
  5178. //判断该医嘱是否执行了
  5179. if advice.ExecutionState == 1 {
  5180. creater := c.GetAdminUserInfo().AdminUser.Id
  5181. service.DrugAutoAddCancelInfo(&advice, creater)
  5182. }
  5183. }
  5184. //开启保存处方扣减功能
  5185. if openConfig.IsOpen == 1 {
  5186. creater := c.GetAdminUserInfo().AdminUser.Id
  5187. service.DrugAutoAddCancelInfo(&advice, creater)
  5188. }
  5189. } else {
  5190. if drugOutConfig.IsOpen == 1 {
  5191. //查询是否在处方中出库
  5192. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5193. if openConfig.IsOpen != 1 {
  5194. //判断该医嘱是否执行了
  5195. if advice.ExecutionState == 1 {
  5196. creater := c.GetAdminUserInfo().AdminUser.Id
  5197. service.DrugAutoAddCancelInfo(&advice, creater)
  5198. }
  5199. }
  5200. //开启保存处方扣减功能
  5201. if openConfig.IsOpen == 1 {
  5202. creater := c.GetAdminUserInfo().AdminUser.Id
  5203. service.DrugAutoAddCancelInfo(&advice, creater)
  5204. }
  5205. } else {
  5206. //判断该医嘱是否执行了
  5207. if advice.ExecutionState == 1 {
  5208. creater := c.GetAdminUserInfo().AdminUser.Id
  5209. service.DrugAutoAddCancelInfo(&advice, creater)
  5210. }
  5211. }
  5212. }
  5213. c.ServeSuccessJSON(map[string]interface{}{
  5214. "msg": "删除成功",
  5215. })
  5216. return
  5217. } else {
  5218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5219. return
  5220. }
  5221. }
  5222. func (c *HisApiController) DeleteProject() {
  5223. id, _ := c.GetInt64("id")
  5224. adminInfo := c.GetAdminUserInfo()
  5225. project, _ := service.GetHisProjectByID(id)
  5226. // var consumable models.DialysisBeforePrepare
  5227. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5228. //耗材保存处方出库
  5229. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5230. isCharge := false
  5231. isMedicine := false
  5232. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5233. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5234. for _, item := range new_prescriptions {
  5235. if item.IsMedicine == 1 {
  5236. isMedicine = true
  5237. }
  5238. }
  5239. for _, item := range new_prescriptions {
  5240. if item.OrderStatus == 4 {
  5241. isCharge = true
  5242. }
  5243. }
  5244. if isMedicine {
  5245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5246. return
  5247. }
  5248. if isCharge {
  5249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5250. return
  5251. }
  5252. if new_prescription.ID > 0 {
  5253. if new_prescription.OrderStatus == 2 {
  5254. isCharge = true
  5255. }
  5256. }
  5257. if isCharge {
  5258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5259. return
  5260. }
  5261. service.DeletePrintInfo(id)
  5262. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5263. label.Status = 0
  5264. service.CreateHisLabelRecordTwo(&label)
  5265. fmt.Println(goodOutConfig.IsOpen)
  5266. if goodOutConfig.IsOpen != 1 {
  5267. if stockConfig.IsOpen == 1 {
  5268. if project.Type == 2 {
  5269. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5270. fmt.Println(err)
  5271. }
  5272. if project.Type == 3 && project.IsOut == 1 {
  5273. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5274. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5275. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5276. operation_time := time.Now().Unix()
  5277. creater := adminInfo.AdminUser.Id
  5278. //创建退库单
  5279. timeStr := time.Now().Format("2006-01-02")
  5280. timeArr := strings.Split(timeStr, "-")
  5281. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5282. total = total + 1
  5283. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5284. cancelStock := models.CancelStock{
  5285. OrderNumber: orderNumber,
  5286. OperaTime: operation_time,
  5287. OrgId: adminInfo.CurrentOrgId,
  5288. Creater: creater,
  5289. Ctime: time.Now().Unix(),
  5290. Status: 1,
  5291. ReturnTime: project.RecordDate,
  5292. Type: 1,
  5293. StorehouseId: houseConfig.StorehouseOutInfo,
  5294. IsCheck: 1,
  5295. }
  5296. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5297. if msgerrkonde == gorm.ErrRecordNotFound {
  5298. service.AddSigleCancelStock(&cancelStock)
  5299. }
  5300. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5301. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5302. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5303. //查询是否有出库
  5304. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5305. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5306. deaerler, _ := service.GetDealerById(info.Dealer)
  5307. if info.ID > 0 {
  5308. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5309. if info.Count >= prescribingNumber {
  5310. cancelStockInfo := models.CancelStockInfo{
  5311. GoodId: project.ProjectId,
  5312. CancelStockId: cancel.ID,
  5313. GoodTypeId: good.GoodTypeId,
  5314. Count: prescribingNumber,
  5315. Price: info.Price,
  5316. Total: 0,
  5317. ProductDate: info.ProductDate,
  5318. ExpiryDate: info.ExpiryDate,
  5319. Ctime: time.Now().Unix(),
  5320. Status: 1,
  5321. OrgId: adminInfo.CurrentOrgId,
  5322. OrderNumber: cancel.OrderNumber,
  5323. Type: 0,
  5324. Dealer: deaerler.DealerName,
  5325. Manufacturer: manufacturer.ManufacturerName,
  5326. Number: info.Number,
  5327. RegisterAccount: "",
  5328. Remark: "",
  5329. WarehouseInfoId: info.WarehouseInfotId,
  5330. PatientId: info.PatientId,
  5331. RecordDate: info.SysRecordTime,
  5332. StorehouseId: houseConfig.StorehouseOutInfo,
  5333. IsCheck: 1,
  5334. }
  5335. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5336. //回退库存
  5337. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5338. //退库数量增加
  5339. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5340. //出库数量减少
  5341. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5342. }
  5343. if info.Count < prescribingNumber {
  5344. cancelStockInfo := models.CancelStockInfo{
  5345. GoodId: project.ProjectId,
  5346. CancelStockId: cancel.ID,
  5347. GoodTypeId: good.GoodTypeId,
  5348. Count: info.Count,
  5349. Price: info.Price,
  5350. Total: 0,
  5351. ProductDate: info.ProductDate,
  5352. ExpiryDate: info.ExpiryDate,
  5353. Ctime: time.Now().Unix(),
  5354. Status: 1,
  5355. OrgId: adminInfo.CurrentOrgId,
  5356. OrderNumber: cancel.OrderNumber,
  5357. Type: 0,
  5358. Dealer: deaerler.DealerName,
  5359. Manufacturer: manufacturer.ManufacturerName,
  5360. Number: info.Number,
  5361. RegisterAccount: "",
  5362. Remark: "",
  5363. WarehouseInfoId: info.WarehouseInfotId,
  5364. PatientId: info.PatientId,
  5365. RecordDate: info.SysRecordTime,
  5366. StorehouseId: houseConfig.StorehouseOutInfo,
  5367. IsCheck: 1,
  5368. }
  5369. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5370. //回退库存
  5371. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5372. //退库数量增加
  5373. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5374. //出库数量减少
  5375. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5376. }
  5377. //查询剩余库存
  5378. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5379. var over_count int64
  5380. for _, it := range goodList {
  5381. over_count += it.StockCount
  5382. }
  5383. //出库数据 大于 退库数量
  5384. if info.Count >= prescribingNumber {
  5385. flow := models.VmStockFlow{
  5386. WarehousingId: info.WarehouseInfotId,
  5387. GoodId: project.ProjectId,
  5388. Number: info.Number,
  5389. LicenseNumber: info.LicenseNumber,
  5390. Count: prescribingNumber,
  5391. UserOrgId: adminInfo.CurrentOrgId,
  5392. PatientId: project.PatientId,
  5393. SystemTime: info.SysRecordTime,
  5394. ConsumableType: 7,
  5395. IsSys: 0,
  5396. WarehousingOrder: "",
  5397. WarehouseOutId: info.WarehouseOutId,
  5398. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5399. IsEdit: 0,
  5400. CancelStockId: cancel.ID,
  5401. CancelOrderNumber: cancel.OrderNumber,
  5402. Manufacturer: manufacturer.ID,
  5403. Dealer: 0,
  5404. Creator: adminInfo.AdminUser.Id,
  5405. UpdateCreator: 0,
  5406. Status: 1,
  5407. Ctime: time.Now().Unix(),
  5408. Mtime: 0,
  5409. Price: info.Price,
  5410. WarehousingDetailId: info.WarehouseInfotId,
  5411. WarehouseOutDetailId: info.ID,
  5412. CancelOutDetailId: cancelInfo.ID,
  5413. ProductDate: info.ProductDate,
  5414. ExpireDate: info.ExpiryDate,
  5415. StorehouseId: houseConfig.StorehouseOutInfo,
  5416. OverCount: over_count,
  5417. OperateTime: time.Now().Unix(),
  5418. }
  5419. service.CreateStockFlowOne(flow)
  5420. }
  5421. //出库数据小于退库数据
  5422. if info.Count < prescribingNumber {
  5423. flow := models.VmStockFlow{
  5424. WarehousingId: info.WarehouseInfotId,
  5425. GoodId: project.ProjectId,
  5426. Number: info.Number,
  5427. LicenseNumber: info.LicenseNumber,
  5428. Count: info.Count,
  5429. UserOrgId: adminInfo.CurrentOrgId,
  5430. PatientId: project.PatientId,
  5431. SystemTime: info.SysRecordTime,
  5432. ConsumableType: 7,
  5433. IsSys: 0,
  5434. WarehousingOrder: "",
  5435. WarehouseOutId: info.WarehouseOutId,
  5436. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5437. IsEdit: 0,
  5438. CancelStockId: cancel.ID,
  5439. CancelOrderNumber: cancel.OrderNumber,
  5440. Manufacturer: manufacturer.ID,
  5441. Dealer: 0,
  5442. Creator: adminInfo.AdminUser.Id,
  5443. UpdateCreator: 0,
  5444. Status: 1,
  5445. Ctime: time.Now().Unix(),
  5446. Mtime: 0,
  5447. Price: info.Price,
  5448. WarehousingDetailId: info.WarehouseInfotId,
  5449. WarehouseOutDetailId: info.ID,
  5450. CancelOutDetailId: cancelInfo.ID,
  5451. ProductDate: info.ProductDate,
  5452. ExpireDate: info.ExpiryDate,
  5453. StorehouseId: houseConfig.StorehouseOutInfo,
  5454. OverCount: over_count,
  5455. OperateTime: time.Now().Unix(),
  5456. }
  5457. service.CreateStockFlowOne(flow)
  5458. }
  5459. //查询已出库数量
  5460. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5461. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5462. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5463. if prescribingNumber < dialysisInfo.Count {
  5464. //改变数量
  5465. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5466. }
  5467. if prescribingNumber >= dialysisInfo.Count {
  5468. //删除出库表
  5469. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5470. }
  5471. //更新剩余库存
  5472. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5473. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5474. var total_count_one int64
  5475. for _, it := range stockList {
  5476. total_count_one += it.StockCount
  5477. }
  5478. //基础库插入数据
  5479. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5480. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5481. var flush_count int64
  5482. for _, it := range goodListOne {
  5483. flush_count += it.StockCount
  5484. }
  5485. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5486. if errs != nil {
  5487. goodErrcode := models.XtGoodErrcode{
  5488. UserOrgId: project.UserOrgId,
  5489. Errcode: "手动出库更新剩余出库失败",
  5490. GoodId: project.ProjectId,
  5491. Status: 1,
  5492. Ctime: time.Now().Unix(),
  5493. Mtime: 0,
  5494. Count: 0,
  5495. StockCount: 0,
  5496. Creater: creater,
  5497. BatchNumberId: 0,
  5498. WarehouseOutId: 0,
  5499. }
  5500. service.CreateGoodErrcode(goodErrcode)
  5501. }
  5502. }
  5503. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5504. fmt.Println(err)
  5505. } else {
  5506. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5507. fmt.Println(err)
  5508. }
  5509. } else {
  5510. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5511. fmt.Println(err)
  5512. }
  5513. }
  5514. //保存处方出库
  5515. if goodOutConfig.IsOpen == 1 {
  5516. if project.Type == 3 {
  5517. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5518. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5519. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5520. operation_time := time.Now().Unix()
  5521. creater := adminInfo.AdminUser.Id
  5522. //创建退库单
  5523. timeStr := time.Now().Format("2006-01-02")
  5524. timeArr := strings.Split(timeStr, "-")
  5525. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5526. total = total + 1
  5527. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5528. cancelStock := models.CancelStock{
  5529. OrderNumber: orderNumber,
  5530. OperaTime: operation_time,
  5531. OrgId: adminInfo.CurrentOrgId,
  5532. Creater: creater,
  5533. Ctime: time.Now().Unix(),
  5534. Status: 1,
  5535. ReturnTime: project.RecordDate,
  5536. Type: 1,
  5537. StorehouseId: houseConfig.StorehouseOutInfo,
  5538. IsCheck: 1,
  5539. }
  5540. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5541. if msgerrkonde == gorm.ErrRecordNotFound {
  5542. service.AddSigleCancelStock(&cancelStock)
  5543. }
  5544. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5545. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5546. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5547. //获取出库数据
  5548. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5549. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5550. deaerler, _ := service.GetDealerById(info.Dealer)
  5551. if info.ID > 0 {
  5552. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5553. if info.Count >= prescribingNumber {
  5554. cancelStockInfo := models.CancelStockInfo{
  5555. GoodId: project.ProjectId,
  5556. CancelStockId: cancel.ID,
  5557. GoodTypeId: good.GoodTypeId,
  5558. Count: prescribingNumber,
  5559. Price: info.Price,
  5560. Total: 0,
  5561. ProductDate: info.ProductDate,
  5562. ExpiryDate: info.ExpiryDate,
  5563. Ctime: time.Now().Unix(),
  5564. Status: 1,
  5565. OrgId: adminInfo.CurrentOrgId,
  5566. OrderNumber: cancel.OrderNumber,
  5567. Type: 0,
  5568. Dealer: deaerler.DealerName,
  5569. Manufacturer: manufacturer.ManufacturerName,
  5570. Number: info.Number,
  5571. RegisterAccount: "",
  5572. Remark: "",
  5573. WarehouseInfoId: info.WarehouseInfotId,
  5574. PatientId: info.PatientId,
  5575. RecordDate: info.SysRecordTime,
  5576. StorehouseId: houseConfig.StorehouseOutInfo,
  5577. IsCheck: 1,
  5578. }
  5579. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5580. //退库数量增加
  5581. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5582. //出库数量减少
  5583. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5584. }
  5585. if info.Count < prescribingNumber {
  5586. cancelStockInfo := models.CancelStockInfo{
  5587. GoodId: project.ProjectId,
  5588. CancelStockId: cancel.ID,
  5589. GoodTypeId: good.GoodTypeId,
  5590. Count: prescribingNumber,
  5591. Price: info.Price,
  5592. Total: 0,
  5593. ProductDate: info.ProductDate,
  5594. ExpiryDate: info.ExpiryDate,
  5595. Ctime: time.Now().Unix(),
  5596. Status: 1,
  5597. OrgId: adminInfo.CurrentOrgId,
  5598. OrderNumber: cancel.OrderNumber,
  5599. Type: 0,
  5600. Dealer: deaerler.DealerName,
  5601. Manufacturer: manufacturer.ManufacturerName,
  5602. Number: info.Number,
  5603. RegisterAccount: "",
  5604. Remark: "",
  5605. WarehouseInfoId: info.WarehouseInfotId,
  5606. PatientId: info.PatientId,
  5607. RecordDate: info.SysRecordTime,
  5608. StorehouseId: houseConfig.StorehouseOutInfo,
  5609. IsCheck: 1,
  5610. }
  5611. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5612. //回退库存
  5613. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5614. }
  5615. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5616. var over_count int64
  5617. for _, it := range goodList {
  5618. over_count += it.StockCount
  5619. }
  5620. //查询出库数量
  5621. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5622. //出库数据 大于 退库数量
  5623. if len(list) > 0 {
  5624. for _, it := range list {
  5625. //回退库存
  5626. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5627. //退库数量增加
  5628. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5629. //出库数量减少
  5630. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5631. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5632. var over_count_one int64
  5633. for _, it := range goodList {
  5634. over_count_one += it.StockCount
  5635. }
  5636. //查询该批次是否有退库数据
  5637. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5638. flow := models.VmStockFlow{
  5639. WarehousingId: it.WarehouseInfotId,
  5640. GoodId: it.GoodId,
  5641. Number: it.Number,
  5642. LicenseNumber: it.LicenseNumber,
  5643. Count: it.Count,
  5644. UserOrgId: adminInfo.CurrentOrgId,
  5645. PatientId: it.PatientId,
  5646. SystemTime: it.SysRecordTime,
  5647. ConsumableType: 7,
  5648. IsSys: 0,
  5649. WarehousingOrder: "",
  5650. WarehouseOutId: it.WarehouseOutId,
  5651. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5652. IsEdit: 0,
  5653. CancelStockId: cancel.ID,
  5654. CancelOrderNumber: cancel.OrderNumber,
  5655. Manufacturer: manufacturer.ID,
  5656. Dealer: 0,
  5657. Creator: adminInfo.AdminUser.Id,
  5658. UpdateCreator: 0,
  5659. Status: 1,
  5660. Ctime: time.Now().Unix(),
  5661. Mtime: 0,
  5662. Price: it.Price,
  5663. WarehousingDetailId: it.WarehouseInfotId,
  5664. WarehouseOutDetailId: it.ID,
  5665. CancelOutDetailId: cancelInfo.ID,
  5666. ProductDate: it.ProductDate,
  5667. ExpireDate: it.ExpiryDate,
  5668. StorehouseId: houseConfig.StorehouseOutInfo,
  5669. OverCount: over_count_one,
  5670. OperateTime: time.Now().Unix(),
  5671. }
  5672. service.CreateStockFlowOne(flow)
  5673. }
  5674. }
  5675. //查询已出库数量
  5676. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5677. if prescribingNumber < dialysisInfo.Count {
  5678. //改变数量
  5679. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5680. }
  5681. if prescribingNumber >= dialysisInfo.Count {
  5682. //删除出库表
  5683. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5684. }
  5685. //更新剩余库存
  5686. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5687. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5688. var total_count_one int64
  5689. for _, it := range stockList {
  5690. total_count_one += it.StockCount
  5691. }
  5692. //基础库插入数据
  5693. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5694. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5695. var flush_count int64
  5696. for _, it := range goodListOne {
  5697. flush_count += it.StockCount
  5698. }
  5699. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5700. if errs != nil {
  5701. goodErrcode := models.XtGoodErrcode{
  5702. UserOrgId: project.UserOrgId,
  5703. Errcode: "手动出库更新剩余出库失败",
  5704. GoodId: project.ProjectId,
  5705. Status: 1,
  5706. Ctime: time.Now().Unix(),
  5707. Mtime: 0,
  5708. Count: 0,
  5709. StockCount: 0,
  5710. Creater: creater,
  5711. BatchNumberId: 0,
  5712. WarehouseOutId: 0,
  5713. }
  5714. service.CreateGoodErrcode(goodErrcode)
  5715. }
  5716. }
  5717. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5718. fmt.Println(err)
  5719. } else {
  5720. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5721. fmt.Println(err)
  5722. }
  5723. }
  5724. c.ServeSuccessJSON(map[string]interface{}{
  5725. "msg": "删除成功",
  5726. })
  5727. return
  5728. }
  5729. func (c *HisApiController) CreateHisAdditionalCharge() {
  5730. his_patient_id, _ := c.GetInt64("his_patient_id")
  5731. patient_id, _ := c.GetInt64("patient_id")
  5732. record_date := c.GetString("record_date")
  5733. timeLayout := "2006-01-02"
  5734. loc, _ := time.LoadLocation("Local")
  5735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5736. if err != nil {
  5737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5738. return
  5739. }
  5740. adminInfo := c.GetAdminUserInfo()
  5741. recordDateTime := theTime.Unix()
  5742. dataBody := make(map[string]interface{}, 0)
  5743. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5744. if err != nil {
  5745. utils.ErrorLog(err.Error())
  5746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5747. return
  5748. }
  5749. var additions []*models.HisAdditionalCharge
  5750. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5751. additions, _ := dataBody["addition"].([]interface{})
  5752. if len(additions) > 0 {
  5753. for _, item := range additions {
  5754. items := item.(map[string]interface{})
  5755. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5756. utils.ErrorLog("item_id")
  5757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5758. return
  5759. }
  5760. item_id := int64(items["item_id"].(float64))
  5761. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5762. utils.ErrorLog("item_name")
  5763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5764. return
  5765. }
  5766. item_name := items["item_name"].(string)
  5767. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5768. utils.ErrorLog("price")
  5769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5770. return
  5771. }
  5772. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5773. ctime := time.Now().Unix()
  5774. additional := &models.HisAdditionalCharge{
  5775. PatientId: patient_id,
  5776. HisPatientId: his_patient_id,
  5777. UserOrgId: adminInfo.CurrentOrgId,
  5778. RecordDate: recordDateTime,
  5779. CreatedTime: ctime,
  5780. UpdatedTime: ctime,
  5781. Modifier: adminInfo.AdminUser.Id,
  5782. Creator: adminInfo.AdminUser.Id,
  5783. Price: price,
  5784. ItemName: item_name,
  5785. ItemId: item_id,
  5786. Status: 1,
  5787. }
  5788. additions = append(additions, additional)
  5789. }
  5790. }
  5791. }
  5792. for _, item := range additions {
  5793. service.CreateAddtionalCharge(item)
  5794. }
  5795. c.ServeSuccessJSON(map[string]interface{}{
  5796. "msg": "创建成功",
  5797. })
  5798. }
  5799. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5800. blood_fat := c.GetString("blood_fat")
  5801. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5802. blood_sugar := c.GetString("blood_sugar")
  5803. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5804. chief_conplaint := c.GetString("chief_conplaint")
  5805. dbp := c.GetString("dbp")
  5806. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5807. delivery_way, _ := c.GetInt64("delivery_way")
  5808. diagnostic := c.GetString("diagnostic")
  5809. family_history := c.GetString("family_history")
  5810. height := c.GetString("height")
  5811. history_of_present_illness := c.GetString("history_of_present_illness")
  5812. is_infect, _ := c.GetInt64("is_infect")
  5813. past_history := c.GetString("past_history")
  5814. patient_id, _ := c.GetInt64("patient_id")
  5815. his_patient_id, _ := c.GetInt64("his_patient_id")
  5816. personal_history := c.GetString("personal_history")
  5817. pulse := c.GetString("pulse")
  5818. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5819. sbp := c.GetString("sbp")
  5820. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5821. heightfloat, _ := strconv.ParseFloat(height, 64)
  5822. sicktype := c.GetString("sick_type")
  5823. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5824. symptom := c.GetString("symptom")
  5825. sick_date := c.GetString("sick_date")
  5826. temperatures := c.GetString("temperature")
  5827. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5828. record_date := c.GetString("record_date")
  5829. breathing := c.GetString("breathing")
  5830. doctor_advice := c.GetString("doctor_advice")
  5831. remark := c.GetString("remark")
  5832. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5833. sick, _ := c.GetInt64("sick")
  5834. diagnose, _ := c.GetInt64("diagnose")
  5835. //id, _ := c.GetInt64("id")
  5836. timeLayout := "2006-01-02"
  5837. loc, _ := time.LoadLocation("Local")
  5838. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5839. allergic_history := c.GetString("allergic_history")
  5840. if err != nil {
  5841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5842. return
  5843. }
  5844. recordDateTime := theTime.Unix()
  5845. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5846. if err != nil {
  5847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5848. return
  5849. }
  5850. sickTimes := sickTime.Unix()
  5851. ctime := time.Now().Unix()
  5852. primary_disease := c.GetString("primary_disease")
  5853. confirm_failure_date := c.GetString("confirm_failure_date")
  5854. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5855. drug_allergy_history := c.GetString("drug_allergy_history")
  5856. physical_examination := c.GetString("physical_examination")
  5857. special_inspection := c.GetString("special_inspection")
  5858. lab_apparatus := c.GetString("lab_apparatus")
  5859. caseHistory := models.HisPatientCaseHistory{
  5860. HisPatientId: his_patient_id,
  5861. PatientId: patient_id,
  5862. Temperature: temperature,
  5863. BloodSugar: bloodsugarfloat,
  5864. Pulse: pulsefloat,
  5865. Sbp: sbpfloat,
  5866. Dbp: dbpfloat,
  5867. Height: heightfloat,
  5868. BloodFat: bloodfatfloat,
  5869. SickType: sick_type,
  5870. Symptom: symptom,
  5871. SickDate: sickTimes,
  5872. IsInfect: is_infect,
  5873. HistoryOfPresentIllness: history_of_present_illness,
  5874. PastHistory: past_history,
  5875. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5876. ChiefConplaint: chief_conplaint,
  5877. PersonalHistory: personal_history,
  5878. FamilyHistory: family_history,
  5879. Diagnostic: diagnostic,
  5880. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5881. Status: 1,
  5882. Ctime: ctime,
  5883. Mtime: ctime,
  5884. RecordDate: recordDateTime,
  5885. DeliveryWay: delivery_way,
  5886. Breathing: breathingfloat,
  5887. DoctorAdvice: doctor_advice,
  5888. Remark: remark,
  5889. Sick: sick,
  5890. Diagnose: diagnose,
  5891. AllergicHistory: allergic_history,
  5892. PrimaryDisease: primary_disease,
  5893. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5894. DrugAllergyHistory: drug_allergy_history,
  5895. PhysicalExamination: physical_examination,
  5896. SpecialInspection: special_inspection,
  5897. LabApparatus: lab_apparatus,
  5898. }
  5899. //查询该患者是否有病历
  5900. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5901. if errcodes == gorm.ErrRecordNotFound {
  5902. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5903. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5904. if err != nil {
  5905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5906. return
  5907. }
  5908. c.ServeSuccessJSON(map[string]interface{}{
  5909. "caseHistory": caseHistory,
  5910. "historyInfo": historyInfo,
  5911. })
  5912. return
  5913. } else if errcodes == nil {
  5914. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5915. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5916. if err != nil {
  5917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5918. return
  5919. }
  5920. c.ServeSuccessJSON(map[string]interface{}{
  5921. "caseHistory": caseHistory,
  5922. "historyInfo": historyInfo,
  5923. })
  5924. }
  5925. //查询该患者是否有病历
  5926. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5927. //if errcode == gorm.ErrRecordNotFound {
  5928. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5929. // if err != nil {
  5930. // c.ServeSuccessJSON(map[string]interface{}{
  5931. // "msg": "保存成功",
  5932. // })
  5933. // }
  5934. //} else if errcode == nil {
  5935. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5936. // return
  5937. //}
  5938. }
  5939. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5940. patient_id, _ := c.GetInt64("patient_id", 0)
  5941. adminUser := c.GetAdminUserInfo()
  5942. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5943. c.ServeSuccessJSON(map[string]interface{}{
  5944. "list": caseHistorys,
  5945. })
  5946. }
  5947. func (c *HisApiController) GetHisPatientCaseHistory() {
  5948. record_date, _ := c.GetInt64("record_date", 0)
  5949. patient_id, _ := c.GetInt64("patient_id", 0)
  5950. admin := c.GetAdminUserInfo()
  5951. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5952. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5953. c.ServeSuccessJSON(map[string]interface{}{
  5954. "info": info,
  5955. "case_history": case_history,
  5956. })
  5957. }
  5958. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5959. template_name := c.GetString("template_name")
  5960. template_remark := c.GetString("template_remark")
  5961. doctor := c.GetAdminUserInfo().AdminUser.Id
  5962. diagnostic := c.GetString("diagnostic")
  5963. chief_conplaint := c.GetString("chief_conplain")
  5964. history_of_present_illness := c.GetString("history_of_present_illness")
  5965. past_history := c.GetString("past_history")
  5966. personal_history := c.GetString("personal_history")
  5967. family_history := c.GetString("family_history")
  5968. user_name := c.GetString("user_name")
  5969. doctor_advice := c.GetString("doctor_advice")
  5970. remark := c.GetString("remark")
  5971. //record_date := c.GetString("record_date")
  5972. //fmt.Println("record_date--------",record_date)
  5973. //timeLayout := "2006-01-02"
  5974. //loc, _ := time.LoadLocation("Local")
  5975. //
  5976. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5977. //if err != nil {
  5978. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5979. // return
  5980. //}
  5981. //recordDateTime := theTime.Unix()
  5982. ctime := time.Now().Unix()
  5983. template := models.HisCaseHistoryTemplate{
  5984. HistoryOfPresentIllness: history_of_present_illness,
  5985. PastHistory: past_history,
  5986. ChiefConplaint: chief_conplaint,
  5987. PersonalHistory: personal_history,
  5988. FamilyHistory: family_history,
  5989. Diagnostic: diagnostic,
  5990. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5991. Status: 1,
  5992. Ctime: ctime,
  5993. Mtime: ctime,
  5994. RecordDate: time.Now().Unix(),
  5995. TemplateName: template_name,
  5996. TemplateRemark: template_remark,
  5997. Creator: doctor,
  5998. Modifier: doctor,
  5999. UserName: user_name,
  6000. DoctorAdvice: doctor_advice,
  6001. Remark: remark,
  6002. }
  6003. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6004. if err == nil {
  6005. c.ServeSuccessJSON(map[string]interface{}{
  6006. "msg": "保存成功",
  6007. })
  6008. } else {
  6009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6010. return
  6011. }
  6012. }
  6013. func (c *HisApiController) GetCaseHistoryTemplate() {
  6014. timeLayout := "2006-01-02"
  6015. loc, _ := time.LoadLocation("Local")
  6016. keyword := c.GetString("keyword")
  6017. start_time := c.GetString("start_time")
  6018. end_time := c.GetString("end_time")
  6019. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6020. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6021. admin := c.GetAdminUserInfo()
  6022. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6023. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6024. c.ServeSuccessJSON(map[string]interface{}{
  6025. "template": template,
  6026. //"history": history,
  6027. })
  6028. }
  6029. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6030. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6031. utils.ErrorLog("drug_name")
  6032. return enums.ErrorCodeParamWrong
  6033. }
  6034. adviceName, _ := json["drug_name"].(string)
  6035. if len(adviceName) == 0 {
  6036. utils.ErrorLog("len(advice_name) == 0")
  6037. return enums.ErrorCodeParamWrong
  6038. }
  6039. advice.AdviceName = adviceName
  6040. adviceDesc, _ := json["advice_desc"].(string)
  6041. advice.AdviceDesc = adviceDesc
  6042. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6043. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6044. advice.DrugSpec = drugSpec
  6045. }
  6046. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6047. remark, _ := json["remark"].(string)
  6048. advice.Remark = remark
  6049. }
  6050. if json["id"] == nil {
  6051. advice.DrugId = 0
  6052. } else {
  6053. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6054. drug_id := int64(json["id"].(float64))
  6055. advice.DrugId = drug_id
  6056. }
  6057. }
  6058. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6059. advice_id := int64(json["advice_id"].(float64))
  6060. advice.ID = advice_id
  6061. if advice.ID > 0 {
  6062. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6063. if err == nil {
  6064. if hisAdvice.ID > 0 {
  6065. advice.ExecutionTime = hisAdvice.ExecutionTime
  6066. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6067. advice.ExecutionState = hisAdvice.ExecutionState
  6068. advice.CheckTime = hisAdvice.CheckTime
  6069. advice.Checker = hisAdvice.Checker
  6070. advice.CheckState = hisAdvice.CheckState
  6071. advice.StartTime = hisAdvice.StartTime
  6072. advice.FeedetlSn = hisAdvice.FeedetlSn
  6073. }
  6074. }
  6075. }
  6076. }
  6077. //
  6078. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6079. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6080. // advice.ExecutionTime = execution_time
  6081. //}
  6082. //
  6083. //
  6084. //
  6085. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6086. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6087. // advice.ExecutionStaff = execution_staff
  6088. //}
  6089. //
  6090. //
  6091. //
  6092. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6093. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6094. // advice.ExecutionState = execution_state
  6095. //}
  6096. //
  6097. //
  6098. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6099. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6100. // advice.CheckTime = check_time
  6101. //}
  6102. //
  6103. //
  6104. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6105. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6106. // advice.CheckState = check_state
  6107. //}
  6108. //
  6109. //
  6110. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6111. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6112. // advice.Checker = checker
  6113. //}
  6114. //
  6115. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6116. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6117. // advice.StartTime = start_time
  6118. //}
  6119. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6120. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6121. advice.IsSelfDrug = is_self_drug
  6122. }
  6123. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6124. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6125. drug_way_count, _ := json["drug_way_count"].(string)
  6126. advice.DrugWayCount = drug_way_count
  6127. }
  6128. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6129. drugSpecUnit, _ := json["min_unit"].(string)
  6130. advice.DrugSpecUnit = drugSpecUnit
  6131. }
  6132. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6133. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6134. advice.SingleDose = singleDose
  6135. }
  6136. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6137. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6138. advice.SingleDoseUnit = singleDoseUnit
  6139. }
  6140. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6141. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6142. advice.PrescribingNumber = prescribingNumber
  6143. }
  6144. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6145. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6146. advice.PrescribingNumberUnit = prescribingNumberUnit
  6147. }
  6148. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6149. deliveryWay, _ := json["delivery_way"].(string)
  6150. advice.DeliveryWay = deliveryWay
  6151. }
  6152. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6153. executionFrequency, _ := json["execution_frequency"].(string)
  6154. advice.ExecutionFrequency = executionFrequency
  6155. }
  6156. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6157. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6158. advice.Price = price
  6159. }
  6160. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6161. med_list_codg, _ := json["medical_insurance_number"].(string)
  6162. advice.MedListCodg = med_list_codg
  6163. }
  6164. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6165. day := int64(json["day"].(float64))
  6166. advice.Day = day
  6167. }
  6168. return 0
  6169. }
  6170. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6171. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6172. id := int64(json["id"].(float64))
  6173. project.ID = id
  6174. historyProject, _ := service.GetHisProjectByID(id)
  6175. project.FeedetlSn = historyProject.FeedetlSn
  6176. }
  6177. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6178. project_id := int64(json["project_id"].(float64))
  6179. project.ProjectId = project_id
  6180. }
  6181. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6182. // price := int64(json["price"].(float64))
  6183. // formatInt_price := strconv.FormatInt(price, 10)
  6184. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6185. // project.Price = float_price
  6186. // }
  6187. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6188. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6189. project.Price = price
  6190. }
  6191. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6192. total, _ := json["total"].(string)
  6193. project.Count = total
  6194. }
  6195. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6196. medical_code, _ := json["medical_code"].(string)
  6197. project.MedListCodg = medical_code
  6198. }
  6199. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6200. single_dose, _ := json["single_dose"].(string)
  6201. project.SingleDose = single_dose
  6202. }
  6203. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6204. delivery_way, _ := json["delivery_way"].(string)
  6205. project.DeliveryWay = delivery_way
  6206. }
  6207. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6208. execution_frequency, _ := json["execution_frequency"].(string)
  6209. project.ExecutionFrequency = execution_frequency
  6210. }
  6211. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6212. remark, _ := json["remark"].(string)
  6213. project.Remark = remark
  6214. }
  6215. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6216. day, _ := json["number_days"].(string)
  6217. project.Day = day
  6218. }
  6219. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6220. unit, _ := json["unit"].(string)
  6221. project.Unit = unit
  6222. }
  6223. return 0
  6224. }
  6225. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6226. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6227. id := int64(json["id"].(float64))
  6228. historyAddtions, _ := service.GetHisAdditionByID(id)
  6229. additionalCharge.ID = id
  6230. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6231. }
  6232. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6233. item_id := int64(json["item_id"].(float64))
  6234. additionalCharge.ItemId = item_id
  6235. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6236. if config.ID > 0 {
  6237. if len(config.Code) > 0 {
  6238. additionalCharge.MedListCodg = config.Code
  6239. }
  6240. }
  6241. }
  6242. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6243. // price := int64(json["price"].(float64))
  6244. // formatInt_price := strconv.FormatInt(price, 10)
  6245. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6246. // additionalCharge.Price = float_price
  6247. // }
  6248. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6249. // price := int64(json["price"].(float64))
  6250. // formatInt_price := strconv.FormatInt(price, 10)
  6251. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6252. // additionalCharge.Price = float_price
  6253. //}
  6254. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6255. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6256. additionalCharge.Price = price
  6257. }
  6258. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6259. count, _ := json["count"].(string)
  6260. counts, _ := strconv.ParseInt(count, 10, 64)
  6261. additionalCharge.Count = counts
  6262. }
  6263. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6264. item_name, _ := json["item_name"].(string)
  6265. additionalCharge.ItemName = item_name
  6266. }
  6267. return 0
  6268. }
  6269. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6270. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6271. utils.ErrorLog("drug_name")
  6272. return enums.ErrorCodeParamWrong
  6273. }
  6274. adviceName, _ := json["drug_name"].(string)
  6275. if len(adviceName) == 0 {
  6276. utils.ErrorLog("len(advice_name) == 0")
  6277. return enums.ErrorCodeParamWrong
  6278. }
  6279. advice.AdviceName = adviceName
  6280. adviceDesc, _ := json["advice_desc"].(string)
  6281. advice.AdviceDesc = adviceDesc
  6282. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6283. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6284. advice.DrugSpec = drugSpec
  6285. }
  6286. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6287. remark, _ := json["remark"].(string)
  6288. advice.Remark = remark
  6289. }
  6290. if json["id"] == nil {
  6291. advice.DrugId = 0
  6292. } else {
  6293. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6294. drug_id := int64(json["id"].(float64))
  6295. advice.DrugId = drug_id
  6296. }
  6297. }
  6298. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6299. groupno := int64(json["groupno"].(float64))
  6300. advice.Groupno = groupno
  6301. }
  6302. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6303. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6304. advice.IsSelfDrug = is_self_drug
  6305. }
  6306. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6307. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6308. drug_way_count, _ := json["drug_way_count"].(string)
  6309. advice.DrugWayCount = drug_way_count
  6310. }
  6311. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6312. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6313. advice.HospApprFlag = hosp_appr_flag
  6314. }
  6315. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6316. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6317. advice.PrescribingNumber = prescribingNumber
  6318. }
  6319. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6320. // frequency_type := int64(json["frequency_type"].(float64))
  6321. // advice.FrequencyType = frequency_type
  6322. //}
  6323. //
  6324. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6325. // day_count := int64(json["day_count"].(float64))
  6326. // advice.DayCount = day_count
  6327. //}
  6328. //
  6329. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6330. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6331. // week_day, _ := json["week_day"].(string)
  6332. // advice.WeekDay = week_day
  6333. //}
  6334. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6335. drugSpecUnit, _ := json["min_unit"].(string)
  6336. advice.DrugSpecUnit = drugSpecUnit
  6337. }
  6338. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6339. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6340. advice.SingleDose = singleDose
  6341. }
  6342. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6343. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6344. advice.SingleDoseUnit = singleDoseUnit
  6345. }
  6346. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6347. deliveryWay, _ := json["delivery_way"].(string)
  6348. advice.DeliveryWay = deliveryWay
  6349. }
  6350. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6351. executionFrequency, _ := json["execution_frequency"].(string)
  6352. advice.ExecutionFrequency = executionFrequency
  6353. }
  6354. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6355. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6356. advice.Price = price
  6357. }
  6358. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6359. med_list_codg, _ := json["medical_insurance_number"].(string)
  6360. advice.MedListCodg = med_list_codg
  6361. }
  6362. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6363. day := int64(json["day"].(float64))
  6364. advice.Day = day
  6365. }
  6366. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6367. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6368. advice.PrescribingNumberUnit = prescribingNumberUnit
  6369. }
  6370. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6371. advice_id := int64(json["advice_id"].(float64))
  6372. advice.ID = advice_id
  6373. if advice.ID > 0 {
  6374. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6375. if err == nil {
  6376. if hisAdvice.ID > 0 {
  6377. advice.ExecutionTime = hisAdvice.ExecutionTime
  6378. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6379. advice.ExecutionState = hisAdvice.ExecutionState
  6380. advice.CheckTime = hisAdvice.CheckTime
  6381. advice.Checker = hisAdvice.Checker
  6382. advice.CheckState = hisAdvice.CheckState
  6383. advice.StartTime = hisAdvice.StartTime
  6384. advice.HospApprFlag = hisAdvice.HospApprFlag
  6385. advice.IsMedicine = hisAdvice.IsMedicine
  6386. if hisAdvice.UserOrgId == 10028 {
  6387. 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 {
  6388. advice.ExecutionTime = 0
  6389. advice.ExecutionStaff = 0
  6390. advice.ExecutionState = 2
  6391. advice.CheckTime = 0
  6392. advice.Checker = 0
  6393. advice.CheckState = 2
  6394. }
  6395. } else {
  6396. 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 {
  6397. advice.ExecutionTime = 0
  6398. advice.ExecutionStaff = 0
  6399. advice.ExecutionState = 2
  6400. advice.CheckTime = 0
  6401. advice.Checker = 0
  6402. advice.CheckState = 2
  6403. advice.UpdatedTime = time.Now().Unix()
  6404. }
  6405. }
  6406. //advice.Groupno = hisAdvice.Groupno
  6407. }
  6408. }
  6409. }
  6410. }
  6411. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6412. //
  6413. //if drugStockConfig.IsOpen == 1 {
  6414. //
  6415. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6416. // if advice.ID == 0 { //医嘱不存在
  6417. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6418. // drug.Total = drug.Total - advice.PrescribingNumber
  6419. // service.UpdateBaseDrugLib(&drug)
  6420. //
  6421. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6422. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6423. // drug.Total = drug.Total - num
  6424. // service.UpdateBaseDrugLib(&drug)
  6425. // }
  6426. //
  6427. // } else if advice.ID > 0 { //医嘱存在
  6428. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6429. // var num float64
  6430. //
  6431. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6432. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6433. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6434. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6435. // drug.Total = drug.Total + num
  6436. // service.UpdateBaseDrugLib(&drug)
  6437. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6438. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6439. // drug.Total = drug.Total - num
  6440. // service.UpdateBaseDrugLib(&drug)
  6441. // }
  6442. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6443. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6444. // if num2 > advice.PrescribingNumber {
  6445. // num = num2 - advice.PrescribingNumber
  6446. // drug.Total = drug.Total + num
  6447. // service.UpdateBaseDrugLib(&drug)
  6448. // } else if num2 < advice.PrescribingNumber {
  6449. // num = advice.PrescribingNumber - num2
  6450. // drug.Total = drug.Total - num
  6451. // service.UpdateBaseDrugLib(&drug)
  6452. // }
  6453. //
  6454. // }
  6455. //
  6456. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6457. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6458. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6459. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6460. // if num1 > num2 {
  6461. // num = num1 - num2
  6462. // drug.Total = drug.Total + num
  6463. // service.UpdateBaseDrugLib(&drug)
  6464. // } else if num1 < num2 {
  6465. // num = num2 - num1
  6466. // drug.Total = drug.Total - num
  6467. // service.UpdateBaseDrugLib(&drug)
  6468. // }
  6469. //
  6470. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6471. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6472. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6473. // if hisAdvice.PrescribingNumber > num2 {
  6474. // num = hisAdvice.PrescribingNumber - num2
  6475. // drug.Total = drug.Total + num
  6476. // service.UpdateBaseDrugLib(&drug)
  6477. // } else if num2 < advice.PrescribingNumber {
  6478. // num = num2 - hisAdvice.PrescribingNumber
  6479. // drug.Total = drug.Total - num
  6480. // service.UpdateBaseDrugLib(&drug)
  6481. // }
  6482. //
  6483. // }
  6484. // }
  6485. // }
  6486. //}
  6487. //
  6488. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6489. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6490. // advice.ExecutionTime = execution_time
  6491. //}
  6492. //
  6493. //
  6494. //
  6495. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6496. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6497. // advice.ExecutionStaff = execution_staff
  6498. //}
  6499. //
  6500. //
  6501. //
  6502. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6503. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6504. // advice.ExecutionState = execution_state
  6505. //}
  6506. //
  6507. //
  6508. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6509. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6510. // advice.CheckTime = check_time
  6511. //}
  6512. //
  6513. //
  6514. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6515. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6516. // advice.CheckState = check_state
  6517. //}
  6518. //
  6519. //
  6520. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6521. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6522. // advice.Checker = checker
  6523. //}
  6524. //
  6525. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6526. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6527. // advice.StartTime = start_time
  6528. //}
  6529. return 0
  6530. }
  6531. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6532. project.ExecutionStaff = 0
  6533. project.ExecutionState = 2
  6534. project.ExecutionTime = 0
  6535. project.Checker = 0
  6536. project.CheckState = 2
  6537. project.CheckTime = 0
  6538. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6539. id := int64(json["id"].(float64))
  6540. project.ID = id
  6541. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6542. project.ExecutionStaff = temp_project.ExecutionStaff
  6543. project.ExecutionState = temp_project.ExecutionState
  6544. project.ExecutionTime = temp_project.ExecutionTime
  6545. project.Checker = temp_project.Checker
  6546. project.CheckState = temp_project.CheckState
  6547. project.CheckTime = temp_project.CheckTime
  6548. project.TeamId = temp_project.TeamId
  6549. }
  6550. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6551. types := int64(json["type"].(float64))
  6552. project.Type = types
  6553. }
  6554. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6555. project_id := int64(json["project_id"].(float64))
  6556. project.ProjectId = project_id
  6557. }
  6558. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6559. team_id := int64(json["team_id"].(float64))
  6560. project.TeamId = team_id
  6561. }
  6562. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6563. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6564. project.Price = price
  6565. }
  6566. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6567. total, _ := json["total"].(string)
  6568. //totals, _ := strconv.ParseInt(total, 10, 64)
  6569. project.Count = total
  6570. }
  6571. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6572. medical_code, _ := json["medical_code"].(string)
  6573. project.MedListCodg = medical_code
  6574. }
  6575. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6576. single_dose, _ := json["single_dose"].(string)
  6577. project.SingleDose = single_dose
  6578. }
  6579. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6580. delivery_way, _ := json["delivery_way"].(string)
  6581. project.DeliveryWay = delivery_way
  6582. }
  6583. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6584. execution_frequency, _ := json["execution_frequency"].(string)
  6585. project.ExecutionFrequency = execution_frequency
  6586. }
  6587. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6588. remark, _ := json["remark"].(string)
  6589. project.Remark = remark
  6590. }
  6591. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6592. day, _ := json["number_days"].(string)
  6593. project.Day = day
  6594. }
  6595. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6596. unit, _ := json["unit"].(string)
  6597. project.Unit = unit
  6598. }
  6599. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6600. // frequency_type := int64(json["frequency_type"].(float64))
  6601. // project.FrequencyType = frequency_type
  6602. //}
  6603. //
  6604. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6605. // day_count := int64(json["day_count"].(float64))
  6606. // project.DayCount = day_count
  6607. //}
  6608. //
  6609. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6610. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6611. // week_day, _ := json["week_day"].(string)
  6612. // project.WeekDay = week_day
  6613. //}
  6614. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6615. //
  6616. //if project.ID == 0 {
  6617. // if stockConfig.IsOpen == 1 {
  6618. // if project.Type == 3 {
  6619. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6620. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6621. // good.Total = good.Total - f_count
  6622. // service.UpdateGoodInfo(&good)
  6623. // }
  6624. // }
  6625. //
  6626. //} else {
  6627. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6628. //
  6629. // if stockConfig.IsOpen == 1 {
  6630. // if project.Type == 3 {
  6631. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6632. // if project.Count < temp_project.Count {
  6633. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6634. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6635. //
  6636. // other_count := f_count_two - f_count_one
  6637. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6638. // good.Total = good.Total + other_count_two
  6639. // service.UpdateGoodInfo(&good)
  6640. // } else if project.Count > temp_project.Count {
  6641. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6642. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6643. //
  6644. // other_count := f_count_one - f_count_two
  6645. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6646. // good.Total = good.Total - other_count_two
  6647. // service.UpdateGoodInfo(&good)
  6648. // }
  6649. //
  6650. // }
  6651. // }
  6652. //
  6653. //}
  6654. return 0
  6655. }
  6656. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6657. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6658. utils.ErrorLog("drug_name")
  6659. return enums.ErrorCodeParamWrong
  6660. }
  6661. adviceName, _ := json["drug_name"].(string)
  6662. if len(adviceName) == 0 {
  6663. utils.ErrorLog("len(advice_name) == 0")
  6664. return enums.ErrorCodeParamWrong
  6665. }
  6666. advice.AdviceName = adviceName
  6667. adviceDesc, _ := json["advice_desc"].(string)
  6668. advice.AdviceDesc = adviceDesc
  6669. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6670. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6671. advice.DrugSpec = drugSpec
  6672. }
  6673. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6674. remark, _ := json["remark"].(string)
  6675. advice.Remark = remark
  6676. }
  6677. if json["id"] == nil {
  6678. advice.DrugId = 0
  6679. } else {
  6680. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6681. drug_id := int64(json["id"].(float64))
  6682. advice.DrugId = drug_id
  6683. }
  6684. }
  6685. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6686. groupno := int64(json["groupno"].(float64))
  6687. advice.Groupno = groupno
  6688. }
  6689. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6690. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6691. advice.IsSelfDrug = is_self_drug
  6692. }
  6693. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6694. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6695. drug_way_count, _ := json["drug_way_count"].(string)
  6696. advice.DrugWayCount = drug_way_count
  6697. }
  6698. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6699. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6700. advice.HospApprFlag = hosp_appr_flag
  6701. }
  6702. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6703. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6704. advice.PrescribingNumber = prescribingNumber
  6705. }
  6706. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6707. // frequency_type := int64(json["frequency_type"].(float64))
  6708. // advice.FrequencyType = frequency_type
  6709. //}
  6710. //
  6711. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6712. // day_count := int64(json["day_count"].(float64))
  6713. // advice.DayCount = day_count
  6714. //}
  6715. //
  6716. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6717. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6718. // week_day, _ := json["week_day"].(string)
  6719. // advice.WeekDay = week_day
  6720. //}
  6721. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6722. drugSpecUnit, _ := json["min_unit"].(string)
  6723. advice.DrugSpecUnit = drugSpecUnit
  6724. }
  6725. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6726. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6727. advice.SingleDose = singleDose
  6728. }
  6729. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6730. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6731. advice.SingleDoseUnit = singleDoseUnit
  6732. }
  6733. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6734. deliveryWay, _ := json["delivery_way"].(string)
  6735. advice.DeliveryWay = deliveryWay
  6736. }
  6737. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6738. executionFrequency, _ := json["execution_frequency"].(string)
  6739. advice.ExecutionFrequency = executionFrequency
  6740. }
  6741. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6742. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6743. advice.Price = price
  6744. }
  6745. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6746. med_list_codg, _ := json["medical_insurance_number"].(string)
  6747. advice.MedListCodg = med_list_codg
  6748. }
  6749. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6750. day := int64(json["day"].(float64))
  6751. advice.Day = day
  6752. }
  6753. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6754. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6755. advice.PrescribingNumberUnit = prescribingNumberUnit
  6756. }
  6757. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6758. advice_id := int64(json["advice_id"].(float64))
  6759. advice.ID = advice_id
  6760. if advice.ID > 0 {
  6761. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6762. if err == nil {
  6763. if hisAdvice.ID > 0 {
  6764. advice.ExecutionTime = hisAdvice.ExecutionTime
  6765. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6766. advice.ExecutionState = hisAdvice.ExecutionState
  6767. advice.CheckTime = hisAdvice.CheckTime
  6768. advice.Checker = hisAdvice.Checker
  6769. advice.CheckState = hisAdvice.CheckState
  6770. advice.StartTime = hisAdvice.StartTime
  6771. advice.HospApprFlag = hisAdvice.HospApprFlag
  6772. advice.IsMedicine = hisAdvice.IsMedicine
  6773. if hisAdvice.UserOrgId == 10028 {
  6774. 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 {
  6775. advice.ExecutionTime = 0
  6776. advice.ExecutionStaff = 0
  6777. advice.ExecutionState = 2
  6778. advice.CheckTime = 0
  6779. advice.Checker = 0
  6780. advice.CheckState = 2
  6781. }
  6782. } else {
  6783. 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 {
  6784. advice.ExecutionTime = 0
  6785. advice.ExecutionStaff = 0
  6786. advice.ExecutionState = 2
  6787. advice.CheckTime = 0
  6788. advice.Checker = 0
  6789. advice.CheckState = 2
  6790. //advice.UpdatedTime = time.Now().Unix()
  6791. advice.CreatedTime = hisAdvice.CreatedTime
  6792. advice.UpdatedTime = time.Now().Unix()
  6793. } else {
  6794. advice.CreatedTime = hisAdvice.CreatedTime
  6795. advice.UpdatedTime = hisAdvice.UpdatedTime
  6796. }
  6797. }
  6798. //advice.Groupno = hisAdvice.Groupno
  6799. } else {
  6800. advice.IsMedicine = 0
  6801. ctime := time.Now().Unix()
  6802. advice.CreatedTime = ctime
  6803. advice.UpdatedTime = ctime
  6804. }
  6805. }
  6806. } else {
  6807. advice.IsMedicine = 0
  6808. ctime := time.Now().Unix()
  6809. advice.CreatedTime = ctime
  6810. advice.UpdatedTime = ctime
  6811. }
  6812. }
  6813. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6814. //
  6815. //if drugStockConfig.IsOpen == 1 {
  6816. //
  6817. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6818. // if advice.ID == 0 { //医嘱不存在
  6819. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6820. // drug.Total = drug.Total - advice.PrescribingNumber
  6821. // service.UpdateBaseDrugLib(&drug)
  6822. //
  6823. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6824. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6825. // drug.Total = drug.Total - num
  6826. // service.UpdateBaseDrugLib(&drug)
  6827. // }
  6828. //
  6829. // } else if advice.ID > 0 { //医嘱存在
  6830. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6831. // var num float64
  6832. //
  6833. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6834. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6835. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6836. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6837. // drug.Total = drug.Total + num
  6838. // service.UpdateBaseDrugLib(&drug)
  6839. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6840. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6841. // drug.Total = drug.Total - num
  6842. // service.UpdateBaseDrugLib(&drug)
  6843. // }
  6844. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6845. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6846. // if num2 > advice.PrescribingNumber {
  6847. // num = num2 - advice.PrescribingNumber
  6848. // drug.Total = drug.Total + num
  6849. // service.UpdateBaseDrugLib(&drug)
  6850. // } else if num2 < advice.PrescribingNumber {
  6851. // num = advice.PrescribingNumber - num2
  6852. // drug.Total = drug.Total - num
  6853. // service.UpdateBaseDrugLib(&drug)
  6854. // }
  6855. //
  6856. // }
  6857. //
  6858. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6859. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6860. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6861. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6862. // if num1 > num2 {
  6863. // num = num1 - num2
  6864. // drug.Total = drug.Total + num
  6865. // service.UpdateBaseDrugLib(&drug)
  6866. // } else if num1 < num2 {
  6867. // num = num2 - num1
  6868. // drug.Total = drug.Total - num
  6869. // service.UpdateBaseDrugLib(&drug)
  6870. // }
  6871. //
  6872. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6873. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6874. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6875. // if hisAdvice.PrescribingNumber > num2 {
  6876. // num = hisAdvice.PrescribingNumber - num2
  6877. // drug.Total = drug.Total + num
  6878. // service.UpdateBaseDrugLib(&drug)
  6879. // } else if num2 < advice.PrescribingNumber {
  6880. // num = num2 - hisAdvice.PrescribingNumber
  6881. // drug.Total = drug.Total - num
  6882. // service.UpdateBaseDrugLib(&drug)
  6883. // }
  6884. //
  6885. // }
  6886. // }
  6887. // }
  6888. //}
  6889. //
  6890. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6891. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6892. // advice.ExecutionTime = execution_time
  6893. //}
  6894. //
  6895. //
  6896. //
  6897. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6898. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6899. // advice.ExecutionStaff = execution_staff
  6900. //}
  6901. //
  6902. //
  6903. //
  6904. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6905. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6906. // advice.ExecutionState = execution_state
  6907. //}
  6908. //
  6909. //
  6910. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6911. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6912. // advice.CheckTime = check_time
  6913. //}
  6914. //
  6915. //
  6916. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6917. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6918. // advice.CheckState = check_state
  6919. //}
  6920. //
  6921. //
  6922. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6923. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6924. // advice.Checker = checker
  6925. //}
  6926. //
  6927. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6928. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6929. // advice.StartTime = start_time
  6930. //}
  6931. return 0
  6932. }
  6933. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6934. project.ExecutionStaff = 0
  6935. project.ExecutionState = 2
  6936. project.ExecutionTime = 0
  6937. project.Checker = 0
  6938. project.CheckState = 2
  6939. project.CheckTime = 0
  6940. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6941. id := int64(json["id"].(float64))
  6942. project.ID = id
  6943. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6944. project.ExecutionStaff = temp_project.ExecutionStaff
  6945. project.ExecutionState = temp_project.ExecutionState
  6946. project.ExecutionTime = temp_project.ExecutionTime
  6947. project.Checker = temp_project.Checker
  6948. project.CheckState = temp_project.CheckState
  6949. project.CheckTime = temp_project.CheckTime
  6950. project.TeamId = temp_project.TeamId
  6951. }
  6952. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6953. types := int64(json["type"].(float64))
  6954. project.Type = types
  6955. }
  6956. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6957. project_id := int64(json["project_id"].(float64))
  6958. project.ProjectId = project_id
  6959. }
  6960. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6961. team_id := int64(json["team_id"].(float64))
  6962. project.TeamId = team_id
  6963. }
  6964. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6965. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6966. project.Price = price
  6967. }
  6968. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6969. total, _ := json["total"].(string)
  6970. //totals, _ := strconv.ParseInt(total, 10, 64)
  6971. project.Count = total
  6972. }
  6973. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6974. medical_code, _ := json["medical_code"].(string)
  6975. project.MedListCodg = medical_code
  6976. }
  6977. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6978. single_dose, _ := json["single_dose"].(string)
  6979. project.SingleDose = single_dose
  6980. }
  6981. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6982. delivery_way, _ := json["delivery_way"].(string)
  6983. project.DeliveryWay = delivery_way
  6984. }
  6985. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6986. execution_frequency, _ := json["execution_frequency"].(string)
  6987. project.ExecutionFrequency = execution_frequency
  6988. }
  6989. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6990. remark, _ := json["remark"].(string)
  6991. project.Remark = remark
  6992. }
  6993. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6994. day, _ := json["number_days"].(string)
  6995. project.Day = day
  6996. }
  6997. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6998. unit, _ := json["unit"].(string)
  6999. project.Unit = unit
  7000. }
  7001. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7002. // frequency_type := int64(json["frequency_type"].(float64))
  7003. // project.FrequencyType = frequency_type
  7004. //}
  7005. //
  7006. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7007. // day_count := int64(json["day_count"].(float64))
  7008. // project.DayCount = day_count
  7009. //}
  7010. //
  7011. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7012. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7013. // week_day, _ := json["week_day"].(string)
  7014. // project.WeekDay = week_day
  7015. //}
  7016. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7017. //
  7018. //if project.ID == 0 {
  7019. // if stockConfig.IsOpen == 1 {
  7020. // if project.Type == 3 {
  7021. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7022. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7023. // good.Total = good.Total - f_count
  7024. // service.UpdateGoodInfo(&good)
  7025. // }
  7026. // }
  7027. //
  7028. //} else {
  7029. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7030. //
  7031. // if stockConfig.IsOpen == 1 {
  7032. // if project.Type == 3 {
  7033. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7034. // if project.Count < temp_project.Count {
  7035. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7036. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7037. //
  7038. // other_count := f_count_two - f_count_one
  7039. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7040. // good.Total = good.Total + other_count_two
  7041. // service.UpdateGoodInfo(&good)
  7042. // } else if project.Count > temp_project.Count {
  7043. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7044. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7045. //
  7046. // other_count := f_count_one - f_count_two
  7047. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7048. // good.Total = good.Total - other_count_two
  7049. // service.UpdateGoodInfo(&good)
  7050. // }
  7051. //
  7052. // }
  7053. // }
  7054. //
  7055. //}
  7056. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7057. id := int64(json["id"].(float64))
  7058. if id > 0 {
  7059. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7060. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7061. fmt.Println("666666")
  7062. project.Mtime = time.Now().Unix()
  7063. project.Ctime = temp_project.Ctime
  7064. } else {
  7065. project.Mtime = temp_project.Mtime
  7066. project.Ctime = temp_project.Ctime
  7067. }
  7068. } else {
  7069. ctime := time.Now().Unix()
  7070. project.Mtime = ctime
  7071. project.Ctime = ctime
  7072. }
  7073. }
  7074. return 0
  7075. }
  7076. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7077. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7078. id := int64(json["id"].(float64))
  7079. additionalCharge.ID = id
  7080. }
  7081. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7082. item_id := int64(json["item_id"].(float64))
  7083. additionalCharge.ItemId = item_id
  7084. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7085. if config.ID > 0 {
  7086. if len(config.Code) > 0 {
  7087. additionalCharge.MedListCodg = config.Code
  7088. }
  7089. }
  7090. }
  7091. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7092. // price := int64(json["price"].(float64))
  7093. // formatInt_price := strconv.FormatInt(price, 10)
  7094. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7095. // additionalCharge.Price = float_price
  7096. // }
  7097. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7098. // price := int64(json["price"].(float64))
  7099. // formatInt_price := strconv.FormatInt(price, 10)
  7100. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7101. // additionalCharge.Price = float_price
  7102. //}
  7103. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7104. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7105. additionalCharge.Price = price
  7106. }
  7107. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7108. count, _ := json["count"].(string)
  7109. counts, _ := strconv.ParseInt(count, 10, 64)
  7110. additionalCharge.Count = counts
  7111. }
  7112. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7113. item_name, _ := json["item_name"].(string)
  7114. additionalCharge.ItemName = item_name
  7115. }
  7116. return 0
  7117. }
  7118. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7119. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7120. utils.ErrorLog("drug_name")
  7121. return enums.ErrorCodeParamWrong
  7122. }
  7123. adviceName, _ := json["drug_name"].(string)
  7124. if len(adviceName) == 0 {
  7125. utils.ErrorLog("len(advice_name) == 0")
  7126. return enums.ErrorCodeParamWrong
  7127. }
  7128. advice.AdviceName = adviceName
  7129. adviceDesc, _ := json["advice_desc"].(string)
  7130. advice.AdviceDesc = adviceDesc
  7131. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7132. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7133. advice.DrugSpec = drugSpec
  7134. }
  7135. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7136. remark, _ := json["remark"].(string)
  7137. advice.Remark = remark
  7138. }
  7139. if json["id"] == nil {
  7140. advice.DrugId = 0
  7141. } else {
  7142. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7143. drug_id := int64(json["id"].(float64))
  7144. advice.DrugId = drug_id
  7145. }
  7146. }
  7147. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7148. groupno := int64(json["groupno"].(float64))
  7149. advice.Groupno = groupno
  7150. }
  7151. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7152. drugSpecUnit, _ := json["min_unit"].(string)
  7153. advice.DrugSpecUnit = drugSpecUnit
  7154. }
  7155. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7156. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7157. advice.SingleDose = singleDose
  7158. }
  7159. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7160. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7161. advice.SingleDoseUnit = singleDoseUnit
  7162. }
  7163. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7164. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7165. advice.PrescribingNumber = prescribingNumber
  7166. }
  7167. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7168. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7169. advice.PrescribingNumberUnit = prescribingNumberUnit
  7170. }
  7171. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7172. deliveryWay, _ := json["delivery_way"].(string)
  7173. advice.DeliveryWay = deliveryWay
  7174. }
  7175. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7176. executionFrequency, _ := json["execution_frequency"].(string)
  7177. advice.ExecutionFrequency = executionFrequency
  7178. }
  7179. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7180. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7181. advice.Price = price
  7182. }
  7183. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7184. med_list_codg, _ := json["medical_insurance_number"].(string)
  7185. advice.MedListCodg = med_list_codg
  7186. }
  7187. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7188. day := int64(json["day"].(float64))
  7189. advice.Day = day
  7190. }
  7191. advice.FrequencyType = 1
  7192. return 0
  7193. }
  7194. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7195. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7196. types := int64(json["type"].(float64))
  7197. project.Type = types
  7198. }
  7199. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7200. project_id := int64(json["project_id"].(float64))
  7201. project.ProjectId = project_id
  7202. }
  7203. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7204. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7205. project.Price = price
  7206. }
  7207. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7208. total, _ := json["total"].(string)
  7209. //totals, _ := strconv.ParseInt(total, 10, 64)
  7210. project.Count = total
  7211. }
  7212. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7213. medical_code, _ := json["medical_code"].(string)
  7214. project.MedListCodg = medical_code
  7215. }
  7216. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7217. single_dose, _ := json["single_dose"].(string)
  7218. project.SingleDose = single_dose
  7219. }
  7220. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7221. delivery_way, _ := json["delivery_way"].(string)
  7222. project.DeliveryWay = delivery_way
  7223. }
  7224. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7225. execution_frequency, _ := json["execution_frequency"].(string)
  7226. project.ExecutionFrequency = execution_frequency
  7227. }
  7228. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7229. remark, _ := json["remark"].(string)
  7230. project.Remark = remark
  7231. }
  7232. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7233. day, _ := json["number_days"].(string)
  7234. project.Day = day
  7235. }
  7236. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7237. unit, _ := json["unit"].(string)
  7238. project.Unit = unit
  7239. }
  7240. project.FrequencyType = 1
  7241. return 0
  7242. }
  7243. func (c *HisApiController) GetHisOrderListTwo() {
  7244. start_time := c.GetString("start_time")
  7245. end_time := c.GetString("end_time")
  7246. timeLayout := "2006-01-02"
  7247. loc, _ := time.LoadLocation("Local")
  7248. var startTime int64
  7249. if len(start_time) > 0 {
  7250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7251. if err != nil {
  7252. //fmt.Println(err)
  7253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7254. return
  7255. }
  7256. startTime = theTime.Unix()
  7257. }
  7258. var endTime int64
  7259. if len(end_time) > 0 {
  7260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7261. if err != nil {
  7262. utils.ErrorLog(err.Error())
  7263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7264. return
  7265. }
  7266. endTime = theTime.Unix()
  7267. }
  7268. adminUser := c.GetAdminUserInfo()
  7269. org_id := adminUser.CurrentOrgId
  7270. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7271. if err == nil {
  7272. c.ServeSuccessJSON(map[string]interface{}{
  7273. "order2": order,
  7274. })
  7275. } else {
  7276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7277. return
  7278. }
  7279. }
  7280. func (c *HisApiController) GetHisOrderList() {
  7281. page, _ := c.GetInt64("page", -1)
  7282. limit, _ := c.GetInt64("limit", -1)
  7283. start_time := c.GetString("start_time")
  7284. end_time := c.GetString("end_time")
  7285. types, _ := c.GetInt64("type", 0)
  7286. keywords := c.GetString("keywords")
  7287. p_type, _ := c.GetInt64("p_type", 0)
  7288. sort_type, _ := c.GetInt64("sort_type", 0)
  7289. charge_type, _ := c.GetInt64("charge_type", 0)
  7290. sch_type, _ := c.GetInt64("sch_type", 0)
  7291. zone_type, _ := c.GetInt64("zone_type", 0)
  7292. med_type, _ := c.GetInt64("med_type", 0)
  7293. timeLayout := "2006-01-02"
  7294. loc, _ := time.LoadLocation("Local")
  7295. var startTime int64
  7296. if len(start_time) > 0 {
  7297. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7298. if err != nil {
  7299. //fmt.Println(err)
  7300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7301. return
  7302. }
  7303. startTime = theTime.Unix()
  7304. }
  7305. var endTime int64
  7306. if len(end_time) > 0 {
  7307. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7308. if err != nil {
  7309. utils.ErrorLog(err.Error())
  7310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7311. return
  7312. }
  7313. endTime = theTime.Unix()
  7314. }
  7315. adminUser := c.GetAdminUserInfo()
  7316. org_id := adminUser.CurrentOrgId
  7317. 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)
  7318. for _, item := range order {
  7319. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7320. item.DoctorName = info.Doctor
  7321. item.DepartmentName = info.XtHisDepartment.Name
  7322. }
  7323. if err == nil {
  7324. c.ServeSuccessJSON(map[string]interface{}{
  7325. "order": order,
  7326. "total": total,
  7327. })
  7328. } else {
  7329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7330. return
  7331. }
  7332. }
  7333. func (c *HisApiController) GetHisOrder() {
  7334. patient_id, _ := c.GetInt64("patient_id", 0)
  7335. number := c.GetString("number")
  7336. adminInfo := c.GetAdminUserInfo()
  7337. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7338. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7339. if err == nil {
  7340. c.ServeSuccessJSON(map[string]interface{}{
  7341. "order": order,
  7342. "prescription": prescriptions,
  7343. })
  7344. } else {
  7345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7346. return
  7347. }
  7348. }
  7349. func (c *HisApiController) GetHisPrescriptionList() {
  7350. record_date := c.GetString("record_date")
  7351. keywords := c.GetString("keywords")
  7352. page, _ := c.GetInt64("page")
  7353. limit, _ := c.GetInt64("limit")
  7354. sch_type, _ := c.GetInt64("sch_type")
  7355. timeLayout := "2006-01-02"
  7356. loc, _ := time.LoadLocation("Local")
  7357. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7358. if err != nil {
  7359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7360. return
  7361. }
  7362. recordDateTime := theTime.Unix()
  7363. adminInfo := c.GetAdminUserInfo()
  7364. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7365. //adminInfo := c.GetAdminUserInfo()
  7366. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7367. //fmt.Println(prescriptionOrder)
  7368. if err == nil {
  7369. c.ServeSuccessJSON(map[string]interface{}{
  7370. "order": prescriptionOrder,
  7371. "total": total,
  7372. })
  7373. } else {
  7374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7375. return
  7376. }
  7377. }
  7378. func (c *HisApiController) GetHisPrescriptionInfo() {
  7379. id, _ := c.GetInt64("id")
  7380. adminInfo := c.GetAdminUserInfo()
  7381. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7382. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7383. if err == nil {
  7384. c.ServeSuccessJSON(map[string]interface{}{
  7385. "order": prescriptionOrder,
  7386. "prescription": prescription,
  7387. })
  7388. } else {
  7389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7390. return
  7391. }
  7392. }
  7393. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7394. adminUser := c.GetAdminUserInfo()
  7395. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7396. c.ServeSuccessJSON(map[string]interface{}{
  7397. "config": config,
  7398. })
  7399. }
  7400. type ResultTwo struct {
  7401. ErrMsg interface{} `json:"err_msg"`
  7402. InfRefmsgid string `json:"inf_refmsgid"`
  7403. Infcode int64 `json:"infcode"`
  7404. Output struct {
  7405. Baseinfo struct {
  7406. Age float64 `json:"age"`
  7407. Brdy string `json:"brdy"`
  7408. Certno string `json:"certno"`
  7409. Gend string `json:"gend"`
  7410. Naty string `json:"naty"`
  7411. PsnCertType string `json:"psn_cert_type"`
  7412. PsnName string `json:"psn_name"`
  7413. PsnNo string `json:"psn_no"`
  7414. } `json:"baseinfo"`
  7415. Idetinfo []interface{} `json:"idetinfo"`
  7416. Iinfo []struct {
  7417. Balc float64 `json:"balc"`
  7418. CvlservFlag string `json:"cvlserv_flag"`
  7419. EmpName string `json:"emp_name"`
  7420. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7421. Insutype string `json:"insutype"`
  7422. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7423. PausInsuDate interface{} `json:"paus_insu_date"`
  7424. PsnInsuDate string `json:"psn_insu_date"`
  7425. PsnInsuStas string `json:"psn_insu_stas"`
  7426. PsnType string `json:"psn_type"`
  7427. } `json:"insuinfo"`
  7428. } `json:"output"`
  7429. RefmsgTime string `json:"refmsg_time"`
  7430. RespondTime string `json:"respond_time"`
  7431. Signtype interface{} `json:"signtype"`
  7432. WarnInfo interface{} `json:"warn_info"`
  7433. }
  7434. type ResultThree struct {
  7435. Cainfo interface{} `json:"cainfo"`
  7436. ErrMsg interface{} `json:"err_msg"`
  7437. InfRefmsgid string `json:"inf_refmsgid"`
  7438. Infcode int64 `json:"infcode"`
  7439. Output struct {
  7440. Data struct {
  7441. IptOtpNo string `json:"ipt_otp_no"`
  7442. MdtrtID string `json:"mdtrt_id"`
  7443. PsnNo string `json:"psn_no"`
  7444. } `json:"data"`
  7445. } `json:"output"`
  7446. RefmsgTime string `json:"refmsg_time"`
  7447. RespondTime string `json:"respond_time"`
  7448. Signtype interface{} `json:"signtype"`
  7449. WarnMsg interface{} `json:"warn_msg"`
  7450. }
  7451. type ResultFour struct {
  7452. Cainfo string `json:"cainfo"`
  7453. ErrMsg string `json:"err_msg"`
  7454. InfRefmsgid string `json:"inf_refmsgid"`
  7455. Infcode int64 `json:"infcode"`
  7456. Output struct {
  7457. Result []struct {
  7458. BasMednFlag string `json:"bas_medn_flag"`
  7459. ChldMedcFlag string `json:"chld_medc_flag"`
  7460. ChrgitmLv string `json:"chrgitm_lv"`
  7461. Cnt float64 `json:"cnt"`
  7462. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7463. DrtReimFlag string `json:"drt_reim_flag"`
  7464. FeedetlSn string `json:"feedetl_sn"`
  7465. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7466. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7467. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7468. ListSpItemFlag string `json:"list_sp_item_flag"`
  7469. LmtUsedFlag string `json:"lmt_used_flag"`
  7470. MedChrgitmType string `json:"med_chrgitm_type"`
  7471. Memo string `json:"memo"`
  7472. OverlmtAmt float64 `json:"overlmt_amt"`
  7473. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7474. Pric float64 `json:"pric"`
  7475. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7476. SelfpayProp float64 `json:"selfpay_prop"`
  7477. } `json:"result"`
  7478. } `json:"output"`
  7479. RefmsgTime string `json:"refmsg_time"`
  7480. RespondTime string `json:"respond_time"`
  7481. Signtype string `json:"signtype"`
  7482. WarnMsg string `json:"warn_msg"`
  7483. }
  7484. type ResultFive struct {
  7485. Insutype string `json:"insutype"`
  7486. }
  7487. type ResultSix struct {
  7488. Cainfo interface{} `json:"cainfo"`
  7489. ErrMsg interface{} `json:"err_msg"`
  7490. InfRefmsgid string `json:"inf_refmsgid"`
  7491. Infcode int64 `json:"infcode"`
  7492. Output struct {
  7493. } `json:"output"`
  7494. RefmsgTime string `json:"refmsg_time"`
  7495. RespondTime string `json:"respond_time"`
  7496. Signtype interface{} `json:"signtype"`
  7497. WarnMsg interface{} `json:"warn_msg"`
  7498. }
  7499. type ResultSeven struct {
  7500. Cainfo string `json:"cainfo"`
  7501. ErrMsg string `json:"err_msg"`
  7502. InfRefmsgid string `json:"inf_refmsgid"`
  7503. Infcode int64 `json:"infcode"`
  7504. Output struct {
  7505. Setldetail []interface{} `json:"setldetail"`
  7506. Setlinfo struct {
  7507. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7508. AcctPay float64 `json:"acct_pay"`
  7509. ActPayDedc float64 `json:"act_pay_dedc"`
  7510. Age float64 `json:"age"`
  7511. Balc float64 `json:"balc"`
  7512. Brdy string `json:"brdy"`
  7513. Certno string `json:"certno"`
  7514. ClrOptins string `json:"clr_optins"`
  7515. ClrType string `json:"clr_type"`
  7516. ClrWay string `json:"clr_way"`
  7517. CvlservFlag string `json:"cvlserv_flag"`
  7518. CvlservPay float64 `json:"cvlserv_pay"`
  7519. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7520. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7521. Gend string `json:"gend"`
  7522. HifesPay float64 `json:"hifes_pay"`
  7523. HifmiPay float64 `json:"hifmi_pay"`
  7524. HifobPay float64 `json:"hifob_pay"`
  7525. HifpPay float64 `json:"hifp_pay"`
  7526. HospPartAmt float64 `json:"hosp_part_amt"`
  7527. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7528. Insutype string `json:"insutype"`
  7529. MafPay float64 `json:"maf_pay"`
  7530. MdtrtCertType string `json:"mdtrt_cert_type"`
  7531. MdtrtID string `json:"mdtrt_id"`
  7532. MedType string `json:"med_type"`
  7533. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7534. MedinsSetlID string `json:"medins_setl_id"`
  7535. Naty string `json:"naty"`
  7536. OthPay float64 `json:"oth_pay"`
  7537. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7538. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7539. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7540. PsnCashPay float64 `json:"psn_cash_pay"`
  7541. PsnCertType string `json:"psn_cert_type"`
  7542. PsnName string `json:"psn_name"`
  7543. PsnNo string `json:"psn_no"`
  7544. PsnPartAmt float64 `json:"psn_part_amt"`
  7545. PsnType string `json:"psn_type"`
  7546. SetlID string `json:"setl_id"`
  7547. SetlTime string `json:"setl_time"`
  7548. } `json:"setlinfo"`
  7549. } `json:"output"`
  7550. RefmsgTime string `json:"refmsg_time"`
  7551. RespondTime string `json:"respond_time"`
  7552. Signtype interface{} `json:"signtype"`
  7553. WarnMsg interface{} `json:"warn_msg"`
  7554. }
  7555. type ResultEight struct {
  7556. Cainfo string `json:"cainfo"`
  7557. ErrMsg string `json:"err_msg"`
  7558. InfRefmsgid string `json:"inf_refmsgid"`
  7559. Infcode int64 `json:"infcode"`
  7560. Output struct {
  7561. Stmtinfo struct {
  7562. SetlOptins string `json:"setl_optins"`
  7563. StmtRslt string `json:"stmt_rslt"`
  7564. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7565. } `json:"stmtinfo"`
  7566. } `json:"output"`
  7567. RefmsgTime string `json:"refmsg_time"`
  7568. RespondTime string `json:"respond_time"`
  7569. Signtype interface{} `json:"signtype"`
  7570. WarnMsg interface{} `json:"warn_msg"`
  7571. }
  7572. type ResultNine struct {
  7573. Cainfo string `json:"cainfo"`
  7574. ErrMsg string `json:"err_msg"`
  7575. InfRefmsgid string `json:"inf_refmsgid"`
  7576. Infcode int64 `json:"infcode"`
  7577. Output struct {
  7578. FileQuryNo string `json:"file_qury_no"`
  7579. } `json:"output"`
  7580. RefmsgTime string `json:"refmsg_time"`
  7581. RespondTime string `json:"respond_time"`
  7582. Signtype interface{} `json:"signtype"`
  7583. WarnMsg interface{} `json:"warn_msg"`
  7584. }
  7585. type ResultTen struct {
  7586. Cainfo string `json:"cainfo"`
  7587. ErrMsg string `json:"err_msg"`
  7588. InfRefmsgid string `json:"inf_refmsgid"`
  7589. Infcode int64 `json:"infcode"`
  7590. Output struct {
  7591. DldEndtime string `json:"dld_endtime"`
  7592. FileQuryNo string `json:"file_qury_no"`
  7593. Filename string `json:"filename"`
  7594. } `json:"output"`
  7595. RefmsgTime string `json:"refmsg_time"`
  7596. RespondTime string `json:"respond_time"`
  7597. Signtype interface{} `json:"signtype"`
  7598. WarnMsg interface{} `json:"warn_msg"`
  7599. }
  7600. type ResultEleven struct {
  7601. Cainfo string `json:"cainfo"`
  7602. ErrMsg string `json:"err_msg"`
  7603. InfRefmsgid string `json:"inf_refmsgid"`
  7604. Infcode int64 `json:"infcode"`
  7605. Output struct {
  7606. Setlinfo struct {
  7607. FixmedinsName string `json:"fixmedins_name"`
  7608. FixmedinsCode string `json:"fixmedins_code"`
  7609. PsnNo string `json:"psn_no"`
  7610. PsnName string `json:"psn_name"`
  7611. HifobPay float64 `json:"hifob_pay"`
  7612. Gend string `json:"gend"`
  7613. Brdy string `json:"brdy"`
  7614. PsnCertType string `json:"psn_cert_type"`
  7615. PsnType string `json:"psn_type"`
  7616. EmpName string `json:"emp_name"`
  7617. Certno string `json:"certno"`
  7618. Insutype string `json:"insutype"`
  7619. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7620. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7621. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7622. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7623. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7624. ActPayDedc float64 `json:"act_pay_dedc"`
  7625. HifpPay float64 `json:"hifp_pay"`
  7626. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7627. CvlservPay float64 `json:"cvlserv_pay"`
  7628. HifesPay float64 `json:"hifes_pay"`
  7629. HifmiPay float64 `json:"hifmi_pay"`
  7630. MafPay float64 `json:"maf_pay"`
  7631. OthPay float64 `json:"oth_pay"`
  7632. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7633. PsnPay float64 `json:"psn_pay"`
  7634. AcctPay float64 `json:"acct_pay"`
  7635. CashPayamt float64 `json:"cash_payamt"`
  7636. Balc float64 `json:"balc"`
  7637. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7638. MedinsSetlId string `json:"medins_setl_id"`
  7639. RefdSetlFlag string `json:"refd_setl_flag"`
  7640. SetlTime string `json:"setl_time"`
  7641. MedType string `json:"med_type"`
  7642. } `json:"setlinfo"`
  7643. } `json:"output"`
  7644. RefmsgTime string `json:"refmsg_time"`
  7645. RespondTime string `json:"respond_time"`
  7646. Signtype interface{} `json:"signtype"`
  7647. WarnMsg interface{} `json:"warn_msg"`
  7648. }
  7649. type Custom struct {
  7650. DetItemFeeSumamt string
  7651. Cut string
  7652. FeedetlSn string
  7653. Price string
  7654. MedListCodg string
  7655. Type int64
  7656. AdviceId int64
  7657. ProjectId int64
  7658. ItemId int64
  7659. }
  7660. // 获取个人信息----挂号-----上传就诊信息
  7661. func (c *HisApiController) GetRegisterInfo() {
  7662. id, _ := c.GetInt64("id")
  7663. record_time := c.GetString("record_time")
  7664. settlementValue, _ := c.GetInt64("settlement_value")
  7665. medical_insurance_card := c.GetString("medical_insurance_card")
  7666. name := c.GetString("name")
  7667. id_card_type, _ := c.GetInt64("id_card_type")
  7668. certificates, _ := c.GetInt64("certificates")
  7669. medical_care, _ := c.GetInt64("medical_care")
  7670. birthday := c.GetString("birthday")
  7671. age, _ := c.GetInt64("age")
  7672. id_card := c.GetString("id_card")
  7673. register_type, _ := c.GetInt64("register")
  7674. doctor, _ := c.GetInt64("doctor")
  7675. department, _ := c.GetInt64("department")
  7676. gender, _ := c.GetInt64("sex")
  7677. phone := c.GetString("phone")
  7678. registration_fee, _ := c.GetFloat("registration_fee")
  7679. medical_expenses, _ := c.GetFloat("medical_expenses")
  7680. social_type, _ := c.GetInt64("social_type")
  7681. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7682. diagnosis_ids := c.GetString("diagnosis")
  7683. sick_type, _ := c.GetInt64("sick_type")
  7684. reg_type := c.GetString("p_type")
  7685. timeLayout := "2006-01-02"
  7686. loc, _ := time.LoadLocation("Local")
  7687. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7688. birthUnix := birthdays.Unix()
  7689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7690. if err != nil {
  7691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7692. return
  7693. }
  7694. recordDateTime := theTime.Unix()
  7695. adminInfo := c.GetAdminUserInfo()
  7696. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7697. if tempPatient.ID == 0 {
  7698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7699. return
  7700. }
  7701. var patient service.Patients
  7702. if id == 0 {
  7703. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7704. } else {
  7705. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7706. }
  7707. if patient.ID == 0 {
  7708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7709. return
  7710. }
  7711. if len(patient.IdCardNo) == 0 {
  7712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7713. return
  7714. }
  7715. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7716. if len(his) >= 1 {
  7717. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7718. if len(his) >= 1 && order.ID == 0 {
  7719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7720. return
  7721. }
  7722. }
  7723. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7724. fmt.Println(timeStr)
  7725. timeArr := strings.Split(timeStr, " ")
  7726. fmt.Println(timeArr)
  7727. timeArrTwo := strings.Split(timeArr[0], "-")
  7728. timeArrThree := strings.Split(timeArr[1], ":")
  7729. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7730. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7731. if len(lists) == 0 {
  7732. var hisPatient models.XtHisPatient
  7733. hisPatient = models.XtHisPatient{
  7734. Name: name,
  7735. Age: age,
  7736. Gender: gender,
  7737. Birthday: birthUnix,
  7738. Phone: phone,
  7739. MedicalTreatmentType: medical_care,
  7740. IdType: certificates,
  7741. IdCardNo: id_card,
  7742. BalanceAccountsType: settlementValue,
  7743. SocialType: social_type,
  7744. MedicalInsuranceNumber: medical_insurance_card,
  7745. RegisterType: register_type,
  7746. RegisterCost: registration_fee,
  7747. TreatmentCost: medical_expenses,
  7748. AdminUserId: adminInfo.AdminUser.Id,
  7749. UserOrgId: adminInfo.CurrentOrgId,
  7750. Status: 1,
  7751. RecordDate: recordDateTime,
  7752. IsReturn: 1,
  7753. PatientId: patient.ID,
  7754. Ctime: time.Now().Unix(),
  7755. Mtime: time.Now().Unix(),
  7756. Number: str,
  7757. IdCardType: id_card_type,
  7758. Departments: department,
  7759. Doctor: doctor,
  7760. PType: reg_type,
  7761. Diagnosis: diagnosis_ids,
  7762. SickType: sick_type,
  7763. }
  7764. service.CreateHisPatient(&hisPatient)
  7765. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7766. c.ServeSuccessJSON(map[string]interface{}{
  7767. "his_info": hisPatient,
  7768. })
  7769. } else {
  7770. //chrgBchno := rand.Intn(1000000) + 10000
  7771. var hisPatient models.XtHisPatient
  7772. hisPatient = models.XtHisPatient{
  7773. Name: name,
  7774. Age: age,
  7775. Gender: gender,
  7776. Birthday: birthUnix,
  7777. Phone: phone,
  7778. MedicalTreatmentType: medical_care,
  7779. IdType: certificates,
  7780. IdCardNo: id_card,
  7781. BalanceAccountsType: settlementValue,
  7782. SocialType: social_type,
  7783. MedicalInsuranceNumber: medical_insurance_card,
  7784. RegisterType: register_type,
  7785. RegisterCost: registration_fee,
  7786. TreatmentCost: medical_expenses,
  7787. AdminUserId: adminInfo.AdminUser.Id,
  7788. UserOrgId: adminInfo.CurrentOrgId,
  7789. Status: 1,
  7790. RecordDate: recordDateTime,
  7791. IsReturn: 1,
  7792. PatientId: patient.ID,
  7793. Ctime: time.Now().Unix(),
  7794. Mtime: time.Now().Unix(),
  7795. Number: str,
  7796. IdCardType: id_card_type,
  7797. Departments: department,
  7798. Doctor: doctor,
  7799. PType: reg_type,
  7800. Diagnosis: diagnosis_ids,
  7801. SickType: sick_type,
  7802. }
  7803. service.CreateHisPatient(&hisPatient)
  7804. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7805. c.ServeSuccessJSON(map[string]interface{}{
  7806. "his_info": hisPatient,
  7807. })
  7808. }
  7809. }
  7810. // 上传明细----结算
  7811. func (c *HisApiController) GetUploadInfo() {
  7812. id, _ := c.GetInt64("id")
  7813. record_time := c.GetString("record_time")
  7814. his_patient_id, _ := c.GetInt64("his_patient_id")
  7815. oth_desc := c.GetString("oth_desc")
  7816. pay_way, _ := c.GetInt64("pay_way")
  7817. pay_ways := c.GetString("pay_ways")
  7818. pay_price, _ := c.GetFloat("pay_price")
  7819. pay_card_no := c.GetString("pay_card_no")
  7820. discount_price, _ := c.GetFloat("discount_price")
  7821. preferential_price, _ := c.GetFloat("preferential_price")
  7822. reality_price, _ := c.GetFloat("reality_price")
  7823. found_price, _ := c.GetFloat("found_price")
  7824. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7825. private_price, _ := c.GetFloat("private_price")
  7826. timeLayout := "2006-01-02"
  7827. loc, _ := time.LoadLocation("Local")
  7828. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7829. fapiao_code := c.GetString("fapiao_code")
  7830. fapiao_number := c.GetString("fapiao_number")
  7831. diagnosis_id := c.GetString("diagnosis")
  7832. sick_type, _ := c.GetInt64("sick_type")
  7833. reg_type, _ := c.GetInt64("p_type")
  7834. order_id, _ := c.GetInt64("order_id")
  7835. cash_pay := c.GetString("cash_pay")
  7836. wechat_pay := c.GetString("wechat_pay")
  7837. ali_pay := c.GetString("ali_pay")
  7838. jifen_pay := c.GetString("jifen_pay")
  7839. band_card_pay := c.GetString("band_card_pay")
  7840. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7841. tmp_decimal := c.GetString("tmp_decimal")
  7842. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7843. var decimal float64 //本次使用的押金
  7844. var errmsg error
  7845. tx := service.XTWriteDB().Begin() //开了事务
  7846. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7847. defer func() {
  7848. if errmsg != nil {
  7849. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7850. tx.Rollback()
  7851. } else {
  7852. tx.Commit()
  7853. }
  7854. }()
  7855. fmt.Println("dec_way", dec_way)
  7856. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7857. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7858. return
  7859. }
  7860. if len(tmp_decimal) > 0 {
  7861. if tmp_decimal[0] == 45 {
  7862. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7863. return
  7864. }
  7865. }
  7866. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7867. fmt.Println(errs)
  7868. decimal = tt
  7869. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7870. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7872. if err != nil {
  7873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7874. return
  7875. }
  7876. recordDateTime := theTime.Unix()
  7877. adminUser := c.GetAdminUserInfo()
  7878. var prescriptions []*models.HisPrescription
  7879. var prescriptionsOne []*models.HisPrescription
  7880. var start_time int64
  7881. var end_time int64
  7882. ids_str := c.GetString("ids")
  7883. ids_arr := strings.Split(ids_str, ",")
  7884. if tempOrder.ID == 0 {
  7885. if settle_accounts_type == 1 { //日结
  7886. fmt.Println(reg_type)
  7887. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7888. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7889. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7890. } else {
  7891. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7892. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7893. }
  7894. } else { //月结
  7895. start_time_str := c.GetString("start_time")
  7896. end_time_str := c.GetString("end_time")
  7897. timeLayout := "2006-01-02"
  7898. loc, _ := time.LoadLocation("Local")
  7899. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7900. if err != nil {
  7901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7902. return
  7903. }
  7904. recordStartTime := theStartTime.Unix()
  7905. start_time = recordStartTime
  7906. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7907. if err != nil {
  7908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7909. return
  7910. }
  7911. recordEndTime := theEndTime.Unix()
  7912. end_time = recordEndTime
  7913. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7914. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7915. }
  7916. var goods []*models.DialysisBeforePrepareGoods
  7917. var newGoods []*models.NewDialysisBeforePrepareGoods
  7918. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7919. var infos []*models.HisDoctorAdviceInfo
  7920. var infoList []*models.HisDoctorAdviceInfo
  7921. var hisAdvice []*models.HisDoctorAdviceInfo
  7922. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7923. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7924. //判断库存不足
  7925. //结算出库开关
  7926. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7927. if settConfig.IsOpen == 1 {
  7928. //判断库存的地方
  7929. for _, info := range prescriptions {
  7930. if info.Type == 1 {
  7931. infos = append(infos, info.HisDoctorAdviceInfo...)
  7932. }
  7933. if info.Type == 2 {
  7934. for _, sumItem := range info.HisPrescriptionProject {
  7935. if sumItem.Type == 3 {
  7936. var good models.DialysisBeforePrepareGoods
  7937. var newGood models.NewDialysisBeforePrepareGoods
  7938. good.GoodId = sumItem.GoodInfo.ID
  7939. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7940. count, _ := strconv.Atoi(sumItem.Count)
  7941. good.Count = int64(count)
  7942. good.StorehouseId = houseConfig.StorehouseOutInfo
  7943. good.ProjectId = sumItem.ID
  7944. goods = append(goods, &good)
  7945. newGood.GoodId = sumItem.GoodInfo.ID
  7946. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7947. count2, _ := strconv.Atoi(sumItem.Count)
  7948. newGood.Count = int64(count2)
  7949. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7950. newGood.ProjectId = sumItem.ID
  7951. newGoods = append(newGoods, &newGood)
  7952. }
  7953. }
  7954. }
  7955. }
  7956. for _, info := range prescriptionsOne {
  7957. if info.Type == 1 {
  7958. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7959. }
  7960. if info.Type == 2 {
  7961. for _, sumItem := range info.HisPrescriptionProject {
  7962. if sumItem.Type == 3 {
  7963. var newGood models.NewDialysisBeforePrepareGoods
  7964. newGood.GoodId = sumItem.GoodInfo.ID
  7965. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7966. count2, _ := strconv.Atoi(sumItem.Count)
  7967. newGood.Count = int64(count2)
  7968. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7969. newGood.ProjectId = sumItem.ID
  7970. newGoodOne = append(newGoodOne, &newGood)
  7971. }
  7972. }
  7973. }
  7974. }
  7975. //判断
  7976. for _, itemOne := range infos {
  7977. for _, itemTwo := range hisAdvice {
  7978. if itemOne.DrugId == itemTwo.DrugId {
  7979. itemTwo.Child = append(itemTwo.Child, itemOne)
  7980. }
  7981. }
  7982. }
  7983. for _, itemTwo := range hisAdvice {
  7984. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7985. var sum_out_count int64
  7986. for _, itemThree := range itemTwo.Child {
  7987. var prescribing_number int64
  7988. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7989. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7990. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7991. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7992. }
  7993. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7994. prescribing_number = parseIntPrescribingNumber
  7995. }
  7996. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7997. prescribing_number = parseIntPrescribingNumber
  7998. }
  7999. sum_out_count += prescribing_number
  8000. }
  8001. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8002. if sum_out_count > drugStockOut.FlushCount {
  8003. c.ServeSuccessJSON(map[string]interface{}{
  8004. "msg": "2",
  8005. "drug": medical,
  8006. })
  8007. return
  8008. }
  8009. }
  8010. for _, itemOne := range newGoods {
  8011. for _, item := range newGoodOne {
  8012. if itemOne.GoodId == item.GoodId {
  8013. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8014. }
  8015. }
  8016. }
  8017. for _, item := range newGoodOne {
  8018. var sum_out_count_one int64
  8019. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8020. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8021. sum_out_count_one += itemOne.Count
  8022. }
  8023. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8024. fmt.Println("sum_out_count_one", sum_out_count_one)
  8025. fmt.Println("list.FlushCount", list.FlushCount)
  8026. if sum_out_count_one > list.FlushCount {
  8027. c.ServeSuccessJSON(map[string]interface{}{
  8028. "msg": "3",
  8029. "good": good,
  8030. })
  8031. return
  8032. }
  8033. }
  8034. }
  8035. timestamp := time.Now().Unix()
  8036. tempTime := time.Unix(timestamp, 0)
  8037. timeFormat := tempTime.Format("20060102150405")
  8038. chrgBchno := rand.Intn(100000) + 10000
  8039. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8040. strconv.FormatInt(his.PatientId, 10)
  8041. var ids []int64
  8042. for _, item := range prescriptions {
  8043. ids = append(ids, item.ID)
  8044. }
  8045. var total float64
  8046. for _, item := range prescriptions {
  8047. fmt.Println(item)
  8048. if item.Type == 1 { //药品
  8049. for _, subItem := range item.HisDoctorAdviceInfo {
  8050. total = total + (subItem.Price * subItem.PrescribingNumber)
  8051. }
  8052. }
  8053. if item.Type == 2 { //项目
  8054. for _, subItem := range item.HisPrescriptionProject {
  8055. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8056. total = total + (subItem.Price * cnt)
  8057. }
  8058. }
  8059. for _, subItem := range item.HisAdditionalCharge {
  8060. total = total + (subItem.Price * float64(subItem.Count))
  8061. }
  8062. }
  8063. if reg_type == 1111 || reg_type == 1112 {
  8064. reg_type = 11
  8065. }
  8066. tm := time.Unix(time.Now().Unix(), 0)
  8067. allTotal := fmt.Sprintf("%.4f", total)
  8068. totals, _ := strconv.ParseFloat(allTotal, 64)
  8069. order := &models.HisOrder{
  8070. UserOrgId: adminUser.CurrentOrgId,
  8071. HisPatientId: his.ID,
  8072. PatientId: id,
  8073. SettleAccountsDate: recordDateTime,
  8074. Ctime: time.Now().Unix(),
  8075. Mtime: time.Now().Unix(),
  8076. Status: 1,
  8077. OrderStatus: 2,
  8078. MdtrtId: his.Number,
  8079. Number: chrg_bchno,
  8080. MedfeeSumamt: totals,
  8081. PayWay: pay_way,
  8082. PayWays: pay_ways,
  8083. PayPrice: pay_price,
  8084. MedType: strconv.Itoa(int(reg_type)),
  8085. PayCardNo: pay_card_no,
  8086. DiscountPrice: discount_price,
  8087. PreferentialPrice: preferential_price,
  8088. RealityPrice: reality_price,
  8089. FoundPrice: found_price,
  8090. MedicalInsurancePrice: medical_insurance_price,
  8091. PrivatePrice: private_price,
  8092. SettleEndTime: end_time,
  8093. SettleStartTime: start_time,
  8094. PsnPartAmt: totals,
  8095. PsnCashPay: totals,
  8096. SettleType: settle_accounts_type,
  8097. FaPiaoCode: fapiao_code,
  8098. FaPiaoNumber: fapiao_number,
  8099. Diagnosis: diagnosis_id,
  8100. PType: 2,
  8101. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8102. Decimal: decimal,
  8103. OthDesc: oth_desc,
  8104. CashPay: cash_pay,
  8105. WechatPay: wechat_pay,
  8106. AliPay: ali_pay,
  8107. JifenPay: jifen_pay,
  8108. BandCardPay: band_card_pay,
  8109. Creator: adminUser.AdminUser.Id,
  8110. }
  8111. err = service.CreateOrderTX(order, tx)
  8112. if err != nil {
  8113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8114. return
  8115. }
  8116. var customs []*Custom
  8117. for _, item := range prescriptions {
  8118. if item.Type == 1 { //药品a
  8119. for _, subItem := range item.HisDoctorAdviceInfo {
  8120. cus := &Custom{
  8121. AdviceId: subItem.ID,
  8122. ProjectId: 0,
  8123. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8124. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8125. FeedetlSn: subItem.FeedetlSn,
  8126. Price: fmt.Sprintf("%.4f", subItem.Price),
  8127. MedListCodg: subItem.MedListCodg,
  8128. Type: 1,
  8129. }
  8130. customs = append(customs, cus)
  8131. }
  8132. }
  8133. if item.Type == 2 { //项目
  8134. for _, subItem := range item.HisPrescriptionProject {
  8135. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8136. cus := &Custom{
  8137. AdviceId: 0,
  8138. ProjectId: subItem.ID,
  8139. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8140. Cut: fmt.Sprintf("%.4f", cnt),
  8141. FeedetlSn: subItem.FeedetlSn,
  8142. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8143. MedListCodg: subItem.MedListCodg,
  8144. Type: 2,
  8145. }
  8146. customs = append(customs, cus)
  8147. }
  8148. }
  8149. for _, item := range item.HisAdditionalCharge {
  8150. cus := &Custom{
  8151. ItemId: item.ID,
  8152. AdviceId: 0,
  8153. ProjectId: 0,
  8154. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8155. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8156. FeedetlSn: item.FeedetlSn,
  8157. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8158. MedListCodg: item.XtHisAddtionConfig.Code,
  8159. Type: 3,
  8160. }
  8161. customs = append(customs, cus)
  8162. }
  8163. }
  8164. for _, item := range customs {
  8165. var advice_id int64 = 0
  8166. var project_id int64 = 0
  8167. var item_id int64 = 0
  8168. var types int64 = 0
  8169. if item.Type == 1 {
  8170. advice_id = item.AdviceId
  8171. project_id = 0
  8172. item_id = 0
  8173. } else if item.Type == 2 {
  8174. advice_id = 0
  8175. item_id = 0
  8176. project_id = item.ProjectId
  8177. } else if item.Type == 3 {
  8178. advice_id = 0
  8179. item_id = item.ItemId
  8180. project_id = 0
  8181. }
  8182. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8183. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8184. pric, _ := strconv.ParseFloat(item.Price, 32)
  8185. info := &models.HisOrderInfo{
  8186. OrderNumber: order.Number,
  8187. UploadDate: time.Now().Unix(),
  8188. AdviceId: advice_id,
  8189. DetItemFeeSumamt: detItemFeeSumamt,
  8190. Cnt: cut,
  8191. Pric: pric,
  8192. PatientId: id,
  8193. Status: 1,
  8194. Mtime: time.Now().Unix(),
  8195. Ctime: time.Now().Unix(),
  8196. UserOrgId: adminUser.CurrentOrgId,
  8197. HisPatientId: his.ID,
  8198. OrderId: order.ID,
  8199. ProjectId: project_id,
  8200. Type: types,
  8201. ItemId: item_id,
  8202. }
  8203. service.CreateOrderInfoTX(info, tx)
  8204. }
  8205. his.Diagnosis = diagnosis_id
  8206. his.SickType = sick_type
  8207. his.RegisterType = reg_type
  8208. his.MedicalTreatmentType = reg_type
  8209. service.UpdataHisPateintTX(&his, tx)
  8210. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8211. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8212. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8213. //判断是否使用了押金
  8214. if dec_way == "true" {
  8215. tmpstring := strconv.FormatInt(order.ID, 10)
  8216. //扣押金
  8217. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8218. order.Decimal = decimal
  8219. service.UpDateOrderTwo(order, tx)
  8220. if errmsg != nil {
  8221. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8222. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8223. return
  8224. }
  8225. }
  8226. if err == nil {
  8227. for _, info := range prescriptions {
  8228. if info.Type == 1 {
  8229. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8230. }
  8231. if info.Type == 2 {
  8232. for _, sumItem := range info.HisPrescriptionProject {
  8233. if sumItem.Type == 3 {
  8234. var good models.DialysisBeforePrepareGoods
  8235. var newGood models.NewDialysisBeforePrepareGoods
  8236. var oldGood models.OldDialysisBeforePrepareGoods
  8237. good.GoodId = sumItem.GoodInfo.ID
  8238. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8239. count, _ := strconv.Atoi(sumItem.Count)
  8240. good.Count = int64(count)
  8241. good.StorehouseId = houseConfig.StorehouseOutInfo
  8242. good.ProjectId = sumItem.ID
  8243. good.PatientId = sumItem.PatientId
  8244. goods = append(goods, &good)
  8245. newGood.GoodId = sumItem.GoodInfo.ID
  8246. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8247. count2, _ := strconv.Atoi(sumItem.Count)
  8248. newGood.Count = int64(count2)
  8249. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8250. newGood.ProjectId = sumItem.ID
  8251. newGood.PatientId = sumItem.HisPatientId
  8252. newGoods = append(newGoods, &newGood)
  8253. oldGood.GoodId = sumItem.GoodInfo.ID
  8254. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8255. count3, _ := strconv.Atoi(sumItem.Count)
  8256. oldGood.Count = int64(count3)
  8257. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8258. oldGood.ProjectId = sumItem.ID
  8259. oldGood.RecordDate = sumItem.RecordDate
  8260. oldGood.PatientId = sumItem.HisPatientId
  8261. oldGoods = append(oldGoods, &oldGood)
  8262. }
  8263. }
  8264. }
  8265. }
  8266. if settConfig.IsOpen == 1 {
  8267. for _, item := range infoList {
  8268. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8269. if medical.IsUse == 2 {
  8270. //药品出库
  8271. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8272. //查询默认仓库
  8273. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8274. //查询默认仓库剩余多少库存
  8275. var sum_count int64
  8276. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8277. for _, its := range stockInfo {
  8278. if its.MaxUnit == medical.MaxUnit {
  8279. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8280. }
  8281. sum_count += its.StockMaxNumber + its.StockMinNumber
  8282. }
  8283. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8284. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8285. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8286. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8287. }
  8288. }
  8289. orgId := c.GetAdminUserInfo().CurrentOrgId
  8290. if len(oldGoods) > 0 {
  8291. timeStr := time.Now().Format("2006-01-02")
  8292. timeArr := strings.Split(timeStr, "-")
  8293. total, _ := service.FindAllWarehouseOut(orgId)
  8294. total = total + 1
  8295. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8296. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8297. number = number + total
  8298. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8299. operation_time := time.Now().Unix()
  8300. creater := c.GetAdminUserInfo().AdminUser.Id
  8301. //查询默认出库仓库库存
  8302. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8303. recordDateStr := time.Now().Format("2006-01-02")
  8304. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8305. nowtime := recordDate.Unix()
  8306. warehouseOut := models.WarehouseOut{
  8307. WarehouseOutOrderNumber: warehousing_out_order,
  8308. OperationTime: operation_time,
  8309. OrgId: orgId,
  8310. Creater: creater,
  8311. Ctime: time.Now().Unix(),
  8312. Status: 1,
  8313. WarehouseOutTime: nowtime,
  8314. Type: 1,
  8315. StorehouseId: storeConfig.StorehouseOutInfo,
  8316. IsCheck: 1,
  8317. OrderId: order.ID,
  8318. IsSys: 5,
  8319. }
  8320. //查询是否生成出库单
  8321. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8322. if out.ID == 0 {
  8323. service.AddSigleWarehouseOut(&warehouseOut)
  8324. }
  8325. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8326. for _, item := range oldGoods {
  8327. dialyPrepareOne := models.DialysisBeforePrepare{
  8328. GoodTypeId: item.GoodTypeId,
  8329. GoodId: item.GoodId,
  8330. PatientId: his.PatientId,
  8331. RecordDate: item.RecordDate,
  8332. UserOrgId: adminUser.CurrentOrgId,
  8333. Count: item.Count,
  8334. Ctime: time.Now().Unix(),
  8335. Creater: adminUser.AdminUser.Id,
  8336. CommdityCode: item.CommdityCode,
  8337. Status: 1,
  8338. StorehouseId: houseConfig.StorehouseOutInfo,
  8339. }
  8340. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8341. //非零用
  8342. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8343. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8344. //查询剩余库存
  8345. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8346. var sum_count int64
  8347. for _, item := range goodList {
  8348. sum_count += item.StockCount
  8349. }
  8350. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8351. //耗材
  8352. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8353. }
  8354. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8355. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8356. //查询剩余库存
  8357. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8358. var sum_count int64
  8359. for _, item := range goodList {
  8360. sum_count += item.StockCount
  8361. }
  8362. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8363. //耗材
  8364. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8365. }
  8366. }
  8367. }
  8368. }
  8369. c.ServeSuccessJSON(map[string]interface{}{
  8370. "msg": "结算成功",
  8371. })
  8372. }
  8373. }
  8374. }
  8375. // 退款
  8376. func (c *HisApiController) Refund() {
  8377. order_id, _ := c.GetInt64("order_id")
  8378. order, _ := service.GetHisOrderByID(order_id)
  8379. adminUser := c.GetAdminUserInfo()
  8380. orgid := c.GetAdminUserInfo().CurrentOrgId
  8381. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8382. if err != nil {
  8383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8384. return
  8385. }
  8386. tmp := strconv.FormatInt(order.ID, 10)
  8387. //当押金不为零时产生退费记录
  8388. if order.Decimal != 0 {
  8389. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8390. if err != nil {
  8391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8392. return
  8393. }
  8394. }
  8395. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8396. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8397. var goods []*models.DialysisBeforePrepareGoods
  8398. var newGoods []*models.NewDialysisBeforePrepareGoods
  8399. var infos []*models.HisDoctorAdviceInfo
  8400. for _, info := range orders {
  8401. if info.AdviceId > 0 && info.ProjectId == 0 {
  8402. infos = append(infos, &info.HisDoctorAdviceInfo)
  8403. }
  8404. if info.ProjectId > 0 && info.AdviceId == 0 {
  8405. if info.HisPrescriptionProject.Type == 3 {
  8406. var good models.DialysisBeforePrepareGoods
  8407. var newGood models.NewDialysisBeforePrepareGoods
  8408. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8409. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8410. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8411. good.Count = int64(count)
  8412. good.StorehouseId = houseConfig.StorehouseOutInfo
  8413. good.ProjectId = info.HisPrescriptionProject.ID
  8414. good.PatientId = info.PatientId
  8415. good.OrderId = order_id
  8416. goods = append(goods, &good)
  8417. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8418. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8419. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8420. newGood.Count = int64(count2)
  8421. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8422. newGood.ProjectId = info.HisPrescriptionProject.ID
  8423. newGood.RecordDate = order.SettleAccountsDate
  8424. newGood.UserOrgId = order.UserOrgId
  8425. newGood.PatientId = info.PatientId
  8426. newGood.OrderId = order_id
  8427. newGoods = append(newGoods, &newGood)
  8428. }
  8429. }
  8430. }
  8431. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8432. if settConfig.IsOpen == 1 {
  8433. for _, item := range infos {
  8434. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8435. }
  8436. for _, item := range newGoods {
  8437. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8438. }
  8439. }
  8440. c.ServeSuccessJSON(map[string]interface{}{
  8441. "msg": "退费成功",
  8442. })
  8443. }
  8444. func (c *HisApiController) RefundNumber() {
  8445. his_patient_id, _ := c.GetInt64("id")
  8446. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8447. info.Status = 0
  8448. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8449. if count > 0 {
  8450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8451. return
  8452. }
  8453. err := service.SaveHisPatient(info)
  8454. if err == nil {
  8455. c.ServeSuccessJSON(map[string]interface{}{
  8456. "msg": "退号成功",
  8457. })
  8458. } else {
  8459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8460. return
  8461. }
  8462. }
  8463. func (this *HisApiController) AdditionalCharge() {
  8464. dataBody := make(map[string]interface{}, 0)
  8465. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8466. fmt.Println(err)
  8467. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8468. patient_id := int64(dataBody["patient_id"].(float64))
  8469. medicineData, _ := dataBody["medicineData"].([]interface{})
  8470. adminUserInfo := this.GetAdminUserInfo()
  8471. orgId := adminUserInfo.CurrentOrgId
  8472. admin_user_id := adminUserInfo.AdminUser.Id
  8473. timeStr := time.Now().Format("2006-01-02")
  8474. timeLayout := "2006-01-02 15:04:05"
  8475. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8476. timenow := timeStringToTime.Unix()
  8477. var additionalCharges []*models.HisAdditionalCharge
  8478. for _, item := range medicineData {
  8479. var randNum int
  8480. randNum = rand.Intn(10000) + 1000
  8481. timestamp := time.Now().Unix()
  8482. tempTime := time.Unix(timestamp, 0)
  8483. timeFormat := tempTime.Format("20060102150405")
  8484. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8485. items := item.(map[string]interface{})
  8486. money := items["price"].(string)
  8487. item_id_str := items["item_id"].(string)
  8488. name := items["name"].(string)
  8489. id_str := items["id"].(string)
  8490. moneys, _ := strconv.ParseInt(money, 10, 64)
  8491. monStr := strconv.FormatInt(moneys, 10)
  8492. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8493. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8494. id, _ := strconv.ParseInt(id_str, 10, 64)
  8495. additionalCharge := &models.HisAdditionalCharge{
  8496. ID: id,
  8497. HisPatientId: his_patient_id,
  8498. UserOrgId: orgId,
  8499. PatientId: patient_id,
  8500. RecordDate: timenow,
  8501. Price: monneyStr,
  8502. Status: 1,
  8503. ItemName: name,
  8504. ItemId: item_id,
  8505. AdminUserId: admin_user_id,
  8506. CreatedTime: time.Now().Unix(),
  8507. OrderStatus: 0,
  8508. PrescriptionNumber: "",
  8509. BatchNumber: "",
  8510. FeedetlSn: p_number,
  8511. }
  8512. service.CreateAdditionalCharge(additionalCharge)
  8513. additionalCharges = append(additionalCharges, additionalCharge)
  8514. }
  8515. this.ServeSuccessJSON(map[string]interface{}{
  8516. "msg": "添加成功",
  8517. "additional_charges": additionalCharges,
  8518. })
  8519. }
  8520. func (this *HisApiController) DeleteAddition() {
  8521. id, _ := this.GetInt64("id")
  8522. //TODO 需要判断是否已经结算
  8523. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8524. if err == nil {
  8525. this.ServeSuccessJSON(map[string]interface{}{
  8526. "msg": "删除成功",
  8527. })
  8528. return
  8529. } else {
  8530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8531. return
  8532. }
  8533. }
  8534. func (this *HisApiController) GetAdminUsers() {
  8535. adminUser := this.GetAdminUserInfo()
  8536. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8537. this.ServeSuccessJSON(map[string]interface{}{
  8538. "doctors": doctors,
  8539. })
  8540. }
  8541. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8542. change_type, _ := this.GetInt64("type", 0)
  8543. record_date := this.GetString("record_time")
  8544. patient_id, _ := this.GetInt64("patient_id", 0)
  8545. p_type, _ := this.GetInt64("p_type", 0)
  8546. timeLayout := "2006-01-02"
  8547. loc, _ := time.LoadLocation("Local")
  8548. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8549. record_time := theAdviceRecordTime.Unix()
  8550. adminUserInfo := this.GetAdminUserInfo()
  8551. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8552. if err == nil {
  8553. if len(prescriptions) == 0 {
  8554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8555. return
  8556. } else {
  8557. this.ServeSuccessJSON(map[string]interface{}{
  8558. "prescriptions": prescriptions,
  8559. })
  8560. return
  8561. }
  8562. } else {
  8563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8564. return
  8565. }
  8566. }
  8567. func (this *HisApiController) GetCallHisPrescription() {
  8568. patient_id, _ := this.GetInt64("patient_id", 0)
  8569. timeLayout := "2006-01-02"
  8570. loc, _ := time.LoadLocation("Local")
  8571. start_time := this.GetString("start_time")
  8572. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8573. end_time := this.GetString("end_time")
  8574. p_type, _ := this.GetInt64("p_type")
  8575. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8576. adminUserInfo := this.GetAdminUserInfo()
  8577. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8578. if err == nil {
  8579. this.ServeSuccessJSON(map[string]interface{}{
  8580. "prescriptions": prescriptions,
  8581. })
  8582. return
  8583. } else {
  8584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8585. return
  8586. }
  8587. }
  8588. func (this *HisApiController) GetHisDayPrescription() {
  8589. timeLayout := "2006-01-02"
  8590. loc, _ := time.LoadLocation("Local")
  8591. start_time := this.GetString("start_time")
  8592. patient_id, _ := this.GetInt64("patient_id", 0)
  8593. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8594. end_time := this.GetString("end_time")
  8595. p_type, _ := this.GetInt64("p_type")
  8596. order_status, _ := this.GetInt64("type")
  8597. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8598. adminUserInfo := this.GetAdminUserInfo()
  8599. var dayHisPrescription []*models.HisPrescription
  8600. var err error
  8601. if order_status == 1 || order_status == 0 {
  8602. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8603. } else if order_status == 2 {
  8604. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8605. }
  8606. var settle_total float64
  8607. for _, item := range dayHisPrescription {
  8608. if len(item.HisPrescriptionProject) > 0 {
  8609. for _, subItem := range item.HisPrescriptionProject {
  8610. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8611. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8612. settle_total = settle_total + total
  8613. }
  8614. }
  8615. if len(item.HisDoctorAdviceInfo) > 0 {
  8616. for _, subItem := range item.HisDoctorAdviceInfo {
  8617. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8618. settle_total = settle_total + total
  8619. }
  8620. }
  8621. }
  8622. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8623. if err == nil {
  8624. this.ServeSuccessJSON(map[string]interface{}{
  8625. "day_prescription": dayHisPrescription,
  8626. "settle_total": settle_total,
  8627. })
  8628. return
  8629. } else {
  8630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8631. return
  8632. }
  8633. }
  8634. func (c *HisApiController) GetHisChargePatientList() {
  8635. record_date := c.GetString("record_date")
  8636. order_status, _ := c.GetInt64("type")
  8637. sch_type, _ := c.GetInt64("sch_type")
  8638. timeLayout := "2006-01-02"
  8639. loc, _ := time.LoadLocation("Local")
  8640. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8641. if err != nil {
  8642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8643. return
  8644. }
  8645. recordDateTime := theTime.Unix()
  8646. adminInfo := c.GetAdminUserInfo()
  8647. var tempPatients []*service.NewTempPatients
  8648. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8649. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8650. if order_status != 2 {
  8651. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8652. } else {
  8653. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8654. }
  8655. } else {
  8656. if order_status != 2 {
  8657. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8658. } else {
  8659. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8660. }
  8661. }
  8662. var patients []*service.NewTempPatients
  8663. var patients_two []*service.NewTempPatients
  8664. for _, item := range tempPatients {
  8665. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8666. //过滤掉没挂号的和没开处方的
  8667. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8668. patients = append(patients, item)
  8669. }
  8670. //过滤掉没挂号的
  8671. if len(item.HisPatient) > 0 {
  8672. patients_two = append(patients_two, item)
  8673. }
  8674. } else {
  8675. if len(item.HisPrescription) > 0 {
  8676. patients = append(patients, item)
  8677. }
  8678. }
  8679. }
  8680. c.ServeSuccessJSON(map[string]interface{}{
  8681. "list": patients,
  8682. "list_two": patients_two,
  8683. })
  8684. }
  8685. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8686. record_date := c.GetString("record_date")
  8687. timeLayout := "2006-01-02"
  8688. loc, _ := time.LoadLocation("Local")
  8689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8690. if err != nil {
  8691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8692. return
  8693. }
  8694. recordDateTime := theTime.Unix()
  8695. adminUser := c.GetAdminUserInfo()
  8696. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8697. var patients []*service.Patients
  8698. for _, item := range tempPatients {
  8699. if item.HisPatient.ID == 0 {
  8700. patients = append(patients, item)
  8701. }
  8702. }
  8703. c.ServeSuccessJSON(map[string]interface{}{
  8704. "list": patients,
  8705. //"list_two": patients_two,
  8706. })
  8707. }
  8708. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8709. newArr = make([]*service.Patients, 0)
  8710. for i := 0; i < len(patient); i++ {
  8711. repeat := false
  8712. for j := i + 1; j < len(patient); j++ {
  8713. if patient[i].ID == patient[j].ID {
  8714. repeat = true
  8715. break
  8716. }
  8717. }
  8718. if !repeat {
  8719. newArr = append(newArr, patient[i])
  8720. }
  8721. }
  8722. return
  8723. }
  8724. func (c *HisApiController) GetHisChargePatientInfo() {
  8725. patient_id, _ := c.GetInt64("patient_id")
  8726. his_patient_id, _ := c.GetInt64("his_patient_id")
  8727. record_date := c.GetString("record_date")
  8728. //start_time := c.GetString("start_time")
  8729. //end_time := c.GetString("end_time")
  8730. order_status, _ := c.GetInt64("type", 0)
  8731. p_type, _ := c.GetInt64("p_type", 0)
  8732. order_id, _ := c.GetInt64("order_id", 0)
  8733. timeLayout := "2006-01-02"
  8734. loc, _ := time.LoadLocation("Local")
  8735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8736. if err != nil {
  8737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8738. return
  8739. }
  8740. recordDateTime := theTime.Unix()
  8741. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8742. //if err != nil {
  8743. //
  8744. //}
  8745. //startRecordDateTime := startTime.Unix()
  8746. //
  8747. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8748. //if err != nil {
  8749. //
  8750. //}
  8751. //endRecordDateTime := endTime.Unix()
  8752. admin := c.GetAdminUserInfo()
  8753. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8754. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8755. var prescriptions []*models.HisPrescription
  8756. //var unChargeMonthPrescriptions []*models.HisPrescription
  8757. order, _ := service.GetHisOrderByID(order_id)
  8758. if order_status == 1 || order_status == 0 {
  8759. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8760. } else if order_status == 2 {
  8761. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8762. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8763. }
  8764. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8765. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8766. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8767. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8768. //获取所有科室信息
  8769. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8770. c.ServeSuccessJSON(map[string]interface{}{
  8771. "his_info": his_patient_info,
  8772. "xt_info": xt_patient_info,
  8773. "prescription": prescriptions,
  8774. "case_history": case_history,
  8775. "info": patientPrescriptionInfo,
  8776. "last_info": lastPatientPrescriptionInfo,
  8777. "order": order,
  8778. "doctors": doctors,
  8779. "department": department,
  8780. })
  8781. return
  8782. }
  8783. func (c *HisApiController) GetAllOrderDetail() {
  8784. order_id, _ := c.GetInt64("id", 0)
  8785. order, _ := service.GetHisOrderByID(order_id)
  8786. if order.ID == 0 {
  8787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8788. return
  8789. }
  8790. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8791. org_id := c.GetAdminUserInfo().CurrentOrgId
  8792. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8793. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8794. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8795. c.ServeSuccessJSON(map[string]interface{}{
  8796. "order": order,
  8797. "order_info": order_info,
  8798. "patient": patient,
  8799. "admin_info": adminInfo,
  8800. "hospital_record": record,
  8801. })
  8802. return
  8803. }
  8804. func (c *HisApiController) GetAllOrderDetailCollect() {
  8805. order_id, _ := c.GetInt64("id", 0)
  8806. order, _ := service.GetHisOrderByID(order_id)
  8807. if order.ID == 0 {
  8808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8809. return
  8810. }
  8811. org_id := c.GetAdminUserInfo().CurrentOrgId
  8812. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8813. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8814. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8815. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8816. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8817. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8818. var bedCostTotal float64 = 0 //床位总费
  8819. //var bedCostSelfTotal float64 = 0 //床位自费
  8820. var operationCostTotal float64 = 0 //手术费
  8821. //var operationCostSelfTotal float64 = 0 //手术费
  8822. var otherCostTotal float64 = 0 //其他费用
  8823. //var otherCostSelfTotal float64 = 0 //其他费用
  8824. var materialCostTotal float64 = 0 //材料费
  8825. //var materialCostSelfTotal float64 = 0 //材料费
  8826. var westernMedicineCostTotal float64 = 0 //西药费
  8827. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8828. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8829. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8830. var checkCostTotal float64 = 0 //检查费
  8831. //var checkCostSelfTotal float64 = 0 //检查费
  8832. var laboratoryCostTotal float64 = 0 //化验费
  8833. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8834. var treatCostTotal float64 = 0 //治疗费用
  8835. //var treatCostSelfTotal float64 = 0 //治疗费用
  8836. var zhenChaCostTotal float64 = 0 //其他费用
  8837. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8838. decimal.DivisionPrecision = 2
  8839. var BalanceAccountsType int64
  8840. if his.ID > 0 {
  8841. BalanceAccountsType = his.BalanceAccountsType
  8842. } else {
  8843. BalanceAccountsType = record.BalanceAccountsType
  8844. }
  8845. if BalanceAccountsType != 2 {
  8846. for _, item := range order_info {
  8847. if org_id == 10215 {
  8848. if item.MedChrgitmType == "01" { //床位费
  8849. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8850. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8851. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8852. }
  8853. if item.MedChrgitmType == "02" { //诊察费
  8854. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8855. //zhenChaCostSelfTotal = zhenChaCostTotal
  8856. }
  8857. if item.MedChrgitmType == "03" { //检查费
  8858. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8859. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8860. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8861. }
  8862. //if item.MedChrgitmType == "02" { //检查费
  8863. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8864. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8865. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8866. //}
  8867. if item.MedChrgitmType == "04" { //化验费
  8868. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8869. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8870. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8871. }
  8872. if item.MedChrgitmType == "05" { //治疗费
  8873. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8874. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8875. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8876. }
  8877. if item.MedChrgitmType == "06" { //手术费
  8878. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8879. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8880. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8881. }
  8882. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8883. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8884. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8885. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8886. }
  8887. if item.MedChrgitmType == "09" { //西药费
  8888. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8889. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8890. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8891. }
  8892. if item.MedChrgitmType == "11" { //中成费
  8893. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8894. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8895. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8896. }
  8897. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8898. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8899. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8900. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8901. }
  8902. } else if org_id == 10188 || org_id == 10217 {
  8903. if item.MedChrgitmType == "01" { //床位费
  8904. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8905. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8906. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8907. }
  8908. if item.MedChrgitmType == "02" { //诊察费
  8909. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8910. //zhenChaCostSelfTotal = zhenChaCostTotal
  8911. }
  8912. if item.MedChrgitmType == "03" { //检查费
  8913. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8914. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8915. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8916. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8917. }
  8918. //if item.MedChrgitmType == "02" { //检查费
  8919. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8920. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8921. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8922. //}
  8923. if item.MedChrgitmType == "04" { //化验费
  8924. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8925. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8926. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8927. }
  8928. if item.MedChrgitmType == "05" { //治疗费
  8929. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8930. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8931. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8932. }
  8933. if item.MedChrgitmType == "06" { //手术费
  8934. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8935. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8936. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8937. }
  8938. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8939. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8940. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8941. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8942. }
  8943. if item.MedChrgitmType == "09" { //西药费
  8944. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8945. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8946. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8947. }
  8948. if item.MedChrgitmType == "11" { //中成费
  8949. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8950. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8951. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8952. }
  8953. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8954. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8955. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8956. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8957. }
  8958. } else {
  8959. if item.MedChrgitmType == "01" { //床位费
  8960. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8961. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8962. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8963. }
  8964. //if item.MedChrgitmType == "02" { //诊察费
  8965. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8966. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8967. //}
  8968. if item.MedChrgitmType == "03" { //检查费
  8969. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8970. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8971. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8972. }
  8973. //if item.MedChrgitmType == "02" { //检查费
  8974. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8975. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8976. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8977. //}
  8978. if item.MedChrgitmType == "04" { //化验费
  8979. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8980. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8981. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8982. }
  8983. if item.MedChrgitmType == "05" { //治疗费
  8984. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8985. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8986. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8987. }
  8988. if item.MedChrgitmType == "06" { //手术费
  8989. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8990. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8991. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8992. }
  8993. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8994. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8995. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8996. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8997. }
  8998. if item.MedChrgitmType == "09" { //西药费
  8999. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9000. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9001. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9002. }
  9003. if item.MedChrgitmType == "11" { //中成费
  9004. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9005. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9006. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9007. }
  9008. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9009. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9010. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9011. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9012. }
  9013. }
  9014. }
  9015. c.ServeSuccessJSON(map[string]interface{}{
  9016. "order": order,
  9017. "order_info": order_info,
  9018. "patient": patient,
  9019. "admin_info": adminInfo,
  9020. "his_hospital": record,
  9021. "bedCostTotal": bedCostTotal,
  9022. "operationCostTotal": operationCostTotal,
  9023. "otherCostTotal": otherCostTotal,
  9024. "materialCostTotal": materialCostTotal,
  9025. "westernMedicineCostTotal": westernMedicineCostTotal,
  9026. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9027. "checkCostTotal": checkCostTotal,
  9028. "zhenChaCostTotal": zhenChaCostTotal,
  9029. "laboratoryCostTotal": laboratoryCostTotal,
  9030. "treatCostTotal": treatCostTotal,
  9031. })
  9032. } else {
  9033. for _, item := range order_info {
  9034. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9035. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9036. item.MedChrgitmType = "09"
  9037. }
  9038. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9039. if item.HisPrescriptionProject.Type == 2 {
  9040. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9041. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9042. case 0:
  9043. item.MedChrgitmType = "0"
  9044. break
  9045. case 1:
  9046. item.MedChrgitmType = "14"
  9047. break
  9048. case 2:
  9049. item.MedChrgitmType = "05"
  9050. break
  9051. case 3:
  9052. item.MedChrgitmType = "03"
  9053. break
  9054. case 4:
  9055. item.MedChrgitmType = "03"
  9056. break
  9057. case 5:
  9058. item.MedChrgitmType = "08"
  9059. break
  9060. case 6:
  9061. item.MedChrgitmType = "14"
  9062. break
  9063. case 7:
  9064. item.MedChrgitmType = "14"
  9065. break
  9066. case 8:
  9067. item.MedChrgitmType = "03"
  9068. break
  9069. case 9:
  9070. item.MedChrgitmType = "14"
  9071. break
  9072. case 10:
  9073. item.MedChrgitmType = "14"
  9074. break
  9075. case 11:
  9076. item.MedChrgitmType = "06"
  9077. break
  9078. case 12:
  9079. item.MedChrgitmType = "12"
  9080. break
  9081. case 13:
  9082. item.MedChrgitmType = "01"
  9083. break
  9084. case 14:
  9085. item.MedChrgitmType = "04"
  9086. break
  9087. case 15:
  9088. item.MedChrgitmType = "14"
  9089. break
  9090. }
  9091. } else {
  9092. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9093. case 1:
  9094. item.MedChrgitmType = "14"
  9095. break
  9096. case 2:
  9097. item.MedChrgitmType = "05"
  9098. break
  9099. case 3:
  9100. item.MedChrgitmType = "04"
  9101. break
  9102. case 4:
  9103. item.MedChrgitmType = "14"
  9104. break
  9105. case 5:
  9106. item.MedChrgitmType = "08"
  9107. break
  9108. case 6:
  9109. item.MedChrgitmType = "14"
  9110. break
  9111. case 7:
  9112. item.MedChrgitmType = "14"
  9113. break
  9114. case 8:
  9115. item.MedChrgitmType = "03"
  9116. break
  9117. case 9:
  9118. item.MedChrgitmType = "14"
  9119. break
  9120. }
  9121. }
  9122. } else if item.HisPrescriptionProject.Type == 3 {
  9123. item.MedChrgitmType = "08"
  9124. }
  9125. }
  9126. }
  9127. for _, item := range order_info {
  9128. if org_id == 10215 {
  9129. if item.MedChrgitmType == "01" { //床位费
  9130. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9131. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9132. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9133. }
  9134. if item.MedChrgitmType == "02" { //诊察费
  9135. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9136. //zhenChaCostSelfTotal = zhenChaCostTotal
  9137. }
  9138. if item.MedChrgitmType == "03" { //检查费
  9139. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9140. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9141. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9142. }
  9143. //if item.MedChrgitmType == "02" { //检查费
  9144. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9145. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9146. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9147. //}
  9148. if item.MedChrgitmType == "04" { //化验费
  9149. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9150. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9151. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9152. }
  9153. if item.MedChrgitmType == "05" { //治疗费
  9154. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9155. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9156. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9157. }
  9158. if item.MedChrgitmType == "06" { //手术费
  9159. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9160. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9161. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9162. }
  9163. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9164. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9165. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9166. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9167. }
  9168. if item.MedChrgitmType == "09" { //西药费
  9169. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9170. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9171. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9172. }
  9173. if item.MedChrgitmType == "11" { //中成费
  9174. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9175. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9176. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9177. }
  9178. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9179. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9180. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9181. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9182. }
  9183. } else {
  9184. if item.MedChrgitmType == "01" { //床位费
  9185. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9186. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9187. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9188. }
  9189. //if item.MedChrgitmType == "02" { //诊察费
  9190. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9191. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9192. //}
  9193. if item.MedChrgitmType == "03" { //检查费
  9194. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9195. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9196. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9197. }
  9198. //if item.MedChrgitmType == "02" { //检查费
  9199. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9200. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9201. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9202. //}
  9203. if item.MedChrgitmType == "04" { //化验费
  9204. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9205. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9206. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9207. }
  9208. if item.MedChrgitmType == "05" { //治疗费
  9209. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9210. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9211. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9212. }
  9213. if item.MedChrgitmType == "06" { //手术费
  9214. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9215. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9216. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9217. }
  9218. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9219. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9220. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9221. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9222. }
  9223. if item.MedChrgitmType == "09" { //西药费
  9224. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9225. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9226. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9227. }
  9228. if item.MedChrgitmType == "11" { //中成费
  9229. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9230. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9231. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9232. }
  9233. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9234. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9235. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9236. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9237. }
  9238. }
  9239. }
  9240. c.ServeSuccessJSON(map[string]interface{}{
  9241. "order": order,
  9242. "order_info": order_info,
  9243. "patient": patient,
  9244. "admin_info": adminInfo,
  9245. "his_hospital": record,
  9246. "bedCostTotal": bedCostTotal,
  9247. "operationCostTotal": operationCostTotal,
  9248. "otherCostTotal": otherCostTotal,
  9249. "materialCostTotal": materialCostTotal,
  9250. "westernMedicineCostTotal": westernMedicineCostTotal,
  9251. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9252. "checkCostTotal": checkCostTotal,
  9253. "zhenChaCostTotal": zhenChaCostTotal,
  9254. "laboratoryCostTotal": laboratoryCostTotal,
  9255. "treatCostTotal": treatCostTotal,
  9256. })
  9257. }
  9258. }
  9259. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9260. page, _ := c.GetInt64("page")
  9261. limit, _ := c.GetInt64("limit")
  9262. keywords := c.GetString("keywords")
  9263. start_time := c.GetString("start_time")
  9264. end_time := c.GetString("end_time")
  9265. //clr_type := c.GetString("clr_type")
  9266. insutype := c.GetString("insutype")
  9267. timeLayout := "2006-01-02"
  9268. loc, _ := time.LoadLocation("Local")
  9269. var theStartTIme int64
  9270. if len(start_time) > 0 {
  9271. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9272. theStartTIme = theTime.Unix()
  9273. }
  9274. var theEndtTIme int64
  9275. if len(end_time) > 0 {
  9276. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9277. theEndtTIme = theTime.Unix()
  9278. }
  9279. if page <= 0 {
  9280. page = 1
  9281. }
  9282. if limit <= 0 {
  9283. limit = 10
  9284. }
  9285. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9286. c.ServeSuccessJSON(map[string]interface{}{
  9287. "total": total,
  9288. "list": list,
  9289. })
  9290. return
  9291. }
  9292. func (c *HisApiController) GetPutOnRecordList() {
  9293. page, _ := c.GetInt64("page")
  9294. limit, _ := c.GetInt64("limit")
  9295. keywords := c.GetString("keywords")
  9296. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9297. if page <= 0 {
  9298. page = 1
  9299. }
  9300. if limit <= 0 {
  9301. limit = 10
  9302. }
  9303. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9304. c.ServeSuccessJSON(map[string]interface{}{
  9305. "total": total,
  9306. "list": list,
  9307. })
  9308. return
  9309. }
  9310. func (c *HisApiController) GetCompareData() {
  9311. start_time := c.GetString("start_time")
  9312. end_time := c.GetString("end_time")
  9313. insutype := c.GetString("insutype")
  9314. clr_type := c.GetString("clr_type")
  9315. timeLayout := "2006-01-02"
  9316. loc, _ := time.LoadLocation("Local")
  9317. var theStartTIme int64
  9318. if len(start_time) > 0 {
  9319. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9320. if err != nil {
  9321. theStartTIme = 0
  9322. }
  9323. theStartTIme = theTime.Unix()
  9324. }
  9325. var theEndtTIme int64
  9326. if len(end_time) > 0 {
  9327. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9328. if err != nil {
  9329. theEndtTIme = 0
  9330. }
  9331. theEndtTIme = theTime.Unix()
  9332. }
  9333. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9334. fmt.Println(err)
  9335. if err == nil {
  9336. c.ServeSuccessJSON(map[string]interface{}{
  9337. "list": formData,
  9338. })
  9339. } else {
  9340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9341. return
  9342. }
  9343. }
  9344. func (c *HisApiController) GetFaPiaoData() {
  9345. order_id, _ := c.GetInt64("order_id")
  9346. patient_id, _ := c.GetInt64("patient_id")
  9347. //number := c.GetString("number")
  9348. adminUser := c.GetAdminUserInfo()
  9349. order, _ := service.GetHisOrderByID(order_id)
  9350. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9351. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9352. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9353. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9354. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9355. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9356. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9357. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9358. var bedCostTotal float64 = 0 //床位总费
  9359. var bedCostSelfTotal float64 = 0 //床位自费
  9360. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9361. var operationCostTotal float64 = 0 //手术费
  9362. var operationCostSelfTotal float64 = 0 //手术费
  9363. var operationCostPartSelfTotal float64 = 0 //手术费
  9364. var otherCostTotal float64 = 0 //其他费用
  9365. var otherCostSelfTotal float64 = 0 //其他费用
  9366. var otherCostPartSelfTotal float64 = 0 //其他费用
  9367. var materialCostTotal float64 = 0 //材料费
  9368. var materialCostSelfTotal float64 = 0 //材料费
  9369. var materialCostPartSelfTotal float64 = 0 //材料费
  9370. var westernMedicineCostTotal float64 = 0 //西药费
  9371. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9372. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9373. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9374. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9375. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9376. var checkCostTotal float64 = 0 //检查费
  9377. var checkCostSelfTotal float64 = 0 //检查费
  9378. var checkCostPartSelfTotal float64 = 0 //检查费
  9379. var hiliCostTotal float64 = 0 //护理费
  9380. var hiliCostSelfTotal float64 = 0 //护理费
  9381. var hiliCostPartSelfTotal float64 = 0 //护理费
  9382. var laboratoryCostTotal float64 = 0 //化验费
  9383. var laboratoryCostSelfTotal float64 = 0 //化验费
  9384. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9385. var treatCostTotal float64 = 0 //治疗费用
  9386. var treatCostSelfTotal float64 = 0 //治疗费用
  9387. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9388. var zhenChaCostTotal float64 = 0 //其他费用
  9389. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9390. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9391. decimal.DivisionPrecision = 2
  9392. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9393. var balanceAccountsType int64
  9394. if his.ID > 0 {
  9395. balanceAccountsType = his.BalanceAccountsType
  9396. } else {
  9397. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9398. }
  9399. if balanceAccountsType == 2 {
  9400. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9401. for _, item := range orderInfos_two {
  9402. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9403. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9404. item.MedChrgitmType = "09"
  9405. }
  9406. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9407. if item.HisPrescriptionProject.Type == 2 {
  9408. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9409. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9410. case 0:
  9411. item.MedChrgitmType = "0"
  9412. break
  9413. case 1:
  9414. item.MedChrgitmType = "14"
  9415. break
  9416. case 2:
  9417. item.MedChrgitmType = "05"
  9418. break
  9419. case 3:
  9420. item.MedChrgitmType = "03"
  9421. break
  9422. case 4:
  9423. item.MedChrgitmType = "03"
  9424. break
  9425. case 5:
  9426. item.MedChrgitmType = "08"
  9427. break
  9428. case 6:
  9429. item.MedChrgitmType = "14"
  9430. break
  9431. case 7:
  9432. item.MedChrgitmType = "14"
  9433. break
  9434. case 8:
  9435. item.MedChrgitmType = "03"
  9436. break
  9437. case 9:
  9438. item.MedChrgitmType = "14"
  9439. break
  9440. case 10:
  9441. item.MedChrgitmType = "14"
  9442. break
  9443. case 11:
  9444. item.MedChrgitmType = "06"
  9445. break
  9446. case 12:
  9447. item.MedChrgitmType = "12"
  9448. break
  9449. case 13:
  9450. item.MedChrgitmType = "01"
  9451. break
  9452. case 14:
  9453. item.MedChrgitmType = "04"
  9454. break
  9455. case 15:
  9456. item.MedChrgitmType = "02"
  9457. break
  9458. }
  9459. } else {
  9460. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9461. case 1:
  9462. item.MedChrgitmType = "14"
  9463. break
  9464. case 2:
  9465. item.MedChrgitmType = "05"
  9466. break
  9467. case 3:
  9468. item.MedChrgitmType = "04"
  9469. break
  9470. case 4:
  9471. item.MedChrgitmType = "03"
  9472. break
  9473. case 5:
  9474. item.MedChrgitmType = "08"
  9475. break
  9476. case 6:
  9477. item.MedChrgitmType = "14"
  9478. break
  9479. case 7:
  9480. item.MedChrgitmType = "14"
  9481. break
  9482. case 8:
  9483. item.MedChrgitmType = "03"
  9484. break
  9485. case 9:
  9486. item.MedChrgitmType = "14"
  9487. break
  9488. }
  9489. }
  9490. } else if item.HisPrescriptionProject.Type == 3 {
  9491. item.MedChrgitmType = "08"
  9492. }
  9493. }
  9494. }
  9495. for _, item := range orderInfos_two {
  9496. fmt.Println(item.MedChrgitmType)
  9497. if item.MedChrgitmType == "07" { //床位费
  9498. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9499. hiliCostSelfTotal = hiliCostTotal
  9500. }
  9501. if item.MedChrgitmType == "01" { //床位费
  9502. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9503. bedCostSelfTotal = bedCostTotal
  9504. }
  9505. if item.MedChrgitmType == "02" { //诊察费
  9506. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9507. zhenChaCostSelfTotal = zhenChaCostTotal
  9508. }
  9509. if item.MedChrgitmType == "03" { //检查费
  9510. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9511. checkCostSelfTotal = checkCostTotal
  9512. }
  9513. if item.MedChrgitmType == "04" { //化验费
  9514. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9515. laboratoryCostSelfTotal = laboratoryCostTotal
  9516. }
  9517. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9518. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9519. treatCostSelfTotal = treatCostTotal
  9520. }
  9521. if item.MedChrgitmType == "06" { //手术费
  9522. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9523. operationCostSelfTotal = treatCostTotal
  9524. }
  9525. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9526. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9527. materialCostSelfTotal = materialCostTotal
  9528. }
  9529. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9530. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9531. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9532. }
  9533. if item.MedChrgitmType == "11" { //中成费
  9534. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9535. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9536. }
  9537. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9538. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9539. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9540. otherCostSelfTotal = otherCostTotal
  9541. }
  9542. } else {
  9543. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9544. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9545. otherCostSelfTotal = otherCostTotal
  9546. }
  9547. }
  9548. }
  9549. } else {
  9550. for _, item := range orderInfos {
  9551. if item.MedChrgitmType == "01" { //床位费
  9552. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9553. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9554. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9555. }
  9556. if item.MedChrgitmType == "02" { //诊察费
  9557. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9558. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9559. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9560. }
  9561. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9562. if item.MedChrgitmType == "03" { //检查费
  9563. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9564. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9565. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9566. }
  9567. } else {
  9568. if item.MedChrgitmType == "03" { //检查费
  9569. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9570. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9571. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9572. }
  9573. }
  9574. if item.MedChrgitmType == "04" { //化验费
  9575. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9576. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9577. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9578. }
  9579. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9580. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9581. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9582. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9583. }
  9584. if item.MedChrgitmType == "06" { //手术费
  9585. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9586. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9587. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9588. }
  9589. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9590. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9591. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9592. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9593. }
  9594. if item.MedChrgitmType == "07" { //护理
  9595. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9596. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9597. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9598. }
  9599. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9600. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9601. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9602. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9603. }
  9604. if item.MedChrgitmType == "11" { //中成费
  9605. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9606. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9607. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9608. }
  9609. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9610. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9611. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9612. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9613. }
  9614. }
  9615. }
  9616. timeLayout := "2006-01-02"
  9617. loc, _ := time.LoadLocation("Local")
  9618. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9619. if err != nil {
  9620. }
  9621. startRecordDateTime := startTime.Unix()
  9622. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9623. if err != nil {
  9624. }
  9625. endRecordDateTime := endTime.Unix()
  9626. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9627. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9628. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9629. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9630. c.ServeSuccessJSON(map[string]interface{}{
  9631. "charge_admin_name": charge_admin.UserName,
  9632. "order_number": order.Number, //业务流水号
  9633. "id_card_no": his.IdCardNo, //社会保障号
  9634. "patient": patient,
  9635. "department_name": department.Name, //科室
  9636. "number": his.Number, //门诊号
  9637. "date": order.SettleAccountsDate, //结算日期
  9638. "name": order.PsnName, //姓名
  9639. "gender": patient.Gender, //性别
  9640. "psn_cash_money": order.PsnCashPay, //个人支付
  9641. "pay_way": "门诊", //结算方式
  9642. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9643. "admin_user_name": admin.UserName, //收款员
  9644. "order": order,
  9645. "order_info": orderInfos_two,
  9646. "his": his,
  9647. "bedCostTotal": bedCostTotal,
  9648. "bedCostSelfTotal": bedCostSelfTotal,
  9649. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9650. "operationCostTotal": operationCostTotal,
  9651. "operationCostSelfTotal": operationCostSelfTotal,
  9652. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9653. "otherCostTotal": otherCostTotal,
  9654. "otherCostSelfTotal": otherCostSelfTotal,
  9655. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9656. "materialCostTotal": materialCostTotal,
  9657. "materialCostSelfTotal": materialCostSelfTotal,
  9658. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9659. "westernMedicineCostTotal": westernMedicineCostTotal,
  9660. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9661. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9662. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9663. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9664. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9665. "checkCostTotal": checkCostTotal,
  9666. "checkCostSelfTotal": checkCostSelfTotal,
  9667. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9668. "laboratoryCostTotal": laboratoryCostTotal,
  9669. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9670. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9671. "treatCostTotal": treatCostTotal,
  9672. "treatCostSelfTotal": treatCostSelfTotal,
  9673. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9674. "zhenChaCostTotal": zhenChaCostTotal,
  9675. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9676. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9677. "his_hospital_record": his_hospital_record,
  9678. "pre_pay_money": pre_pay_money,
  9679. "refund_sum": sum,
  9680. "doctor_info": doctor_info,
  9681. "hiliCostTotal": hiliCostTotal,
  9682. "hiliCostSelfTotal": hiliCostSelfTotal,
  9683. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9684. })
  9685. }
  9686. //func (c *HisApiController) GetFaPiaoDatas() {
  9687. // order_ids := c.GetString("order_ids")
  9688. // patient_id, _ := c.GetInt64("patient_id")
  9689. // adminUser := c.GetAdminUserInfo()
  9690. //
  9691. // orders := strings.Split(order_ids, ",")
  9692. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9693. //
  9694. // for _, item := range orders {
  9695. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9696. // order, _ := service.GetHisOrderByID(order_id)
  9697. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9698. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9699. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9700. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9701. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9702. //
  9703. // }
  9704. //
  9705. // var bedCostTotal float64 = 0 //床位总费
  9706. // var bedCostSelfTotal float64 = 0 //床位自费
  9707. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9708. //
  9709. // var operationCostTotal float64 = 0 //手术费
  9710. // var operationCostSelfTotal float64 = 0 //手术费
  9711. // var operationCostPartSelfTotal float64 = 0 //手术费
  9712. //
  9713. // var otherCostTotal float64 = 0 //其他费用
  9714. // var otherCostSelfTotal float64 = 0 //其他费用
  9715. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9716. //
  9717. // var materialCostTotal float64 = 0 //材料费
  9718. // var materialCostSelfTotal float64 = 0 //材料费
  9719. // var materialCostPartSelfTotal float64 = 0 //材料费
  9720. //
  9721. // var westernMedicineCostTotal float64 = 0 //西药费
  9722. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9723. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9724. //
  9725. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9726. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9727. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9728. //
  9729. // var checkCostTotal float64 = 0 //检查费
  9730. // var checkCostSelfTotal float64 = 0 //检查费
  9731. // var checkCostPartSelfTotal float64 = 0 //检查费
  9732. //
  9733. // var laboratoryCostTotal float64 = 0 //化验费
  9734. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9735. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9736. //
  9737. // var treatCostTotal float64 = 0 //治疗费用
  9738. // var treatCostSelfTotal float64 = 0 //治疗费用
  9739. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9740. //
  9741. // var zhenChaCostTotal float64 = 0 //其他费用
  9742. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9743. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9744. //
  9745. // decimal.DivisionPrecision = 2
  9746. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9747. //
  9748. // var balanceAccountsType int64
  9749. // if his.ID > 0 {
  9750. // balanceAccountsType = his.BalanceAccountsType
  9751. // } else {
  9752. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9753. // }
  9754. // if balanceAccountsType == 2 {
  9755. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9756. // for _, item := range orderInfos_two {
  9757. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9758. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9759. // item.MedChrgitmType = "09"
  9760. // }
  9761. //
  9762. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9763. // if item.HisPrescriptionProject.Type == 2 {
  9764. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9765. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9766. // case 0:
  9767. // item.MedChrgitmType = "0"
  9768. // break
  9769. // case 1:
  9770. // item.MedChrgitmType = "14"
  9771. // break
  9772. // case 2:
  9773. // item.MedChrgitmType = "05"
  9774. //
  9775. // break
  9776. // case 3:
  9777. // item.MedChrgitmType = "03"
  9778. //
  9779. // break
  9780. // case 4:
  9781. // item.MedChrgitmType = "03"
  9782. //
  9783. // break
  9784. // case 5:
  9785. // item.MedChrgitmType = "08"
  9786. //
  9787. // break
  9788. // case 6:
  9789. // item.MedChrgitmType = "14"
  9790. //
  9791. // break
  9792. // case 7:
  9793. // item.MedChrgitmType = "14"
  9794. //
  9795. // break
  9796. // case 8:
  9797. // item.MedChrgitmType = "03"
  9798. // break
  9799. // case 9:
  9800. // item.MedChrgitmType = "14"
  9801. // break
  9802. // case 10:
  9803. // item.MedChrgitmType = "14"
  9804. // break
  9805. // case 11:
  9806. // item.MedChrgitmType = "06"
  9807. // break
  9808. // case 12:
  9809. // item.MedChrgitmType = "12"
  9810. // break
  9811. // case 13:
  9812. // item.MedChrgitmType = "01"
  9813. // break
  9814. // case 14:
  9815. // item.MedChrgitmType = "04"
  9816. // break
  9817. // case 15:
  9818. // item.MedChrgitmType = "02"
  9819. // break
  9820. //
  9821. // }
  9822. //
  9823. // } else {
  9824. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9825. //
  9826. // case 1:
  9827. // item.MedChrgitmType = "14"
  9828. // break
  9829. // case 2:
  9830. // item.MedChrgitmType = "05"
  9831. //
  9832. // break
  9833. // case 3:
  9834. // item.MedChrgitmType = "03"
  9835. //
  9836. // break
  9837. // case 4:
  9838. // item.MedChrgitmType = "03"
  9839. //
  9840. // break
  9841. // case 5:
  9842. // item.MedChrgitmType = "08"
  9843. //
  9844. // break
  9845. // case 6:
  9846. // item.MedChrgitmType = "14"
  9847. //
  9848. // break
  9849. // case 7:
  9850. // item.MedChrgitmType = "14"
  9851. //
  9852. // break
  9853. // case 8:
  9854. // item.MedChrgitmType = "03"
  9855. // break
  9856. // case 9:
  9857. // item.MedChrgitmType = "14"
  9858. // break
  9859. //
  9860. // }
  9861. //
  9862. // }
  9863. //
  9864. // } else if item.HisPrescriptionProject.Type == 3 {
  9865. // item.MedChrgitmType = "08"
  9866. // }
  9867. // }
  9868. // }
  9869. //
  9870. // for _, item := range orderInfos_two {
  9871. // fmt.Println(item.MedChrgitmType)
  9872. // if item.MedChrgitmType == "01" { //床位费
  9873. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9874. // bedCostSelfTotal = bedCostTotal
  9875. // }
  9876. //
  9877. // if item.MedChrgitmType == "02" { //诊察费
  9878. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9879. // zhenChaCostSelfTotal = zhenChaCostTotal
  9880. // }
  9881. //
  9882. // if item.MedChrgitmType == "03" { //检查费
  9883. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9884. // checkCostSelfTotal = checkCostTotal
  9885. // }
  9886. //
  9887. // if item.MedChrgitmType == "04" { //化验费
  9888. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9889. // laboratoryCostSelfTotal = laboratoryCostTotal
  9890. // }
  9891. //
  9892. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9893. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9894. // treatCostSelfTotal = treatCostTotal
  9895. // }
  9896. //
  9897. // if item.MedChrgitmType == "06" { //手术费
  9898. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9899. // operationCostSelfTotal = treatCostTotal
  9900. // }
  9901. //
  9902. // if item.MedChrgitmType == "08" { //材料费
  9903. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9904. // materialCostSelfTotal = materialCostTotal
  9905. // }
  9906. //
  9907. // if item.MedChrgitmType == "09" { //西药费
  9908. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9909. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9910. // }
  9911. //
  9912. // if item.MedChrgitmType == "11" { //中成费
  9913. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9914. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9915. // }
  9916. //
  9917. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9918. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9919. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9920. // otherCostSelfTotal = otherCostTotal
  9921. // }
  9922. // } else {
  9923. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9924. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9925. // otherCostSelfTotal = otherCostTotal
  9926. // }
  9927. //
  9928. // }
  9929. //
  9930. // }
  9931. //
  9932. // } else {
  9933. // for _, item := range orderInfos {
  9934. // if item.MedChrgitmType == "01" { //床位费
  9935. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9936. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9937. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9938. // }
  9939. //
  9940. // if item.MedChrgitmType == "02" { //诊察费
  9941. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9942. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9943. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9944. // }
  9945. //
  9946. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9947. // if item.MedChrgitmType == "03" { //检查费
  9948. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9949. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9950. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9951. //
  9952. // }
  9953. // } else {
  9954. // if item.MedChrgitmType == "03" { //检查费
  9955. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9956. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9957. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9958. // }
  9959. //
  9960. // }
  9961. //
  9962. // if item.MedChrgitmType == "04" { //化验费
  9963. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9964. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9965. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9966. //
  9967. // }
  9968. //
  9969. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9970. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9971. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9972. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9973. //
  9974. // }
  9975. //
  9976. // if item.MedChrgitmType == "06" { //手术费
  9977. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9978. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9979. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9980. // }
  9981. //
  9982. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9983. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9984. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9985. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9986. // }
  9987. //
  9988. // if item.MedChrgitmType == "09" { //西药费
  9989. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9990. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9991. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9992. // }
  9993. //
  9994. // if item.MedChrgitmType == "11" { //中成费
  9995. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9996. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9997. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9998. // }
  9999. //
  10000. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10001. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10002. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10003. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10004. // }
  10005. //
  10006. // }
  10007. // }
  10008. // timeLayout := "2006-01-02"
  10009. // loc, _ := time.LoadLocation("Local")
  10010. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10011. // if err != nil {
  10012. // }
  10013. // startRecordDateTime := startTime.Unix()
  10014. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10015. // if err != nil {
  10016. // }
  10017. // endRecordDateTime := endTime.Unix()
  10018. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10019. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10020. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10021. //
  10022. // c.ServeSuccessJSON(map[string]interface{}{
  10023. // "order_number": order.Number, //业务流水号
  10024. // "id_card_no": his.IdCardNo, //社会保障号
  10025. // "department_name": department.Name, //科室
  10026. // "number": his.Number, //门诊号
  10027. // "date": order.SettleAccountsDate, //结算日期
  10028. // "name": order.PsnName, //姓名
  10029. // "gender": patient.Gender, //性别
  10030. // "psn_cash_money": order.PsnCashPay, //个人支付
  10031. // "pay_way": "门诊", //结算方式
  10032. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10033. // "admin_user_name": admin.UserName, //收款员
  10034. // "order": order,
  10035. // "order_info": orderInfos_two,
  10036. // "his": his,
  10037. // "bedCostTotal": bedCostTotal,
  10038. // "bedCostSelfTotal": bedCostSelfTotal,
  10039. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10040. // "operationCostTotal": operationCostTotal,
  10041. // "operationCostSelfTotal": operationCostSelfTotal,
  10042. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10043. // "otherCostTotal": otherCostTotal,
  10044. // "otherCostSelfTotal": otherCostSelfTotal,
  10045. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10046. // "materialCostTotal": materialCostTotal,
  10047. // "materialCostSelfTotal": materialCostSelfTotal,
  10048. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10049. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10050. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10051. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10052. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10053. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10054. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10055. // "checkCostTotal": checkCostTotal,
  10056. // "checkCostSelfTotal": checkCostSelfTotal,
  10057. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10058. // "laboratoryCostTotal": laboratoryCostTotal,
  10059. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10060. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10061. // "treatCostTotal": treatCostTotal,
  10062. // "treatCostSelfTotal": treatCostSelfTotal,
  10063. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10064. // "zhenChaCostTotal": zhenChaCostTotal,
  10065. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10066. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10067. // "his_hospital_record": his_hospital_record,
  10068. // "pre_pay_money": pre_pay_money,
  10069. // "refund_sum": sum,
  10070. // })
  10071. //
  10072. //}
  10073. func (this *HisApiController) GetIncomeStatisticsData() {
  10074. start_time := this.GetString("start_time")
  10075. end_time := this.GetString("end_time")
  10076. key_words := this.GetString("key_words")
  10077. limit, _ := this.GetInt64("limit")
  10078. page, _ := this.GetInt64("page")
  10079. if page <= 0 {
  10080. page = 1
  10081. }
  10082. if limit <= 0 {
  10083. limit = 10
  10084. }
  10085. statistics_type, _ := this.GetInt64("statistics_type")
  10086. admin := this.GetAdminUserInfo()
  10087. timeLayout := "2006-01-02"
  10088. loc, _ := time.LoadLocation("Local")
  10089. var theStartTIme int64
  10090. if len(start_time) > 0 {
  10091. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10092. if err != nil {
  10093. theStartTIme = 0
  10094. }
  10095. theStartTIme = theTime.Unix()
  10096. }
  10097. var theEndtTIme int64
  10098. if len(end_time) > 0 {
  10099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10100. if err != nil {
  10101. theEndtTIme = 0
  10102. }
  10103. theEndtTIme = theTime.Unix()
  10104. }
  10105. if statistics_type == 1 {
  10106. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10107. this.ServeSuccessJSON(map[string]interface{}{
  10108. "list": list,
  10109. "total": total,
  10110. })
  10111. } else {
  10112. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10113. this.ServeSuccessJSON(map[string]interface{}{
  10114. "list": list,
  10115. "total": total,
  10116. })
  10117. }
  10118. }
  10119. func (c *HisApiController) PostProjectInformation() {
  10120. adminUser := c.GetAdminUserInfo()
  10121. orgId := adminUser.CurrentOrgId
  10122. dataBody := make(map[string]interface{}, 0)
  10123. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10124. if err != nil {
  10125. utils.ErrorLog(err.Error())
  10126. return
  10127. }
  10128. utils.ErrorLog("%v", dataBody)
  10129. var projectList []*models.HisProject
  10130. var total_goods []interface{}
  10131. tempProjects := dataBody["projects"].([]interface{})
  10132. total_goods = tempProjects
  10133. for index, projectMap := range tempProjects {
  10134. projectM := projectMap.(map[string]interface{})
  10135. var project models.HisProject
  10136. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10137. utils.ErrorLog("project_name")
  10138. return
  10139. }
  10140. project_name, _ := projectM["project_name"].(string)
  10141. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10142. err_log := models.ExportErrLog{
  10143. LogType: 6,
  10144. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10145. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10146. Status: 1,
  10147. CreateTime: time.Now().Unix(),
  10148. UpdateTime: time.Now().Unix(),
  10149. ExportTime: time.Now().Unix(),
  10150. }
  10151. service.CreateExportErrLog(&err_log)
  10152. continue
  10153. }
  10154. project.ProjectName = project_name
  10155. prices := projectM["price"].(string)
  10156. price, _ := strconv.ParseFloat(prices, 64)
  10157. if price <= 0 { //名字为空则生成一条导入错误日志
  10158. err_log := models.ExportErrLog{
  10159. LogType: 6,
  10160. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10161. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10162. Status: 1,
  10163. CreateTime: time.Now().Unix(),
  10164. UpdateTime: time.Now().Unix(),
  10165. ExportTime: time.Now().Unix(),
  10166. }
  10167. service.CreateExportErrLog(&err_log)
  10168. continue
  10169. }
  10170. project.Price = price
  10171. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10172. utils.ErrorLog("unit_id")
  10173. return
  10174. }
  10175. unit := projectM["unit"].(string)
  10176. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10177. err_log := models.ExportErrLog{
  10178. LogType: 6,
  10179. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10180. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10181. Status: 1,
  10182. CreateTime: time.Now().Unix(),
  10183. UpdateTime: time.Now().Unix(),
  10184. ExportTime: time.Now().Unix(),
  10185. }
  10186. service.CreateExportErrLog(&err_log)
  10187. continue
  10188. }
  10189. project.Unit = unit
  10190. cost_classify := projectM["cost_classify"].(string)
  10191. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10192. err_log := models.ExportErrLog{
  10193. LogType: 6,
  10194. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10195. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10196. Status: 1,
  10197. CreateTime: time.Now().Unix(),
  10198. UpdateTime: time.Now().Unix(),
  10199. ExportTime: time.Now().Unix(),
  10200. }
  10201. service.CreateExportErrLog(&err_log)
  10202. continue
  10203. }
  10204. var costClassify = "费用类别"
  10205. var cost_classify_id int64
  10206. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10207. if len(cost_classify) != 0 {
  10208. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10209. if errcode == gorm.ErrRecordNotFound {
  10210. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10211. dataconfig := models.DictDataconfig{
  10212. ParentId: costClassifyConfig.ID,
  10213. Module: "system",
  10214. OrgId: orgId,
  10215. Name: cost_classify,
  10216. FieldName: "",
  10217. Value: costConfig.Value + 1,
  10218. CreatedTime: "",
  10219. UpdatedTime: "",
  10220. CreateUserId: adminUser.AdminUser.Id,
  10221. Status: 1,
  10222. Remark: "",
  10223. DeleteIdSystem: 0,
  10224. Title: "",
  10225. Content: "",
  10226. Order: 0,
  10227. Code: "",
  10228. }
  10229. service.CreatedDicConfig(&dataconfig)
  10230. }
  10231. }
  10232. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10233. for _, it := range costClassList {
  10234. if cost_classify == it.Name {
  10235. cost_classify_id = int64(it.Value)
  10236. }
  10237. }
  10238. project.CostClassify = cost_classify_id
  10239. executive_section := projectM["executive_section"].(string)
  10240. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10241. err_log := models.ExportErrLog{
  10242. LogType: 6,
  10243. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10244. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10245. Status: 1,
  10246. CreateTime: time.Now().Unix(),
  10247. UpdateTime: time.Now().Unix(),
  10248. ExportTime: time.Now().Unix(),
  10249. }
  10250. service.CreateExportErrLog(&err_log)
  10251. continue
  10252. }
  10253. if len(executive_section) != 0 {
  10254. //查找科室是否有内容
  10255. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10256. if errcodedepart == gorm.ErrRecordNotFound {
  10257. department := models.XtHisDepartment{
  10258. Name: executive_section,
  10259. Status: 1,
  10260. UserOrgId: adminUser.CurrentOrgId,
  10261. CreatedTime: time.Now().Unix(),
  10262. }
  10263. service.CreateDePartment(&department)
  10264. }
  10265. }
  10266. var executive_section_id int64
  10267. departMentList, _ := service.GetAllDepartMent(orgId)
  10268. for _, it := range departMentList {
  10269. if executive_section == it.Name {
  10270. executive_section_id = it.ID
  10271. }
  10272. }
  10273. project.ExecutiveSection = executive_section_id
  10274. medical_coverage := projectM["medical_coverage"].(string)
  10275. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10276. err_log := models.ExportErrLog{
  10277. LogType: 6,
  10278. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10279. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10280. Status: 1,
  10281. CreateTime: time.Now().Unix(),
  10282. UpdateTime: time.Now().Unix(),
  10283. ExportTime: time.Now().Unix(),
  10284. }
  10285. service.CreateExportErrLog(&err_log)
  10286. continue
  10287. }
  10288. var medicalCoverage = "医保等级"
  10289. var medical_coverage_id int64
  10290. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10291. if len(medical_coverage) != 0 {
  10292. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10293. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10294. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10295. dataconfig := models.DictDataconfig{
  10296. ParentId: medicalCoverageConfig.ID,
  10297. Module: "system",
  10298. OrgId: orgId,
  10299. Name: medical_coverage,
  10300. FieldName: "",
  10301. Value: medicalCoverageConfig.Value + 1,
  10302. CreatedTime: "",
  10303. UpdatedTime: "",
  10304. CreateUserId: adminUser.AdminUser.Id,
  10305. Status: 1,
  10306. Remark: "",
  10307. DeleteIdSystem: 0,
  10308. Title: "",
  10309. Content: "",
  10310. Order: 0,
  10311. Code: "",
  10312. }
  10313. service.CreatedDicConfig(&dataconfig)
  10314. }
  10315. }
  10316. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10317. for _, it := range medicalCoverageList {
  10318. if medical_coverage == it.Name {
  10319. medical_coverage_id = int64(it.Value)
  10320. }
  10321. }
  10322. project.MedicalCoverage = medical_coverage_id
  10323. pinyin := projectM["pinyin"].(string)
  10324. project.Pinyin = pinyin
  10325. wubi := projectM["wubi"].(string)
  10326. project.Wubi = wubi
  10327. statistical_classification := projectM["statistical_classification"].(string)
  10328. var statisticalClassification = "统计分类"
  10329. var statistical_classification_id int64
  10330. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10331. if len(statistical_classification) != 0 {
  10332. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10333. if classificationerrcodes == gorm.ErrRecordNotFound {
  10334. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10335. dataconfig := models.DictDataconfig{
  10336. ParentId: classiFication.ID,
  10337. Module: "system",
  10338. OrgId: orgId,
  10339. Name: statistical_classification,
  10340. FieldName: "",
  10341. Value: classiFicationConfig.Value + 1,
  10342. CreatedTime: "",
  10343. UpdatedTime: "",
  10344. CreateUserId: adminUser.AdminUser.Id,
  10345. Status: 1,
  10346. Remark: "",
  10347. DeleteIdSystem: 0,
  10348. Title: "",
  10349. Content: "",
  10350. Order: 0,
  10351. Code: "",
  10352. }
  10353. service.CreatedDicConfig(&dataconfig)
  10354. }
  10355. }
  10356. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10357. for _, it := range classiFicationList {
  10358. if statistical_classification == it.Name {
  10359. statistical_classification_id = int64(it.Value)
  10360. }
  10361. }
  10362. project.StatisticalClassification = statistical_classification_id
  10363. disease_directory := int64(projectM["disease_directory"].(float64))
  10364. project.DiseaseDirectory = disease_directory
  10365. is_record := int64(projectM["is_record"].(float64))
  10366. project.IsRecord = is_record
  10367. medical_code := projectM["medical_code"].(string)
  10368. project.MedicalCode = medical_code
  10369. tube_color := projectM["tube_color"].(string)
  10370. var tubeColor = "试管颜色"
  10371. var tube_color_id int64
  10372. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10373. if len(tube_color) != 0 {
  10374. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10375. if errcodetube == gorm.ErrRecordNotFound {
  10376. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10377. dataconfig := models.DictDataconfig{
  10378. ParentId: tubeColorConfig.ID,
  10379. Module: "system",
  10380. OrgId: orgId,
  10381. Name: tube_color,
  10382. FieldName: "",
  10383. Value: tubeConfig.Value + 1,
  10384. CreatedTime: "",
  10385. UpdatedTime: "",
  10386. CreateUserId: adminUser.AdminUser.Id,
  10387. Status: 1,
  10388. Remark: "",
  10389. DeleteIdSystem: 0,
  10390. Title: "",
  10391. Content: "",
  10392. Order: 0,
  10393. Code: "",
  10394. }
  10395. service.CreatedDicConfig(&dataconfig)
  10396. }
  10397. }
  10398. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10399. for _, it := range tubeColorList {
  10400. if tube_color == it.Name {
  10401. tube_color_id = int64(it.Value)
  10402. }
  10403. }
  10404. project.TubeColor = tube_color_id
  10405. single_dose := projectM["single_dose"].(string)
  10406. project.SingleDose = single_dose
  10407. execution_frequency := projectM["execution_frequency"].(string)
  10408. project.ExecutionFrequency = execution_frequency
  10409. delivery_way := projectM["delivery_way"].(string)
  10410. project.DeliveryWay = delivery_way
  10411. number_days := projectM["number_days"].(string)
  10412. project.NumberDays = number_days
  10413. total := projectM["total"].(string)
  10414. project.Total = total
  10415. medical_status := int64(projectM["medical_status"].(float64))
  10416. project.MedicalStatus = medical_status
  10417. category := int64(projectM["category"].(float64))
  10418. project.Category = category
  10419. specail_project := int64(projectM["specail_project"].(float64))
  10420. project.SpecailProject = specail_project
  10421. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10422. project.SocialSecurityDirectoryCode = social_security_directory_code
  10423. remark := projectM["remark"].(string)
  10424. project.Remark = remark
  10425. record_date := projectM["record_date"].(string)
  10426. timeLayout := "2006-01-02"
  10427. loc, _ := time.LoadLocation("Local")
  10428. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10429. project.RecordDate = theTime.Unix()
  10430. projectList = append(projectList, &project)
  10431. }
  10432. export_time := time.Now().Unix()
  10433. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10434. if len(projectList) > 0 {
  10435. for _, item := range projectList {
  10436. hans := item.ProjectName // 要转换的汉字字符串
  10437. // 创建一个拼音转换器
  10438. p := pinyin.NewArgs()
  10439. // 将汉字转为拼音
  10440. pinyinSlice := pinyin.Pinyin(hans, p)
  10441. // 输出拼音
  10442. fmt.Println("Pinyin:", pinyinSlice)
  10443. // 获取首字母
  10444. firstLetter := ""
  10445. for _, py := range pinyinSlice {
  10446. if len(py) > 0 {
  10447. firstLetter += string(py[0][0])
  10448. }
  10449. }
  10450. item.FirstLetter = firstLetter
  10451. project := models.HisProject{
  10452. ProjectName: item.ProjectName,
  10453. Price: item.Price,
  10454. Unit: item.Unit,
  10455. CostClassify: item.CostClassify,
  10456. ExecutiveSection: item.ExecutiveSection,
  10457. MedicalCoverage: item.MedicalCoverage,
  10458. UserOrgId: orgId,
  10459. Status: 1,
  10460. CreatedTime: time.Now().Unix(),
  10461. Pinyin: item.Pinyin,
  10462. Wubi: item.Wubi,
  10463. StatisticalClassification: item.StatisticalClassification,
  10464. DiseaseDirectory: item.DiseaseDirectory,
  10465. IsRecord: item.IsRecord,
  10466. MedicalCode: item.MedicalCode,
  10467. TubeColor: item.TubeColor,
  10468. SingleDose: item.SingleDose,
  10469. DeliveryWay: item.DeliveryWay,
  10470. NumberDays: item.NumberDays,
  10471. Total: item.Total,
  10472. Category: item.Category,
  10473. MedicalStatus: item.MedicalStatus,
  10474. SpecailProject: item.SpecailProject,
  10475. RecordDate: item.RecordDate,
  10476. Remark: item.Remark,
  10477. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10478. ExecutionFrequency: item.ExecutionFrequency,
  10479. FirstLetter: item.FirstLetter,
  10480. }
  10481. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10482. if errcodeproject == gorm.ErrRecordNotFound {
  10483. service.CreateProjectInfomation(&project)
  10484. } else if errcodeproject == nil {
  10485. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10486. }
  10487. log := models.ExportLog{
  10488. LogType: 6,
  10489. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10490. TotalNum: int64(len(total_goods)),
  10491. FailNum: int64(len(errLogs)),
  10492. SuccessNum: int64(len(projectList)),
  10493. CreateTime: time.Now().Unix(),
  10494. UpdateTime: time.Now().Unix(),
  10495. ExportTime: export_time,
  10496. Status: 1,
  10497. }
  10498. service.CreateExportLog(&log)
  10499. c.ServeSuccessJSON(map[string]interface{}{
  10500. "msg": "导入成功",
  10501. "total_num": len(total_goods),
  10502. "success_num": len(projectList),
  10503. "fail_num": int64(len(errLogs)),
  10504. })
  10505. }
  10506. } else {
  10507. log := models.ExportLog{
  10508. LogType: 6,
  10509. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10510. TotalNum: int64(len(total_goods)),
  10511. FailNum: int64(len(errLogs)),
  10512. SuccessNum: int64(len(projectList)),
  10513. CreateTime: time.Now().Unix(),
  10514. UpdateTime: time.Now().Unix(),
  10515. ExportTime: export_time,
  10516. Status: 1,
  10517. }
  10518. service.CreateExportLog(&log)
  10519. c.ServeSuccessJSON(map[string]interface{}{
  10520. "msg": "导入成功",
  10521. "total_num": len(total_goods),
  10522. "success_num": len(projectList),
  10523. "fail_num": int64(len(errLogs)),
  10524. })
  10525. }
  10526. }
  10527. //func (this *HisApiController) EditProjectInformation(){
  10528. //
  10529. // id, _ := this.GetInt64("id")
  10530. // project_team := this.GetString("project_team")
  10531. // price := this.GetString("price")
  10532. // price_float, _ := strconv.ParseFloat(price, 64)
  10533. // pinyin := this.GetString("pinyin")
  10534. // wubi := this.GetString("wubi")
  10535. // tube_color, _ := this.GetInt64("tube_color")
  10536. // team_type, _ := this.GetInt64("team_type")
  10537. // remark := this.GetString("remark")
  10538. // ids := this.GetString("ids")
  10539. // item_id := this.GetString("item_id")
  10540. // projectTeam := models.XtHisProjectTeam{
  10541. // ProjectTeam: project_team,
  10542. // Price: price_float,
  10543. // Pinyin: pinyin,
  10544. // Wubi: wubi,
  10545. // TubeColor: tube_color,
  10546. // TeamType: team_type,
  10547. // Remark: remark,
  10548. // ProjectId: ids,
  10549. // ItemId: item_id,
  10550. // }
  10551. //
  10552. //
  10553. // dataBody := make(map[string]interface{}, 0)
  10554. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10555. // if err != nil {
  10556. // utils.ErrorLog(err.Error())
  10557. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10558. // return
  10559. // }
  10560. //
  10561. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10562. //
  10563. //
  10564. // if err != nil {
  10565. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10566. // return
  10567. // }
  10568. //
  10569. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10570. // infos, _ := dataBody["info"].([]interface{})
  10571. // if len(infos) > 0 {
  10572. // var ids []string
  10573. //
  10574. // for _, item := range infos {
  10575. // items := item.(map[string]interface{})
  10576. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10577. // utils.ErrorLog("id")
  10578. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10579. // return
  10580. // }
  10581. // id := int64(items["id"].(float64))
  10582. //
  10583. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10584. // utils.ErrorLog("type")
  10585. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10586. // return
  10587. // }
  10588. // types := int64(items["type"].(float64))
  10589. //
  10590. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10591. // utils.ErrorLog("number")
  10592. // }
  10593. //
  10594. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10595. //
  10596. // projectList := models.XtHisProjectList{
  10597. // Number: number,
  10598. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10599. // ProjectId: id,
  10600. // Status: 1,
  10601. // CreatedTime: time.Now().Unix(),
  10602. // UpdatedTime: time.Now().Unix(),
  10603. // TeamId: projectTeam.ID,
  10604. // Type: types,
  10605. // }
  10606. // list := projectList
  10607. //
  10608. // service.CreateProjectList(&list)
  10609. //
  10610. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10611. //
  10612. // }
  10613. // ids_str := strings.Join(ids, ",")
  10614. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10615. // service.SaveProjectTeam(&projectTeam)
  10616. // this.ServeSuccessJSON(map[string]interface{}{
  10617. // "projectTeam": projectTeam,
  10618. // })
  10619. // }
  10620. // }
  10621. //}
  10622. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10623. name := c.GetString("name")
  10624. mode_id, _ := c.GetInt64("mode", 0)
  10625. types, _ := c.GetInt64("type", 0)
  10626. patient_id, _ := c.GetInt64("patient_id", 0)
  10627. types = 1
  10628. adminInfo := c.GetAdminUserInfo()
  10629. template := &models.HisPrescriptionTemplate{
  10630. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10631. PatientId: patient_id,
  10632. Type: types,
  10633. Status: 1,
  10634. Ctime: time.Now().Unix(),
  10635. Mtime: time.Now().Unix(),
  10636. Name: name,
  10637. Mode: mode_id,
  10638. }
  10639. dataBody := make(map[string]interface{}, 0)
  10640. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10641. if err != nil {
  10642. utils.ErrorLog(err.Error())
  10643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10644. return
  10645. }
  10646. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10647. //如果已经存在记录则删除处方
  10648. if template_one.ID > 0 {
  10649. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10650. var ids []int64
  10651. var org_id int64
  10652. for _, item := range ps {
  10653. org_id = c.GetAdminUserInfo().CurrentOrgId
  10654. ids = append(ids, item.ID)
  10655. }
  10656. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10657. if err2 == nil {
  10658. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10659. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10660. if len(prescriptions) > 0 {
  10661. for _, item := range prescriptions {
  10662. items := item.(map[string]interface{})
  10663. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10664. utils.ErrorLog("type")
  10665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10666. return
  10667. }
  10668. types := int64(items["type"].(float64))
  10669. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10670. utils.ErrorLog("med_type")
  10671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10672. return
  10673. }
  10674. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10675. ctime := time.Now().Unix()
  10676. prescription := &models.HisPrescriptionInfoTemplate{
  10677. PatientId: patient_id,
  10678. UserOrgId: adminInfo.CurrentOrgId,
  10679. Ctime: ctime,
  10680. Mtime: ctime,
  10681. Type: types,
  10682. Modifier: adminInfo.AdminUser.Id,
  10683. Creator: adminInfo.AdminUser.Id,
  10684. Status: 1,
  10685. PTemplateId: template_one.ID,
  10686. MedType: med_type,
  10687. }
  10688. service.CreateHisPrescriptionInfoTemplate(prescription)
  10689. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10690. advices := items["advices"].([]interface{})
  10691. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10692. ctime := time.Now().Unix()
  10693. mtime := ctime
  10694. if len(advices) > 0 {
  10695. for _, advice := range advices {
  10696. var s models.HisPrescriptionAdviceTemplate
  10697. s.PrescriptionId = prescription.ID
  10698. s.AdviceType = 2
  10699. s.StopState = 2
  10700. s.ExecutionState = 2
  10701. s.Status = 1
  10702. s.UserOrgId = adminInfo.CurrentOrgId
  10703. s.CreatedTime = ctime
  10704. s.UpdatedTime = mtime
  10705. s.PatientId = patient_id
  10706. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10707. if errcode > 0 {
  10708. c.ServeFailJSONWithSGJErrorCode(errcode)
  10709. return
  10710. }
  10711. service.CreateHisPrescriptionAdviceTemplate(&s)
  10712. }
  10713. }
  10714. }
  10715. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10716. projects := items["project"].([]interface{})
  10717. if len(projects) > 0 {
  10718. for _, project := range projects {
  10719. var p models.HisPrescriptionProjectTemplate
  10720. p.PrescriptionId = prescription.ID
  10721. p.Ctime = time.Now().Unix()
  10722. p.Mtime = time.Now().Unix()
  10723. p.PatientId = patient_id
  10724. p.UserOrgId = adminInfo.CurrentOrgId
  10725. p.Status = 1
  10726. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10727. if errcode > 0 {
  10728. c.ServeFailJSONWithSGJErrorCode(errcode)
  10729. return
  10730. }
  10731. service.CreateHisPrescriptionProjectTemplate(&p)
  10732. }
  10733. }
  10734. }
  10735. }
  10736. c.ServeSuccessJSON(map[string]interface{}{
  10737. "msg": "创建成功",
  10738. })
  10739. }
  10740. }
  10741. } else {
  10742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10743. return
  10744. }
  10745. } else {
  10746. err3 := service.CreateHisPrescriptionTemplate(template)
  10747. if err3 == nil {
  10748. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10749. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10750. if len(prescriptions) > 0 {
  10751. for _, item := range prescriptions {
  10752. items := item.(map[string]interface{})
  10753. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10754. utils.ErrorLog("type")
  10755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10756. return
  10757. }
  10758. types := int64(items["type"].(float64))
  10759. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10760. utils.ErrorLog("med_type")
  10761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10762. return
  10763. }
  10764. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10765. ctime := time.Now().Unix()
  10766. prescription := &models.HisPrescriptionInfoTemplate{
  10767. PatientId: patient_id,
  10768. UserOrgId: adminInfo.CurrentOrgId,
  10769. Ctime: ctime,
  10770. Mtime: ctime,
  10771. Type: types,
  10772. Modifier: adminInfo.AdminUser.Id,
  10773. Creator: adminInfo.AdminUser.Id,
  10774. Status: 1,
  10775. PTemplateId: template.ID,
  10776. MedType: med_type,
  10777. }
  10778. service.CreateHisPrescriptionInfoTemplate(prescription)
  10779. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10780. advices := items["advices"].([]interface{})
  10781. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10782. ctime := time.Now().Unix()
  10783. mtime := ctime
  10784. if len(advices) > 0 {
  10785. for _, advice := range advices {
  10786. var s models.HisPrescriptionAdviceTemplate
  10787. s.PrescriptionId = prescription.ID
  10788. s.AdviceType = 2
  10789. s.StopState = 2
  10790. s.ExecutionState = 2
  10791. s.Status = 1
  10792. s.UserOrgId = adminInfo.CurrentOrgId
  10793. s.CreatedTime = ctime
  10794. s.UpdatedTime = mtime
  10795. s.PatientId = patient_id
  10796. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10797. if errcode > 0 {
  10798. c.ServeFailJSONWithSGJErrorCode(errcode)
  10799. return
  10800. }
  10801. service.CreateHisPrescriptionAdviceTemplate(&s)
  10802. }
  10803. }
  10804. }
  10805. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10806. projects := items["project"].([]interface{})
  10807. if len(projects) > 0 {
  10808. for _, project := range projects {
  10809. var p models.HisPrescriptionProjectTemplate
  10810. p.PrescriptionId = prescription.ID
  10811. p.Ctime = time.Now().Unix()
  10812. p.Mtime = time.Now().Unix()
  10813. p.PatientId = patient_id
  10814. p.UserOrgId = adminInfo.CurrentOrgId
  10815. p.Status = 1
  10816. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10817. if errcode > 0 {
  10818. c.ServeFailJSONWithSGJErrorCode(errcode)
  10819. return
  10820. }
  10821. service.CreateHisPrescriptionProjectTemplate(&p)
  10822. }
  10823. }
  10824. }
  10825. }
  10826. c.ServeSuccessJSON(map[string]interface{}{
  10827. "msg": "创建成功",
  10828. })
  10829. }
  10830. }
  10831. } else {
  10832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10833. return
  10834. }
  10835. }
  10836. }
  10837. func (c *HisApiController) PreSettle() {
  10838. id, _ := c.GetInt64("id")
  10839. record_time := c.GetString("record_time")
  10840. his_patient_id, _ := c.GetInt64("his_patient_id")
  10841. timeLayout := "2006-01-02"
  10842. loc, _ := time.LoadLocation("Local")
  10843. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10844. diagnosis_id := c.GetString("diagnosis")
  10845. sick_type, _ := c.GetInt64("sick_type")
  10846. reg_type, _ := c.GetInt64("p_type")
  10847. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10848. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10849. if err != nil {
  10850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10851. return
  10852. }
  10853. recordDateTime := theTime.Unix()
  10854. adminUser := c.GetAdminUserInfo()
  10855. var prescriptions []*models.HisPrescription
  10856. var start_time int64
  10857. var end_time int64
  10858. ids_str := c.GetString("ids")
  10859. ids_arr := strings.Split(ids_str, ",")
  10860. fmt.Println(reg_type)
  10861. if settle_accounts_type == 1 { //日结
  10862. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10863. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10864. } else {
  10865. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10866. }
  10867. fmt.Println(prescriptions)
  10868. } else { //月结
  10869. start_time_str := c.GetString("start_time")
  10870. end_time_str := c.GetString("end_time")
  10871. timeLayout := "2006-01-02"
  10872. loc, _ := time.LoadLocation("Local")
  10873. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10874. if err != nil {
  10875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10876. return
  10877. }
  10878. recordStartTime := theStartTime.Unix()
  10879. start_time = recordStartTime
  10880. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10881. if err != nil {
  10882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10883. return
  10884. }
  10885. recordEndTime := theEndTime.Unix()
  10886. end_time = recordEndTime
  10887. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10888. }
  10889. if reg_type == 1111 || reg_type == 1112 {
  10890. reg_type = 11
  10891. }
  10892. timestamp := time.Now().Unix()
  10893. tempTime := time.Unix(timestamp, 0)
  10894. timeFormat := tempTime.Format("20060102150405")
  10895. chrgBchno := rand.Intn(100000) + 10000
  10896. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10897. strconv.FormatInt(his.PatientId, 10)
  10898. var ids []int64
  10899. for _, item := range prescriptions {
  10900. ids = append(ids, item.ID)
  10901. }
  10902. fmt.Println(ids)
  10903. var total float64
  10904. for _, item := range prescriptions {
  10905. fmt.Println(item)
  10906. if item.Type == 1 { //药品
  10907. for _, subItem := range item.HisDoctorAdviceInfo {
  10908. total = total + (subItem.Price * subItem.PrescribingNumber)
  10909. }
  10910. }
  10911. if item.Type == 2 { //项目
  10912. for _, subItem := range item.HisPrescriptionProject {
  10913. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10914. total = total + (subItem.Price * cnt)
  10915. }
  10916. }
  10917. for _, subItem := range item.HisAdditionalCharge {
  10918. total = total + (subItem.Price * float64(subItem.Count))
  10919. }
  10920. }
  10921. allTotal := fmt.Sprintf("%.2f", total)
  10922. totals, _ := strconv.ParseFloat(allTotal, 64)
  10923. order := &models.HisOrder{
  10924. UserOrgId: adminUser.CurrentOrgId,
  10925. HisPatientId: his.ID,
  10926. PatientId: id,
  10927. SettleAccountsDate: recordDateTime,
  10928. Ctime: time.Now().Unix(),
  10929. Mtime: time.Now().Unix(),
  10930. Status: 1,
  10931. OrderStatus: 1,
  10932. MdtrtId: his.Number,
  10933. Number: chrg_bchno,
  10934. MedfeeSumamt: totals,
  10935. SettleEndTime: end_time,
  10936. SettleStartTime: start_time,
  10937. SettleType: settle_accounts_type,
  10938. PsnPartAmt: totals,
  10939. PsnCashPay: totals,
  10940. PType: 2,
  10941. IsPre: 1,
  10942. MedType: strconv.Itoa(int(reg_type)),
  10943. Diagnosis: diagnosis_id,
  10944. }
  10945. err = service.CreateOrder(order)
  10946. if err != nil {
  10947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10948. return
  10949. }
  10950. var customs []*Custom
  10951. for _, item := range prescriptions {
  10952. fmt.Println(item.Type)
  10953. if item.Type == 1 { //药品
  10954. for _, subItem := range item.HisDoctorAdviceInfo {
  10955. cus := &Custom{
  10956. AdviceId: subItem.ID,
  10957. ProjectId: 0,
  10958. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10959. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10960. FeedetlSn: subItem.FeedetlSn,
  10961. Price: fmt.Sprintf("%.2f", subItem.Price),
  10962. MedListCodg: subItem.MedListCodg,
  10963. Type: 1,
  10964. }
  10965. customs = append(customs, cus)
  10966. }
  10967. }
  10968. if item.Type == 2 { //项目
  10969. for _, subItem := range item.HisPrescriptionProject {
  10970. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10971. cus := &Custom{
  10972. AdviceId: 0,
  10973. ProjectId: subItem.ID,
  10974. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10975. Cut: fmt.Sprintf("%.2f", cnt),
  10976. FeedetlSn: subItem.FeedetlSn,
  10977. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10978. MedListCodg: subItem.MedListCodg,
  10979. Type: 2,
  10980. }
  10981. customs = append(customs, cus)
  10982. }
  10983. }
  10984. for _, item := range item.HisAdditionalCharge {
  10985. cus := &Custom{
  10986. ItemId: item.ID,
  10987. AdviceId: 0,
  10988. ProjectId: 0,
  10989. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10990. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10991. FeedetlSn: item.FeedetlSn,
  10992. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10993. MedListCodg: item.XtHisAddtionConfig.Code,
  10994. Type: 3,
  10995. }
  10996. customs = append(customs, cus)
  10997. }
  10998. }
  10999. fmt.Println(customs)
  11000. for _, item := range customs {
  11001. var advice_id int64 = 0
  11002. var project_id int64 = 0
  11003. var item_id int64 = 0
  11004. var types int64 = 0
  11005. if item.Type == 1 {
  11006. advice_id = item.AdviceId
  11007. project_id = 0
  11008. item_id = 0
  11009. } else if item.Type == 2 {
  11010. advice_id = 0
  11011. item_id = 0
  11012. project_id = item.ProjectId
  11013. } else if item.Type == 3 {
  11014. advice_id = 0
  11015. item_id = item.ItemId
  11016. project_id = 0
  11017. }
  11018. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11019. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11020. pric, _ := strconv.ParseFloat(item.Price, 32)
  11021. info := &models.HisOrderInfo{
  11022. OrderNumber: order.Number,
  11023. UploadDate: time.Now().Unix(),
  11024. AdviceId: advice_id,
  11025. DetItemFeeSumamt: detItemFeeSumamt,
  11026. Cnt: cut,
  11027. Pric: pric,
  11028. PatientId: id,
  11029. Status: 1,
  11030. Mtime: time.Now().Unix(),
  11031. Ctime: time.Now().Unix(),
  11032. UserOrgId: adminUser.CurrentOrgId,
  11033. HisPatientId: his.ID,
  11034. OrderId: order.ID,
  11035. ProjectId: project_id,
  11036. Type: types,
  11037. ItemId: item_id,
  11038. }
  11039. service.CreateOrderInfo(info)
  11040. }
  11041. his.SickType = sick_type
  11042. service.UpdataHisPateint(&his)
  11043. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11044. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11045. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11046. if err == nil {
  11047. c.ServeSuccessJSON(map[string]interface{}{
  11048. "msg": "结算成功",
  11049. })
  11050. }
  11051. }
  11052. type CustomOrderInfo struct {
  11053. Name string
  11054. Spec string
  11055. Unit string
  11056. Count float64
  11057. Price float64
  11058. Total float64
  11059. }
  11060. func (c *HisApiController) GetPrivateExpensesInfo() {
  11061. order_id, _ := c.GetInt64("id", 0)
  11062. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11063. order, _ := service.GetHisOrderByID(order_id)
  11064. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11065. if order.ID == 0 {
  11066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11067. return
  11068. }
  11069. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11070. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11071. org_id := c.GetAdminUserInfo().CurrentOrgId
  11072. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11073. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11074. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11075. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11076. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11077. //var orderInfos_four []*models.HisOrderInfoTwo
  11078. //for _, item := range orderInfos_three {
  11079. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11080. // item.HisPrescriptionProject.IsCheckTeam = 1
  11081. // orderInfos_four = append(orderInfos_four, item)
  11082. //
  11083. // }
  11084. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11085. // item.HisPrescriptionProject.IsCheckTeam = 2
  11086. // orderInfos_two = append(orderInfos_two, item)
  11087. // }
  11088. //}
  11089. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11090. //var cus_slice []CustomOrderInfo
  11091. //for _, item := range new_order_info {
  11092. // var cus CustomOrderInfo
  11093. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11094. // cus.Unit = ""
  11095. // cus.Spec = ""
  11096. // var total float64
  11097. // for _, subItem := range orderInfos_four {
  11098. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11099. // total = total + subItem.DetItemFeeSumamt
  11100. // fmt.Println(subItem.DetItemFeeSumamt)
  11101. // }
  11102. // }
  11103. // cus.Count = 1
  11104. // cus.Total = total
  11105. // cus_slice = append(cus_slice, cus)
  11106. //}
  11107. orderInfos = append(orderInfos, orderInfos_two...)
  11108. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11109. //orderInfos = append(orderInfos, orderInfos_three...)
  11110. //}/**/
  11111. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11112. c.ServeSuccessJSON(map[string]interface{}{
  11113. "order": order,
  11114. "order_info": orderInfos,
  11115. "patient": patient,
  11116. "admin_info": adminInfo,
  11117. "his": his,
  11118. "current_admin": role,
  11119. "org_config": miConfig,
  11120. //"new_order_info": cus_slice,
  11121. })
  11122. }
  11123. func (this *HisApiController) ChangeMedType() {
  11124. med_type := this.GetString("med_type")
  11125. old_med_type := this.GetString("old_med_type")
  11126. ids := this.GetString("ids")
  11127. settle_type, _ := this.GetInt64("settle_type")
  11128. start_time := this.GetString("start_time")
  11129. end_time := this.GetString("end_time")
  11130. ids_arr := strings.Split(ids, ",")
  11131. if settle_type == 1 { //日结
  11132. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11133. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11134. prescription.MedType = med_type
  11135. err := service.SaveHisPrescriptionTwo(&prescription)
  11136. if err == nil {
  11137. this.ServeSuccessJSON(map[string]interface{}{
  11138. "msg": "修改成功",
  11139. })
  11140. } else {
  11141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11142. return
  11143. }
  11144. } else if settle_type == 2 {
  11145. timeLayout := "2006-01-02"
  11146. loc, _ := time.LoadLocation("Local")
  11147. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11148. if err != nil {
  11149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11150. return
  11151. }
  11152. recordStartTime := theStartTime.Unix()
  11153. start_time_timestamp := recordStartTime
  11154. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11155. if err != nil {
  11156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11157. return
  11158. }
  11159. recordEndTime := theEndTime.Unix()
  11160. end_time_timestamp := recordEndTime
  11161. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11162. if updateErr == nil {
  11163. this.ServeSuccessJSON(map[string]interface{}{
  11164. "msg": "修改成功",
  11165. })
  11166. } else {
  11167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11168. return
  11169. }
  11170. }
  11171. }
  11172. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11173. patient_id, _ := c.GetInt64("patient_id")
  11174. his_patient_id, _ := c.GetInt64("his_patient_id")
  11175. record_date := c.GetString("record_date")
  11176. start_time := c.GetString("start_time")
  11177. end_time := c.GetString("end_time")
  11178. order_status, _ := c.GetInt64("type", 0)
  11179. p_type, _ := c.GetInt64("p_type", 0)
  11180. order_id, _ := c.GetInt64("order_id", 0)
  11181. timeLayout := "2006-01-02"
  11182. loc, _ := time.LoadLocation("Local")
  11183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11184. if err != nil {
  11185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11186. return
  11187. }
  11188. recordDateTime := theTime.Unix()
  11189. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11190. if err != nil {
  11191. }
  11192. startRecordDateTime := startTime.Unix()
  11193. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11194. if err != nil {
  11195. }
  11196. endRecordDateTime := endTime.Unix()
  11197. admin := c.GetAdminUserInfo()
  11198. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11199. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11200. order, _ := service.GetHisOrderByID(order_id)
  11201. var monthPrescriptions []*models.HisPrescription
  11202. if order_status == 1 || order_status == 0 {
  11203. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11204. } else if order_status == 2 {
  11205. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11206. }
  11207. var settle_total float64
  11208. for _, item := range monthPrescriptions {
  11209. if len(item.HisPrescriptionProject) > 0 {
  11210. for _, subItem := range item.HisPrescriptionProject {
  11211. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11212. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11213. settle_total = settle_total + total
  11214. }
  11215. }
  11216. if len(item.HisDoctorAdviceInfo) > 0 {
  11217. for _, subItem := range item.HisDoctorAdviceInfo {
  11218. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11219. settle_total = settle_total + total
  11220. }
  11221. }
  11222. }
  11223. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11224. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11225. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11226. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11227. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11228. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11229. //获取所有科室信息
  11230. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11231. var dia string
  11232. for _, item := range month_p_info {
  11233. if len(dia) == 0 {
  11234. dia = item.Diagnosis
  11235. } else {
  11236. dia = dia + "," + item.Diagnosis
  11237. }
  11238. }
  11239. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11240. dia_arr = removeEmptyStrings(dia_arr)
  11241. c.ServeSuccessJSON(map[string]interface{}{
  11242. "his_info": his_patient_info,
  11243. "xt_info": xt_patient_info,
  11244. "case_history": case_history,
  11245. "info": patientPrescriptionInfo,
  11246. "last_info": lastPatientPrescriptionInfo,
  11247. "month_prescriptions": monthPrescriptions,
  11248. "order": order,
  11249. "doctors": doctors,
  11250. "department": department,
  11251. "settle_total": settle_total,
  11252. "dia_arr": dia_arr,
  11253. })
  11254. return
  11255. }
  11256. func removeEmptyStrings(input []string) []string {
  11257. var output []string
  11258. for _, s := range input {
  11259. if s != "" {
  11260. output = append(output, s)
  11261. }
  11262. }
  11263. return output
  11264. }
  11265. func removeDuplicates(input []string) []string {
  11266. seen := make(map[string]bool)
  11267. output := []string{}
  11268. for _, s := range input {
  11269. if _, exists := seen[s]; !exists {
  11270. seen[s] = true
  11271. output = append(output, s)
  11272. }
  11273. }
  11274. return output
  11275. }
  11276. func (c *HisApiController) GetHisMonthPatientInfo() {
  11277. patient_id, _ := c.GetInt64("patient_id")
  11278. his_patient_id, _ := c.GetInt64("his_patient_id")
  11279. record_date := c.GetString("record_date")
  11280. number := c.GetString("number")
  11281. start_time := c.GetString("start_time")
  11282. end_time := c.GetString("end_time")
  11283. p_type, _ := c.GetInt64("p_type")
  11284. timeLayout := "2006-01-02"
  11285. loc, _ := time.LoadLocation("Local")
  11286. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11287. if err != nil {
  11288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11289. return
  11290. }
  11291. recordDateTime := theTime.Unix()
  11292. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11293. if err != nil {
  11294. }
  11295. startRecordDateTime := startTime.Unix()
  11296. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11297. if err != nil {
  11298. }
  11299. endRecordDateTime := endTime.Unix()
  11300. admin := c.GetAdminUserInfo()
  11301. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11302. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11303. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11304. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11305. var settle_total float64
  11306. for _, item := range monthPrescriptions {
  11307. if len(item.HisPrescriptionProject) > 0 {
  11308. for _, subItem := range item.HisPrescriptionProject {
  11309. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11310. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11311. settle_total = settle_total + total
  11312. }
  11313. }
  11314. if len(item.HisDoctorAdviceInfo) > 0 {
  11315. for _, subItem := range item.HisDoctorAdviceInfo {
  11316. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11317. settle_total = settle_total + total
  11318. }
  11319. }
  11320. }
  11321. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11322. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11323. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11324. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11325. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11326. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11327. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11328. //获取所有科室信息
  11329. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11330. c.ServeSuccessJSON(map[string]interface{}{
  11331. "his_info": his_patient_info,
  11332. "xt_info": xt_patient_info,
  11333. "case_history": case_history,
  11334. "info": patientPrescriptionInfo,
  11335. "month_prescriptions": monthPrescriptions,
  11336. "order": order,
  11337. "doctors": doctors,
  11338. "department": department,
  11339. "count": count,
  11340. "drugStockConfig": drugStockConfig,
  11341. "last_info": lastPatientPrescriptionInfo,
  11342. "settle_total": settle_total,
  11343. })
  11344. return
  11345. }
  11346. func (c *HisApiController) GetAllOrder() {
  11347. org_id := c.GetAdminUserInfo().CurrentOrgId
  11348. orders, _ := service.GetNewHisOrderList(org_id)
  11349. c.ServeSuccessJSON(map[string]interface{}{
  11350. "order": orders,
  11351. })
  11352. return
  11353. }
  11354. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11355. newArr = make([]*models.HisOrderInfoTwo, 0)
  11356. for i := 0; i < len(arr); i++ {
  11357. repeat := false
  11358. for j := i + 1; j < len(arr); j++ {
  11359. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11360. repeat = true
  11361. break
  11362. }
  11363. }
  11364. if !repeat {
  11365. newArr = append(newArr, arr[i])
  11366. }
  11367. }
  11368. return
  11369. }
  11370. // 修改处方退库操作 参数传修改之前的处方数据
  11371. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11372. if advice.ExecutionState == 1 {
  11373. //查询该病人该药品是否有库存记录
  11374. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11375. if errcode == gorm.ErrRecordNotFound {
  11376. } else {
  11377. //退库
  11378. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11379. if advice.PrescribingNumberUnit == drug.MinUnit {
  11380. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11381. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11382. //退库
  11383. warehouseInfo := models.DrugWarehouseInfo{
  11384. StockMinNumber: prescribingNumber,
  11385. }
  11386. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11387. operation_time := time.Now().Unix()
  11388. creater := advice.AdviceDoctor
  11389. ctime := time.Now().Unix()
  11390. timeStr := time.Now().Format("2006-01-02")
  11391. timeArr := strings.Split(timeStr, "-")
  11392. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11393. total = total + 1
  11394. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11395. cancelStock := models.DrugCancelStock{
  11396. OrderNumber: orderNumber,
  11397. OperaTime: operation_time,
  11398. OrgId: advice.UserOrgId,
  11399. Creater: creater,
  11400. Ctime: ctime,
  11401. Status: 1,
  11402. ReturnTime: advice.AdviceDate,
  11403. Dealer: info.Dealer,
  11404. Manufacturer: info.Manufacturer,
  11405. Type: 1,
  11406. }
  11407. service.AddSigleDrugCancelStock(&cancelStock)
  11408. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11409. dealer, _ := service.GetDealerById(info.Dealer)
  11410. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11411. cancelStockInfo := models.DrugCancelStockInfo{
  11412. OrderNumber: cancelInfo.OrderNumber,
  11413. CancelStockId: cancelInfo.ID,
  11414. DrugId: info.DrugId,
  11415. Count: info.Count,
  11416. Status: 1,
  11417. Ctime: ctime,
  11418. OrgId: advice.UserOrgId,
  11419. Type: 1,
  11420. Manufacturer: manufactureName.ManufacturerName,
  11421. Dealer: dealer.DealerName,
  11422. Total: 0,
  11423. RetailPrice: info.RetailPrice,
  11424. RetailTotalPrice: info.RetailTotalPrice,
  11425. Price: info.Price,
  11426. RegisterAccount: "",
  11427. Remark: info.Remark,
  11428. BatchNumber: info.BatchNumber,
  11429. MaxUnit: info.CountUnit,
  11430. ProductDate: info.ProductDate,
  11431. ExpiryDate: info.ExpiryDate,
  11432. BatchNumberId: info.WarehouseInfoId,
  11433. }
  11434. flow := models.DrugFlow{
  11435. WarehousingId: 0,
  11436. DrugId: info.DrugId,
  11437. Number: "",
  11438. BatchNumber: info.BatchNumber,
  11439. Count: info.Count,
  11440. UserOrgId: advice.UserOrgId,
  11441. PatientId: 0,
  11442. SystemTime: ctime,
  11443. ConsumableType: 4,
  11444. IsSys: 0,
  11445. WarehousingOrder: "",
  11446. WarehouseOutId: 0,
  11447. WarehouseOutOrderNumber: "",
  11448. IsEdit: 0,
  11449. CancelStockId: cancelStock.ID,
  11450. CancelOrderNumber: cancelStock.OrderNumber,
  11451. Manufacturer: info.Manufacturer,
  11452. Dealer: info.Dealer,
  11453. Creator: advice.UserOrgId,
  11454. UpdateCreator: 0,
  11455. Status: 1,
  11456. Ctime: time.Now().Unix(),
  11457. Mtime: 0,
  11458. Price: info.Price,
  11459. WarehousingDetailId: 0,
  11460. WarehouseOutDetailId: 0,
  11461. CancelOutDetailId: 0,
  11462. ExpireDate: info.ExpiryDate,
  11463. ProductDate: info.ProductDate,
  11464. MaxUnit: info.CountUnit,
  11465. MinUnit: "",
  11466. }
  11467. service.CreatedCancelStock(cancelStockInfo)
  11468. service.CreateDrugFlowOne(flow)
  11469. } else {
  11470. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11471. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11472. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11473. warehouseInfo := models.DrugWarehouseInfo{
  11474. StockMinNumber: prescribingNumber,
  11475. }
  11476. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11477. }
  11478. operation_time := time.Now().Unix()
  11479. creater := advice.AdviceDoctor
  11480. ctime := time.Now().Unix()
  11481. timeStr := time.Now().Format("2006-01-02")
  11482. timeArr := strings.Split(timeStr, "-")
  11483. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11484. total = total + 1
  11485. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11486. cancelStock := models.DrugCancelStock{
  11487. OrderNumber: orderNumber,
  11488. OperaTime: operation_time,
  11489. OrgId: advice.UserOrgId,
  11490. Creater: creater,
  11491. Ctime: ctime,
  11492. Status: 1,
  11493. ReturnTime: advice.AdviceDate,
  11494. Dealer: info.Dealer,
  11495. Manufacturer: info.Manufacturer,
  11496. Type: 1,
  11497. }
  11498. service.AddSigleDrugCancelStock(&cancelStock)
  11499. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11500. dealer, _ := service.GetDealerById(info.Dealer)
  11501. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11502. cancelStockInfo := models.DrugCancelStockInfo{
  11503. OrderNumber: cancelInfo.OrderNumber,
  11504. CancelStockId: cancelInfo.ID,
  11505. DrugId: info.DrugId,
  11506. Count: info.Count,
  11507. Status: 1,
  11508. Ctime: ctime,
  11509. OrgId: advice.UserOrgId,
  11510. Type: 1,
  11511. Manufacturer: manufactureName.ManufacturerName,
  11512. Dealer: dealer.DealerName,
  11513. Total: 0,
  11514. RetailPrice: info.RetailPrice,
  11515. RetailTotalPrice: info.RetailTotalPrice,
  11516. Price: info.Price,
  11517. RegisterAccount: "",
  11518. Remark: info.Remark,
  11519. BatchNumber: info.BatchNumber,
  11520. MaxUnit: info.CountUnit,
  11521. ProductDate: info.ProductDate,
  11522. ExpiryDate: info.ExpiryDate,
  11523. BatchNumberId: info.WarehouseInfoId,
  11524. }
  11525. flow := models.DrugFlow{
  11526. WarehousingId: 0,
  11527. DrugId: info.DrugId,
  11528. Number: "",
  11529. BatchNumber: info.BatchNumber,
  11530. Count: info.Count,
  11531. UserOrgId: advice.UserOrgId,
  11532. PatientId: 0,
  11533. SystemTime: ctime,
  11534. ConsumableType: 4,
  11535. IsSys: 0,
  11536. WarehousingOrder: "",
  11537. WarehouseOutId: 0,
  11538. WarehouseOutOrderNumber: "",
  11539. IsEdit: 0,
  11540. CancelStockId: cancelStock.ID,
  11541. CancelOrderNumber: cancelStock.OrderNumber,
  11542. Manufacturer: info.Manufacturer,
  11543. Dealer: info.Dealer,
  11544. Creator: advice.AdviceDoctor,
  11545. UpdateCreator: 0,
  11546. Status: 1,
  11547. Ctime: time.Now().Unix(),
  11548. Mtime: 0,
  11549. Price: info.Price,
  11550. WarehousingDetailId: 0,
  11551. WarehouseOutDetailId: 0,
  11552. CancelOutDetailId: 0,
  11553. ExpireDate: info.ExpiryDate,
  11554. ProductDate: info.ProductDate,
  11555. MaxUnit: info.CountUnit,
  11556. MinUnit: "",
  11557. }
  11558. service.CreatedCancelStock(cancelStockInfo)
  11559. service.CreateDrugFlowOne(flow)
  11560. }
  11561. }
  11562. }
  11563. return err
  11564. }
  11565. func (this *HisApiController) DeleteNCDS() {
  11566. id, _ := this.GetInt64("id", 0)
  11567. if id > 0 {
  11568. service.DeletePsnNCDSRecordById(id)
  11569. this.ServeSuccessJSON(map[string]interface{}{
  11570. "msg": "删除成功",
  11571. })
  11572. } else {
  11573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11574. return
  11575. }
  11576. }
  11577. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11578. id, _ := c.GetInt64("id")
  11579. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11580. c.ServeSuccessJSON(map[string]interface{}{
  11581. "advice": advice,
  11582. })
  11583. return
  11584. }
  11585. func (c *HisApiController) GetHisMonthChargePatientList() {
  11586. record_date := c.GetString("record_date")
  11587. start_time := c.GetString("start_time")
  11588. end_time := c.GetString("end_time")
  11589. timeLayout := "2006-01-02"
  11590. loc, _ := time.LoadLocation("Local")
  11591. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11592. if err != nil {
  11593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11594. return
  11595. }
  11596. if err != nil {
  11597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11598. return
  11599. }
  11600. recordDateTime := theTime.Unix()
  11601. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11602. if err != nil {
  11603. }
  11604. startRecordDateTime := startTime.Unix()
  11605. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11606. if err != nil {
  11607. }
  11608. endRecordDateTime := endTime.Unix()
  11609. adminInfo := c.GetAdminUserInfo()
  11610. var tempMonthChargePatients []*service.MonthChargePatients
  11611. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11612. for _, item := range tempPatients {
  11613. //过滤没有处方的
  11614. if len(item.HisPrescription) == 0 {
  11615. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11616. }
  11617. }
  11618. c.ServeSuccessJSON(map[string]interface{}{
  11619. "list": tempMonthChargePatients,
  11620. })
  11621. }
  11622. // PrescriptionDifference 医嘱数量差值结构体
  11623. type PrescriptionDrugDifference struct {
  11624. DrugID int64 //基础库药品id
  11625. ID int64 //医嘱id
  11626. Difference float64 //差值
  11627. Unit string //单位
  11628. }
  11629. type PrescriptionGoodDifference struct {
  11630. GoodID int64 //基础库项目耗材id
  11631. ID int64 //医嘱id
  11632. Difference int64 //差值
  11633. Unit string //单位
  11634. Type int64 //类型
  11635. }
  11636. type EditCustomData struct {
  11637. adviceList []*models.HisDoctorAdviceInfo
  11638. projectList []*models.HisPrescriptionProject
  11639. }
  11640. type SrcCustomData struct {
  11641. adviceList []*models.HisDoctorAdviceInfo
  11642. projectList []*models.HisPrescriptionProject
  11643. }
  11644. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11645. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11646. differences := make([]*PrescriptionDrugDifference, 0)
  11647. // 创建一个 map 来存储第一个切片中的药品信息
  11648. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11649. for _, advice := range firstPrescription {
  11650. firstMap[advice.DrugId] = advice
  11651. }
  11652. // 遍历第二个切片中的药品信息,并比较数量差值
  11653. for _, advice := range secondPrescription {
  11654. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11655. diff := &PrescriptionDrugDifference{
  11656. DrugID: advice.DrugId,
  11657. ID: firstAdvice.ID,
  11658. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11659. Unit: firstAdvice.PrescribingNumberUnit,
  11660. }
  11661. differences = append(differences, diff)
  11662. }
  11663. }
  11664. return differences
  11665. }
  11666. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11667. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11668. differences := make([]*PrescriptionGoodDifference, 0)
  11669. // 创建一个 map 来存储第一个切片中的耗材信息
  11670. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11671. for _, good := range firstPrescription {
  11672. firstMap[good.ProjectId] = good
  11673. }
  11674. // 遍历第二个切片中的耗材信息,并比较数量差值
  11675. for _, good := range secondPrescription {
  11676. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11677. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11678. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11679. diff := &PrescriptionGoodDifference{
  11680. GoodID: good.ProjectId,
  11681. ID: firstGood.ID,
  11682. Difference: count - firstCount,
  11683. Unit: firstGood.Unit,
  11684. Type: firstGood.Type,
  11685. }
  11686. differences = append(differences, diff)
  11687. }
  11688. }
  11689. return differences
  11690. }
  11691. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11692. var adviceList []*models.HisDoctorAdviceInfo
  11693. var projectList []*models.HisPrescriptionProject
  11694. var advice_ids []int64
  11695. var project_ids []int64
  11696. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11697. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11698. //var tempPrescription *models.HisPrescriptionProjectscription
  11699. if len(prescriptions) > 0 {
  11700. for _, item := range prescriptions {
  11701. items := item.(map[string]interface{})
  11702. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11703. advices := items["advices"].([]interface{})
  11704. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11705. groupNo := int64(0)
  11706. ctime := time.Now().Unix()
  11707. mtime := ctime
  11708. if len(advices) > 0 {
  11709. for _, advice := range advices {
  11710. var s models.HisDoctorAdviceInfo
  11711. s.AdviceType = 2
  11712. s.StopState = 2
  11713. s.ExecutionState = 2
  11714. s.Status = 1
  11715. s.Groupno = groupNo
  11716. s.CreatedTime = ctime
  11717. s.UpdatedTime = mtime
  11718. s.IsSettle = 2
  11719. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11720. //存储切片中
  11721. if s.ID > 0 {
  11722. advice_ids = append(advice_ids, s.ID)
  11723. adviceList = append(adviceList, &s)
  11724. }
  11725. }
  11726. }
  11727. }
  11728. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11729. projects := items["project"].([]interface{})
  11730. if len(projects) > 0 {
  11731. for _, project := range projects {
  11732. var p models.HisPrescriptionProject
  11733. p.Ctime = time.Now().Unix()
  11734. p.Mtime = time.Now().Unix()
  11735. p.Status = 1
  11736. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11737. if p.ID > 0 {
  11738. project_ids = append(project_ids, p.ID)
  11739. projectList = append(projectList, &p)
  11740. }
  11741. }
  11742. }
  11743. }
  11744. }
  11745. }
  11746. }
  11747. editCustomData.projectList = projectList
  11748. editCustomData.adviceList = adviceList
  11749. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11750. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11751. srcCustomData.adviceList = list
  11752. srcCustomData.projectList = list2
  11753. return
  11754. }