his_api_controller.go 505KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005
  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. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "his_info": his_patient_info,
  1461. "xt_info": xt_patient_info,
  1462. "prescription": prescriptions,
  1463. "case_history": case_history,
  1464. "info": patientPrescriptionInfo,
  1465. //"month_prescriptions": monthPrescriptions,
  1466. "order": order,
  1467. "doctors": doctors,
  1468. "department": department,
  1469. "sch_prescriptions": sch_prescriptions,
  1470. "last_prescriptions": last_prescriptions,
  1471. "schedule": sch,
  1472. "count": count,
  1473. "drugStockConfig": drugStockConfig,
  1474. "last_info": lastPatientPrescriptionInfo,
  1475. })
  1476. return
  1477. }
  1478. func (c *HisApiController) GetHisPrescriptionConfig() {
  1479. adminInfo := c.GetAdminUserInfo()
  1480. //获取医嘱模版
  1481. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1483. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1484. //获取所有基础药
  1485. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1486. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1487. if config.ID > 0 && config.IsOpen == 1 {
  1488. for _, item := range drugs {
  1489. var index = 0
  1490. for _, subItem := range item.OtherDrugWarehouseInfo {
  1491. if index == 0 {
  1492. index = index + 1
  1493. if subItem.RetailPrice > 0 {
  1494. item.MinPrice = subItem.RetailPrice
  1495. }
  1496. }
  1497. }
  1498. }
  1499. }
  1500. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1501. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1502. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1503. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1504. //获取所有科室信息
  1505. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1506. //获取诊断信息
  1507. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1508. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1509. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1510. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1511. //获取是否开启保存耗材出库的开关
  1512. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "drugs": drugs,
  1515. "advices_template": advices,
  1516. "drugways": drugways,
  1517. "efs": efs,
  1518. "doctors": doctors,
  1519. "department": department,
  1520. "sick": sick,
  1521. "additions": additions,
  1522. "diagnose": diagnose,
  1523. "manufacturers": manufacturers,
  1524. "goodOutOpen": goodOutOpen,
  1525. "patientDiagnose": patientDiagnose,
  1526. })
  1527. }
  1528. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1529. //获取所有基础药
  1530. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1531. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1532. if config.ID > 0 && config.IsOpen == 1 {
  1533. for _, item := range drugs {
  1534. var index = 0
  1535. for _, subItem := range item.OtherDrugWarehouseInfo {
  1536. if index == 0 {
  1537. index = index + 1
  1538. if subItem.RetailPrice > 0 {
  1539. item.MinPrice = subItem.RetailPrice
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1546. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1547. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1548. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1551. //获取诊断信息
  1552. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1553. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1554. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1555. //获取是否开启保存耗材出库的开关
  1556. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1557. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1558. c.ServeSuccessJSON(map[string]interface{}{
  1559. "drugs": drugs,
  1560. "advices_template": advices,
  1561. "drugways": drugways,
  1562. "efs": efs,
  1563. "doctors": doctors,
  1564. "department": department,
  1565. "sick": sick,
  1566. "additions": additions,
  1567. "diagnose": diagnose,
  1568. "manufacturers": manufacturers,
  1569. "goodOutOpen": goodOutOpen,
  1570. "patientDiagnose": patientDiagnose,
  1571. })
  1572. }
  1573. }
  1574. func (c *HisApiController) CreateHisPrescription() {
  1575. record_date := c.GetString("record_date")
  1576. patient_id, _ := c.GetInt64("patient_id")
  1577. reg_type, _ := c.GetInt64("reg_type")
  1578. diagnose := c.GetString("diagnose")
  1579. sick_type, _ := c.GetInt64("sick_type")
  1580. sick_history := c.GetString("sick_history")
  1581. doctor_id, _ := c.GetInt64("doctor", 0)
  1582. department, _ := c.GetInt64("department", 0)
  1583. his_patient_id, _ := c.GetInt64("his_patient_id")
  1584. p_type, _ := c.GetInt64("p_type")
  1585. patient_diagnose := c.GetString("patient_diagnose")
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //edit, src := GetCompareData(dataBody)
  1594. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1595. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1596. //fmt.Println(drugResult)
  1597. //fmt.Println(goodResult)
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. adminInfo := c.GetAdminUserInfo()
  1606. recordDateTime := theTime.Unix()
  1607. //查询默认出库仓库库存
  1608. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1610. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1611. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1612. if len(lists) == 1 {
  1613. his_patient_id = lists[0].ID
  1614. }
  1615. }
  1616. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1617. //自动出库的开关开启
  1618. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1619. //自动出库
  1620. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1621. //耗材保存处方出库
  1622. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1623. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1624. //已发药和已收费限制逻辑
  1625. isMidicine := false
  1626. isCharge := false
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1633. utils.ErrorLog("id")
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. id := int64(items["id"].(float64))
  1638. if id > 0 {
  1639. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1640. if err != nil {
  1641. if new_prescription.OrderStatus == 4 {
  1642. isCharge = true
  1643. }
  1644. }
  1645. }
  1646. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1647. advices := items["advices"].([]interface{})
  1648. if len(advices) > 0 {
  1649. for _, advice := range advices {
  1650. var adviceId int64
  1651. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1652. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1653. }
  1654. if adviceId > 0 {
  1655. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1656. if err == nil {
  1657. if his_advice_info.IsMedicine == 1 {
  1658. isMidicine = true
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. }
  1667. }
  1668. if isMidicine == true {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1670. return
  1671. }
  1672. if isCharge == true {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1674. return
  1675. }
  1676. // 开始主事务
  1677. db := service.XTWriteDB()
  1678. tx := db.Begin()
  1679. // 在函数结束时处理事务回滚
  1680. defer func() {
  1681. if r := recover(); r != nil {
  1682. tx.Rollback()
  1683. }
  1684. }()
  1685. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1686. //药品发药出库
  1687. if pharmacyConfig.IsOpen == 1 {
  1688. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1689. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1690. if len(prescriptions) > 0 {
  1691. for _, item := range prescriptions {
  1692. items := item.(map[string]interface{})
  1693. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1694. advices := items["advices"].([]interface{})
  1695. if len(advices) > 0 {
  1696. for _, advice := range advices {
  1697. var drug_id int64
  1698. var prescribing_number float64
  1699. var prescribingNumberUnit string
  1700. var adviceId int64
  1701. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1702. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1703. }
  1704. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1705. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1706. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1709. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1710. }
  1711. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1712. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1713. }
  1714. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1715. if drug.ID == 0 {
  1716. tx.Rollback()
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. //查询药品的所有库存
  1721. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1722. var total_count int64
  1723. for _, it := range list {
  1724. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1725. }
  1726. totals := strconv.FormatInt(total_count, 10)
  1727. //查询该药品是否存在开药记录
  1728. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1729. //新增处方盘点库存是否充足
  1730. if advicelist.ID == 0 {
  1731. all_count, _ := strconv.ParseFloat(totals, 64)
  1732. if prescribingNumberUnit == drug.MinUnit {
  1733. if drug.IsUse != 1 {
  1734. if drug.IsProject == 0 || drug.IsProject == 2 {
  1735. if all_count == 0 {
  1736. tx.Rollback()
  1737. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1738. return
  1739. }
  1740. if prescribing_number > all_count {
  1741. tx.Rollback()
  1742. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1743. return
  1744. }
  1745. }
  1746. }
  1747. }
  1748. if prescribingNumberUnit == drug.MaxUnit {
  1749. num := prescribing_number * float64(drug.MinNumber)
  1750. if drug.IsUse != 1 {
  1751. if drug.IsProject == 0 || drug.IsProject == 2 {
  1752. if all_count == 0 {
  1753. tx.Rollback()
  1754. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1755. return
  1756. }
  1757. if num > all_count {
  1758. tx.Rollback()
  1759. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1760. return
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1767. //不使用保存处方出库
  1768. if drugOutConfig.IsOpen != 1 {
  1769. //修改处方
  1770. for _, advice := range advices {
  1771. var drug_id int64
  1772. var prescribing_number float64
  1773. var prescribingNumberUnit string
  1774. var prescribingNumber string
  1775. var adviceId int64
  1776. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1777. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1778. }
  1779. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1780. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1781. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1782. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1783. }
  1784. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1785. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1786. }
  1787. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1788. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1789. }
  1790. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1791. if drug.ID == 0 {
  1792. tx.Rollback()
  1793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1794. return
  1795. }
  1796. //查询药品的所有库存
  1797. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1798. var total_count int64
  1799. for _, it := range list {
  1800. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1801. }
  1802. totals := strconv.FormatInt(total_count, 10)
  1803. //查询该药品是否存在开药记录
  1804. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1805. //新增处方
  1806. if advicelist.ID == 0 {
  1807. all_count, _ := strconv.ParseFloat(totals, 64)
  1808. if prescribingNumberUnit == drug.MinUnit {
  1809. if drug.IsUse != 1 {
  1810. if drug.IsProject == 0 || drug.IsProject == 2 {
  1811. if all_count == 0 {
  1812. tx.Rollback()
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. if prescribing_number > all_count {
  1817. tx.Rollback()
  1818. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1819. return
  1820. }
  1821. }
  1822. }
  1823. } else {
  1824. if prescribingNumberUnit == drug.MaxUnit {
  1825. num := prescribing_number * float64(drug.MinNumber)
  1826. if drug.IsUse != 1 {
  1827. if drug.IsProject == 0 || drug.IsProject == 2 {
  1828. if all_count == 0 {
  1829. tx.Rollback()
  1830. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1831. return
  1832. }
  1833. if num > all_count {
  1834. tx.Rollback()
  1835. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1836. return
  1837. }
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. //修改处方
  1844. if advicelist.ID > 0 {
  1845. var device_number int64
  1846. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1849. device_number = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1853. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1854. device_number = prescribingNumberInt
  1855. }
  1856. var number_count int64
  1857. if prescribingNumberUnit == drug.MaxUnit {
  1858. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1859. number_count = prescribingNumberInt * drug.MinNumber
  1860. }
  1861. if prescribingNumberUnit == drug.MinUnit {
  1862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1863. number_count = prescribingNumberInt
  1864. }
  1865. //如果修改的数量大于之前修改的数量
  1866. if (number_count - device_number) > 0 {
  1867. //如果修改的差数量 大于库存数量
  1868. if drug.IsUse != 1 {
  1869. if (number_count - device_number) > total_count {
  1870. tx.Rollback()
  1871. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1872. return
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. //已发药和已收费限制逻辑
  1887. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1888. //校验库存总量
  1889. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1890. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1891. if len(prescriptions) > 0 {
  1892. for _, item := range prescriptions {
  1893. items := item.(map[string]interface{})
  1894. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1895. advices := items["advices"].([]interface{})
  1896. if len(advices) > 0 {
  1897. for _, advice := range advices {
  1898. var drug_id int64
  1899. var prescribing_number float64
  1900. var prescribingNumberUnit string
  1901. var adviceId int64
  1902. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1903. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1904. }
  1905. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1906. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1907. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1908. }
  1909. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1910. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1911. }
  1912. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1913. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1914. }
  1915. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1916. if drug.ID == 0 {
  1917. tx.Rollback()
  1918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1919. return
  1920. }
  1921. //查询药品的所有库存
  1922. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1923. var total_count int64
  1924. for _, it := range list {
  1925. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1926. }
  1927. totals := strconv.FormatInt(total_count, 10)
  1928. //查询该药品是否存在开药记录
  1929. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1930. //查询最新批次库存
  1931. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1932. var batch_number_count int64
  1933. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1934. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1935. //新增处方
  1936. if advicelist.ID == 0 {
  1937. all_count, _ := strconv.ParseFloat(totals, 64)
  1938. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1939. if prescribingNumberUnit == drug.MinUnit {
  1940. if drug.IsUse != 1 {
  1941. if drug.IsProject == 0 || drug.IsProject == 2 {
  1942. if all_count == 0 {
  1943. tx.Rollback()
  1944. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1945. return
  1946. }
  1947. if prescribing_number > all_count {
  1948. tx.Rollback()
  1949. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1950. return
  1951. }
  1952. }
  1953. if adminInfo.CurrentOrgId == 10215 {
  1954. if prescribing_number > batch_number_all_count {
  1955. tx.Rollback()
  1956. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1957. return
  1958. }
  1959. }
  1960. }
  1961. }
  1962. if prescribingNumberUnit == drug.MaxUnit {
  1963. num := prescribing_number * float64(drug.MinNumber)
  1964. if drug.IsUse != 1 {
  1965. if drug.IsProject == 0 || drug.IsProject == 2 {
  1966. if all_count == 0 {
  1967. tx.Rollback()
  1968. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1969. return
  1970. }
  1971. if num > all_count {
  1972. tx.Rollback()
  1973. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1974. return
  1975. }
  1976. }
  1977. if adminInfo.CurrentOrgId == 10215 {
  1978. if num > batch_number_all_count {
  1979. tx.Rollback()
  1980. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1981. return
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1988. if drugOutConfig.IsOpen != 1 {
  1989. //修改处方
  1990. for _, advice := range advices {
  1991. var drug_id int64
  1992. var prescribing_number float64
  1993. var prescribingNumberUnit string
  1994. var prescribingNumber string
  1995. var adviceId int64
  1996. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1997. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1998. }
  1999. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2000. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2001. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2002. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2003. }
  2004. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2005. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2006. }
  2007. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2008. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2009. }
  2010. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2011. if drug.ID == 0 {
  2012. tx.Rollback()
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2014. return
  2015. }
  2016. //查询药品的所有库存
  2017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2018. var total_count int64
  2019. for _, it := range list {
  2020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2021. }
  2022. totals := strconv.FormatInt(total_count, 10)
  2023. //查询该药品是否存在开药记录
  2024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2025. //新增处方
  2026. if advicelist.ID == 0 {
  2027. //查询最新批次库存
  2028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2029. var batch_number_count int64
  2030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2032. all_count, _ := strconv.ParseFloat(totals, 64)
  2033. if prescribingNumberUnit == drug.MinUnit {
  2034. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2035. if drug.IsUse != 1 {
  2036. if drug.IsProject == 0 || drug.IsProject == 2 {
  2037. if all_count == 0 {
  2038. tx.Rollback()
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2040. return
  2041. }
  2042. if prescribing_number > all_count {
  2043. tx.Rollback()
  2044. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2045. return
  2046. }
  2047. }
  2048. if adminInfo.CurrentOrgId == 10215 {
  2049. if prescribing_number > batch_number_all_count {
  2050. tx.Rollback()
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2052. return
  2053. }
  2054. }
  2055. }
  2056. } else {
  2057. if prescribingNumberUnit == drug.MaxUnit {
  2058. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2059. num := prescribing_number * float64(drug.MinNumber)
  2060. if drug.IsUse != 1 {
  2061. if drug.IsProject == 0 || drug.IsProject == 2 {
  2062. if all_count == 0 {
  2063. tx.Rollback()
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2065. return
  2066. }
  2067. if num > all_count {
  2068. tx.Rollback()
  2069. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2070. return
  2071. }
  2072. }
  2073. if adminInfo.CurrentOrgId == 10215 {
  2074. if prescribing_number > batch_number_all_count {
  2075. tx.Rollback()
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2077. return
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. }
  2084. //修改处方
  2085. if advicelist.ID > 0 {
  2086. //查询最新批次库存
  2087. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2088. var batch_number_count int64
  2089. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2090. var device_number int64
  2091. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt * drug.MinNumber
  2095. }
  2096. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2097. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2099. device_number = prescribingNumberInt
  2100. }
  2101. var number_count int64
  2102. if prescribingNumberUnit == drug.MaxUnit {
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2104. number_count = prescribingNumberInt * drug.MinNumber
  2105. }
  2106. if prescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt
  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. fmt.Println("sum_in_count", sum_in_count)
  2161. //如果修改的数量大于有库存的第一个批次
  2162. if number_count > sum_in_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. if pharmacyConfig.IsOpen != 1 {
  2173. if device_number != number_count {
  2174. // 查询该药品最后一次出库记录
  2175. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2176. //回退库存
  2177. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2178. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2179. }
  2180. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2181. var stock_max_number int64
  2182. var stock_min_number int64
  2183. if number_count >= drug.MinNumber {
  2184. stock_max_number = device_number / drug.MinNumber
  2185. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2186. stock_min_number = device_number % drug.MinNumber
  2187. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2188. } else {
  2189. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2190. }
  2191. }
  2192. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2193. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2194. }
  2195. //删除记录
  2196. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2197. //查询默认仓库剩余多少库存
  2198. var sum_count int64
  2199. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2200. for _, its := range stockInfo {
  2201. if its.MaxUnit == drug.MaxUnit {
  2202. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2203. }
  2204. sum_count += its.StockMaxNumber + its.StockMinNumber
  2205. }
  2206. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. //保存处方开药
  2213. if drugOutConfig.IsOpen == 1 {
  2214. //修改处方
  2215. for _, advice := range advices {
  2216. var drug_id int64
  2217. var prescribing_number float64
  2218. var prescribingNumberUnit string
  2219. var prescribingNumber string
  2220. var adviceId int64
  2221. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2222. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2223. }
  2224. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2225. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2226. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2227. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2228. }
  2229. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2230. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2231. }
  2232. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2233. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2234. }
  2235. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2236. if drug.ID == 0 {
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2238. return
  2239. }
  2240. //查询药品的所有库存
  2241. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2242. var total_count int64
  2243. for _, it := range list {
  2244. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2245. }
  2246. totals := strconv.FormatInt(total_count, 10)
  2247. //查询该药品是否存在开药记录
  2248. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2249. //新增处方
  2250. if advicelist.ID == 0 {
  2251. //查询最新批次库存
  2252. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2253. var batch_number_count int64
  2254. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2255. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2256. all_count, _ := strconv.ParseFloat(totals, 64)
  2257. if prescribingNumberUnit == drug.MinUnit {
  2258. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2259. if drug.IsUse != 1 {
  2260. if drug.IsProject == 0 || drug.IsProject == 2 {
  2261. if all_count == 0 {
  2262. tx.Rollback()
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2264. return
  2265. }
  2266. if prescribing_number > all_count {
  2267. tx.Rollback()
  2268. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2269. return
  2270. }
  2271. }
  2272. if adminInfo.CurrentOrgId == 10215 {
  2273. if prescribing_number > batch_number_all_count {
  2274. tx.Rollback()
  2275. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2276. return
  2277. }
  2278. }
  2279. }
  2280. } else {
  2281. if prescribingNumberUnit == drug.MaxUnit {
  2282. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2283. num := prescribing_number * float64(drug.MinNumber)
  2284. if drug.IsUse != 1 {
  2285. if drug.IsProject == 0 || drug.IsProject == 2 {
  2286. if all_count == 0 {
  2287. tx.Rollback()
  2288. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2289. return
  2290. }
  2291. if num > all_count {
  2292. tx.Rollback()
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. }
  2297. if adminInfo.CurrentOrgId == 10215 {
  2298. if prescribing_number > batch_number_all_count {
  2299. tx.Rollback()
  2300. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2301. return
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. //修改处方
  2309. if advicelist.ID > 0 {
  2310. //查询最新批次库存
  2311. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2312. var batch_number_count int64
  2313. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2314. var device_number int64
  2315. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2316. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2317. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2318. device_number = prescribingNumberInt * drug.MinNumber
  2319. }
  2320. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2321. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2322. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2323. device_number = prescribingNumberInt
  2324. }
  2325. var number_count int64
  2326. if prescribingNumberUnit == drug.MaxUnit {
  2327. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2328. number_count = prescribingNumberInt * drug.MinNumber
  2329. }
  2330. if prescribingNumberUnit == drug.MinUnit {
  2331. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2332. number_count = prescribingNumberInt
  2333. }
  2334. fmt.Println("number_count--------------", number_count)
  2335. fmt.Println("device_number--------------", device_number)
  2336. fmt.Println("batch_number_count", batch_number_count)
  2337. //如果修改的数量大于之前修改的数量
  2338. if (number_count - device_number) > 0 {
  2339. //如果修改的差数量 大于库存数量
  2340. if drug.IsUse != 1 {
  2341. if drug.IsProject == 0 || drug.IsProject == 2 {
  2342. if total_count == 0 {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2345. return
  2346. }
  2347. if (number_count - device_number) > total_count {
  2348. tx.Rollback()
  2349. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2350. return
  2351. }
  2352. }
  2353. if adminInfo.CurrentOrgId == 10215 {
  2354. if (number_count - device_number) > batch_number_count {
  2355. tx.Rollback()
  2356. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2357. return
  2358. }
  2359. }
  2360. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2361. //查询历史出库数据总批次
  2362. // 查询该药品最后一次出库记录
  2363. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2364. var out_count int64
  2365. var in_count int64
  2366. var stock_max_number int64
  2367. var stock_min_number int64
  2368. for _, it := range outInfo {
  2369. if it.CountUnit == drug.MaxUnit {
  2370. it.Count = it.Count * drug.MinNumber
  2371. }
  2372. out_count += it.Count
  2373. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2374. stock_max_number = warehouseInfoList.StockMaxNumber
  2375. stock_min_number = warehouseInfoList.StockMinNumber
  2376. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2377. }
  2378. if out_count > 0 {
  2379. if (number_count - device_number) > in_count {
  2380. tx.Rollback()
  2381. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2382. return
  2383. }
  2384. }
  2385. // 未出库
  2386. if out_count == 0 {
  2387. var sum_in_count int64
  2388. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2389. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2390. if sum_in_count == 0 {
  2391. tx.Rollback()
  2392. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2393. return
  2394. }
  2395. //如果修改的数量大于有库存的第一个批次
  2396. if number_count > sum_in_count {
  2397. tx.Rollback()
  2398. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2399. return
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. //校验耗材库存
  2416. if goodOutConfig.IsOpen == 1 {
  2417. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2418. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2419. if len(prescriptions) > 0 {
  2420. for _, item := range prescriptions {
  2421. items := item.(map[string]interface{})
  2422. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2423. projects := items["project"].([]interface{})
  2424. if len(projects) > 0 {
  2425. for _, project := range projects {
  2426. var project_id int64
  2427. var project_type int64
  2428. var totals float64
  2429. var project_name string
  2430. var parsetotal int64
  2431. var id int64
  2432. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2433. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2434. }
  2435. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2436. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2437. }
  2438. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2439. total, _ := project.(map[string]interface{})["total"].(string)
  2440. totals, _ = strconv.ParseFloat(total, 64)
  2441. }
  2442. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2443. project_name = project.(map[string]interface{})["project_name"].(string)
  2444. }
  2445. if project_type == 3 {
  2446. //查找该耗材的出库记录
  2447. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2448. if len(goodWarehouseInfo) == 0 {
  2449. //查询耗材库存
  2450. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2451. var stock_count int64
  2452. for _, it := range list {
  2453. stock_count += it.StockCount
  2454. }
  2455. stock_counts := strconv.FormatInt(stock_count, 10)
  2456. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2457. if stock_total_count == 0 {
  2458. tx.Rollback()
  2459. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2460. return
  2461. }
  2462. if totals > stock_total_count {
  2463. tx.Rollback()
  2464. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2465. return
  2466. }
  2467. }
  2468. if len(goodWarehouseInfo) > 0 {
  2469. //查询该患者耗材的历史数据
  2470. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2471. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2472. //数量发生改变
  2473. if parsetotal != count {
  2474. //如果现在的数量大于历史数量,就要看库存是否足够
  2475. if parsetotal > count {
  2476. //查询耗材所有库存
  2477. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2478. var stock_count int64
  2479. for _, it := range list {
  2480. stock_count += it.StockCount
  2481. }
  2482. //库存不足
  2483. if stock_count == 0 {
  2484. tx.Rollback()
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. if (parsetotal - count) > stock_count {
  2489. tx.Rollback()
  2490. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2491. return
  2492. }
  2493. }
  2494. }
  2495. }
  2496. }
  2497. }
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. //不使用耗材保存处方出库
  2505. if goodOutConfig.IsOpen != 1 {
  2506. if stockConfig.IsOpen == 1 {
  2507. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2508. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2509. if len(prescriptions) > 0 {
  2510. for _, item := range prescriptions {
  2511. items := item.(map[string]interface{})
  2512. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2513. projects := items["project"].([]interface{})
  2514. if len(projects) > 0 {
  2515. for _, project := range projects {
  2516. var project_id int64
  2517. var project_type int64
  2518. var totals float64
  2519. var project_name string
  2520. var parsetotal int64
  2521. var id int64
  2522. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2523. id = int64(project.(map[string]interface{})["id"].(float64))
  2524. }
  2525. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2526. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2527. }
  2528. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2529. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2530. }
  2531. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2532. total, _ := project.(map[string]interface{})["total"].(string)
  2533. totals, _ = strconv.ParseFloat(total, 64)
  2534. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2535. }
  2536. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2537. project_name = project.(map[string]interface{})["project_name"].(string)
  2538. }
  2539. if project_type == 3 {
  2540. //查找该耗材的出库记录
  2541. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2542. //没有出库记录
  2543. if len(goodWarehouseInfo) == 0 {
  2544. //查询耗材库存
  2545. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2546. var stock_count int64
  2547. for _, it := range list {
  2548. stock_count += it.StockCount
  2549. }
  2550. stock_counts := strconv.FormatInt(stock_count, 10)
  2551. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2552. if stock_total_count == 0 {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2555. return
  2556. }
  2557. if totals > stock_total_count {
  2558. tx.Rollback()
  2559. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2560. return
  2561. }
  2562. //查找今日该患者已经出库的所有耗材
  2563. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2564. for _, item := range goodList {
  2565. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2566. var flush_count int64
  2567. for _, it := range goodListSix {
  2568. flush_count += it.StockCount
  2569. }
  2570. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2571. creater := adminInfo.AdminUser.Id
  2572. if errs != nil {
  2573. goodErrcode := models.XtGoodErrcode{
  2574. UserOrgId: item.OrgId,
  2575. Errcode: "手动出库更新剩余出库失败",
  2576. GoodId: item.GoodId,
  2577. Status: 1,
  2578. Ctime: time.Now().Unix(),
  2579. Mtime: 0,
  2580. Count: 0,
  2581. StockCount: 0,
  2582. Creater: creater,
  2583. BatchNumberId: 0,
  2584. WarehouseOutId: 0,
  2585. }
  2586. service.CreateGoodErrcode(goodErrcode)
  2587. }
  2588. }
  2589. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2590. }
  2591. //有出库记录
  2592. if len(goodWarehouseInfo) > 0 {
  2593. //查询该患者耗材的历史数据
  2594. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2595. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2596. //数量发生改变
  2597. if parsetotal != count {
  2598. //查找今日该患者已经出库的所有耗材
  2599. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2600. for _, item := range goodList {
  2601. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2602. var flush_count int64
  2603. for _, it := range goodListSix {
  2604. flush_count += it.StockCount
  2605. }
  2606. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2607. //减少出库数量
  2608. creater := adminInfo.AdminUser.Id
  2609. if errs != nil {
  2610. goodErrcode := models.XtGoodErrcode{
  2611. UserOrgId: item.OrgId,
  2612. Errcode: "手动出库更新剩余出库失败",
  2613. GoodId: item.GoodId,
  2614. Status: 1,
  2615. Ctime: time.Now().Unix(),
  2616. Mtime: 0,
  2617. Count: 0,
  2618. StockCount: 0,
  2619. Creater: creater,
  2620. BatchNumberId: 0,
  2621. WarehouseOutId: 0,
  2622. }
  2623. service.CreateGoodErrcode(goodErrcode)
  2624. }
  2625. //查询默认仓库
  2626. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2627. var total_count int64
  2628. for _, it := range stockList {
  2629. total_count += it.StockCount
  2630. }
  2631. //基础库插入数据
  2632. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2633. }
  2634. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2635. }
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2647. var hpInfo models.HisPrescriptionInfo
  2648. if info.ID == 0 {
  2649. var randNum int
  2650. randNum = rand.Intn(10000) + 1000
  2651. timestamp := time.Now().Unix()
  2652. tempTime := time.Unix(timestamp, 0)
  2653. timeFormat := tempTime.Format("20060102150405")
  2654. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2655. hpInfo = models.HisPrescriptionInfo{
  2656. HisPatientId: his_patient_id,
  2657. UserOrgId: adminInfo.CurrentOrgId,
  2658. RecordDate: theTime.Unix(),
  2659. PatientId: patient_id,
  2660. Status: 1,
  2661. Ctime: time.Now().Unix(),
  2662. Mtime: time.Now().Unix(),
  2663. Creator: adminInfo.AdminUser.Id,
  2664. Modifier: adminInfo.AdminUser.Id,
  2665. Diagnosis: diagnose,
  2666. SickHistory: sick_history,
  2667. Departments: department,
  2668. RegisterType: reg_type,
  2669. PrescriptionNumber: p_number,
  2670. PrescriptionStatus: 1,
  2671. Doctor: role.UserName,
  2672. DoctorId: doctor_id,
  2673. SickType: sick_type,
  2674. PType: p_type,
  2675. PatientDiagnosis: patient_diagnose,
  2676. }
  2677. service.SavePatientPrescriptionInfo(hpInfo)
  2678. //创建步骤表
  2679. finish := models.XtDialysisFinish{
  2680. IsFinish: 1,
  2681. UserOrgId: adminInfo.CurrentOrgId,
  2682. Status: 1,
  2683. Ctime: time.Now().Unix(),
  2684. Mtime: 0,
  2685. Module: 4,
  2686. RecordDate: theTime.Unix(),
  2687. Sourse: 1,
  2688. PatientId: patient_id,
  2689. }
  2690. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2691. if dialysisFinish.ID == 0 {
  2692. service.CreateDialysisFinish(finish)
  2693. }
  2694. redis := service.RedisClient()
  2695. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2696. redis.Set(key, "", time.Second)
  2697. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2698. redis.Set(keyOne, "", time.Second)
  2699. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2700. redis.Set(keySeven, "", time.Second)
  2701. defer redis.Close()
  2702. } else {
  2703. hpInfo = models.HisPrescriptionInfo{
  2704. ID: info.ID,
  2705. UserOrgId: adminInfo.CurrentOrgId,
  2706. RecordDate: info.RecordDate,
  2707. PatientId: info.PatientId,
  2708. Status: 1,
  2709. Ctime: info.Ctime,
  2710. Mtime: time.Now().Unix(),
  2711. Creator: info.Creator,
  2712. Modifier: adminInfo.AdminUser.Id,
  2713. Diagnosis: diagnose,
  2714. SickHistory: sick_history,
  2715. Departments: department,
  2716. RegisterType: reg_type,
  2717. PrescriptionNumber: info.PrescriptionNumber,
  2718. Doctor: role.UserName,
  2719. PrescriptionStatus: info.PrescriptionStatus,
  2720. DoctorId: doctor_id,
  2721. SickType: sick_type,
  2722. PType: info.PType,
  2723. HisPatientId: info.HisPatientId,
  2724. PatientDiagnosis: patient_diagnose,
  2725. }
  2726. service.SavePatientPrescriptionInfo(hpInfo)
  2727. //创建步骤表
  2728. finish := models.XtDialysisFinish{
  2729. IsFinish: 1,
  2730. UserOrgId: adminInfo.CurrentOrgId,
  2731. Status: 1,
  2732. Ctime: time.Now().Unix(),
  2733. Mtime: 0,
  2734. Module: 4,
  2735. RecordDate: info.RecordDate,
  2736. Sourse: 1,
  2737. PatientId: info.PatientId,
  2738. }
  2739. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2740. if dialysisFinish.ID == 0 {
  2741. service.CreateDialysisFinish(finish)
  2742. }
  2743. redis := service.RedisClient()
  2744. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2745. redis.Set(key, "", time.Second)
  2746. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2747. redis.Set(keyOne, "", time.Second)
  2748. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2749. redis.Set(keySeven, "", time.Second)
  2750. defer redis.Close()
  2751. }
  2752. //定义切片
  2753. var adviceList []models.HisDoctorAdviceInfo
  2754. var projectList []models.HisPrescriptionProject
  2755. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 {
  2756. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2757. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2758. var tempPrescription *models.HisPrescription
  2759. if len(prescriptions) > 0 {
  2760. for _, item := range prescriptions {
  2761. // 开始外部循环的事务
  2762. tx := db.Begin()
  2763. // 在函数结束时处理事务回滚
  2764. defer func() {
  2765. if r := recover(); r != nil {
  2766. tx.Rollback()
  2767. }
  2768. }()
  2769. items := item.(map[string]interface{})
  2770. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2771. utils.ErrorLog("id")
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2773. return
  2774. }
  2775. id := int64(items["id"].(float64))
  2776. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2777. tempPrescription = &new_prescription
  2778. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2779. utils.ErrorLog("type")
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2781. return
  2782. }
  2783. types := int64(items["type"].(float64))
  2784. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2785. utils.ErrorLog("med_type")
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. return
  2788. }
  2789. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2790. if med_type == "0" {
  2791. med_type = "14"
  2792. }
  2793. //if order_status == 0 {
  2794. // order_status = 1
  2795. //}
  2796. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2797. utils.ErrorLog("pre_time")
  2798. }
  2799. preTime, _ := items["pre_time"].(string)
  2800. fmt.Println("preTime", preTime)
  2801. timeLayout := "2006-01-02"
  2802. loc, _ := time.LoadLocation("Local")
  2803. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2804. result := strings.Split(preTime, " ")
  2805. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2806. if err != nil {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. pTime := theTime2.Unix()
  2811. ctime := time.Now().Unix()
  2812. if tempPrescription.ID == 0 {
  2813. prescription := &models.HisPrescription{
  2814. ID: 0,
  2815. PatientId: patient_id,
  2816. UserOrgId: adminInfo.CurrentOrgId,
  2817. RecordDate: recordDateTime,
  2818. Ctime: ctime,
  2819. Mtime: ctime,
  2820. Type: types,
  2821. Modifier: adminInfo.AdminUser.Id,
  2822. Creator: adminInfo.AdminUser.Id,
  2823. Status: 1,
  2824. Doctor: role.UserName,
  2825. HisPatientId: his_patient_id,
  2826. OrderStatus: 1,
  2827. BatchNumber: "",
  2828. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2829. PreTime: pTime,
  2830. PType: p_type,
  2831. MedType: med_type,
  2832. }
  2833. tempPrescription = prescription
  2834. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2835. redis := service.RedisClient()
  2836. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2837. redis.Set(key, "", time.Second)
  2838. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2839. redis.Set(keyOne, "", time.Second)
  2840. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2841. redis.Set(keySeven, "", time.Second)
  2842. defer redis.Close()
  2843. } else {
  2844. tempPrescription.ID = id
  2845. tempPrescription.Type = types
  2846. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2847. tempPrescription.Mtime = time.Now().Unix()
  2848. tempPrescription.Doctor = role.UserName
  2849. //tempPrescription.OrderStatus = order_status
  2850. tempPrescription.PreTime = pTime
  2851. tempPrescription.MedType = med_type
  2852. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2853. redis := service.RedisClient()
  2854. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2855. redis.Set(key, "", time.Second)
  2856. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2857. redis.Set(keyOne, "", time.Second)
  2858. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2859. redis.Set(keySeven, "", time.Second)
  2860. defer redis.Close()
  2861. }
  2862. //service.SaveHisPrescription(prescription)
  2863. //更改患者挂号状态
  2864. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2865. fmt.Println("更改失败", err2)
  2866. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2867. advices := items["advices"].([]interface{})
  2868. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2869. groupNo := int64(0)
  2870. if len(advices) > 0 {
  2871. for _, advice := range advices {
  2872. tx := db.Begin()
  2873. // 在函数结束时处理事务回滚
  2874. defer func() {
  2875. if r := recover(); r != nil {
  2876. tx.Rollback()
  2877. }
  2878. }()
  2879. var s models.HisDoctorAdviceInfo
  2880. s.PrescriptionId = tempPrescription.ID
  2881. s.AdviceType = 2
  2882. s.AdviceDoctor = doctor_id
  2883. s.StopState = 2
  2884. s.ExecutionState = 2
  2885. s.AdviceDate = theTime3.Unix()
  2886. s.Status = 1
  2887. s.UserOrgId = adminInfo.CurrentOrgId
  2888. s.RecordDate = theTime3.Unix()
  2889. s.StartTime = tempPrescription.PreTime
  2890. s.Groupno = groupNo
  2891. s.PatientId = patient_id
  2892. s.HisPatientId = his_patient_id
  2893. s.StartTime = pTime
  2894. s.IsSettle = 2
  2895. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2896. if errcode > 0 {
  2897. c.ServeFailJSONWithSGJErrorCode(errcode)
  2898. return
  2899. }
  2900. s.StartTime = pTime
  2901. var total_count int64 //处方总库存
  2902. //查询改药品信息
  2903. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2904. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2905. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2906. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2907. total_count += prescribingNumberSeven * medical.MinNumber
  2908. }
  2909. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2910. total_count += prescribingNumberSeven
  2911. }
  2912. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2913. total_count += prescribingNumberSeven
  2914. }
  2915. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2916. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2917. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2918. if s.Price != lastWarehouse.RetailPrice {
  2919. s.Price = lastWarehouse.RetailPrice
  2920. }
  2921. if s.Price == 0 {
  2922. if lastWarehouse.ID == 0 {
  2923. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2924. s.Price = lastWarehouseTwo.RetailPrice
  2925. }
  2926. }
  2927. }
  2928. //查询保存处方出库开关是否打开
  2929. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2930. if drugOutConfig.IsOpen == 1 {
  2931. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2932. // 查询该药品最后一次出库记录
  2933. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2934. var is_user_total int64
  2935. var no_user_total int64
  2936. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2937. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2938. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2939. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2940. }
  2941. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2942. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2943. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2944. no_user_total += prescribingNumberSevenTy
  2945. }
  2946. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2947. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2948. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2949. no_user_total += prescribingNumberSevenTy
  2950. }
  2951. if len(druginfo) > 0 {
  2952. for _, it := range druginfo {
  2953. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2954. it.Count = it.Count * drug.MinNumber
  2955. is_user_total += it.Count
  2956. }
  2957. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2958. is_user_total += it.Count
  2959. }
  2960. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2961. is_user_total += it.Count
  2962. }
  2963. }
  2964. }
  2965. fmt.Println("is_user_total-----------------------------", is_user_total)
  2966. fmt.Println("no_user_total-----------------------------", no_user_total)
  2967. if is_user_total != no_user_total {
  2968. if len(druginfo) > 0 {
  2969. //回退库存
  2970. //for _, it := range druginfo {
  2971. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2972. //
  2973. // service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2974. //
  2975. // }
  2976. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2977. //
  2978. // service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2979. //
  2980. // }
  2981. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2982. //
  2983. // service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2984. //
  2985. // }
  2986. //}
  2987. //删除记录
  2988. //service.DeleteNewDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2989. }
  2990. //出库
  2991. if drug.IsUse == 2 {
  2992. creater := adminInfo.AdminUser.Id
  2993. newadviceInfo := &models.HisDoctorAdviceInfo{
  2994. ID: s.ID,
  2995. UserOrgId: s.UserOrgId,
  2996. PatientId: s.PatientId,
  2997. HisPatientId: s.HisPatientId,
  2998. AdviceType: s.AdviceType,
  2999. AdviceDate: s.AdviceDate,
  3000. StartTime: s.StartTime,
  3001. AdviceName: s.AdviceName,
  3002. AdviceDesc: s.AdviceDesc,
  3003. ReminderDate: s.ReminderDate,
  3004. SingleDose: s.SingleDose,
  3005. SingleDoseUnit: s.SingleDoseUnit,
  3006. PrescribingNumber: s.PrescribingNumber,
  3007. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3008. DeliveryWay: s.DeliveryWay,
  3009. ExecutionFrequency: s.ExecutionFrequency,
  3010. AdviceDoctor: s.AdviceDoctor,
  3011. Status: s.Status,
  3012. CreatedTime: s.CreatedTime,
  3013. UpdatedTime: s.UpdatedTime,
  3014. AdviceAffirm: s.AdviceAffirm,
  3015. Remark: s.Remark,
  3016. StopTime: s.StopTime,
  3017. StopReason: s.StopReason,
  3018. StopDoctor: s.StopDoctor,
  3019. StopState: s.StopState,
  3020. ParentId: s.ParentId,
  3021. ExecutionTime: s.ExecutionTime,
  3022. ExecutionStaff: s.ExecutionStaff,
  3023. ExecutionState: s.ExecutionState,
  3024. Checker: s.Checker,
  3025. RecordDate: s.RecordDate,
  3026. DialysisOrderId: s.DialysisOrderId,
  3027. CheckTime: s.CheckTime,
  3028. CheckState: s.CheckState,
  3029. DrugSpec: s.DrugSpec,
  3030. DrugSpecUnit: s.DrugSpecUnit,
  3031. Groupno: s.Groupno,
  3032. RemindType: s.RemindType,
  3033. FrequencyType: s.FrequencyType,
  3034. DayCount: s.DayCount,
  3035. WeekDay: s.WeekDay,
  3036. TemplateId: s.TemplateId,
  3037. Modifier: s.Modifier,
  3038. DrugId: s.DrugId,
  3039. Price: s.Price,
  3040. PrescriptionId: s.PrescriptionId,
  3041. MedListCodg: s.MedListCodg,
  3042. FeedetlSn: s.FeedetlSn,
  3043. Day: s.DayCount,
  3044. ChildDoctorAdvice: nil,
  3045. Drug: models.Drug{},
  3046. Diagnosis: s.Diagnosis,
  3047. Way: s.Way,
  3048. HospApprFlag: s.HospApprFlag,
  3049. LmtUsedFlag: s.LmtUsedFlag,
  3050. HisOrderInfo: models.HisOrderInfo{},
  3051. IsMedicine: s.IsMedicine,
  3052. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3053. Child: nil,
  3054. IsSettle: s.IsSettle,
  3055. IsMobile: s.IsMobile,
  3056. IsSelfDrug: s.IsSelfDrug,
  3057. DrugWayCount: s.DrugWayCount,
  3058. }
  3059. var history_count int64
  3060. var local_count int64
  3061. //查找已经开过的医嘱信息
  3062. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3063. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3064. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3065. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3066. local_count += prescribingNumberSevenTy * drug.MinNumber
  3067. }
  3068. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3069. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3070. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3071. local_count += prescribingNumberSevenTy
  3072. }
  3073. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3074. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3075. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3076. local_count += prescribingNumberSevenTy
  3077. }
  3078. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3079. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3080. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3081. history_count += prescribingNumberSevenTy * drug.MinNumber
  3082. }
  3083. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3084. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3085. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3086. history_count += prescribingNumberSevenTy
  3087. }
  3088. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3089. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3090. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3091. history_count += prescribingNumberSevenTy
  3092. }
  3093. //fmt.Println("local_count0000000000000000000000000000000000000000000", local_count)
  3094. //
  3095. //fmt.Println("history_count999999999999999999999999999999999999999", history_count)
  3096. //如果当前出库数量大于历史出库数量则需要出库
  3097. if local_count > history_count {
  3098. //按最小单位出库
  3099. var cha_count = local_count - history_count
  3100. //fmt.Println("cha_count000000000000000000000000000", cha_count)
  3101. newadviceInfo.PrescribingNumber = float64(cha_count)
  3102. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3103. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3104. }
  3105. //如果当前出库数量小于历史出库数量则需要退库
  3106. if local_count < history_count {
  3107. var cha_count = history_count - local_count
  3108. //fmt.Println("退库----------------------------", cha_count)
  3109. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3110. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3111. }
  3112. }
  3113. //更新字典里面的库存
  3114. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3115. var sum_count int64
  3116. for _, its := range stockInfo {
  3117. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3118. if its.MaxUnit == baseDrug.MaxUnit {
  3119. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3120. }
  3121. sum_count += its.StockMaxNumber + its.StockMinNumber
  3122. }
  3123. //更新基础库存
  3124. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3125. //剩余库存
  3126. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3127. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3128. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3129. //创建医嘱
  3130. service.CreateHisDoctorAdviceOne(&s, tx)
  3131. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3132. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. if len(outInfoTwo) > 0 {
  3134. for _, item := range outInfoTwo {
  3135. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3136. }
  3137. }
  3138. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3139. if len(drugAutoDetail) > 0 {
  3140. for _, item := range drugAutoDetail {
  3141. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3142. }
  3143. }
  3144. }
  3145. }
  3146. //记录日志
  3147. byterequest, _ := json.Marshal(s)
  3148. adviceLog := models.XtDoctorAdviceLog{
  3149. UserOrgId: s.UserOrgId,
  3150. PatientId: s.PatientId,
  3151. AdminUserId: adminInfo.AdminUser.Id,
  3152. Module: 1,
  3153. ErrLog: string(byterequest),
  3154. Status: 1,
  3155. Ctime: time.Now().Unix(),
  3156. Mtime: 0,
  3157. Source: "电脑端新建his医嘱",
  3158. RecordDate: s.AdviceDate,
  3159. }
  3160. service.CreateDoctorAdviceLog(adviceLog)
  3161. //存储切片中
  3162. adviceList = append(adviceList, s)
  3163. redis := service.RedisClient()
  3164. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3165. redis.Set(key, "", time.Second)
  3166. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3167. redis.Set(keyOne, "", time.Second)
  3168. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3169. redis.Set(keySeven, "", time.Second)
  3170. var randNum int
  3171. randNum = rand.Intn(10000) + 1000
  3172. timestamp := time.Now().Unix()
  3173. tempTime := time.Unix(timestamp, 0)
  3174. timeFormat := tempTime.Format("20060102150405")
  3175. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3176. service.CreateHisDoctorAdviceOne(&s, tx)
  3177. tx.Commit()
  3178. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3179. redis.Set(keySix, "", time.Second)
  3180. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3181. redis.Set(keyFive, "", time.Second)
  3182. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3183. redis.Set(keyEight, "", time.Second)
  3184. defer redis.Close()
  3185. }
  3186. }
  3187. }
  3188. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3189. projects := items["project"].([]interface{})
  3190. if len(projects) > 0 {
  3191. for _, project := range projects {
  3192. tx := db.Begin()
  3193. // 在函数结束时处理事务回滚
  3194. defer func() {
  3195. if r := recover(); r != nil {
  3196. tx.Rollback()
  3197. }
  3198. }()
  3199. var p models.HisPrescriptionProject
  3200. p.PrescriptionId = tempPrescription.ID
  3201. p.PatientId = patient_id
  3202. p.RecordDate = theTime3.Unix()
  3203. p.Doctor = doctor_id
  3204. p.UserOrgId = adminInfo.CurrentOrgId
  3205. p.HisPatientId = his_patient_id
  3206. p.Status = 1
  3207. p.StartTime = pTime
  3208. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3209. if errcode > 0 {
  3210. c.ServeFailJSONWithSGJErrorCode(errcode)
  3211. return
  3212. }
  3213. if p.ID == 0 {
  3214. p.IsOut = 2
  3215. }
  3216. if p.ID > 0 {
  3217. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3218. p.IsOut = projectDetail.IsOut
  3219. }
  3220. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3221. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3222. if p.Type == 3 {
  3223. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3224. if p.Price != lastWarehouse.PackingPrice {
  3225. p.Price = lastWarehouse.PackingPrice
  3226. }
  3227. if p.Unit == "" {
  3228. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3229. p.Unit = goodInfoOne.PackingUnit
  3230. }
  3231. }
  3232. }
  3233. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3234. //
  3235. // if p.Type == 3 {
  3236. // //查询该耗材是否停用
  3237. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3238. // //表示该耗材已经停用,不能保存
  3239. // if goodInfoSeven.ID == 0 {
  3240. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3241. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3242. // return
  3243. // }
  3244. // }
  3245. //
  3246. //}
  3247. service.CreateNewHisProjectTwo(&p, tx)
  3248. var randNum int
  3249. randNum = rand.Intn(10000) + 1000
  3250. timestamp := time.Now().Unix()
  3251. tempTime := time.Unix(timestamp, 0)
  3252. timeFormat := tempTime.Format("20060102150405")
  3253. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3254. service.CreateNewHisProjectTwo(&p, tx)
  3255. //查询保存耗材出库开关是否打开
  3256. if goodOutConfig.IsOpen == 1 {
  3257. //耗材出库
  3258. if p.Type == 3 {
  3259. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3260. //查询历史出库数据
  3261. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3262. var out_count_five int64
  3263. for _, item := range flowGood {
  3264. out_count_five += item.Count
  3265. }
  3266. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3267. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3268. if out_count_five != parseIntCount {
  3269. //查询耗材最后一次出库记录
  3270. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3271. //查询默认出库仓库库存
  3272. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3273. if len(wareOut) > 0 {
  3274. for _, it := range wareOut {
  3275. //回退库存
  3276. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3277. //删除出库记录
  3278. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3279. }
  3280. }
  3281. timeStr := time.Now().Format("2006-01-02")
  3282. timeArr := strings.Split(timeStr, "-")
  3283. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3284. total = total + 1
  3285. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3286. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3287. number = number + total
  3288. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3289. operation_time := time.Now().Unix()
  3290. creater := c.GetAdminUserInfo().AdminUser.Id
  3291. recordDateStr := time.Now().Format("2006-01-02")
  3292. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3293. nowtime := recordDate.Unix()
  3294. warehouseOut := models.WarehouseOut{
  3295. WarehouseOutOrderNumber: warehousing_out_order,
  3296. OperationTime: operation_time,
  3297. OrgId: adminInfo.CurrentOrgId,
  3298. Creater: creater,
  3299. Ctime: time.Now().Unix(),
  3300. Status: 1,
  3301. WarehouseOutTime: nowtime,
  3302. Type: 1,
  3303. StorehouseId: storeConfig.StorehouseOutInfo,
  3304. IsCheck: 1,
  3305. IsSys: 1,
  3306. }
  3307. //查询是否生成出库单
  3308. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3309. if out.ID == 0 {
  3310. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3311. }
  3312. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3313. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3314. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3315. dialyPrepareOne := models.DialysisBeforePrepare{
  3316. GoodTypeId: goodObj.GoodTypeId,
  3317. GoodId: p.ProjectId,
  3318. PatientId: p.PatientId,
  3319. RecordDate: p.RecordDate,
  3320. UserOrgId: adminInfo.CurrentOrgId,
  3321. Count: parseIntCount,
  3322. Ctime: time.Now().Unix(),
  3323. Creater: creater,
  3324. Status: 1,
  3325. StorehouseId: houseConfig.StorehouseOutInfo,
  3326. ProjectId: lastHisProject.ID,
  3327. }
  3328. //判断是否是零用耗材(非零用)
  3329. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3330. //查询历史出库数据
  3331. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3332. var out_count int64
  3333. for _, item := range flowGood {
  3334. out_count += item.Count
  3335. }
  3336. //如果历史数和当前数据不想等才进行退库出库
  3337. if out_count != parseIntCount {
  3338. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3339. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3340. detail := models.AutomaticReduceDetail{
  3341. WarehouseOutId: 0,
  3342. WarehouseOutOrderNumber: "",
  3343. PatientId: p.PatientId,
  3344. Ctime: time.Now().Unix(),
  3345. Mtime: 0,
  3346. Status: 1,
  3347. RecordTime: p.RecordDate,
  3348. OrgId: p.UserOrgId,
  3349. GoodId: p.ProjectId,
  3350. GoodTypeId: 0,
  3351. Count: parseIntCount,
  3352. Type: 0,
  3353. ProjectId: lastHisProject.ID,
  3354. StorehouseId: 0,
  3355. }
  3356. service.CreateNewAutoDetail(detail, tx)
  3357. //查询剩余库存
  3358. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3359. var sum_count int64
  3360. for _, item := range goodList {
  3361. sum_count += item.StockCount
  3362. }
  3363. //更新剩余库存
  3364. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3365. //耗材
  3366. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3367. }
  3368. //判断是否是零用耗材(零用但是是出库耗材)
  3369. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3370. //查询历史出库数据
  3371. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3372. var out_count int64
  3373. for _, item := range flowGood {
  3374. out_count += item.Count
  3375. }
  3376. //如果历史数和当前数据不想等才进行退库出库
  3377. if out_count != parseIntCount {
  3378. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3379. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3380. detail := models.AutomaticReduceDetail{
  3381. WarehouseOutId: 0,
  3382. WarehouseOutOrderNumber: "",
  3383. PatientId: p.PatientId,
  3384. Ctime: time.Now().Unix(),
  3385. Mtime: 0,
  3386. Status: 1,
  3387. RecordTime: p.RecordDate,
  3388. OrgId: p.UserOrgId,
  3389. GoodId: p.ProjectId,
  3390. GoodTypeId: 0,
  3391. Count: parseIntCount,
  3392. Type: 0,
  3393. ProjectId: p.ID,
  3394. StorehouseId: 0,
  3395. }
  3396. service.CreateNewAutoDetail(detail, tx)
  3397. //查询剩余库存
  3398. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3399. var sum_count int64
  3400. for _, item := range goodList {
  3401. sum_count += item.StockCount
  3402. }
  3403. //更新剩余库存
  3404. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3405. //耗材
  3406. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3407. }
  3408. }
  3409. }
  3410. }
  3411. //记录日志
  3412. byterequest, _ := json.Marshal(p)
  3413. adviceLog := models.XtDoctorAdviceLog{
  3414. UserOrgId: p.UserOrgId,
  3415. PatientId: p.PatientId,
  3416. AdminUserId: adminInfo.AdminUser.Id,
  3417. Module: 1,
  3418. ErrLog: string(byterequest),
  3419. Status: 1,
  3420. Ctime: time.Now().Unix(),
  3421. Mtime: 0,
  3422. Source: "电脑端新建his项目",
  3423. RecordDate: p.RecordDate,
  3424. }
  3425. service.CreateDoctorAdviceLog(adviceLog)
  3426. projectList = append(projectList, p)
  3427. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3428. //新增或者编辑项目,修改对应的标签数据
  3429. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3430. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3431. var label models.HisLabelPrintInfo
  3432. project, _ := service.GetProjectDetail(p.ProjectId)
  3433. if project.CostClassify == 3 { //类别为检验检查
  3434. if p.TeamId > 0 { //检验检查组套
  3435. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3436. if tempLabel.ID == 0 {
  3437. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3438. label.Number = tempPrescription.PrescriptionNumber
  3439. label.ProjectId = project.ID
  3440. label.Status = 1
  3441. label.IsPrint = 2
  3442. label.DoctorId = info.DoctorId
  3443. label.UserOrgId = p.UserOrgId
  3444. label.PatientId = patient_id
  3445. label.RecordDate = recordDateTime
  3446. label.Ctime = time.Now().Unix()
  3447. label.Mtime = time.Now().Unix()
  3448. label.ItemId = p.TeamId
  3449. label.FeedetlSn = p.FeedetlSn
  3450. label.PProjectId = p.ID
  3451. label.ProjectName = team.ProjectTeam
  3452. label.PatientName = patient.Name
  3453. service.CreateNewHisLabelRecord(&label, tx)
  3454. }
  3455. } else { //单条检验检查项目
  3456. label.Number = tempPrescription.PrescriptionNumber
  3457. label.ProjectId = project.ID
  3458. label.Status = 1
  3459. label.DoctorId = info.DoctorId
  3460. label.UserOrgId = p.UserOrgId
  3461. label.PatientId = patient_id
  3462. label.RecordDate = recordDateTime
  3463. label.IsPrint = 2
  3464. label.Ctime = time.Now().Unix()
  3465. label.Mtime = time.Now().Unix()
  3466. label.FeedetlSn = p.FeedetlSn
  3467. label.PProjectId = p.ID
  3468. label.ItemId = p.TeamId
  3469. label.ProjectName = project.ProjectName
  3470. label.PatientName = patient.Name
  3471. service.CreateNewHisLabelRecord(&label, tx)
  3472. }
  3473. }
  3474. }
  3475. }
  3476. }
  3477. }
  3478. tx.Commit()
  3479. }
  3480. }
  3481. }
  3482. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3483. // addition := items["addition"].([]interface{})
  3484. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3485. // ctime := time.Now().Unix()
  3486. // mtime := ctime
  3487. // if len(addition) > 0 {
  3488. // for _, item := range addition {
  3489. // var s models.HisAdditionalCharge
  3490. // s.PrescriptionId = tempPrescription.ID
  3491. // s.Status = 1
  3492. // s.UserOrgId = adminInfo.CurrentOrgId
  3493. // s.RecordDate = recordDateTime
  3494. // s.CreatedTime = ctime
  3495. // s.UpdatedTime = mtime
  3496. // s.PatientId = patient_id
  3497. // s.HisPatientId = his_patient_id
  3498. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3499. // if errcode > 0 {
  3500. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3501. // return
  3502. // }
  3503. // service.CreateAdditionalCharge(&s)
  3504. // var randNum int
  3505. // randNum = rand.Intn(10000) + 1000
  3506. // timestamp := time.Now().Unix()
  3507. // tempTime := time.Unix(timestamp, 0)
  3508. // timeFormat := tempTime.Format("20060102150405")
  3509. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3510. // service.CreateAdditionalCharge(&s)
  3511. //
  3512. // }
  3513. // }
  3514. //}
  3515. }
  3516. }
  3517. }
  3518. tx.Commit()
  3519. if err == nil {
  3520. c.ServeSuccessJSON(map[string]interface{}{
  3521. "msg": "保存成功",
  3522. })
  3523. return
  3524. } else {
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3526. return
  3527. }
  3528. } else {
  3529. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3530. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3531. var tempPrescription *models.HisPrescription
  3532. if len(prescriptions) > 0 {
  3533. for _, item := range prescriptions {
  3534. items := item.(map[string]interface{})
  3535. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3536. utils.ErrorLog("id")
  3537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3538. return
  3539. }
  3540. id := int64(items["id"].(float64))
  3541. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3542. tempPrescription = &new_prescription
  3543. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3544. utils.ErrorLog("type")
  3545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3546. return
  3547. }
  3548. types := int64(items["type"].(float64))
  3549. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3550. utils.ErrorLog("med_type")
  3551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3552. return
  3553. }
  3554. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3555. if med_type == "0" {
  3556. med_type = "14"
  3557. }
  3558. //if order_status == 0 {
  3559. // order_status = 1
  3560. //}
  3561. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3562. utils.ErrorLog("pre_time")
  3563. }
  3564. preTime, _ := items["pre_time"].(string)
  3565. timeLayout := "2006-01-02"
  3566. loc, _ := time.LoadLocation("Local")
  3567. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3568. result := strings.Split(preTime, " ")
  3569. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3570. if err != nil {
  3571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3572. return
  3573. }
  3574. pTime := theTime2.Unix()
  3575. ctime := time.Now().Unix()
  3576. if tempPrescription.ID == 0 {
  3577. prescription := &models.HisPrescription{
  3578. ID: 0,
  3579. PatientId: patient_id,
  3580. UserOrgId: adminInfo.CurrentOrgId,
  3581. RecordDate: recordDateTime,
  3582. Ctime: ctime,
  3583. Mtime: ctime,
  3584. Type: types,
  3585. Modifier: adminInfo.AdminUser.Id,
  3586. Creator: adminInfo.AdminUser.Id,
  3587. Status: 1,
  3588. Doctor: role.UserName,
  3589. HisPatientId: his_patient_id,
  3590. OrderStatus: 1,
  3591. BatchNumber: "",
  3592. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3593. PreTime: pTime,
  3594. PType: p_type,
  3595. MedType: med_type,
  3596. }
  3597. tempPrescription = prescription
  3598. service.SaveHisPrescription(tempPrescription)
  3599. redis := service.RedisClient()
  3600. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3601. redis.Set(key, "", time.Second)
  3602. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3603. redis.Set(keyOne, "", time.Second)
  3604. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3605. redis.Set(keySeven, "", time.Second)
  3606. defer redis.Close()
  3607. } else {
  3608. tempPrescription.ID = id
  3609. tempPrescription.Type = types
  3610. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3611. tempPrescription.Mtime = time.Now().Unix()
  3612. tempPrescription.Doctor = role.UserName
  3613. //tempPrescription.OrderStatus = order_status
  3614. tempPrescription.PreTime = pTime
  3615. tempPrescription.MedType = med_type
  3616. service.SaveHisPrescription(tempPrescription)
  3617. redis := service.RedisClient()
  3618. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3619. redis.Set(key, "", time.Second)
  3620. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3621. redis.Set(keyOne, "", time.Second)
  3622. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3623. redis.Set(keySeven, "", time.Second)
  3624. defer redis.Close()
  3625. }
  3626. //service.SaveHisPrescription(prescription)
  3627. //更改患者挂号状态
  3628. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3629. fmt.Println("更改失败", err2)
  3630. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3631. advices := items["advices"].([]interface{})
  3632. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3633. groupNo := int64(0)
  3634. if len(advices) > 0 {
  3635. for _, advice := range advices {
  3636. var s models.HisDoctorAdviceInfo
  3637. s.PrescriptionId = tempPrescription.ID
  3638. s.AdviceType = 2
  3639. s.AdviceDoctor = doctor_id
  3640. s.StopState = 2
  3641. s.ExecutionState = 2
  3642. s.AdviceDate = theTime3.Unix()
  3643. s.Status = 1
  3644. s.UserOrgId = adminInfo.CurrentOrgId
  3645. s.RecordDate = theTime3.Unix()
  3646. s.StartTime = tempPrescription.PreTime
  3647. s.Groupno = groupNo
  3648. s.PatientId = patient_id
  3649. s.HisPatientId = his_patient_id
  3650. s.StartTime = pTime
  3651. s.IsSettle = 2
  3652. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3653. if errcode > 0 {
  3654. c.ServeFailJSONWithSGJErrorCode(errcode)
  3655. return
  3656. }
  3657. s.StartTime = pTime
  3658. var total_count int64 //处方总库存
  3659. //查询改药品信息
  3660. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3661. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3662. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3663. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3664. total_count += prescribingNumberSeven * medical.MinNumber
  3665. }
  3666. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3667. total_count += prescribingNumberSeven
  3668. }
  3669. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3670. total_count += prescribingNumberSeven
  3671. }
  3672. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3673. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3674. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3675. if s.Price != lastWarehouse.RetailPrice {
  3676. s.Price = lastWarehouse.RetailPrice
  3677. }
  3678. if s.Price == 0 {
  3679. s.Price = lastWarehouse.RetailPrice
  3680. }
  3681. }
  3682. service.CreateHisDoctorAdvice(&s)
  3683. //记录日志
  3684. byterequest, _ := json.Marshal(s)
  3685. adviceLog := models.XtDoctorAdviceLog{
  3686. UserOrgId: s.UserOrgId,
  3687. PatientId: s.PatientId,
  3688. AdminUserId: adminInfo.AdminUser.Id,
  3689. Module: 1,
  3690. ErrLog: string(byterequest),
  3691. Status: 1,
  3692. Ctime: time.Now().Unix(),
  3693. Mtime: 0,
  3694. Source: "电脑端新建his医嘱",
  3695. RecordDate: s.AdviceDate,
  3696. }
  3697. service.CreateDoctorAdviceLog(adviceLog)
  3698. //存储切片中
  3699. adviceList = append(adviceList, s)
  3700. redis := service.RedisClient()
  3701. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3702. redis.Set(key, "", time.Second)
  3703. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3704. redis.Set(keyOne, "", time.Second)
  3705. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3706. redis.Set(keySeven, "", time.Second)
  3707. var randNum int
  3708. randNum = rand.Intn(10000) + 1000
  3709. timestamp := time.Now().Unix()
  3710. tempTime := time.Unix(timestamp, 0)
  3711. timeFormat := tempTime.Format("20060102150405")
  3712. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3713. service.CreateHisDoctorAdvice(&s)
  3714. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3715. redis.Set(keySix, "", time.Second)
  3716. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3717. redis.Set(keyFive, "", time.Second)
  3718. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3719. redis.Set(keyEight, "", time.Second)
  3720. defer redis.Close()
  3721. }
  3722. }
  3723. }
  3724. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3725. projects := items["project"].([]interface{})
  3726. if len(projects) > 0 {
  3727. for _, project := range projects {
  3728. var p models.HisPrescriptionProject
  3729. p.PrescriptionId = tempPrescription.ID
  3730. p.PatientId = patient_id
  3731. p.RecordDate = theTime3.Unix()
  3732. p.Doctor = doctor_id
  3733. p.UserOrgId = adminInfo.CurrentOrgId
  3734. p.HisPatientId = his_patient_id
  3735. p.Status = 1
  3736. p.StartTime = pTime
  3737. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3738. if errcode > 0 {
  3739. c.ServeFailJSONWithSGJErrorCode(errcode)
  3740. return
  3741. }
  3742. if p.ID == 0 {
  3743. p.IsOut = 2
  3744. }
  3745. if p.ID > 0 {
  3746. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3747. p.IsOut = projectDetail.IsOut
  3748. }
  3749. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3750. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3751. if p.Type == 3 {
  3752. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3753. if p.Price != lastWarehouse.PackingPrice {
  3754. p.Price = lastWarehouse.PackingPrice
  3755. }
  3756. if p.Unit == "" {
  3757. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3758. p.Unit = goodInfoOne.PackingUnit
  3759. }
  3760. }
  3761. }
  3762. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3763. //
  3764. // if p.Type == 3 {
  3765. // //查询该耗材是否停用
  3766. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3767. // //表示该耗材已经停用,不能保存
  3768. // if goodInfoSeven.ID == 0 {
  3769. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3770. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3771. // return
  3772. // }
  3773. // }
  3774. //
  3775. //}
  3776. service.CreateHisProjectTwo(&p)
  3777. //记录日志
  3778. byterequest, _ := json.Marshal(p)
  3779. adviceLog := models.XtDoctorAdviceLog{
  3780. UserOrgId: p.UserOrgId,
  3781. PatientId: p.PatientId,
  3782. AdminUserId: adminInfo.AdminUser.Id,
  3783. Module: 1,
  3784. ErrLog: string(byterequest),
  3785. Status: 1,
  3786. Ctime: time.Now().Unix(),
  3787. Mtime: 0,
  3788. Source: "电脑端新建his项目",
  3789. RecordDate: p.RecordDate,
  3790. }
  3791. service.CreateDoctorAdviceLog(adviceLog)
  3792. projectList = append(projectList, p)
  3793. var randNum int
  3794. randNum = rand.Intn(10000) + 1000
  3795. timestamp := time.Now().Unix()
  3796. tempTime := time.Unix(timestamp, 0)
  3797. timeFormat := tempTime.Format("20060102150405")
  3798. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3799. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3800. //新增或者编辑项目,修改对应的标签数据
  3801. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3802. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3803. var label models.HisLabelPrintInfo
  3804. project, _ := service.GetProjectDetail(p.ProjectId)
  3805. if project.CostClassify == 3 { //类别为检验检查
  3806. if p.TeamId > 0 { //检验检查组套
  3807. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3808. if tempLabel.ID == 0 {
  3809. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3810. label.Number = tempPrescription.PrescriptionNumber
  3811. label.ProjectId = project.ID
  3812. label.Status = 1
  3813. label.IsPrint = 2
  3814. label.DoctorId = info.DoctorId
  3815. label.UserOrgId = p.UserOrgId
  3816. label.PatientId = patient_id
  3817. label.RecordDate = recordDateTime
  3818. label.Ctime = time.Now().Unix()
  3819. label.Mtime = time.Now().Unix()
  3820. label.ItemId = p.TeamId
  3821. label.FeedetlSn = p.FeedetlSn
  3822. label.PProjectId = p.ID
  3823. label.ProjectName = team.ProjectTeam
  3824. label.PatientName = patient.Name
  3825. service.CreateHisLabelRecord(&label)
  3826. }
  3827. } else { //单条检验检查项目
  3828. label.Number = tempPrescription.PrescriptionNumber
  3829. label.ProjectId = project.ID
  3830. label.Status = 1
  3831. label.DoctorId = info.DoctorId
  3832. label.UserOrgId = p.UserOrgId
  3833. label.PatientId = patient_id
  3834. label.RecordDate = recordDateTime
  3835. label.IsPrint = 2
  3836. label.Ctime = time.Now().Unix()
  3837. label.Mtime = time.Now().Unix()
  3838. label.FeedetlSn = p.FeedetlSn
  3839. label.PProjectId = p.ID
  3840. label.ItemId = p.TeamId
  3841. label.ProjectName = project.ProjectName
  3842. label.PatientName = patient.Name
  3843. service.CreateHisLabelRecord(&label)
  3844. }
  3845. }
  3846. }
  3847. }
  3848. service.SaveHisProjectTwo(&p)
  3849. }
  3850. }
  3851. }
  3852. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3853. // addition := items["addition"].([]interface{})
  3854. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3855. // ctime := time.Now().Unix()
  3856. // mtime := ctime
  3857. // if len(addition) > 0 {
  3858. // for _, item := range addition {
  3859. // var s models.HisAdditionalCharge
  3860. // s.PrescriptionId = tempPrescription.ID
  3861. // s.Status = 1
  3862. // s.UserOrgId = adminInfo.CurrentOrgId
  3863. // s.RecordDate = recordDateTime
  3864. // s.CreatedTime = ctime
  3865. // s.UpdatedTime = mtime
  3866. // s.PatientId = patient_id
  3867. // s.HisPatientId = his_patient_id
  3868. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3869. // if errcode > 0 {
  3870. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3871. // return
  3872. // }
  3873. // service.CreateAdditionalCharge(&s)
  3874. // var randNum int
  3875. // randNum = rand.Intn(10000) + 1000
  3876. // timestamp := time.Now().Unix()
  3877. // tempTime := time.Unix(timestamp, 0)
  3878. // timeFormat := tempTime.Format("20060102150405")
  3879. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3880. // service.CreateAdditionalCharge(&s)
  3881. //
  3882. // }
  3883. // }
  3884. //}
  3885. }
  3886. }
  3887. //查询今日该患者开的药品处方
  3888. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3889. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3890. //药品出库
  3891. if drugOutConfig.IsOpen == 1 {
  3892. for _, item := range hisdoctorlist {
  3893. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3894. // 查询该药品最后一次出库记录
  3895. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3896. if len(druginfo) > 0 {
  3897. //回退库存
  3898. for _, it := range druginfo {
  3899. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3900. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3901. }
  3902. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3903. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3904. }
  3905. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3906. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3907. }
  3908. }
  3909. }
  3910. //删除记录
  3911. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3912. //查询最后一次数据
  3913. if drugOutConfig.IsOpen == 1 {
  3914. //出库
  3915. if drug.IsUse == 2 {
  3916. creater := adminInfo.AdminUser.Id
  3917. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3918. }
  3919. //更新字典里面的库存
  3920. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3921. var sum_count int64
  3922. for _, its := range stockInfo {
  3923. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3924. if its.MaxUnit == baseDrug.MaxUnit {
  3925. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3926. }
  3927. sum_count += its.StockMaxNumber + its.StockMinNumber
  3928. }
  3929. //更新基础库存
  3930. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3931. //剩余库存
  3932. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3933. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3934. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3935. }
  3936. }
  3937. }
  3938. //耗材保存处方出库
  3939. if goodOutConfig.IsOpen == 1 {
  3940. //查询今日耗材出库数量
  3941. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3942. for _, item := range hisgoodlist {
  3943. //查询历史出库数据
  3944. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3945. var out_count_five int64
  3946. for _, item := range flowGood {
  3947. out_count_five += item.Count
  3948. }
  3949. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3950. if out_count_five != parseIntCount {
  3951. //查询耗材最后一次出库记录
  3952. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3953. //查询默认出库仓库库存
  3954. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3955. if len(wareOut) > 0 {
  3956. for _, it := range wareOut {
  3957. //回退库存
  3958. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3959. //删除出库记录
  3960. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3961. }
  3962. }
  3963. timeStr := time.Now().Format("2006-01-02")
  3964. timeArr := strings.Split(timeStr, "-")
  3965. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3966. total = total + 1
  3967. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3968. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3969. number = number + total
  3970. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3971. operation_time := time.Now().Unix()
  3972. creater := c.GetAdminUserInfo().AdminUser.Id
  3973. recordDateStr := time.Now().Format("2006-01-02")
  3974. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3975. nowtime := recordDate.Unix()
  3976. warehouseOut := models.WarehouseOut{
  3977. WarehouseOutOrderNumber: warehousing_out_order,
  3978. OperationTime: operation_time,
  3979. OrgId: adminInfo.CurrentOrgId,
  3980. Creater: creater,
  3981. Ctime: time.Now().Unix(),
  3982. Status: 1,
  3983. WarehouseOutTime: nowtime,
  3984. Type: 1,
  3985. StorehouseId: storeConfig.StorehouseOutInfo,
  3986. IsCheck: 1,
  3987. IsSys: 1,
  3988. }
  3989. //查询是否生成出库单
  3990. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3991. if out.ID == 0 {
  3992. service.AddSigleWarehouseOut(&warehouseOut)
  3993. }
  3994. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3995. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3996. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3997. dialyPrepareOne := models.DialysisBeforePrepare{
  3998. GoodTypeId: goodObj.GoodTypeId,
  3999. GoodId: item.ProjectId,
  4000. PatientId: item.PatientId,
  4001. RecordDate: item.RecordDate,
  4002. UserOrgId: adminInfo.CurrentOrgId,
  4003. Count: parseIntCount,
  4004. Ctime: time.Now().Unix(),
  4005. Creater: creater,
  4006. Status: 1,
  4007. StorehouseId: houseConfig.StorehouseOutInfo,
  4008. ProjectId: item.ID,
  4009. }
  4010. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4011. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4012. //查询历史出库数据
  4013. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4014. var out_count int64
  4015. for _, item := range flowGood {
  4016. out_count += item.Count
  4017. }
  4018. //如果历史数和当前数据不想等才进行退库出库
  4019. if out_count != parseIntCount {
  4020. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4021. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4022. detail := models.AutomaticReduceDetail{
  4023. WarehouseOutId: 0,
  4024. WarehouseOutOrderNumber: "",
  4025. PatientId: item.PatientId,
  4026. Ctime: time.Now().Unix(),
  4027. Mtime: 0,
  4028. Status: 1,
  4029. RecordTime: item.RecordDate,
  4030. OrgId: item.UserOrgId,
  4031. GoodId: item.ProjectId,
  4032. GoodTypeId: 0,
  4033. Count: parseIntCount,
  4034. Type: 0,
  4035. ProjectId: item.ID,
  4036. StorehouseId: 0,
  4037. }
  4038. service.CreateAutoDetail(detail)
  4039. //查询剩余库存
  4040. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4041. var sum_count int64
  4042. for _, item := range goodList {
  4043. sum_count += item.StockCount
  4044. }
  4045. //更新剩余库存
  4046. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4047. //耗材
  4048. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4049. }
  4050. }
  4051. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4052. //查询历史出库数据
  4053. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4054. var out_count int64
  4055. for _, item := range flowGood {
  4056. out_count += item.Count
  4057. }
  4058. //如果历史数和当前数据不想等才进行退库出库
  4059. if out_count != parseIntCount {
  4060. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4061. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4062. detail := models.AutomaticReduceDetail{
  4063. WarehouseOutId: 0,
  4064. WarehouseOutOrderNumber: "",
  4065. PatientId: item.PatientId,
  4066. Ctime: time.Now().Unix(),
  4067. Mtime: 0,
  4068. Status: 1,
  4069. RecordTime: item.RecordDate,
  4070. OrgId: item.UserOrgId,
  4071. GoodId: item.ProjectId,
  4072. GoodTypeId: 0,
  4073. Count: parseIntCount,
  4074. Type: 0,
  4075. ProjectId: item.ID,
  4076. StorehouseId: 0,
  4077. }
  4078. service.CreateAutoDetail(detail)
  4079. //查询剩余库存
  4080. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4081. var sum_count int64
  4082. for _, item := range goodList {
  4083. sum_count += item.StockCount
  4084. }
  4085. //更新剩余库存
  4086. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4087. //耗材
  4088. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4089. }
  4090. }
  4091. }
  4092. }
  4093. }
  4094. }
  4095. tx.Commit()
  4096. if err == nil {
  4097. c.ServeSuccessJSON(map[string]interface{}{
  4098. "msg": "保存成功",
  4099. })
  4100. return
  4101. } else {
  4102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4103. return
  4104. }
  4105. }
  4106. }
  4107. //func (c *HisApiController) EditHisPrescription() {
  4108. // record_date := c.GetString("record_date")
  4109. // patient_id, _ := c.GetInt64("patient_id")
  4110. // reg_type, _ := c.GetInt64("reg_type")
  4111. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4112. // diagnose := c.GetString("diagnose")
  4113. // sick_type, _ := c.GetInt64("sick_type")
  4114. // sick_history := c.GetString("sick_history")
  4115. // doctor_id, _ := c.GetInt64("doctor", 0)
  4116. // department, _ := c.GetInt64("department", 0)
  4117. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4118. // p_type, _ := c.GetInt64("p_type")
  4119. //
  4120. // dataBody := make(map[string]interface{}, 0)
  4121. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4122. // if err != nil {
  4123. // utils.ErrorLog(err.Error())
  4124. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4125. // return
  4126. // }
  4127. //
  4128. // timeLayout := "2006-01-02"
  4129. // loc, _ := time.LoadLocation("Local")
  4130. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4131. // if err != nil {
  4132. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4133. // return
  4134. // }
  4135. // adminInfo := c.GetAdminUserInfo()
  4136. // recordDateTime := theTime.Unix()
  4137. //
  4138. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4139. //
  4140. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4141. // var hpInfo models.HisPrescriptionInfo
  4142. // if info.ID == 0 {
  4143. // var randNum int
  4144. // randNum = rand.Intn(10000) + 1000
  4145. // timestamp := time.Now().Unix()
  4146. // tempTime := time.Unix(timestamp, 0)
  4147. // timeFormat := tempTime.Format("20060102150405")
  4148. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4149. //
  4150. // hpInfo = models.HisPrescriptionInfo{
  4151. // UserOrgId: adminInfo.CurrentOrgId,
  4152. // RecordDate: theTime.Unix(),
  4153. // PatientId: patient_id,
  4154. // Status: 1,
  4155. // Ctime: time.Now().Unix(),
  4156. // Mtime: time.Now().Unix(),
  4157. // Creator: adminInfo.AdminUser.Id,
  4158. // Modifier: adminInfo.AdminUser.Id,
  4159. // Diagnosis: diagnose,
  4160. // SickHistory: sick_history,
  4161. // Departments: department,
  4162. // RegisterType: reg_type,
  4163. // PrescriptionNumber: p_number,
  4164. // PrescriptionStatus: 1,
  4165. // Doctor: role.UserName,
  4166. // DoctorId: doctor_id,
  4167. // SickType: sick_type,
  4168. // PType: p_type,
  4169. // }
  4170. // service.SavePatientPrescriptionInfo(hpInfo)
  4171. //
  4172. // } else {
  4173. // hpInfo = models.HisPrescriptionInfo{
  4174. // ID: info.ID,
  4175. // UserOrgId: adminInfo.CurrentOrgId,
  4176. // RecordDate: info.RecordDate,
  4177. // PatientId: info.PatientId,
  4178. // Status: 1,
  4179. // Ctime: info.Ctime,
  4180. // Mtime: time.Now().Unix(),
  4181. // Creator: info.Creator,
  4182. // Modifier: adminInfo.AdminUser.Id,
  4183. // Diagnosis: diagnose,
  4184. // SickHistory: sick_history,
  4185. // Departments: department,
  4186. // RegisterType: reg_type,
  4187. // PrescriptionNumber: info.PrescriptionNumber,
  4188. // Doctor: role.UserName,
  4189. // PrescriptionStatus: info.PrescriptionStatus,
  4190. // DoctorId: doctor_id,
  4191. // SickType: sick_type,
  4192. // PType: info.PType,
  4193. // }
  4194. // service.SavePatientPrescriptionInfo(hpInfo)
  4195. // }
  4196. //
  4197. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4198. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4199. //
  4200. // if len(prescriptions) > 0 {
  4201. // for _, item := range prescriptions {
  4202. // items := item.(map[string]interface{})
  4203. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4204. // utils.ErrorLog("id")
  4205. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4206. // return
  4207. // }
  4208. // id := int64(items["id"].(float64))
  4209. //
  4210. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4211. // utils.ErrorLog("type")
  4212. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4213. // return
  4214. // }
  4215. // types := int64(items["type"].(float64))
  4216. //
  4217. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4218. // utils.ErrorLog("med_type")
  4219. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4220. // return
  4221. // }
  4222. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4223. //
  4224. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4225. //
  4226. // ctime := time.Now().Unix()
  4227. //
  4228. // prescription := &models.HisPrescription{
  4229. // ID: id,
  4230. // PatientId: patient_id,
  4231. // UserOrgId: adminInfo.CurrentOrgId,
  4232. // RecordDate: recordDateTime,
  4233. // Ctime: ctime,
  4234. // Mtime: ctime,
  4235. // Type: types,
  4236. // Modifier: adminInfo.AdminUser.Id,
  4237. // Creator: adminInfo.AdminUser.Id,
  4238. // Status: 1,
  4239. // Doctor: role.UserName,
  4240. // HisPatientId: his_patient_id,
  4241. // OrderStatus: 1,
  4242. // BatchNumber: "",
  4243. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4244. // PType: hpInfo.PType,
  4245. // MedType: med_type,
  4246. // }
  4247. //
  4248. // if historyPrescription.ID > 0 {
  4249. // prescription.PreTime = historyPrescription.PreTime
  4250. //
  4251. // }
  4252. //
  4253. // service.SaveHisPrescription(prescription)
  4254. //
  4255. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4256. // advices := items["advices"].([]interface{})
  4257. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4258. // groupNo := int64(0)
  4259. // ctime := time.Now().Unix()
  4260. // mtime := ctime
  4261. // if len(advices) > 0 {
  4262. // for _, advice := range advices {
  4263. // var s models.HisDoctorAdviceInfo
  4264. // s.PrescriptionId = prescription.ID
  4265. // s.AdviceType = 2
  4266. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4267. // s.StopState = 2
  4268. // s.ExecutionState = 2
  4269. // s.AdviceDate = recordDateTime
  4270. // s.Status = 1
  4271. // s.UserOrgId = adminInfo.CurrentOrgId
  4272. // s.RecordDate = recordDateTime
  4273. // s.StartTime = prescription.PreTime
  4274. // s.Groupno = groupNo
  4275. // s.CreatedTime = ctime
  4276. // s.UpdatedTime = mtime
  4277. // s.PatientId = patient_id
  4278. // s.HisPatientId = his_patient_id
  4279. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4280. // if errcode > 0 {
  4281. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4282. // return
  4283. // }
  4284. //
  4285. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4286. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4287. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4288. // if s.Price == 0 {
  4289. // s.Price = lastWarehouse.RetailPrice
  4290. // }
  4291. // }
  4292. //
  4293. // service.CreateHisDoctorAdvice(&s)
  4294. // //记录日志
  4295. // byterequest, _ := json.Marshal(s)
  4296. // adviceLog := models.XtDoctorAdviceLog{
  4297. // UserOrgId: s.UserOrgId,
  4298. // PatientId: s.PatientId,
  4299. // AdminUserId: adminInfo.AdminUser.Id,
  4300. // Module: 1,
  4301. // ErrLog: string(byterequest),
  4302. // Status: 1,
  4303. // Ctime: time.Now().Unix(),
  4304. // Mtime: 0,
  4305. // Source: "电脑端his医嘱修改",
  4306. // RecordDate: s.AdviceDate,
  4307. // }
  4308. // service.CreateDoctorAdviceLog(adviceLog)
  4309. // redis := service.RedisClient()
  4310. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4311. // redis.Set(key, "", time.Second)
  4312. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4313. // fmt.Println("keyOne", keyOne)
  4314. // redis.Set(keyOne, "", time.Second)
  4315. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4316. // redis.Set(keySeven, "", time.Second)
  4317. // redis.Close()
  4318. //
  4319. // }
  4320. // }
  4321. // }
  4322. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4323. // projects := items["project"].([]interface{})
  4324. // if len(projects) > 0 {
  4325. // for _, project := range projects {
  4326. // var p models.HisPrescriptionProject
  4327. // p.PrescriptionId = prescription.ID
  4328. // p.Ctime = time.Now().Unix()
  4329. // p.Mtime = time.Now().Unix()
  4330. // p.PatientId = patient_id
  4331. // p.RecordDate = recordDateTime
  4332. // p.UserOrgId = adminInfo.CurrentOrgId
  4333. // p.HisPatientId = his_patient_id
  4334. // p.Status = 1
  4335. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4336. // if errcode > 0 {
  4337. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4338. // return
  4339. // }
  4340. // service.CreateHisProjectTwo(&p)
  4341. //
  4342. // //记录日志
  4343. // byterequest, _ := json.Marshal(p)
  4344. // adviceLog := models.XtDoctorAdviceLog{
  4345. // UserOrgId: p.UserOrgId,
  4346. // PatientId: p.PatientId,
  4347. // AdminUserId: adminInfo.AdminUser.Id,
  4348. // Module: 1,
  4349. // ErrLog: string(byterequest),
  4350. // Status: 1,
  4351. // Ctime: time.Now().Unix(),
  4352. // Mtime: 0,
  4353. // Source: "电脑端his项目修改",
  4354. // RecordDate: p.RecordDate,
  4355. // }
  4356. // service.CreateDoctorAdviceLog(adviceLog)
  4357. // }
  4358. // }
  4359. // }
  4360. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4361. // addition := items["addition"].([]interface{})
  4362. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4363. // ctime := time.Now().Unix()
  4364. // mtime := ctime
  4365. // if len(addition) > 0 {
  4366. // for _, item := range addition {
  4367. // var s models.HisAdditionalCharge
  4368. // s.PrescriptionId = prescription.ID
  4369. // s.Status = 1
  4370. // s.UserOrgId = adminInfo.CurrentOrgId
  4371. // s.RecordDate = recordDateTime
  4372. // s.CreatedTime = ctime
  4373. // s.UpdatedTime = mtime
  4374. // s.PatientId = patient_id
  4375. // s.HisPatientId = his_patient_id
  4376. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4377. // if errcode > 0 {
  4378. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4379. // return
  4380. // }
  4381. // service.CreateAdditionalCharge(&s)
  4382. // }
  4383. // }
  4384. // }
  4385. //
  4386. // }
  4387. // }
  4388. // }
  4389. // if err == nil {
  4390. // c.ServeSuccessJSON(map[string]interface{}{
  4391. // "msg": "保存成功",
  4392. // })
  4393. // return
  4394. //
  4395. // } else {
  4396. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4397. // return
  4398. // }
  4399. //}
  4400. func (c *HisApiController) DeletePrescription() {
  4401. prescription_id, _ := c.GetInt64("id")
  4402. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4403. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4404. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4405. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4406. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4407. //耗材保存处方出库
  4408. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4409. //已收费和已发药限制逻辑
  4410. isCharge := false
  4411. isMedicine := false
  4412. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4413. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4414. for _, item := range new_prescriptions {
  4415. if item.IsMedicine == 1 {
  4416. isMedicine = true
  4417. }
  4418. }
  4419. for _, item := range new_prescriptions {
  4420. if item.OrderStatus == 4 {
  4421. isCharge = true
  4422. }
  4423. }
  4424. if p_err != nil {
  4425. if new_prescription.ID > 0 {
  4426. if new_prescription.OrderStatus == 2 {
  4427. isCharge = true
  4428. }
  4429. }
  4430. }
  4431. for _, item := range advices {
  4432. if item.IsMedicine == 1 {
  4433. isMedicine = true
  4434. }
  4435. }
  4436. if isCharge {
  4437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4438. return
  4439. }
  4440. if isMedicine {
  4441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4442. return
  4443. }
  4444. //已收费和已发药限制逻辑
  4445. if len(projects) > 0 {
  4446. for _, item := range projects {
  4447. service.DeletePrintInfo(item.ID) //删除打印信息
  4448. if goodOutConfig.IsOpen != 1 {
  4449. if stockConfig.IsOpen == 1 {
  4450. if item.Type == 3 && item.IsOut == 1 {
  4451. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4452. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4453. good.Total = good.Total + f_count
  4454. service.UpdateGoodInfo(&good)
  4455. operation_time := time.Now().Unix()
  4456. creater := c.GetAdminUserInfo().AdminUser.Id
  4457. //创建退库单
  4458. timeStr := time.Now().Format("2006-01-02")
  4459. timeArr := strings.Split(timeStr, "-")
  4460. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4461. total = total + 1
  4462. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4463. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4464. cancelStock := models.CancelStock{
  4465. OrderNumber: orderNumber,
  4466. OperaTime: operation_time,
  4467. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4468. Creater: creater,
  4469. Ctime: time.Now().Unix(),
  4470. Status: 1,
  4471. ReturnTime: item.RecordDate,
  4472. Type: 1,
  4473. StorehouseId: houseConfig.StorehouseOutInfo,
  4474. IsCheck: 1,
  4475. }
  4476. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4477. if msgerrkonde == gorm.ErrRecordNotFound {
  4478. service.AddSigleCancelStock(&cancelStock)
  4479. }
  4480. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4481. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4482. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4483. //查询该耗材是否出库
  4484. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4485. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4486. deaerler, _ := service.GetDealerById(info.Dealer)
  4487. var total_count int64
  4488. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4489. total_count += count
  4490. if info.ID > 0 {
  4491. if info.Count >= total_count {
  4492. //回退库存
  4493. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4494. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4495. var flush_count int64
  4496. for _, it := range goodList {
  4497. flush_count += it.StockCount
  4498. }
  4499. cancelStockInfo := models.CancelStockInfo{
  4500. GoodId: item.ProjectId,
  4501. CancelStockId: cancel.ID,
  4502. GoodTypeId: good.GoodTypeId,
  4503. Count: prescribingNumber,
  4504. Price: info.Price,
  4505. Total: 0,
  4506. ProductDate: info.ProductDate,
  4507. ExpiryDate: info.ExpiryDate,
  4508. Ctime: time.Now().Unix(),
  4509. Status: 1,
  4510. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4511. OrderNumber: cancel.OrderNumber,
  4512. Type: 0,
  4513. Dealer: deaerler.DealerName,
  4514. Manufacturer: manufacturer.ManufacturerName,
  4515. Number: info.Number,
  4516. RegisterAccount: "",
  4517. Remark: "",
  4518. WarehouseInfoId: info.WarehouseInfotId,
  4519. PatientId: info.PatientId,
  4520. RecordDate: info.SysRecordTime,
  4521. StorehouseId: houseConfig.StorehouseOutInfo,
  4522. IsCheck: 1,
  4523. }
  4524. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4525. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4526. flow := models.VmStockFlow{
  4527. WarehousingId: info.WarehouseInfotId,
  4528. GoodId: item.ProjectId,
  4529. Number: info.Number,
  4530. LicenseNumber: info.LicenseNumber,
  4531. Count: prescribingNumber,
  4532. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4533. PatientId: item.PatientId,
  4534. SystemTime: info.SysRecordTime,
  4535. ConsumableType: 7,
  4536. IsSys: 0,
  4537. WarehousingOrder: "",
  4538. WarehouseOutId: info.WarehouseOutId,
  4539. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4540. IsEdit: 0,
  4541. CancelStockId: cancel.ID,
  4542. CancelOrderNumber: cancel.OrderNumber,
  4543. Manufacturer: manufacturer.ID,
  4544. Dealer: 0,
  4545. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4546. UpdateCreator: 0,
  4547. Status: 1,
  4548. Ctime: time.Now().Unix(),
  4549. Mtime: 0,
  4550. Price: info.Price,
  4551. WarehousingDetailId: info.WarehouseInfotId,
  4552. WarehouseOutDetailId: info.ID,
  4553. CancelOutDetailId: cancelInfo.ID,
  4554. ProductDate: info.ProductDate,
  4555. ExpireDate: info.ExpiryDate,
  4556. StorehouseId: houseConfig.StorehouseOutInfo,
  4557. OverCount: flush_count,
  4558. }
  4559. service.CreateStockFlowOne(flow)
  4560. //退库数量增加
  4561. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4562. //出库数量减少
  4563. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4564. }
  4565. if info.Count < total_count {
  4566. //回退库存
  4567. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4568. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4569. var flush_count int64
  4570. for _, it := range goodList {
  4571. flush_count += it.StockCount
  4572. }
  4573. cancelStockInfo := models.CancelStockInfo{
  4574. GoodId: item.ProjectId,
  4575. CancelStockId: cancel.ID,
  4576. GoodTypeId: good.GoodTypeId,
  4577. Count: info.Count,
  4578. Price: info.Price,
  4579. Total: 0,
  4580. ProductDate: info.ProductDate,
  4581. ExpiryDate: info.ExpiryDate,
  4582. Ctime: time.Now().Unix(),
  4583. Status: 1,
  4584. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4585. OrderNumber: cancel.OrderNumber,
  4586. Type: 0,
  4587. Dealer: deaerler.DealerName,
  4588. Manufacturer: manufacturer.ManufacturerName,
  4589. Number: info.Number,
  4590. RegisterAccount: "",
  4591. Remark: "",
  4592. WarehouseInfoId: info.WarehouseInfotId,
  4593. PatientId: info.PatientId,
  4594. RecordDate: info.SysRecordTime,
  4595. StorehouseId: houseConfig.StorehouseOutInfo,
  4596. IsCheck: 1,
  4597. }
  4598. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4599. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4600. flow := models.VmStockFlow{
  4601. WarehousingId: info.WarehouseInfotId,
  4602. GoodId: item.ProjectId,
  4603. Number: info.Number,
  4604. LicenseNumber: info.LicenseNumber,
  4605. Count: info.Count,
  4606. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4607. PatientId: item.PatientId,
  4608. SystemTime: info.SysRecordTime,
  4609. ConsumableType: 7,
  4610. IsSys: 0,
  4611. WarehousingOrder: "",
  4612. WarehouseOutId: info.WarehouseOutId,
  4613. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4614. IsEdit: 0,
  4615. CancelStockId: cancel.ID,
  4616. CancelOrderNumber: cancel.OrderNumber,
  4617. Manufacturer: manufacturer.ID,
  4618. Dealer: 0,
  4619. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4620. UpdateCreator: 0,
  4621. Status: 1,
  4622. Ctime: time.Now().Unix(),
  4623. Mtime: 0,
  4624. Price: info.Price,
  4625. WarehousingDetailId: info.WarehouseInfotId,
  4626. WarehouseOutDetailId: info.ID,
  4627. CancelOutDetailId: cancelInfo.ID,
  4628. ProductDate: info.ProductDate,
  4629. ExpireDate: info.ExpiryDate,
  4630. StorehouseId: houseConfig.StorehouseOutInfo,
  4631. OverCount: flush_count,
  4632. }
  4633. service.CreateStockFlowOne(flow)
  4634. //退库数量增加
  4635. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4636. //出库数量减少
  4637. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4638. }
  4639. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4640. var flush_count int64
  4641. for _, it := range goodList {
  4642. flush_count += it.StockCount
  4643. }
  4644. //查询已出库数量
  4645. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4646. if prescribingNumber < dialysisInfo.Count {
  4647. //改变数量
  4648. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4649. }
  4650. if prescribingNumber >= dialysisInfo.Count {
  4651. //删除出库表
  4652. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4653. }
  4654. //更新库存
  4655. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4656. //更新基础库库存
  4657. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4658. }
  4659. }
  4660. }
  4661. }
  4662. //保存耗材出库
  4663. if goodOutConfig.IsOpen == 1 {
  4664. if item.Type == 3 {
  4665. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4666. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4667. good.Total = good.Total + f_count
  4668. service.UpdateGoodInfo(&good)
  4669. operation_time := time.Now().Unix()
  4670. creater := c.GetAdminUserInfo().AdminUser.Id
  4671. //创建退库单
  4672. timeStr := time.Now().Format("2006-01-02")
  4673. timeArr := strings.Split(timeStr, "-")
  4674. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4675. total = total + 1
  4676. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4677. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4678. cancelStock := models.CancelStock{
  4679. OrderNumber: orderNumber,
  4680. OperaTime: operation_time,
  4681. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4682. Creater: creater,
  4683. Ctime: time.Now().Unix(),
  4684. Status: 1,
  4685. ReturnTime: item.RecordDate,
  4686. Type: 1,
  4687. StorehouseId: houseConfig.StorehouseOutInfo,
  4688. IsCheck: 1,
  4689. }
  4690. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4691. if msgerrkonde == gorm.ErrRecordNotFound {
  4692. service.AddSigleCancelStock(&cancelStock)
  4693. }
  4694. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4695. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4696. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4697. //查询该耗材是否出库
  4698. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4699. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4700. deaerler, _ := service.GetDealerById(info.Dealer)
  4701. var total_count int64
  4702. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4703. total_count += count
  4704. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4705. var flush_count int64
  4706. for _, it := range goodList {
  4707. flush_count += it.StockCount
  4708. }
  4709. fmt.Println("历史出库数据", info.Count)
  4710. fmt.Println("出库数量", total_count)
  4711. if info.ID > 0 {
  4712. cancelStockInfo := models.CancelStockInfo{
  4713. GoodId: item.ProjectId,
  4714. CancelStockId: cancel.ID,
  4715. GoodTypeId: good.GoodTypeId,
  4716. Count: prescribingNumber,
  4717. Price: info.Price,
  4718. Total: 0,
  4719. ProductDate: info.ProductDate,
  4720. ExpiryDate: info.ExpiryDate,
  4721. Ctime: time.Now().Unix(),
  4722. Status: 1,
  4723. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4724. OrderNumber: cancel.OrderNumber,
  4725. Type: 0,
  4726. Dealer: deaerler.DealerName,
  4727. Manufacturer: manufacturer.ManufacturerName,
  4728. Number: info.Number,
  4729. RegisterAccount: "",
  4730. Remark: "",
  4731. WarehouseInfoId: info.WarehouseInfotId,
  4732. PatientId: info.PatientId,
  4733. RecordDate: info.SysRecordTime,
  4734. StorehouseId: houseConfig.StorehouseOutInfo,
  4735. IsCheck: 1,
  4736. }
  4737. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4738. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4739. //查询出库数量
  4740. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4741. //出库数据 大于 退库数量
  4742. if len(list) > 0 {
  4743. for _, it := range list {
  4744. //回退库存
  4745. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4746. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4747. var flush_count_one int64
  4748. for _, it := range goodList {
  4749. flush_count_one += it.StockCount
  4750. }
  4751. //查询该批次是否有退库数据
  4752. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4753. creater := c.GetAdminUserInfo().AdminUser.Id
  4754. flow := models.VmStockFlow{
  4755. WarehousingId: it.WarehouseInfotId,
  4756. GoodId: it.GoodId,
  4757. Number: it.Number,
  4758. LicenseNumber: it.LicenseNumber,
  4759. Count: it.Count,
  4760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4761. PatientId: it.PatientId,
  4762. SystemTime: it.SysRecordTime,
  4763. ConsumableType: 7,
  4764. IsSys: 0,
  4765. WarehousingOrder: "",
  4766. WarehouseOutId: it.WarehouseOutId,
  4767. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4768. IsEdit: 0,
  4769. CancelStockId: cancel.ID,
  4770. CancelOrderNumber: cancel.OrderNumber,
  4771. Manufacturer: manufacturer.ID,
  4772. Dealer: 0,
  4773. Creator: creater,
  4774. UpdateCreator: 0,
  4775. Status: 1,
  4776. Ctime: time.Now().Unix(),
  4777. Mtime: 0,
  4778. Price: it.Price,
  4779. WarehousingDetailId: it.WarehouseInfotId,
  4780. WarehouseOutDetailId: it.ID,
  4781. CancelOutDetailId: cancelInfo.ID,
  4782. ProductDate: it.ProductDate,
  4783. ExpireDate: it.ExpiryDate,
  4784. StorehouseId: houseConfig.StorehouseOutInfo,
  4785. OverCount: flush_count_one,
  4786. }
  4787. service.CreateStockFlowOne(flow)
  4788. //if flow.ID > 0 {
  4789. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4790. //}
  4791. }
  4792. }
  4793. //flow := models.VmStockFlow{
  4794. // WarehousingId: info.WarehouseInfotId,
  4795. // GoodId: item.ProjectId,
  4796. // Number: info.Number,
  4797. // LicenseNumber: info.LicenseNumber,
  4798. // Count: prescribingNumber,
  4799. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4800. // PatientId: item.PatientId,
  4801. // SystemTime: info.SysRecordTime,
  4802. // ConsumableType: 7,
  4803. // IsSys: 0,
  4804. // WarehousingOrder: "",
  4805. // WarehouseOutId: info.WarehouseOutId,
  4806. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4807. // IsEdit: 0,
  4808. // CancelStockId: cancel.ID,
  4809. // CancelOrderNumber: cancel.OrderNumber,
  4810. // Manufacturer: manufacturer.ID,
  4811. // Dealer: 0,
  4812. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4813. // UpdateCreator: 0,
  4814. // Status: 1,
  4815. // Ctime: time.Now().Unix(),
  4816. // Mtime: 0,
  4817. // Price: info.Price,
  4818. // WarehousingDetailId: info.WarehouseInfotId,
  4819. // WarehouseOutDetailId: info.ID,
  4820. // CancelOutDetailId: cancelInfo.ID,
  4821. // ProductDate: info.ProductDate,
  4822. // ExpireDate: info.ExpiryDate,
  4823. // StorehouseId: houseConfig.StorehouseOutInfo,
  4824. // OverCount: flush_count,
  4825. //}
  4826. //service.CreateStockFlowOne(flow)
  4827. //退库数量增加
  4828. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4829. //出库数量减少
  4830. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4831. //查询已出库数量
  4832. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4833. if prescribingNumber < dialysisInfo.Count {
  4834. //改变数量
  4835. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4836. }
  4837. if prescribingNumber >= dialysisInfo.Count {
  4838. //删除出库表
  4839. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4840. }
  4841. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4842. var flush_count_one int64
  4843. for _, it := range goodList {
  4844. flush_count_one += it.StockCount
  4845. }
  4846. //更新库存
  4847. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4848. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4849. //更新基础库库存
  4850. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4851. }
  4852. }
  4853. }
  4854. }
  4855. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4856. fmt.Println(err)
  4857. }
  4858. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4859. fmt.Println(err)
  4860. if len(advices) > 0 {
  4861. for _, item := range advices {
  4862. redis := service.RedisClient()
  4863. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4864. redis.Set(keyFive, "", time.Second)
  4865. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4866. redis.Set(keyOne, "", time.Second)
  4867. redis.Close()
  4868. }
  4869. }
  4870. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4871. if len(advices) > 0 {
  4872. for _, item := range advices {
  4873. creater := c.GetAdminUserInfo().AdminUser.Id
  4874. service.DrugAutoAddCancelInfo(item, creater)
  4875. }
  4876. }
  4877. } else {
  4878. if drugOutConfig.IsOpen == 1 {
  4879. if len(advices) > 0 {
  4880. for _, item := range advices {
  4881. creater := c.GetAdminUserInfo().AdminUser.Id
  4882. service.DrugAutoAddCancelInfo(item, creater)
  4883. }
  4884. }
  4885. } else {
  4886. if len(advices) > 0 {
  4887. for _, item := range advices {
  4888. creater := c.GetAdminUserInfo().AdminUser.Id
  4889. service.DrugAutoAddCancelInfo(item, creater)
  4890. }
  4891. }
  4892. }
  4893. }
  4894. c.ServeSuccessJSON(map[string]interface{}{
  4895. "msg": "删除成功",
  4896. })
  4897. return
  4898. }
  4899. func (c *HisApiController) DeleteDoctorAdvice() {
  4900. id, _ := c.GetInt64("id")
  4901. advice, _ := service.GetHisDoctorAdvicesById(id)
  4902. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4903. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4904. //已收费和已发药的限制逻辑
  4905. isCharge := false
  4906. isMedicine := false
  4907. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4908. //获取今天该患者所有处方,判断是否发药或者收费
  4909. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4910. for _, item := range new_prescriptions {
  4911. if item.IsMedicine == 1 {
  4912. isMedicine = true
  4913. }
  4914. }
  4915. for _, item := range new_prescriptions {
  4916. if item.OrderStatus == 4 {
  4917. isCharge = true
  4918. }
  4919. }
  4920. if isMedicine {
  4921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4922. return
  4923. }
  4924. if isCharge {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4926. return
  4927. }
  4928. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4929. for _, item := range advices {
  4930. if item.IsMedicine == 1 {
  4931. isMedicine = true
  4932. }
  4933. }
  4934. if isMedicine {
  4935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4936. return
  4937. }
  4938. if new_prescription.ID > 0 {
  4939. if new_prescription.OrderStatus == 2 {
  4940. isCharge = true
  4941. }
  4942. }
  4943. if isCharge {
  4944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4945. return
  4946. }
  4947. //已收费和已发药的限制逻辑
  4948. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4949. redis := service.RedisClient()
  4950. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4951. redis.Set(keyFive, "", time.Second)
  4952. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4953. redis.Set(keyOne, "", time.Second)
  4954. defer redis.Close()
  4955. if err == nil {
  4956. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4957. //查询是否在处方中出库
  4958. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4959. if openConfig.IsOpen != 1 {
  4960. //判断该医嘱是否执行了
  4961. if advice.ExecutionState == 1 {
  4962. creater := c.GetAdminUserInfo().AdminUser.Id
  4963. service.DrugAutoAddCancelInfo(&advice, creater)
  4964. }
  4965. }
  4966. //开启保存处方扣减功能
  4967. if openConfig.IsOpen == 1 {
  4968. creater := c.GetAdminUserInfo().AdminUser.Id
  4969. service.DrugAutoAddCancelInfo(&advice, creater)
  4970. }
  4971. } else {
  4972. if drugOutConfig.IsOpen == 1 {
  4973. //查询是否在处方中出库
  4974. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4975. if openConfig.IsOpen != 1 {
  4976. //判断该医嘱是否执行了
  4977. if advice.ExecutionState == 1 {
  4978. creater := c.GetAdminUserInfo().AdminUser.Id
  4979. service.DrugAutoAddCancelInfo(&advice, creater)
  4980. }
  4981. }
  4982. //开启保存处方扣减功能
  4983. if openConfig.IsOpen == 1 {
  4984. creater := c.GetAdminUserInfo().AdminUser.Id
  4985. service.DrugAutoAddCancelInfo(&advice, creater)
  4986. }
  4987. } else {
  4988. //判断该医嘱是否执行了
  4989. if advice.ExecutionState == 1 {
  4990. creater := c.GetAdminUserInfo().AdminUser.Id
  4991. service.DrugAutoAddCancelInfo(&advice, creater)
  4992. }
  4993. }
  4994. }
  4995. c.ServeSuccessJSON(map[string]interface{}{
  4996. "msg": "删除成功",
  4997. })
  4998. return
  4999. } else {
  5000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5001. return
  5002. }
  5003. }
  5004. func (c *HisApiController) DeleteProject() {
  5005. id, _ := c.GetInt64("id")
  5006. adminInfo := c.GetAdminUserInfo()
  5007. project, _ := service.GetHisProjectByID(id)
  5008. // var consumable models.DialysisBeforePrepare
  5009. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5010. //耗材保存处方出库
  5011. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5012. isCharge := false
  5013. isMedicine := false
  5014. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5015. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5016. for _, item := range new_prescriptions {
  5017. if item.IsMedicine == 1 {
  5018. isMedicine = true
  5019. }
  5020. }
  5021. for _, item := range new_prescriptions {
  5022. if item.OrderStatus == 4 {
  5023. isCharge = true
  5024. }
  5025. }
  5026. if isMedicine {
  5027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5028. return
  5029. }
  5030. if isCharge {
  5031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5032. return
  5033. }
  5034. if new_prescription.ID > 0 {
  5035. if new_prescription.OrderStatus == 2 {
  5036. isCharge = true
  5037. }
  5038. }
  5039. if isCharge {
  5040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5041. return
  5042. }
  5043. service.DeletePrintInfo(id)
  5044. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5045. label.Status = 0
  5046. service.CreateHisLabelRecordTwo(&label)
  5047. fmt.Println(goodOutConfig.IsOpen)
  5048. if goodOutConfig.IsOpen != 1 {
  5049. if stockConfig.IsOpen == 1 {
  5050. if project.Type == 2 {
  5051. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5052. fmt.Println(err)
  5053. }
  5054. if project.Type == 3 && project.IsOut == 1 {
  5055. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5056. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5057. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5058. operation_time := time.Now().Unix()
  5059. creater := adminInfo.AdminUser.Id
  5060. //创建退库单
  5061. timeStr := time.Now().Format("2006-01-02")
  5062. timeArr := strings.Split(timeStr, "-")
  5063. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5064. total = total + 1
  5065. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5066. cancelStock := models.CancelStock{
  5067. OrderNumber: orderNumber,
  5068. OperaTime: operation_time,
  5069. OrgId: adminInfo.CurrentOrgId,
  5070. Creater: creater,
  5071. Ctime: time.Now().Unix(),
  5072. Status: 1,
  5073. ReturnTime: project.RecordDate,
  5074. Type: 1,
  5075. StorehouseId: houseConfig.StorehouseOutInfo,
  5076. IsCheck: 1,
  5077. }
  5078. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5079. if msgerrkonde == gorm.ErrRecordNotFound {
  5080. service.AddSigleCancelStock(&cancelStock)
  5081. }
  5082. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5083. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5084. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5085. //查询是否有出库
  5086. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5087. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5088. deaerler, _ := service.GetDealerById(info.Dealer)
  5089. if info.ID > 0 {
  5090. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5091. if info.Count >= prescribingNumber {
  5092. cancelStockInfo := models.CancelStockInfo{
  5093. GoodId: project.ProjectId,
  5094. CancelStockId: cancel.ID,
  5095. GoodTypeId: good.GoodTypeId,
  5096. Count: prescribingNumber,
  5097. Price: info.Price,
  5098. Total: 0,
  5099. ProductDate: info.ProductDate,
  5100. ExpiryDate: info.ExpiryDate,
  5101. Ctime: time.Now().Unix(),
  5102. Status: 1,
  5103. OrgId: adminInfo.CurrentOrgId,
  5104. OrderNumber: cancel.OrderNumber,
  5105. Type: 0,
  5106. Dealer: deaerler.DealerName,
  5107. Manufacturer: manufacturer.ManufacturerName,
  5108. Number: info.Number,
  5109. RegisterAccount: "",
  5110. Remark: "",
  5111. WarehouseInfoId: info.WarehouseInfotId,
  5112. PatientId: info.PatientId,
  5113. RecordDate: info.SysRecordTime,
  5114. StorehouseId: houseConfig.StorehouseOutInfo,
  5115. IsCheck: 1,
  5116. }
  5117. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5118. //回退库存
  5119. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5120. //退库数量增加
  5121. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5122. //出库数量减少
  5123. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5124. }
  5125. if info.Count < prescribingNumber {
  5126. cancelStockInfo := models.CancelStockInfo{
  5127. GoodId: project.ProjectId,
  5128. CancelStockId: cancel.ID,
  5129. GoodTypeId: good.GoodTypeId,
  5130. Count: info.Count,
  5131. Price: info.Price,
  5132. Total: 0,
  5133. ProductDate: info.ProductDate,
  5134. ExpiryDate: info.ExpiryDate,
  5135. Ctime: time.Now().Unix(),
  5136. Status: 1,
  5137. OrgId: adminInfo.CurrentOrgId,
  5138. OrderNumber: cancel.OrderNumber,
  5139. Type: 0,
  5140. Dealer: deaerler.DealerName,
  5141. Manufacturer: manufacturer.ManufacturerName,
  5142. Number: info.Number,
  5143. RegisterAccount: "",
  5144. Remark: "",
  5145. WarehouseInfoId: info.WarehouseInfotId,
  5146. PatientId: info.PatientId,
  5147. RecordDate: info.SysRecordTime,
  5148. StorehouseId: houseConfig.StorehouseOutInfo,
  5149. IsCheck: 1,
  5150. }
  5151. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5152. //回退库存
  5153. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5154. //退库数量增加
  5155. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5156. //出库数量减少
  5157. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5158. }
  5159. //查询剩余库存
  5160. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5161. var over_count int64
  5162. for _, it := range goodList {
  5163. over_count += it.StockCount
  5164. }
  5165. //出库数据 大于 退库数量
  5166. if info.Count >= prescribingNumber {
  5167. flow := models.VmStockFlow{
  5168. WarehousingId: info.WarehouseInfotId,
  5169. GoodId: project.ProjectId,
  5170. Number: info.Number,
  5171. LicenseNumber: info.LicenseNumber,
  5172. Count: prescribingNumber,
  5173. UserOrgId: adminInfo.CurrentOrgId,
  5174. PatientId: project.PatientId,
  5175. SystemTime: info.SysRecordTime,
  5176. ConsumableType: 7,
  5177. IsSys: 0,
  5178. WarehousingOrder: "",
  5179. WarehouseOutId: info.WarehouseOutId,
  5180. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5181. IsEdit: 0,
  5182. CancelStockId: cancel.ID,
  5183. CancelOrderNumber: cancel.OrderNumber,
  5184. Manufacturer: manufacturer.ID,
  5185. Dealer: 0,
  5186. Creator: adminInfo.AdminUser.Id,
  5187. UpdateCreator: 0,
  5188. Status: 1,
  5189. Ctime: time.Now().Unix(),
  5190. Mtime: 0,
  5191. Price: info.Price,
  5192. WarehousingDetailId: info.WarehouseInfotId,
  5193. WarehouseOutDetailId: info.ID,
  5194. CancelOutDetailId: cancelInfo.ID,
  5195. ProductDate: info.ProductDate,
  5196. ExpireDate: info.ExpiryDate,
  5197. StorehouseId: houseConfig.StorehouseOutInfo,
  5198. OverCount: over_count,
  5199. }
  5200. service.CreateStockFlowOne(flow)
  5201. }
  5202. //出库数据小于退库数据
  5203. if info.Count < prescribingNumber {
  5204. flow := models.VmStockFlow{
  5205. WarehousingId: info.WarehouseInfotId,
  5206. GoodId: project.ProjectId,
  5207. Number: info.Number,
  5208. LicenseNumber: info.LicenseNumber,
  5209. Count: info.Count,
  5210. UserOrgId: adminInfo.CurrentOrgId,
  5211. PatientId: project.PatientId,
  5212. SystemTime: info.SysRecordTime,
  5213. ConsumableType: 7,
  5214. IsSys: 0,
  5215. WarehousingOrder: "",
  5216. WarehouseOutId: info.WarehouseOutId,
  5217. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5218. IsEdit: 0,
  5219. CancelStockId: cancel.ID,
  5220. CancelOrderNumber: cancel.OrderNumber,
  5221. Manufacturer: manufacturer.ID,
  5222. Dealer: 0,
  5223. Creator: adminInfo.AdminUser.Id,
  5224. UpdateCreator: 0,
  5225. Status: 1,
  5226. Ctime: time.Now().Unix(),
  5227. Mtime: 0,
  5228. Price: info.Price,
  5229. WarehousingDetailId: info.WarehouseInfotId,
  5230. WarehouseOutDetailId: info.ID,
  5231. CancelOutDetailId: cancelInfo.ID,
  5232. ProductDate: info.ProductDate,
  5233. ExpireDate: info.ExpiryDate,
  5234. StorehouseId: houseConfig.StorehouseOutInfo,
  5235. OverCount: over_count,
  5236. }
  5237. service.CreateStockFlowOne(flow)
  5238. }
  5239. //查询已出库数量
  5240. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5241. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5242. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5243. if prescribingNumber < dialysisInfo.Count {
  5244. //改变数量
  5245. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5246. }
  5247. if prescribingNumber >= dialysisInfo.Count {
  5248. //删除出库表
  5249. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5250. }
  5251. //更新剩余库存
  5252. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5253. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5254. var total_count_one int64
  5255. for _, it := range stockList {
  5256. total_count_one += it.StockCount
  5257. }
  5258. //基础库插入数据
  5259. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5260. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5261. var flush_count int64
  5262. for _, it := range goodListOne {
  5263. flush_count += it.StockCount
  5264. }
  5265. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5266. if errs != nil {
  5267. goodErrcode := models.XtGoodErrcode{
  5268. UserOrgId: project.UserOrgId,
  5269. Errcode: "手动出库更新剩余出库失败",
  5270. GoodId: project.ProjectId,
  5271. Status: 1,
  5272. Ctime: time.Now().Unix(),
  5273. Mtime: 0,
  5274. Count: 0,
  5275. StockCount: 0,
  5276. Creater: creater,
  5277. BatchNumberId: 0,
  5278. WarehouseOutId: 0,
  5279. }
  5280. service.CreateGoodErrcode(goodErrcode)
  5281. }
  5282. }
  5283. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5284. fmt.Println(err)
  5285. } else {
  5286. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5287. fmt.Println(err)
  5288. }
  5289. } else {
  5290. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5291. fmt.Println(err)
  5292. }
  5293. }
  5294. //保存处方出库
  5295. if goodOutConfig.IsOpen == 1 {
  5296. if project.Type == 3 {
  5297. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5298. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5299. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5300. operation_time := time.Now().Unix()
  5301. creater := adminInfo.AdminUser.Id
  5302. //创建退库单
  5303. timeStr := time.Now().Format("2006-01-02")
  5304. timeArr := strings.Split(timeStr, "-")
  5305. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5306. total = total + 1
  5307. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5308. cancelStock := models.CancelStock{
  5309. OrderNumber: orderNumber,
  5310. OperaTime: operation_time,
  5311. OrgId: adminInfo.CurrentOrgId,
  5312. Creater: creater,
  5313. Ctime: time.Now().Unix(),
  5314. Status: 1,
  5315. ReturnTime: project.RecordDate,
  5316. Type: 1,
  5317. StorehouseId: houseConfig.StorehouseOutInfo,
  5318. IsCheck: 1,
  5319. }
  5320. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5321. if msgerrkonde == gorm.ErrRecordNotFound {
  5322. service.AddSigleCancelStock(&cancelStock)
  5323. }
  5324. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5325. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5326. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5327. //获取出库数据
  5328. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5329. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5330. deaerler, _ := service.GetDealerById(info.Dealer)
  5331. if info.ID > 0 {
  5332. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5333. if info.Count >= prescribingNumber {
  5334. cancelStockInfo := models.CancelStockInfo{
  5335. GoodId: project.ProjectId,
  5336. CancelStockId: cancel.ID,
  5337. GoodTypeId: good.GoodTypeId,
  5338. Count: prescribingNumber,
  5339. Price: info.Price,
  5340. Total: 0,
  5341. ProductDate: info.ProductDate,
  5342. ExpiryDate: info.ExpiryDate,
  5343. Ctime: time.Now().Unix(),
  5344. Status: 1,
  5345. OrgId: adminInfo.CurrentOrgId,
  5346. OrderNumber: cancel.OrderNumber,
  5347. Type: 0,
  5348. Dealer: deaerler.DealerName,
  5349. Manufacturer: manufacturer.ManufacturerName,
  5350. Number: info.Number,
  5351. RegisterAccount: "",
  5352. Remark: "",
  5353. WarehouseInfoId: info.WarehouseInfotId,
  5354. PatientId: info.PatientId,
  5355. RecordDate: info.SysRecordTime,
  5356. StorehouseId: houseConfig.StorehouseOutInfo,
  5357. IsCheck: 1,
  5358. }
  5359. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5360. //退库数量增加
  5361. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5362. //出库数量减少
  5363. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5364. }
  5365. if info.Count < prescribingNumber {
  5366. cancelStockInfo := models.CancelStockInfo{
  5367. GoodId: project.ProjectId,
  5368. CancelStockId: cancel.ID,
  5369. GoodTypeId: good.GoodTypeId,
  5370. Count: prescribingNumber,
  5371. Price: info.Price,
  5372. Total: 0,
  5373. ProductDate: info.ProductDate,
  5374. ExpiryDate: info.ExpiryDate,
  5375. Ctime: time.Now().Unix(),
  5376. Status: 1,
  5377. OrgId: adminInfo.CurrentOrgId,
  5378. OrderNumber: cancel.OrderNumber,
  5379. Type: 0,
  5380. Dealer: deaerler.DealerName,
  5381. Manufacturer: manufacturer.ManufacturerName,
  5382. Number: info.Number,
  5383. RegisterAccount: "",
  5384. Remark: "",
  5385. WarehouseInfoId: info.WarehouseInfotId,
  5386. PatientId: info.PatientId,
  5387. RecordDate: info.SysRecordTime,
  5388. StorehouseId: houseConfig.StorehouseOutInfo,
  5389. IsCheck: 1,
  5390. }
  5391. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5392. //回退库存
  5393. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5394. }
  5395. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5396. var over_count int64
  5397. for _, it := range goodList {
  5398. over_count += it.StockCount
  5399. }
  5400. //查询出库数量
  5401. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5402. //出库数据 大于 退库数量
  5403. if len(list) > 0 {
  5404. for _, it := range list {
  5405. //回退库存
  5406. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5407. //退库数量增加
  5408. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5409. //出库数量减少
  5410. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5411. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5412. var over_count_one int64
  5413. for _, it := range goodList {
  5414. over_count_one += it.StockCount
  5415. }
  5416. //查询该批次是否有退库数据
  5417. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5418. flow := models.VmStockFlow{
  5419. WarehousingId: it.WarehouseInfotId,
  5420. GoodId: it.GoodId,
  5421. Number: it.Number,
  5422. LicenseNumber: it.LicenseNumber,
  5423. Count: it.Count,
  5424. UserOrgId: adminInfo.CurrentOrgId,
  5425. PatientId: it.PatientId,
  5426. SystemTime: it.SysRecordTime,
  5427. ConsumableType: 7,
  5428. IsSys: 0,
  5429. WarehousingOrder: "",
  5430. WarehouseOutId: it.WarehouseOutId,
  5431. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5432. IsEdit: 0,
  5433. CancelStockId: cancel.ID,
  5434. CancelOrderNumber: cancel.OrderNumber,
  5435. Manufacturer: manufacturer.ID,
  5436. Dealer: 0,
  5437. Creator: adminInfo.AdminUser.Id,
  5438. UpdateCreator: 0,
  5439. Status: 1,
  5440. Ctime: time.Now().Unix(),
  5441. Mtime: 0,
  5442. Price: it.Price,
  5443. WarehousingDetailId: it.WarehouseInfotId,
  5444. WarehouseOutDetailId: it.ID,
  5445. CancelOutDetailId: cancelInfo.ID,
  5446. ProductDate: it.ProductDate,
  5447. ExpireDate: it.ExpiryDate,
  5448. StorehouseId: houseConfig.StorehouseOutInfo,
  5449. OverCount: over_count_one,
  5450. }
  5451. service.CreateStockFlowOne(flow)
  5452. }
  5453. }
  5454. //查询已出库数量
  5455. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5456. if prescribingNumber < dialysisInfo.Count {
  5457. //改变数量
  5458. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5459. }
  5460. if prescribingNumber >= dialysisInfo.Count {
  5461. //删除出库表
  5462. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5463. }
  5464. //更新剩余库存
  5465. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5466. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5467. var total_count_one int64
  5468. for _, it := range stockList {
  5469. total_count_one += it.StockCount
  5470. }
  5471. //基础库插入数据
  5472. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5473. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5474. var flush_count int64
  5475. for _, it := range goodListOne {
  5476. flush_count += it.StockCount
  5477. }
  5478. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5479. if errs != nil {
  5480. goodErrcode := models.XtGoodErrcode{
  5481. UserOrgId: project.UserOrgId,
  5482. Errcode: "手动出库更新剩余出库失败",
  5483. GoodId: project.ProjectId,
  5484. Status: 1,
  5485. Ctime: time.Now().Unix(),
  5486. Mtime: 0,
  5487. Count: 0,
  5488. StockCount: 0,
  5489. Creater: creater,
  5490. BatchNumberId: 0,
  5491. WarehouseOutId: 0,
  5492. }
  5493. service.CreateGoodErrcode(goodErrcode)
  5494. }
  5495. }
  5496. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5497. fmt.Println(err)
  5498. } else {
  5499. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5500. fmt.Println(err)
  5501. }
  5502. }
  5503. c.ServeSuccessJSON(map[string]interface{}{
  5504. "msg": "删除成功",
  5505. })
  5506. return
  5507. }
  5508. func (c *HisApiController) CreateHisAdditionalCharge() {
  5509. his_patient_id, _ := c.GetInt64("his_patient_id")
  5510. patient_id, _ := c.GetInt64("patient_id")
  5511. record_date := c.GetString("record_date")
  5512. timeLayout := "2006-01-02"
  5513. loc, _ := time.LoadLocation("Local")
  5514. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5515. if err != nil {
  5516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5517. return
  5518. }
  5519. adminInfo := c.GetAdminUserInfo()
  5520. recordDateTime := theTime.Unix()
  5521. dataBody := make(map[string]interface{}, 0)
  5522. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5523. if err != nil {
  5524. utils.ErrorLog(err.Error())
  5525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5526. return
  5527. }
  5528. var additions []*models.HisAdditionalCharge
  5529. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5530. additions, _ := dataBody["addition"].([]interface{})
  5531. if len(additions) > 0 {
  5532. for _, item := range additions {
  5533. items := item.(map[string]interface{})
  5534. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5535. utils.ErrorLog("item_id")
  5536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5537. return
  5538. }
  5539. item_id := int64(items["item_id"].(float64))
  5540. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5541. utils.ErrorLog("item_name")
  5542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5543. return
  5544. }
  5545. item_name := items["item_name"].(string)
  5546. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5547. utils.ErrorLog("price")
  5548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5549. return
  5550. }
  5551. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5552. ctime := time.Now().Unix()
  5553. additional := &models.HisAdditionalCharge{
  5554. PatientId: patient_id,
  5555. HisPatientId: his_patient_id,
  5556. UserOrgId: adminInfo.CurrentOrgId,
  5557. RecordDate: recordDateTime,
  5558. CreatedTime: ctime,
  5559. UpdatedTime: ctime,
  5560. Modifier: adminInfo.AdminUser.Id,
  5561. Creator: adminInfo.AdminUser.Id,
  5562. Price: price,
  5563. ItemName: item_name,
  5564. ItemId: item_id,
  5565. Status: 1,
  5566. }
  5567. additions = append(additions, additional)
  5568. }
  5569. }
  5570. }
  5571. for _, item := range additions {
  5572. service.CreateAddtionalCharge(item)
  5573. }
  5574. c.ServeSuccessJSON(map[string]interface{}{
  5575. "msg": "创建成功",
  5576. })
  5577. }
  5578. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5579. blood_fat := c.GetString("blood_fat")
  5580. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5581. blood_sugar := c.GetString("blood_sugar")
  5582. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5583. chief_conplaint := c.GetString("chief_conplaint")
  5584. dbp := c.GetString("dbp")
  5585. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5586. delivery_way, _ := c.GetInt64("delivery_way")
  5587. diagnostic := c.GetString("diagnostic")
  5588. family_history := c.GetString("family_history")
  5589. height := c.GetString("height")
  5590. history_of_present_illness := c.GetString("history_of_present_illness")
  5591. is_infect, _ := c.GetInt64("is_infect")
  5592. past_history := c.GetString("past_history")
  5593. patient_id, _ := c.GetInt64("patient_id")
  5594. his_patient_id, _ := c.GetInt64("his_patient_id")
  5595. personal_history := c.GetString("personal_history")
  5596. pulse := c.GetString("pulse")
  5597. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5598. sbp := c.GetString("sbp")
  5599. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5600. heightfloat, _ := strconv.ParseFloat(height, 64)
  5601. sicktype := c.GetString("sick_type")
  5602. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5603. symptom := c.GetString("symptom")
  5604. sick_date := c.GetString("sick_date")
  5605. temperatures := c.GetString("temperature")
  5606. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5607. record_date := c.GetString("record_date")
  5608. breathing := c.GetString("breathing")
  5609. doctor_advice := c.GetString("doctor_advice")
  5610. remark := c.GetString("remark")
  5611. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5612. sick, _ := c.GetInt64("sick")
  5613. diagnose, _ := c.GetInt64("diagnose")
  5614. //id, _ := c.GetInt64("id")
  5615. timeLayout := "2006-01-02"
  5616. loc, _ := time.LoadLocation("Local")
  5617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5618. allergic_history := c.GetString("allergic_history")
  5619. if err != nil {
  5620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5621. return
  5622. }
  5623. recordDateTime := theTime.Unix()
  5624. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5625. if err != nil {
  5626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5627. return
  5628. }
  5629. sickTimes := sickTime.Unix()
  5630. ctime := time.Now().Unix()
  5631. primary_disease := c.GetString("primary_disease")
  5632. confirm_failure_date := c.GetString("confirm_failure_date")
  5633. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5634. drug_allergy_history := c.GetString("drug_allergy_history")
  5635. physical_examination := c.GetString("physical_examination")
  5636. special_inspection := c.GetString("special_inspection")
  5637. lab_apparatus := c.GetString("lab_apparatus")
  5638. caseHistory := models.HisPatientCaseHistory{
  5639. HisPatientId: his_patient_id,
  5640. PatientId: patient_id,
  5641. Temperature: temperature,
  5642. BloodSugar: bloodsugarfloat,
  5643. Pulse: pulsefloat,
  5644. Sbp: sbpfloat,
  5645. Dbp: dbpfloat,
  5646. Height: heightfloat,
  5647. BloodFat: bloodfatfloat,
  5648. SickType: sick_type,
  5649. Symptom: symptom,
  5650. SickDate: sickTimes,
  5651. IsInfect: is_infect,
  5652. HistoryOfPresentIllness: history_of_present_illness,
  5653. PastHistory: past_history,
  5654. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5655. ChiefConplaint: chief_conplaint,
  5656. PersonalHistory: personal_history,
  5657. FamilyHistory: family_history,
  5658. Diagnostic: diagnostic,
  5659. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5660. Status: 1,
  5661. Ctime: ctime,
  5662. Mtime: ctime,
  5663. RecordDate: recordDateTime,
  5664. DeliveryWay: delivery_way,
  5665. Breathing: breathingfloat,
  5666. DoctorAdvice: doctor_advice,
  5667. Remark: remark,
  5668. Sick: sick,
  5669. Diagnose: diagnose,
  5670. AllergicHistory: allergic_history,
  5671. PrimaryDisease: primary_disease,
  5672. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5673. DrugAllergyHistory: drug_allergy_history,
  5674. PhysicalExamination: physical_examination,
  5675. SpecialInspection: special_inspection,
  5676. LabApparatus: lab_apparatus,
  5677. }
  5678. //查询该患者是否有病历
  5679. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5680. if errcodes == gorm.ErrRecordNotFound {
  5681. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5682. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5683. if err != nil {
  5684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5685. return
  5686. }
  5687. c.ServeSuccessJSON(map[string]interface{}{
  5688. "caseHistory": caseHistory,
  5689. "historyInfo": historyInfo,
  5690. })
  5691. return
  5692. } else if errcodes == nil {
  5693. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5694. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5695. if err != nil {
  5696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5697. return
  5698. }
  5699. c.ServeSuccessJSON(map[string]interface{}{
  5700. "caseHistory": caseHistory,
  5701. "historyInfo": historyInfo,
  5702. })
  5703. }
  5704. //查询该患者是否有病历
  5705. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5706. //if errcode == gorm.ErrRecordNotFound {
  5707. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5708. // if err != nil {
  5709. // c.ServeSuccessJSON(map[string]interface{}{
  5710. // "msg": "保存成功",
  5711. // })
  5712. // }
  5713. //} else if errcode == nil {
  5714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5715. // return
  5716. //}
  5717. }
  5718. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5719. patient_id, _ := c.GetInt64("patient_id", 0)
  5720. adminUser := c.GetAdminUserInfo()
  5721. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5722. c.ServeSuccessJSON(map[string]interface{}{
  5723. "list": caseHistorys,
  5724. })
  5725. }
  5726. func (c *HisApiController) GetHisPatientCaseHistory() {
  5727. record_date, _ := c.GetInt64("record_date", 0)
  5728. patient_id, _ := c.GetInt64("patient_id", 0)
  5729. admin := c.GetAdminUserInfo()
  5730. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5731. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5732. c.ServeSuccessJSON(map[string]interface{}{
  5733. "info": info,
  5734. "case_history": case_history,
  5735. })
  5736. }
  5737. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5738. template_name := c.GetString("template_name")
  5739. template_remark := c.GetString("template_remark")
  5740. doctor := c.GetAdminUserInfo().AdminUser.Id
  5741. diagnostic := c.GetString("diagnostic")
  5742. chief_conplaint := c.GetString("chief_conplain")
  5743. history_of_present_illness := c.GetString("history_of_present_illness")
  5744. past_history := c.GetString("past_history")
  5745. personal_history := c.GetString("personal_history")
  5746. family_history := c.GetString("family_history")
  5747. user_name := c.GetString("user_name")
  5748. doctor_advice := c.GetString("doctor_advice")
  5749. remark := c.GetString("remark")
  5750. //record_date := c.GetString("record_date")
  5751. //fmt.Println("record_date--------",record_date)
  5752. //timeLayout := "2006-01-02"
  5753. //loc, _ := time.LoadLocation("Local")
  5754. //
  5755. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5756. //if err != nil {
  5757. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5758. // return
  5759. //}
  5760. //recordDateTime := theTime.Unix()
  5761. ctime := time.Now().Unix()
  5762. template := models.HisCaseHistoryTemplate{
  5763. HistoryOfPresentIllness: history_of_present_illness,
  5764. PastHistory: past_history,
  5765. ChiefConplaint: chief_conplaint,
  5766. PersonalHistory: personal_history,
  5767. FamilyHistory: family_history,
  5768. Diagnostic: diagnostic,
  5769. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5770. Status: 1,
  5771. Ctime: ctime,
  5772. Mtime: ctime,
  5773. RecordDate: time.Now().Unix(),
  5774. TemplateName: template_name,
  5775. TemplateRemark: template_remark,
  5776. Creator: doctor,
  5777. Modifier: doctor,
  5778. UserName: user_name,
  5779. DoctorAdvice: doctor_advice,
  5780. Remark: remark,
  5781. }
  5782. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5783. if err == nil {
  5784. c.ServeSuccessJSON(map[string]interface{}{
  5785. "msg": "保存成功",
  5786. })
  5787. } else {
  5788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5789. return
  5790. }
  5791. }
  5792. func (c *HisApiController) GetCaseHistoryTemplate() {
  5793. timeLayout := "2006-01-02"
  5794. loc, _ := time.LoadLocation("Local")
  5795. keyword := c.GetString("keyword")
  5796. start_time := c.GetString("start_time")
  5797. end_time := c.GetString("end_time")
  5798. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5799. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5800. admin := c.GetAdminUserInfo()
  5801. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5802. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5803. c.ServeSuccessJSON(map[string]interface{}{
  5804. "template": template,
  5805. //"history": history,
  5806. })
  5807. }
  5808. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5809. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5810. utils.ErrorLog("drug_name")
  5811. return enums.ErrorCodeParamWrong
  5812. }
  5813. adviceName, _ := json["drug_name"].(string)
  5814. if len(adviceName) == 0 {
  5815. utils.ErrorLog("len(advice_name) == 0")
  5816. return enums.ErrorCodeParamWrong
  5817. }
  5818. advice.AdviceName = adviceName
  5819. adviceDesc, _ := json["advice_desc"].(string)
  5820. advice.AdviceDesc = adviceDesc
  5821. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5822. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5823. advice.DrugSpec = drugSpec
  5824. }
  5825. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5826. remark, _ := json["remark"].(string)
  5827. advice.Remark = remark
  5828. }
  5829. if json["id"] == nil {
  5830. advice.DrugId = 0
  5831. } else {
  5832. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5833. drug_id := int64(json["id"].(float64))
  5834. advice.DrugId = drug_id
  5835. }
  5836. }
  5837. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5838. advice_id := int64(json["advice_id"].(float64))
  5839. advice.ID = advice_id
  5840. if advice.ID > 0 {
  5841. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5842. if err == nil {
  5843. if hisAdvice.ID > 0 {
  5844. advice.ExecutionTime = hisAdvice.ExecutionTime
  5845. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5846. advice.ExecutionState = hisAdvice.ExecutionState
  5847. advice.CheckTime = hisAdvice.CheckTime
  5848. advice.Checker = hisAdvice.Checker
  5849. advice.CheckState = hisAdvice.CheckState
  5850. advice.StartTime = hisAdvice.StartTime
  5851. advice.FeedetlSn = hisAdvice.FeedetlSn
  5852. }
  5853. }
  5854. }
  5855. }
  5856. //
  5857. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5858. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5859. // advice.ExecutionTime = execution_time
  5860. //}
  5861. //
  5862. //
  5863. //
  5864. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5865. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5866. // advice.ExecutionStaff = execution_staff
  5867. //}
  5868. //
  5869. //
  5870. //
  5871. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5872. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5873. // advice.ExecutionState = execution_state
  5874. //}
  5875. //
  5876. //
  5877. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5878. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5879. // advice.CheckTime = check_time
  5880. //}
  5881. //
  5882. //
  5883. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5884. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5885. // advice.CheckState = check_state
  5886. //}
  5887. //
  5888. //
  5889. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5890. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5891. // advice.Checker = checker
  5892. //}
  5893. //
  5894. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5895. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5896. // advice.StartTime = start_time
  5897. //}
  5898. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5899. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5900. advice.IsSelfDrug = is_self_drug
  5901. }
  5902. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5903. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5904. drug_way_count, _ := json["drug_way_count"].(string)
  5905. advice.DrugWayCount = drug_way_count
  5906. }
  5907. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5908. drugSpecUnit, _ := json["min_unit"].(string)
  5909. advice.DrugSpecUnit = drugSpecUnit
  5910. }
  5911. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5912. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5913. advice.SingleDose = singleDose
  5914. }
  5915. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5916. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5917. advice.SingleDoseUnit = singleDoseUnit
  5918. }
  5919. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5920. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5921. advice.PrescribingNumber = prescribingNumber
  5922. }
  5923. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5924. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5925. advice.PrescribingNumberUnit = prescribingNumberUnit
  5926. }
  5927. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5928. deliveryWay, _ := json["delivery_way"].(string)
  5929. advice.DeliveryWay = deliveryWay
  5930. }
  5931. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5932. executionFrequency, _ := json["execution_frequency"].(string)
  5933. advice.ExecutionFrequency = executionFrequency
  5934. }
  5935. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5936. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5937. advice.Price = price
  5938. }
  5939. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5940. med_list_codg, _ := json["medical_insurance_number"].(string)
  5941. advice.MedListCodg = med_list_codg
  5942. }
  5943. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5944. day := int64(json["day"].(float64))
  5945. advice.Day = day
  5946. }
  5947. return 0
  5948. }
  5949. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5950. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5951. id := int64(json["id"].(float64))
  5952. project.ID = id
  5953. historyProject, _ := service.GetHisProjectByID(id)
  5954. project.FeedetlSn = historyProject.FeedetlSn
  5955. }
  5956. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5957. project_id := int64(json["project_id"].(float64))
  5958. project.ProjectId = project_id
  5959. }
  5960. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5961. // price := int64(json["price"].(float64))
  5962. // formatInt_price := strconv.FormatInt(price, 10)
  5963. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5964. // project.Price = float_price
  5965. // }
  5966. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5967. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5968. project.Price = price
  5969. }
  5970. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5971. total, _ := json["total"].(string)
  5972. project.Count = total
  5973. }
  5974. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5975. medical_code, _ := json["medical_code"].(string)
  5976. project.MedListCodg = medical_code
  5977. }
  5978. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5979. single_dose, _ := json["single_dose"].(string)
  5980. project.SingleDose = single_dose
  5981. }
  5982. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5983. delivery_way, _ := json["delivery_way"].(string)
  5984. project.DeliveryWay = delivery_way
  5985. }
  5986. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5987. execution_frequency, _ := json["execution_frequency"].(string)
  5988. project.ExecutionFrequency = execution_frequency
  5989. }
  5990. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5991. remark, _ := json["remark"].(string)
  5992. project.Remark = remark
  5993. }
  5994. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5995. day, _ := json["number_days"].(string)
  5996. project.Day = day
  5997. }
  5998. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5999. unit, _ := json["unit"].(string)
  6000. project.Unit = unit
  6001. }
  6002. return 0
  6003. }
  6004. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6005. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6006. id := int64(json["id"].(float64))
  6007. historyAddtions, _ := service.GetHisAdditionByID(id)
  6008. additionalCharge.ID = id
  6009. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6010. }
  6011. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6012. item_id := int64(json["item_id"].(float64))
  6013. additionalCharge.ItemId = item_id
  6014. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6015. if config.ID > 0 {
  6016. if len(config.Code) > 0 {
  6017. additionalCharge.MedListCodg = config.Code
  6018. }
  6019. }
  6020. }
  6021. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6022. // price := int64(json["price"].(float64))
  6023. // formatInt_price := strconv.FormatInt(price, 10)
  6024. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6025. // additionalCharge.Price = float_price
  6026. // }
  6027. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6028. // price := int64(json["price"].(float64))
  6029. // formatInt_price := strconv.FormatInt(price, 10)
  6030. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6031. // additionalCharge.Price = float_price
  6032. //}
  6033. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6034. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6035. additionalCharge.Price = price
  6036. }
  6037. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6038. count, _ := json["count"].(string)
  6039. counts, _ := strconv.ParseInt(count, 10, 64)
  6040. additionalCharge.Count = counts
  6041. }
  6042. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6043. item_name, _ := json["item_name"].(string)
  6044. additionalCharge.ItemName = item_name
  6045. }
  6046. return 0
  6047. }
  6048. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6049. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6050. utils.ErrorLog("drug_name")
  6051. return enums.ErrorCodeParamWrong
  6052. }
  6053. adviceName, _ := json["drug_name"].(string)
  6054. if len(adviceName) == 0 {
  6055. utils.ErrorLog("len(advice_name) == 0")
  6056. return enums.ErrorCodeParamWrong
  6057. }
  6058. advice.AdviceName = adviceName
  6059. adviceDesc, _ := json["advice_desc"].(string)
  6060. advice.AdviceDesc = adviceDesc
  6061. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6062. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6063. advice.DrugSpec = drugSpec
  6064. }
  6065. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6066. remark, _ := json["remark"].(string)
  6067. advice.Remark = remark
  6068. }
  6069. if json["id"] == nil {
  6070. advice.DrugId = 0
  6071. } else {
  6072. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6073. drug_id := int64(json["id"].(float64))
  6074. advice.DrugId = drug_id
  6075. }
  6076. }
  6077. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6078. groupno := int64(json["groupno"].(float64))
  6079. advice.Groupno = groupno
  6080. }
  6081. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6082. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6083. advice.IsSelfDrug = is_self_drug
  6084. }
  6085. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6086. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6087. drug_way_count, _ := json["drug_way_count"].(string)
  6088. advice.DrugWayCount = drug_way_count
  6089. }
  6090. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6091. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6092. advice.HospApprFlag = hosp_appr_flag
  6093. }
  6094. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6095. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6096. advice.PrescribingNumber = prescribingNumber
  6097. }
  6098. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6099. // frequency_type := int64(json["frequency_type"].(float64))
  6100. // advice.FrequencyType = frequency_type
  6101. //}
  6102. //
  6103. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6104. // day_count := int64(json["day_count"].(float64))
  6105. // advice.DayCount = day_count
  6106. //}
  6107. //
  6108. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6109. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6110. // week_day, _ := json["week_day"].(string)
  6111. // advice.WeekDay = week_day
  6112. //}
  6113. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6114. drugSpecUnit, _ := json["min_unit"].(string)
  6115. advice.DrugSpecUnit = drugSpecUnit
  6116. }
  6117. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6118. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6119. advice.SingleDose = singleDose
  6120. }
  6121. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6122. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6123. advice.SingleDoseUnit = singleDoseUnit
  6124. }
  6125. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6126. deliveryWay, _ := json["delivery_way"].(string)
  6127. advice.DeliveryWay = deliveryWay
  6128. }
  6129. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6130. executionFrequency, _ := json["execution_frequency"].(string)
  6131. advice.ExecutionFrequency = executionFrequency
  6132. }
  6133. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6134. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6135. advice.Price = price
  6136. }
  6137. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6138. med_list_codg, _ := json["medical_insurance_number"].(string)
  6139. advice.MedListCodg = med_list_codg
  6140. }
  6141. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6142. day := int64(json["day"].(float64))
  6143. advice.Day = day
  6144. }
  6145. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6146. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6147. advice.PrescribingNumberUnit = prescribingNumberUnit
  6148. }
  6149. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6150. advice_id := int64(json["advice_id"].(float64))
  6151. advice.ID = advice_id
  6152. if advice.ID > 0 {
  6153. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6154. if err == nil {
  6155. if hisAdvice.ID > 0 {
  6156. advice.ExecutionTime = hisAdvice.ExecutionTime
  6157. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6158. advice.ExecutionState = hisAdvice.ExecutionState
  6159. advice.CheckTime = hisAdvice.CheckTime
  6160. advice.Checker = hisAdvice.Checker
  6161. advice.CheckState = hisAdvice.CheckState
  6162. advice.StartTime = hisAdvice.StartTime
  6163. advice.HospApprFlag = hisAdvice.HospApprFlag
  6164. advice.IsMedicine = hisAdvice.IsMedicine
  6165. if hisAdvice.UserOrgId == 10028 {
  6166. 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 {
  6167. advice.ExecutionTime = 0
  6168. advice.ExecutionStaff = 0
  6169. advice.ExecutionState = 2
  6170. advice.CheckTime = 0
  6171. advice.Checker = 0
  6172. advice.CheckState = 2
  6173. }
  6174. } else {
  6175. 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 {
  6176. advice.ExecutionTime = 0
  6177. advice.ExecutionStaff = 0
  6178. advice.ExecutionState = 2
  6179. advice.CheckTime = 0
  6180. advice.Checker = 0
  6181. advice.CheckState = 2
  6182. advice.UpdatedTime = time.Now().Unix()
  6183. }
  6184. }
  6185. //advice.Groupno = hisAdvice.Groupno
  6186. }
  6187. }
  6188. }
  6189. }
  6190. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6191. //
  6192. //if drugStockConfig.IsOpen == 1 {
  6193. //
  6194. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6195. // if advice.ID == 0 { //医嘱不存在
  6196. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6197. // drug.Total = drug.Total - advice.PrescribingNumber
  6198. // service.UpdateBaseDrugLib(&drug)
  6199. //
  6200. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6201. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6202. // drug.Total = drug.Total - num
  6203. // service.UpdateBaseDrugLib(&drug)
  6204. // }
  6205. //
  6206. // } else if advice.ID > 0 { //医嘱存在
  6207. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6208. // var num float64
  6209. //
  6210. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6211. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6212. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6213. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6214. // drug.Total = drug.Total + num
  6215. // service.UpdateBaseDrugLib(&drug)
  6216. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6217. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6218. // drug.Total = drug.Total - num
  6219. // service.UpdateBaseDrugLib(&drug)
  6220. // }
  6221. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6222. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6223. // if num2 > advice.PrescribingNumber {
  6224. // num = num2 - advice.PrescribingNumber
  6225. // drug.Total = drug.Total + num
  6226. // service.UpdateBaseDrugLib(&drug)
  6227. // } else if num2 < advice.PrescribingNumber {
  6228. // num = advice.PrescribingNumber - num2
  6229. // drug.Total = drug.Total - num
  6230. // service.UpdateBaseDrugLib(&drug)
  6231. // }
  6232. //
  6233. // }
  6234. //
  6235. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6236. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6237. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6238. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6239. // if num1 > num2 {
  6240. // num = num1 - num2
  6241. // drug.Total = drug.Total + num
  6242. // service.UpdateBaseDrugLib(&drug)
  6243. // } else if num1 < num2 {
  6244. // num = num2 - num1
  6245. // drug.Total = drug.Total - num
  6246. // service.UpdateBaseDrugLib(&drug)
  6247. // }
  6248. //
  6249. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6250. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6251. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6252. // if hisAdvice.PrescribingNumber > num2 {
  6253. // num = hisAdvice.PrescribingNumber - num2
  6254. // drug.Total = drug.Total + num
  6255. // service.UpdateBaseDrugLib(&drug)
  6256. // } else if num2 < advice.PrescribingNumber {
  6257. // num = num2 - hisAdvice.PrescribingNumber
  6258. // drug.Total = drug.Total - num
  6259. // service.UpdateBaseDrugLib(&drug)
  6260. // }
  6261. //
  6262. // }
  6263. // }
  6264. // }
  6265. //}
  6266. //
  6267. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6268. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6269. // advice.ExecutionTime = execution_time
  6270. //}
  6271. //
  6272. //
  6273. //
  6274. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6275. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6276. // advice.ExecutionStaff = execution_staff
  6277. //}
  6278. //
  6279. //
  6280. //
  6281. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6282. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6283. // advice.ExecutionState = execution_state
  6284. //}
  6285. //
  6286. //
  6287. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6288. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6289. // advice.CheckTime = check_time
  6290. //}
  6291. //
  6292. //
  6293. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6294. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6295. // advice.CheckState = check_state
  6296. //}
  6297. //
  6298. //
  6299. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6300. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6301. // advice.Checker = checker
  6302. //}
  6303. //
  6304. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6305. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6306. // advice.StartTime = start_time
  6307. //}
  6308. return 0
  6309. }
  6310. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6311. project.ExecutionStaff = 0
  6312. project.ExecutionState = 2
  6313. project.ExecutionTime = 0
  6314. project.Checker = 0
  6315. project.CheckState = 2
  6316. project.CheckTime = 0
  6317. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6318. id := int64(json["id"].(float64))
  6319. project.ID = id
  6320. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6321. project.ExecutionStaff = temp_project.ExecutionStaff
  6322. project.ExecutionState = temp_project.ExecutionState
  6323. project.ExecutionTime = temp_project.ExecutionTime
  6324. project.Checker = temp_project.Checker
  6325. project.CheckState = temp_project.CheckState
  6326. project.CheckTime = temp_project.CheckTime
  6327. project.TeamId = temp_project.TeamId
  6328. }
  6329. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6330. types := int64(json["type"].(float64))
  6331. project.Type = types
  6332. }
  6333. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6334. project_id := int64(json["project_id"].(float64))
  6335. project.ProjectId = project_id
  6336. }
  6337. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6338. team_id := int64(json["team_id"].(float64))
  6339. project.TeamId = team_id
  6340. }
  6341. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6342. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6343. project.Price = price
  6344. }
  6345. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6346. total, _ := json["total"].(string)
  6347. //totals, _ := strconv.ParseInt(total, 10, 64)
  6348. project.Count = total
  6349. }
  6350. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6351. medical_code, _ := json["medical_code"].(string)
  6352. project.MedListCodg = medical_code
  6353. }
  6354. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6355. single_dose, _ := json["single_dose"].(string)
  6356. project.SingleDose = single_dose
  6357. }
  6358. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6359. delivery_way, _ := json["delivery_way"].(string)
  6360. project.DeliveryWay = delivery_way
  6361. }
  6362. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6363. execution_frequency, _ := json["execution_frequency"].(string)
  6364. project.ExecutionFrequency = execution_frequency
  6365. }
  6366. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6367. remark, _ := json["remark"].(string)
  6368. project.Remark = remark
  6369. }
  6370. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6371. day, _ := json["number_days"].(string)
  6372. project.Day = day
  6373. }
  6374. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6375. unit, _ := json["unit"].(string)
  6376. project.Unit = unit
  6377. }
  6378. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6379. // frequency_type := int64(json["frequency_type"].(float64))
  6380. // project.FrequencyType = frequency_type
  6381. //}
  6382. //
  6383. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6384. // day_count := int64(json["day_count"].(float64))
  6385. // project.DayCount = day_count
  6386. //}
  6387. //
  6388. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6389. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6390. // week_day, _ := json["week_day"].(string)
  6391. // project.WeekDay = week_day
  6392. //}
  6393. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6394. //
  6395. //if project.ID == 0 {
  6396. // if stockConfig.IsOpen == 1 {
  6397. // if project.Type == 3 {
  6398. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6399. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6400. // good.Total = good.Total - f_count
  6401. // service.UpdateGoodInfo(&good)
  6402. // }
  6403. // }
  6404. //
  6405. //} else {
  6406. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6407. //
  6408. // if stockConfig.IsOpen == 1 {
  6409. // if project.Type == 3 {
  6410. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6411. // if project.Count < temp_project.Count {
  6412. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6413. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6414. //
  6415. // other_count := f_count_two - f_count_one
  6416. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6417. // good.Total = good.Total + other_count_two
  6418. // service.UpdateGoodInfo(&good)
  6419. // } else if project.Count > temp_project.Count {
  6420. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6421. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6422. //
  6423. // other_count := f_count_one - f_count_two
  6424. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6425. // good.Total = good.Total - other_count_two
  6426. // service.UpdateGoodInfo(&good)
  6427. // }
  6428. //
  6429. // }
  6430. // }
  6431. //
  6432. //}
  6433. return 0
  6434. }
  6435. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6436. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6437. utils.ErrorLog("drug_name")
  6438. return enums.ErrorCodeParamWrong
  6439. }
  6440. adviceName, _ := json["drug_name"].(string)
  6441. if len(adviceName) == 0 {
  6442. utils.ErrorLog("len(advice_name) == 0")
  6443. return enums.ErrorCodeParamWrong
  6444. }
  6445. advice.AdviceName = adviceName
  6446. adviceDesc, _ := json["advice_desc"].(string)
  6447. advice.AdviceDesc = adviceDesc
  6448. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6449. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6450. advice.DrugSpec = drugSpec
  6451. }
  6452. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6453. remark, _ := json["remark"].(string)
  6454. advice.Remark = remark
  6455. }
  6456. if json["id"] == nil {
  6457. advice.DrugId = 0
  6458. } else {
  6459. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6460. drug_id := int64(json["id"].(float64))
  6461. advice.DrugId = drug_id
  6462. }
  6463. }
  6464. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6465. groupno := int64(json["groupno"].(float64))
  6466. advice.Groupno = groupno
  6467. }
  6468. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6469. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6470. advice.IsSelfDrug = is_self_drug
  6471. }
  6472. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6473. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6474. drug_way_count, _ := json["drug_way_count"].(string)
  6475. advice.DrugWayCount = drug_way_count
  6476. }
  6477. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6478. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6479. advice.HospApprFlag = hosp_appr_flag
  6480. }
  6481. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6482. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6483. advice.PrescribingNumber = prescribingNumber
  6484. }
  6485. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6486. // frequency_type := int64(json["frequency_type"].(float64))
  6487. // advice.FrequencyType = frequency_type
  6488. //}
  6489. //
  6490. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6491. // day_count := int64(json["day_count"].(float64))
  6492. // advice.DayCount = day_count
  6493. //}
  6494. //
  6495. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6496. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6497. // week_day, _ := json["week_day"].(string)
  6498. // advice.WeekDay = week_day
  6499. //}
  6500. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6501. drugSpecUnit, _ := json["min_unit"].(string)
  6502. advice.DrugSpecUnit = drugSpecUnit
  6503. }
  6504. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6505. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6506. advice.SingleDose = singleDose
  6507. }
  6508. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6509. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6510. advice.SingleDoseUnit = singleDoseUnit
  6511. }
  6512. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6513. deliveryWay, _ := json["delivery_way"].(string)
  6514. advice.DeliveryWay = deliveryWay
  6515. }
  6516. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6517. executionFrequency, _ := json["execution_frequency"].(string)
  6518. advice.ExecutionFrequency = executionFrequency
  6519. }
  6520. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6521. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6522. advice.Price = price
  6523. }
  6524. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6525. med_list_codg, _ := json["medical_insurance_number"].(string)
  6526. advice.MedListCodg = med_list_codg
  6527. }
  6528. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6529. day := int64(json["day"].(float64))
  6530. advice.Day = day
  6531. }
  6532. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6533. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6534. advice.PrescribingNumberUnit = prescribingNumberUnit
  6535. }
  6536. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6537. advice_id := int64(json["advice_id"].(float64))
  6538. advice.ID = advice_id
  6539. if advice.ID > 0 {
  6540. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6541. if err == nil {
  6542. if hisAdvice.ID > 0 {
  6543. advice.ExecutionTime = hisAdvice.ExecutionTime
  6544. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6545. advice.ExecutionState = hisAdvice.ExecutionState
  6546. advice.CheckTime = hisAdvice.CheckTime
  6547. advice.Checker = hisAdvice.Checker
  6548. advice.CheckState = hisAdvice.CheckState
  6549. advice.StartTime = hisAdvice.StartTime
  6550. advice.HospApprFlag = hisAdvice.HospApprFlag
  6551. advice.IsMedicine = hisAdvice.IsMedicine
  6552. if hisAdvice.UserOrgId == 10028 {
  6553. 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 {
  6554. advice.ExecutionTime = 0
  6555. advice.ExecutionStaff = 0
  6556. advice.ExecutionState = 2
  6557. advice.CheckTime = 0
  6558. advice.Checker = 0
  6559. advice.CheckState = 2
  6560. }
  6561. } else {
  6562. 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 {
  6563. advice.ExecutionTime = 0
  6564. advice.ExecutionStaff = 0
  6565. advice.ExecutionState = 2
  6566. advice.CheckTime = 0
  6567. advice.Checker = 0
  6568. advice.CheckState = 2
  6569. //advice.UpdatedTime = time.Now().Unix()
  6570. advice.CreatedTime = hisAdvice.CreatedTime
  6571. advice.UpdatedTime = time.Now().Unix()
  6572. } else {
  6573. advice.CreatedTime = hisAdvice.CreatedTime
  6574. advice.UpdatedTime = hisAdvice.UpdatedTime
  6575. }
  6576. }
  6577. //advice.Groupno = hisAdvice.Groupno
  6578. } else {
  6579. ctime := time.Now().Unix()
  6580. advice.CreatedTime = ctime
  6581. advice.UpdatedTime = ctime
  6582. }
  6583. }
  6584. } else {
  6585. ctime := time.Now().Unix()
  6586. advice.CreatedTime = ctime
  6587. advice.UpdatedTime = ctime
  6588. }
  6589. }
  6590. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6591. //
  6592. //if drugStockConfig.IsOpen == 1 {
  6593. //
  6594. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6595. // if advice.ID == 0 { //医嘱不存在
  6596. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6597. // drug.Total = drug.Total - advice.PrescribingNumber
  6598. // service.UpdateBaseDrugLib(&drug)
  6599. //
  6600. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6601. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6602. // drug.Total = drug.Total - num
  6603. // service.UpdateBaseDrugLib(&drug)
  6604. // }
  6605. //
  6606. // } else if advice.ID > 0 { //医嘱存在
  6607. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6608. // var num float64
  6609. //
  6610. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6611. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6612. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6613. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6614. // drug.Total = drug.Total + num
  6615. // service.UpdateBaseDrugLib(&drug)
  6616. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6617. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6618. // drug.Total = drug.Total - num
  6619. // service.UpdateBaseDrugLib(&drug)
  6620. // }
  6621. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6622. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6623. // if num2 > advice.PrescribingNumber {
  6624. // num = num2 - advice.PrescribingNumber
  6625. // drug.Total = drug.Total + num
  6626. // service.UpdateBaseDrugLib(&drug)
  6627. // } else if num2 < advice.PrescribingNumber {
  6628. // num = advice.PrescribingNumber - num2
  6629. // drug.Total = drug.Total - num
  6630. // service.UpdateBaseDrugLib(&drug)
  6631. // }
  6632. //
  6633. // }
  6634. //
  6635. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6636. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6637. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6638. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6639. // if num1 > num2 {
  6640. // num = num1 - num2
  6641. // drug.Total = drug.Total + num
  6642. // service.UpdateBaseDrugLib(&drug)
  6643. // } else if num1 < num2 {
  6644. // num = num2 - num1
  6645. // drug.Total = drug.Total - num
  6646. // service.UpdateBaseDrugLib(&drug)
  6647. // }
  6648. //
  6649. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6650. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6651. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6652. // if hisAdvice.PrescribingNumber > num2 {
  6653. // num = hisAdvice.PrescribingNumber - num2
  6654. // drug.Total = drug.Total + num
  6655. // service.UpdateBaseDrugLib(&drug)
  6656. // } else if num2 < advice.PrescribingNumber {
  6657. // num = num2 - hisAdvice.PrescribingNumber
  6658. // drug.Total = drug.Total - num
  6659. // service.UpdateBaseDrugLib(&drug)
  6660. // }
  6661. //
  6662. // }
  6663. // }
  6664. // }
  6665. //}
  6666. //
  6667. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6668. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6669. // advice.ExecutionTime = execution_time
  6670. //}
  6671. //
  6672. //
  6673. //
  6674. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6675. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6676. // advice.ExecutionStaff = execution_staff
  6677. //}
  6678. //
  6679. //
  6680. //
  6681. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6682. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6683. // advice.ExecutionState = execution_state
  6684. //}
  6685. //
  6686. //
  6687. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6688. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6689. // advice.CheckTime = check_time
  6690. //}
  6691. //
  6692. //
  6693. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6694. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6695. // advice.CheckState = check_state
  6696. //}
  6697. //
  6698. //
  6699. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6700. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6701. // advice.Checker = checker
  6702. //}
  6703. //
  6704. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6705. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6706. // advice.StartTime = start_time
  6707. //}
  6708. return 0
  6709. }
  6710. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6711. project.ExecutionStaff = 0
  6712. project.ExecutionState = 2
  6713. project.ExecutionTime = 0
  6714. project.Checker = 0
  6715. project.CheckState = 2
  6716. project.CheckTime = 0
  6717. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6718. id := int64(json["id"].(float64))
  6719. project.ID = id
  6720. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6721. project.ExecutionStaff = temp_project.ExecutionStaff
  6722. project.ExecutionState = temp_project.ExecutionState
  6723. project.ExecutionTime = temp_project.ExecutionTime
  6724. project.Checker = temp_project.Checker
  6725. project.CheckState = temp_project.CheckState
  6726. project.CheckTime = temp_project.CheckTime
  6727. project.TeamId = temp_project.TeamId
  6728. }
  6729. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6730. types := int64(json["type"].(float64))
  6731. project.Type = types
  6732. }
  6733. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6734. project_id := int64(json["project_id"].(float64))
  6735. project.ProjectId = project_id
  6736. }
  6737. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6738. team_id := int64(json["team_id"].(float64))
  6739. project.TeamId = team_id
  6740. }
  6741. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6742. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6743. project.Price = price
  6744. }
  6745. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6746. total, _ := json["total"].(string)
  6747. //totals, _ := strconv.ParseInt(total, 10, 64)
  6748. project.Count = total
  6749. }
  6750. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6751. medical_code, _ := json["medical_code"].(string)
  6752. project.MedListCodg = medical_code
  6753. }
  6754. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6755. single_dose, _ := json["single_dose"].(string)
  6756. project.SingleDose = single_dose
  6757. }
  6758. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6759. delivery_way, _ := json["delivery_way"].(string)
  6760. project.DeliveryWay = delivery_way
  6761. }
  6762. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6763. execution_frequency, _ := json["execution_frequency"].(string)
  6764. project.ExecutionFrequency = execution_frequency
  6765. }
  6766. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6767. remark, _ := json["remark"].(string)
  6768. project.Remark = remark
  6769. }
  6770. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6771. day, _ := json["number_days"].(string)
  6772. project.Day = day
  6773. }
  6774. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6775. unit, _ := json["unit"].(string)
  6776. project.Unit = unit
  6777. }
  6778. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6779. // frequency_type := int64(json["frequency_type"].(float64))
  6780. // project.FrequencyType = frequency_type
  6781. //}
  6782. //
  6783. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6784. // day_count := int64(json["day_count"].(float64))
  6785. // project.DayCount = day_count
  6786. //}
  6787. //
  6788. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6789. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6790. // week_day, _ := json["week_day"].(string)
  6791. // project.WeekDay = week_day
  6792. //}
  6793. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6794. //
  6795. //if project.ID == 0 {
  6796. // if stockConfig.IsOpen == 1 {
  6797. // if project.Type == 3 {
  6798. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6799. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6800. // good.Total = good.Total - f_count
  6801. // service.UpdateGoodInfo(&good)
  6802. // }
  6803. // }
  6804. //
  6805. //} else {
  6806. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6807. //
  6808. // if stockConfig.IsOpen == 1 {
  6809. // if project.Type == 3 {
  6810. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6811. // if project.Count < temp_project.Count {
  6812. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6813. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6814. //
  6815. // other_count := f_count_two - f_count_one
  6816. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6817. // good.Total = good.Total + other_count_two
  6818. // service.UpdateGoodInfo(&good)
  6819. // } else if project.Count > temp_project.Count {
  6820. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6821. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6822. //
  6823. // other_count := f_count_one - f_count_two
  6824. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6825. // good.Total = good.Total - other_count_two
  6826. // service.UpdateGoodInfo(&good)
  6827. // }
  6828. //
  6829. // }
  6830. // }
  6831. //
  6832. //}
  6833. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6834. id := int64(json["id"].(float64))
  6835. if id > 0 {
  6836. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6837. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  6838. fmt.Println("666666")
  6839. project.Mtime = time.Now().Unix()
  6840. project.Ctime = temp_project.Ctime
  6841. } else {
  6842. project.Mtime = temp_project.Mtime
  6843. project.Ctime = temp_project.Ctime
  6844. }
  6845. } else {
  6846. ctime := time.Now().Unix()
  6847. project.Mtime = ctime
  6848. project.Ctime = ctime
  6849. }
  6850. }
  6851. return 0
  6852. }
  6853. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6854. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6855. id := int64(json["id"].(float64))
  6856. additionalCharge.ID = id
  6857. }
  6858. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6859. item_id := int64(json["item_id"].(float64))
  6860. additionalCharge.ItemId = item_id
  6861. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6862. if config.ID > 0 {
  6863. if len(config.Code) > 0 {
  6864. additionalCharge.MedListCodg = config.Code
  6865. }
  6866. }
  6867. }
  6868. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6869. // price := int64(json["price"].(float64))
  6870. // formatInt_price := strconv.FormatInt(price, 10)
  6871. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6872. // additionalCharge.Price = float_price
  6873. // }
  6874. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6875. // price := int64(json["price"].(float64))
  6876. // formatInt_price := strconv.FormatInt(price, 10)
  6877. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6878. // additionalCharge.Price = float_price
  6879. //}
  6880. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6881. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6882. additionalCharge.Price = price
  6883. }
  6884. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6885. count, _ := json["count"].(string)
  6886. counts, _ := strconv.ParseInt(count, 10, 64)
  6887. additionalCharge.Count = counts
  6888. }
  6889. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6890. item_name, _ := json["item_name"].(string)
  6891. additionalCharge.ItemName = item_name
  6892. }
  6893. return 0
  6894. }
  6895. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6896. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6897. utils.ErrorLog("drug_name")
  6898. return enums.ErrorCodeParamWrong
  6899. }
  6900. adviceName, _ := json["drug_name"].(string)
  6901. if len(adviceName) == 0 {
  6902. utils.ErrorLog("len(advice_name) == 0")
  6903. return enums.ErrorCodeParamWrong
  6904. }
  6905. advice.AdviceName = adviceName
  6906. adviceDesc, _ := json["advice_desc"].(string)
  6907. advice.AdviceDesc = adviceDesc
  6908. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6909. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6910. advice.DrugSpec = drugSpec
  6911. }
  6912. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6913. remark, _ := json["remark"].(string)
  6914. advice.Remark = remark
  6915. }
  6916. if json["id"] == nil {
  6917. advice.DrugId = 0
  6918. } else {
  6919. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6920. drug_id := int64(json["id"].(float64))
  6921. advice.DrugId = drug_id
  6922. }
  6923. }
  6924. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6925. groupno := int64(json["groupno"].(float64))
  6926. advice.Groupno = groupno
  6927. }
  6928. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6929. drugSpecUnit, _ := json["min_unit"].(string)
  6930. advice.DrugSpecUnit = drugSpecUnit
  6931. }
  6932. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6933. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6934. advice.SingleDose = singleDose
  6935. }
  6936. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6937. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6938. advice.SingleDoseUnit = singleDoseUnit
  6939. }
  6940. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6941. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6942. advice.PrescribingNumber = prescribingNumber
  6943. }
  6944. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6945. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6946. advice.PrescribingNumberUnit = prescribingNumberUnit
  6947. }
  6948. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6949. deliveryWay, _ := json["delivery_way"].(string)
  6950. advice.DeliveryWay = deliveryWay
  6951. }
  6952. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6953. executionFrequency, _ := json["execution_frequency"].(string)
  6954. advice.ExecutionFrequency = executionFrequency
  6955. }
  6956. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6957. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6958. advice.Price = price
  6959. }
  6960. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6961. med_list_codg, _ := json["medical_insurance_number"].(string)
  6962. advice.MedListCodg = med_list_codg
  6963. }
  6964. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6965. day := int64(json["day"].(float64))
  6966. advice.Day = day
  6967. }
  6968. advice.FrequencyType = 1
  6969. return 0
  6970. }
  6971. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  6972. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6973. types := int64(json["type"].(float64))
  6974. project.Type = types
  6975. }
  6976. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6977. project_id := int64(json["project_id"].(float64))
  6978. project.ProjectId = project_id
  6979. }
  6980. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6981. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6982. project.Price = price
  6983. }
  6984. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6985. total, _ := json["total"].(string)
  6986. //totals, _ := strconv.ParseInt(total, 10, 64)
  6987. project.Count = total
  6988. }
  6989. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6990. medical_code, _ := json["medical_code"].(string)
  6991. project.MedListCodg = medical_code
  6992. }
  6993. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6994. single_dose, _ := json["single_dose"].(string)
  6995. project.SingleDose = single_dose
  6996. }
  6997. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6998. delivery_way, _ := json["delivery_way"].(string)
  6999. project.DeliveryWay = delivery_way
  7000. }
  7001. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7002. execution_frequency, _ := json["execution_frequency"].(string)
  7003. project.ExecutionFrequency = execution_frequency
  7004. }
  7005. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7006. remark, _ := json["remark"].(string)
  7007. project.Remark = remark
  7008. }
  7009. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7010. day, _ := json["number_days"].(string)
  7011. project.Day = day
  7012. }
  7013. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7014. unit, _ := json["unit"].(string)
  7015. project.Unit = unit
  7016. }
  7017. project.FrequencyType = 1
  7018. return 0
  7019. }
  7020. func (c *HisApiController) GetHisOrderListTwo() {
  7021. start_time := c.GetString("start_time")
  7022. end_time := c.GetString("end_time")
  7023. timeLayout := "2006-01-02"
  7024. loc, _ := time.LoadLocation("Local")
  7025. var startTime int64
  7026. if len(start_time) > 0 {
  7027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7028. if err != nil {
  7029. //fmt.Println(err)
  7030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7031. return
  7032. }
  7033. startTime = theTime.Unix()
  7034. }
  7035. var endTime int64
  7036. if len(end_time) > 0 {
  7037. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7038. if err != nil {
  7039. utils.ErrorLog(err.Error())
  7040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7041. return
  7042. }
  7043. endTime = theTime.Unix()
  7044. }
  7045. adminUser := c.GetAdminUserInfo()
  7046. org_id := adminUser.CurrentOrgId
  7047. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7048. if err == nil {
  7049. c.ServeSuccessJSON(map[string]interface{}{
  7050. "order2": order,
  7051. })
  7052. } else {
  7053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7054. return
  7055. }
  7056. }
  7057. func (c *HisApiController) GetHisOrderList() {
  7058. page, _ := c.GetInt64("page", -1)
  7059. limit, _ := c.GetInt64("limit", -1)
  7060. start_time := c.GetString("start_time")
  7061. end_time := c.GetString("end_time")
  7062. types, _ := c.GetInt64("type", 0)
  7063. keywords := c.GetString("keywords")
  7064. p_type, _ := c.GetInt64("p_type", 0)
  7065. sort_type, _ := c.GetInt64("sort_type", 0)
  7066. charge_type, _ := c.GetInt64("charge_type", 0)
  7067. sch_type, _ := c.GetInt64("sch_type", 0)
  7068. zone_type, _ := c.GetInt64("zone_type", 0)
  7069. med_type, _ := c.GetInt64("med_type", 0)
  7070. timeLayout := "2006-01-02"
  7071. loc, _ := time.LoadLocation("Local")
  7072. var startTime int64
  7073. if len(start_time) > 0 {
  7074. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7075. if err != nil {
  7076. //fmt.Println(err)
  7077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7078. return
  7079. }
  7080. startTime = theTime.Unix()
  7081. }
  7082. var endTime int64
  7083. if len(end_time) > 0 {
  7084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7085. if err != nil {
  7086. utils.ErrorLog(err.Error())
  7087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7088. return
  7089. }
  7090. endTime = theTime.Unix()
  7091. }
  7092. adminUser := c.GetAdminUserInfo()
  7093. org_id := adminUser.CurrentOrgId
  7094. 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)
  7095. for _, item := range order {
  7096. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7097. item.DoctorName = info.Doctor
  7098. item.DepartmentName = info.XtHisDepartment.Name
  7099. }
  7100. if err == nil {
  7101. c.ServeSuccessJSON(map[string]interface{}{
  7102. "order": order,
  7103. "total": total,
  7104. })
  7105. } else {
  7106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7107. return
  7108. }
  7109. }
  7110. func (c *HisApiController) GetHisOrder() {
  7111. patient_id, _ := c.GetInt64("patient_id", 0)
  7112. number := c.GetString("number")
  7113. adminInfo := c.GetAdminUserInfo()
  7114. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7115. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7116. if err == nil {
  7117. c.ServeSuccessJSON(map[string]interface{}{
  7118. "order": order,
  7119. "prescription": prescriptions,
  7120. })
  7121. } else {
  7122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7123. return
  7124. }
  7125. }
  7126. func (c *HisApiController) GetHisPrescriptionList() {
  7127. record_date := c.GetString("record_date")
  7128. keywords := c.GetString("keywords")
  7129. page, _ := c.GetInt64("page")
  7130. limit, _ := c.GetInt64("limit")
  7131. sch_type, _ := c.GetInt64("sch_type")
  7132. timeLayout := "2006-01-02"
  7133. loc, _ := time.LoadLocation("Local")
  7134. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7135. if err != nil {
  7136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7137. return
  7138. }
  7139. recordDateTime := theTime.Unix()
  7140. adminInfo := c.GetAdminUserInfo()
  7141. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7142. //adminInfo := c.GetAdminUserInfo()
  7143. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7144. //fmt.Println(prescriptionOrder)
  7145. if err == nil {
  7146. c.ServeSuccessJSON(map[string]interface{}{
  7147. "order": prescriptionOrder,
  7148. "total": total,
  7149. })
  7150. } else {
  7151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7152. return
  7153. }
  7154. }
  7155. func (c *HisApiController) GetHisPrescriptionInfo() {
  7156. id, _ := c.GetInt64("id")
  7157. adminInfo := c.GetAdminUserInfo()
  7158. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7159. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7160. if err == nil {
  7161. c.ServeSuccessJSON(map[string]interface{}{
  7162. "order": prescriptionOrder,
  7163. "prescription": prescription,
  7164. })
  7165. } else {
  7166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7167. return
  7168. }
  7169. }
  7170. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7171. adminUser := c.GetAdminUserInfo()
  7172. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7173. c.ServeSuccessJSON(map[string]interface{}{
  7174. "config": config,
  7175. })
  7176. }
  7177. type ResultTwo struct {
  7178. ErrMsg interface{} `json:"err_msg"`
  7179. InfRefmsgid string `json:"inf_refmsgid"`
  7180. Infcode int64 `json:"infcode"`
  7181. Output struct {
  7182. Baseinfo struct {
  7183. Age float64 `json:"age"`
  7184. Brdy string `json:"brdy"`
  7185. Certno string `json:"certno"`
  7186. Gend string `json:"gend"`
  7187. Naty string `json:"naty"`
  7188. PsnCertType string `json:"psn_cert_type"`
  7189. PsnName string `json:"psn_name"`
  7190. PsnNo string `json:"psn_no"`
  7191. } `json:"baseinfo"`
  7192. Idetinfo []interface{} `json:"idetinfo"`
  7193. Iinfo []struct {
  7194. Balc float64 `json:"balc"`
  7195. CvlservFlag string `json:"cvlserv_flag"`
  7196. EmpName string `json:"emp_name"`
  7197. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7198. Insutype string `json:"insutype"`
  7199. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7200. PausInsuDate interface{} `json:"paus_insu_date"`
  7201. PsnInsuDate string `json:"psn_insu_date"`
  7202. PsnInsuStas string `json:"psn_insu_stas"`
  7203. PsnType string `json:"psn_type"`
  7204. } `json:"insuinfo"`
  7205. } `json:"output"`
  7206. RefmsgTime string `json:"refmsg_time"`
  7207. RespondTime string `json:"respond_time"`
  7208. Signtype interface{} `json:"signtype"`
  7209. WarnInfo interface{} `json:"warn_info"`
  7210. }
  7211. type ResultThree struct {
  7212. Cainfo interface{} `json:"cainfo"`
  7213. ErrMsg interface{} `json:"err_msg"`
  7214. InfRefmsgid string `json:"inf_refmsgid"`
  7215. Infcode int64 `json:"infcode"`
  7216. Output struct {
  7217. Data struct {
  7218. IptOtpNo string `json:"ipt_otp_no"`
  7219. MdtrtID string `json:"mdtrt_id"`
  7220. PsnNo string `json:"psn_no"`
  7221. } `json:"data"`
  7222. } `json:"output"`
  7223. RefmsgTime string `json:"refmsg_time"`
  7224. RespondTime string `json:"respond_time"`
  7225. Signtype interface{} `json:"signtype"`
  7226. WarnMsg interface{} `json:"warn_msg"`
  7227. }
  7228. type ResultFour struct {
  7229. Cainfo string `json:"cainfo"`
  7230. ErrMsg string `json:"err_msg"`
  7231. InfRefmsgid string `json:"inf_refmsgid"`
  7232. Infcode int64 `json:"infcode"`
  7233. Output struct {
  7234. Result []struct {
  7235. BasMednFlag string `json:"bas_medn_flag"`
  7236. ChldMedcFlag string `json:"chld_medc_flag"`
  7237. ChrgitmLv string `json:"chrgitm_lv"`
  7238. Cnt float64 `json:"cnt"`
  7239. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7240. DrtReimFlag string `json:"drt_reim_flag"`
  7241. FeedetlSn string `json:"feedetl_sn"`
  7242. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7243. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7244. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7245. ListSpItemFlag string `json:"list_sp_item_flag"`
  7246. LmtUsedFlag string `json:"lmt_used_flag"`
  7247. MedChrgitmType string `json:"med_chrgitm_type"`
  7248. Memo string `json:"memo"`
  7249. OverlmtAmt float64 `json:"overlmt_amt"`
  7250. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7251. Pric float64 `json:"pric"`
  7252. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7253. SelfpayProp float64 `json:"selfpay_prop"`
  7254. } `json:"result"`
  7255. } `json:"output"`
  7256. RefmsgTime string `json:"refmsg_time"`
  7257. RespondTime string `json:"respond_time"`
  7258. Signtype string `json:"signtype"`
  7259. WarnMsg string `json:"warn_msg"`
  7260. }
  7261. type ResultFive struct {
  7262. Insutype string `json:"insutype"`
  7263. }
  7264. type ResultSix struct {
  7265. Cainfo interface{} `json:"cainfo"`
  7266. ErrMsg interface{} `json:"err_msg"`
  7267. InfRefmsgid string `json:"inf_refmsgid"`
  7268. Infcode int64 `json:"infcode"`
  7269. Output struct {
  7270. } `json:"output"`
  7271. RefmsgTime string `json:"refmsg_time"`
  7272. RespondTime string `json:"respond_time"`
  7273. Signtype interface{} `json:"signtype"`
  7274. WarnMsg interface{} `json:"warn_msg"`
  7275. }
  7276. type ResultSeven struct {
  7277. Cainfo string `json:"cainfo"`
  7278. ErrMsg string `json:"err_msg"`
  7279. InfRefmsgid string `json:"inf_refmsgid"`
  7280. Infcode int64 `json:"infcode"`
  7281. Output struct {
  7282. Setldetail []interface{} `json:"setldetail"`
  7283. Setlinfo struct {
  7284. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7285. AcctPay float64 `json:"acct_pay"`
  7286. ActPayDedc float64 `json:"act_pay_dedc"`
  7287. Age float64 `json:"age"`
  7288. Balc float64 `json:"balc"`
  7289. Brdy string `json:"brdy"`
  7290. Certno string `json:"certno"`
  7291. ClrOptins string `json:"clr_optins"`
  7292. ClrType string `json:"clr_type"`
  7293. ClrWay string `json:"clr_way"`
  7294. CvlservFlag string `json:"cvlserv_flag"`
  7295. CvlservPay float64 `json:"cvlserv_pay"`
  7296. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7297. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7298. Gend string `json:"gend"`
  7299. HifesPay float64 `json:"hifes_pay"`
  7300. HifmiPay float64 `json:"hifmi_pay"`
  7301. HifobPay float64 `json:"hifob_pay"`
  7302. HifpPay float64 `json:"hifp_pay"`
  7303. HospPartAmt float64 `json:"hosp_part_amt"`
  7304. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7305. Insutype string `json:"insutype"`
  7306. MafPay float64 `json:"maf_pay"`
  7307. MdtrtCertType string `json:"mdtrt_cert_type"`
  7308. MdtrtID string `json:"mdtrt_id"`
  7309. MedType string `json:"med_type"`
  7310. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7311. MedinsSetlID string `json:"medins_setl_id"`
  7312. Naty string `json:"naty"`
  7313. OthPay float64 `json:"oth_pay"`
  7314. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7315. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7316. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7317. PsnCashPay float64 `json:"psn_cash_pay"`
  7318. PsnCertType string `json:"psn_cert_type"`
  7319. PsnName string `json:"psn_name"`
  7320. PsnNo string `json:"psn_no"`
  7321. PsnPartAmt float64 `json:"psn_part_amt"`
  7322. PsnType string `json:"psn_type"`
  7323. SetlID string `json:"setl_id"`
  7324. SetlTime string `json:"setl_time"`
  7325. } `json:"setlinfo"`
  7326. } `json:"output"`
  7327. RefmsgTime string `json:"refmsg_time"`
  7328. RespondTime string `json:"respond_time"`
  7329. Signtype interface{} `json:"signtype"`
  7330. WarnMsg interface{} `json:"warn_msg"`
  7331. }
  7332. type ResultEight struct {
  7333. Cainfo string `json:"cainfo"`
  7334. ErrMsg string `json:"err_msg"`
  7335. InfRefmsgid string `json:"inf_refmsgid"`
  7336. Infcode int64 `json:"infcode"`
  7337. Output struct {
  7338. Stmtinfo struct {
  7339. SetlOptins string `json:"setl_optins"`
  7340. StmtRslt string `json:"stmt_rslt"`
  7341. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7342. } `json:"stmtinfo"`
  7343. } `json:"output"`
  7344. RefmsgTime string `json:"refmsg_time"`
  7345. RespondTime string `json:"respond_time"`
  7346. Signtype interface{} `json:"signtype"`
  7347. WarnMsg interface{} `json:"warn_msg"`
  7348. }
  7349. type ResultNine struct {
  7350. Cainfo string `json:"cainfo"`
  7351. ErrMsg string `json:"err_msg"`
  7352. InfRefmsgid string `json:"inf_refmsgid"`
  7353. Infcode int64 `json:"infcode"`
  7354. Output struct {
  7355. FileQuryNo string `json:"file_qury_no"`
  7356. } `json:"output"`
  7357. RefmsgTime string `json:"refmsg_time"`
  7358. RespondTime string `json:"respond_time"`
  7359. Signtype interface{} `json:"signtype"`
  7360. WarnMsg interface{} `json:"warn_msg"`
  7361. }
  7362. type ResultTen struct {
  7363. Cainfo string `json:"cainfo"`
  7364. ErrMsg string `json:"err_msg"`
  7365. InfRefmsgid string `json:"inf_refmsgid"`
  7366. Infcode int64 `json:"infcode"`
  7367. Output struct {
  7368. DldEndtime string `json:"dld_endtime"`
  7369. FileQuryNo string `json:"file_qury_no"`
  7370. Filename string `json:"filename"`
  7371. } `json:"output"`
  7372. RefmsgTime string `json:"refmsg_time"`
  7373. RespondTime string `json:"respond_time"`
  7374. Signtype interface{} `json:"signtype"`
  7375. WarnMsg interface{} `json:"warn_msg"`
  7376. }
  7377. type ResultEleven struct {
  7378. Cainfo string `json:"cainfo"`
  7379. ErrMsg string `json:"err_msg"`
  7380. InfRefmsgid string `json:"inf_refmsgid"`
  7381. Infcode int64 `json:"infcode"`
  7382. Output struct {
  7383. Setlinfo struct {
  7384. FixmedinsName string `json:"fixmedins_name"`
  7385. FixmedinsCode string `json:"fixmedins_code"`
  7386. PsnNo string `json:"psn_no"`
  7387. PsnName string `json:"psn_name"`
  7388. HifobPay float64 `json:"hifob_pay"`
  7389. Gend string `json:"gend"`
  7390. Brdy string `json:"brdy"`
  7391. PsnCertType string `json:"psn_cert_type"`
  7392. PsnType string `json:"psn_type"`
  7393. EmpName string `json:"emp_name"`
  7394. Certno string `json:"certno"`
  7395. Insutype string `json:"insutype"`
  7396. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7397. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7398. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7399. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7400. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7401. ActPayDedc float64 `json:"act_pay_dedc"`
  7402. HifpPay float64 `json:"hifp_pay"`
  7403. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7404. CvlservPay float64 `json:"cvlserv_pay"`
  7405. HifesPay float64 `json:"hifes_pay"`
  7406. HifmiPay float64 `json:"hifmi_pay"`
  7407. MafPay float64 `json:"maf_pay"`
  7408. OthPay float64 `json:"oth_pay"`
  7409. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7410. PsnPay float64 `json:"psn_pay"`
  7411. AcctPay float64 `json:"acct_pay"`
  7412. CashPayamt float64 `json:"cash_payamt"`
  7413. Balc float64 `json:"balc"`
  7414. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7415. MedinsSetlId string `json:"medins_setl_id"`
  7416. RefdSetlFlag string `json:"refd_setl_flag"`
  7417. SetlTime string `json:"setl_time"`
  7418. MedType string `json:"med_type"`
  7419. } `json:"setlinfo"`
  7420. } `json:"output"`
  7421. RefmsgTime string `json:"refmsg_time"`
  7422. RespondTime string `json:"respond_time"`
  7423. Signtype interface{} `json:"signtype"`
  7424. WarnMsg interface{} `json:"warn_msg"`
  7425. }
  7426. type Custom struct {
  7427. DetItemFeeSumamt string
  7428. Cut string
  7429. FeedetlSn string
  7430. Price string
  7431. MedListCodg string
  7432. Type int64
  7433. AdviceId int64
  7434. ProjectId int64
  7435. ItemId int64
  7436. }
  7437. // 获取个人信息----挂号-----上传就诊信息
  7438. func (c *HisApiController) GetRegisterInfo() {
  7439. id, _ := c.GetInt64("id")
  7440. record_time := c.GetString("record_time")
  7441. settlementValue, _ := c.GetInt64("settlement_value")
  7442. medical_insurance_card := c.GetString("medical_insurance_card")
  7443. name := c.GetString("name")
  7444. id_card_type, _ := c.GetInt64("id_card_type")
  7445. certificates, _ := c.GetInt64("certificates")
  7446. medical_care, _ := c.GetInt64("medical_care")
  7447. birthday := c.GetString("birthday")
  7448. age, _ := c.GetInt64("age")
  7449. id_card := c.GetString("id_card")
  7450. register_type, _ := c.GetInt64("register")
  7451. doctor, _ := c.GetInt64("doctor")
  7452. department, _ := c.GetInt64("department")
  7453. gender, _ := c.GetInt64("sex")
  7454. phone := c.GetString("phone")
  7455. registration_fee, _ := c.GetFloat("registration_fee")
  7456. medical_expenses, _ := c.GetFloat("medical_expenses")
  7457. social_type, _ := c.GetInt64("social_type")
  7458. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7459. diagnosis_ids := c.GetString("diagnosis")
  7460. sick_type, _ := c.GetInt64("sick_type")
  7461. reg_type := c.GetString("p_type")
  7462. timeLayout := "2006-01-02"
  7463. loc, _ := time.LoadLocation("Local")
  7464. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7465. birthUnix := birthdays.Unix()
  7466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7467. if err != nil {
  7468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7469. return
  7470. }
  7471. recordDateTime := theTime.Unix()
  7472. adminInfo := c.GetAdminUserInfo()
  7473. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7474. if tempPatient.ID == 0 {
  7475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7476. return
  7477. }
  7478. var patient service.Patients
  7479. if id == 0 {
  7480. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7481. } else {
  7482. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7483. }
  7484. if patient.ID == 0 {
  7485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7486. return
  7487. }
  7488. if len(patient.IdCardNo) == 0 {
  7489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7490. return
  7491. }
  7492. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7493. if len(his) >= 1 {
  7494. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7495. if len(his) >= 1 && order.ID == 0 {
  7496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7497. return
  7498. }
  7499. }
  7500. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7501. fmt.Println(timeStr)
  7502. timeArr := strings.Split(timeStr, " ")
  7503. fmt.Println(timeArr)
  7504. timeArrTwo := strings.Split(timeArr[0], "-")
  7505. timeArrThree := strings.Split(timeArr[1], ":")
  7506. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7507. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7508. if len(lists) == 0 {
  7509. var hisPatient models.XtHisPatient
  7510. hisPatient = models.XtHisPatient{
  7511. Name: name,
  7512. Age: age,
  7513. Gender: gender,
  7514. Birthday: birthUnix,
  7515. Phone: phone,
  7516. MedicalTreatmentType: medical_care,
  7517. IdType: certificates,
  7518. IdCardNo: id_card,
  7519. BalanceAccountsType: settlementValue,
  7520. SocialType: social_type,
  7521. MedicalInsuranceNumber: medical_insurance_card,
  7522. RegisterType: register_type,
  7523. RegisterCost: registration_fee,
  7524. TreatmentCost: medical_expenses,
  7525. AdminUserId: adminInfo.AdminUser.Id,
  7526. UserOrgId: adminInfo.CurrentOrgId,
  7527. Status: 1,
  7528. RecordDate: recordDateTime,
  7529. IsReturn: 1,
  7530. PatientId: patient.ID,
  7531. Ctime: time.Now().Unix(),
  7532. Mtime: time.Now().Unix(),
  7533. Number: str,
  7534. IdCardType: id_card_type,
  7535. Departments: department,
  7536. Doctor: doctor,
  7537. PType: reg_type,
  7538. Diagnosis: diagnosis_ids,
  7539. SickType: sick_type,
  7540. }
  7541. service.CreateHisPatient(&hisPatient)
  7542. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7543. c.ServeSuccessJSON(map[string]interface{}{
  7544. "his_info": hisPatient,
  7545. })
  7546. } else {
  7547. //chrgBchno := rand.Intn(1000000) + 10000
  7548. var hisPatient models.XtHisPatient
  7549. hisPatient = models.XtHisPatient{
  7550. Name: name,
  7551. Age: age,
  7552. Gender: gender,
  7553. Birthday: birthUnix,
  7554. Phone: phone,
  7555. MedicalTreatmentType: medical_care,
  7556. IdType: certificates,
  7557. IdCardNo: id_card,
  7558. BalanceAccountsType: settlementValue,
  7559. SocialType: social_type,
  7560. MedicalInsuranceNumber: medical_insurance_card,
  7561. RegisterType: register_type,
  7562. RegisterCost: registration_fee,
  7563. TreatmentCost: medical_expenses,
  7564. AdminUserId: adminInfo.AdminUser.Id,
  7565. UserOrgId: adminInfo.CurrentOrgId,
  7566. Status: 1,
  7567. RecordDate: recordDateTime,
  7568. IsReturn: 1,
  7569. PatientId: patient.ID,
  7570. Ctime: time.Now().Unix(),
  7571. Mtime: time.Now().Unix(),
  7572. Number: str,
  7573. IdCardType: id_card_type,
  7574. Departments: department,
  7575. Doctor: doctor,
  7576. PType: reg_type,
  7577. Diagnosis: diagnosis_ids,
  7578. SickType: sick_type,
  7579. }
  7580. service.CreateHisPatient(&hisPatient)
  7581. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7582. c.ServeSuccessJSON(map[string]interface{}{
  7583. "his_info": hisPatient,
  7584. })
  7585. }
  7586. }
  7587. // 上传明细----结算
  7588. func (c *HisApiController) GetUploadInfo() {
  7589. id, _ := c.GetInt64("id")
  7590. record_time := c.GetString("record_time")
  7591. his_patient_id, _ := c.GetInt64("his_patient_id")
  7592. oth_desc := c.GetString("oth_desc")
  7593. pay_way, _ := c.GetInt64("pay_way")
  7594. pay_ways := c.GetString("pay_ways")
  7595. pay_price, _ := c.GetFloat("pay_price")
  7596. pay_card_no := c.GetString("pay_card_no")
  7597. discount_price, _ := c.GetFloat("discount_price")
  7598. preferential_price, _ := c.GetFloat("preferential_price")
  7599. reality_price, _ := c.GetFloat("reality_price")
  7600. found_price, _ := c.GetFloat("found_price")
  7601. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7602. private_price, _ := c.GetFloat("private_price")
  7603. timeLayout := "2006-01-02"
  7604. loc, _ := time.LoadLocation("Local")
  7605. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7606. fapiao_code := c.GetString("fapiao_code")
  7607. fapiao_number := c.GetString("fapiao_number")
  7608. diagnosis_id := c.GetString("diagnosis")
  7609. sick_type, _ := c.GetInt64("sick_type")
  7610. reg_type, _ := c.GetInt64("p_type")
  7611. order_id, _ := c.GetInt64("order_id")
  7612. cash_pay := c.GetString("cash_pay")
  7613. wechat_pay := c.GetString("wechat_pay")
  7614. ali_pay := c.GetString("ali_pay")
  7615. jifen_pay := c.GetString("jifen_pay")
  7616. band_card_pay := c.GetString("band_card_pay")
  7617. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7618. tmp_decimal := c.GetString("tmp_decimal")
  7619. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7620. var decimal float64 //本次使用的押金
  7621. var errmsg error
  7622. tx := service.XTWriteDB().Begin() //开了事务
  7623. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7624. defer func() {
  7625. if errmsg != nil {
  7626. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7627. tx.Rollback()
  7628. } else {
  7629. tx.Commit()
  7630. }
  7631. }()
  7632. fmt.Println("dec_way", dec_way)
  7633. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7634. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7635. return
  7636. }
  7637. if len(tmp_decimal) > 0 {
  7638. if tmp_decimal[0] == 45 {
  7639. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7640. return
  7641. }
  7642. }
  7643. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7644. fmt.Println(errs)
  7645. decimal = tt
  7646. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7647. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7649. if err != nil {
  7650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7651. return
  7652. }
  7653. recordDateTime := theTime.Unix()
  7654. adminUser := c.GetAdminUserInfo()
  7655. var prescriptions []*models.HisPrescription
  7656. var prescriptionsOne []*models.HisPrescription
  7657. var start_time int64
  7658. var end_time int64
  7659. ids_str := c.GetString("ids")
  7660. ids_arr := strings.Split(ids_str, ",")
  7661. if tempOrder.ID == 0 {
  7662. if settle_accounts_type == 1 { //日结
  7663. fmt.Println(reg_type)
  7664. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7665. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7666. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7667. } else {
  7668. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7669. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7670. }
  7671. } else { //月结
  7672. start_time_str := c.GetString("start_time")
  7673. end_time_str := c.GetString("end_time")
  7674. timeLayout := "2006-01-02"
  7675. loc, _ := time.LoadLocation("Local")
  7676. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7677. if err != nil {
  7678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7679. return
  7680. }
  7681. recordStartTime := theStartTime.Unix()
  7682. start_time = recordStartTime
  7683. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7684. if err != nil {
  7685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7686. return
  7687. }
  7688. recordEndTime := theEndTime.Unix()
  7689. end_time = recordEndTime
  7690. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7691. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7692. }
  7693. var goods []*models.DialysisBeforePrepareGoods
  7694. var newGoods []*models.NewDialysisBeforePrepareGoods
  7695. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7696. var infos []*models.HisDoctorAdviceInfo
  7697. var infoList []*models.HisDoctorAdviceInfo
  7698. var hisAdvice []*models.HisDoctorAdviceInfo
  7699. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7700. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7701. //判断库存不足
  7702. //结算出库开关
  7703. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7704. if settConfig.IsOpen == 1 {
  7705. //判断库存的地方
  7706. for _, info := range prescriptions {
  7707. if info.Type == 1 {
  7708. infos = append(infos, info.HisDoctorAdviceInfo...)
  7709. }
  7710. if info.Type == 2 {
  7711. for _, sumItem := range info.HisPrescriptionProject {
  7712. if sumItem.Type == 3 {
  7713. var good models.DialysisBeforePrepareGoods
  7714. var newGood models.NewDialysisBeforePrepareGoods
  7715. good.GoodId = sumItem.GoodInfo.ID
  7716. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7717. count, _ := strconv.Atoi(sumItem.Count)
  7718. good.Count = int64(count)
  7719. good.StorehouseId = houseConfig.StorehouseOutInfo
  7720. good.ProjectId = sumItem.ID
  7721. goods = append(goods, &good)
  7722. newGood.GoodId = sumItem.GoodInfo.ID
  7723. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7724. count2, _ := strconv.Atoi(sumItem.Count)
  7725. newGood.Count = int64(count2)
  7726. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7727. newGood.ProjectId = sumItem.ID
  7728. newGoods = append(newGoods, &newGood)
  7729. }
  7730. }
  7731. }
  7732. }
  7733. for _, info := range prescriptionsOne {
  7734. if info.Type == 1 {
  7735. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7736. }
  7737. if info.Type == 2 {
  7738. for _, sumItem := range info.HisPrescriptionProject {
  7739. if sumItem.Type == 3 {
  7740. var newGood models.NewDialysisBeforePrepareGoods
  7741. newGood.GoodId = sumItem.GoodInfo.ID
  7742. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7743. count2, _ := strconv.Atoi(sumItem.Count)
  7744. newGood.Count = int64(count2)
  7745. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7746. newGood.ProjectId = sumItem.ID
  7747. newGoodOne = append(newGoodOne, &newGood)
  7748. }
  7749. }
  7750. }
  7751. }
  7752. //判断
  7753. for _, itemOne := range infos {
  7754. for _, itemTwo := range hisAdvice {
  7755. if itemOne.DrugId == itemTwo.DrugId {
  7756. itemTwo.Child = append(itemTwo.Child, itemOne)
  7757. }
  7758. }
  7759. }
  7760. for _, itemTwo := range hisAdvice {
  7761. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7762. var sum_out_count int64
  7763. for _, itemThree := range itemTwo.Child {
  7764. var prescribing_number int64
  7765. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7766. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7767. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7768. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7769. }
  7770. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7771. prescribing_number = parseIntPrescribingNumber
  7772. }
  7773. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7774. prescribing_number = parseIntPrescribingNumber
  7775. }
  7776. sum_out_count += prescribing_number
  7777. }
  7778. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7779. if sum_out_count > drugStockOut.FlushCount {
  7780. c.ServeSuccessJSON(map[string]interface{}{
  7781. "msg": "2",
  7782. "drug": medical,
  7783. })
  7784. return
  7785. }
  7786. }
  7787. for _, itemOne := range newGoods {
  7788. for _, item := range newGoodOne {
  7789. if itemOne.GoodId == item.GoodId {
  7790. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7791. }
  7792. }
  7793. }
  7794. for _, item := range newGoodOne {
  7795. var sum_out_count_one int64
  7796. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7797. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7798. sum_out_count_one += itemOne.Count
  7799. }
  7800. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7801. fmt.Println("sum_out_count_one", sum_out_count_one)
  7802. fmt.Println("list.FlushCount", list.FlushCount)
  7803. if sum_out_count_one > list.FlushCount {
  7804. c.ServeSuccessJSON(map[string]interface{}{
  7805. "msg": "3",
  7806. "good": good,
  7807. })
  7808. return
  7809. }
  7810. }
  7811. }
  7812. timestamp := time.Now().Unix()
  7813. tempTime := time.Unix(timestamp, 0)
  7814. timeFormat := tempTime.Format("20060102150405")
  7815. chrgBchno := rand.Intn(100000) + 10000
  7816. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7817. strconv.FormatInt(his.PatientId, 10)
  7818. var ids []int64
  7819. for _, item := range prescriptions {
  7820. ids = append(ids, item.ID)
  7821. }
  7822. var total float64
  7823. for _, item := range prescriptions {
  7824. fmt.Println(item)
  7825. if item.Type == 1 { //药品
  7826. for _, subItem := range item.HisDoctorAdviceInfo {
  7827. total = total + (subItem.Price * subItem.PrescribingNumber)
  7828. }
  7829. }
  7830. if item.Type == 2 { //项目
  7831. for _, subItem := range item.HisPrescriptionProject {
  7832. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7833. total = total + (subItem.Price * cnt)
  7834. }
  7835. }
  7836. for _, subItem := range item.HisAdditionalCharge {
  7837. total = total + (subItem.Price * float64(subItem.Count))
  7838. }
  7839. }
  7840. if reg_type == 1111 || reg_type == 1112 {
  7841. reg_type = 11
  7842. }
  7843. tm := time.Unix(time.Now().Unix(), 0)
  7844. allTotal := fmt.Sprintf("%.4f", total)
  7845. totals, _ := strconv.ParseFloat(allTotal, 64)
  7846. order := &models.HisOrder{
  7847. UserOrgId: adminUser.CurrentOrgId,
  7848. HisPatientId: his.ID,
  7849. PatientId: id,
  7850. SettleAccountsDate: recordDateTime,
  7851. Ctime: time.Now().Unix(),
  7852. Mtime: time.Now().Unix(),
  7853. Status: 1,
  7854. OrderStatus: 2,
  7855. MdtrtId: his.Number,
  7856. Number: chrg_bchno,
  7857. MedfeeSumamt: totals,
  7858. PayWay: pay_way,
  7859. PayWays: pay_ways,
  7860. PayPrice: pay_price,
  7861. MedType: strconv.Itoa(int(reg_type)),
  7862. PayCardNo: pay_card_no,
  7863. DiscountPrice: discount_price,
  7864. PreferentialPrice: preferential_price,
  7865. RealityPrice: reality_price,
  7866. FoundPrice: found_price,
  7867. MedicalInsurancePrice: medical_insurance_price,
  7868. PrivatePrice: private_price,
  7869. SettleEndTime: end_time,
  7870. SettleStartTime: start_time,
  7871. PsnPartAmt: totals,
  7872. PsnCashPay: totals,
  7873. SettleType: settle_accounts_type,
  7874. FaPiaoCode: fapiao_code,
  7875. FaPiaoNumber: fapiao_number,
  7876. Diagnosis: diagnosis_id,
  7877. PType: 2,
  7878. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7879. Decimal: decimal,
  7880. OthDesc: oth_desc,
  7881. CashPay: cash_pay,
  7882. WechatPay: wechat_pay,
  7883. AliPay: ali_pay,
  7884. JifenPay: jifen_pay,
  7885. BandCardPay: band_card_pay,
  7886. Creator: adminUser.AdminUser.Id,
  7887. }
  7888. err = service.CreateOrderTX(order, tx)
  7889. if err != nil {
  7890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7891. return
  7892. }
  7893. var customs []*Custom
  7894. for _, item := range prescriptions {
  7895. if item.Type == 1 { //药品a
  7896. for _, subItem := range item.HisDoctorAdviceInfo {
  7897. cus := &Custom{
  7898. AdviceId: subItem.ID,
  7899. ProjectId: 0,
  7900. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7901. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7902. FeedetlSn: subItem.FeedetlSn,
  7903. Price: fmt.Sprintf("%.4f", subItem.Price),
  7904. MedListCodg: subItem.MedListCodg,
  7905. Type: 1,
  7906. }
  7907. customs = append(customs, cus)
  7908. }
  7909. }
  7910. if item.Type == 2 { //项目
  7911. for _, subItem := range item.HisPrescriptionProject {
  7912. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7913. cus := &Custom{
  7914. AdviceId: 0,
  7915. ProjectId: subItem.ID,
  7916. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7917. Cut: fmt.Sprintf("%.4f", cnt),
  7918. FeedetlSn: subItem.FeedetlSn,
  7919. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7920. MedListCodg: subItem.MedListCodg,
  7921. Type: 2,
  7922. }
  7923. customs = append(customs, cus)
  7924. }
  7925. }
  7926. for _, item := range item.HisAdditionalCharge {
  7927. cus := &Custom{
  7928. ItemId: item.ID,
  7929. AdviceId: 0,
  7930. ProjectId: 0,
  7931. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7932. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7933. FeedetlSn: item.FeedetlSn,
  7934. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7935. MedListCodg: item.XtHisAddtionConfig.Code,
  7936. Type: 3,
  7937. }
  7938. customs = append(customs, cus)
  7939. }
  7940. }
  7941. for _, item := range customs {
  7942. var advice_id int64 = 0
  7943. var project_id int64 = 0
  7944. var item_id int64 = 0
  7945. var types int64 = 0
  7946. if item.Type == 1 {
  7947. advice_id = item.AdviceId
  7948. project_id = 0
  7949. item_id = 0
  7950. } else if item.Type == 2 {
  7951. advice_id = 0
  7952. item_id = 0
  7953. project_id = item.ProjectId
  7954. } else if item.Type == 3 {
  7955. advice_id = 0
  7956. item_id = item.ItemId
  7957. project_id = 0
  7958. }
  7959. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7960. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7961. pric, _ := strconv.ParseFloat(item.Price, 32)
  7962. info := &models.HisOrderInfo{
  7963. OrderNumber: order.Number,
  7964. UploadDate: time.Now().Unix(),
  7965. AdviceId: advice_id,
  7966. DetItemFeeSumamt: detItemFeeSumamt,
  7967. Cnt: cut,
  7968. Pric: pric,
  7969. PatientId: id,
  7970. Status: 1,
  7971. Mtime: time.Now().Unix(),
  7972. Ctime: time.Now().Unix(),
  7973. UserOrgId: adminUser.CurrentOrgId,
  7974. HisPatientId: his.ID,
  7975. OrderId: order.ID,
  7976. ProjectId: project_id,
  7977. Type: types,
  7978. ItemId: item_id,
  7979. }
  7980. service.CreateOrderInfoTX(info, tx)
  7981. }
  7982. his.Diagnosis = diagnosis_id
  7983. his.SickType = sick_type
  7984. his.RegisterType = reg_type
  7985. his.MedicalTreatmentType = reg_type
  7986. service.UpdataHisPateintTX(&his, tx)
  7987. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  7988. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  7989. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  7990. //判断是否使用了押金
  7991. if dec_way == "true" {
  7992. tmpstring := strconv.FormatInt(order.ID, 10)
  7993. //扣押金
  7994. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  7995. order.Decimal = decimal
  7996. service.UpDateOrderTwo(order, tx)
  7997. if errmsg != nil {
  7998. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  7999. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8000. return
  8001. }
  8002. }
  8003. if err == nil {
  8004. for _, info := range prescriptions {
  8005. if info.Type == 1 {
  8006. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8007. }
  8008. if info.Type == 2 {
  8009. for _, sumItem := range info.HisPrescriptionProject {
  8010. if sumItem.Type == 3 {
  8011. var good models.DialysisBeforePrepareGoods
  8012. var newGood models.NewDialysisBeforePrepareGoods
  8013. var oldGood models.OldDialysisBeforePrepareGoods
  8014. good.GoodId = sumItem.GoodInfo.ID
  8015. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8016. count, _ := strconv.Atoi(sumItem.Count)
  8017. good.Count = int64(count)
  8018. good.StorehouseId = houseConfig.StorehouseOutInfo
  8019. good.ProjectId = sumItem.ID
  8020. good.PatientId = sumItem.PatientId
  8021. goods = append(goods, &good)
  8022. newGood.GoodId = sumItem.GoodInfo.ID
  8023. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8024. count2, _ := strconv.Atoi(sumItem.Count)
  8025. newGood.Count = int64(count2)
  8026. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8027. newGood.ProjectId = sumItem.ID
  8028. newGood.PatientId = sumItem.HisPatientId
  8029. newGoods = append(newGoods, &newGood)
  8030. oldGood.GoodId = sumItem.GoodInfo.ID
  8031. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8032. count3, _ := strconv.Atoi(sumItem.Count)
  8033. oldGood.Count = int64(count3)
  8034. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8035. oldGood.ProjectId = sumItem.ID
  8036. oldGood.RecordDate = sumItem.RecordDate
  8037. oldGood.PatientId = sumItem.HisPatientId
  8038. oldGoods = append(oldGoods, &oldGood)
  8039. }
  8040. }
  8041. }
  8042. }
  8043. if settConfig.IsOpen == 1 {
  8044. for _, item := range infoList {
  8045. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8046. if medical.IsUse == 2 {
  8047. //药品出库
  8048. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8049. //查询默认仓库
  8050. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8051. //查询默认仓库剩余多少库存
  8052. var sum_count int64
  8053. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8054. for _, its := range stockInfo {
  8055. if its.MaxUnit == medical.MaxUnit {
  8056. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8057. }
  8058. sum_count += its.StockMaxNumber + its.StockMinNumber
  8059. }
  8060. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8061. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8062. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8063. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8064. }
  8065. }
  8066. orgId := c.GetAdminUserInfo().CurrentOrgId
  8067. if len(oldGoods) > 0 {
  8068. timeStr := time.Now().Format("2006-01-02")
  8069. timeArr := strings.Split(timeStr, "-")
  8070. total, _ := service.FindAllWarehouseOut(orgId)
  8071. total = total + 1
  8072. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8073. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8074. number = number + total
  8075. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8076. operation_time := time.Now().Unix()
  8077. creater := c.GetAdminUserInfo().AdminUser.Id
  8078. //查询默认出库仓库库存
  8079. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8080. recordDateStr := time.Now().Format("2006-01-02")
  8081. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8082. nowtime := recordDate.Unix()
  8083. warehouseOut := models.WarehouseOut{
  8084. WarehouseOutOrderNumber: warehousing_out_order,
  8085. OperationTime: operation_time,
  8086. OrgId: orgId,
  8087. Creater: creater,
  8088. Ctime: time.Now().Unix(),
  8089. Status: 1,
  8090. WarehouseOutTime: nowtime,
  8091. Type: 1,
  8092. StorehouseId: storeConfig.StorehouseOutInfo,
  8093. IsCheck: 1,
  8094. OrderId: order.ID,
  8095. IsSys: 5,
  8096. }
  8097. //查询是否生成出库单
  8098. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8099. if out.ID == 0 {
  8100. service.AddSigleWarehouseOut(&warehouseOut)
  8101. }
  8102. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8103. for _, item := range oldGoods {
  8104. dialyPrepareOne := models.DialysisBeforePrepare{
  8105. GoodTypeId: item.GoodTypeId,
  8106. GoodId: item.GoodId,
  8107. PatientId: his.PatientId,
  8108. RecordDate: item.RecordDate,
  8109. UserOrgId: adminUser.CurrentOrgId,
  8110. Count: item.Count,
  8111. Ctime: time.Now().Unix(),
  8112. Creater: adminUser.AdminUser.Id,
  8113. CommdityCode: item.CommdityCode,
  8114. Status: 1,
  8115. StorehouseId: houseConfig.StorehouseOutInfo,
  8116. }
  8117. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8118. //非零用
  8119. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8120. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8121. //查询剩余库存
  8122. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8123. var sum_count int64
  8124. for _, item := range goodList {
  8125. sum_count += item.StockCount
  8126. }
  8127. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8128. //耗材
  8129. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8130. }
  8131. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8132. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8133. //查询剩余库存
  8134. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8135. var sum_count int64
  8136. for _, item := range goodList {
  8137. sum_count += item.StockCount
  8138. }
  8139. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8140. //耗材
  8141. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8142. }
  8143. }
  8144. }
  8145. }
  8146. c.ServeSuccessJSON(map[string]interface{}{
  8147. "msg": "结算成功",
  8148. })
  8149. }
  8150. }
  8151. }
  8152. // 退款
  8153. func (c *HisApiController) Refund() {
  8154. order_id, _ := c.GetInt64("order_id")
  8155. order, _ := service.GetHisOrderByID(order_id)
  8156. adminUser := c.GetAdminUserInfo()
  8157. orgid := c.GetAdminUserInfo().CurrentOrgId
  8158. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8159. if err != nil {
  8160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8161. return
  8162. }
  8163. tmp := strconv.FormatInt(order.ID, 10)
  8164. //当押金不为零时产生退费记录
  8165. if order.Decimal != 0 {
  8166. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8167. if err != nil {
  8168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8169. return
  8170. }
  8171. }
  8172. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8173. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8174. var goods []*models.DialysisBeforePrepareGoods
  8175. var newGoods []*models.NewDialysisBeforePrepareGoods
  8176. var infos []*models.HisDoctorAdviceInfo
  8177. for _, info := range orders {
  8178. if info.AdviceId > 0 && info.ProjectId == 0 {
  8179. infos = append(infos, &info.HisDoctorAdviceInfo)
  8180. }
  8181. if info.ProjectId > 0 && info.AdviceId == 0 {
  8182. if info.HisPrescriptionProject.Type == 3 {
  8183. var good models.DialysisBeforePrepareGoods
  8184. var newGood models.NewDialysisBeforePrepareGoods
  8185. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8186. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8187. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8188. good.Count = int64(count)
  8189. good.StorehouseId = houseConfig.StorehouseOutInfo
  8190. good.ProjectId = info.HisPrescriptionProject.ID
  8191. good.PatientId = info.PatientId
  8192. good.OrderId = order_id
  8193. goods = append(goods, &good)
  8194. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8195. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8196. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8197. newGood.Count = int64(count2)
  8198. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8199. newGood.ProjectId = info.HisPrescriptionProject.ID
  8200. newGood.RecordDate = order.SettleAccountsDate
  8201. newGood.UserOrgId = order.UserOrgId
  8202. newGood.PatientId = info.PatientId
  8203. newGood.OrderId = order_id
  8204. newGoods = append(newGoods, &newGood)
  8205. }
  8206. }
  8207. }
  8208. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8209. if settConfig.IsOpen == 1 {
  8210. for _, item := range infos {
  8211. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8212. }
  8213. for _, item := range newGoods {
  8214. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8215. }
  8216. }
  8217. c.ServeSuccessJSON(map[string]interface{}{
  8218. "msg": "退费成功",
  8219. })
  8220. }
  8221. func (c *HisApiController) RefundNumber() {
  8222. his_patient_id, _ := c.GetInt64("id")
  8223. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8224. info.Status = 0
  8225. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8226. if count > 0 {
  8227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8228. return
  8229. }
  8230. err := service.SaveHisPatient(info)
  8231. if err == nil {
  8232. c.ServeSuccessJSON(map[string]interface{}{
  8233. "msg": "退号成功",
  8234. })
  8235. } else {
  8236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8237. return
  8238. }
  8239. }
  8240. func (this *HisApiController) AdditionalCharge() {
  8241. dataBody := make(map[string]interface{}, 0)
  8242. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8243. fmt.Println(err)
  8244. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8245. patient_id := int64(dataBody["patient_id"].(float64))
  8246. medicineData, _ := dataBody["medicineData"].([]interface{})
  8247. adminUserInfo := this.GetAdminUserInfo()
  8248. orgId := adminUserInfo.CurrentOrgId
  8249. admin_user_id := adminUserInfo.AdminUser.Id
  8250. timeStr := time.Now().Format("2006-01-02")
  8251. timeLayout := "2006-01-02 15:04:05"
  8252. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8253. timenow := timeStringToTime.Unix()
  8254. var additionalCharges []*models.HisAdditionalCharge
  8255. for _, item := range medicineData {
  8256. var randNum int
  8257. randNum = rand.Intn(10000) + 1000
  8258. timestamp := time.Now().Unix()
  8259. tempTime := time.Unix(timestamp, 0)
  8260. timeFormat := tempTime.Format("20060102150405")
  8261. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8262. items := item.(map[string]interface{})
  8263. money := items["price"].(string)
  8264. item_id_str := items["item_id"].(string)
  8265. name := items["name"].(string)
  8266. id_str := items["id"].(string)
  8267. moneys, _ := strconv.ParseInt(money, 10, 64)
  8268. monStr := strconv.FormatInt(moneys, 10)
  8269. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8270. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8271. id, _ := strconv.ParseInt(id_str, 10, 64)
  8272. additionalCharge := &models.HisAdditionalCharge{
  8273. ID: id,
  8274. HisPatientId: his_patient_id,
  8275. UserOrgId: orgId,
  8276. PatientId: patient_id,
  8277. RecordDate: timenow,
  8278. Price: monneyStr,
  8279. Status: 1,
  8280. ItemName: name,
  8281. ItemId: item_id,
  8282. AdminUserId: admin_user_id,
  8283. CreatedTime: time.Now().Unix(),
  8284. OrderStatus: 0,
  8285. PrescriptionNumber: "",
  8286. BatchNumber: "",
  8287. FeedetlSn: p_number,
  8288. }
  8289. service.CreateAdditionalCharge(additionalCharge)
  8290. additionalCharges = append(additionalCharges, additionalCharge)
  8291. }
  8292. this.ServeSuccessJSON(map[string]interface{}{
  8293. "msg": "添加成功",
  8294. "additional_charges": additionalCharges,
  8295. })
  8296. }
  8297. func (this *HisApiController) DeleteAddition() {
  8298. id, _ := this.GetInt64("id")
  8299. //TODO 需要判断是否已经结算
  8300. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8301. if err == nil {
  8302. this.ServeSuccessJSON(map[string]interface{}{
  8303. "msg": "删除成功",
  8304. })
  8305. return
  8306. } else {
  8307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8308. return
  8309. }
  8310. }
  8311. func (this *HisApiController) GetAdminUsers() {
  8312. adminUser := this.GetAdminUserInfo()
  8313. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8314. this.ServeSuccessJSON(map[string]interface{}{
  8315. "doctors": doctors,
  8316. })
  8317. }
  8318. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8319. change_type, _ := this.GetInt64("type", 0)
  8320. record_date := this.GetString("record_time")
  8321. patient_id, _ := this.GetInt64("patient_id", 0)
  8322. p_type, _ := this.GetInt64("p_type", 0)
  8323. timeLayout := "2006-01-02"
  8324. loc, _ := time.LoadLocation("Local")
  8325. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8326. record_time := theAdviceRecordTime.Unix()
  8327. adminUserInfo := this.GetAdminUserInfo()
  8328. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8329. if err == nil {
  8330. if len(prescriptions) == 0 {
  8331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8332. return
  8333. } else {
  8334. this.ServeSuccessJSON(map[string]interface{}{
  8335. "prescriptions": prescriptions,
  8336. })
  8337. return
  8338. }
  8339. } else {
  8340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8341. return
  8342. }
  8343. }
  8344. func (this *HisApiController) GetCallHisPrescription() {
  8345. patient_id, _ := this.GetInt64("patient_id", 0)
  8346. timeLayout := "2006-01-02"
  8347. loc, _ := time.LoadLocation("Local")
  8348. start_time := this.GetString("start_time")
  8349. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8350. end_time := this.GetString("end_time")
  8351. p_type, _ := this.GetInt64("p_type")
  8352. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8353. adminUserInfo := this.GetAdminUserInfo()
  8354. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8355. if err == nil {
  8356. this.ServeSuccessJSON(map[string]interface{}{
  8357. "prescriptions": prescriptions,
  8358. })
  8359. return
  8360. } else {
  8361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8362. return
  8363. }
  8364. }
  8365. func (this *HisApiController) GetHisDayPrescription() {
  8366. timeLayout := "2006-01-02"
  8367. loc, _ := time.LoadLocation("Local")
  8368. start_time := this.GetString("start_time")
  8369. patient_id, _ := this.GetInt64("patient_id", 0)
  8370. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8371. end_time := this.GetString("end_time")
  8372. p_type, _ := this.GetInt64("p_type")
  8373. order_status, _ := this.GetInt64("type")
  8374. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8375. adminUserInfo := this.GetAdminUserInfo()
  8376. var dayHisPrescription []*models.HisPrescription
  8377. var err error
  8378. if order_status == 1 || order_status == 0 {
  8379. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8380. } else if order_status == 2 {
  8381. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8382. }
  8383. var settle_total float64
  8384. for _, item := range dayHisPrescription {
  8385. if len(item.HisPrescriptionProject) > 0 {
  8386. for _, subItem := range item.HisPrescriptionProject {
  8387. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8388. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8389. settle_total = settle_total + total
  8390. }
  8391. }
  8392. if len(item.HisDoctorAdviceInfo) > 0 {
  8393. for _, subItem := range item.HisDoctorAdviceInfo {
  8394. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8395. settle_total = settle_total + total
  8396. }
  8397. }
  8398. }
  8399. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8400. if err == nil {
  8401. this.ServeSuccessJSON(map[string]interface{}{
  8402. "day_prescription": dayHisPrescription,
  8403. "settle_total": settle_total,
  8404. })
  8405. return
  8406. } else {
  8407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8408. return
  8409. }
  8410. }
  8411. func (c *HisApiController) GetHisChargePatientList() {
  8412. record_date := c.GetString("record_date")
  8413. order_status, _ := c.GetInt64("type")
  8414. sch_type, _ := c.GetInt64("sch_type")
  8415. timeLayout := "2006-01-02"
  8416. loc, _ := time.LoadLocation("Local")
  8417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8418. if err != nil {
  8419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8420. return
  8421. }
  8422. recordDateTime := theTime.Unix()
  8423. adminInfo := c.GetAdminUserInfo()
  8424. var tempPatients []*service.NewTempPatients
  8425. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8426. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8427. if order_status != 2 {
  8428. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8429. } else {
  8430. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8431. }
  8432. } else {
  8433. if order_status != 2 {
  8434. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8435. } else {
  8436. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8437. }
  8438. }
  8439. var patients []*service.NewTempPatients
  8440. var patients_two []*service.NewTempPatients
  8441. for _, item := range tempPatients {
  8442. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8443. //过滤掉没挂号的和没开处方的
  8444. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8445. patients = append(patients, item)
  8446. }
  8447. //过滤掉没挂号的
  8448. if len(item.HisPatient) > 0 {
  8449. patients_two = append(patients_two, item)
  8450. }
  8451. } else {
  8452. if len(item.HisPrescription) > 0 {
  8453. patients = append(patients, item)
  8454. }
  8455. }
  8456. }
  8457. c.ServeSuccessJSON(map[string]interface{}{
  8458. "list": patients,
  8459. "list_two": patients_two,
  8460. })
  8461. }
  8462. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8463. record_date := c.GetString("record_date")
  8464. timeLayout := "2006-01-02"
  8465. loc, _ := time.LoadLocation("Local")
  8466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8467. if err != nil {
  8468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8469. return
  8470. }
  8471. recordDateTime := theTime.Unix()
  8472. adminUser := c.GetAdminUserInfo()
  8473. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8474. var patients []*service.Patients
  8475. for _, item := range tempPatients {
  8476. if item.HisPatient.ID == 0 {
  8477. patients = append(patients, item)
  8478. }
  8479. }
  8480. c.ServeSuccessJSON(map[string]interface{}{
  8481. "list": patients,
  8482. //"list_two": patients_two,
  8483. })
  8484. }
  8485. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8486. newArr = make([]*service.Patients, 0)
  8487. for i := 0; i < len(patient); i++ {
  8488. repeat := false
  8489. for j := i + 1; j < len(patient); j++ {
  8490. if patient[i].ID == patient[j].ID {
  8491. repeat = true
  8492. break
  8493. }
  8494. }
  8495. if !repeat {
  8496. newArr = append(newArr, patient[i])
  8497. }
  8498. }
  8499. return
  8500. }
  8501. func (c *HisApiController) GetHisChargePatientInfo() {
  8502. patient_id, _ := c.GetInt64("patient_id")
  8503. his_patient_id, _ := c.GetInt64("his_patient_id")
  8504. record_date := c.GetString("record_date")
  8505. //start_time := c.GetString("start_time")
  8506. //end_time := c.GetString("end_time")
  8507. order_status, _ := c.GetInt64("type", 0)
  8508. p_type, _ := c.GetInt64("p_type", 0)
  8509. order_id, _ := c.GetInt64("order_id", 0)
  8510. timeLayout := "2006-01-02"
  8511. loc, _ := time.LoadLocation("Local")
  8512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8513. if err != nil {
  8514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8515. return
  8516. }
  8517. recordDateTime := theTime.Unix()
  8518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8519. //if err != nil {
  8520. //
  8521. //}
  8522. //startRecordDateTime := startTime.Unix()
  8523. //
  8524. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8525. //if err != nil {
  8526. //
  8527. //}
  8528. //endRecordDateTime := endTime.Unix()
  8529. admin := c.GetAdminUserInfo()
  8530. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8532. var prescriptions []*models.HisPrescription
  8533. //var unChargeMonthPrescriptions []*models.HisPrescription
  8534. order, _ := service.GetHisOrderByID(order_id)
  8535. if order_status == 1 || order_status == 0 {
  8536. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8537. } else if order_status == 2 {
  8538. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8539. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8540. }
  8541. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8542. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8543. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8544. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8545. //获取所有科室信息
  8546. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8547. c.ServeSuccessJSON(map[string]interface{}{
  8548. "his_info": his_patient_info,
  8549. "xt_info": xt_patient_info,
  8550. "prescription": prescriptions,
  8551. "case_history": case_history,
  8552. "info": patientPrescriptionInfo,
  8553. "last_info": lastPatientPrescriptionInfo,
  8554. "order": order,
  8555. "doctors": doctors,
  8556. "department": department,
  8557. })
  8558. return
  8559. }
  8560. func (c *HisApiController) GetAllOrderDetail() {
  8561. order_id, _ := c.GetInt64("id", 0)
  8562. order, _ := service.GetHisOrderByID(order_id)
  8563. if order.ID == 0 {
  8564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8565. return
  8566. }
  8567. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8568. org_id := c.GetAdminUserInfo().CurrentOrgId
  8569. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8570. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8571. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8572. c.ServeSuccessJSON(map[string]interface{}{
  8573. "order": order,
  8574. "order_info": order_info,
  8575. "patient": patient,
  8576. "admin_info": adminInfo,
  8577. "hospital_record": record,
  8578. })
  8579. return
  8580. }
  8581. func (c *HisApiController) GetAllOrderDetailCollect() {
  8582. order_id, _ := c.GetInt64("id", 0)
  8583. order, _ := service.GetHisOrderByID(order_id)
  8584. if order.ID == 0 {
  8585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8586. return
  8587. }
  8588. org_id := c.GetAdminUserInfo().CurrentOrgId
  8589. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8590. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8591. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8592. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8593. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8594. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8595. var bedCostTotal float64 = 0 //床位总费
  8596. //var bedCostSelfTotal float64 = 0 //床位自费
  8597. var operationCostTotal float64 = 0 //手术费
  8598. //var operationCostSelfTotal float64 = 0 //手术费
  8599. var otherCostTotal float64 = 0 //其他费用
  8600. //var otherCostSelfTotal float64 = 0 //其他费用
  8601. var materialCostTotal float64 = 0 //材料费
  8602. //var materialCostSelfTotal float64 = 0 //材料费
  8603. var westernMedicineCostTotal float64 = 0 //西药费
  8604. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8605. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8606. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8607. var checkCostTotal float64 = 0 //检查费
  8608. //var checkCostSelfTotal float64 = 0 //检查费
  8609. var laboratoryCostTotal float64 = 0 //化验费
  8610. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8611. var treatCostTotal float64 = 0 //治疗费用
  8612. //var treatCostSelfTotal float64 = 0 //治疗费用
  8613. var zhenChaCostTotal float64 = 0 //其他费用
  8614. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8615. decimal.DivisionPrecision = 2
  8616. var BalanceAccountsType int64
  8617. if his.ID > 0 {
  8618. BalanceAccountsType = his.BalanceAccountsType
  8619. } else {
  8620. BalanceAccountsType = record.BalanceAccountsType
  8621. }
  8622. if BalanceAccountsType != 2 {
  8623. for _, item := range order_info {
  8624. if org_id == 10215 {
  8625. if item.MedChrgitmType == "01" { //床位费
  8626. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8627. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8628. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8629. }
  8630. if item.MedChrgitmType == "02" { //诊察费
  8631. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8632. //zhenChaCostSelfTotal = zhenChaCostTotal
  8633. }
  8634. if item.MedChrgitmType == "03" { //检查费
  8635. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8636. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8637. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8638. }
  8639. //if item.MedChrgitmType == "02" { //检查费
  8640. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8641. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8642. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8643. //}
  8644. if item.MedChrgitmType == "04" { //化验费
  8645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8646. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8647. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8648. }
  8649. if item.MedChrgitmType == "05" { //治疗费
  8650. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8651. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8652. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8653. }
  8654. if item.MedChrgitmType == "06" { //手术费
  8655. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8656. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8657. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8658. }
  8659. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8660. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8661. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8662. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8663. }
  8664. if item.MedChrgitmType == "09" { //西药费
  8665. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8666. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8667. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8668. }
  8669. if item.MedChrgitmType == "11" { //中成费
  8670. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8671. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8672. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8673. }
  8674. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8675. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8676. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8677. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8678. }
  8679. } else if org_id == 10188 || org_id == 10217 {
  8680. if item.MedChrgitmType == "01" { //床位费
  8681. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8682. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8683. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8684. }
  8685. if item.MedChrgitmType == "02" { //诊察费
  8686. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8687. //zhenChaCostSelfTotal = zhenChaCostTotal
  8688. }
  8689. if item.MedChrgitmType == "03" { //检查费
  8690. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8691. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8692. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8693. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8694. }
  8695. //if item.MedChrgitmType == "02" { //检查费
  8696. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8697. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8698. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8699. //}
  8700. if item.MedChrgitmType == "04" { //化验费
  8701. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8702. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8703. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8704. }
  8705. if item.MedChrgitmType == "05" { //治疗费
  8706. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8707. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8708. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8709. }
  8710. if item.MedChrgitmType == "06" { //手术费
  8711. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8712. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8713. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8714. }
  8715. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8716. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8717. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8718. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8719. }
  8720. if item.MedChrgitmType == "09" { //西药费
  8721. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8722. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8723. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8724. }
  8725. if item.MedChrgitmType == "11" { //中成费
  8726. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8727. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8728. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8729. }
  8730. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8731. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8732. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8733. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8734. }
  8735. } else {
  8736. if item.MedChrgitmType == "01" { //床位费
  8737. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8738. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8739. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8740. }
  8741. //if item.MedChrgitmType == "02" { //诊察费
  8742. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8743. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8744. //}
  8745. if item.MedChrgitmType == "03" { //检查费
  8746. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8747. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8748. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8749. }
  8750. //if item.MedChrgitmType == "02" { //检查费
  8751. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8752. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8753. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8754. //}
  8755. if item.MedChrgitmType == "04" { //化验费
  8756. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8757. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8758. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8759. }
  8760. if item.MedChrgitmType == "05" { //治疗费
  8761. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8762. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8763. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8764. }
  8765. if item.MedChrgitmType == "06" { //手术费
  8766. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8767. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8768. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8769. }
  8770. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8771. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8772. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8773. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8774. }
  8775. if item.MedChrgitmType == "09" { //西药费
  8776. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8777. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8778. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8779. }
  8780. if item.MedChrgitmType == "11" { //中成费
  8781. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8782. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8783. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8784. }
  8785. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8786. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8787. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8788. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8789. }
  8790. }
  8791. }
  8792. c.ServeSuccessJSON(map[string]interface{}{
  8793. "order": order,
  8794. "order_info": order_info,
  8795. "patient": patient,
  8796. "admin_info": adminInfo,
  8797. "his_hospital": record,
  8798. "bedCostTotal": bedCostTotal,
  8799. "operationCostTotal": operationCostTotal,
  8800. "otherCostTotal": otherCostTotal,
  8801. "materialCostTotal": materialCostTotal,
  8802. "westernMedicineCostTotal": westernMedicineCostTotal,
  8803. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8804. "checkCostTotal": checkCostTotal,
  8805. "zhenChaCostTotal": zhenChaCostTotal,
  8806. "laboratoryCostTotal": laboratoryCostTotal,
  8807. "treatCostTotal": treatCostTotal,
  8808. })
  8809. } else {
  8810. for _, item := range order_info {
  8811. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8812. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8813. item.MedChrgitmType = "09"
  8814. }
  8815. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8816. if item.HisPrescriptionProject.Type == 2 {
  8817. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8818. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8819. case 0:
  8820. item.MedChrgitmType = "0"
  8821. break
  8822. case 1:
  8823. item.MedChrgitmType = "14"
  8824. break
  8825. case 2:
  8826. item.MedChrgitmType = "05"
  8827. break
  8828. case 3:
  8829. item.MedChrgitmType = "03"
  8830. break
  8831. case 4:
  8832. item.MedChrgitmType = "03"
  8833. break
  8834. case 5:
  8835. item.MedChrgitmType = "08"
  8836. break
  8837. case 6:
  8838. item.MedChrgitmType = "14"
  8839. break
  8840. case 7:
  8841. item.MedChrgitmType = "14"
  8842. break
  8843. case 8:
  8844. item.MedChrgitmType = "03"
  8845. break
  8846. case 9:
  8847. item.MedChrgitmType = "14"
  8848. break
  8849. case 10:
  8850. item.MedChrgitmType = "14"
  8851. break
  8852. case 11:
  8853. item.MedChrgitmType = "06"
  8854. break
  8855. case 12:
  8856. item.MedChrgitmType = "12"
  8857. break
  8858. case 13:
  8859. item.MedChrgitmType = "01"
  8860. break
  8861. case 14:
  8862. item.MedChrgitmType = "04"
  8863. break
  8864. case 15:
  8865. item.MedChrgitmType = "14"
  8866. break
  8867. }
  8868. } else {
  8869. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8870. case 1:
  8871. item.MedChrgitmType = "14"
  8872. break
  8873. case 2:
  8874. item.MedChrgitmType = "05"
  8875. break
  8876. case 3:
  8877. item.MedChrgitmType = "04"
  8878. break
  8879. case 4:
  8880. item.MedChrgitmType = "14"
  8881. break
  8882. case 5:
  8883. item.MedChrgitmType = "08"
  8884. break
  8885. case 6:
  8886. item.MedChrgitmType = "14"
  8887. break
  8888. case 7:
  8889. item.MedChrgitmType = "14"
  8890. break
  8891. case 8:
  8892. item.MedChrgitmType = "03"
  8893. break
  8894. case 9:
  8895. item.MedChrgitmType = "14"
  8896. break
  8897. }
  8898. }
  8899. } else if item.HisPrescriptionProject.Type == 3 {
  8900. item.MedChrgitmType = "08"
  8901. }
  8902. }
  8903. }
  8904. for _, item := range order_info {
  8905. if org_id == 10215 {
  8906. if item.MedChrgitmType == "01" { //床位费
  8907. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8908. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8909. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8910. }
  8911. if item.MedChrgitmType == "02" { //诊察费
  8912. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8913. //zhenChaCostSelfTotal = zhenChaCostTotal
  8914. }
  8915. if item.MedChrgitmType == "03" { //检查费
  8916. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8917. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8918. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8919. }
  8920. //if item.MedChrgitmType == "02" { //检查费
  8921. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8922. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8923. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8924. //}
  8925. if item.MedChrgitmType == "04" { //化验费
  8926. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8927. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8928. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8929. }
  8930. if item.MedChrgitmType == "05" { //治疗费
  8931. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8932. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8933. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8934. }
  8935. if item.MedChrgitmType == "06" { //手术费
  8936. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8937. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8938. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8939. }
  8940. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8941. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8942. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8943. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8944. }
  8945. if item.MedChrgitmType == "09" { //西药费
  8946. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8947. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8948. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8949. }
  8950. if item.MedChrgitmType == "11" { //中成费
  8951. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8952. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8953. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8954. }
  8955. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8956. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8957. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8958. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8959. }
  8960. } else {
  8961. if item.MedChrgitmType == "01" { //床位费
  8962. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8963. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8964. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8965. }
  8966. //if item.MedChrgitmType == "02" { //诊察费
  8967. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8968. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8969. //}
  8970. if item.MedChrgitmType == "03" { //检查费
  8971. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8972. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8973. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8974. }
  8975. //if item.MedChrgitmType == "02" { //检查费
  8976. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8977. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8978. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8979. //}
  8980. if item.MedChrgitmType == "04" { //化验费
  8981. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8982. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8983. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8984. }
  8985. if item.MedChrgitmType == "05" { //治疗费
  8986. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8987. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8988. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8989. }
  8990. if item.MedChrgitmType == "06" { //手术费
  8991. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8992. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8993. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8994. }
  8995. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8996. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8997. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8998. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8999. }
  9000. if item.MedChrgitmType == "09" { //西药费
  9001. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9002. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9003. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9004. }
  9005. if item.MedChrgitmType == "11" { //中成费
  9006. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9007. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9008. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9009. }
  9010. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9011. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9012. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9013. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9014. }
  9015. }
  9016. }
  9017. c.ServeSuccessJSON(map[string]interface{}{
  9018. "order": order,
  9019. "order_info": order_info,
  9020. "patient": patient,
  9021. "admin_info": adminInfo,
  9022. "his_hospital": record,
  9023. "bedCostTotal": bedCostTotal,
  9024. "operationCostTotal": operationCostTotal,
  9025. "otherCostTotal": otherCostTotal,
  9026. "materialCostTotal": materialCostTotal,
  9027. "westernMedicineCostTotal": westernMedicineCostTotal,
  9028. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9029. "checkCostTotal": checkCostTotal,
  9030. "zhenChaCostTotal": zhenChaCostTotal,
  9031. "laboratoryCostTotal": laboratoryCostTotal,
  9032. "treatCostTotal": treatCostTotal,
  9033. })
  9034. }
  9035. }
  9036. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9037. page, _ := c.GetInt64("page")
  9038. limit, _ := c.GetInt64("limit")
  9039. keywords := c.GetString("keywords")
  9040. start_time := c.GetString("start_time")
  9041. end_time := c.GetString("end_time")
  9042. //clr_type := c.GetString("clr_type")
  9043. insutype := c.GetString("insutype")
  9044. timeLayout := "2006-01-02"
  9045. loc, _ := time.LoadLocation("Local")
  9046. var theStartTIme int64
  9047. if len(start_time) > 0 {
  9048. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9049. theStartTIme = theTime.Unix()
  9050. }
  9051. var theEndtTIme int64
  9052. if len(end_time) > 0 {
  9053. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9054. theEndtTIme = theTime.Unix()
  9055. }
  9056. if page <= 0 {
  9057. page = 1
  9058. }
  9059. if limit <= 0 {
  9060. limit = 10
  9061. }
  9062. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9063. c.ServeSuccessJSON(map[string]interface{}{
  9064. "total": total,
  9065. "list": list,
  9066. })
  9067. return
  9068. }
  9069. func (c *HisApiController) GetPutOnRecordList() {
  9070. page, _ := c.GetInt64("page")
  9071. limit, _ := c.GetInt64("limit")
  9072. keywords := c.GetString("keywords")
  9073. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9074. if page <= 0 {
  9075. page = 1
  9076. }
  9077. if limit <= 0 {
  9078. limit = 10
  9079. }
  9080. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9081. c.ServeSuccessJSON(map[string]interface{}{
  9082. "total": total,
  9083. "list": list,
  9084. })
  9085. return
  9086. }
  9087. func (c *HisApiController) GetCompareData() {
  9088. start_time := c.GetString("start_time")
  9089. end_time := c.GetString("end_time")
  9090. insutype := c.GetString("insutype")
  9091. clr_type := c.GetString("clr_type")
  9092. timeLayout := "2006-01-02"
  9093. loc, _ := time.LoadLocation("Local")
  9094. var theStartTIme int64
  9095. if len(start_time) > 0 {
  9096. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9097. if err != nil {
  9098. theStartTIme = 0
  9099. }
  9100. theStartTIme = theTime.Unix()
  9101. }
  9102. var theEndtTIme int64
  9103. if len(end_time) > 0 {
  9104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9105. if err != nil {
  9106. theEndtTIme = 0
  9107. }
  9108. theEndtTIme = theTime.Unix()
  9109. }
  9110. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9111. fmt.Println(err)
  9112. if err == nil {
  9113. c.ServeSuccessJSON(map[string]interface{}{
  9114. "list": formData,
  9115. })
  9116. } else {
  9117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9118. return
  9119. }
  9120. }
  9121. func (c *HisApiController) GetFaPiaoData() {
  9122. order_id, _ := c.GetInt64("order_id")
  9123. patient_id, _ := c.GetInt64("patient_id")
  9124. //number := c.GetString("number")
  9125. adminUser := c.GetAdminUserInfo()
  9126. order, _ := service.GetHisOrderByID(order_id)
  9127. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9128. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9129. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9130. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9131. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9132. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9133. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9134. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9135. var bedCostTotal float64 = 0 //床位总费
  9136. var bedCostSelfTotal float64 = 0 //床位自费
  9137. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9138. var operationCostTotal float64 = 0 //手术费
  9139. var operationCostSelfTotal float64 = 0 //手术费
  9140. var operationCostPartSelfTotal float64 = 0 //手术费
  9141. var otherCostTotal float64 = 0 //其他费用
  9142. var otherCostSelfTotal float64 = 0 //其他费用
  9143. var otherCostPartSelfTotal float64 = 0 //其他费用
  9144. var materialCostTotal float64 = 0 //材料费
  9145. var materialCostSelfTotal float64 = 0 //材料费
  9146. var materialCostPartSelfTotal float64 = 0 //材料费
  9147. var westernMedicineCostTotal float64 = 0 //西药费
  9148. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9149. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9150. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9151. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9152. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9153. var checkCostTotal float64 = 0 //检查费
  9154. var checkCostSelfTotal float64 = 0 //检查费
  9155. var checkCostPartSelfTotal float64 = 0 //检查费
  9156. var hiliCostTotal float64 = 0 //护理费
  9157. var hiliCostSelfTotal float64 = 0 //护理费
  9158. var hiliCostPartSelfTotal float64 = 0 //护理费
  9159. var laboratoryCostTotal float64 = 0 //化验费
  9160. var laboratoryCostSelfTotal float64 = 0 //化验费
  9161. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9162. var treatCostTotal float64 = 0 //治疗费用
  9163. var treatCostSelfTotal float64 = 0 //治疗费用
  9164. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9165. var zhenChaCostTotal float64 = 0 //其他费用
  9166. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9167. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9168. decimal.DivisionPrecision = 2
  9169. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9170. var balanceAccountsType int64
  9171. if his.ID > 0 {
  9172. balanceAccountsType = his.BalanceAccountsType
  9173. } else {
  9174. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9175. }
  9176. if balanceAccountsType == 2 {
  9177. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9178. for _, item := range orderInfos_two {
  9179. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9180. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9181. item.MedChrgitmType = "09"
  9182. }
  9183. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9184. if item.HisPrescriptionProject.Type == 2 {
  9185. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9186. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9187. case 0:
  9188. item.MedChrgitmType = "0"
  9189. break
  9190. case 1:
  9191. item.MedChrgitmType = "14"
  9192. break
  9193. case 2:
  9194. item.MedChrgitmType = "05"
  9195. break
  9196. case 3:
  9197. item.MedChrgitmType = "03"
  9198. break
  9199. case 4:
  9200. item.MedChrgitmType = "03"
  9201. break
  9202. case 5:
  9203. item.MedChrgitmType = "08"
  9204. break
  9205. case 6:
  9206. item.MedChrgitmType = "14"
  9207. break
  9208. case 7:
  9209. item.MedChrgitmType = "14"
  9210. break
  9211. case 8:
  9212. item.MedChrgitmType = "03"
  9213. break
  9214. case 9:
  9215. item.MedChrgitmType = "14"
  9216. break
  9217. case 10:
  9218. item.MedChrgitmType = "14"
  9219. break
  9220. case 11:
  9221. item.MedChrgitmType = "06"
  9222. break
  9223. case 12:
  9224. item.MedChrgitmType = "12"
  9225. break
  9226. case 13:
  9227. item.MedChrgitmType = "01"
  9228. break
  9229. case 14:
  9230. item.MedChrgitmType = "04"
  9231. break
  9232. case 15:
  9233. item.MedChrgitmType = "02"
  9234. break
  9235. }
  9236. } else {
  9237. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9238. case 1:
  9239. item.MedChrgitmType = "14"
  9240. break
  9241. case 2:
  9242. item.MedChrgitmType = "05"
  9243. break
  9244. case 3:
  9245. item.MedChrgitmType = "04"
  9246. break
  9247. case 4:
  9248. item.MedChrgitmType = "03"
  9249. break
  9250. case 5:
  9251. item.MedChrgitmType = "08"
  9252. break
  9253. case 6:
  9254. item.MedChrgitmType = "14"
  9255. break
  9256. case 7:
  9257. item.MedChrgitmType = "14"
  9258. break
  9259. case 8:
  9260. item.MedChrgitmType = "03"
  9261. break
  9262. case 9:
  9263. item.MedChrgitmType = "14"
  9264. break
  9265. }
  9266. }
  9267. } else if item.HisPrescriptionProject.Type == 3 {
  9268. item.MedChrgitmType = "08"
  9269. }
  9270. }
  9271. }
  9272. for _, item := range orderInfos_two {
  9273. fmt.Println(item.MedChrgitmType)
  9274. if item.MedChrgitmType == "07" { //床位费
  9275. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9276. hiliCostSelfTotal = hiliCostTotal
  9277. }
  9278. if item.MedChrgitmType == "01" { //床位费
  9279. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9280. bedCostSelfTotal = bedCostTotal
  9281. }
  9282. if item.MedChrgitmType == "02" { //诊察费
  9283. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9284. zhenChaCostSelfTotal = zhenChaCostTotal
  9285. }
  9286. if item.MedChrgitmType == "03" { //检查费
  9287. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9288. checkCostSelfTotal = checkCostTotal
  9289. }
  9290. if item.MedChrgitmType == "04" { //化验费
  9291. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9292. laboratoryCostSelfTotal = laboratoryCostTotal
  9293. }
  9294. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9295. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9296. treatCostSelfTotal = treatCostTotal
  9297. }
  9298. if item.MedChrgitmType == "06" { //手术费
  9299. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9300. operationCostSelfTotal = treatCostTotal
  9301. }
  9302. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9303. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9304. materialCostSelfTotal = materialCostTotal
  9305. }
  9306. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9307. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9308. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9309. }
  9310. if item.MedChrgitmType == "11" { //中成费
  9311. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9312. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9313. }
  9314. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9315. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9316. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9317. otherCostSelfTotal = otherCostTotal
  9318. }
  9319. } else {
  9320. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9321. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9322. otherCostSelfTotal = otherCostTotal
  9323. }
  9324. }
  9325. }
  9326. } else {
  9327. for _, item := range orderInfos {
  9328. if item.MedChrgitmType == "01" { //床位费
  9329. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9330. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9331. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9332. }
  9333. if item.MedChrgitmType == "02" { //诊察费
  9334. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9335. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9336. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9337. }
  9338. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9339. if item.MedChrgitmType == "03" { //检查费
  9340. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9341. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9342. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9343. }
  9344. } else {
  9345. if item.MedChrgitmType == "03" { //检查费
  9346. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9347. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9348. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9349. }
  9350. }
  9351. if item.MedChrgitmType == "04" { //化验费
  9352. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9353. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9354. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9355. }
  9356. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9357. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9358. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9359. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9360. }
  9361. if item.MedChrgitmType == "06" { //手术费
  9362. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9363. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9364. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9365. }
  9366. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9367. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9368. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9369. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9370. }
  9371. if item.MedChrgitmType == "07" { //护理
  9372. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9373. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9374. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9375. }
  9376. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9377. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9378. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9379. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9380. }
  9381. if item.MedChrgitmType == "11" { //中成费
  9382. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9383. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9384. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9385. }
  9386. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9387. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9388. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9389. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9390. }
  9391. }
  9392. }
  9393. timeLayout := "2006-01-02"
  9394. loc, _ := time.LoadLocation("Local")
  9395. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9396. if err != nil {
  9397. }
  9398. startRecordDateTime := startTime.Unix()
  9399. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9400. if err != nil {
  9401. }
  9402. endRecordDateTime := endTime.Unix()
  9403. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9404. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9405. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9406. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9407. c.ServeSuccessJSON(map[string]interface{}{
  9408. "charge_admin_name": charge_admin.UserName,
  9409. "order_number": order.Number, //业务流水号
  9410. "id_card_no": his.IdCardNo, //社会保障号
  9411. "patient": patient,
  9412. "department_name": department.Name, //科室
  9413. "number": his.Number, //门诊号
  9414. "date": order.SettleAccountsDate, //结算日期
  9415. "name": order.PsnName, //姓名
  9416. "gender": patient.Gender, //性别
  9417. "psn_cash_money": order.PsnCashPay, //个人支付
  9418. "pay_way": "门诊", //结算方式
  9419. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9420. "admin_user_name": admin.UserName, //收款员
  9421. "order": order,
  9422. "order_info": orderInfos_two,
  9423. "his": his,
  9424. "bedCostTotal": bedCostTotal,
  9425. "bedCostSelfTotal": bedCostSelfTotal,
  9426. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9427. "operationCostTotal": operationCostTotal,
  9428. "operationCostSelfTotal": operationCostSelfTotal,
  9429. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9430. "otherCostTotal": otherCostTotal,
  9431. "otherCostSelfTotal": otherCostSelfTotal,
  9432. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9433. "materialCostTotal": materialCostTotal,
  9434. "materialCostSelfTotal": materialCostSelfTotal,
  9435. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9436. "westernMedicineCostTotal": westernMedicineCostTotal,
  9437. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9438. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9439. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9440. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9441. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9442. "checkCostTotal": checkCostTotal,
  9443. "checkCostSelfTotal": checkCostSelfTotal,
  9444. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9445. "laboratoryCostTotal": laboratoryCostTotal,
  9446. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9447. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9448. "treatCostTotal": treatCostTotal,
  9449. "treatCostSelfTotal": treatCostSelfTotal,
  9450. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9451. "zhenChaCostTotal": zhenChaCostTotal,
  9452. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9453. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9454. "his_hospital_record": his_hospital_record,
  9455. "pre_pay_money": pre_pay_money,
  9456. "refund_sum": sum,
  9457. "doctor_info": doctor_info,
  9458. "hiliCostTotal": hiliCostTotal,
  9459. "hiliCostSelfTotal": hiliCostSelfTotal,
  9460. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9461. })
  9462. }
  9463. //func (c *HisApiController) GetFaPiaoDatas() {
  9464. // order_ids := c.GetString("order_ids")
  9465. // patient_id, _ := c.GetInt64("patient_id")
  9466. // adminUser := c.GetAdminUserInfo()
  9467. //
  9468. // orders := strings.Split(order_ids, ",")
  9469. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9470. //
  9471. // for _, item := range orders {
  9472. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9473. // order, _ := service.GetHisOrderByID(order_id)
  9474. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9475. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9476. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9477. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9478. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9479. //
  9480. // }
  9481. //
  9482. // var bedCostTotal float64 = 0 //床位总费
  9483. // var bedCostSelfTotal float64 = 0 //床位自费
  9484. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9485. //
  9486. // var operationCostTotal float64 = 0 //手术费
  9487. // var operationCostSelfTotal float64 = 0 //手术费
  9488. // var operationCostPartSelfTotal float64 = 0 //手术费
  9489. //
  9490. // var otherCostTotal float64 = 0 //其他费用
  9491. // var otherCostSelfTotal float64 = 0 //其他费用
  9492. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9493. //
  9494. // var materialCostTotal float64 = 0 //材料费
  9495. // var materialCostSelfTotal float64 = 0 //材料费
  9496. // var materialCostPartSelfTotal float64 = 0 //材料费
  9497. //
  9498. // var westernMedicineCostTotal float64 = 0 //西药费
  9499. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9500. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9501. //
  9502. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9503. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9504. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9505. //
  9506. // var checkCostTotal float64 = 0 //检查费
  9507. // var checkCostSelfTotal float64 = 0 //检查费
  9508. // var checkCostPartSelfTotal float64 = 0 //检查费
  9509. //
  9510. // var laboratoryCostTotal float64 = 0 //化验费
  9511. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9512. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9513. //
  9514. // var treatCostTotal float64 = 0 //治疗费用
  9515. // var treatCostSelfTotal float64 = 0 //治疗费用
  9516. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9517. //
  9518. // var zhenChaCostTotal float64 = 0 //其他费用
  9519. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9520. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9521. //
  9522. // decimal.DivisionPrecision = 2
  9523. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9524. //
  9525. // var balanceAccountsType int64
  9526. // if his.ID > 0 {
  9527. // balanceAccountsType = his.BalanceAccountsType
  9528. // } else {
  9529. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9530. // }
  9531. // if balanceAccountsType == 2 {
  9532. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9533. // for _, item := range orderInfos_two {
  9534. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9535. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9536. // item.MedChrgitmType = "09"
  9537. // }
  9538. //
  9539. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9540. // if item.HisPrescriptionProject.Type == 2 {
  9541. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9542. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9543. // case 0:
  9544. // item.MedChrgitmType = "0"
  9545. // break
  9546. // case 1:
  9547. // item.MedChrgitmType = "14"
  9548. // break
  9549. // case 2:
  9550. // item.MedChrgitmType = "05"
  9551. //
  9552. // break
  9553. // case 3:
  9554. // item.MedChrgitmType = "03"
  9555. //
  9556. // break
  9557. // case 4:
  9558. // item.MedChrgitmType = "03"
  9559. //
  9560. // break
  9561. // case 5:
  9562. // item.MedChrgitmType = "08"
  9563. //
  9564. // break
  9565. // case 6:
  9566. // item.MedChrgitmType = "14"
  9567. //
  9568. // break
  9569. // case 7:
  9570. // item.MedChrgitmType = "14"
  9571. //
  9572. // break
  9573. // case 8:
  9574. // item.MedChrgitmType = "03"
  9575. // break
  9576. // case 9:
  9577. // item.MedChrgitmType = "14"
  9578. // break
  9579. // case 10:
  9580. // item.MedChrgitmType = "14"
  9581. // break
  9582. // case 11:
  9583. // item.MedChrgitmType = "06"
  9584. // break
  9585. // case 12:
  9586. // item.MedChrgitmType = "12"
  9587. // break
  9588. // case 13:
  9589. // item.MedChrgitmType = "01"
  9590. // break
  9591. // case 14:
  9592. // item.MedChrgitmType = "04"
  9593. // break
  9594. // case 15:
  9595. // item.MedChrgitmType = "02"
  9596. // break
  9597. //
  9598. // }
  9599. //
  9600. // } else {
  9601. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9602. //
  9603. // case 1:
  9604. // item.MedChrgitmType = "14"
  9605. // break
  9606. // case 2:
  9607. // item.MedChrgitmType = "05"
  9608. //
  9609. // break
  9610. // case 3:
  9611. // item.MedChrgitmType = "03"
  9612. //
  9613. // break
  9614. // case 4:
  9615. // item.MedChrgitmType = "03"
  9616. //
  9617. // break
  9618. // case 5:
  9619. // item.MedChrgitmType = "08"
  9620. //
  9621. // break
  9622. // case 6:
  9623. // item.MedChrgitmType = "14"
  9624. //
  9625. // break
  9626. // case 7:
  9627. // item.MedChrgitmType = "14"
  9628. //
  9629. // break
  9630. // case 8:
  9631. // item.MedChrgitmType = "03"
  9632. // break
  9633. // case 9:
  9634. // item.MedChrgitmType = "14"
  9635. // break
  9636. //
  9637. // }
  9638. //
  9639. // }
  9640. //
  9641. // } else if item.HisPrescriptionProject.Type == 3 {
  9642. // item.MedChrgitmType = "08"
  9643. // }
  9644. // }
  9645. // }
  9646. //
  9647. // for _, item := range orderInfos_two {
  9648. // fmt.Println(item.MedChrgitmType)
  9649. // if item.MedChrgitmType == "01" { //床位费
  9650. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9651. // bedCostSelfTotal = bedCostTotal
  9652. // }
  9653. //
  9654. // if item.MedChrgitmType == "02" { //诊察费
  9655. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9656. // zhenChaCostSelfTotal = zhenChaCostTotal
  9657. // }
  9658. //
  9659. // if item.MedChrgitmType == "03" { //检查费
  9660. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9661. // checkCostSelfTotal = checkCostTotal
  9662. // }
  9663. //
  9664. // if item.MedChrgitmType == "04" { //化验费
  9665. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9666. // laboratoryCostSelfTotal = laboratoryCostTotal
  9667. // }
  9668. //
  9669. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9670. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9671. // treatCostSelfTotal = treatCostTotal
  9672. // }
  9673. //
  9674. // if item.MedChrgitmType == "06" { //手术费
  9675. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9676. // operationCostSelfTotal = treatCostTotal
  9677. // }
  9678. //
  9679. // if item.MedChrgitmType == "08" { //材料费
  9680. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9681. // materialCostSelfTotal = materialCostTotal
  9682. // }
  9683. //
  9684. // if item.MedChrgitmType == "09" { //西药费
  9685. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9686. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9687. // }
  9688. //
  9689. // if item.MedChrgitmType == "11" { //中成费
  9690. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9691. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9692. // }
  9693. //
  9694. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9695. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9696. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9697. // otherCostSelfTotal = otherCostTotal
  9698. // }
  9699. // } else {
  9700. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9701. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9702. // otherCostSelfTotal = otherCostTotal
  9703. // }
  9704. //
  9705. // }
  9706. //
  9707. // }
  9708. //
  9709. // } else {
  9710. // for _, item := range orderInfos {
  9711. // if item.MedChrgitmType == "01" { //床位费
  9712. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9713. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9714. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9715. // }
  9716. //
  9717. // if item.MedChrgitmType == "02" { //诊察费
  9718. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9720. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9721. // }
  9722. //
  9723. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9724. // if item.MedChrgitmType == "03" { //检查费
  9725. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9726. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9727. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9728. //
  9729. // }
  9730. // } else {
  9731. // if item.MedChrgitmType == "03" { //检查费
  9732. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9733. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9734. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9735. // }
  9736. //
  9737. // }
  9738. //
  9739. // if item.MedChrgitmType == "04" { //化验费
  9740. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9741. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9742. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9743. //
  9744. // }
  9745. //
  9746. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9747. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9748. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9749. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9750. //
  9751. // }
  9752. //
  9753. // if item.MedChrgitmType == "06" { //手术费
  9754. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9755. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9756. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9757. // }
  9758. //
  9759. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9760. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9761. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9762. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9763. // }
  9764. //
  9765. // if item.MedChrgitmType == "09" { //西药费
  9766. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9767. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9768. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9769. // }
  9770. //
  9771. // if item.MedChrgitmType == "11" { //中成费
  9772. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9773. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9774. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9775. // }
  9776. //
  9777. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9778. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9779. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9780. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9781. // }
  9782. //
  9783. // }
  9784. // }
  9785. // timeLayout := "2006-01-02"
  9786. // loc, _ := time.LoadLocation("Local")
  9787. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9788. // if err != nil {
  9789. // }
  9790. // startRecordDateTime := startTime.Unix()
  9791. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9792. // if err != nil {
  9793. // }
  9794. // endRecordDateTime := endTime.Unix()
  9795. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9796. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9797. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9798. //
  9799. // c.ServeSuccessJSON(map[string]interface{}{
  9800. // "order_number": order.Number, //业务流水号
  9801. // "id_card_no": his.IdCardNo, //社会保障号
  9802. // "department_name": department.Name, //科室
  9803. // "number": his.Number, //门诊号
  9804. // "date": order.SettleAccountsDate, //结算日期
  9805. // "name": order.PsnName, //姓名
  9806. // "gender": patient.Gender, //性别
  9807. // "psn_cash_money": order.PsnCashPay, //个人支付
  9808. // "pay_way": "门诊", //结算方式
  9809. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9810. // "admin_user_name": admin.UserName, //收款员
  9811. // "order": order,
  9812. // "order_info": orderInfos_two,
  9813. // "his": his,
  9814. // "bedCostTotal": bedCostTotal,
  9815. // "bedCostSelfTotal": bedCostSelfTotal,
  9816. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9817. // "operationCostTotal": operationCostTotal,
  9818. // "operationCostSelfTotal": operationCostSelfTotal,
  9819. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9820. // "otherCostTotal": otherCostTotal,
  9821. // "otherCostSelfTotal": otherCostSelfTotal,
  9822. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9823. // "materialCostTotal": materialCostTotal,
  9824. // "materialCostSelfTotal": materialCostSelfTotal,
  9825. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9826. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9827. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9828. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9829. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9830. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9831. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9832. // "checkCostTotal": checkCostTotal,
  9833. // "checkCostSelfTotal": checkCostSelfTotal,
  9834. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9835. // "laboratoryCostTotal": laboratoryCostTotal,
  9836. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9837. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9838. // "treatCostTotal": treatCostTotal,
  9839. // "treatCostSelfTotal": treatCostSelfTotal,
  9840. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9841. // "zhenChaCostTotal": zhenChaCostTotal,
  9842. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9843. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9844. // "his_hospital_record": his_hospital_record,
  9845. // "pre_pay_money": pre_pay_money,
  9846. // "refund_sum": sum,
  9847. // })
  9848. //
  9849. //}
  9850. func (this *HisApiController) GetIncomeStatisticsData() {
  9851. start_time := this.GetString("start_time")
  9852. end_time := this.GetString("end_time")
  9853. key_words := this.GetString("key_words")
  9854. limit, _ := this.GetInt64("limit")
  9855. page, _ := this.GetInt64("page")
  9856. if page <= 0 {
  9857. page = 1
  9858. }
  9859. if limit <= 0 {
  9860. limit = 10
  9861. }
  9862. statistics_type, _ := this.GetInt64("statistics_type")
  9863. admin := this.GetAdminUserInfo()
  9864. timeLayout := "2006-01-02"
  9865. loc, _ := time.LoadLocation("Local")
  9866. var theStartTIme int64
  9867. if len(start_time) > 0 {
  9868. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9869. if err != nil {
  9870. theStartTIme = 0
  9871. }
  9872. theStartTIme = theTime.Unix()
  9873. }
  9874. var theEndtTIme int64
  9875. if len(end_time) > 0 {
  9876. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9877. if err != nil {
  9878. theEndtTIme = 0
  9879. }
  9880. theEndtTIme = theTime.Unix()
  9881. }
  9882. if statistics_type == 1 {
  9883. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9884. this.ServeSuccessJSON(map[string]interface{}{
  9885. "list": list,
  9886. "total": total,
  9887. })
  9888. } else {
  9889. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9890. this.ServeSuccessJSON(map[string]interface{}{
  9891. "list": list,
  9892. "total": total,
  9893. })
  9894. }
  9895. }
  9896. func (c *HisApiController) PostProjectInformation() {
  9897. adminUser := c.GetAdminUserInfo()
  9898. orgId := adminUser.CurrentOrgId
  9899. dataBody := make(map[string]interface{}, 0)
  9900. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9901. if err != nil {
  9902. utils.ErrorLog(err.Error())
  9903. return
  9904. }
  9905. utils.ErrorLog("%v", dataBody)
  9906. var projectList []*models.HisProject
  9907. var total_goods []interface{}
  9908. tempProjects := dataBody["projects"].([]interface{})
  9909. total_goods = tempProjects
  9910. for index, projectMap := range tempProjects {
  9911. projectM := projectMap.(map[string]interface{})
  9912. var project models.HisProject
  9913. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9914. utils.ErrorLog("project_name")
  9915. return
  9916. }
  9917. project_name, _ := projectM["project_name"].(string)
  9918. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9919. err_log := models.ExportErrLog{
  9920. LogType: 6,
  9921. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9922. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9923. Status: 1,
  9924. CreateTime: time.Now().Unix(),
  9925. UpdateTime: time.Now().Unix(),
  9926. ExportTime: time.Now().Unix(),
  9927. }
  9928. service.CreateExportErrLog(&err_log)
  9929. continue
  9930. }
  9931. project.ProjectName = project_name
  9932. prices := projectM["price"].(string)
  9933. price, _ := strconv.ParseFloat(prices, 64)
  9934. if price <= 0 { //名字为空则生成一条导入错误日志
  9935. err_log := models.ExportErrLog{
  9936. LogType: 6,
  9937. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9938. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  9939. Status: 1,
  9940. CreateTime: time.Now().Unix(),
  9941. UpdateTime: time.Now().Unix(),
  9942. ExportTime: time.Now().Unix(),
  9943. }
  9944. service.CreateExportErrLog(&err_log)
  9945. continue
  9946. }
  9947. project.Price = price
  9948. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  9949. utils.ErrorLog("unit_id")
  9950. return
  9951. }
  9952. unit := projectM["unit"].(string)
  9953. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  9954. err_log := models.ExportErrLog{
  9955. LogType: 6,
  9956. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9957. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  9958. Status: 1,
  9959. CreateTime: time.Now().Unix(),
  9960. UpdateTime: time.Now().Unix(),
  9961. ExportTime: time.Now().Unix(),
  9962. }
  9963. service.CreateExportErrLog(&err_log)
  9964. continue
  9965. }
  9966. project.Unit = unit
  9967. cost_classify := projectM["cost_classify"].(string)
  9968. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  9969. err_log := models.ExportErrLog{
  9970. LogType: 6,
  9971. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9972. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9973. Status: 1,
  9974. CreateTime: time.Now().Unix(),
  9975. UpdateTime: time.Now().Unix(),
  9976. ExportTime: time.Now().Unix(),
  9977. }
  9978. service.CreateExportErrLog(&err_log)
  9979. continue
  9980. }
  9981. var costClassify = "费用类别"
  9982. var cost_classify_id int64
  9983. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  9984. if len(cost_classify) != 0 {
  9985. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  9986. if errcode == gorm.ErrRecordNotFound {
  9987. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  9988. dataconfig := models.DictDataconfig{
  9989. ParentId: costClassifyConfig.ID,
  9990. Module: "system",
  9991. OrgId: orgId,
  9992. Name: cost_classify,
  9993. FieldName: "",
  9994. Value: costConfig.Value + 1,
  9995. CreatedTime: "",
  9996. UpdatedTime: "",
  9997. CreateUserId: adminUser.AdminUser.Id,
  9998. Status: 1,
  9999. Remark: "",
  10000. DeleteIdSystem: 0,
  10001. Title: "",
  10002. Content: "",
  10003. Order: 0,
  10004. Code: "",
  10005. }
  10006. service.CreatedDicConfig(&dataconfig)
  10007. }
  10008. }
  10009. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10010. for _, it := range costClassList {
  10011. if cost_classify == it.Name {
  10012. cost_classify_id = int64(it.Value)
  10013. }
  10014. }
  10015. project.CostClassify = cost_classify_id
  10016. executive_section := projectM["executive_section"].(string)
  10017. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10018. err_log := models.ExportErrLog{
  10019. LogType: 6,
  10020. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10021. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10022. Status: 1,
  10023. CreateTime: time.Now().Unix(),
  10024. UpdateTime: time.Now().Unix(),
  10025. ExportTime: time.Now().Unix(),
  10026. }
  10027. service.CreateExportErrLog(&err_log)
  10028. continue
  10029. }
  10030. if len(executive_section) != 0 {
  10031. //查找科室是否有内容
  10032. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10033. if errcodedepart == gorm.ErrRecordNotFound {
  10034. department := models.XtHisDepartment{
  10035. Name: executive_section,
  10036. Status: 1,
  10037. UserOrgId: adminUser.CurrentOrgId,
  10038. CreatedTime: time.Now().Unix(),
  10039. }
  10040. service.CreateDePartment(&department)
  10041. }
  10042. }
  10043. var executive_section_id int64
  10044. departMentList, _ := service.GetAllDepartMent(orgId)
  10045. for _, it := range departMentList {
  10046. if executive_section == it.Name {
  10047. executive_section_id = it.ID
  10048. }
  10049. }
  10050. project.ExecutiveSection = executive_section_id
  10051. medical_coverage := projectM["medical_coverage"].(string)
  10052. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10053. err_log := models.ExportErrLog{
  10054. LogType: 6,
  10055. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10056. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10057. Status: 1,
  10058. CreateTime: time.Now().Unix(),
  10059. UpdateTime: time.Now().Unix(),
  10060. ExportTime: time.Now().Unix(),
  10061. }
  10062. service.CreateExportErrLog(&err_log)
  10063. continue
  10064. }
  10065. var medicalCoverage = "医保等级"
  10066. var medical_coverage_id int64
  10067. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10068. if len(medical_coverage) != 0 {
  10069. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10070. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10071. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10072. dataconfig := models.DictDataconfig{
  10073. ParentId: medicalCoverageConfig.ID,
  10074. Module: "system",
  10075. OrgId: orgId,
  10076. Name: medical_coverage,
  10077. FieldName: "",
  10078. Value: medicalCoverageConfig.Value + 1,
  10079. CreatedTime: "",
  10080. UpdatedTime: "",
  10081. CreateUserId: adminUser.AdminUser.Id,
  10082. Status: 1,
  10083. Remark: "",
  10084. DeleteIdSystem: 0,
  10085. Title: "",
  10086. Content: "",
  10087. Order: 0,
  10088. Code: "",
  10089. }
  10090. service.CreatedDicConfig(&dataconfig)
  10091. }
  10092. }
  10093. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10094. for _, it := range medicalCoverageList {
  10095. if medical_coverage == it.Name {
  10096. medical_coverage_id = int64(it.Value)
  10097. }
  10098. }
  10099. project.MedicalCoverage = medical_coverage_id
  10100. pinyin := projectM["pinyin"].(string)
  10101. project.Pinyin = pinyin
  10102. wubi := projectM["wubi"].(string)
  10103. project.Wubi = wubi
  10104. statistical_classification := projectM["statistical_classification"].(string)
  10105. var statisticalClassification = "统计分类"
  10106. var statistical_classification_id int64
  10107. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10108. if len(statistical_classification) != 0 {
  10109. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10110. if classificationerrcodes == gorm.ErrRecordNotFound {
  10111. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10112. dataconfig := models.DictDataconfig{
  10113. ParentId: classiFication.ID,
  10114. Module: "system",
  10115. OrgId: orgId,
  10116. Name: statistical_classification,
  10117. FieldName: "",
  10118. Value: classiFicationConfig.Value + 1,
  10119. CreatedTime: "",
  10120. UpdatedTime: "",
  10121. CreateUserId: adminUser.AdminUser.Id,
  10122. Status: 1,
  10123. Remark: "",
  10124. DeleteIdSystem: 0,
  10125. Title: "",
  10126. Content: "",
  10127. Order: 0,
  10128. Code: "",
  10129. }
  10130. service.CreatedDicConfig(&dataconfig)
  10131. }
  10132. }
  10133. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10134. for _, it := range classiFicationList {
  10135. if statistical_classification == it.Name {
  10136. statistical_classification_id = int64(it.Value)
  10137. }
  10138. }
  10139. project.StatisticalClassification = statistical_classification_id
  10140. disease_directory := int64(projectM["disease_directory"].(float64))
  10141. project.DiseaseDirectory = disease_directory
  10142. is_record := int64(projectM["is_record"].(float64))
  10143. project.IsRecord = is_record
  10144. medical_code := projectM["medical_code"].(string)
  10145. project.MedicalCode = medical_code
  10146. tube_color := projectM["tube_color"].(string)
  10147. var tubeColor = "试管颜色"
  10148. var tube_color_id int64
  10149. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10150. if len(tube_color) != 0 {
  10151. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10152. if errcodetube == gorm.ErrRecordNotFound {
  10153. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10154. dataconfig := models.DictDataconfig{
  10155. ParentId: tubeColorConfig.ID,
  10156. Module: "system",
  10157. OrgId: orgId,
  10158. Name: tube_color,
  10159. FieldName: "",
  10160. Value: tubeConfig.Value + 1,
  10161. CreatedTime: "",
  10162. UpdatedTime: "",
  10163. CreateUserId: adminUser.AdminUser.Id,
  10164. Status: 1,
  10165. Remark: "",
  10166. DeleteIdSystem: 0,
  10167. Title: "",
  10168. Content: "",
  10169. Order: 0,
  10170. Code: "",
  10171. }
  10172. service.CreatedDicConfig(&dataconfig)
  10173. }
  10174. }
  10175. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10176. for _, it := range tubeColorList {
  10177. if tube_color == it.Name {
  10178. tube_color_id = int64(it.Value)
  10179. }
  10180. }
  10181. project.TubeColor = tube_color_id
  10182. single_dose := projectM["single_dose"].(string)
  10183. project.SingleDose = single_dose
  10184. execution_frequency := projectM["execution_frequency"].(string)
  10185. project.ExecutionFrequency = execution_frequency
  10186. delivery_way := projectM["delivery_way"].(string)
  10187. project.DeliveryWay = delivery_way
  10188. number_days := projectM["number_days"].(string)
  10189. project.NumberDays = number_days
  10190. total := projectM["total"].(string)
  10191. project.Total = total
  10192. medical_status := int64(projectM["medical_status"].(float64))
  10193. project.MedicalStatus = medical_status
  10194. category := int64(projectM["category"].(float64))
  10195. project.Category = category
  10196. specail_project := int64(projectM["specail_project"].(float64))
  10197. project.SpecailProject = specail_project
  10198. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10199. project.SocialSecurityDirectoryCode = social_security_directory_code
  10200. remark := projectM["remark"].(string)
  10201. project.Remark = remark
  10202. record_date := projectM["record_date"].(string)
  10203. timeLayout := "2006-01-02"
  10204. loc, _ := time.LoadLocation("Local")
  10205. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10206. project.RecordDate = theTime.Unix()
  10207. projectList = append(projectList, &project)
  10208. }
  10209. export_time := time.Now().Unix()
  10210. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10211. if len(projectList) > 0 {
  10212. for _, item := range projectList {
  10213. hans := item.ProjectName // 要转换的汉字字符串
  10214. // 创建一个拼音转换器
  10215. p := pinyin.NewArgs()
  10216. // 将汉字转为拼音
  10217. pinyinSlice := pinyin.Pinyin(hans, p)
  10218. // 输出拼音
  10219. fmt.Println("Pinyin:", pinyinSlice)
  10220. // 获取首字母
  10221. firstLetter := ""
  10222. for _, py := range pinyinSlice {
  10223. if len(py) > 0 {
  10224. firstLetter += string(py[0][0])
  10225. }
  10226. }
  10227. item.FirstLetter = firstLetter
  10228. project := models.HisProject{
  10229. ProjectName: item.ProjectName,
  10230. Price: item.Price,
  10231. Unit: item.Unit,
  10232. CostClassify: item.CostClassify,
  10233. ExecutiveSection: item.ExecutiveSection,
  10234. MedicalCoverage: item.MedicalCoverage,
  10235. UserOrgId: orgId,
  10236. Status: 1,
  10237. CreatedTime: time.Now().Unix(),
  10238. Pinyin: item.Pinyin,
  10239. Wubi: item.Wubi,
  10240. StatisticalClassification: item.StatisticalClassification,
  10241. DiseaseDirectory: item.DiseaseDirectory,
  10242. IsRecord: item.IsRecord,
  10243. MedicalCode: item.MedicalCode,
  10244. TubeColor: item.TubeColor,
  10245. SingleDose: item.SingleDose,
  10246. DeliveryWay: item.DeliveryWay,
  10247. NumberDays: item.NumberDays,
  10248. Total: item.Total,
  10249. Category: item.Category,
  10250. MedicalStatus: item.MedicalStatus,
  10251. SpecailProject: item.SpecailProject,
  10252. RecordDate: item.RecordDate,
  10253. Remark: item.Remark,
  10254. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10255. ExecutionFrequency: item.ExecutionFrequency,
  10256. FirstLetter: item.FirstLetter,
  10257. }
  10258. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10259. if errcodeproject == gorm.ErrRecordNotFound {
  10260. service.CreateProjectInfomation(&project)
  10261. } else if errcodeproject == nil {
  10262. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10263. }
  10264. log := models.ExportLog{
  10265. LogType: 6,
  10266. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10267. TotalNum: int64(len(total_goods)),
  10268. FailNum: int64(len(errLogs)),
  10269. SuccessNum: int64(len(projectList)),
  10270. CreateTime: time.Now().Unix(),
  10271. UpdateTime: time.Now().Unix(),
  10272. ExportTime: export_time,
  10273. Status: 1,
  10274. }
  10275. service.CreateExportLog(&log)
  10276. c.ServeSuccessJSON(map[string]interface{}{
  10277. "msg": "导入成功",
  10278. "total_num": len(total_goods),
  10279. "success_num": len(projectList),
  10280. "fail_num": int64(len(errLogs)),
  10281. })
  10282. }
  10283. } else {
  10284. log := models.ExportLog{
  10285. LogType: 6,
  10286. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10287. TotalNum: int64(len(total_goods)),
  10288. FailNum: int64(len(errLogs)),
  10289. SuccessNum: int64(len(projectList)),
  10290. CreateTime: time.Now().Unix(),
  10291. UpdateTime: time.Now().Unix(),
  10292. ExportTime: export_time,
  10293. Status: 1,
  10294. }
  10295. service.CreateExportLog(&log)
  10296. c.ServeSuccessJSON(map[string]interface{}{
  10297. "msg": "导入成功",
  10298. "total_num": len(total_goods),
  10299. "success_num": len(projectList),
  10300. "fail_num": int64(len(errLogs)),
  10301. })
  10302. }
  10303. }
  10304. //func (this *HisApiController) EditProjectInformation(){
  10305. //
  10306. // id, _ := this.GetInt64("id")
  10307. // project_team := this.GetString("project_team")
  10308. // price := this.GetString("price")
  10309. // price_float, _ := strconv.ParseFloat(price, 64)
  10310. // pinyin := this.GetString("pinyin")
  10311. // wubi := this.GetString("wubi")
  10312. // tube_color, _ := this.GetInt64("tube_color")
  10313. // team_type, _ := this.GetInt64("team_type")
  10314. // remark := this.GetString("remark")
  10315. // ids := this.GetString("ids")
  10316. // item_id := this.GetString("item_id")
  10317. // projectTeam := models.XtHisProjectTeam{
  10318. // ProjectTeam: project_team,
  10319. // Price: price_float,
  10320. // Pinyin: pinyin,
  10321. // Wubi: wubi,
  10322. // TubeColor: tube_color,
  10323. // TeamType: team_type,
  10324. // Remark: remark,
  10325. // ProjectId: ids,
  10326. // ItemId: item_id,
  10327. // }
  10328. //
  10329. //
  10330. // dataBody := make(map[string]interface{}, 0)
  10331. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10332. // if err != nil {
  10333. // utils.ErrorLog(err.Error())
  10334. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10335. // return
  10336. // }
  10337. //
  10338. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10339. //
  10340. //
  10341. // if err != nil {
  10342. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10343. // return
  10344. // }
  10345. //
  10346. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10347. // infos, _ := dataBody["info"].([]interface{})
  10348. // if len(infos) > 0 {
  10349. // var ids []string
  10350. //
  10351. // for _, item := range infos {
  10352. // items := item.(map[string]interface{})
  10353. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10354. // utils.ErrorLog("id")
  10355. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10356. // return
  10357. // }
  10358. // id := int64(items["id"].(float64))
  10359. //
  10360. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10361. // utils.ErrorLog("type")
  10362. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10363. // return
  10364. // }
  10365. // types := int64(items["type"].(float64))
  10366. //
  10367. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10368. // utils.ErrorLog("number")
  10369. // }
  10370. //
  10371. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10372. //
  10373. // projectList := models.XtHisProjectList{
  10374. // Number: number,
  10375. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10376. // ProjectId: id,
  10377. // Status: 1,
  10378. // CreatedTime: time.Now().Unix(),
  10379. // UpdatedTime: time.Now().Unix(),
  10380. // TeamId: projectTeam.ID,
  10381. // Type: types,
  10382. // }
  10383. // list := projectList
  10384. //
  10385. // service.CreateProjectList(&list)
  10386. //
  10387. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10388. //
  10389. // }
  10390. // ids_str := strings.Join(ids, ",")
  10391. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10392. // service.SaveProjectTeam(&projectTeam)
  10393. // this.ServeSuccessJSON(map[string]interface{}{
  10394. // "projectTeam": projectTeam,
  10395. // })
  10396. // }
  10397. // }
  10398. //}
  10399. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10400. name := c.GetString("name")
  10401. mode_id, _ := c.GetInt64("mode", 0)
  10402. types, _ := c.GetInt64("type", 0)
  10403. patient_id, _ := c.GetInt64("patient_id", 0)
  10404. types = 1
  10405. adminInfo := c.GetAdminUserInfo()
  10406. template := &models.HisPrescriptionTemplate{
  10407. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10408. PatientId: patient_id,
  10409. Type: types,
  10410. Status: 1,
  10411. Ctime: time.Now().Unix(),
  10412. Mtime: time.Now().Unix(),
  10413. Name: name,
  10414. Mode: mode_id,
  10415. }
  10416. dataBody := make(map[string]interface{}, 0)
  10417. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10418. if err != nil {
  10419. utils.ErrorLog(err.Error())
  10420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10421. return
  10422. }
  10423. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10424. //如果已经存在记录则删除处方
  10425. if template_one.ID > 0 {
  10426. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10427. var ids []int64
  10428. var org_id int64
  10429. for _, item := range ps {
  10430. org_id = c.GetAdminUserInfo().CurrentOrgId
  10431. ids = append(ids, item.ID)
  10432. }
  10433. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10434. if err2 == nil {
  10435. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10436. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10437. if len(prescriptions) > 0 {
  10438. for _, item := range prescriptions {
  10439. items := item.(map[string]interface{})
  10440. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10441. utils.ErrorLog("type")
  10442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10443. return
  10444. }
  10445. types := int64(items["type"].(float64))
  10446. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10447. utils.ErrorLog("med_type")
  10448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10449. return
  10450. }
  10451. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10452. ctime := time.Now().Unix()
  10453. prescription := &models.HisPrescriptionInfoTemplate{
  10454. PatientId: patient_id,
  10455. UserOrgId: adminInfo.CurrentOrgId,
  10456. Ctime: ctime,
  10457. Mtime: ctime,
  10458. Type: types,
  10459. Modifier: adminInfo.AdminUser.Id,
  10460. Creator: adminInfo.AdminUser.Id,
  10461. Status: 1,
  10462. PTemplateId: template_one.ID,
  10463. MedType: med_type,
  10464. }
  10465. service.CreateHisPrescriptionInfoTemplate(prescription)
  10466. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10467. advices := items["advices"].([]interface{})
  10468. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10469. ctime := time.Now().Unix()
  10470. mtime := ctime
  10471. if len(advices) > 0 {
  10472. for _, advice := range advices {
  10473. var s models.HisPrescriptionAdviceTemplate
  10474. s.PrescriptionId = prescription.ID
  10475. s.AdviceType = 2
  10476. s.StopState = 2
  10477. s.ExecutionState = 2
  10478. s.Status = 1
  10479. s.UserOrgId = adminInfo.CurrentOrgId
  10480. s.CreatedTime = ctime
  10481. s.UpdatedTime = mtime
  10482. s.PatientId = patient_id
  10483. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10484. if errcode > 0 {
  10485. c.ServeFailJSONWithSGJErrorCode(errcode)
  10486. return
  10487. }
  10488. service.CreateHisPrescriptionAdviceTemplate(&s)
  10489. }
  10490. }
  10491. }
  10492. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10493. projects := items["project"].([]interface{})
  10494. if len(projects) > 0 {
  10495. for _, project := range projects {
  10496. var p models.HisPrescriptionProjectTemplate
  10497. p.PrescriptionId = prescription.ID
  10498. p.Ctime = time.Now().Unix()
  10499. p.Mtime = time.Now().Unix()
  10500. p.PatientId = patient_id
  10501. p.UserOrgId = adminInfo.CurrentOrgId
  10502. p.Status = 1
  10503. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10504. if errcode > 0 {
  10505. c.ServeFailJSONWithSGJErrorCode(errcode)
  10506. return
  10507. }
  10508. service.CreateHisPrescriptionProjectTemplate(&p)
  10509. }
  10510. }
  10511. }
  10512. }
  10513. c.ServeSuccessJSON(map[string]interface{}{
  10514. "msg": "创建成功",
  10515. })
  10516. }
  10517. }
  10518. } else {
  10519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10520. return
  10521. }
  10522. } else {
  10523. err3 := service.CreateHisPrescriptionTemplate(template)
  10524. if err3 == nil {
  10525. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10526. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10527. if len(prescriptions) > 0 {
  10528. for _, item := range prescriptions {
  10529. items := item.(map[string]interface{})
  10530. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10531. utils.ErrorLog("type")
  10532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10533. return
  10534. }
  10535. types := int64(items["type"].(float64))
  10536. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10537. utils.ErrorLog("med_type")
  10538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10539. return
  10540. }
  10541. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10542. ctime := time.Now().Unix()
  10543. prescription := &models.HisPrescriptionInfoTemplate{
  10544. PatientId: patient_id,
  10545. UserOrgId: adminInfo.CurrentOrgId,
  10546. Ctime: ctime,
  10547. Mtime: ctime,
  10548. Type: types,
  10549. Modifier: adminInfo.AdminUser.Id,
  10550. Creator: adminInfo.AdminUser.Id,
  10551. Status: 1,
  10552. PTemplateId: template.ID,
  10553. MedType: med_type,
  10554. }
  10555. service.CreateHisPrescriptionInfoTemplate(prescription)
  10556. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10557. advices := items["advices"].([]interface{})
  10558. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10559. ctime := time.Now().Unix()
  10560. mtime := ctime
  10561. if len(advices) > 0 {
  10562. for _, advice := range advices {
  10563. var s models.HisPrescriptionAdviceTemplate
  10564. s.PrescriptionId = prescription.ID
  10565. s.AdviceType = 2
  10566. s.StopState = 2
  10567. s.ExecutionState = 2
  10568. s.Status = 1
  10569. s.UserOrgId = adminInfo.CurrentOrgId
  10570. s.CreatedTime = ctime
  10571. s.UpdatedTime = mtime
  10572. s.PatientId = patient_id
  10573. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10574. if errcode > 0 {
  10575. c.ServeFailJSONWithSGJErrorCode(errcode)
  10576. return
  10577. }
  10578. service.CreateHisPrescriptionAdviceTemplate(&s)
  10579. }
  10580. }
  10581. }
  10582. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10583. projects := items["project"].([]interface{})
  10584. if len(projects) > 0 {
  10585. for _, project := range projects {
  10586. var p models.HisPrescriptionProjectTemplate
  10587. p.PrescriptionId = prescription.ID
  10588. p.Ctime = time.Now().Unix()
  10589. p.Mtime = time.Now().Unix()
  10590. p.PatientId = patient_id
  10591. p.UserOrgId = adminInfo.CurrentOrgId
  10592. p.Status = 1
  10593. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10594. if errcode > 0 {
  10595. c.ServeFailJSONWithSGJErrorCode(errcode)
  10596. return
  10597. }
  10598. service.CreateHisPrescriptionProjectTemplate(&p)
  10599. }
  10600. }
  10601. }
  10602. }
  10603. c.ServeSuccessJSON(map[string]interface{}{
  10604. "msg": "创建成功",
  10605. })
  10606. }
  10607. }
  10608. } else {
  10609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10610. return
  10611. }
  10612. }
  10613. }
  10614. func (c *HisApiController) PreSettle() {
  10615. id, _ := c.GetInt64("id")
  10616. record_time := c.GetString("record_time")
  10617. his_patient_id, _ := c.GetInt64("his_patient_id")
  10618. timeLayout := "2006-01-02"
  10619. loc, _ := time.LoadLocation("Local")
  10620. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10621. diagnosis_id := c.GetString("diagnosis")
  10622. sick_type, _ := c.GetInt64("sick_type")
  10623. reg_type, _ := c.GetInt64("p_type")
  10624. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10626. if err != nil {
  10627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10628. return
  10629. }
  10630. recordDateTime := theTime.Unix()
  10631. adminUser := c.GetAdminUserInfo()
  10632. var prescriptions []*models.HisPrescription
  10633. var start_time int64
  10634. var end_time int64
  10635. ids_str := c.GetString("ids")
  10636. ids_arr := strings.Split(ids_str, ",")
  10637. fmt.Println(reg_type)
  10638. if settle_accounts_type == 1 { //日结
  10639. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10640. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10641. } else {
  10642. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10643. }
  10644. fmt.Println(prescriptions)
  10645. } else { //月结
  10646. start_time_str := c.GetString("start_time")
  10647. end_time_str := c.GetString("end_time")
  10648. timeLayout := "2006-01-02"
  10649. loc, _ := time.LoadLocation("Local")
  10650. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10651. if err != nil {
  10652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10653. return
  10654. }
  10655. recordStartTime := theStartTime.Unix()
  10656. start_time = recordStartTime
  10657. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10658. if err != nil {
  10659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10660. return
  10661. }
  10662. recordEndTime := theEndTime.Unix()
  10663. end_time = recordEndTime
  10664. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10665. }
  10666. if reg_type == 1111 || reg_type == 1112 {
  10667. reg_type = 11
  10668. }
  10669. timestamp := time.Now().Unix()
  10670. tempTime := time.Unix(timestamp, 0)
  10671. timeFormat := tempTime.Format("20060102150405")
  10672. chrgBchno := rand.Intn(100000) + 10000
  10673. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10674. strconv.FormatInt(his.PatientId, 10)
  10675. var ids []int64
  10676. for _, item := range prescriptions {
  10677. ids = append(ids, item.ID)
  10678. }
  10679. fmt.Println(ids)
  10680. var total float64
  10681. for _, item := range prescriptions {
  10682. fmt.Println(item)
  10683. if item.Type == 1 { //药品
  10684. for _, subItem := range item.HisDoctorAdviceInfo {
  10685. total = total + (subItem.Price * subItem.PrescribingNumber)
  10686. }
  10687. }
  10688. if item.Type == 2 { //项目
  10689. for _, subItem := range item.HisPrescriptionProject {
  10690. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10691. total = total + (subItem.Price * cnt)
  10692. }
  10693. }
  10694. for _, subItem := range item.HisAdditionalCharge {
  10695. total = total + (subItem.Price * float64(subItem.Count))
  10696. }
  10697. }
  10698. allTotal := fmt.Sprintf("%.2f", total)
  10699. totals, _ := strconv.ParseFloat(allTotal, 64)
  10700. order := &models.HisOrder{
  10701. UserOrgId: adminUser.CurrentOrgId,
  10702. HisPatientId: his.ID,
  10703. PatientId: id,
  10704. SettleAccountsDate: recordDateTime,
  10705. Ctime: time.Now().Unix(),
  10706. Mtime: time.Now().Unix(),
  10707. Status: 1,
  10708. OrderStatus: 1,
  10709. MdtrtId: his.Number,
  10710. Number: chrg_bchno,
  10711. MedfeeSumamt: totals,
  10712. SettleEndTime: end_time,
  10713. SettleStartTime: start_time,
  10714. SettleType: settle_accounts_type,
  10715. PsnPartAmt: totals,
  10716. PsnCashPay: totals,
  10717. PType: 2,
  10718. IsPre: 1,
  10719. MedType: strconv.Itoa(int(reg_type)),
  10720. Diagnosis: diagnosis_id,
  10721. }
  10722. err = service.CreateOrder(order)
  10723. if err != nil {
  10724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10725. return
  10726. }
  10727. var customs []*Custom
  10728. for _, item := range prescriptions {
  10729. fmt.Println(item.Type)
  10730. if item.Type == 1 { //药品
  10731. for _, subItem := range item.HisDoctorAdviceInfo {
  10732. cus := &Custom{
  10733. AdviceId: subItem.ID,
  10734. ProjectId: 0,
  10735. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10736. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10737. FeedetlSn: subItem.FeedetlSn,
  10738. Price: fmt.Sprintf("%.2f", subItem.Price),
  10739. MedListCodg: subItem.MedListCodg,
  10740. Type: 1,
  10741. }
  10742. customs = append(customs, cus)
  10743. }
  10744. }
  10745. if item.Type == 2 { //项目
  10746. for _, subItem := range item.HisPrescriptionProject {
  10747. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10748. cus := &Custom{
  10749. AdviceId: 0,
  10750. ProjectId: subItem.ID,
  10751. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10752. Cut: fmt.Sprintf("%.2f", cnt),
  10753. FeedetlSn: subItem.FeedetlSn,
  10754. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10755. MedListCodg: subItem.MedListCodg,
  10756. Type: 2,
  10757. }
  10758. customs = append(customs, cus)
  10759. }
  10760. }
  10761. for _, item := range item.HisAdditionalCharge {
  10762. cus := &Custom{
  10763. ItemId: item.ID,
  10764. AdviceId: 0,
  10765. ProjectId: 0,
  10766. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10767. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10768. FeedetlSn: item.FeedetlSn,
  10769. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10770. MedListCodg: item.XtHisAddtionConfig.Code,
  10771. Type: 3,
  10772. }
  10773. customs = append(customs, cus)
  10774. }
  10775. }
  10776. fmt.Println(customs)
  10777. for _, item := range customs {
  10778. var advice_id int64 = 0
  10779. var project_id int64 = 0
  10780. var item_id int64 = 0
  10781. var types int64 = 0
  10782. if item.Type == 1 {
  10783. advice_id = item.AdviceId
  10784. project_id = 0
  10785. item_id = 0
  10786. } else if item.Type == 2 {
  10787. advice_id = 0
  10788. item_id = 0
  10789. project_id = item.ProjectId
  10790. } else if item.Type == 3 {
  10791. advice_id = 0
  10792. item_id = item.ItemId
  10793. project_id = 0
  10794. }
  10795. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10796. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10797. pric, _ := strconv.ParseFloat(item.Price, 32)
  10798. info := &models.HisOrderInfo{
  10799. OrderNumber: order.Number,
  10800. UploadDate: time.Now().Unix(),
  10801. AdviceId: advice_id,
  10802. DetItemFeeSumamt: detItemFeeSumamt,
  10803. Cnt: cut,
  10804. Pric: pric,
  10805. PatientId: id,
  10806. Status: 1,
  10807. Mtime: time.Now().Unix(),
  10808. Ctime: time.Now().Unix(),
  10809. UserOrgId: adminUser.CurrentOrgId,
  10810. HisPatientId: his.ID,
  10811. OrderId: order.ID,
  10812. ProjectId: project_id,
  10813. Type: types,
  10814. ItemId: item_id,
  10815. }
  10816. service.CreateOrderInfo(info)
  10817. }
  10818. his.SickType = sick_type
  10819. service.UpdataHisPateint(&his)
  10820. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10821. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10822. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10823. if err == nil {
  10824. c.ServeSuccessJSON(map[string]interface{}{
  10825. "msg": "结算成功",
  10826. })
  10827. }
  10828. }
  10829. type CustomOrderInfo struct {
  10830. Name string
  10831. Spec string
  10832. Unit string
  10833. Count float64
  10834. Price float64
  10835. Total float64
  10836. }
  10837. func (c *HisApiController) GetPrivateExpensesInfo() {
  10838. order_id, _ := c.GetInt64("id", 0)
  10839. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10840. order, _ := service.GetHisOrderByID(order_id)
  10841. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10842. if order.ID == 0 {
  10843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10844. return
  10845. }
  10846. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10847. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10848. org_id := c.GetAdminUserInfo().CurrentOrgId
  10849. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10850. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10851. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10852. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10853. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10854. //var orderInfos_four []*models.HisOrderInfoTwo
  10855. //for _, item := range orderInfos_three {
  10856. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10857. // item.HisPrescriptionProject.IsCheckTeam = 1
  10858. // orderInfos_four = append(orderInfos_four, item)
  10859. //
  10860. // }
  10861. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10862. // item.HisPrescriptionProject.IsCheckTeam = 2
  10863. // orderInfos_two = append(orderInfos_two, item)
  10864. // }
  10865. //}
  10866. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10867. //var cus_slice []CustomOrderInfo
  10868. //for _, item := range new_order_info {
  10869. // var cus CustomOrderInfo
  10870. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10871. // cus.Unit = ""
  10872. // cus.Spec = ""
  10873. // var total float64
  10874. // for _, subItem := range orderInfos_four {
  10875. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10876. // total = total + subItem.DetItemFeeSumamt
  10877. // fmt.Println(subItem.DetItemFeeSumamt)
  10878. // }
  10879. // }
  10880. // cus.Count = 1
  10881. // cus.Total = total
  10882. // cus_slice = append(cus_slice, cus)
  10883. //}
  10884. orderInfos = append(orderInfos, orderInfos_two...)
  10885. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10886. //orderInfos = append(orderInfos, orderInfos_three...)
  10887. //}/**/
  10888. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10889. c.ServeSuccessJSON(map[string]interface{}{
  10890. "order": order,
  10891. "order_info": orderInfos,
  10892. "patient": patient,
  10893. "admin_info": adminInfo,
  10894. "his": his,
  10895. "current_admin": role,
  10896. "org_config": miConfig,
  10897. //"new_order_info": cus_slice,
  10898. })
  10899. }
  10900. func (this *HisApiController) ChangeMedType() {
  10901. med_type := this.GetString("med_type")
  10902. old_med_type := this.GetString("old_med_type")
  10903. ids := this.GetString("ids")
  10904. settle_type, _ := this.GetInt64("settle_type")
  10905. start_time := this.GetString("start_time")
  10906. end_time := this.GetString("end_time")
  10907. ids_arr := strings.Split(ids, ",")
  10908. if settle_type == 1 { //日结
  10909. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10910. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10911. prescription.MedType = med_type
  10912. err := service.SaveHisPrescriptionTwo(&prescription)
  10913. if err == nil {
  10914. this.ServeSuccessJSON(map[string]interface{}{
  10915. "msg": "修改成功",
  10916. })
  10917. } else {
  10918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10919. return
  10920. }
  10921. } else if settle_type == 2 {
  10922. timeLayout := "2006-01-02"
  10923. loc, _ := time.LoadLocation("Local")
  10924. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10925. if err != nil {
  10926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10927. return
  10928. }
  10929. recordStartTime := theStartTime.Unix()
  10930. start_time_timestamp := recordStartTime
  10931. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10932. if err != nil {
  10933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10934. return
  10935. }
  10936. recordEndTime := theEndTime.Unix()
  10937. end_time_timestamp := recordEndTime
  10938. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10939. if updateErr == nil {
  10940. this.ServeSuccessJSON(map[string]interface{}{
  10941. "msg": "修改成功",
  10942. })
  10943. } else {
  10944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10945. return
  10946. }
  10947. }
  10948. }
  10949. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10950. patient_id, _ := c.GetInt64("patient_id")
  10951. his_patient_id, _ := c.GetInt64("his_patient_id")
  10952. record_date := c.GetString("record_date")
  10953. start_time := c.GetString("start_time")
  10954. end_time := c.GetString("end_time")
  10955. order_status, _ := c.GetInt64("type", 0)
  10956. p_type, _ := c.GetInt64("p_type", 0)
  10957. order_id, _ := c.GetInt64("order_id", 0)
  10958. timeLayout := "2006-01-02"
  10959. loc, _ := time.LoadLocation("Local")
  10960. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10961. if err != nil {
  10962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10963. return
  10964. }
  10965. recordDateTime := theTime.Unix()
  10966. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10967. if err != nil {
  10968. }
  10969. startRecordDateTime := startTime.Unix()
  10970. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10971. if err != nil {
  10972. }
  10973. endRecordDateTime := endTime.Unix()
  10974. admin := c.GetAdminUserInfo()
  10975. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10976. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10977. order, _ := service.GetHisOrderByID(order_id)
  10978. var monthPrescriptions []*models.HisPrescription
  10979. if order_status == 1 || order_status == 0 {
  10980. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10981. } else if order_status == 2 {
  10982. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10983. }
  10984. var settle_total float64
  10985. for _, item := range monthPrescriptions {
  10986. if len(item.HisPrescriptionProject) > 0 {
  10987. for _, subItem := range item.HisPrescriptionProject {
  10988. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10989. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10990. settle_total = settle_total + total
  10991. }
  10992. }
  10993. if len(item.HisDoctorAdviceInfo) > 0 {
  10994. for _, subItem := range item.HisDoctorAdviceInfo {
  10995. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10996. settle_total = settle_total + total
  10997. }
  10998. }
  10999. }
  11000. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11001. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11002. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11003. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11004. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11005. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11006. //获取所有科室信息
  11007. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11008. var dia string
  11009. for _, item := range month_p_info {
  11010. if len(dia) == 0 {
  11011. dia = item.Diagnosis
  11012. } else {
  11013. dia = dia + "," + item.Diagnosis
  11014. }
  11015. }
  11016. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11017. dia_arr = removeEmptyStrings(dia_arr)
  11018. c.ServeSuccessJSON(map[string]interface{}{
  11019. "his_info": his_patient_info,
  11020. "xt_info": xt_patient_info,
  11021. "case_history": case_history,
  11022. "info": patientPrescriptionInfo,
  11023. "last_info": lastPatientPrescriptionInfo,
  11024. "month_prescriptions": monthPrescriptions,
  11025. "order": order,
  11026. "doctors": doctors,
  11027. "department": department,
  11028. "settle_total": settle_total,
  11029. "dia_arr": dia_arr,
  11030. })
  11031. return
  11032. }
  11033. func removeEmptyStrings(input []string) []string {
  11034. var output []string
  11035. for _, s := range input {
  11036. if s != "" {
  11037. output = append(output, s)
  11038. }
  11039. }
  11040. return output
  11041. }
  11042. func removeDuplicates(input []string) []string {
  11043. seen := make(map[string]bool)
  11044. output := []string{}
  11045. for _, s := range input {
  11046. if _, exists := seen[s]; !exists {
  11047. seen[s] = true
  11048. output = append(output, s)
  11049. }
  11050. }
  11051. return output
  11052. }
  11053. func (c *HisApiController) GetHisMonthPatientInfo() {
  11054. patient_id, _ := c.GetInt64("patient_id")
  11055. his_patient_id, _ := c.GetInt64("his_patient_id")
  11056. record_date := c.GetString("record_date")
  11057. number := c.GetString("number")
  11058. start_time := c.GetString("start_time")
  11059. end_time := c.GetString("end_time")
  11060. p_type, _ := c.GetInt64("p_type")
  11061. timeLayout := "2006-01-02"
  11062. loc, _ := time.LoadLocation("Local")
  11063. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11064. if err != nil {
  11065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11066. return
  11067. }
  11068. recordDateTime := theTime.Unix()
  11069. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11070. if err != nil {
  11071. }
  11072. startRecordDateTime := startTime.Unix()
  11073. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11074. if err != nil {
  11075. }
  11076. endRecordDateTime := endTime.Unix()
  11077. admin := c.GetAdminUserInfo()
  11078. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11079. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11080. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11081. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11082. var settle_total float64
  11083. for _, item := range monthPrescriptions {
  11084. if len(item.HisPrescriptionProject) > 0 {
  11085. for _, subItem := range item.HisPrescriptionProject {
  11086. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11087. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11088. settle_total = settle_total + total
  11089. }
  11090. }
  11091. if len(item.HisDoctorAdviceInfo) > 0 {
  11092. for _, subItem := range item.HisDoctorAdviceInfo {
  11093. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11094. settle_total = settle_total + total
  11095. }
  11096. }
  11097. }
  11098. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11099. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11100. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11101. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11102. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11103. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11104. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11105. //获取所有科室信息
  11106. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11107. c.ServeSuccessJSON(map[string]interface{}{
  11108. "his_info": his_patient_info,
  11109. "xt_info": xt_patient_info,
  11110. "case_history": case_history,
  11111. "info": patientPrescriptionInfo,
  11112. "month_prescriptions": monthPrescriptions,
  11113. "order": order,
  11114. "doctors": doctors,
  11115. "department": department,
  11116. "count": count,
  11117. "drugStockConfig": drugStockConfig,
  11118. "last_info": lastPatientPrescriptionInfo,
  11119. "settle_total": settle_total,
  11120. })
  11121. return
  11122. }
  11123. func (c *HisApiController) GetAllOrder() {
  11124. org_id := c.GetAdminUserInfo().CurrentOrgId
  11125. orders, _ := service.GetNewHisOrderList(org_id)
  11126. c.ServeSuccessJSON(map[string]interface{}{
  11127. "order": orders,
  11128. })
  11129. return
  11130. }
  11131. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11132. newArr = make([]*models.HisOrderInfoTwo, 0)
  11133. for i := 0; i < len(arr); i++ {
  11134. repeat := false
  11135. for j := i + 1; j < len(arr); j++ {
  11136. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11137. repeat = true
  11138. break
  11139. }
  11140. }
  11141. if !repeat {
  11142. newArr = append(newArr, arr[i])
  11143. }
  11144. }
  11145. return
  11146. }
  11147. // 修改处方退库操作 参数传修改之前的处方数据
  11148. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11149. if advice.ExecutionState == 1 {
  11150. //查询该病人该药品是否有库存记录
  11151. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11152. if errcode == gorm.ErrRecordNotFound {
  11153. } else {
  11154. //退库
  11155. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11156. if advice.PrescribingNumberUnit == drug.MinUnit {
  11157. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11158. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11159. //退库
  11160. warehouseInfo := models.DrugWarehouseInfo{
  11161. StockMinNumber: prescribingNumber,
  11162. }
  11163. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11164. operation_time := time.Now().Unix()
  11165. creater := advice.AdviceDoctor
  11166. ctime := time.Now().Unix()
  11167. timeStr := time.Now().Format("2006-01-02")
  11168. timeArr := strings.Split(timeStr, "-")
  11169. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11170. total = total + 1
  11171. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11172. cancelStock := models.DrugCancelStock{
  11173. OrderNumber: orderNumber,
  11174. OperaTime: operation_time,
  11175. OrgId: advice.UserOrgId,
  11176. Creater: creater,
  11177. Ctime: ctime,
  11178. Status: 1,
  11179. ReturnTime: advice.AdviceDate,
  11180. Dealer: info.Dealer,
  11181. Manufacturer: info.Manufacturer,
  11182. Type: 1,
  11183. }
  11184. service.AddSigleDrugCancelStock(&cancelStock)
  11185. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11186. dealer, _ := service.GetDealerById(info.Dealer)
  11187. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11188. cancelStockInfo := models.DrugCancelStockInfo{
  11189. OrderNumber: cancelInfo.OrderNumber,
  11190. CancelStockId: cancelInfo.ID,
  11191. DrugId: info.DrugId,
  11192. Count: info.Count,
  11193. Status: 1,
  11194. Ctime: ctime,
  11195. OrgId: advice.UserOrgId,
  11196. Type: 1,
  11197. Manufacturer: manufactureName.ManufacturerName,
  11198. Dealer: dealer.DealerName,
  11199. Total: 0,
  11200. RetailPrice: info.RetailPrice,
  11201. RetailTotalPrice: info.RetailTotalPrice,
  11202. Price: info.Price,
  11203. RegisterAccount: "",
  11204. Remark: info.Remark,
  11205. BatchNumber: info.BatchNumber,
  11206. MaxUnit: info.CountUnit,
  11207. ProductDate: info.ProductDate,
  11208. ExpiryDate: info.ExpiryDate,
  11209. BatchNumberId: info.WarehouseInfoId,
  11210. }
  11211. flow := models.DrugFlow{
  11212. WarehousingId: 0,
  11213. DrugId: info.DrugId,
  11214. Number: "",
  11215. BatchNumber: info.BatchNumber,
  11216. Count: info.Count,
  11217. UserOrgId: advice.UserOrgId,
  11218. PatientId: 0,
  11219. SystemTime: ctime,
  11220. ConsumableType: 4,
  11221. IsSys: 0,
  11222. WarehousingOrder: "",
  11223. WarehouseOutId: 0,
  11224. WarehouseOutOrderNumber: "",
  11225. IsEdit: 0,
  11226. CancelStockId: cancelStock.ID,
  11227. CancelOrderNumber: cancelStock.OrderNumber,
  11228. Manufacturer: info.Manufacturer,
  11229. Dealer: info.Dealer,
  11230. Creator: advice.UserOrgId,
  11231. UpdateCreator: 0,
  11232. Status: 1,
  11233. Ctime: time.Now().Unix(),
  11234. Mtime: 0,
  11235. Price: info.Price,
  11236. WarehousingDetailId: 0,
  11237. WarehouseOutDetailId: 0,
  11238. CancelOutDetailId: 0,
  11239. ExpireDate: info.ExpiryDate,
  11240. ProductDate: info.ProductDate,
  11241. MaxUnit: info.CountUnit,
  11242. MinUnit: "",
  11243. }
  11244. service.CreatedCancelStock(cancelStockInfo)
  11245. service.CreateDrugFlowOne(flow)
  11246. } else {
  11247. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11248. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11249. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11250. warehouseInfo := models.DrugWarehouseInfo{
  11251. StockMinNumber: prescribingNumber,
  11252. }
  11253. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11254. }
  11255. operation_time := time.Now().Unix()
  11256. creater := advice.AdviceDoctor
  11257. ctime := time.Now().Unix()
  11258. timeStr := time.Now().Format("2006-01-02")
  11259. timeArr := strings.Split(timeStr, "-")
  11260. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11261. total = total + 1
  11262. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11263. cancelStock := models.DrugCancelStock{
  11264. OrderNumber: orderNumber,
  11265. OperaTime: operation_time,
  11266. OrgId: advice.UserOrgId,
  11267. Creater: creater,
  11268. Ctime: ctime,
  11269. Status: 1,
  11270. ReturnTime: advice.AdviceDate,
  11271. Dealer: info.Dealer,
  11272. Manufacturer: info.Manufacturer,
  11273. Type: 1,
  11274. }
  11275. service.AddSigleDrugCancelStock(&cancelStock)
  11276. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11277. dealer, _ := service.GetDealerById(info.Dealer)
  11278. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11279. cancelStockInfo := models.DrugCancelStockInfo{
  11280. OrderNumber: cancelInfo.OrderNumber,
  11281. CancelStockId: cancelInfo.ID,
  11282. DrugId: info.DrugId,
  11283. Count: info.Count,
  11284. Status: 1,
  11285. Ctime: ctime,
  11286. OrgId: advice.UserOrgId,
  11287. Type: 1,
  11288. Manufacturer: manufactureName.ManufacturerName,
  11289. Dealer: dealer.DealerName,
  11290. Total: 0,
  11291. RetailPrice: info.RetailPrice,
  11292. RetailTotalPrice: info.RetailTotalPrice,
  11293. Price: info.Price,
  11294. RegisterAccount: "",
  11295. Remark: info.Remark,
  11296. BatchNumber: info.BatchNumber,
  11297. MaxUnit: info.CountUnit,
  11298. ProductDate: info.ProductDate,
  11299. ExpiryDate: info.ExpiryDate,
  11300. BatchNumberId: info.WarehouseInfoId,
  11301. }
  11302. flow := models.DrugFlow{
  11303. WarehousingId: 0,
  11304. DrugId: info.DrugId,
  11305. Number: "",
  11306. BatchNumber: info.BatchNumber,
  11307. Count: info.Count,
  11308. UserOrgId: advice.UserOrgId,
  11309. PatientId: 0,
  11310. SystemTime: ctime,
  11311. ConsumableType: 4,
  11312. IsSys: 0,
  11313. WarehousingOrder: "",
  11314. WarehouseOutId: 0,
  11315. WarehouseOutOrderNumber: "",
  11316. IsEdit: 0,
  11317. CancelStockId: cancelStock.ID,
  11318. CancelOrderNumber: cancelStock.OrderNumber,
  11319. Manufacturer: info.Manufacturer,
  11320. Dealer: info.Dealer,
  11321. Creator: advice.AdviceDoctor,
  11322. UpdateCreator: 0,
  11323. Status: 1,
  11324. Ctime: time.Now().Unix(),
  11325. Mtime: 0,
  11326. Price: info.Price,
  11327. WarehousingDetailId: 0,
  11328. WarehouseOutDetailId: 0,
  11329. CancelOutDetailId: 0,
  11330. ExpireDate: info.ExpiryDate,
  11331. ProductDate: info.ProductDate,
  11332. MaxUnit: info.CountUnit,
  11333. MinUnit: "",
  11334. }
  11335. service.CreatedCancelStock(cancelStockInfo)
  11336. service.CreateDrugFlowOne(flow)
  11337. }
  11338. }
  11339. }
  11340. return err
  11341. }
  11342. func (this *HisApiController) DeleteNCDS() {
  11343. id, _ := this.GetInt64("id", 0)
  11344. if id > 0 {
  11345. service.DeletePsnNCDSRecordById(id)
  11346. this.ServeSuccessJSON(map[string]interface{}{
  11347. "msg": "删除成功",
  11348. })
  11349. } else {
  11350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11351. return
  11352. }
  11353. }
  11354. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11355. id, _ := c.GetInt64("id")
  11356. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11357. c.ServeSuccessJSON(map[string]interface{}{
  11358. "advice": advice,
  11359. })
  11360. return
  11361. }
  11362. func (c *HisApiController) GetHisMonthChargePatientList() {
  11363. record_date := c.GetString("record_date")
  11364. start_time := c.GetString("start_time")
  11365. end_time := c.GetString("end_time")
  11366. timeLayout := "2006-01-02"
  11367. loc, _ := time.LoadLocation("Local")
  11368. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11369. if err != nil {
  11370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11371. return
  11372. }
  11373. if err != nil {
  11374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11375. return
  11376. }
  11377. recordDateTime := theTime.Unix()
  11378. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11379. if err != nil {
  11380. }
  11381. startRecordDateTime := startTime.Unix()
  11382. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11383. if err != nil {
  11384. }
  11385. endRecordDateTime := endTime.Unix()
  11386. adminInfo := c.GetAdminUserInfo()
  11387. var tempMonthChargePatients []*service.MonthChargePatients
  11388. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11389. for _, item := range tempPatients {
  11390. //过滤没有处方的
  11391. if len(item.HisPrescription) == 0 {
  11392. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11393. }
  11394. }
  11395. c.ServeSuccessJSON(map[string]interface{}{
  11396. "list": tempMonthChargePatients,
  11397. })
  11398. }
  11399. // PrescriptionDifference 医嘱数量差值结构体
  11400. type PrescriptionDrugDifference struct {
  11401. DrugID int64 //基础库药品id
  11402. ID int64 //医嘱id
  11403. Difference float64 //差值
  11404. Unit string //单位
  11405. }
  11406. type PrescriptionGoodDifference struct {
  11407. GoodID int64 //基础库项目耗材id
  11408. ID int64 //医嘱id
  11409. Difference int64 //差值
  11410. Unit string //单位
  11411. Type int64 //类型
  11412. }
  11413. type EditCustomData struct {
  11414. adviceList []*models.HisDoctorAdviceInfo
  11415. projectList []*models.HisPrescriptionProject
  11416. }
  11417. type SrcCustomData struct {
  11418. adviceList []*models.HisDoctorAdviceInfo
  11419. projectList []*models.HisPrescriptionProject
  11420. }
  11421. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11422. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11423. differences := make([]*PrescriptionDrugDifference, 0)
  11424. // 创建一个 map 来存储第一个切片中的药品信息
  11425. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11426. for _, advice := range firstPrescription {
  11427. firstMap[advice.DrugId] = advice
  11428. }
  11429. // 遍历第二个切片中的药品信息,并比较数量差值
  11430. for _, advice := range secondPrescription {
  11431. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11432. diff := &PrescriptionDrugDifference{
  11433. DrugID: advice.DrugId,
  11434. ID: firstAdvice.ID,
  11435. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11436. Unit: firstAdvice.PrescribingNumberUnit,
  11437. }
  11438. differences = append(differences, diff)
  11439. }
  11440. }
  11441. return differences
  11442. }
  11443. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11444. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11445. differences := make([]*PrescriptionGoodDifference, 0)
  11446. // 创建一个 map 来存储第一个切片中的耗材信息
  11447. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11448. for _, good := range firstPrescription {
  11449. firstMap[good.ProjectId] = good
  11450. }
  11451. // 遍历第二个切片中的耗材信息,并比较数量差值
  11452. for _, good := range secondPrescription {
  11453. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11454. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11455. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11456. diff := &PrescriptionGoodDifference{
  11457. GoodID: good.ProjectId,
  11458. ID: firstGood.ID,
  11459. Difference: count - firstCount,
  11460. Unit: firstGood.Unit,
  11461. Type: firstGood.Type,
  11462. }
  11463. differences = append(differences, diff)
  11464. }
  11465. }
  11466. return differences
  11467. }
  11468. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11469. var adviceList []*models.HisDoctorAdviceInfo
  11470. var projectList []*models.HisPrescriptionProject
  11471. var advice_ids []int64
  11472. var project_ids []int64
  11473. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11474. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11475. //var tempPrescription *models.HisPrescriptionProjectscription
  11476. if len(prescriptions) > 0 {
  11477. for _, item := range prescriptions {
  11478. items := item.(map[string]interface{})
  11479. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11480. advices := items["advices"].([]interface{})
  11481. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11482. groupNo := int64(0)
  11483. ctime := time.Now().Unix()
  11484. mtime := ctime
  11485. if len(advices) > 0 {
  11486. for _, advice := range advices {
  11487. var s models.HisDoctorAdviceInfo
  11488. s.AdviceType = 2
  11489. s.StopState = 2
  11490. s.ExecutionState = 2
  11491. s.Status = 1
  11492. s.Groupno = groupNo
  11493. s.CreatedTime = ctime
  11494. s.UpdatedTime = mtime
  11495. s.IsSettle = 2
  11496. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11497. //存储切片中
  11498. if s.ID > 0 {
  11499. advice_ids = append(advice_ids, s.ID)
  11500. adviceList = append(adviceList, &s)
  11501. }
  11502. }
  11503. }
  11504. }
  11505. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11506. projects := items["project"].([]interface{})
  11507. if len(projects) > 0 {
  11508. for _, project := range projects {
  11509. var p models.HisPrescriptionProject
  11510. p.Ctime = time.Now().Unix()
  11511. p.Mtime = time.Now().Unix()
  11512. p.Status = 1
  11513. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11514. if p.ID > 0 {
  11515. project_ids = append(project_ids, p.ID)
  11516. projectList = append(projectList, &p)
  11517. }
  11518. }
  11519. }
  11520. }
  11521. }
  11522. }
  11523. }
  11524. editCustomData.projectList = projectList
  11525. editCustomData.adviceList = adviceList
  11526. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11527. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11528. srcCustomData.adviceList = list
  11529. srcCustomData.projectList = list2
  11530. return
  11531. }