his_api_controller.go 428KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. }
  87. func (c *HisApiController) ChangeOrderDesc() {
  88. id, _ := c.GetInt64("id")
  89. desc := c.GetString("desc")
  90. change_type := c.GetString("change_type")
  91. order, _ := service.GetHisOrderByID(id)
  92. if order.ID == 0 {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. switch change_type {
  97. case "oth_desc":
  98. order.OthDesc = desc
  99. break
  100. case "cash_pay":
  101. order.CashPay = desc
  102. break
  103. case "jifen_pay":
  104. order.JifenPay = desc
  105. break
  106. case "band_card_pay":
  107. order.BandCardPay = desc
  108. break
  109. case "ali_pay":
  110. order.AliPay = desc
  111. break
  112. case "wechat_pay":
  113. order.WechatPay = desc
  114. break
  115. }
  116. err := service.SaveHisOrder(&order)
  117. if err == nil {
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "msg": "修改成功",
  120. })
  121. return
  122. } else {
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  124. return
  125. }
  126. }
  127. func (c *HisApiController) GetMonthHisPatient() {
  128. record_date := c.GetString("record_date")
  129. //order_status, _ := c.GetInt64("type")
  130. timeLayout := "2006-01-02"
  131. loc, _ := time.LoadLocation("Local")
  132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. recordDateTime := theTime.Unix()
  138. adminInfo := c.GetAdminUserInfo()
  139. var tempPatients []service.NewTempPatients
  140. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  141. // 获取当前时间
  142. now := time.Now()
  143. // 获取本月的第一天
  144. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  145. // 获取下个月的第一天
  146. nextMonth := firstDay.AddDate(0, 1, 0)
  147. // 获取本月的最后一天
  148. lastDay := nextMonth.Add(-time.Nanosecond)
  149. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  150. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  151. var patients []service.NewTempPatients
  152. var patients_two []service.NewTempPatients
  153. for _, item := range tempPatients {
  154. //过滤掉没挂号的和没开处方的
  155. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  156. patients = append(patients, item)
  157. }
  158. ////过滤掉没挂号的
  159. //if len(item.HisPatient) > 0 {
  160. // patients_two = append(patients_two, item)
  161. //}
  162. }
  163. c.ServeSuccessJSON(map[string]interface{}{
  164. "list": patients,
  165. "list_two": patients_two,
  166. "chargePatients": chargePatients,
  167. })
  168. }
  169. func (c *HisApiController) GetBatchSettleAccounts() {
  170. order_ids := c.GetString("order_ids")
  171. admin_user_id, _ := c.GetInt64("admin_user_id")
  172. adminUser := c.GetAdminUserInfo()
  173. orders := strings.Split(order_ids, ",")
  174. var newOrders []models.Orders
  175. for _, item := range orders {
  176. order, _ := service.GetHisOrderByIDTenOne(item)
  177. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  178. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  179. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  180. orderInfos = append(orderInfos, orderInfos_two...)
  181. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  182. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  183. var diagnosis_ids []string
  184. if his.ID > 0 {
  185. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  186. } else {
  187. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  188. }
  189. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  190. var dia_config []*models.HisXtDiagnoseConfig
  191. var name string
  192. for _, item := range diagnosis_ids {
  193. id, _ := strconv.ParseInt(item, 10, 64)
  194. diagnosisConfig, _ := service.FindDiagnoseById(id)
  195. dia_config = append(dia_config, diagnosisConfig)
  196. if len(name) == 0 {
  197. name = diagnosisConfig.ClassName
  198. } else {
  199. name = name + "," + diagnosisConfig.ClassName
  200. }
  201. }
  202. var bedCostTotal float64 = 0 //床位总费
  203. var bedCostSelfTotal float64 = 0 //床位自费
  204. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  205. var bedSelfTotal float64 = 0 //床位部分项目自费
  206. var bedInscpTotal float64 = 0 //床位部分项目自费
  207. var operationCostTotal float64 = 0 //手术费
  208. var operationCostSelfTotal float64 = 0 //手术费
  209. var operationCostPartSelfTotal float64 = 0 //手术费
  210. var operationSelfTotal float64 = 0 //床位部分项目自费
  211. var operationInscpTotal float64 = 0 //床位部分项目自费
  212. var otherCostTotal float64 = 0 //其他费用
  213. var otherCostSelfTotal float64 = 0 //其他费用
  214. var otherCostPartSelfTotal float64 = 0 //其他费用
  215. var otherSelfTotal float64 = 0 //床位部分项目自费
  216. var otherInscpTotal float64 = 0 //床位部分项目自费
  217. var materialCostTotal float64 = 0 //材料费
  218. var materialCostSelfTotal float64 = 0 //材料费
  219. var materialCostPartSelfTotal float64 = 0 //材料费
  220. var materialSelfTotal float64 = 0 //床位部分项目自费
  221. var materialInscpTotal float64 = 0 //床位部分项目自费
  222. var westernMedicineCostTotal float64 = 0 //西药费
  223. var westernMedicineCostSelfTotal float64 = 0 //西药费
  224. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  225. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  226. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  227. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  228. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  229. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  230. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  231. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  232. var checkCostTotal float64 = 0 //检查费
  233. var checkCostSelfTotal float64 = 0 //检查费
  234. var checkCostPartSelfTotal float64 = 0 //检查费
  235. var checkSelfTotal float64 = 0 //床位部分项目自费
  236. var checkInscpTotal float64 = 0 //床位部分项目自费
  237. var laboratoryCostTotal float64 = 0 //化验费
  238. var laboratoryCostSelfTotal float64 = 0 //化验费
  239. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  240. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  241. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  242. var treatCostTotal float64 = 0 //治疗费用
  243. var treatCostSelfTotal float64 = 0 //治疗费用
  244. var treatCostPartSelfTotal float64 = 0 //治疗费用
  245. var treatSelfTotal float64 = 0 //床位部分项目自费
  246. var treatInscpTotal float64 = 0 //床位部分项目自费
  247. decimal.DivisionPrecision = 2
  248. for _, item := range orderInfos {
  249. if item.MedChrgitmType == "01" { //床位费
  250. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  251. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  253. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  254. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  255. }
  256. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  257. if item.MedChrgitmType == "03" { //检查费
  258. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  259. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  260. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  261. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  262. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  263. }
  264. } else {
  265. if item.MedChrgitmType == "03" { //检查费
  266. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  267. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  268. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  269. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  270. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  271. }
  272. }
  273. if item.MedChrgitmType == "04" { //化验费
  274. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  275. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  276. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  277. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  278. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  279. }
  280. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  281. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. if item.MedChrgitmType == "06" { //手术费
  288. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  289. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  290. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  291. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  292. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  293. }
  294. if item.MedChrgitmType == "08" { //材料费
  295. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  296. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  298. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  299. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  300. }
  301. if item.MedChrgitmType == "09" { //西药费
  302. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  306. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  307. }
  308. if item.MedChrgitmType == "11" { //中成费
  309. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  310. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  311. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  312. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  313. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  316. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  320. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  321. }
  322. }
  323. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  324. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  325. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  326. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  327. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  328. var doctor_name string
  329. if roles.ID == 0 {
  330. doctor_name = "管理员"
  331. } else {
  332. doctor_name = roles.UserName
  333. }
  334. yiliao_leibie := ""
  335. switch order.MedType {
  336. case "11":
  337. yiliao_leibie = "普通门诊"
  338. break
  339. case "12":
  340. yiliao_leibie = "门诊挂号"
  341. break
  342. case "13":
  343. yiliao_leibie = "急诊"
  344. break
  345. case "14":
  346. yiliao_leibie = "门诊特殊病"
  347. break
  348. case "15":
  349. yiliao_leibie = "门诊统筹"
  350. break
  351. case "16":
  352. yiliao_leibie = "门诊慢性病"
  353. break
  354. case "21":
  355. yiliao_leibie = "普通住院"
  356. break
  357. }
  358. var newOrder models.Orders
  359. newOrder.Diagnosis = name
  360. newOrder.OrderInfos = orderInfos
  361. newOrder.Number = order.MdtrtId
  362. newOrder.Date = order.SettleAccountsDate
  363. newOrder.ChargeAdmin = charge_admin
  364. newOrder.PrintorAdmin = printor_admin
  365. newOrder.Order = order
  366. newOrder.BedCostTotal = bedCostTotal
  367. newOrder.BedCostSelfTotal = bedCostSelfTotal
  368. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  369. newOrder.BedSelfTotal = bedSelfTotal
  370. newOrder.BedInscpTotal = bedInscpTotal
  371. newOrder.OperationCostTotal = operationCostTotal
  372. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  373. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  374. newOrder.OperationSelfTotal = operationSelfTotal
  375. newOrder.OperationInscpTotal = operationInscpTotal
  376. newOrder.OtherCostTotal = otherCostTotal
  377. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  378. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  379. newOrder.OtherSelfTotal = otherSelfTotal
  380. newOrder.OtherInscpTotal = otherInscpTotal
  381. newOrder.MaterialCostTotal = materialCostTotal
  382. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  383. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  384. newOrder.MaterialSelfTotal = materialSelfTotal
  385. newOrder.MaterialInscpTotal = materialInscpTotal
  386. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  387. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  388. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  389. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  390. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  391. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  392. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  393. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  394. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  395. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  396. newOrder.CheckCostTotal = checkCostTotal
  397. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  398. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  399. newOrder.CheckSelfTotal = checkSelfTotal
  400. newOrder.CheckInscpTotal = checkInscpTotal
  401. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  402. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  403. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  404. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  405. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  406. newOrder.TreatCostTotal = treatCostTotal
  407. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  408. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  409. newOrder.TreatSelfTotal = treatSelfTotal
  410. newOrder.TreatInscpTotal = treatInscpTotal
  411. newOrder.DoctorInfo = doctor_info
  412. newOrder.DoctorName = doctor_name
  413. newOrder.HealthCardNo = order.PsnNo
  414. newOrder.YiliaoLeibie = yiliao_leibie
  415. newOrder.Patient = patient
  416. newOrder.OrgName = miConfig.OrgName
  417. newOrder.OrgCode = miConfig.Code
  418. newOrder.OrderNumber = order.Number
  419. newOrder.HisPatient = his
  420. newOrder.DiaConfig = dia_config
  421. newOrders = append(newOrders, newOrder)
  422. }
  423. c.ServeSuccessJSON(map[string]interface{}{
  424. "orders": newOrders,
  425. })
  426. }
  427. func (c *HisApiController) GetTestOrder() {
  428. order_id, _ := c.GetInt64("order_id")
  429. admin_user_id, _ := c.GetInt64("admin_user_id")
  430. adminUser := c.GetAdminUserInfo()
  431. order, _ := service.GetHisOrderByID(order_id)
  432. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  433. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  434. orderInfos = append(orderInfos, orderInfos_two...)
  435. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  436. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  437. var dia_config []*models.HisXtDiagnoseConfig
  438. var name string
  439. var bedCostTotal float64 = 0 //床位总费
  440. var bedCostSelfTotal float64 = 0 //床位自费
  441. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  442. var bedSelfTotal float64 = 0 //床位部分项目自费
  443. var bedInscpTotal float64 = 0 //床位部分项目自费
  444. var operationCostTotal float64 = 0 //手术费
  445. var operationCostSelfTotal float64 = 0 //手术费
  446. var operationCostPartSelfTotal float64 = 0 //手术费
  447. var operationSelfTotal float64 = 0 //床位部分项目自费
  448. var operationInscpTotal float64 = 0 //床位部分项目自费
  449. var otherCostTotal float64 = 0 //其他费用
  450. var otherCostSelfTotal float64 = 0 //其他费用
  451. var otherCostPartSelfTotal float64 = 0 //其他费用
  452. var otherSelfTotal float64 = 0 //床位部分项目自费
  453. var otherInscpTotal float64 = 0 //床位部分项目自费
  454. var materialCostTotal float64 = 0 //材料费
  455. var materialCostSelfTotal float64 = 0 //材料费
  456. var materialCostPartSelfTotal float64 = 0 //材料费
  457. var materialSelfTotal float64 = 0 //床位部分项目自费
  458. var materialInscpTotal float64 = 0 //床位部分项目自费
  459. var westernMedicineCostTotal float64 = 0 //西药费
  460. var westernMedicineCostSelfTotal float64 = 0 //西药费
  461. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  462. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  463. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  464. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  465. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  466. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  467. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  468. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  469. var checkCostTotal float64 = 0 //检查费
  470. var checkCostSelfTotal float64 = 0 //检查费
  471. var checkCostPartSelfTotal float64 = 0 //检查费
  472. var checkSelfTotal float64 = 0 //床位部分项目自费
  473. var checkInscpTotal float64 = 0 //床位部分项目自费
  474. var laboratoryCostTotal float64 = 0 //化验费
  475. var laboratoryCostSelfTotal float64 = 0 //化验费
  476. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  477. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  478. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  479. var treatCostTotal float64 = 0 //治疗费用
  480. var treatCostSelfTotal float64 = 0 //治疗费用
  481. var treatCostPartSelfTotal float64 = 0 //治疗费用
  482. var treatSelfTotal float64 = 0 //床位部分项目自费
  483. var treatInscpTotal float64 = 0 //床位部分项目自费
  484. decimal.DivisionPrecision = 2
  485. for _, item := range orderInfos {
  486. if item.MedChrgitmType == "01" { //床位费
  487. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  488. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  489. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  490. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  491. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  492. }
  493. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  494. if item.MedChrgitmType == "03" { //检查费
  495. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  496. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  497. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  498. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  499. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  500. }
  501. } else {
  502. if item.MedChrgitmType == "03" { //检查费
  503. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  504. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  505. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  506. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  507. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  508. }
  509. }
  510. if item.MedChrgitmType == "04" { //化验费
  511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  512. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  513. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  514. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  515. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  516. }
  517. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  518. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. if item.MedChrgitmType == "06" { //手术费
  525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  526. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  527. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  528. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  529. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  530. }
  531. if item.MedChrgitmType == "08" { //材料费
  532. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  533. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  534. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  535. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  536. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  537. }
  538. if item.MedChrgitmType == "09" { //西药费
  539. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  540. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  541. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  543. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  544. }
  545. if item.MedChrgitmType == "11" { //中成费
  546. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  550. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  551. }
  552. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  553. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  555. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  556. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  557. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  558. }
  559. }
  560. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  561. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  562. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  563. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  564. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  565. var doctor_name string
  566. if roles.ID == 0 {
  567. doctor_name = "管理员"
  568. } else {
  569. doctor_name = roles.UserName
  570. }
  571. yiliao_leibie := ""
  572. switch order.MedType {
  573. case "11":
  574. yiliao_leibie = "普通门诊"
  575. break
  576. case "12":
  577. yiliao_leibie = "门诊挂号"
  578. break
  579. case "13":
  580. yiliao_leibie = "急诊"
  581. break
  582. case "14":
  583. yiliao_leibie = "门诊特殊病"
  584. break
  585. case "15":
  586. yiliao_leibie = "门诊统筹"
  587. break
  588. case "16":
  589. yiliao_leibie = "门诊慢性病"
  590. break
  591. case "21":
  592. yiliao_leibie = "普通住院"
  593. break
  594. }
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "diagnosis": name,
  597. "order_infos": orderInfos,
  598. "number": order.MdtrtId,
  599. "date": order.SettleAccountsDate,
  600. "charge_admin": charge_admin,
  601. "printor_admin": printor_admin,
  602. "info": order,
  603. "order": order,
  604. "bedCostTotal": bedCostTotal,
  605. "bedCostSelfTotal": bedCostSelfTotal,
  606. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  607. "bedSelfTotal": bedSelfTotal,
  608. "bedInscpTotal": bedInscpTotal,
  609. "operationCostTotal": operationCostTotal,
  610. "operationCostSelfTotal": operationCostSelfTotal,
  611. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  612. "operationSelfTotal": operationSelfTotal,
  613. "operationInscpTotal": operationInscpTotal,
  614. "otherCostTotal": otherCostTotal,
  615. "otherCostSelfTotal": otherCostSelfTotal,
  616. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  617. "otherSelfTotal": otherSelfTotal,
  618. "otherInscpTotal": otherInscpTotal,
  619. "materialCostTotal": materialCostTotal,
  620. "materialCostSelfTotal": materialCostSelfTotal,
  621. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  622. "materialSelfTotal": materialSelfTotal,
  623. "materialInscpTotal": materialInscpTotal,
  624. "westernMedicineCostTotal": westernMedicineCostTotal,
  625. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  626. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  627. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  628. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  629. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  630. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  631. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  632. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  633. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  634. "checkCostTotal": checkCostTotal,
  635. "checkCostSelfTotal": checkCostSelfTotal,
  636. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  637. "checkSelfTotal": checkSelfTotal,
  638. "checkInscpTotal": checkInscpTotal,
  639. "laboratoryCostTotal": laboratoryCostTotal,
  640. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  641. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  642. "laboratorySelfTotal": laboratorySelfTotal,
  643. "laboratoryInscpTotal": laboratoryInscpTotal,
  644. "treatCostTotal": treatCostTotal,
  645. "treatCostSelfTotal": treatCostSelfTotal,
  646. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  647. "treatSelfTotal": treatSelfTotal,
  648. "treatInscpTotal": treatInscpTotal,
  649. "doctor_info": doctor_info,
  650. "doctor_name": doctor_name,
  651. "health_card_no": order.PsnNo,
  652. "yiliao_leibie": yiliao_leibie,
  653. "patient": patient,
  654. "org_name": miConfig.OrgName,
  655. "org_code": miConfig.Code,
  656. "order_number": order.Number,
  657. "his_hospital": his_hospital,
  658. "dia_config": dia_config,
  659. })
  660. }
  661. func (c *PublicApiController) GetBaiLinExportData() {
  662. data := service.GetBaiLinOrderData()
  663. fmt.Println(len(data))
  664. var new_data []*models.NewCustomHisOrder
  665. for _, item := range data {
  666. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  667. new_data = append(new_data, item)
  668. }
  669. }
  670. fmt.Println(len(new_data))
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "list": new_data,
  673. })
  674. }
  675. func (c *HisApiController) GetHisUnChargePatientList() {
  676. record_date := c.GetString("record_date")
  677. timeLayout := "2006-01-02"
  678. loc, _ := time.LoadLocation("Local")
  679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  680. if err != nil {
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. recordDateTime := theTime.Unix()
  685. adminInfo := c.GetAdminUserInfo()
  686. var tempPatients []*service.NewTempPatients
  687. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  688. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  689. var patients []*service.NewTempPatients
  690. var patients_two []*service.NewTempPatients
  691. for _, item := range tempPatients {
  692. //过滤掉没挂号的和没开处方的
  693. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  694. patients = append(patients, item)
  695. }
  696. //过滤掉没挂号的
  697. if len(item.HisPatient) > 0 {
  698. patients_two = append(patients_two, item)
  699. }
  700. }
  701. c.ServeSuccessJSON(map[string]interface{}{
  702. "list": patients,
  703. "list_two": patients_two,
  704. })
  705. }
  706. func (c *HisApiController) GetPrivateExpensesOrder() {
  707. //id, _ := c.GetInt64("id")
  708. //record_time := c.GetString("record_time")
  709. order_id, _ := c.GetInt64("order_id")
  710. admin_user_id, _ := c.GetInt64("admin_user_id")
  711. //timeLayout := "2006-01-02"
  712. //loc, _ := time.LoadLocation("Local")
  713. //
  714. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  715. //if err != nil {
  716. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. // return
  718. //}
  719. //recordDateTime := theTime.Unix()
  720. adminUser := c.GetAdminUserInfo()
  721. order, _ := service.GetHisOrderByID(order_id)
  722. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  723. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  724. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  725. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  726. //var config []*models.HisXtDiagnoseConfig
  727. var name string
  728. if order.PType == 1 {
  729. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  730. for _, item := range diagnosis_ids {
  731. id, _ := strconv.ParseInt(item, 10, 64)
  732. diagnosisConfig, _ := service.FindDiagnoseById(id)
  733. if len(name) == 0 {
  734. name = diagnosisConfig.ClassName
  735. } else {
  736. name = name + "," + diagnosisConfig.ClassName
  737. }
  738. }
  739. } else {
  740. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  741. for _, item := range diagnosis_ids {
  742. id, _ := strconv.ParseInt(item, 10, 64)
  743. diagnosisConfig, _ := service.FindDiagnoseById(id)
  744. if len(name) == 0 {
  745. name = diagnosisConfig.ClassName
  746. } else {
  747. name = name + "," + diagnosisConfig.ClassName
  748. }
  749. }
  750. }
  751. var bedCostTotal float64 = 0 //床位总费
  752. //var bedCostSelfTotal float64 = 0 //床位自费
  753. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  754. var operationCostTotal float64 = 0 //手术费
  755. //var operationCostSelfTotal float64 = 0 //手术费
  756. var operationCostPartSelfTotal float64 = 0 //手术费
  757. var otherCostTotal float64 = 0 //其他费用
  758. //var otherCostSelfTotal float64 = 0 //其他费用
  759. var otherCostPartSelfTotal float64 = 0 //其他费用
  760. var materialCostTotal float64 = 0 //材料费
  761. //var materialCostSelfTotal float64 = 0 //材料费
  762. var materialCostPartSelfTotal float64 = 0 //材料费
  763. var westernMedicineCostTotal float64 = 0 //西药费
  764. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  765. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  766. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  767. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  768. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  769. var checkCostTotal float64 = 0 //检查费
  770. //var checkCostSelfTotal float64 = 0 //检查费
  771. var checkCostPartSelfTotal float64 = 0 //检查费
  772. var laboratoryCostTotal float64 = 0 //化验费
  773. //var laboratoryCostSelfTotal float64 = 0 //化验费
  774. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  775. var treatCostTotal float64 = 0 //治疗费用
  776. //var treatCostSelfTotal float64 = 0 //治疗费用
  777. var treatCostPartSelfTotal float64 = 0 //治疗费用
  778. var zhenChaCostTotal float64 = 0 //其他费用
  779. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  780. decimal.DivisionPrecision = 2
  781. for _, item := range orderInfos {
  782. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  783. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  784. item.MedChrgitmType = "09"
  785. }
  786. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  787. if item.HisPrescriptionProject.Type == 2 {
  788. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  789. fmt.Println("CostClassify")
  790. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  791. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  792. case 0:
  793. item.MedChrgitmType = "0"
  794. break
  795. case 1:
  796. item.MedChrgitmType = "14"
  797. break
  798. case 2:
  799. item.MedChrgitmType = "05"
  800. break
  801. case 3:
  802. item.MedChrgitmType = "03"
  803. break
  804. case 4:
  805. item.MedChrgitmType = "03"
  806. break
  807. case 5:
  808. item.MedChrgitmType = "08"
  809. break
  810. case 6:
  811. item.MedChrgitmType = "14"
  812. break
  813. case 7:
  814. item.MedChrgitmType = "14"
  815. break
  816. case 8:
  817. item.MedChrgitmType = "03"
  818. break
  819. case 9:
  820. item.MedChrgitmType = "14"
  821. break
  822. case 10:
  823. item.MedChrgitmType = "14"
  824. break
  825. case 11:
  826. item.MedChrgitmType = "06"
  827. break
  828. case 12:
  829. item.MedChrgitmType = "12"
  830. break
  831. case 13:
  832. item.MedChrgitmType = "01"
  833. break
  834. case 14:
  835. item.MedChrgitmType = "04"
  836. break
  837. case 15:
  838. item.MedChrgitmType = "14"
  839. break
  840. }
  841. } else {
  842. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  843. case 1:
  844. item.MedChrgitmType = "14"
  845. break
  846. case 2:
  847. item.MedChrgitmType = "05"
  848. break
  849. case 3:
  850. item.MedChrgitmType = "04"
  851. break
  852. case 4:
  853. item.MedChrgitmType = "14"
  854. break
  855. case 5:
  856. item.MedChrgitmType = "08"
  857. break
  858. case 6:
  859. item.MedChrgitmType = "14"
  860. break
  861. case 7:
  862. item.MedChrgitmType = "14"
  863. break
  864. case 8:
  865. item.MedChrgitmType = "03"
  866. break
  867. case 9:
  868. item.MedChrgitmType = "14"
  869. break
  870. }
  871. }
  872. } else if item.HisPrescriptionProject.Type == 3 {
  873. item.MedChrgitmType = "08"
  874. }
  875. }
  876. }
  877. order.PsnCashPay = order.MedfeeSumamt
  878. for _, item := range orderInfos {
  879. if item.MedChrgitmType == "01" { //床位费
  880. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  881. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  882. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  883. }
  884. if item.MedChrgitmType == "02" { //诊察费
  885. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  886. //zhenChaCostSelfTotal = zhenChaCostTotal
  887. }
  888. if item.MedChrgitmType == "03" { //检查费
  889. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  890. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  891. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  892. }
  893. if item.MedChrgitmType == "02" { //检查费
  894. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  895. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  896. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  897. }
  898. if item.MedChrgitmType == "04" { //化验费
  899. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  900. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  901. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  902. }
  903. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  904. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  905. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  906. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  907. }
  908. if item.MedChrgitmType == "06" { //手术费
  909. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  910. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  911. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  912. }
  913. if item.MedChrgitmType == "08" { //材料费
  914. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  915. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  916. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  917. }
  918. if item.MedChrgitmType == "09" { //西药费
  919. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  920. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  921. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  922. }
  923. if item.MedChrgitmType == "11" { //中成费
  924. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  925. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  926. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  927. }
  928. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  929. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  930. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  931. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  932. }
  933. }
  934. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  935. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  936. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  937. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "patient": patient,
  940. "order_infos": orderInfos,
  941. "diagnosis": name,
  942. "bedCostTotal": bedCostTotal,
  943. "bedCostSelfTotal": bedCostTotal,
  944. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  945. "operationCostTotal": operationCostTotal,
  946. "operationCostSelfTotal": operationCostTotal,
  947. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  948. "otherCostTotal": otherCostTotal,
  949. "otherCostSelfTotal": otherCostTotal,
  950. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  951. "materialCostTotal": materialCostTotal,
  952. "materialCostSelfTotal": materialCostTotal,
  953. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  954. "westernMedicineCostTotal": westernMedicineCostTotal,
  955. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  956. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  957. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  958. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  959. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  960. "checkCostTotal": checkCostTotal,
  961. "checkCostSelfTotal": checkCostTotal,
  962. "zhenChaCostTotal": zhenChaCostTotal,
  963. "zhenChaCostSelfTotal": zhenChaCostTotal,
  964. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  965. "laboratoryCostTotal": laboratoryCostTotal,
  966. "laboratoryCostSelfTotal": laboratoryCostTotal,
  967. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  968. "treatCostTotal": treatCostTotal,
  969. "treatCostSelfTotal": treatCostTotal,
  970. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  971. "charge_admin": charge_admin,
  972. "printor_admin": printor_admin,
  973. "org_name": org.OrgName,
  974. "org_code": miConfig.Code,
  975. "name": patient.Name,
  976. "number": order.MdtrtId,
  977. "date": order.SettleAccountsDate,
  978. "info": order,
  979. "his_hospital": his_hospital,
  980. "his": his,
  981. })
  982. }
  983. func (c *HisApiController) RefudDetail() {
  984. order_id, _ := c.GetInt64("order_id")
  985. order, _ := service.GetHisOrderByID(order_id)
  986. adminUser := c.GetAdminUserInfo()
  987. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "msg": "撤销成功",
  990. })
  991. }
  992. func (c *HisApiController) Sscard() {
  993. //r := CardInit()
  994. //if r == 0 {
  995. // GetBaseInfo()
  996. //}
  997. //c.ServeSuccessJSON(map[string]interface{}{
  998. // "list": "11",
  999. //})
  1000. }
  1001. func GetBaseInfo() error {
  1002. //handle := syscall.MustLoadDLL("SSCard.dll")
  1003. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1004. //
  1005. //str := make([]byte, 256)
  1006. //str1 := make([]byte, 256)
  1007. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1008. //if ferr != nil {
  1009. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1010. // return ferr
  1011. //}
  1012. //
  1013. //fmt.Println(string(str))
  1014. //
  1015. //fmt.Println(r)
  1016. return nil
  1017. }
  1018. func CardInit() int {
  1019. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1020. //add := DllTestDef.MustFindProc("Init")
  1021. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1022. //if err != nil {
  1023. // fmt.Println("SSCard的运算结果为:", ret)
  1024. //}
  1025. //result := int(ret)
  1026. return 0
  1027. }
  1028. func IntPtr(n int) uintptr {
  1029. return uintptr(n)
  1030. }
  1031. func StrPtr(s string) uintptr {
  1032. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1033. }
  1034. func (c *HisApiController) GetHisPatientList() {
  1035. //types, _ := c.GetInt64("type", 0)
  1036. record_date := c.GetString("record_date")
  1037. sch_type, _ := c.GetInt64("sch_type")
  1038. timeLayout := "2006-01-02"
  1039. loc, _ := time.LoadLocation("Local")
  1040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1041. if err != nil {
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. return
  1044. }
  1045. recordDateTime := theTime.Unix()
  1046. adminInfo := c.GetAdminUserInfo()
  1047. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1048. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1049. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1050. //获取当前用户的信息
  1051. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1052. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1053. //获取所有科室信息
  1054. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1055. c.ServeSuccessJSON(map[string]interface{}{
  1056. "list": patients,
  1057. "list_two": patients_two,
  1058. "info": adminUserInfo,
  1059. "doctors": doctors,
  1060. "department": department,
  1061. })
  1062. }
  1063. type CustomTemplate struct {
  1064. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1065. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1066. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1067. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1068. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1069. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1070. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1071. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1072. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1073. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1074. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1075. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1076. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1077. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1078. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1079. }
  1080. func (c *HisApiController) GetHisPatientInfo() {
  1081. patient_id, _ := c.GetInt64("patient_id")
  1082. his_patient_id, _ := c.GetInt64("his_patient_id")
  1083. record_date := c.GetString("record_date")
  1084. number := c.GetString("number")
  1085. //start_time := c.GetString("start_time")
  1086. //end_time := c.GetString("end_time")
  1087. p_type, _ := c.GetInt64("p_type")
  1088. timeLayout := "2006-01-02"
  1089. loc, _ := time.LoadLocation("Local")
  1090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1091. if err != nil {
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1093. return
  1094. }
  1095. recordDateTime := theTime.Unix()
  1096. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1097. //if err != nil {
  1098. //
  1099. //}
  1100. //startRecordDateTime := startTime.Unix()
  1101. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1102. //if err != nil {
  1103. //
  1104. //}
  1105. //endRecordDateTime := endTime.Unix()
  1106. admin := c.GetAdminUserInfo()
  1107. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1108. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1109. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1110. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1111. var prescriptions []*models.HisPrescription
  1112. var last_prescriptions []*models.HisPrescription
  1113. var sch_prescriptions []CustomTemplate
  1114. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1115. if p_type == 1 { //住院
  1116. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1117. for _, item := range prescriptions {
  1118. for _, subItem := range item.HisDoctorAdviceInfo {
  1119. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1120. if info.RetailPrice > 0 {
  1121. subItem.Drug.MinPrice = info.RetailPrice
  1122. }
  1123. }
  1124. }
  1125. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1126. } else { //门诊
  1127. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1128. for _, item := range prescriptions {
  1129. for _, subItem := range item.HisDoctorAdviceInfo {
  1130. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1131. if info.RetailPrice > 0 {
  1132. subItem.Drug.MinPrice = info.RetailPrice
  1133. }
  1134. }
  1135. }
  1136. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1137. }
  1138. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1139. if sch.ID > 0 {
  1140. var week string
  1141. t := time.Now()
  1142. switch t.Weekday().String() {
  1143. case "Monday":
  1144. week = "周一"
  1145. break
  1146. case "Tuesday":
  1147. week = "周二"
  1148. break
  1149. case "Wednesday":
  1150. week = "周三"
  1151. break
  1152. case "Thursday":
  1153. week = "周四"
  1154. break
  1155. case "Friday":
  1156. week = "周五"
  1157. break
  1158. case "Saturday":
  1159. week = "周六"
  1160. break
  1161. case "Sunday":
  1162. week = "周日"
  1163. break
  1164. }
  1165. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1166. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1167. //根据推送频率组装新的数组
  1168. for _, item := range temp_sch_prescriptions {
  1169. var cus CustomTemplate
  1170. cus.ID = item.ID
  1171. cus.UserOrgId = item.UserOrgId
  1172. cus.PatientId = item.PatientId
  1173. cus.MedType = item.MedType
  1174. cus.RecordDate = item.RecordDate
  1175. cus.Type = item.Type
  1176. cus.PType = item.PType
  1177. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1178. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1179. if subItem.FrequencyType == 1 { //每次必推
  1180. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1181. }
  1182. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1183. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1184. }
  1185. if subItem.FrequencyType == 2 { //按照天数频率
  1186. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1187. now := p.Unix()
  1188. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1189. dayStr2 := "-" + dayStr
  1190. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1191. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1192. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1193. if len(advices) == 0 {
  1194. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1195. }
  1196. }
  1197. }
  1198. }
  1199. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1200. if subItem.Type == 2 {
  1201. if subItem.XtHisProject.MedicalStatus != 1 {
  1202. if subItem.FrequencyType == 1 {
  1203. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1204. }
  1205. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1206. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1207. }
  1208. if subItem.FrequencyType == 2 {
  1209. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1210. now := p.Unix()
  1211. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1212. dayStr2 := "-" + dayStr
  1213. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1214. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1215. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1216. if len(projects) == 0 {
  1217. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1218. }
  1219. }
  1220. }
  1221. } else if subItem.Type == 3 {
  1222. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1223. if subItem.FrequencyType == 1 {
  1224. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1225. }
  1226. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1227. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1228. }
  1229. if subItem.FrequencyType == 2 {
  1230. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1231. now := p.Unix()
  1232. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1233. dayStr2 := "-" + dayStr
  1234. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1235. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1236. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1237. if len(projects) == 0 {
  1238. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1239. }
  1240. }
  1241. }
  1242. }
  1243. }
  1244. sch_prescriptions = append(sch_prescriptions, cus)
  1245. }
  1246. for _, item := range sch_prescriptions {
  1247. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1248. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1249. }
  1250. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1251. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1252. }
  1253. }
  1254. }
  1255. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1256. if config.ID > 0 && config.IsOpen == 1 {
  1257. for _, item := range sch_prescriptions {
  1258. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1259. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1260. if info.RetailPrice > 0 {
  1261. subItem.Drug.MinPrice = info.RetailPrice
  1262. }
  1263. }
  1264. }
  1265. }
  1266. if config.ID > 0 && config.IsOpen == 1 {
  1267. for _, item := range sch_prescriptions {
  1268. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1269. if subItem.Type == 3 {
  1270. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1271. if info.Price > 0 {
  1272. subItem.GoodInfo.PackingPrice = info.Price
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1279. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1280. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1281. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1282. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1283. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1284. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1285. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1286. //获取所有科室信息
  1287. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1288. c.ServeSuccessJSON(map[string]interface{}{
  1289. "his_info": his_patient_info,
  1290. "xt_info": xt_patient_info,
  1291. "prescription": prescriptions,
  1292. "case_history": case_history,
  1293. "info": patientPrescriptionInfo,
  1294. //"month_prescriptions": monthPrescriptions,
  1295. "order": order,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. "sch_prescriptions": sch_prescriptions,
  1299. "last_prescriptions": last_prescriptions,
  1300. "schedule": sch,
  1301. "count": count,
  1302. "drugStockConfig": drugStockConfig,
  1303. "last_info": lastPatientPrescriptionInfo,
  1304. })
  1305. return
  1306. }
  1307. func (c *HisApiController) GetHisPrescriptionConfig() {
  1308. adminInfo := c.GetAdminUserInfo()
  1309. //获取医嘱模版
  1310. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1311. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1312. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1313. //获取所有基础药
  1314. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1315. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1316. if config.ID > 0 && config.IsOpen == 1 {
  1317. for _, item := range drugs {
  1318. var index = 0
  1319. for _, subItem := range item.OtherDrugWarehouseInfo {
  1320. if index == 0 {
  1321. index = index + 1
  1322. if subItem.RetailPrice > 0 {
  1323. item.MinPrice = subItem.RetailPrice
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1330. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1331. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1332. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1333. //获取所有科室信息
  1334. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1335. //获取诊断信息
  1336. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1337. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1338. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1339. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1340. //获取是否开启保存耗材出库的开关
  1341. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1342. c.ServeSuccessJSON(map[string]interface{}{
  1343. "drugs": drugs,
  1344. "advices_template": advices,
  1345. "drugways": drugways,
  1346. "efs": efs,
  1347. "doctors": doctors,
  1348. "department": department,
  1349. "sick": sick,
  1350. "additions": additions,
  1351. "diagnose": diagnose,
  1352. "manufacturers": manufacturers,
  1353. "goodOutOpen": goodOutOpen,
  1354. "patientDiagnose": patientDiagnose,
  1355. })
  1356. }
  1357. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1358. //获取所有基础药
  1359. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1360. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1361. if config.ID > 0 && config.IsOpen == 1 {
  1362. for _, item := range drugs {
  1363. var index = 0
  1364. for _, subItem := range item.OtherDrugWarehouseInfo {
  1365. if index == 0 {
  1366. index = index + 1
  1367. if subItem.RetailPrice > 0 {
  1368. item.MinPrice = subItem.RetailPrice
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1375. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1376. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1377. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1378. //获取所有科室信息
  1379. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1380. //获取诊断信息
  1381. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1382. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1383. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1384. //获取是否开启保存耗材出库的开关
  1385. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1386. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1387. c.ServeSuccessJSON(map[string]interface{}{
  1388. "drugs": drugs,
  1389. "advices_template": advices,
  1390. "drugways": drugways,
  1391. "efs": efs,
  1392. "doctors": doctors,
  1393. "department": department,
  1394. "sick": sick,
  1395. "additions": additions,
  1396. "diagnose": diagnose,
  1397. "manufacturers": manufacturers,
  1398. "goodOutOpen": goodOutOpen,
  1399. "patientDiagnose": patientDiagnose,
  1400. })
  1401. }
  1402. }
  1403. func (c *HisApiController) CreateHisPrescription() {
  1404. record_date := c.GetString("record_date")
  1405. patient_id, _ := c.GetInt64("patient_id")
  1406. reg_type, _ := c.GetInt64("reg_type")
  1407. diagnose := c.GetString("diagnose")
  1408. sick_type, _ := c.GetInt64("sick_type")
  1409. sick_history := c.GetString("sick_history")
  1410. doctor_id, _ := c.GetInt64("doctor", 0)
  1411. department, _ := c.GetInt64("department", 0)
  1412. his_patient_id, _ := c.GetInt64("his_patient_id")
  1413. p_type, _ := c.GetInt64("p_type")
  1414. patient_diagnose := c.GetString("patient_diagnose")
  1415. dataBody := make(map[string]interface{}, 0)
  1416. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1417. if err != nil {
  1418. utils.ErrorLog(err.Error())
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. timeLayout := "2006-01-02"
  1423. loc, _ := time.LoadLocation("Local")
  1424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1425. if err != nil {
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. adminInfo := c.GetAdminUserInfo()
  1430. recordDateTime := theTime.Unix()
  1431. //查询默认出库仓库库存
  1432. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1433. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1434. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1435. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1436. if len(lists) == 1 {
  1437. his_patient_id = lists[0].ID
  1438. }
  1439. }
  1440. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1441. //保存处方出库
  1442. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1443. //自动出库
  1444. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1445. //耗材保存处方出库
  1446. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1447. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1448. //已发药和已收费限制逻辑
  1449. isMidicine := false
  1450. isCharge := false
  1451. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1452. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1453. if len(prescriptions) > 0 {
  1454. for _, item := range prescriptions {
  1455. items := item.(map[string]interface{})
  1456. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1457. utils.ErrorLog("id")
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. id := int64(items["id"].(float64))
  1462. if id > 0 {
  1463. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1464. if err != nil {
  1465. if new_prescription.OrderStatus == 4 {
  1466. isCharge = true
  1467. }
  1468. }
  1469. }
  1470. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1471. advices := items["advices"].([]interface{})
  1472. if len(advices) > 0 {
  1473. for _, advice := range advices {
  1474. var adviceId int64
  1475. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1476. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1477. }
  1478. if adviceId > 0 {
  1479. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1480. if err == nil {
  1481. if his_advice_info.IsMedicine == 1 {
  1482. isMidicine = true
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. if isMidicine == true {
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1494. return
  1495. }
  1496. if isCharge == true {
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1498. return
  1499. }
  1500. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1501. //药品发药出库
  1502. if pharmacyConfig.IsOpen == 1 {
  1503. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1504. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1505. if len(prescriptions) > 0 {
  1506. for _, item := range prescriptions {
  1507. items := item.(map[string]interface{})
  1508. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1509. advices := items["advices"].([]interface{})
  1510. if len(advices) > 0 {
  1511. for _, advice := range advices {
  1512. var drug_id int64
  1513. var prescribing_number float64
  1514. var prescribingNumberUnit string
  1515. var adviceId int64
  1516. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1517. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1518. }
  1519. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1520. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1521. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1522. }
  1523. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1524. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1525. }
  1526. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1527. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1528. }
  1529. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1530. if drug.ID == 0 {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. //查询药品的所有库存
  1535. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1536. var total_count int64
  1537. for _, it := range list {
  1538. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1539. }
  1540. totals := strconv.FormatInt(total_count, 10)
  1541. //查询该药品是否存在开药记录
  1542. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1543. //新增处方
  1544. if advicelist.ID == 0 {
  1545. all_count, _ := strconv.ParseFloat(totals, 64)
  1546. if prescribingNumberUnit == drug.MinUnit {
  1547. if drug.IsUse != 1 {
  1548. if prescribing_number > all_count {
  1549. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1550. return
  1551. }
  1552. }
  1553. }
  1554. if prescribingNumberUnit == drug.MaxUnit {
  1555. num := prescribing_number * float64(drug.MinNumber)
  1556. if drug.IsUse != 1 {
  1557. if num > all_count {
  1558. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1559. return
  1560. }
  1561. }
  1562. }
  1563. }
  1564. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1565. if drugOutConfig.IsOpen != 1 {
  1566. //修改处方
  1567. for _, advice := range advices {
  1568. var drug_id int64
  1569. var prescribing_number float64
  1570. var prescribingNumberUnit string
  1571. var prescribingNumber string
  1572. var adviceId int64
  1573. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1574. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1575. }
  1576. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1577. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1578. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1579. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1580. }
  1581. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1582. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1583. }
  1584. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1585. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1586. }
  1587. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1588. if drug.ID == 0 {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1590. return
  1591. }
  1592. //查询药品的所有库存
  1593. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1594. var total_count int64
  1595. for _, it := range list {
  1596. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1597. }
  1598. totals := strconv.FormatInt(total_count, 10)
  1599. //查询该药品是否存在开药记录
  1600. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1601. //新增处方
  1602. if advicelist.ID == 0 {
  1603. all_count, _ := strconv.ParseFloat(totals, 64)
  1604. if prescribingNumberUnit == drug.MinUnit {
  1605. if drug.IsUse != 1 {
  1606. if prescribing_number > all_count {
  1607. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1608. return
  1609. }
  1610. }
  1611. } else {
  1612. if prescribingNumberUnit == drug.MaxUnit {
  1613. num := prescribing_number * float64(drug.MinNumber)
  1614. if drug.IsUse != 1 {
  1615. if num > all_count {
  1616. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1617. return
  1618. }
  1619. }
  1620. }
  1621. }
  1622. }
  1623. //修改处方
  1624. if advicelist.ID > 0 {
  1625. var device_number int64
  1626. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1627. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1628. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1629. device_number = prescribingNumberInt * drug.MinNumber
  1630. }
  1631. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1632. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1633. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1634. device_number = prescribingNumberInt
  1635. }
  1636. var number_count int64
  1637. if prescribingNumberUnit == drug.MaxUnit {
  1638. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1639. number_count = prescribingNumberInt * drug.MinNumber
  1640. }
  1641. if prescribingNumberUnit == drug.MinUnit {
  1642. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1643. number_count = prescribingNumberInt
  1644. }
  1645. //如果修改的数量大于之前修改的数量
  1646. if (number_count - device_number) > 0 {
  1647. //如果修改的差数量 大于库存数量
  1648. if drug.IsUse != 1 {
  1649. if (number_count - device_number) > total_count {
  1650. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1651. return
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. //已发药和已收费限制逻辑
  1666. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1667. //校验库存总量
  1668. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1669. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1670. if len(prescriptions) > 0 {
  1671. for _, item := range prescriptions {
  1672. items := item.(map[string]interface{})
  1673. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1674. advices := items["advices"].([]interface{})
  1675. if len(advices) > 0 {
  1676. for _, advice := range advices {
  1677. var drug_id int64
  1678. var prescribing_number float64
  1679. var prescribingNumberUnit string
  1680. var adviceId int64
  1681. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1682. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1683. }
  1684. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1685. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1686. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1687. }
  1688. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1689. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1690. }
  1691. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1692. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1693. }
  1694. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1695. if drug.ID == 0 {
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1697. return
  1698. }
  1699. //查询药品的所有库存
  1700. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1701. var total_count int64
  1702. for _, it := range list {
  1703. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1704. }
  1705. totals := strconv.FormatInt(total_count, 10)
  1706. //查询该药品是否存在开药记录
  1707. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1708. //查询最新批次库存
  1709. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1710. var batch_number_count int64
  1711. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1712. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1713. //新增处方
  1714. if advicelist.ID == 0 {
  1715. all_count, _ := strconv.ParseFloat(totals, 64)
  1716. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1717. if prescribingNumberUnit == drug.MinUnit {
  1718. if drug.IsUse != 1 {
  1719. if prescribing_number > all_count {
  1720. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1721. return
  1722. }
  1723. if adminInfo.CurrentOrgId == 10215 {
  1724. if prescribing_number > batch_number_all_count {
  1725. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1726. return
  1727. }
  1728. }
  1729. }
  1730. }
  1731. if prescribingNumberUnit == drug.MaxUnit {
  1732. num := prescribing_number * float64(drug.MinNumber)
  1733. if drug.IsUse != 1 {
  1734. if num > all_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1736. return
  1737. }
  1738. if adminInfo.CurrentOrgId == 10215 {
  1739. if num > batch_number_all_count {
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1741. return
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1748. if drugOutConfig.IsOpen != 1 {
  1749. //修改处方
  1750. for _, advice := range advices {
  1751. var drug_id int64
  1752. var prescribing_number float64
  1753. var prescribingNumberUnit string
  1754. var prescribingNumber string
  1755. var adviceId int64
  1756. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1757. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1758. }
  1759. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1760. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1761. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1762. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1765. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1768. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1769. }
  1770. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1771. if drug.ID == 0 {
  1772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1773. return
  1774. }
  1775. //查询药品的所有库存
  1776. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1777. var total_count int64
  1778. for _, it := range list {
  1779. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1780. }
  1781. totals := strconv.FormatInt(total_count, 10)
  1782. //查询该药品是否存在开药记录
  1783. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1784. //新增处方
  1785. if advicelist.ID == 0 {
  1786. //查询最新批次库存
  1787. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1788. var batch_number_count int64
  1789. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1790. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1791. all_count, _ := strconv.ParseFloat(totals, 64)
  1792. if prescribingNumberUnit == drug.MinUnit {
  1793. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1794. if drug.IsUse != 1 {
  1795. if prescribing_number > all_count {
  1796. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1797. return
  1798. }
  1799. if adminInfo.CurrentOrgId == 10215 {
  1800. if prescribing_number > batch_number_all_count {
  1801. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1802. return
  1803. }
  1804. }
  1805. }
  1806. } else {
  1807. if prescribingNumberUnit == drug.MaxUnit {
  1808. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1809. num := prescribing_number * float64(drug.MinNumber)
  1810. if drug.IsUse != 1 {
  1811. if num > all_count {
  1812. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1813. return
  1814. }
  1815. if adminInfo.CurrentOrgId == 10215 {
  1816. if prescribing_number > batch_number_all_count {
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. //修改处方
  1826. if advicelist.ID > 0 {
  1827. //查询最新批次库存
  1828. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1829. var batch_number_count int64
  1830. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1831. var device_number int64
  1832. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1833. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1834. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1835. device_number = prescribingNumberInt * drug.MinNumber
  1836. }
  1837. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1838. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1839. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1840. device_number = prescribingNumberInt
  1841. }
  1842. var number_count int64
  1843. if prescribingNumberUnit == drug.MaxUnit {
  1844. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1845. number_count = prescribingNumberInt * drug.MinNumber
  1846. }
  1847. if prescribingNumberUnit == drug.MinUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt
  1850. }
  1851. //如果修改的数量大于之前修改的数量
  1852. if (number_count - device_number) > 0 {
  1853. //如果修改的差数量 大于库存数量
  1854. if drug.IsUse != 1 {
  1855. if (number_count - device_number) > total_count {
  1856. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1857. return
  1858. }
  1859. if (number_count - device_number) > batch_number_count {
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1861. return
  1862. }
  1863. if adminInfo.CurrentOrgId == 10215 {
  1864. // 查询该药品最后一次出库记录
  1865. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1866. var out_count int64
  1867. var in_count int64
  1868. var stock_max_number int64
  1869. var stock_min_number int64
  1870. for _, it := range outInfo {
  1871. if it.CountUnit == drug.MaxUnit {
  1872. it.Count = it.Count * drug.MinNumber
  1873. }
  1874. out_count += it.Count
  1875. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1876. stock_max_number = warehouseInfoList.StockMaxNumber
  1877. stock_min_number = warehouseInfoList.StockMinNumber
  1878. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1879. }
  1880. if out_count > 0 {
  1881. if (number_count - device_number) > in_count {
  1882. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1883. return
  1884. }
  1885. }
  1886. // 未出库
  1887. if out_count == 0 {
  1888. var sum_in_count int64
  1889. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1890. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1891. fmt.Println("sum_in_count", sum_in_count)
  1892. //如果修改的数量大于有库存的第一个批次
  1893. if number_count > sum_in_count {
  1894. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1895. return
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1902. if pharmacyConfig.IsOpen != 1 {
  1903. if device_number != number_count {
  1904. // 查询该药品最后一次出库记录
  1905. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1906. //回退库存
  1907. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1908. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1909. }
  1910. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1911. var stock_max_number int64
  1912. var stock_min_number int64
  1913. if number_count >= drug.MinNumber {
  1914. stock_max_number = device_number / drug.MinNumber
  1915. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1916. stock_min_number = device_number % drug.MinNumber
  1917. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1918. } else {
  1919. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1920. }
  1921. }
  1922. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1923. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1924. }
  1925. //删除记录
  1926. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1927. //查询默认仓库剩余多少库存
  1928. var sum_count int64
  1929. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1930. for _, its := range stockInfo {
  1931. if its.MaxUnit == drug.MaxUnit {
  1932. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1933. }
  1934. sum_count += its.StockMaxNumber + its.StockMinNumber
  1935. }
  1936. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1937. }
  1938. }
  1939. }
  1940. }
  1941. }
  1942. //保存处方开药
  1943. if drugOutConfig.IsOpen == 1 {
  1944. //修改处方
  1945. for _, advice := range advices {
  1946. var drug_id int64
  1947. var prescribing_number float64
  1948. var prescribingNumberUnit string
  1949. var prescribingNumber string
  1950. var adviceId int64
  1951. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1952. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1953. }
  1954. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1955. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1956. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1957. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1958. }
  1959. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1960. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1961. }
  1962. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1963. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1964. }
  1965. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1966. if drug.ID == 0 {
  1967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1968. return
  1969. }
  1970. //查询药品的所有库存
  1971. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1972. var total_count int64
  1973. for _, it := range list {
  1974. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1975. }
  1976. totals := strconv.FormatInt(total_count, 10)
  1977. //查询该药品是否存在开药记录
  1978. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1979. //新增处方
  1980. if advicelist.ID == 0 {
  1981. //查询最新批次库存
  1982. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1983. var batch_number_count int64
  1984. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1985. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1986. all_count, _ := strconv.ParseFloat(totals, 64)
  1987. if prescribingNumberUnit == drug.MinUnit {
  1988. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1989. if drug.IsUse != 1 {
  1990. if prescribing_number > all_count {
  1991. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1992. return
  1993. }
  1994. if adminInfo.CurrentOrgId == 10215 {
  1995. if prescribing_number > batch_number_all_count {
  1996. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1997. return
  1998. }
  1999. }
  2000. }
  2001. } else {
  2002. if prescribingNumberUnit == drug.MaxUnit {
  2003. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2004. num := prescribing_number * float64(drug.MinNumber)
  2005. if drug.IsUse != 1 {
  2006. if num > all_count {
  2007. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2008. return
  2009. }
  2010. if adminInfo.CurrentOrgId == 10215 {
  2011. if prescribing_number > batch_number_all_count {
  2012. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2013. return
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. //修改处方
  2021. if advicelist.ID > 0 {
  2022. //查询最新批次库存
  2023. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2024. var batch_number_count int64
  2025. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2026. var device_number int64
  2027. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2028. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2029. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2030. device_number = prescribingNumberInt * drug.MinNumber
  2031. }
  2032. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2033. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2034. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2035. device_number = prescribingNumberInt
  2036. }
  2037. var number_count int64
  2038. if prescribingNumberUnit == drug.MaxUnit {
  2039. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2040. number_count = prescribingNumberInt * drug.MinNumber
  2041. }
  2042. if prescribingNumberUnit == drug.MinUnit {
  2043. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2044. number_count = prescribingNumberInt
  2045. }
  2046. //如果修改的数量大于之前修改的数量
  2047. if (number_count - device_number) > 0 {
  2048. //如果修改的差数量 大于库存数量
  2049. if drug.IsUse != 1 {
  2050. if (number_count - device_number) > total_count {
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2052. return
  2053. }
  2054. if adminInfo.CurrentOrgId == 10215 {
  2055. if (number_count - device_number) > batch_number_count {
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2057. return
  2058. }
  2059. }
  2060. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2061. //查询历史出库数据总批次
  2062. // 查询该药品最后一次出库记录
  2063. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2064. var out_count int64
  2065. var in_count int64
  2066. var stock_max_number int64
  2067. var stock_min_number int64
  2068. for _, it := range outInfo {
  2069. if it.CountUnit == drug.MaxUnit {
  2070. it.Count = it.Count * drug.MinNumber
  2071. }
  2072. out_count += it.Count
  2073. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2074. stock_max_number = warehouseInfoList.StockMaxNumber
  2075. stock_min_number = warehouseInfoList.StockMinNumber
  2076. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2077. }
  2078. if out_count > 0 {
  2079. if (number_count - device_number) > in_count {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. // 未出库
  2085. if out_count == 0 {
  2086. var sum_in_count int64
  2087. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2088. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2089. //如果修改的数量大于有库存的第一个批次
  2090. if number_count > sum_in_count {
  2091. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2092. return
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. //校验耗材库存
  2109. if goodOutConfig.IsOpen == 1 {
  2110. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2111. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2112. if len(prescriptions) > 0 {
  2113. for _, item := range prescriptions {
  2114. items := item.(map[string]interface{})
  2115. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2116. projects := items["project"].([]interface{})
  2117. if len(projects) > 0 {
  2118. for _, project := range projects {
  2119. var project_id int64
  2120. var project_type int64
  2121. var totals float64
  2122. var project_name string
  2123. var parsetotal int64
  2124. var id int64
  2125. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2126. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2127. }
  2128. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2129. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2130. }
  2131. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2132. total, _ := project.(map[string]interface{})["total"].(string)
  2133. totals, _ = strconv.ParseFloat(total, 64)
  2134. }
  2135. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2136. project_name = project.(map[string]interface{})["project_name"].(string)
  2137. }
  2138. if project_type == 3 {
  2139. //查找该耗材的出库记录
  2140. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2141. if len(goodWarehouseInfo) == 0 {
  2142. //查询耗材库存
  2143. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2144. var stock_count int64
  2145. for _, it := range list {
  2146. stock_count += it.StockCount
  2147. }
  2148. stock_counts := strconv.FormatInt(stock_count, 10)
  2149. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2150. if totals > stock_total_count {
  2151. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2152. return
  2153. }
  2154. }
  2155. if len(goodWarehouseInfo) > 0 {
  2156. //查询该患者耗材的历史数据
  2157. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2158. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2159. //数量发生改变
  2160. if parsetotal != count {
  2161. //如果现在的数量大于历史数量,就要看库存是否足够
  2162. if parsetotal > count {
  2163. //查询耗材所有库存
  2164. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2165. var stock_count int64
  2166. for _, it := range list {
  2167. stock_count += it.StockCount
  2168. }
  2169. //库存不足
  2170. if (parsetotal - count) > stock_count {
  2171. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2172. return
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. //不使用耗材保存处方出库
  2186. if goodOutConfig.IsOpen != 1 {
  2187. if stockConfig.IsOpen == 1 {
  2188. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2189. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2190. if len(prescriptions) > 0 {
  2191. for _, item := range prescriptions {
  2192. items := item.(map[string]interface{})
  2193. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2194. projects := items["project"].([]interface{})
  2195. if len(projects) > 0 {
  2196. for _, project := range projects {
  2197. var project_id int64
  2198. var project_type int64
  2199. var totals float64
  2200. var project_name string
  2201. var parsetotal int64
  2202. var id int64
  2203. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2204. id = int64(project.(map[string]interface{})["id"].(float64))
  2205. }
  2206. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2207. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2208. }
  2209. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2210. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2211. }
  2212. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2213. total, _ := project.(map[string]interface{})["total"].(string)
  2214. totals, _ = strconv.ParseFloat(total, 64)
  2215. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2216. }
  2217. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2218. project_name = project.(map[string]interface{})["project_name"].(string)
  2219. }
  2220. if project_type == 3 {
  2221. //查找该耗材的出库记录
  2222. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2223. //没有出库记录
  2224. if len(goodWarehouseInfo) == 0 {
  2225. //查询耗材库存
  2226. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2227. var stock_count int64
  2228. for _, it := range list {
  2229. stock_count += it.StockCount
  2230. }
  2231. stock_counts := strconv.FormatInt(stock_count, 10)
  2232. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2233. if totals > stock_total_count {
  2234. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2235. return
  2236. }
  2237. //查找今日该患者已经出库的所有耗材
  2238. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2239. for _, item := range goodList {
  2240. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2241. var flush_count int64
  2242. for _, it := range goodListSix {
  2243. flush_count += it.StockCount
  2244. }
  2245. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2246. creater := adminInfo.AdminUser.Id
  2247. if errs != nil {
  2248. goodErrcode := models.XtGoodErrcode{
  2249. UserOrgId: item.OrgId,
  2250. Errcode: "手动出库更新剩余出库失败",
  2251. GoodId: item.GoodId,
  2252. Status: 1,
  2253. Ctime: time.Now().Unix(),
  2254. Mtime: 0,
  2255. Count: 0,
  2256. StockCount: 0,
  2257. Creater: creater,
  2258. BatchNumberId: 0,
  2259. WarehouseOutId: 0,
  2260. }
  2261. service.CreateGoodErrcode(goodErrcode)
  2262. }
  2263. }
  2264. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2265. }
  2266. //有出库记录
  2267. if len(goodWarehouseInfo) > 0 {
  2268. //查询该患者耗材的历史数据
  2269. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2270. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2271. //数量发生改变
  2272. if parsetotal != count {
  2273. //查找今日该患者已经出库的所有耗材
  2274. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2275. for _, item := range goodList {
  2276. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2277. var flush_count int64
  2278. for _, it := range goodListSix {
  2279. flush_count += it.StockCount
  2280. }
  2281. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2282. //减少出库数量
  2283. creater := adminInfo.AdminUser.Id
  2284. if errs != nil {
  2285. goodErrcode := models.XtGoodErrcode{
  2286. UserOrgId: item.OrgId,
  2287. Errcode: "手动出库更新剩余出库失败",
  2288. GoodId: item.GoodId,
  2289. Status: 1,
  2290. Ctime: time.Now().Unix(),
  2291. Mtime: 0,
  2292. Count: 0,
  2293. StockCount: 0,
  2294. Creater: creater,
  2295. BatchNumberId: 0,
  2296. WarehouseOutId: 0,
  2297. }
  2298. service.CreateGoodErrcode(goodErrcode)
  2299. }
  2300. //查询默认仓库
  2301. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2302. var total_count int64
  2303. for _, it := range stockList {
  2304. total_count += it.StockCount
  2305. }
  2306. //基础库插入数据
  2307. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2308. }
  2309. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2310. }
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2322. var hpInfo models.HisPrescriptionInfo
  2323. if info.ID == 0 {
  2324. var randNum int
  2325. randNum = rand.Intn(10000) + 1000
  2326. timestamp := time.Now().Unix()
  2327. tempTime := time.Unix(timestamp, 0)
  2328. timeFormat := tempTime.Format("20060102150405")
  2329. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2330. hpInfo = models.HisPrescriptionInfo{
  2331. HisPatientId: his_patient_id,
  2332. UserOrgId: adminInfo.CurrentOrgId,
  2333. RecordDate: theTime.Unix(),
  2334. PatientId: patient_id,
  2335. Status: 1,
  2336. Ctime: time.Now().Unix(),
  2337. Mtime: time.Now().Unix(),
  2338. Creator: adminInfo.AdminUser.Id,
  2339. Modifier: adminInfo.AdminUser.Id,
  2340. Diagnosis: diagnose,
  2341. SickHistory: sick_history,
  2342. Departments: department,
  2343. RegisterType: reg_type,
  2344. PrescriptionNumber: p_number,
  2345. PrescriptionStatus: 1,
  2346. Doctor: role.UserName,
  2347. DoctorId: doctor_id,
  2348. SickType: sick_type,
  2349. PType: p_type,
  2350. PatientDiagnosis: patient_diagnose,
  2351. }
  2352. service.SavePatientPrescriptionInfo(hpInfo)
  2353. //创建步骤表
  2354. finish := models.XtDialysisFinish{
  2355. IsFinish: 1,
  2356. UserOrgId: adminInfo.CurrentOrgId,
  2357. Status: 1,
  2358. Ctime: time.Now().Unix(),
  2359. Mtime: 0,
  2360. Module: 4,
  2361. RecordDate: theTime.Unix(),
  2362. Sourse: 1,
  2363. PatientId: patient_id,
  2364. }
  2365. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2366. if dialysisFinish.ID == 0 {
  2367. service.CreateDialysisFinish(finish)
  2368. }
  2369. redis := service.RedisClient()
  2370. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2371. redis.Set(key, "", time.Second)
  2372. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2373. redis.Set(keyOne, "", time.Second)
  2374. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2375. redis.Set(keySeven, "", time.Second)
  2376. defer redis.Close()
  2377. } else {
  2378. hpInfo = models.HisPrescriptionInfo{
  2379. ID: info.ID,
  2380. UserOrgId: adminInfo.CurrentOrgId,
  2381. RecordDate: info.RecordDate,
  2382. PatientId: info.PatientId,
  2383. Status: 1,
  2384. Ctime: info.Ctime,
  2385. Mtime: time.Now().Unix(),
  2386. Creator: info.Creator,
  2387. Modifier: adminInfo.AdminUser.Id,
  2388. Diagnosis: diagnose,
  2389. SickHistory: sick_history,
  2390. Departments: department,
  2391. RegisterType: reg_type,
  2392. PrescriptionNumber: info.PrescriptionNumber,
  2393. Doctor: role.UserName,
  2394. PrescriptionStatus: info.PrescriptionStatus,
  2395. DoctorId: doctor_id,
  2396. SickType: sick_type,
  2397. PType: info.PType,
  2398. HisPatientId: info.HisPatientId,
  2399. PatientDiagnosis: patient_diagnose,
  2400. }
  2401. service.SavePatientPrescriptionInfo(hpInfo)
  2402. //创建步骤表
  2403. finish := models.XtDialysisFinish{
  2404. IsFinish: 1,
  2405. UserOrgId: adminInfo.CurrentOrgId,
  2406. Status: 1,
  2407. Ctime: time.Now().Unix(),
  2408. Mtime: 0,
  2409. Module: 4,
  2410. RecordDate: info.RecordDate,
  2411. Sourse: 1,
  2412. PatientId: info.PatientId,
  2413. }
  2414. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2415. if dialysisFinish.ID == 0 {
  2416. service.CreateDialysisFinish(finish)
  2417. }
  2418. redis := service.RedisClient()
  2419. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2420. redis.Set(key, "", time.Second)
  2421. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2422. redis.Set(keyOne, "", time.Second)
  2423. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2424. redis.Set(keySeven, "", time.Second)
  2425. defer redis.Close()
  2426. }
  2427. //定义切片
  2428. var adviceList []models.HisDoctorAdviceInfo
  2429. var projectList []models.HisPrescriptionProject
  2430. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2431. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2432. var tempPrescription *models.HisPrescription
  2433. if len(prescriptions) > 0 {
  2434. for _, item := range prescriptions {
  2435. items := item.(map[string]interface{})
  2436. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2437. utils.ErrorLog("id")
  2438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2439. return
  2440. }
  2441. id := int64(items["id"].(float64))
  2442. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2443. tempPrescription = &new_prescription
  2444. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2445. utils.ErrorLog("type")
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2447. return
  2448. }
  2449. types := int64(items["type"].(float64))
  2450. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2451. utils.ErrorLog("med_type")
  2452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2453. return
  2454. }
  2455. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2456. if med_type == "0" {
  2457. med_type = "14"
  2458. }
  2459. //if order_status == 0 {
  2460. // order_status = 1
  2461. //}
  2462. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2463. utils.ErrorLog("pre_time")
  2464. }
  2465. preTime, _ := items["pre_time"].(string)
  2466. timeLayout := "2006-01-02"
  2467. loc, _ := time.LoadLocation("Local")
  2468. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2469. if err != nil {
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2471. return
  2472. }
  2473. pTime := theTime2.Unix()
  2474. ctime := time.Now().Unix()
  2475. if tempPrescription.ID == 0 {
  2476. prescription := &models.HisPrescription{
  2477. ID: 0,
  2478. PatientId: patient_id,
  2479. UserOrgId: adminInfo.CurrentOrgId,
  2480. RecordDate: recordDateTime,
  2481. Ctime: ctime,
  2482. Mtime: ctime,
  2483. Type: types,
  2484. Modifier: adminInfo.AdminUser.Id,
  2485. Creator: adminInfo.AdminUser.Id,
  2486. Status: 1,
  2487. Doctor: role.UserName,
  2488. HisPatientId: his_patient_id,
  2489. OrderStatus: 1,
  2490. BatchNumber: "",
  2491. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2492. PreTime: pTime,
  2493. PType: p_type,
  2494. MedType: med_type,
  2495. }
  2496. tempPrescription = prescription
  2497. service.SaveHisPrescription(tempPrescription)
  2498. redis := service.RedisClient()
  2499. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2500. redis.Set(key, "", time.Second)
  2501. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2502. redis.Set(keyOne, "", time.Second)
  2503. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2504. redis.Set(keySeven, "", time.Second)
  2505. defer redis.Close()
  2506. } else {
  2507. tempPrescription.ID = id
  2508. tempPrescription.Type = types
  2509. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2510. tempPrescription.Mtime = time.Now().Unix()
  2511. tempPrescription.Doctor = role.UserName
  2512. //tempPrescription.OrderStatus = order_status
  2513. tempPrescription.PreTime = pTime
  2514. tempPrescription.MedType = med_type
  2515. service.SaveHisPrescription(tempPrescription)
  2516. redis := service.RedisClient()
  2517. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2518. redis.Set(key, "", time.Second)
  2519. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2520. redis.Set(keyOne, "", time.Second)
  2521. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2522. redis.Set(keySeven, "", time.Second)
  2523. defer redis.Close()
  2524. }
  2525. //service.SaveHisPrescription(prescription)
  2526. //更改患者挂号状态
  2527. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2528. fmt.Println("更改失败", err2)
  2529. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2530. advices := items["advices"].([]interface{})
  2531. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2532. groupNo := int64(0)
  2533. ctime := time.Now().Unix()
  2534. mtime := ctime
  2535. if len(advices) > 0 {
  2536. for _, advice := range advices {
  2537. var s models.HisDoctorAdviceInfo
  2538. s.PrescriptionId = tempPrescription.ID
  2539. s.AdviceType = 2
  2540. s.AdviceDoctor = doctor_id
  2541. s.StopState = 2
  2542. s.ExecutionState = 2
  2543. s.AdviceDate = recordDateTime
  2544. s.Status = 1
  2545. s.UserOrgId = adminInfo.CurrentOrgId
  2546. s.RecordDate = recordDateTime
  2547. s.StartTime = tempPrescription.PreTime
  2548. s.Groupno = groupNo
  2549. s.CreatedTime = ctime
  2550. s.UpdatedTime = mtime
  2551. s.PatientId = patient_id
  2552. s.HisPatientId = his_patient_id
  2553. s.StartTime = pTime
  2554. s.IsSettle = 2
  2555. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2556. if errcode > 0 {
  2557. c.ServeFailJSONWithSGJErrorCode(errcode)
  2558. return
  2559. }
  2560. s.StartTime = pTime
  2561. var total_count int64 //处方总库存
  2562. //查询改药品信息
  2563. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2564. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2565. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2566. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2567. total_count += prescribingNumberSeven * medical.MinNumber
  2568. }
  2569. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2570. total_count += prescribingNumberSeven
  2571. }
  2572. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2573. total_count += prescribingNumberSeven
  2574. }
  2575. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2576. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2577. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2578. if s.Price != lastWarehouse.RetailPrice {
  2579. s.Price = lastWarehouse.RetailPrice
  2580. }
  2581. if s.Price == 0 {
  2582. s.Price = lastWarehouse.RetailPrice
  2583. }
  2584. }
  2585. service.CreateHisDoctorAdvice(&s)
  2586. //记录日志
  2587. byterequest, _ := json.Marshal(s)
  2588. adviceLog := models.XtDoctorAdviceLog{
  2589. UserOrgId: s.UserOrgId,
  2590. PatientId: s.PatientId,
  2591. AdminUserId: adminInfo.AdminUser.Id,
  2592. Module: 1,
  2593. ErrLog: string(byterequest),
  2594. Status: 1,
  2595. Ctime: time.Now().Unix(),
  2596. Mtime: 0,
  2597. Source: "电脑端新建his医嘱",
  2598. RecordDate: s.AdviceDate,
  2599. }
  2600. service.CreateDoctorAdviceLog(adviceLog)
  2601. //存储切片中
  2602. adviceList = append(adviceList, s)
  2603. redis := service.RedisClient()
  2604. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2605. redis.Set(key, "", time.Second)
  2606. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2607. redis.Set(keyOne, "", time.Second)
  2608. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2609. redis.Set(keySeven, "", time.Second)
  2610. var randNum int
  2611. randNum = rand.Intn(10000) + 1000
  2612. timestamp := time.Now().Unix()
  2613. tempTime := time.Unix(timestamp, 0)
  2614. timeFormat := tempTime.Format("20060102150405")
  2615. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2616. service.CreateHisDoctorAdvice(&s)
  2617. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2618. redis.Set(keySix, "", time.Second)
  2619. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2620. redis.Set(keyFive, "", time.Second)
  2621. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2622. redis.Set(keyEight, "", time.Second)
  2623. defer redis.Close()
  2624. }
  2625. }
  2626. }
  2627. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2628. projects := items["project"].([]interface{})
  2629. if len(projects) > 0 {
  2630. for _, project := range projects {
  2631. var p models.HisPrescriptionProject
  2632. p.PrescriptionId = tempPrescription.ID
  2633. p.Ctime = time.Now().Unix()
  2634. p.Mtime = time.Now().Unix()
  2635. p.PatientId = patient_id
  2636. p.RecordDate = recordDateTime
  2637. p.Doctor = doctor_id
  2638. p.UserOrgId = adminInfo.CurrentOrgId
  2639. p.HisPatientId = his_patient_id
  2640. p.Status = 1
  2641. p.StartTime = pTime
  2642. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2643. if errcode > 0 {
  2644. c.ServeFailJSONWithSGJErrorCode(errcode)
  2645. return
  2646. }
  2647. if p.ID == 0 {
  2648. p.IsOut = 2
  2649. }
  2650. if p.ID > 0 {
  2651. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2652. p.IsOut = projectDetail.IsOut
  2653. }
  2654. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2655. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2656. if p.Type == 3 {
  2657. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2658. if p.Price != lastWarehouse.PackingPrice {
  2659. p.Price = lastWarehouse.PackingPrice
  2660. }
  2661. if p.Unit == "" {
  2662. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2663. p.Unit = goodInfoOne.PackingUnit
  2664. }
  2665. }
  2666. }
  2667. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2668. //
  2669. // if p.Type == 3 {
  2670. // //查询该耗材是否停用
  2671. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2672. // //表示该耗材已经停用,不能保存
  2673. // if goodInfoSeven.ID == 0 {
  2674. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2675. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2676. // return
  2677. // }
  2678. // }
  2679. //
  2680. //}
  2681. service.CreateHisProjectTwo(&p)
  2682. //记录日志
  2683. byterequest, _ := json.Marshal(p)
  2684. adviceLog := models.XtDoctorAdviceLog{
  2685. UserOrgId: p.UserOrgId,
  2686. PatientId: p.PatientId,
  2687. AdminUserId: adminInfo.AdminUser.Id,
  2688. Module: 1,
  2689. ErrLog: string(byterequest),
  2690. Status: 1,
  2691. Ctime: time.Now().Unix(),
  2692. Mtime: 0,
  2693. Source: "电脑端新建his项目",
  2694. RecordDate: p.RecordDate,
  2695. }
  2696. service.CreateDoctorAdviceLog(adviceLog)
  2697. projectList = append(projectList, p)
  2698. var randNum int
  2699. randNum = rand.Intn(10000) + 1000
  2700. timestamp := time.Now().Unix()
  2701. tempTime := time.Unix(timestamp, 0)
  2702. timeFormat := tempTime.Format("20060102150405")
  2703. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2704. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2705. //新增或者编辑项目,修改对应的标签数据
  2706. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2707. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2708. var label models.HisLabelPrintInfo
  2709. project, _ := service.GetProjectDetail(p.ProjectId)
  2710. if project.CostClassify == 3 { //类别为检验检查
  2711. if p.TeamId > 0 { //检验检查组套
  2712. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2713. if tempLabel.ID == 0 {
  2714. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2715. label.Number = tempPrescription.PrescriptionNumber
  2716. label.ProjectId = project.ID
  2717. label.Status = 1
  2718. label.IsPrint = 2
  2719. label.DoctorId = info.DoctorId
  2720. label.UserOrgId = p.UserOrgId
  2721. label.PatientId = patient_id
  2722. label.RecordDate = recordDateTime
  2723. label.Ctime = time.Now().Unix()
  2724. label.Mtime = time.Now().Unix()
  2725. label.ItemId = p.TeamId
  2726. label.FeedetlSn = p.FeedetlSn
  2727. label.PProjectId = p.ID
  2728. label.ProjectName = team.ProjectTeam
  2729. label.PatientName = patient.Name
  2730. service.CreateHisLabelRecord(&label)
  2731. }
  2732. } else { //单条检验检查项目
  2733. label.Number = tempPrescription.PrescriptionNumber
  2734. label.ProjectId = project.ID
  2735. label.Status = 1
  2736. label.DoctorId = info.DoctorId
  2737. label.UserOrgId = p.UserOrgId
  2738. label.PatientId = patient_id
  2739. label.RecordDate = recordDateTime
  2740. label.IsPrint = 2
  2741. label.Ctime = time.Now().Unix()
  2742. label.Mtime = time.Now().Unix()
  2743. label.FeedetlSn = p.FeedetlSn
  2744. label.PProjectId = p.ID
  2745. label.ItemId = p.TeamId
  2746. label.ProjectName = project.ProjectName
  2747. label.PatientName = patient.Name
  2748. service.CreateHisLabelRecord(&label)
  2749. }
  2750. }
  2751. }
  2752. }
  2753. service.SaveHisProjectTwo(&p)
  2754. }
  2755. }
  2756. }
  2757. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2758. // addition := items["addition"].([]interface{})
  2759. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2760. // ctime := time.Now().Unix()
  2761. // mtime := ctime
  2762. // if len(addition) > 0 {
  2763. // for _, item := range addition {
  2764. // var s models.HisAdditionalCharge
  2765. // s.PrescriptionId = tempPrescription.ID
  2766. // s.Status = 1
  2767. // s.UserOrgId = adminInfo.CurrentOrgId
  2768. // s.RecordDate = recordDateTime
  2769. // s.CreatedTime = ctime
  2770. // s.UpdatedTime = mtime
  2771. // s.PatientId = patient_id
  2772. // s.HisPatientId = his_patient_id
  2773. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2774. // if errcode > 0 {
  2775. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2776. // return
  2777. // }
  2778. // service.CreateAdditionalCharge(&s)
  2779. // var randNum int
  2780. // randNum = rand.Intn(10000) + 1000
  2781. // timestamp := time.Now().Unix()
  2782. // tempTime := time.Unix(timestamp, 0)
  2783. // timeFormat := tempTime.Format("20060102150405")
  2784. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2785. // service.CreateAdditionalCharge(&s)
  2786. //
  2787. // }
  2788. // }
  2789. //}
  2790. }
  2791. }
  2792. //查询今日该患者开的药品处方
  2793. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2794. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2795. //药品出库
  2796. if drugOutConfig.IsOpen == 1 {
  2797. for _, item := range hisdoctorlist {
  2798. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2799. // 查询该药品最后一次出库记录
  2800. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2801. if len(druginfo) > 0 {
  2802. //回退库存
  2803. for _, it := range druginfo {
  2804. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2805. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2806. }
  2807. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2808. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2809. }
  2810. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2811. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2812. }
  2813. }
  2814. }
  2815. //删除记录
  2816. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2817. //查询最后一次数据
  2818. if drugOutConfig.IsOpen == 1 {
  2819. //出库
  2820. if drug.IsUse == 2 {
  2821. creater := adminInfo.AdminUser.Id
  2822. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2823. }
  2824. //更新字典里面的库存
  2825. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2826. var sum_count int64
  2827. for _, its := range stockInfo {
  2828. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2829. if its.MaxUnit == baseDrug.MaxUnit {
  2830. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2831. }
  2832. sum_count += its.StockMaxNumber + its.StockMinNumber
  2833. }
  2834. //更新基础库存
  2835. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2836. //剩余库存
  2837. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2838. }
  2839. }
  2840. }
  2841. //耗材保存处方出库
  2842. if goodOutConfig.IsOpen == 1 {
  2843. //查询今日耗材出库数量
  2844. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2845. for _, item := range hisgoodlist {
  2846. //查询历史出库数据
  2847. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2848. var out_count_five int64
  2849. for _, item := range flowGood {
  2850. out_count_five += item.Count
  2851. }
  2852. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2853. if out_count_five != parseIntCount {
  2854. //查询耗材最后一次出库记录
  2855. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2856. //查询默认出库仓库库存
  2857. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2858. if len(wareOut) > 0 {
  2859. for _, it := range wareOut {
  2860. //回退库存
  2861. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2862. //删除出库记录
  2863. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2864. }
  2865. }
  2866. timeStr := time.Now().Format("2006-01-02")
  2867. timeArr := strings.Split(timeStr, "-")
  2868. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2869. total = total + 1
  2870. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2871. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2872. number = number + total
  2873. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2874. operation_time := time.Now().Unix()
  2875. creater := c.GetAdminUserInfo().AdminUser.Id
  2876. recordDateStr := time.Now().Format("2006-01-02")
  2877. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2878. nowtime := recordDate.Unix()
  2879. warehouseOut := models.WarehouseOut{
  2880. WarehouseOutOrderNumber: warehousing_out_order,
  2881. OperationTime: operation_time,
  2882. OrgId: adminInfo.CurrentOrgId,
  2883. Creater: creater,
  2884. Ctime: time.Now().Unix(),
  2885. Status: 1,
  2886. WarehouseOutTime: nowtime,
  2887. Type: 1,
  2888. StorehouseId: storeConfig.StorehouseOutInfo,
  2889. IsCheck: 1,
  2890. IsSys: 1,
  2891. }
  2892. //查询是否生成出库单
  2893. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2894. if out.ID == 0 {
  2895. service.AddSigleWarehouseOut(&warehouseOut)
  2896. }
  2897. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2898. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2899. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2900. dialyPrepareOne := models.DialysisBeforePrepare{
  2901. GoodTypeId: goodObj.GoodTypeId,
  2902. GoodId: item.ProjectId,
  2903. PatientId: item.PatientId,
  2904. RecordDate: item.RecordDate,
  2905. UserOrgId: adminInfo.CurrentOrgId,
  2906. Count: parseIntCount,
  2907. Ctime: time.Now().Unix(),
  2908. Creater: creater,
  2909. Status: 1,
  2910. StorehouseId: houseConfig.StorehouseOutInfo,
  2911. ProjectId: item.ID,
  2912. }
  2913. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2914. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2915. //查询历史出库数据
  2916. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2917. var out_count int64
  2918. for _, item := range flowGood {
  2919. out_count += item.Count
  2920. }
  2921. //如果历史数和当前数据不想等才进行退库出库
  2922. if out_count != parseIntCount {
  2923. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2924. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2925. detail := models.AutomaticReduceDetail{
  2926. WarehouseOutId: 0,
  2927. WarehouseOutOrderNumber: "",
  2928. PatientId: item.PatientId,
  2929. Ctime: time.Now().Unix(),
  2930. Mtime: 0,
  2931. Status: 1,
  2932. RecordTime: item.RecordDate,
  2933. OrgId: item.UserOrgId,
  2934. GoodId: item.ProjectId,
  2935. GoodTypeId: 0,
  2936. Count: parseIntCount,
  2937. Type: 0,
  2938. ProjectId: item.ID,
  2939. StorehouseId: 0,
  2940. }
  2941. service.CreateAutoDetail(detail)
  2942. //查询剩余库存
  2943. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2944. var sum_count int64
  2945. for _, item := range goodList {
  2946. sum_count += item.StockCount
  2947. }
  2948. //更新剩余库存
  2949. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2950. //耗材
  2951. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2952. }
  2953. }
  2954. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2955. //查询历史出库数据
  2956. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2957. var out_count int64
  2958. for _, item := range flowGood {
  2959. out_count += item.Count
  2960. }
  2961. //如果历史数和当前数据不想等才进行退库出库
  2962. if out_count != parseIntCount {
  2963. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2964. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2965. detail := models.AutomaticReduceDetail{
  2966. WarehouseOutId: 0,
  2967. WarehouseOutOrderNumber: "",
  2968. PatientId: item.PatientId,
  2969. Ctime: time.Now().Unix(),
  2970. Mtime: 0,
  2971. Status: 1,
  2972. RecordTime: item.RecordDate,
  2973. OrgId: item.UserOrgId,
  2974. GoodId: item.ProjectId,
  2975. GoodTypeId: 0,
  2976. Count: parseIntCount,
  2977. Type: 0,
  2978. ProjectId: item.ID,
  2979. StorehouseId: 0,
  2980. }
  2981. service.CreateAutoDetail(detail)
  2982. //查询剩余库存
  2983. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2984. var sum_count int64
  2985. for _, item := range goodList {
  2986. sum_count += item.StockCount
  2987. }
  2988. //更新剩余库存
  2989. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2990. //耗材
  2991. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2992. }
  2993. }
  2994. }
  2995. }
  2996. }
  2997. }
  2998. //redisClient := service.RedisClient()
  2999. //defer redisClient.Close()
  3000. //
  3001. //list := models.HisList{
  3002. // Patient_id: patient_id,
  3003. // Advice_id:0,
  3004. // Record_date: 0,
  3005. // Advice: adviceList,
  3006. // Project: nil,
  3007. //}
  3008. //hisLis = append(hisLis, list)
  3009. //
  3010. //advice_json, _ := json.Marshal(&hisLis)
  3011. //redisClient.RPush("111", advice_json).Result()
  3012. //result, _ := redisClient.RPop("111").Result()
  3013. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3014. //
  3015. //var dat []map[string]interface{}
  3016. //json.Unmarshal([]byte(result), &dat)
  3017. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3018. //
  3019. //for k,v:=range dat{
  3020. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3021. //}
  3022. //project_json, _ := json.Marshal(&projectList)
  3023. //redisClient.LPush("222", project_json).Result()
  3024. if err == nil {
  3025. c.ServeSuccessJSON(map[string]interface{}{
  3026. "msg": "保存成功",
  3027. })
  3028. return
  3029. } else {
  3030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3031. return
  3032. }
  3033. }
  3034. func (c *HisApiController) EditHisPrescription() {
  3035. record_date := c.GetString("record_date")
  3036. patient_id, _ := c.GetInt64("patient_id")
  3037. reg_type, _ := c.GetInt64("reg_type")
  3038. //diagnose, _ := c.GetInt64("diagnose", 0)
  3039. diagnose := c.GetString("diagnose")
  3040. sick_type, _ := c.GetInt64("sick_type")
  3041. sick_history := c.GetString("sick_history")
  3042. doctor_id, _ := c.GetInt64("doctor", 0)
  3043. department, _ := c.GetInt64("department", 0)
  3044. his_patient_id, _ := c.GetInt64("his_patient_id")
  3045. p_type, _ := c.GetInt64("p_type")
  3046. dataBody := make(map[string]interface{}, 0)
  3047. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3048. if err != nil {
  3049. utils.ErrorLog(err.Error())
  3050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3051. return
  3052. }
  3053. timeLayout := "2006-01-02"
  3054. loc, _ := time.LoadLocation("Local")
  3055. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3056. if err != nil {
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. adminInfo := c.GetAdminUserInfo()
  3061. recordDateTime := theTime.Unix()
  3062. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3063. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3064. var hpInfo models.HisPrescriptionInfo
  3065. if info.ID == 0 {
  3066. var randNum int
  3067. randNum = rand.Intn(10000) + 1000
  3068. timestamp := time.Now().Unix()
  3069. tempTime := time.Unix(timestamp, 0)
  3070. timeFormat := tempTime.Format("20060102150405")
  3071. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3072. hpInfo = models.HisPrescriptionInfo{
  3073. UserOrgId: adminInfo.CurrentOrgId,
  3074. RecordDate: theTime.Unix(),
  3075. PatientId: patient_id,
  3076. Status: 1,
  3077. Ctime: time.Now().Unix(),
  3078. Mtime: time.Now().Unix(),
  3079. Creator: adminInfo.AdminUser.Id,
  3080. Modifier: adminInfo.AdminUser.Id,
  3081. Diagnosis: diagnose,
  3082. SickHistory: sick_history,
  3083. Departments: department,
  3084. RegisterType: reg_type,
  3085. PrescriptionNumber: p_number,
  3086. PrescriptionStatus: 1,
  3087. Doctor: role.UserName,
  3088. DoctorId: doctor_id,
  3089. SickType: sick_type,
  3090. PType: p_type,
  3091. }
  3092. service.SavePatientPrescriptionInfo(hpInfo)
  3093. } else {
  3094. hpInfo = models.HisPrescriptionInfo{
  3095. ID: info.ID,
  3096. UserOrgId: adminInfo.CurrentOrgId,
  3097. RecordDate: info.RecordDate,
  3098. PatientId: info.PatientId,
  3099. Status: 1,
  3100. Ctime: info.Ctime,
  3101. Mtime: time.Now().Unix(),
  3102. Creator: info.Creator,
  3103. Modifier: adminInfo.AdminUser.Id,
  3104. Diagnosis: diagnose,
  3105. SickHistory: sick_history,
  3106. Departments: department,
  3107. RegisterType: reg_type,
  3108. PrescriptionNumber: info.PrescriptionNumber,
  3109. Doctor: role.UserName,
  3110. PrescriptionStatus: info.PrescriptionStatus,
  3111. DoctorId: doctor_id,
  3112. SickType: sick_type,
  3113. PType: info.PType,
  3114. }
  3115. service.SavePatientPrescriptionInfo(hpInfo)
  3116. }
  3117. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3118. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3119. if len(prescriptions) > 0 {
  3120. for _, item := range prescriptions {
  3121. items := item.(map[string]interface{})
  3122. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3123. utils.ErrorLog("id")
  3124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3125. return
  3126. }
  3127. id := int64(items["id"].(float64))
  3128. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3129. utils.ErrorLog("type")
  3130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3131. return
  3132. }
  3133. types := int64(items["type"].(float64))
  3134. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3135. utils.ErrorLog("med_type")
  3136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3137. return
  3138. }
  3139. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3140. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3141. ctime := time.Now().Unix()
  3142. prescription := &models.HisPrescription{
  3143. ID: id,
  3144. PatientId: patient_id,
  3145. UserOrgId: adminInfo.CurrentOrgId,
  3146. RecordDate: recordDateTime,
  3147. Ctime: ctime,
  3148. Mtime: ctime,
  3149. Type: types,
  3150. Modifier: adminInfo.AdminUser.Id,
  3151. Creator: adminInfo.AdminUser.Id,
  3152. Status: 1,
  3153. Doctor: role.UserName,
  3154. HisPatientId: his_patient_id,
  3155. OrderStatus: 1,
  3156. BatchNumber: "",
  3157. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3158. PType: hpInfo.PType,
  3159. MedType: med_type,
  3160. }
  3161. if historyPrescription.ID > 0 {
  3162. prescription.PreTime = historyPrescription.PreTime
  3163. }
  3164. service.SaveHisPrescription(prescription)
  3165. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3166. advices := items["advices"].([]interface{})
  3167. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3168. groupNo := int64(0)
  3169. ctime := time.Now().Unix()
  3170. mtime := ctime
  3171. if len(advices) > 0 {
  3172. for _, advice := range advices {
  3173. var s models.HisDoctorAdviceInfo
  3174. s.PrescriptionId = prescription.ID
  3175. s.AdviceType = 2
  3176. s.AdviceDoctor = adminInfo.AdminUser.Id
  3177. s.StopState = 2
  3178. s.ExecutionState = 2
  3179. s.AdviceDate = recordDateTime
  3180. s.Status = 1
  3181. s.UserOrgId = adminInfo.CurrentOrgId
  3182. s.RecordDate = recordDateTime
  3183. s.StartTime = prescription.PreTime
  3184. s.Groupno = groupNo
  3185. s.CreatedTime = ctime
  3186. s.UpdatedTime = mtime
  3187. s.PatientId = patient_id
  3188. s.HisPatientId = his_patient_id
  3189. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3190. if errcode > 0 {
  3191. c.ServeFailJSONWithSGJErrorCode(errcode)
  3192. return
  3193. }
  3194. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3195. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3196. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3197. if s.Price == 0 {
  3198. s.Price = lastWarehouse.RetailPrice
  3199. }
  3200. }
  3201. service.CreateHisDoctorAdvice(&s)
  3202. //记录日志
  3203. byterequest, _ := json.Marshal(s)
  3204. adviceLog := models.XtDoctorAdviceLog{
  3205. UserOrgId: s.UserOrgId,
  3206. PatientId: s.PatientId,
  3207. AdminUserId: adminInfo.AdminUser.Id,
  3208. Module: 1,
  3209. ErrLog: string(byterequest),
  3210. Status: 1,
  3211. Ctime: time.Now().Unix(),
  3212. Mtime: 0,
  3213. Source: "电脑端his医嘱修改",
  3214. RecordDate: s.AdviceDate,
  3215. }
  3216. service.CreateDoctorAdviceLog(adviceLog)
  3217. redis := service.RedisClient()
  3218. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3219. redis.Set(key, "", time.Second)
  3220. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3221. fmt.Println("keyOne", keyOne)
  3222. redis.Set(keyOne, "", time.Second)
  3223. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3224. redis.Set(keySeven, "", time.Second)
  3225. redis.Close()
  3226. }
  3227. }
  3228. }
  3229. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3230. projects := items["project"].([]interface{})
  3231. if len(projects) > 0 {
  3232. for _, project := range projects {
  3233. var p models.HisPrescriptionProject
  3234. p.PrescriptionId = prescription.ID
  3235. p.Ctime = time.Now().Unix()
  3236. p.Mtime = time.Now().Unix()
  3237. p.PatientId = patient_id
  3238. p.RecordDate = recordDateTime
  3239. p.UserOrgId = adminInfo.CurrentOrgId
  3240. p.HisPatientId = his_patient_id
  3241. p.Status = 1
  3242. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3243. if errcode > 0 {
  3244. c.ServeFailJSONWithSGJErrorCode(errcode)
  3245. return
  3246. }
  3247. service.CreateHisProjectTwo(&p)
  3248. //记录日志
  3249. byterequest, _ := json.Marshal(p)
  3250. adviceLog := models.XtDoctorAdviceLog{
  3251. UserOrgId: p.UserOrgId,
  3252. PatientId: p.PatientId,
  3253. AdminUserId: adminInfo.AdminUser.Id,
  3254. Module: 1,
  3255. ErrLog: string(byterequest),
  3256. Status: 1,
  3257. Ctime: time.Now().Unix(),
  3258. Mtime: 0,
  3259. Source: "电脑端his项目修改",
  3260. RecordDate: p.RecordDate,
  3261. }
  3262. service.CreateDoctorAdviceLog(adviceLog)
  3263. }
  3264. }
  3265. }
  3266. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3267. addition := items["addition"].([]interface{})
  3268. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3269. ctime := time.Now().Unix()
  3270. mtime := ctime
  3271. if len(addition) > 0 {
  3272. for _, item := range addition {
  3273. var s models.HisAdditionalCharge
  3274. s.PrescriptionId = prescription.ID
  3275. s.Status = 1
  3276. s.UserOrgId = adminInfo.CurrentOrgId
  3277. s.RecordDate = recordDateTime
  3278. s.CreatedTime = ctime
  3279. s.UpdatedTime = mtime
  3280. s.PatientId = patient_id
  3281. s.HisPatientId = his_patient_id
  3282. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3283. if errcode > 0 {
  3284. c.ServeFailJSONWithSGJErrorCode(errcode)
  3285. return
  3286. }
  3287. service.CreateAdditionalCharge(&s)
  3288. }
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. if err == nil {
  3295. c.ServeSuccessJSON(map[string]interface{}{
  3296. "msg": "保存成功",
  3297. })
  3298. return
  3299. } else {
  3300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3301. return
  3302. }
  3303. }
  3304. func (c *HisApiController) DeletePrescription() {
  3305. prescription_id, _ := c.GetInt64("id")
  3306. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3307. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3308. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3309. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3310. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3311. //耗材保存处方出库
  3312. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3313. //已收费和已发药限制逻辑
  3314. isCharge := false
  3315. isMedicine := false
  3316. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3317. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3318. for _, item := range new_prescriptions {
  3319. if item.IsMedicine == 1 {
  3320. isMedicine = true
  3321. }
  3322. }
  3323. for _, item := range new_prescriptions {
  3324. if item.OrderStatus == 4 {
  3325. isCharge = true
  3326. }
  3327. }
  3328. if p_err != nil {
  3329. if new_prescription.ID > 0 {
  3330. if new_prescription.OrderStatus == 2 {
  3331. isCharge = true
  3332. }
  3333. }
  3334. }
  3335. for _, item := range advices {
  3336. if item.IsMedicine == 1 {
  3337. isMedicine = true
  3338. }
  3339. }
  3340. if isCharge {
  3341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3342. return
  3343. }
  3344. if isMedicine {
  3345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3346. return
  3347. }
  3348. //已收费和已发药限制逻辑
  3349. if len(projects) > 0 {
  3350. for _, item := range projects {
  3351. service.DeletePrintInfo(item.ID) //删除打印信息
  3352. if goodOutConfig.IsOpen != 1 {
  3353. if stockConfig.IsOpen == 1 {
  3354. if item.Type == 3 && item.IsOut == 1 {
  3355. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3356. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3357. good.Total = good.Total + f_count
  3358. service.UpdateGoodInfo(&good)
  3359. operation_time := time.Now().Unix()
  3360. creater := c.GetAdminUserInfo().AdminUser.Id
  3361. //创建退库单
  3362. timeStr := time.Now().Format("2006-01-02")
  3363. timeArr := strings.Split(timeStr, "-")
  3364. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3365. total = total + 1
  3366. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3367. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3368. cancelStock := models.CancelStock{
  3369. OrderNumber: orderNumber,
  3370. OperaTime: operation_time,
  3371. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3372. Creater: creater,
  3373. Ctime: time.Now().Unix(),
  3374. Status: 1,
  3375. ReturnTime: item.RecordDate,
  3376. Type: 1,
  3377. StorehouseId: houseConfig.StorehouseOutInfo,
  3378. IsCheck: 1,
  3379. }
  3380. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3381. if msgerrkonde == gorm.ErrRecordNotFound {
  3382. service.AddSigleCancelStock(&cancelStock)
  3383. }
  3384. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3385. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3386. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3387. //查询该耗材是否出库
  3388. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3389. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3390. deaerler, _ := service.GetDealerById(info.Dealer)
  3391. var total_count int64
  3392. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3393. total_count += count
  3394. if info.ID > 0 {
  3395. if info.Count >= total_count {
  3396. //回退库存
  3397. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3398. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3399. var flush_count int64
  3400. for _, it := range goodList {
  3401. flush_count += it.StockCount
  3402. }
  3403. cancelStockInfo := models.CancelStockInfo{
  3404. GoodId: item.ProjectId,
  3405. CancelStockId: cancel.ID,
  3406. GoodTypeId: good.GoodTypeId,
  3407. Count: prescribingNumber,
  3408. Price: info.Price,
  3409. Total: 0,
  3410. ProductDate: info.ProductDate,
  3411. ExpiryDate: info.ExpiryDate,
  3412. Ctime: time.Now().Unix(),
  3413. Status: 1,
  3414. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3415. OrderNumber: cancel.OrderNumber,
  3416. Type: 0,
  3417. Dealer: deaerler.DealerName,
  3418. Manufacturer: manufacturer.ManufacturerName,
  3419. Number: info.Number,
  3420. RegisterAccount: "",
  3421. Remark: "",
  3422. WarehouseInfoId: info.WarehouseInfotId,
  3423. PatientId: info.PatientId,
  3424. RecordDate: info.SysRecordTime,
  3425. StorehouseId: houseConfig.StorehouseOutInfo,
  3426. IsCheck: 1,
  3427. }
  3428. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3429. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3430. flow := models.VmStockFlow{
  3431. WarehousingId: info.WarehouseInfotId,
  3432. GoodId: item.ProjectId,
  3433. Number: info.Number,
  3434. LicenseNumber: info.LicenseNumber,
  3435. Count: prescribingNumber,
  3436. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3437. PatientId: item.PatientId,
  3438. SystemTime: info.SysRecordTime,
  3439. ConsumableType: 7,
  3440. IsSys: 0,
  3441. WarehousingOrder: "",
  3442. WarehouseOutId: info.WarehouseOutId,
  3443. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3444. IsEdit: 0,
  3445. CancelStockId: cancel.ID,
  3446. CancelOrderNumber: cancel.OrderNumber,
  3447. Manufacturer: manufacturer.ID,
  3448. Dealer: 0,
  3449. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3450. UpdateCreator: 0,
  3451. Status: 1,
  3452. Ctime: time.Now().Unix(),
  3453. Mtime: 0,
  3454. Price: info.Price,
  3455. WarehousingDetailId: info.WarehouseInfotId,
  3456. WarehouseOutDetailId: info.ID,
  3457. CancelOutDetailId: cancelInfo.ID,
  3458. ProductDate: info.ProductDate,
  3459. ExpireDate: info.ExpiryDate,
  3460. StorehouseId: houseConfig.StorehouseOutInfo,
  3461. OverCount: flush_count,
  3462. }
  3463. service.CreateStockFlowOne(flow)
  3464. //退库数量增加
  3465. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3466. //出库数量减少
  3467. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3468. }
  3469. if info.Count < total_count {
  3470. //回退库存
  3471. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3472. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3473. var flush_count int64
  3474. for _, it := range goodList {
  3475. flush_count += it.StockCount
  3476. }
  3477. cancelStockInfo := models.CancelStockInfo{
  3478. GoodId: item.ProjectId,
  3479. CancelStockId: cancel.ID,
  3480. GoodTypeId: good.GoodTypeId,
  3481. Count: info.Count,
  3482. Price: info.Price,
  3483. Total: 0,
  3484. ProductDate: info.ProductDate,
  3485. ExpiryDate: info.ExpiryDate,
  3486. Ctime: time.Now().Unix(),
  3487. Status: 1,
  3488. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3489. OrderNumber: cancel.OrderNumber,
  3490. Type: 0,
  3491. Dealer: deaerler.DealerName,
  3492. Manufacturer: manufacturer.ManufacturerName,
  3493. Number: info.Number,
  3494. RegisterAccount: "",
  3495. Remark: "",
  3496. WarehouseInfoId: info.WarehouseInfotId,
  3497. PatientId: info.PatientId,
  3498. RecordDate: info.SysRecordTime,
  3499. StorehouseId: houseConfig.StorehouseOutInfo,
  3500. IsCheck: 1,
  3501. }
  3502. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3503. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3504. flow := models.VmStockFlow{
  3505. WarehousingId: info.WarehouseInfotId,
  3506. GoodId: item.ProjectId,
  3507. Number: info.Number,
  3508. LicenseNumber: info.LicenseNumber,
  3509. Count: info.Count,
  3510. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3511. PatientId: item.PatientId,
  3512. SystemTime: info.SysRecordTime,
  3513. ConsumableType: 7,
  3514. IsSys: 0,
  3515. WarehousingOrder: "",
  3516. WarehouseOutId: info.WarehouseOutId,
  3517. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3518. IsEdit: 0,
  3519. CancelStockId: cancel.ID,
  3520. CancelOrderNumber: cancel.OrderNumber,
  3521. Manufacturer: manufacturer.ID,
  3522. Dealer: 0,
  3523. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3524. UpdateCreator: 0,
  3525. Status: 1,
  3526. Ctime: time.Now().Unix(),
  3527. Mtime: 0,
  3528. Price: info.Price,
  3529. WarehousingDetailId: info.WarehouseInfotId,
  3530. WarehouseOutDetailId: info.ID,
  3531. CancelOutDetailId: cancelInfo.ID,
  3532. ProductDate: info.ProductDate,
  3533. ExpireDate: info.ExpiryDate,
  3534. StorehouseId: houseConfig.StorehouseOutInfo,
  3535. OverCount: flush_count,
  3536. }
  3537. service.CreateStockFlowOne(flow)
  3538. //退库数量增加
  3539. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3540. //出库数量减少
  3541. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3542. }
  3543. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3544. var flush_count int64
  3545. for _, it := range goodList {
  3546. flush_count += it.StockCount
  3547. }
  3548. //查询已出库数量
  3549. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3550. if prescribingNumber < dialysisInfo.Count {
  3551. //改变数量
  3552. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3553. }
  3554. if prescribingNumber >= dialysisInfo.Count {
  3555. //删除出库表
  3556. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3557. }
  3558. //更新库存
  3559. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3560. //更新基础库库存
  3561. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3562. }
  3563. }
  3564. }
  3565. }
  3566. //保存耗材出库
  3567. if goodOutConfig.IsOpen == 1 {
  3568. if item.Type == 3 {
  3569. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3570. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3571. good.Total = good.Total + f_count
  3572. service.UpdateGoodInfo(&good)
  3573. operation_time := time.Now().Unix()
  3574. creater := c.GetAdminUserInfo().AdminUser.Id
  3575. //创建退库单
  3576. timeStr := time.Now().Format("2006-01-02")
  3577. timeArr := strings.Split(timeStr, "-")
  3578. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3579. total = total + 1
  3580. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3581. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3582. cancelStock := models.CancelStock{
  3583. OrderNumber: orderNumber,
  3584. OperaTime: operation_time,
  3585. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3586. Creater: creater,
  3587. Ctime: time.Now().Unix(),
  3588. Status: 1,
  3589. ReturnTime: item.RecordDate,
  3590. Type: 1,
  3591. StorehouseId: houseConfig.StorehouseOutInfo,
  3592. IsCheck: 1,
  3593. }
  3594. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3595. if msgerrkonde == gorm.ErrRecordNotFound {
  3596. service.AddSigleCancelStock(&cancelStock)
  3597. }
  3598. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3599. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3600. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3601. //查询该耗材是否出库
  3602. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3603. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3604. deaerler, _ := service.GetDealerById(info.Dealer)
  3605. var total_count int64
  3606. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3607. total_count += count
  3608. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3609. var flush_count int64
  3610. for _, it := range goodList {
  3611. flush_count += it.StockCount
  3612. }
  3613. fmt.Println("历史出库数据", info.Count)
  3614. fmt.Println("出库数量", total_count)
  3615. if info.ID > 0 {
  3616. cancelStockInfo := models.CancelStockInfo{
  3617. GoodId: item.ProjectId,
  3618. CancelStockId: cancel.ID,
  3619. GoodTypeId: good.GoodTypeId,
  3620. Count: prescribingNumber,
  3621. Price: info.Price,
  3622. Total: 0,
  3623. ProductDate: info.ProductDate,
  3624. ExpiryDate: info.ExpiryDate,
  3625. Ctime: time.Now().Unix(),
  3626. Status: 1,
  3627. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3628. OrderNumber: cancel.OrderNumber,
  3629. Type: 0,
  3630. Dealer: deaerler.DealerName,
  3631. Manufacturer: manufacturer.ManufacturerName,
  3632. Number: info.Number,
  3633. RegisterAccount: "",
  3634. Remark: "",
  3635. WarehouseInfoId: info.WarehouseInfotId,
  3636. PatientId: info.PatientId,
  3637. RecordDate: info.SysRecordTime,
  3638. StorehouseId: houseConfig.StorehouseOutInfo,
  3639. IsCheck: 1,
  3640. }
  3641. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3642. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3643. //查询出库数量
  3644. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3645. //出库数据 大于 退库数量
  3646. if len(list) > 0 {
  3647. for _, it := range list {
  3648. //回退库存
  3649. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3650. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3651. var flush_count_one int64
  3652. for _, it := range goodList {
  3653. flush_count_one += it.StockCount
  3654. }
  3655. //查询该批次是否有退库数据
  3656. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3657. creater := c.GetAdminUserInfo().AdminUser.Id
  3658. flow := models.VmStockFlow{
  3659. WarehousingId: it.WarehouseInfotId,
  3660. GoodId: it.GoodId,
  3661. Number: it.Number,
  3662. LicenseNumber: it.LicenseNumber,
  3663. Count: it.Count,
  3664. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3665. PatientId: it.PatientId,
  3666. SystemTime: it.SysRecordTime,
  3667. ConsumableType: 7,
  3668. IsSys: 0,
  3669. WarehousingOrder: "",
  3670. WarehouseOutId: it.WarehouseOutId,
  3671. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3672. IsEdit: 0,
  3673. CancelStockId: cancel.ID,
  3674. CancelOrderNumber: cancel.OrderNumber,
  3675. Manufacturer: manufacturer.ID,
  3676. Dealer: 0,
  3677. Creator: creater,
  3678. UpdateCreator: 0,
  3679. Status: 1,
  3680. Ctime: time.Now().Unix(),
  3681. Mtime: 0,
  3682. Price: it.Price,
  3683. WarehousingDetailId: it.WarehouseInfotId,
  3684. WarehouseOutDetailId: it.ID,
  3685. CancelOutDetailId: cancelInfo.ID,
  3686. ProductDate: it.ProductDate,
  3687. ExpireDate: it.ExpiryDate,
  3688. StorehouseId: houseConfig.StorehouseOutInfo,
  3689. OverCount: flush_count_one,
  3690. }
  3691. service.CreateStockFlowOne(flow)
  3692. //if flow.ID > 0 {
  3693. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3694. //}
  3695. }
  3696. }
  3697. //flow := models.VmStockFlow{
  3698. // WarehousingId: info.WarehouseInfotId,
  3699. // GoodId: item.ProjectId,
  3700. // Number: info.Number,
  3701. // LicenseNumber: info.LicenseNumber,
  3702. // Count: prescribingNumber,
  3703. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3704. // PatientId: item.PatientId,
  3705. // SystemTime: info.SysRecordTime,
  3706. // ConsumableType: 7,
  3707. // IsSys: 0,
  3708. // WarehousingOrder: "",
  3709. // WarehouseOutId: info.WarehouseOutId,
  3710. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3711. // IsEdit: 0,
  3712. // CancelStockId: cancel.ID,
  3713. // CancelOrderNumber: cancel.OrderNumber,
  3714. // Manufacturer: manufacturer.ID,
  3715. // Dealer: 0,
  3716. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3717. // UpdateCreator: 0,
  3718. // Status: 1,
  3719. // Ctime: time.Now().Unix(),
  3720. // Mtime: 0,
  3721. // Price: info.Price,
  3722. // WarehousingDetailId: info.WarehouseInfotId,
  3723. // WarehouseOutDetailId: info.ID,
  3724. // CancelOutDetailId: cancelInfo.ID,
  3725. // ProductDate: info.ProductDate,
  3726. // ExpireDate: info.ExpiryDate,
  3727. // StorehouseId: houseConfig.StorehouseOutInfo,
  3728. // OverCount: flush_count,
  3729. //}
  3730. //service.CreateStockFlowOne(flow)
  3731. //退库数量增加
  3732. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3733. //出库数量减少
  3734. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3735. //查询已出库数量
  3736. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3737. if prescribingNumber < dialysisInfo.Count {
  3738. //改变数量
  3739. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3740. }
  3741. if prescribingNumber >= dialysisInfo.Count {
  3742. //删除出库表
  3743. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3744. }
  3745. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3746. var flush_count_one int64
  3747. for _, it := range goodList {
  3748. flush_count_one += it.StockCount
  3749. }
  3750. //更新库存
  3751. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3752. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3753. //更新基础库库存
  3754. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3755. }
  3756. }
  3757. }
  3758. }
  3759. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3760. fmt.Println(err)
  3761. }
  3762. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3763. fmt.Println(err)
  3764. if len(advices) > 0 {
  3765. for _, item := range advices {
  3766. redis := service.RedisClient()
  3767. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3768. redis.Set(keyFive, "", time.Second)
  3769. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3770. redis.Set(keyOne, "", time.Second)
  3771. redis.Close()
  3772. }
  3773. }
  3774. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3775. if len(advices) > 0 {
  3776. for _, item := range advices {
  3777. creater := c.GetAdminUserInfo().AdminUser.Id
  3778. service.DrugAutoAddCancelInfo(item, creater)
  3779. }
  3780. }
  3781. } else {
  3782. if drugOutConfig.IsOpen == 1 {
  3783. if len(advices) > 0 {
  3784. for _, item := range advices {
  3785. creater := c.GetAdminUserInfo().AdminUser.Id
  3786. service.DrugAutoAddCancelInfo(item, creater)
  3787. }
  3788. }
  3789. } else {
  3790. if len(advices) > 0 {
  3791. for _, item := range advices {
  3792. creater := c.GetAdminUserInfo().AdminUser.Id
  3793. service.DrugAutoAddCancelInfo(item, creater)
  3794. }
  3795. }
  3796. }
  3797. }
  3798. c.ServeSuccessJSON(map[string]interface{}{
  3799. "msg": "删除成功",
  3800. })
  3801. return
  3802. }
  3803. func (c *HisApiController) DeleteDoctorAdvice() {
  3804. id, _ := c.GetInt64("id")
  3805. advice, _ := service.GetHisDoctorAdvicesById(id)
  3806. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3807. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3808. //已收费和已发药的限制逻辑
  3809. isCharge := false
  3810. isMedicine := false
  3811. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3812. //获取今天该患者所有处方,判断是否发药或者收费
  3813. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3814. for _, item := range new_prescriptions {
  3815. if item.IsMedicine == 1 {
  3816. isMedicine = true
  3817. }
  3818. }
  3819. for _, item := range new_prescriptions {
  3820. if item.OrderStatus == 4 {
  3821. isCharge = true
  3822. }
  3823. }
  3824. if isMedicine {
  3825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3826. return
  3827. }
  3828. if isCharge {
  3829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3830. return
  3831. }
  3832. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3833. for _, item := range advices {
  3834. if item.IsMedicine == 1 {
  3835. isMedicine = true
  3836. }
  3837. }
  3838. if isMedicine {
  3839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3840. return
  3841. }
  3842. if new_prescription.ID > 0 {
  3843. if new_prescription.OrderStatus == 2 {
  3844. isCharge = true
  3845. }
  3846. }
  3847. if isCharge {
  3848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3849. return
  3850. }
  3851. //已收费和已发药的限制逻辑
  3852. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3853. redis := service.RedisClient()
  3854. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3855. redis.Set(keyFive, "", time.Second)
  3856. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3857. redis.Set(keyOne, "", time.Second)
  3858. defer redis.Close()
  3859. if err == nil {
  3860. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3861. //查询是否在处方中出库
  3862. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3863. if openConfig.IsOpen != 1 {
  3864. //判断该医嘱是否执行了
  3865. if advice.ExecutionState == 1 {
  3866. creater := c.GetAdminUserInfo().AdminUser.Id
  3867. service.DrugAutoAddCancelInfo(&advice, creater)
  3868. }
  3869. }
  3870. //开启保存处方扣减功能
  3871. if openConfig.IsOpen == 1 {
  3872. creater := c.GetAdminUserInfo().AdminUser.Id
  3873. service.DrugAutoAddCancelInfo(&advice, creater)
  3874. }
  3875. } else {
  3876. if drugOutConfig.IsOpen == 1 {
  3877. //查询是否在处方中出库
  3878. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3879. if openConfig.IsOpen != 1 {
  3880. //判断该医嘱是否执行了
  3881. if advice.ExecutionState == 1 {
  3882. creater := c.GetAdminUserInfo().AdminUser.Id
  3883. service.DrugAutoAddCancelInfo(&advice, creater)
  3884. }
  3885. }
  3886. //开启保存处方扣减功能
  3887. if openConfig.IsOpen == 1 {
  3888. creater := c.GetAdminUserInfo().AdminUser.Id
  3889. service.DrugAutoAddCancelInfo(&advice, creater)
  3890. }
  3891. } else {
  3892. //判断该医嘱是否执行了
  3893. if advice.ExecutionState == 1 {
  3894. creater := c.GetAdminUserInfo().AdminUser.Id
  3895. service.DrugAutoAddCancelInfo(&advice, creater)
  3896. }
  3897. }
  3898. }
  3899. c.ServeSuccessJSON(map[string]interface{}{
  3900. "msg": "删除成功",
  3901. })
  3902. return
  3903. } else {
  3904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3905. return
  3906. }
  3907. }
  3908. func (c *HisApiController) DeleteProject() {
  3909. id, _ := c.GetInt64("id")
  3910. adminInfo := c.GetAdminUserInfo()
  3911. project, _ := service.GetHisProjectByID(id)
  3912. // var consumable models.DialysisBeforePrepare
  3913. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3914. //耗材保存处方出库
  3915. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3916. isCharge := false
  3917. isMedicine := false
  3918. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3919. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3920. for _, item := range new_prescriptions {
  3921. if item.IsMedicine == 1 {
  3922. isMedicine = true
  3923. }
  3924. }
  3925. for _, item := range new_prescriptions {
  3926. if item.OrderStatus == 4 {
  3927. isCharge = true
  3928. }
  3929. }
  3930. if isMedicine {
  3931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3932. return
  3933. }
  3934. if isCharge {
  3935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3936. return
  3937. }
  3938. if new_prescription.ID > 0 {
  3939. if new_prescription.OrderStatus == 2 {
  3940. isCharge = true
  3941. }
  3942. }
  3943. if isCharge {
  3944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3945. return
  3946. }
  3947. service.DeletePrintInfo(id)
  3948. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3949. label.Status = 0
  3950. service.CreateHisLabelRecord(&label)
  3951. fmt.Println(goodOutConfig.IsOpen)
  3952. if goodOutConfig.IsOpen != 1 {
  3953. if stockConfig.IsOpen == 1 {
  3954. if project.Type == 2 {
  3955. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3956. fmt.Println(err)
  3957. }
  3958. if project.Type == 3 && project.IsOut == 1 {
  3959. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3960. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3961. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3962. operation_time := time.Now().Unix()
  3963. creater := adminInfo.AdminUser.Id
  3964. //创建退库单
  3965. timeStr := time.Now().Format("2006-01-02")
  3966. timeArr := strings.Split(timeStr, "-")
  3967. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3968. total = total + 1
  3969. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3970. cancelStock := models.CancelStock{
  3971. OrderNumber: orderNumber,
  3972. OperaTime: operation_time,
  3973. OrgId: adminInfo.CurrentOrgId,
  3974. Creater: creater,
  3975. Ctime: time.Now().Unix(),
  3976. Status: 1,
  3977. ReturnTime: project.RecordDate,
  3978. Type: 1,
  3979. StorehouseId: houseConfig.StorehouseOutInfo,
  3980. IsCheck: 1,
  3981. }
  3982. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3983. if msgerrkonde == gorm.ErrRecordNotFound {
  3984. service.AddSigleCancelStock(&cancelStock)
  3985. }
  3986. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3987. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3988. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3989. //查询是否有出库
  3990. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3991. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3992. deaerler, _ := service.GetDealerById(info.Dealer)
  3993. if info.ID > 0 {
  3994. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3995. if info.Count >= prescribingNumber {
  3996. cancelStockInfo := models.CancelStockInfo{
  3997. GoodId: project.ProjectId,
  3998. CancelStockId: cancel.ID,
  3999. GoodTypeId: good.GoodTypeId,
  4000. Count: prescribingNumber,
  4001. Price: info.Price,
  4002. Total: 0,
  4003. ProductDate: info.ProductDate,
  4004. ExpiryDate: info.ExpiryDate,
  4005. Ctime: time.Now().Unix(),
  4006. Status: 1,
  4007. OrgId: adminInfo.CurrentOrgId,
  4008. OrderNumber: cancel.OrderNumber,
  4009. Type: 0,
  4010. Dealer: deaerler.DealerName,
  4011. Manufacturer: manufacturer.ManufacturerName,
  4012. Number: info.Number,
  4013. RegisterAccount: "",
  4014. Remark: "",
  4015. WarehouseInfoId: info.WarehouseInfotId,
  4016. PatientId: info.PatientId,
  4017. RecordDate: info.SysRecordTime,
  4018. StorehouseId: houseConfig.StorehouseOutInfo,
  4019. IsCheck: 1,
  4020. }
  4021. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4022. //回退库存
  4023. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4024. //退库数量增加
  4025. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4026. //出库数量减少
  4027. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4028. }
  4029. if info.Count < prescribingNumber {
  4030. cancelStockInfo := models.CancelStockInfo{
  4031. GoodId: project.ProjectId,
  4032. CancelStockId: cancel.ID,
  4033. GoodTypeId: good.GoodTypeId,
  4034. Count: info.Count,
  4035. Price: info.Price,
  4036. Total: 0,
  4037. ProductDate: info.ProductDate,
  4038. ExpiryDate: info.ExpiryDate,
  4039. Ctime: time.Now().Unix(),
  4040. Status: 1,
  4041. OrgId: adminInfo.CurrentOrgId,
  4042. OrderNumber: cancel.OrderNumber,
  4043. Type: 0,
  4044. Dealer: deaerler.DealerName,
  4045. Manufacturer: manufacturer.ManufacturerName,
  4046. Number: info.Number,
  4047. RegisterAccount: "",
  4048. Remark: "",
  4049. WarehouseInfoId: info.WarehouseInfotId,
  4050. PatientId: info.PatientId,
  4051. RecordDate: info.SysRecordTime,
  4052. StorehouseId: houseConfig.StorehouseOutInfo,
  4053. IsCheck: 1,
  4054. }
  4055. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4056. //回退库存
  4057. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4058. //退库数量增加
  4059. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4060. //出库数量减少
  4061. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4062. }
  4063. //查询剩余库存
  4064. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4065. var over_count int64
  4066. for _, it := range goodList {
  4067. over_count += it.StockCount
  4068. }
  4069. //出库数据 大于 退库数量
  4070. if info.Count >= prescribingNumber {
  4071. flow := models.VmStockFlow{
  4072. WarehousingId: info.WarehouseInfotId,
  4073. GoodId: project.ProjectId,
  4074. Number: info.Number,
  4075. LicenseNumber: info.LicenseNumber,
  4076. Count: prescribingNumber,
  4077. UserOrgId: adminInfo.CurrentOrgId,
  4078. PatientId: project.PatientId,
  4079. SystemTime: info.SysRecordTime,
  4080. ConsumableType: 7,
  4081. IsSys: 0,
  4082. WarehousingOrder: "",
  4083. WarehouseOutId: info.WarehouseOutId,
  4084. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4085. IsEdit: 0,
  4086. CancelStockId: cancel.ID,
  4087. CancelOrderNumber: cancel.OrderNumber,
  4088. Manufacturer: manufacturer.ID,
  4089. Dealer: 0,
  4090. Creator: adminInfo.AdminUser.Id,
  4091. UpdateCreator: 0,
  4092. Status: 1,
  4093. Ctime: time.Now().Unix(),
  4094. Mtime: 0,
  4095. Price: info.Price,
  4096. WarehousingDetailId: info.WarehouseInfotId,
  4097. WarehouseOutDetailId: info.ID,
  4098. CancelOutDetailId: cancelInfo.ID,
  4099. ProductDate: info.ProductDate,
  4100. ExpireDate: info.ExpiryDate,
  4101. StorehouseId: houseConfig.StorehouseOutInfo,
  4102. OverCount: over_count,
  4103. }
  4104. service.CreateStockFlowOne(flow)
  4105. }
  4106. //出库数据小于退库数据
  4107. if info.Count < prescribingNumber {
  4108. flow := models.VmStockFlow{
  4109. WarehousingId: info.WarehouseInfotId,
  4110. GoodId: project.ProjectId,
  4111. Number: info.Number,
  4112. LicenseNumber: info.LicenseNumber,
  4113. Count: info.Count,
  4114. UserOrgId: adminInfo.CurrentOrgId,
  4115. PatientId: project.PatientId,
  4116. SystemTime: info.SysRecordTime,
  4117. ConsumableType: 7,
  4118. IsSys: 0,
  4119. WarehousingOrder: "",
  4120. WarehouseOutId: info.WarehouseOutId,
  4121. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4122. IsEdit: 0,
  4123. CancelStockId: cancel.ID,
  4124. CancelOrderNumber: cancel.OrderNumber,
  4125. Manufacturer: manufacturer.ID,
  4126. Dealer: 0,
  4127. Creator: adminInfo.AdminUser.Id,
  4128. UpdateCreator: 0,
  4129. Status: 1,
  4130. Ctime: time.Now().Unix(),
  4131. Mtime: 0,
  4132. Price: info.Price,
  4133. WarehousingDetailId: info.WarehouseInfotId,
  4134. WarehouseOutDetailId: info.ID,
  4135. CancelOutDetailId: cancelInfo.ID,
  4136. ProductDate: info.ProductDate,
  4137. ExpireDate: info.ExpiryDate,
  4138. StorehouseId: houseConfig.StorehouseOutInfo,
  4139. OverCount: over_count,
  4140. }
  4141. service.CreateStockFlowOne(flow)
  4142. }
  4143. //查询已出库数量
  4144. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4145. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4146. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4147. if prescribingNumber < dialysisInfo.Count {
  4148. //改变数量
  4149. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4150. }
  4151. if prescribingNumber >= dialysisInfo.Count {
  4152. //删除出库表
  4153. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4154. }
  4155. //更新剩余库存
  4156. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4157. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4158. var total_count_one int64
  4159. for _, it := range stockList {
  4160. total_count_one += it.StockCount
  4161. }
  4162. //基础库插入数据
  4163. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4164. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4165. var flush_count int64
  4166. for _, it := range goodListOne {
  4167. flush_count += it.StockCount
  4168. }
  4169. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4170. if errs != nil {
  4171. goodErrcode := models.XtGoodErrcode{
  4172. UserOrgId: project.UserOrgId,
  4173. Errcode: "手动出库更新剩余出库失败",
  4174. GoodId: project.ProjectId,
  4175. Status: 1,
  4176. Ctime: time.Now().Unix(),
  4177. Mtime: 0,
  4178. Count: 0,
  4179. StockCount: 0,
  4180. Creater: creater,
  4181. BatchNumberId: 0,
  4182. WarehouseOutId: 0,
  4183. }
  4184. service.CreateGoodErrcode(goodErrcode)
  4185. }
  4186. }
  4187. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4188. fmt.Println(err)
  4189. } else {
  4190. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4191. fmt.Println(err)
  4192. }
  4193. } else {
  4194. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4195. fmt.Println(err)
  4196. }
  4197. }
  4198. //保存处方出库
  4199. if goodOutConfig.IsOpen == 1 {
  4200. if project.Type == 3 {
  4201. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4202. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4203. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4204. operation_time := time.Now().Unix()
  4205. creater := adminInfo.AdminUser.Id
  4206. //创建退库单
  4207. timeStr := time.Now().Format("2006-01-02")
  4208. timeArr := strings.Split(timeStr, "-")
  4209. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4210. total = total + 1
  4211. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4212. cancelStock := models.CancelStock{
  4213. OrderNumber: orderNumber,
  4214. OperaTime: operation_time,
  4215. OrgId: adminInfo.CurrentOrgId,
  4216. Creater: creater,
  4217. Ctime: time.Now().Unix(),
  4218. Status: 1,
  4219. ReturnTime: project.RecordDate,
  4220. Type: 1,
  4221. StorehouseId: houseConfig.StorehouseOutInfo,
  4222. IsCheck: 1,
  4223. }
  4224. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4225. if msgerrkonde == gorm.ErrRecordNotFound {
  4226. service.AddSigleCancelStock(&cancelStock)
  4227. }
  4228. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4229. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4230. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4231. //获取出库数据
  4232. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4233. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4234. deaerler, _ := service.GetDealerById(info.Dealer)
  4235. if info.ID > 0 {
  4236. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4237. if info.Count >= prescribingNumber {
  4238. cancelStockInfo := models.CancelStockInfo{
  4239. GoodId: project.ProjectId,
  4240. CancelStockId: cancel.ID,
  4241. GoodTypeId: good.GoodTypeId,
  4242. Count: prescribingNumber,
  4243. Price: info.Price,
  4244. Total: 0,
  4245. ProductDate: info.ProductDate,
  4246. ExpiryDate: info.ExpiryDate,
  4247. Ctime: time.Now().Unix(),
  4248. Status: 1,
  4249. OrgId: adminInfo.CurrentOrgId,
  4250. OrderNumber: cancel.OrderNumber,
  4251. Type: 0,
  4252. Dealer: deaerler.DealerName,
  4253. Manufacturer: manufacturer.ManufacturerName,
  4254. Number: info.Number,
  4255. RegisterAccount: "",
  4256. Remark: "",
  4257. WarehouseInfoId: info.WarehouseInfotId,
  4258. PatientId: info.PatientId,
  4259. RecordDate: info.SysRecordTime,
  4260. StorehouseId: houseConfig.StorehouseOutInfo,
  4261. IsCheck: 1,
  4262. }
  4263. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4264. //退库数量增加
  4265. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4266. //出库数量减少
  4267. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4268. }
  4269. if info.Count < prescribingNumber {
  4270. cancelStockInfo := models.CancelStockInfo{
  4271. GoodId: project.ProjectId,
  4272. CancelStockId: cancel.ID,
  4273. GoodTypeId: good.GoodTypeId,
  4274. Count: prescribingNumber,
  4275. Price: info.Price,
  4276. Total: 0,
  4277. ProductDate: info.ProductDate,
  4278. ExpiryDate: info.ExpiryDate,
  4279. Ctime: time.Now().Unix(),
  4280. Status: 1,
  4281. OrgId: adminInfo.CurrentOrgId,
  4282. OrderNumber: cancel.OrderNumber,
  4283. Type: 0,
  4284. Dealer: deaerler.DealerName,
  4285. Manufacturer: manufacturer.ManufacturerName,
  4286. Number: info.Number,
  4287. RegisterAccount: "",
  4288. Remark: "",
  4289. WarehouseInfoId: info.WarehouseInfotId,
  4290. PatientId: info.PatientId,
  4291. RecordDate: info.SysRecordTime,
  4292. StorehouseId: houseConfig.StorehouseOutInfo,
  4293. IsCheck: 1,
  4294. }
  4295. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4296. //回退库存
  4297. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4298. }
  4299. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4300. var over_count int64
  4301. for _, it := range goodList {
  4302. over_count += it.StockCount
  4303. }
  4304. //查询出库数量
  4305. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4306. //出库数据 大于 退库数量
  4307. if len(list) > 0 {
  4308. for _, it := range list {
  4309. //回退库存
  4310. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4311. //退库数量增加
  4312. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4313. //出库数量减少
  4314. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4315. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4316. var over_count_one int64
  4317. for _, it := range goodList {
  4318. over_count_one += it.StockCount
  4319. }
  4320. //查询该批次是否有退库数据
  4321. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4322. flow := models.VmStockFlow{
  4323. WarehousingId: it.WarehouseInfotId,
  4324. GoodId: it.GoodId,
  4325. Number: it.Number,
  4326. LicenseNumber: it.LicenseNumber,
  4327. Count: it.Count,
  4328. UserOrgId: adminInfo.CurrentOrgId,
  4329. PatientId: it.PatientId,
  4330. SystemTime: it.SysRecordTime,
  4331. ConsumableType: 7,
  4332. IsSys: 0,
  4333. WarehousingOrder: "",
  4334. WarehouseOutId: it.WarehouseOutId,
  4335. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4336. IsEdit: 0,
  4337. CancelStockId: cancel.ID,
  4338. CancelOrderNumber: cancel.OrderNumber,
  4339. Manufacturer: manufacturer.ID,
  4340. Dealer: 0,
  4341. Creator: adminInfo.AdminUser.Id,
  4342. UpdateCreator: 0,
  4343. Status: 1,
  4344. Ctime: time.Now().Unix(),
  4345. Mtime: 0,
  4346. Price: it.Price,
  4347. WarehousingDetailId: it.WarehouseInfotId,
  4348. WarehouseOutDetailId: it.ID,
  4349. CancelOutDetailId: cancelInfo.ID,
  4350. ProductDate: it.ProductDate,
  4351. ExpireDate: it.ExpiryDate,
  4352. StorehouseId: houseConfig.StorehouseOutInfo,
  4353. OverCount: over_count_one,
  4354. }
  4355. service.CreateStockFlowOne(flow)
  4356. }
  4357. }
  4358. //查询已出库数量
  4359. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4360. if prescribingNumber < dialysisInfo.Count {
  4361. //改变数量
  4362. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4363. }
  4364. if prescribingNumber >= dialysisInfo.Count {
  4365. //删除出库表
  4366. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4367. }
  4368. //更新剩余库存
  4369. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4370. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4371. var total_count_one int64
  4372. for _, it := range stockList {
  4373. total_count_one += it.StockCount
  4374. }
  4375. //基础库插入数据
  4376. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4377. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4378. var flush_count int64
  4379. for _, it := range goodListOne {
  4380. flush_count += it.StockCount
  4381. }
  4382. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4383. if errs != nil {
  4384. goodErrcode := models.XtGoodErrcode{
  4385. UserOrgId: project.UserOrgId,
  4386. Errcode: "手动出库更新剩余出库失败",
  4387. GoodId: project.ProjectId,
  4388. Status: 1,
  4389. Ctime: time.Now().Unix(),
  4390. Mtime: 0,
  4391. Count: 0,
  4392. StockCount: 0,
  4393. Creater: creater,
  4394. BatchNumberId: 0,
  4395. WarehouseOutId: 0,
  4396. }
  4397. service.CreateGoodErrcode(goodErrcode)
  4398. }
  4399. }
  4400. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4401. fmt.Println(err)
  4402. } else {
  4403. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4404. fmt.Println(err)
  4405. }
  4406. }
  4407. c.ServeSuccessJSON(map[string]interface{}{
  4408. "msg": "删除成功",
  4409. })
  4410. return
  4411. }
  4412. func (c *HisApiController) CreateHisAdditionalCharge() {
  4413. his_patient_id, _ := c.GetInt64("his_patient_id")
  4414. patient_id, _ := c.GetInt64("patient_id")
  4415. record_date := c.GetString("record_date")
  4416. timeLayout := "2006-01-02"
  4417. loc, _ := time.LoadLocation("Local")
  4418. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4419. if err != nil {
  4420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4421. return
  4422. }
  4423. adminInfo := c.GetAdminUserInfo()
  4424. recordDateTime := theTime.Unix()
  4425. dataBody := make(map[string]interface{}, 0)
  4426. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4427. if err != nil {
  4428. utils.ErrorLog(err.Error())
  4429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4430. return
  4431. }
  4432. var additions []*models.HisAdditionalCharge
  4433. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4434. additions, _ := dataBody["addition"].([]interface{})
  4435. if len(additions) > 0 {
  4436. for _, item := range additions {
  4437. items := item.(map[string]interface{})
  4438. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4439. utils.ErrorLog("item_id")
  4440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4441. return
  4442. }
  4443. item_id := int64(items["item_id"].(float64))
  4444. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4445. utils.ErrorLog("item_name")
  4446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4447. return
  4448. }
  4449. item_name := items["item_name"].(string)
  4450. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4451. utils.ErrorLog("price")
  4452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4453. return
  4454. }
  4455. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4456. ctime := time.Now().Unix()
  4457. additional := &models.HisAdditionalCharge{
  4458. PatientId: patient_id,
  4459. HisPatientId: his_patient_id,
  4460. UserOrgId: adminInfo.CurrentOrgId,
  4461. RecordDate: recordDateTime,
  4462. CreatedTime: ctime,
  4463. UpdatedTime: ctime,
  4464. Modifier: adminInfo.AdminUser.Id,
  4465. Creator: adminInfo.AdminUser.Id,
  4466. Price: price,
  4467. ItemName: item_name,
  4468. ItemId: item_id,
  4469. Status: 1,
  4470. }
  4471. additions = append(additions, additional)
  4472. }
  4473. }
  4474. }
  4475. for _, item := range additions {
  4476. service.CreateAddtionalCharge(item)
  4477. }
  4478. c.ServeSuccessJSON(map[string]interface{}{
  4479. "msg": "创建成功",
  4480. })
  4481. }
  4482. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4483. blood_fat := c.GetString("blood_fat")
  4484. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4485. blood_sugar := c.GetString("blood_sugar")
  4486. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4487. chief_conplaint := c.GetString("chief_conplaint")
  4488. dbp := c.GetString("dbp")
  4489. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4490. delivery_way, _ := c.GetInt64("delivery_way")
  4491. diagnostic := c.GetString("diagnostic")
  4492. family_history := c.GetString("family_history")
  4493. height := c.GetString("height")
  4494. history_of_present_illness := c.GetString("history_of_present_illness")
  4495. is_infect, _ := c.GetInt64("is_infect")
  4496. past_history := c.GetString("past_history")
  4497. patient_id, _ := c.GetInt64("patient_id")
  4498. his_patient_id, _ := c.GetInt64("his_patient_id")
  4499. personal_history := c.GetString("personal_history")
  4500. pulse := c.GetString("pulse")
  4501. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4502. sbp := c.GetString("sbp")
  4503. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4504. heightfloat, _ := strconv.ParseFloat(height, 64)
  4505. sicktype := c.GetString("sick_type")
  4506. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4507. symptom := c.GetString("symptom")
  4508. sick_date := c.GetString("sick_date")
  4509. temperatures := c.GetString("temperature")
  4510. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4511. record_date := c.GetString("record_date")
  4512. breathing := c.GetString("breathing")
  4513. doctor_advice := c.GetString("doctor_advice")
  4514. remark := c.GetString("remark")
  4515. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4516. sick, _ := c.GetInt64("sick")
  4517. diagnose, _ := c.GetInt64("diagnose")
  4518. //id, _ := c.GetInt64("id")
  4519. timeLayout := "2006-01-02"
  4520. loc, _ := time.LoadLocation("Local")
  4521. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4522. allergic_history := c.GetString("allergic_history")
  4523. if err != nil {
  4524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4525. return
  4526. }
  4527. recordDateTime := theTime.Unix()
  4528. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4529. if err != nil {
  4530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4531. return
  4532. }
  4533. sickTimes := sickTime.Unix()
  4534. ctime := time.Now().Unix()
  4535. primary_disease := c.GetString("primary_disease")
  4536. confirm_failure_date := c.GetString("confirm_failure_date")
  4537. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4538. drug_allergy_history := c.GetString("drug_allergy_history")
  4539. physical_examination := c.GetString("physical_examination")
  4540. special_inspection := c.GetString("special_inspection")
  4541. lab_apparatus := c.GetString("lab_apparatus")
  4542. caseHistory := models.HisPatientCaseHistory{
  4543. HisPatientId: his_patient_id,
  4544. PatientId: patient_id,
  4545. Temperature: temperature,
  4546. BloodSugar: bloodsugarfloat,
  4547. Pulse: pulsefloat,
  4548. Sbp: sbpfloat,
  4549. Dbp: dbpfloat,
  4550. Height: heightfloat,
  4551. BloodFat: bloodfatfloat,
  4552. SickType: sick_type,
  4553. Symptom: symptom,
  4554. SickDate: sickTimes,
  4555. IsInfect: is_infect,
  4556. HistoryOfPresentIllness: history_of_present_illness,
  4557. PastHistory: past_history,
  4558. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4559. ChiefConplaint: chief_conplaint,
  4560. PersonalHistory: personal_history,
  4561. FamilyHistory: family_history,
  4562. Diagnostic: diagnostic,
  4563. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4564. Status: 1,
  4565. Ctime: ctime,
  4566. Mtime: ctime,
  4567. RecordDate: recordDateTime,
  4568. DeliveryWay: delivery_way,
  4569. Breathing: breathingfloat,
  4570. DoctorAdvice: doctor_advice,
  4571. Remark: remark,
  4572. Sick: sick,
  4573. Diagnose: diagnose,
  4574. AllergicHistory: allergic_history,
  4575. PrimaryDisease: primary_disease,
  4576. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4577. DrugAllergyHistory: drug_allergy_history,
  4578. PhysicalExamination: physical_examination,
  4579. SpecialInspection: special_inspection,
  4580. LabApparatus: lab_apparatus,
  4581. }
  4582. //查询该患者是否有病历
  4583. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4584. if errcodes == gorm.ErrRecordNotFound {
  4585. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4586. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4587. if err != nil {
  4588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4589. return
  4590. }
  4591. c.ServeSuccessJSON(map[string]interface{}{
  4592. "caseHistory": caseHistory,
  4593. "historyInfo": historyInfo,
  4594. })
  4595. return
  4596. } else if errcodes == nil {
  4597. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4598. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4599. if err != nil {
  4600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4601. return
  4602. }
  4603. c.ServeSuccessJSON(map[string]interface{}{
  4604. "caseHistory": caseHistory,
  4605. "historyInfo": historyInfo,
  4606. })
  4607. }
  4608. //查询该患者是否有病历
  4609. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4610. //if errcode == gorm.ErrRecordNotFound {
  4611. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4612. // if err != nil {
  4613. // c.ServeSuccessJSON(map[string]interface{}{
  4614. // "msg": "保存成功",
  4615. // })
  4616. // }
  4617. //} else if errcode == nil {
  4618. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4619. // return
  4620. //}
  4621. }
  4622. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4623. patient_id, _ := c.GetInt64("patient_id", 0)
  4624. adminUser := c.GetAdminUserInfo()
  4625. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4626. c.ServeSuccessJSON(map[string]interface{}{
  4627. "list": caseHistorys,
  4628. })
  4629. }
  4630. func (c *HisApiController) GetHisPatientCaseHistory() {
  4631. record_date, _ := c.GetInt64("record_date", 0)
  4632. patient_id, _ := c.GetInt64("patient_id", 0)
  4633. admin := c.GetAdminUserInfo()
  4634. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4635. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4636. c.ServeSuccessJSON(map[string]interface{}{
  4637. "info": info,
  4638. "case_history": case_history,
  4639. })
  4640. }
  4641. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4642. template_name := c.GetString("template_name")
  4643. template_remark := c.GetString("template_remark")
  4644. doctor := c.GetAdminUserInfo().AdminUser.Id
  4645. diagnostic := c.GetString("diagnostic")
  4646. chief_conplaint := c.GetString("chief_conplain")
  4647. history_of_present_illness := c.GetString("history_of_present_illness")
  4648. past_history := c.GetString("past_history")
  4649. personal_history := c.GetString("personal_history")
  4650. family_history := c.GetString("family_history")
  4651. user_name := c.GetString("user_name")
  4652. doctor_advice := c.GetString("doctor_advice")
  4653. remark := c.GetString("remark")
  4654. //record_date := c.GetString("record_date")
  4655. //fmt.Println("record_date--------",record_date)
  4656. //timeLayout := "2006-01-02"
  4657. //loc, _ := time.LoadLocation("Local")
  4658. //
  4659. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4660. //if err != nil {
  4661. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4662. // return
  4663. //}
  4664. //recordDateTime := theTime.Unix()
  4665. ctime := time.Now().Unix()
  4666. template := models.HisCaseHistoryTemplate{
  4667. HistoryOfPresentIllness: history_of_present_illness,
  4668. PastHistory: past_history,
  4669. ChiefConplaint: chief_conplaint,
  4670. PersonalHistory: personal_history,
  4671. FamilyHistory: family_history,
  4672. Diagnostic: diagnostic,
  4673. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4674. Status: 1,
  4675. Ctime: ctime,
  4676. Mtime: ctime,
  4677. RecordDate: time.Now().Unix(),
  4678. TemplateName: template_name,
  4679. TemplateRemark: template_remark,
  4680. Creator: doctor,
  4681. Modifier: doctor,
  4682. UserName: user_name,
  4683. DoctorAdvice: doctor_advice,
  4684. Remark: remark,
  4685. }
  4686. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4687. if err == nil {
  4688. c.ServeSuccessJSON(map[string]interface{}{
  4689. "msg": "保存成功",
  4690. })
  4691. } else {
  4692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4693. return
  4694. }
  4695. }
  4696. func (c *HisApiController) GetCaseHistoryTemplate() {
  4697. timeLayout := "2006-01-02"
  4698. loc, _ := time.LoadLocation("Local")
  4699. keyword := c.GetString("keyword")
  4700. start_time := c.GetString("start_time")
  4701. end_time := c.GetString("end_time")
  4702. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4703. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4704. admin := c.GetAdminUserInfo()
  4705. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4706. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4707. c.ServeSuccessJSON(map[string]interface{}{
  4708. "template": template,
  4709. //"history": history,
  4710. })
  4711. }
  4712. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4713. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4714. utils.ErrorLog("drug_name")
  4715. return enums.ErrorCodeParamWrong
  4716. }
  4717. adviceName, _ := json["drug_name"].(string)
  4718. if len(adviceName) == 0 {
  4719. utils.ErrorLog("len(advice_name) == 0")
  4720. return enums.ErrorCodeParamWrong
  4721. }
  4722. advice.AdviceName = adviceName
  4723. adviceDesc, _ := json["advice_desc"].(string)
  4724. advice.AdviceDesc = adviceDesc
  4725. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4726. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4727. advice.DrugSpec = drugSpec
  4728. }
  4729. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4730. remark, _ := json["remark"].(string)
  4731. advice.Remark = remark
  4732. }
  4733. if json["id"] == nil {
  4734. advice.DrugId = 0
  4735. } else {
  4736. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4737. drug_id := int64(json["id"].(float64))
  4738. advice.DrugId = drug_id
  4739. }
  4740. }
  4741. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4742. advice_id := int64(json["advice_id"].(float64))
  4743. advice.ID = advice_id
  4744. if advice.ID > 0 {
  4745. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4746. if err == nil {
  4747. if hisAdvice.ID > 0 {
  4748. advice.ExecutionTime = hisAdvice.ExecutionTime
  4749. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4750. advice.ExecutionState = hisAdvice.ExecutionState
  4751. advice.CheckTime = hisAdvice.CheckTime
  4752. advice.Checker = hisAdvice.Checker
  4753. advice.CheckState = hisAdvice.CheckState
  4754. advice.StartTime = hisAdvice.StartTime
  4755. advice.FeedetlSn = hisAdvice.FeedetlSn
  4756. }
  4757. }
  4758. }
  4759. }
  4760. //
  4761. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4762. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4763. // advice.ExecutionTime = execution_time
  4764. //}
  4765. //
  4766. //
  4767. //
  4768. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4769. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4770. // advice.ExecutionStaff = execution_staff
  4771. //}
  4772. //
  4773. //
  4774. //
  4775. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4776. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4777. // advice.ExecutionState = execution_state
  4778. //}
  4779. //
  4780. //
  4781. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4782. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4783. // advice.CheckTime = check_time
  4784. //}
  4785. //
  4786. //
  4787. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4788. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4789. // advice.CheckState = check_state
  4790. //}
  4791. //
  4792. //
  4793. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4794. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4795. // advice.Checker = checker
  4796. //}
  4797. //
  4798. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4799. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4800. // advice.StartTime = start_time
  4801. //}
  4802. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4803. drugSpecUnit, _ := json["min_unit"].(string)
  4804. advice.DrugSpecUnit = drugSpecUnit
  4805. }
  4806. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4807. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4808. advice.SingleDose = singleDose
  4809. }
  4810. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4811. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4812. advice.SingleDoseUnit = singleDoseUnit
  4813. }
  4814. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4815. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4816. advice.PrescribingNumber = prescribingNumber
  4817. }
  4818. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4819. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4820. advice.PrescribingNumberUnit = prescribingNumberUnit
  4821. }
  4822. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4823. deliveryWay, _ := json["delivery_way"].(string)
  4824. advice.DeliveryWay = deliveryWay
  4825. }
  4826. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4827. executionFrequency, _ := json["execution_frequency"].(string)
  4828. advice.ExecutionFrequency = executionFrequency
  4829. }
  4830. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4831. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4832. advice.Price = price
  4833. }
  4834. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4835. med_list_codg, _ := json["medical_insurance_number"].(string)
  4836. advice.MedListCodg = med_list_codg
  4837. }
  4838. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4839. day := int64(json["day"].(float64))
  4840. advice.Day = day
  4841. }
  4842. return 0
  4843. }
  4844. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4845. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4846. id := int64(json["id"].(float64))
  4847. project.ID = id
  4848. historyProject, _ := service.GetHisProjectByID(id)
  4849. project.FeedetlSn = historyProject.FeedetlSn
  4850. }
  4851. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4852. project_id := int64(json["project_id"].(float64))
  4853. project.ProjectId = project_id
  4854. }
  4855. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4856. // price := int64(json["price"].(float64))
  4857. // formatInt_price := strconv.FormatInt(price, 10)
  4858. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4859. // project.Price = float_price
  4860. // }
  4861. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4862. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4863. project.Price = price
  4864. }
  4865. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4866. total, _ := json["total"].(string)
  4867. project.Count = total
  4868. }
  4869. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4870. medical_code, _ := json["medical_code"].(string)
  4871. project.MedListCodg = medical_code
  4872. }
  4873. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4874. single_dose, _ := json["single_dose"].(string)
  4875. project.SingleDose = single_dose
  4876. }
  4877. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4878. delivery_way, _ := json["delivery_way"].(string)
  4879. project.DeliveryWay = delivery_way
  4880. }
  4881. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4882. execution_frequency, _ := json["execution_frequency"].(string)
  4883. project.ExecutionFrequency = execution_frequency
  4884. }
  4885. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4886. remark, _ := json["remark"].(string)
  4887. project.Remark = remark
  4888. }
  4889. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4890. day, _ := json["number_days"].(string)
  4891. project.Day = day
  4892. }
  4893. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4894. unit, _ := json["unit"].(string)
  4895. project.Unit = unit
  4896. }
  4897. return 0
  4898. }
  4899. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4900. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4901. id := int64(json["id"].(float64))
  4902. historyAddtions, _ := service.GetHisAdditionByID(id)
  4903. additionalCharge.ID = id
  4904. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4905. }
  4906. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4907. item_id := int64(json["item_id"].(float64))
  4908. additionalCharge.ItemId = item_id
  4909. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4910. if config.ID > 0 {
  4911. if len(config.Code) > 0 {
  4912. additionalCharge.MedListCodg = config.Code
  4913. }
  4914. }
  4915. }
  4916. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4917. // price := int64(json["price"].(float64))
  4918. // formatInt_price := strconv.FormatInt(price, 10)
  4919. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4920. // additionalCharge.Price = float_price
  4921. // }
  4922. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4923. // price := int64(json["price"].(float64))
  4924. // formatInt_price := strconv.FormatInt(price, 10)
  4925. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4926. // additionalCharge.Price = float_price
  4927. //}
  4928. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4929. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4930. additionalCharge.Price = price
  4931. }
  4932. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4933. count, _ := json["count"].(string)
  4934. counts, _ := strconv.ParseInt(count, 10, 64)
  4935. additionalCharge.Count = counts
  4936. }
  4937. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4938. item_name, _ := json["item_name"].(string)
  4939. additionalCharge.ItemName = item_name
  4940. }
  4941. return 0
  4942. }
  4943. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4944. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4945. utils.ErrorLog("drug_name")
  4946. return enums.ErrorCodeParamWrong
  4947. }
  4948. adviceName, _ := json["drug_name"].(string)
  4949. if len(adviceName) == 0 {
  4950. utils.ErrorLog("len(advice_name) == 0")
  4951. return enums.ErrorCodeParamWrong
  4952. }
  4953. advice.AdviceName = adviceName
  4954. adviceDesc, _ := json["advice_desc"].(string)
  4955. advice.AdviceDesc = adviceDesc
  4956. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4957. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4958. advice.DrugSpec = drugSpec
  4959. }
  4960. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4961. remark, _ := json["remark"].(string)
  4962. advice.Remark = remark
  4963. }
  4964. if json["id"] == nil {
  4965. advice.DrugId = 0
  4966. } else {
  4967. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4968. drug_id := int64(json["id"].(float64))
  4969. advice.DrugId = drug_id
  4970. }
  4971. }
  4972. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4973. groupno := int64(json["groupno"].(float64))
  4974. advice.Groupno = groupno
  4975. }
  4976. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4977. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4978. advice.HospApprFlag = hosp_appr_flag
  4979. }
  4980. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4981. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4982. advice.PrescribingNumber = prescribingNumber
  4983. }
  4984. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4985. // frequency_type := int64(json["frequency_type"].(float64))
  4986. // advice.FrequencyType = frequency_type
  4987. //}
  4988. //
  4989. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4990. // day_count := int64(json["day_count"].(float64))
  4991. // advice.DayCount = day_count
  4992. //}
  4993. //
  4994. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4995. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4996. // week_day, _ := json["week_day"].(string)
  4997. // advice.WeekDay = week_day
  4998. //}
  4999. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5000. drugSpecUnit, _ := json["min_unit"].(string)
  5001. advice.DrugSpecUnit = drugSpecUnit
  5002. }
  5003. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5004. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5005. advice.SingleDose = singleDose
  5006. }
  5007. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5008. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5009. advice.SingleDoseUnit = singleDoseUnit
  5010. }
  5011. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5012. deliveryWay, _ := json["delivery_way"].(string)
  5013. advice.DeliveryWay = deliveryWay
  5014. }
  5015. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5016. executionFrequency, _ := json["execution_frequency"].(string)
  5017. advice.ExecutionFrequency = executionFrequency
  5018. }
  5019. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5020. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5021. advice.Price = price
  5022. }
  5023. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5024. med_list_codg, _ := json["medical_insurance_number"].(string)
  5025. advice.MedListCodg = med_list_codg
  5026. }
  5027. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5028. day := int64(json["day"].(float64))
  5029. advice.Day = day
  5030. }
  5031. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5032. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5033. advice.PrescribingNumberUnit = prescribingNumberUnit
  5034. }
  5035. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5036. advice_id := int64(json["advice_id"].(float64))
  5037. advice.ID = advice_id
  5038. if advice.ID > 0 {
  5039. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5040. if err == nil {
  5041. if hisAdvice.ID > 0 {
  5042. advice.ExecutionTime = hisAdvice.ExecutionTime
  5043. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5044. advice.ExecutionState = hisAdvice.ExecutionState
  5045. advice.CheckTime = hisAdvice.CheckTime
  5046. advice.Checker = hisAdvice.Checker
  5047. advice.CheckState = hisAdvice.CheckState
  5048. advice.StartTime = hisAdvice.StartTime
  5049. advice.HospApprFlag = hisAdvice.HospApprFlag
  5050. advice.IsMedicine = hisAdvice.IsMedicine
  5051. if hisAdvice.UserOrgId == 10028 {
  5052. 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 {
  5053. advice.ExecutionTime = 0
  5054. advice.ExecutionStaff = 0
  5055. advice.ExecutionState = 2
  5056. advice.CheckTime = 0
  5057. advice.Checker = 0
  5058. advice.CheckState = 2
  5059. }
  5060. } else {
  5061. 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 {
  5062. advice.ExecutionTime = 0
  5063. advice.ExecutionStaff = 0
  5064. advice.ExecutionState = 2
  5065. advice.CheckTime = 0
  5066. advice.Checker = 0
  5067. advice.CheckState = 2
  5068. }
  5069. }
  5070. //advice.Groupno = hisAdvice.Groupno
  5071. }
  5072. }
  5073. }
  5074. }
  5075. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5076. //
  5077. //if drugStockConfig.IsOpen == 1 {
  5078. //
  5079. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5080. // if advice.ID == 0 { //医嘱不存在
  5081. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5082. // drug.Total = drug.Total - advice.PrescribingNumber
  5083. // service.UpdateBaseDrugLib(&drug)
  5084. //
  5085. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5086. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5087. // drug.Total = drug.Total - num
  5088. // service.UpdateBaseDrugLib(&drug)
  5089. // }
  5090. //
  5091. // } else if advice.ID > 0 { //医嘱存在
  5092. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5093. // var num float64
  5094. //
  5095. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5096. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5097. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5098. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5099. // drug.Total = drug.Total + num
  5100. // service.UpdateBaseDrugLib(&drug)
  5101. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5102. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5103. // drug.Total = drug.Total - num
  5104. // service.UpdateBaseDrugLib(&drug)
  5105. // }
  5106. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5107. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5108. // if num2 > advice.PrescribingNumber {
  5109. // num = num2 - advice.PrescribingNumber
  5110. // drug.Total = drug.Total + num
  5111. // service.UpdateBaseDrugLib(&drug)
  5112. // } else if num2 < advice.PrescribingNumber {
  5113. // num = advice.PrescribingNumber - num2
  5114. // drug.Total = drug.Total - num
  5115. // service.UpdateBaseDrugLib(&drug)
  5116. // }
  5117. //
  5118. // }
  5119. //
  5120. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5121. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5122. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5123. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5124. // if num1 > num2 {
  5125. // num = num1 - num2
  5126. // drug.Total = drug.Total + num
  5127. // service.UpdateBaseDrugLib(&drug)
  5128. // } else if num1 < num2 {
  5129. // num = num2 - num1
  5130. // drug.Total = drug.Total - num
  5131. // service.UpdateBaseDrugLib(&drug)
  5132. // }
  5133. //
  5134. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5135. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5136. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5137. // if hisAdvice.PrescribingNumber > num2 {
  5138. // num = hisAdvice.PrescribingNumber - num2
  5139. // drug.Total = drug.Total + num
  5140. // service.UpdateBaseDrugLib(&drug)
  5141. // } else if num2 < advice.PrescribingNumber {
  5142. // num = num2 - hisAdvice.PrescribingNumber
  5143. // drug.Total = drug.Total - num
  5144. // service.UpdateBaseDrugLib(&drug)
  5145. // }
  5146. //
  5147. // }
  5148. // }
  5149. // }
  5150. //}
  5151. //
  5152. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5153. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5154. // advice.ExecutionTime = execution_time
  5155. //}
  5156. //
  5157. //
  5158. //
  5159. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5160. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5161. // advice.ExecutionStaff = execution_staff
  5162. //}
  5163. //
  5164. //
  5165. //
  5166. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5167. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5168. // advice.ExecutionState = execution_state
  5169. //}
  5170. //
  5171. //
  5172. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5173. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5174. // advice.CheckTime = check_time
  5175. //}
  5176. //
  5177. //
  5178. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5179. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5180. // advice.CheckState = check_state
  5181. //}
  5182. //
  5183. //
  5184. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5185. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5186. // advice.Checker = checker
  5187. //}
  5188. //
  5189. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5190. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5191. // advice.StartTime = start_time
  5192. //}
  5193. return 0
  5194. }
  5195. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5196. project.ExecutionStaff = 0
  5197. project.ExecutionState = 2
  5198. project.ExecutionTime = 0
  5199. project.Checker = 0
  5200. project.CheckState = 2
  5201. project.CheckTime = 0
  5202. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5203. id := int64(json["id"].(float64))
  5204. project.ID = id
  5205. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5206. project.ExecutionStaff = temp_project.ExecutionStaff
  5207. project.ExecutionState = temp_project.ExecutionState
  5208. project.ExecutionTime = temp_project.ExecutionTime
  5209. project.Checker = temp_project.Checker
  5210. project.CheckState = temp_project.CheckState
  5211. project.CheckTime = temp_project.CheckTime
  5212. project.TeamId = temp_project.TeamId
  5213. }
  5214. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5215. types := int64(json["type"].(float64))
  5216. project.Type = types
  5217. }
  5218. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5219. project_id := int64(json["project_id"].(float64))
  5220. project.ProjectId = project_id
  5221. }
  5222. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5223. team_id := int64(json["team_id"].(float64))
  5224. project.TeamId = team_id
  5225. }
  5226. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5227. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5228. project.Price = price
  5229. }
  5230. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5231. total, _ := json["total"].(string)
  5232. //totals, _ := strconv.ParseInt(total, 10, 64)
  5233. project.Count = total
  5234. }
  5235. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5236. medical_code, _ := json["medical_code"].(string)
  5237. project.MedListCodg = medical_code
  5238. }
  5239. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5240. single_dose, _ := json["single_dose"].(string)
  5241. project.SingleDose = single_dose
  5242. }
  5243. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5244. delivery_way, _ := json["delivery_way"].(string)
  5245. project.DeliveryWay = delivery_way
  5246. }
  5247. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5248. execution_frequency, _ := json["execution_frequency"].(string)
  5249. project.ExecutionFrequency = execution_frequency
  5250. }
  5251. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5252. remark, _ := json["remark"].(string)
  5253. project.Remark = remark
  5254. }
  5255. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5256. day, _ := json["number_days"].(string)
  5257. project.Day = day
  5258. }
  5259. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5260. unit, _ := json["unit"].(string)
  5261. project.Unit = unit
  5262. }
  5263. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5264. // frequency_type := int64(json["frequency_type"].(float64))
  5265. // project.FrequencyType = frequency_type
  5266. //}
  5267. //
  5268. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5269. // day_count := int64(json["day_count"].(float64))
  5270. // project.DayCount = day_count
  5271. //}
  5272. //
  5273. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5274. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5275. // week_day, _ := json["week_day"].(string)
  5276. // project.WeekDay = week_day
  5277. //}
  5278. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5279. //
  5280. //if project.ID == 0 {
  5281. // if stockConfig.IsOpen == 1 {
  5282. // if project.Type == 3 {
  5283. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5284. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5285. // good.Total = good.Total - f_count
  5286. // service.UpdateGoodInfo(&good)
  5287. // }
  5288. // }
  5289. //
  5290. //} else {
  5291. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5292. //
  5293. // if stockConfig.IsOpen == 1 {
  5294. // if project.Type == 3 {
  5295. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5296. // if project.Count < temp_project.Count {
  5297. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5298. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5299. //
  5300. // other_count := f_count_two - f_count_one
  5301. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5302. // good.Total = good.Total + other_count_two
  5303. // service.UpdateGoodInfo(&good)
  5304. // } else if project.Count > temp_project.Count {
  5305. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5306. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5307. //
  5308. // other_count := f_count_one - f_count_two
  5309. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5310. // good.Total = good.Total - other_count_two
  5311. // service.UpdateGoodInfo(&good)
  5312. // }
  5313. //
  5314. // }
  5315. // }
  5316. //
  5317. //}
  5318. return 0
  5319. }
  5320. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5321. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5322. id := int64(json["id"].(float64))
  5323. additionalCharge.ID = id
  5324. }
  5325. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5326. item_id := int64(json["item_id"].(float64))
  5327. additionalCharge.ItemId = item_id
  5328. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5329. if config.ID > 0 {
  5330. if len(config.Code) > 0 {
  5331. additionalCharge.MedListCodg = config.Code
  5332. }
  5333. }
  5334. }
  5335. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5336. // price := int64(json["price"].(float64))
  5337. // formatInt_price := strconv.FormatInt(price, 10)
  5338. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5339. // additionalCharge.Price = float_price
  5340. // }
  5341. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5342. // price := int64(json["price"].(float64))
  5343. // formatInt_price := strconv.FormatInt(price, 10)
  5344. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5345. // additionalCharge.Price = float_price
  5346. //}
  5347. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5348. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5349. additionalCharge.Price = price
  5350. }
  5351. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5352. count, _ := json["count"].(string)
  5353. counts, _ := strconv.ParseInt(count, 10, 64)
  5354. additionalCharge.Count = counts
  5355. }
  5356. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5357. item_name, _ := json["item_name"].(string)
  5358. additionalCharge.ItemName = item_name
  5359. }
  5360. return 0
  5361. }
  5362. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5363. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5364. utils.ErrorLog("drug_name")
  5365. return enums.ErrorCodeParamWrong
  5366. }
  5367. adviceName, _ := json["drug_name"].(string)
  5368. if len(adviceName) == 0 {
  5369. utils.ErrorLog("len(advice_name) == 0")
  5370. return enums.ErrorCodeParamWrong
  5371. }
  5372. advice.AdviceName = adviceName
  5373. adviceDesc, _ := json["advice_desc"].(string)
  5374. advice.AdviceDesc = adviceDesc
  5375. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5376. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5377. advice.DrugSpec = drugSpec
  5378. }
  5379. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5380. remark, _ := json["remark"].(string)
  5381. advice.Remark = remark
  5382. }
  5383. if json["id"] == nil {
  5384. advice.DrugId = 0
  5385. } else {
  5386. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5387. drug_id := int64(json["id"].(float64))
  5388. advice.DrugId = drug_id
  5389. }
  5390. }
  5391. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5392. groupno := int64(json["groupno"].(float64))
  5393. advice.Groupno = groupno
  5394. }
  5395. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5396. drugSpecUnit, _ := json["min_unit"].(string)
  5397. advice.DrugSpecUnit = drugSpecUnit
  5398. }
  5399. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5400. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5401. advice.SingleDose = singleDose
  5402. }
  5403. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5404. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5405. advice.SingleDoseUnit = singleDoseUnit
  5406. }
  5407. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5408. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5409. advice.PrescribingNumber = prescribingNumber
  5410. }
  5411. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5412. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5413. advice.PrescribingNumberUnit = prescribingNumberUnit
  5414. }
  5415. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5416. deliveryWay, _ := json["delivery_way"].(string)
  5417. advice.DeliveryWay = deliveryWay
  5418. }
  5419. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5420. executionFrequency, _ := json["execution_frequency"].(string)
  5421. advice.ExecutionFrequency = executionFrequency
  5422. }
  5423. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5424. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5425. advice.Price = price
  5426. }
  5427. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5428. med_list_codg, _ := json["medical_insurance_number"].(string)
  5429. advice.MedListCodg = med_list_codg
  5430. }
  5431. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5432. day := int64(json["day"].(float64))
  5433. advice.Day = day
  5434. }
  5435. advice.FrequencyType = 1
  5436. return 0
  5437. }
  5438. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5439. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5440. types := int64(json["type"].(float64))
  5441. project.Type = types
  5442. }
  5443. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5444. project_id := int64(json["project_id"].(float64))
  5445. project.ProjectId = project_id
  5446. }
  5447. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5448. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5449. project.Price = price
  5450. }
  5451. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5452. total, _ := json["total"].(string)
  5453. //totals, _ := strconv.ParseInt(total, 10, 64)
  5454. project.Count = total
  5455. }
  5456. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5457. medical_code, _ := json["medical_code"].(string)
  5458. project.MedListCodg = medical_code
  5459. }
  5460. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5461. single_dose, _ := json["single_dose"].(string)
  5462. project.SingleDose = single_dose
  5463. }
  5464. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5465. delivery_way, _ := json["delivery_way"].(string)
  5466. project.DeliveryWay = delivery_way
  5467. }
  5468. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5469. execution_frequency, _ := json["execution_frequency"].(string)
  5470. project.ExecutionFrequency = execution_frequency
  5471. }
  5472. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5473. remark, _ := json["remark"].(string)
  5474. project.Remark = remark
  5475. }
  5476. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5477. day, _ := json["number_days"].(string)
  5478. project.Day = day
  5479. }
  5480. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5481. unit, _ := json["unit"].(string)
  5482. project.Unit = unit
  5483. }
  5484. project.FrequencyType = 1
  5485. return 0
  5486. }
  5487. func (c *HisApiController) GetHisOrderList() {
  5488. page, _ := c.GetInt64("page", -1)
  5489. limit, _ := c.GetInt64("limit", -1)
  5490. start_time := c.GetString("start_time")
  5491. end_time := c.GetString("end_time")
  5492. types, _ := c.GetInt64("type", 0)
  5493. keywords := c.GetString("keywords")
  5494. p_type, _ := c.GetInt64("p_type", 0)
  5495. sort_type, _ := c.GetInt64("sort_type", 0)
  5496. charge_type, _ := c.GetInt64("charge_type", 0)
  5497. sch_type, _ := c.GetInt64("sch_type", 0)
  5498. zone_type, _ := c.GetInt64("zone_type", 0)
  5499. timeLayout := "2006-01-02"
  5500. loc, _ := time.LoadLocation("Local")
  5501. var startTime int64
  5502. if len(start_time) > 0 {
  5503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5504. if err != nil {
  5505. //fmt.Println(err)
  5506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5507. return
  5508. }
  5509. startTime = theTime.Unix()
  5510. }
  5511. var endTime int64
  5512. if len(end_time) > 0 {
  5513. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5514. if err != nil {
  5515. utils.ErrorLog(err.Error())
  5516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5517. return
  5518. }
  5519. endTime = theTime.Unix()
  5520. }
  5521. adminUser := c.GetAdminUserInfo()
  5522. org_id := adminUser.CurrentOrgId
  5523. 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)
  5524. for _, item := range order {
  5525. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5526. item.DoctorName = info.Doctor
  5527. item.DepartmentName = info.XtHisDepartment.Name
  5528. }
  5529. if err == nil {
  5530. c.ServeSuccessJSON(map[string]interface{}{
  5531. "order": order,
  5532. "total": total,
  5533. })
  5534. } else {
  5535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5536. return
  5537. }
  5538. }
  5539. func (c *HisApiController) GetHisOrder() {
  5540. patient_id, _ := c.GetInt64("patient_id", 0)
  5541. number := c.GetString("number")
  5542. adminInfo := c.GetAdminUserInfo()
  5543. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5544. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5545. if err == nil {
  5546. c.ServeSuccessJSON(map[string]interface{}{
  5547. "order": order,
  5548. "prescription": prescriptions,
  5549. })
  5550. } else {
  5551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5552. return
  5553. }
  5554. }
  5555. func (c *HisApiController) GetHisPrescriptionList() {
  5556. record_date := c.GetString("record_date")
  5557. keywords := c.GetString("keywords")
  5558. page, _ := c.GetInt64("page")
  5559. limit, _ := c.GetInt64("limit")
  5560. sch_type, _ := c.GetInt64("sch_type")
  5561. timeLayout := "2006-01-02"
  5562. loc, _ := time.LoadLocation("Local")
  5563. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5564. if err != nil {
  5565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5566. return
  5567. }
  5568. recordDateTime := theTime.Unix()
  5569. adminInfo := c.GetAdminUserInfo()
  5570. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5571. //adminInfo := c.GetAdminUserInfo()
  5572. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5573. //fmt.Println(prescriptionOrder)
  5574. if err == nil {
  5575. c.ServeSuccessJSON(map[string]interface{}{
  5576. "order": prescriptionOrder,
  5577. "total": total,
  5578. })
  5579. } else {
  5580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5581. return
  5582. }
  5583. }
  5584. func (c *HisApiController) GetHisPrescriptionInfo() {
  5585. id, _ := c.GetInt64("id")
  5586. adminInfo := c.GetAdminUserInfo()
  5587. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5588. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5589. if err == nil {
  5590. c.ServeSuccessJSON(map[string]interface{}{
  5591. "order": prescriptionOrder,
  5592. "prescription": prescription,
  5593. })
  5594. } else {
  5595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5596. return
  5597. }
  5598. }
  5599. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5600. adminUser := c.GetAdminUserInfo()
  5601. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5602. c.ServeSuccessJSON(map[string]interface{}{
  5603. "config": config,
  5604. })
  5605. }
  5606. type ResultTwo struct {
  5607. ErrMsg interface{} `json:"err_msg"`
  5608. InfRefmsgid string `json:"inf_refmsgid"`
  5609. Infcode int64 `json:"infcode"`
  5610. Output struct {
  5611. Baseinfo struct {
  5612. Age float64 `json:"age"`
  5613. Brdy string `json:"brdy"`
  5614. Certno string `json:"certno"`
  5615. Gend string `json:"gend"`
  5616. Naty string `json:"naty"`
  5617. PsnCertType string `json:"psn_cert_type"`
  5618. PsnName string `json:"psn_name"`
  5619. PsnNo string `json:"psn_no"`
  5620. } `json:"baseinfo"`
  5621. Idetinfo []interface{} `json:"idetinfo"`
  5622. Iinfo []struct {
  5623. Balc float64 `json:"balc"`
  5624. CvlservFlag string `json:"cvlserv_flag"`
  5625. EmpName string `json:"emp_name"`
  5626. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5627. Insutype string `json:"insutype"`
  5628. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5629. PausInsuDate interface{} `json:"paus_insu_date"`
  5630. PsnInsuDate string `json:"psn_insu_date"`
  5631. PsnInsuStas string `json:"psn_insu_stas"`
  5632. PsnType string `json:"psn_type"`
  5633. } `json:"insuinfo"`
  5634. } `json:"output"`
  5635. RefmsgTime string `json:"refmsg_time"`
  5636. RespondTime string `json:"respond_time"`
  5637. Signtype interface{} `json:"signtype"`
  5638. WarnInfo interface{} `json:"warn_info"`
  5639. }
  5640. type ResultThree struct {
  5641. Cainfo interface{} `json:"cainfo"`
  5642. ErrMsg interface{} `json:"err_msg"`
  5643. InfRefmsgid string `json:"inf_refmsgid"`
  5644. Infcode int64 `json:"infcode"`
  5645. Output struct {
  5646. Data struct {
  5647. IptOtpNo string `json:"ipt_otp_no"`
  5648. MdtrtID string `json:"mdtrt_id"`
  5649. PsnNo string `json:"psn_no"`
  5650. } `json:"data"`
  5651. } `json:"output"`
  5652. RefmsgTime string `json:"refmsg_time"`
  5653. RespondTime string `json:"respond_time"`
  5654. Signtype interface{} `json:"signtype"`
  5655. WarnMsg interface{} `json:"warn_msg"`
  5656. }
  5657. type ResultFour struct {
  5658. Cainfo string `json:"cainfo"`
  5659. ErrMsg string `json:"err_msg"`
  5660. InfRefmsgid string `json:"inf_refmsgid"`
  5661. Infcode int64 `json:"infcode"`
  5662. Output struct {
  5663. Result []struct {
  5664. BasMednFlag string `json:"bas_medn_flag"`
  5665. ChldMedcFlag string `json:"chld_medc_flag"`
  5666. ChrgitmLv string `json:"chrgitm_lv"`
  5667. Cnt float64 `json:"cnt"`
  5668. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5669. DrtReimFlag string `json:"drt_reim_flag"`
  5670. FeedetlSn string `json:"feedetl_sn"`
  5671. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5672. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5673. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5674. ListSpItemFlag string `json:"list_sp_item_flag"`
  5675. LmtUsedFlag string `json:"lmt_used_flag"`
  5676. MedChrgitmType string `json:"med_chrgitm_type"`
  5677. Memo string `json:"memo"`
  5678. OverlmtAmt float64 `json:"overlmt_amt"`
  5679. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5680. Pric float64 `json:"pric"`
  5681. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5682. SelfpayProp float64 `json:"selfpay_prop"`
  5683. } `json:"result"`
  5684. } `json:"output"`
  5685. RefmsgTime string `json:"refmsg_time"`
  5686. RespondTime string `json:"respond_time"`
  5687. Signtype string `json:"signtype"`
  5688. WarnMsg string `json:"warn_msg"`
  5689. }
  5690. type ResultFive struct {
  5691. Insutype string `json:"insutype"`
  5692. }
  5693. type ResultSix struct {
  5694. Cainfo interface{} `json:"cainfo"`
  5695. ErrMsg interface{} `json:"err_msg"`
  5696. InfRefmsgid string `json:"inf_refmsgid"`
  5697. Infcode int64 `json:"infcode"`
  5698. Output struct {
  5699. } `json:"output"`
  5700. RefmsgTime string `json:"refmsg_time"`
  5701. RespondTime string `json:"respond_time"`
  5702. Signtype interface{} `json:"signtype"`
  5703. WarnMsg interface{} `json:"warn_msg"`
  5704. }
  5705. type ResultSeven struct {
  5706. Cainfo string `json:"cainfo"`
  5707. ErrMsg string `json:"err_msg"`
  5708. InfRefmsgid string `json:"inf_refmsgid"`
  5709. Infcode int64 `json:"infcode"`
  5710. Output struct {
  5711. Setldetail []interface{} `json:"setldetail"`
  5712. Setlinfo struct {
  5713. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5714. AcctPay float64 `json:"acct_pay"`
  5715. ActPayDedc float64 `json:"act_pay_dedc"`
  5716. Age float64 `json:"age"`
  5717. Balc float64 `json:"balc"`
  5718. Brdy string `json:"brdy"`
  5719. Certno string `json:"certno"`
  5720. ClrOptins string `json:"clr_optins"`
  5721. ClrType string `json:"clr_type"`
  5722. ClrWay string `json:"clr_way"`
  5723. CvlservFlag string `json:"cvlserv_flag"`
  5724. CvlservPay float64 `json:"cvlserv_pay"`
  5725. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5726. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5727. Gend string `json:"gend"`
  5728. HifesPay float64 `json:"hifes_pay"`
  5729. HifmiPay float64 `json:"hifmi_pay"`
  5730. HifobPay float64 `json:"hifob_pay"`
  5731. HifpPay float64 `json:"hifp_pay"`
  5732. HospPartAmt float64 `json:"hosp_part_amt"`
  5733. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5734. Insutype string `json:"insutype"`
  5735. MafPay float64 `json:"maf_pay"`
  5736. MdtrtCertType string `json:"mdtrt_cert_type"`
  5737. MdtrtID string `json:"mdtrt_id"`
  5738. MedType string `json:"med_type"`
  5739. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5740. MedinsSetlID string `json:"medins_setl_id"`
  5741. Naty string `json:"naty"`
  5742. OthPay float64 `json:"oth_pay"`
  5743. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5744. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5745. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5746. PsnCashPay float64 `json:"psn_cash_pay"`
  5747. PsnCertType string `json:"psn_cert_type"`
  5748. PsnName string `json:"psn_name"`
  5749. PsnNo string `json:"psn_no"`
  5750. PsnPartAmt float64 `json:"psn_part_amt"`
  5751. PsnType string `json:"psn_type"`
  5752. SetlID string `json:"setl_id"`
  5753. SetlTime string `json:"setl_time"`
  5754. } `json:"setlinfo"`
  5755. } `json:"output"`
  5756. RefmsgTime string `json:"refmsg_time"`
  5757. RespondTime string `json:"respond_time"`
  5758. Signtype interface{} `json:"signtype"`
  5759. WarnMsg interface{} `json:"warn_msg"`
  5760. }
  5761. type ResultEight struct {
  5762. Cainfo string `json:"cainfo"`
  5763. ErrMsg string `json:"err_msg"`
  5764. InfRefmsgid string `json:"inf_refmsgid"`
  5765. Infcode int64 `json:"infcode"`
  5766. Output struct {
  5767. Stmtinfo struct {
  5768. SetlOptins string `json:"setl_optins"`
  5769. StmtRslt string `json:"stmt_rslt"`
  5770. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5771. } `json:"stmtinfo"`
  5772. } `json:"output"`
  5773. RefmsgTime string `json:"refmsg_time"`
  5774. RespondTime string `json:"respond_time"`
  5775. Signtype interface{} `json:"signtype"`
  5776. WarnMsg interface{} `json:"warn_msg"`
  5777. }
  5778. type ResultNine struct {
  5779. Cainfo string `json:"cainfo"`
  5780. ErrMsg string `json:"err_msg"`
  5781. InfRefmsgid string `json:"inf_refmsgid"`
  5782. Infcode int64 `json:"infcode"`
  5783. Output struct {
  5784. FileQuryNo string `json:"file_qury_no"`
  5785. } `json:"output"`
  5786. RefmsgTime string `json:"refmsg_time"`
  5787. RespondTime string `json:"respond_time"`
  5788. Signtype interface{} `json:"signtype"`
  5789. WarnMsg interface{} `json:"warn_msg"`
  5790. }
  5791. type ResultTen struct {
  5792. Cainfo string `json:"cainfo"`
  5793. ErrMsg string `json:"err_msg"`
  5794. InfRefmsgid string `json:"inf_refmsgid"`
  5795. Infcode int64 `json:"infcode"`
  5796. Output struct {
  5797. DldEndtime string `json:"dld_endtime"`
  5798. FileQuryNo string `json:"file_qury_no"`
  5799. Filename string `json:"filename"`
  5800. } `json:"output"`
  5801. RefmsgTime string `json:"refmsg_time"`
  5802. RespondTime string `json:"respond_time"`
  5803. Signtype interface{} `json:"signtype"`
  5804. WarnMsg interface{} `json:"warn_msg"`
  5805. }
  5806. type ResultEleven struct {
  5807. Cainfo string `json:"cainfo"`
  5808. ErrMsg string `json:"err_msg"`
  5809. InfRefmsgid string `json:"inf_refmsgid"`
  5810. Infcode int64 `json:"infcode"`
  5811. Output struct {
  5812. Setlinfo struct {
  5813. FixmedinsName string `json:"fixmedins_name"`
  5814. FixmedinsCode string `json:"fixmedins_code"`
  5815. PsnNo string `json:"psn_no"`
  5816. PsnName string `json:"psn_name"`
  5817. HifobPay float64 `json:"hifob_pay"`
  5818. Gend string `json:"gend"`
  5819. Brdy string `json:"brdy"`
  5820. PsnCertType string `json:"psn_cert_type"`
  5821. PsnType string `json:"psn_type"`
  5822. EmpName string `json:"emp_name"`
  5823. Certno string `json:"certno"`
  5824. Insutype string `json:"insutype"`
  5825. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5826. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5827. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5828. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5829. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5830. ActPayDedc float64 `json:"act_pay_dedc"`
  5831. HifpPay float64 `json:"hifp_pay"`
  5832. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5833. CvlservPay float64 `json:"cvlserv_pay"`
  5834. HifesPay float64 `json:"hifes_pay"`
  5835. HifmiPay float64 `json:"hifmi_pay"`
  5836. MafPay float64 `json:"maf_pay"`
  5837. OthPay float64 `json:"oth_pay"`
  5838. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5839. PsnPay float64 `json:"psn_pay"`
  5840. AcctPay float64 `json:"acct_pay"`
  5841. CashPayamt float64 `json:"cash_payamt"`
  5842. Balc float64 `json:"balc"`
  5843. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5844. MedinsSetlId string `json:"medins_setl_id"`
  5845. RefdSetlFlag string `json:"refd_setl_flag"`
  5846. SetlTime string `json:"setl_time"`
  5847. MedType string `json:"med_type"`
  5848. } `json:"setlinfo"`
  5849. } `json:"output"`
  5850. RefmsgTime string `json:"refmsg_time"`
  5851. RespondTime string `json:"respond_time"`
  5852. Signtype interface{} `json:"signtype"`
  5853. WarnMsg interface{} `json:"warn_msg"`
  5854. }
  5855. type Custom struct {
  5856. DetItemFeeSumamt string
  5857. Cut string
  5858. FeedetlSn string
  5859. Price string
  5860. MedListCodg string
  5861. Type int64
  5862. AdviceId int64
  5863. ProjectId int64
  5864. ItemId int64
  5865. }
  5866. // 获取个人信息----挂号-----上传就诊信息
  5867. func (c *HisApiController) GetRegisterInfo() {
  5868. id, _ := c.GetInt64("id")
  5869. record_time := c.GetString("record_time")
  5870. settlementValue, _ := c.GetInt64("settlement_value")
  5871. medical_insurance_card := c.GetString("medical_insurance_card")
  5872. name := c.GetString("name")
  5873. id_card_type, _ := c.GetInt64("id_card_type")
  5874. certificates, _ := c.GetInt64("certificates")
  5875. medical_care, _ := c.GetInt64("medical_care")
  5876. birthday := c.GetString("birthday")
  5877. age, _ := c.GetInt64("age")
  5878. id_card := c.GetString("id_card")
  5879. register_type, _ := c.GetInt64("register")
  5880. doctor, _ := c.GetInt64("doctor")
  5881. department, _ := c.GetInt64("department")
  5882. gender, _ := c.GetInt64("sex")
  5883. phone := c.GetString("phone")
  5884. registration_fee, _ := c.GetFloat("registration_fee")
  5885. medical_expenses, _ := c.GetFloat("medical_expenses")
  5886. social_type, _ := c.GetInt64("social_type")
  5887. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5888. diagnosis_ids := c.GetString("diagnosis")
  5889. sick_type, _ := c.GetInt64("sick_type")
  5890. reg_type := c.GetString("p_type")
  5891. timeLayout := "2006-01-02"
  5892. loc, _ := time.LoadLocation("Local")
  5893. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5894. birthUnix := birthdays.Unix()
  5895. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5896. if err != nil {
  5897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5898. return
  5899. }
  5900. recordDateTime := theTime.Unix()
  5901. adminInfo := c.GetAdminUserInfo()
  5902. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5903. if tempPatient.ID == 0 {
  5904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5905. return
  5906. }
  5907. var patient service.Patients
  5908. if id == 0 {
  5909. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5910. } else {
  5911. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5912. }
  5913. if patient.ID == 0 {
  5914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5915. return
  5916. }
  5917. if len(patient.IdCardNo) == 0 {
  5918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5919. return
  5920. }
  5921. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5922. if len(his) >= 1 {
  5923. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5924. if len(his) >= 1 && order.ID == 0 {
  5925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5926. return
  5927. }
  5928. }
  5929. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5930. fmt.Println(timeStr)
  5931. timeArr := strings.Split(timeStr, " ")
  5932. fmt.Println(timeArr)
  5933. timeArrTwo := strings.Split(timeArr[0], "-")
  5934. timeArrThree := strings.Split(timeArr[1], ":")
  5935. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5936. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5937. if len(lists) == 0 {
  5938. var hisPatient models.XtHisPatient
  5939. hisPatient = models.XtHisPatient{
  5940. Name: name,
  5941. Age: age,
  5942. Gender: gender,
  5943. Birthday: birthUnix,
  5944. Phone: phone,
  5945. MedicalTreatmentType: medical_care,
  5946. IdType: certificates,
  5947. IdCardNo: id_card,
  5948. BalanceAccountsType: settlementValue,
  5949. SocialType: social_type,
  5950. MedicalInsuranceNumber: medical_insurance_card,
  5951. RegisterType: register_type,
  5952. RegisterCost: registration_fee,
  5953. TreatmentCost: medical_expenses,
  5954. AdminUserId: adminInfo.AdminUser.Id,
  5955. UserOrgId: adminInfo.CurrentOrgId,
  5956. Status: 1,
  5957. RecordDate: recordDateTime,
  5958. IsReturn: 1,
  5959. PatientId: patient.ID,
  5960. Ctime: time.Now().Unix(),
  5961. Mtime: time.Now().Unix(),
  5962. Number: str,
  5963. IdCardType: id_card_type,
  5964. Departments: department,
  5965. Doctor: doctor,
  5966. PType: reg_type,
  5967. Diagnosis: diagnosis_ids,
  5968. SickType: sick_type,
  5969. }
  5970. service.CreateHisPatient(&hisPatient)
  5971. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5972. c.ServeSuccessJSON(map[string]interface{}{
  5973. "his_info": hisPatient,
  5974. })
  5975. } else {
  5976. //chrgBchno := rand.Intn(1000000) + 10000
  5977. var hisPatient models.XtHisPatient
  5978. hisPatient = models.XtHisPatient{
  5979. Name: name,
  5980. Age: age,
  5981. Gender: gender,
  5982. Birthday: birthUnix,
  5983. Phone: phone,
  5984. MedicalTreatmentType: medical_care,
  5985. IdType: certificates,
  5986. IdCardNo: id_card,
  5987. BalanceAccountsType: settlementValue,
  5988. SocialType: social_type,
  5989. MedicalInsuranceNumber: medical_insurance_card,
  5990. RegisterType: register_type,
  5991. RegisterCost: registration_fee,
  5992. TreatmentCost: medical_expenses,
  5993. AdminUserId: adminInfo.AdminUser.Id,
  5994. UserOrgId: adminInfo.CurrentOrgId,
  5995. Status: 1,
  5996. RecordDate: recordDateTime,
  5997. IsReturn: 1,
  5998. PatientId: patient.ID,
  5999. Ctime: time.Now().Unix(),
  6000. Mtime: time.Now().Unix(),
  6001. Number: str,
  6002. IdCardType: id_card_type,
  6003. Departments: department,
  6004. Doctor: doctor,
  6005. PType: reg_type,
  6006. Diagnosis: diagnosis_ids,
  6007. SickType: sick_type,
  6008. }
  6009. service.CreateHisPatient(&hisPatient)
  6010. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6011. c.ServeSuccessJSON(map[string]interface{}{
  6012. "his_info": hisPatient,
  6013. })
  6014. }
  6015. }
  6016. // 上传明细----结算
  6017. func (c *HisApiController) GetUploadInfo() {
  6018. id, _ := c.GetInt64("id")
  6019. record_time := c.GetString("record_time")
  6020. his_patient_id, _ := c.GetInt64("his_patient_id")
  6021. oth_desc := c.GetString("oth_desc")
  6022. pay_way, _ := c.GetInt64("pay_way")
  6023. pay_ways := c.GetString("pay_ways")
  6024. pay_price, _ := c.GetFloat("pay_price")
  6025. pay_card_no := c.GetString("pay_card_no")
  6026. discount_price, _ := c.GetFloat("discount_price")
  6027. preferential_price, _ := c.GetFloat("preferential_price")
  6028. reality_price, _ := c.GetFloat("reality_price")
  6029. found_price, _ := c.GetFloat("found_price")
  6030. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6031. private_price, _ := c.GetFloat("private_price")
  6032. timeLayout := "2006-01-02"
  6033. loc, _ := time.LoadLocation("Local")
  6034. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6035. fapiao_code := c.GetString("fapiao_code")
  6036. fapiao_number := c.GetString("fapiao_number")
  6037. diagnosis_id := c.GetString("diagnosis")
  6038. sick_type, _ := c.GetInt64("sick_type")
  6039. reg_type, _ := c.GetInt64("p_type")
  6040. order_id, _ := c.GetInt64("order_id")
  6041. cash_pay := c.GetString("cash_pay")
  6042. wechat_pay := c.GetString("wechat_pay")
  6043. ali_pay := c.GetString("ali_pay")
  6044. jifen_pay := c.GetString("jifen_pay")
  6045. band_card_pay := c.GetString("band_card_pay")
  6046. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6047. tmp_decimal := c.GetString("tmp_decimal")
  6048. var decimal float64 //本次使用的押金
  6049. var errmsg error
  6050. tx := service.XTWriteDB().Begin() //开了事务
  6051. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6052. defer func() {
  6053. if errmsg != nil {
  6054. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6055. tx.Rollback()
  6056. } else {
  6057. tx.Commit()
  6058. }
  6059. }()
  6060. fmt.Println("dec_way", dec_way)
  6061. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6062. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6063. return
  6064. }
  6065. if len(tmp_decimal) > 0 {
  6066. if tmp_decimal[0] == 45 {
  6067. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6068. return
  6069. }
  6070. }
  6071. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6072. fmt.Println(errs)
  6073. decimal = tt
  6074. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6075. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6077. if err != nil {
  6078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6079. return
  6080. }
  6081. recordDateTime := theTime.Unix()
  6082. adminUser := c.GetAdminUserInfo()
  6083. var prescriptions []*models.HisPrescription
  6084. var prescriptionsOne []*models.HisPrescription
  6085. var start_time int64
  6086. var end_time int64
  6087. ids_str := c.GetString("ids")
  6088. ids_arr := strings.Split(ids_str, ",")
  6089. if tempOrder.ID == 0 {
  6090. if settle_accounts_type == 1 { //日结
  6091. fmt.Println(reg_type)
  6092. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6093. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6094. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6095. } else {
  6096. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6097. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6098. }
  6099. } else { //月结
  6100. start_time_str := c.GetString("start_time")
  6101. end_time_str := c.GetString("end_time")
  6102. timeLayout := "2006-01-02"
  6103. loc, _ := time.LoadLocation("Local")
  6104. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6105. if err != nil {
  6106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6107. return
  6108. }
  6109. recordStartTime := theStartTime.Unix()
  6110. start_time = recordStartTime
  6111. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6112. if err != nil {
  6113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6114. return
  6115. }
  6116. recordEndTime := theEndTime.Unix()
  6117. end_time = recordEndTime
  6118. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6119. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6120. }
  6121. var goods []*models.DialysisBeforePrepareGoods
  6122. var newGoods []*models.NewDialysisBeforePrepareGoods
  6123. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6124. var infos []*models.HisDoctorAdviceInfo
  6125. var infoList []*models.HisDoctorAdviceInfo
  6126. var hisAdvice []*models.HisDoctorAdviceInfo
  6127. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6128. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6129. //判断库存不足
  6130. //结算出库开关
  6131. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6132. if settConfig.IsOpen == 1 {
  6133. //判断库存的地方
  6134. for _, info := range prescriptions {
  6135. if info.Type == 1 {
  6136. infos = append(infos, info.HisDoctorAdviceInfo...)
  6137. }
  6138. if info.Type == 2 {
  6139. for _, sumItem := range info.HisPrescriptionProject {
  6140. if sumItem.Type == 3 {
  6141. var good models.DialysisBeforePrepareGoods
  6142. var newGood models.NewDialysisBeforePrepareGoods
  6143. good.GoodId = sumItem.GoodInfo.ID
  6144. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6145. count, _ := strconv.Atoi(sumItem.Count)
  6146. good.Count = int64(count)
  6147. good.StorehouseId = houseConfig.StorehouseOutInfo
  6148. good.ProjectId = sumItem.ID
  6149. goods = append(goods, &good)
  6150. newGood.GoodId = sumItem.GoodInfo.ID
  6151. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6152. count2, _ := strconv.Atoi(sumItem.Count)
  6153. newGood.Count = int64(count2)
  6154. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6155. newGood.ProjectId = sumItem.ID
  6156. newGoods = append(newGoods, &newGood)
  6157. }
  6158. }
  6159. }
  6160. }
  6161. for _, info := range prescriptionsOne {
  6162. if info.Type == 1 {
  6163. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6164. }
  6165. if info.Type == 2 {
  6166. for _, sumItem := range info.HisPrescriptionProject {
  6167. if sumItem.Type == 3 {
  6168. var newGood models.NewDialysisBeforePrepareGoods
  6169. newGood.GoodId = sumItem.GoodInfo.ID
  6170. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6171. count2, _ := strconv.Atoi(sumItem.Count)
  6172. newGood.Count = int64(count2)
  6173. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6174. newGood.ProjectId = sumItem.ID
  6175. newGoodOne = append(newGoodOne, &newGood)
  6176. }
  6177. }
  6178. }
  6179. }
  6180. //判断
  6181. for _, itemOne := range infos {
  6182. for _, itemTwo := range hisAdvice {
  6183. if itemOne.DrugId == itemTwo.DrugId {
  6184. itemTwo.Child = append(itemTwo.Child, itemOne)
  6185. }
  6186. }
  6187. }
  6188. for _, itemTwo := range hisAdvice {
  6189. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6190. var sum_out_count int64
  6191. for _, itemThree := range itemTwo.Child {
  6192. var prescribing_number int64
  6193. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6194. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6195. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6196. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6197. }
  6198. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6199. prescribing_number = parseIntPrescribingNumber
  6200. }
  6201. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6202. prescribing_number = parseIntPrescribingNumber
  6203. }
  6204. sum_out_count += prescribing_number
  6205. }
  6206. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6207. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6208. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6209. if sum_out_count > drugStockOut.FlushCount {
  6210. c.ServeSuccessJSON(map[string]interface{}{
  6211. "msg": "2",
  6212. "drug": medical,
  6213. })
  6214. return
  6215. }
  6216. }
  6217. fmt.Println("newGoods99999988882os", newGoods)
  6218. for _, itemOne := range newGoods {
  6219. for _, item := range newGoodOne {
  6220. if itemOne.GoodId == item.GoodId {
  6221. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6222. }
  6223. }
  6224. }
  6225. for _, item := range newGoodOne {
  6226. var sum_out_count_one int64
  6227. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6228. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6229. sum_out_count_one += itemOne.Count
  6230. }
  6231. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6232. fmt.Println("sum_out_count_one", sum_out_count_one)
  6233. fmt.Println("list.FlushCount", list.FlushCount)
  6234. if sum_out_count_one > list.FlushCount {
  6235. c.ServeSuccessJSON(map[string]interface{}{
  6236. "msg": "3",
  6237. "good": good,
  6238. })
  6239. return
  6240. }
  6241. }
  6242. }
  6243. timestamp := time.Now().Unix()
  6244. tempTime := time.Unix(timestamp, 0)
  6245. timeFormat := tempTime.Format("20060102150405")
  6246. chrgBchno := rand.Intn(100000) + 10000
  6247. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6248. strconv.FormatInt(his.PatientId, 10)
  6249. var ids []int64
  6250. for _, item := range prescriptions {
  6251. ids = append(ids, item.ID)
  6252. }
  6253. var total float64
  6254. for _, item := range prescriptions {
  6255. fmt.Println(item)
  6256. if item.Type == 1 { //药品
  6257. for _, subItem := range item.HisDoctorAdviceInfo {
  6258. total = total + (subItem.Price * subItem.PrescribingNumber)
  6259. }
  6260. }
  6261. if item.Type == 2 { //项目
  6262. for _, subItem := range item.HisPrescriptionProject {
  6263. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6264. total = total + (subItem.Price * cnt)
  6265. }
  6266. }
  6267. for _, subItem := range item.HisAdditionalCharge {
  6268. total = total + (subItem.Price * float64(subItem.Count))
  6269. }
  6270. }
  6271. if reg_type == 1111 || reg_type == 1112 {
  6272. reg_type = 11
  6273. }
  6274. tm := time.Unix(time.Now().Unix(), 0)
  6275. allTotal := fmt.Sprintf("%.4f", total)
  6276. totals, _ := strconv.ParseFloat(allTotal, 64)
  6277. order := &models.HisOrder{
  6278. UserOrgId: adminUser.CurrentOrgId,
  6279. HisPatientId: his.ID,
  6280. PatientId: id,
  6281. SettleAccountsDate: recordDateTime,
  6282. Ctime: time.Now().Unix(),
  6283. Mtime: time.Now().Unix(),
  6284. Status: 1,
  6285. OrderStatus: 2,
  6286. MdtrtId: his.Number,
  6287. Number: chrg_bchno,
  6288. MedfeeSumamt: totals,
  6289. PayWay: pay_way,
  6290. PayWays: pay_ways,
  6291. PayPrice: pay_price,
  6292. MedType: strconv.Itoa(int(reg_type)),
  6293. PayCardNo: pay_card_no,
  6294. DiscountPrice: discount_price,
  6295. PreferentialPrice: preferential_price,
  6296. RealityPrice: reality_price,
  6297. FoundPrice: found_price,
  6298. MedicalInsurancePrice: medical_insurance_price,
  6299. PrivatePrice: private_price,
  6300. SettleEndTime: end_time,
  6301. SettleStartTime: start_time,
  6302. PsnPartAmt: totals,
  6303. PsnCashPay: totals,
  6304. SettleType: settle_accounts_type,
  6305. FaPiaoCode: fapiao_code,
  6306. FaPiaoNumber: fapiao_number,
  6307. Diagnosis: diagnosis_id,
  6308. PType: 2,
  6309. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6310. Decimal: decimal,
  6311. OthDesc: oth_desc,
  6312. CashPay: cash_pay,
  6313. WechatPay: wechat_pay,
  6314. AliPay: ali_pay,
  6315. JifenPay: jifen_pay,
  6316. BandCardPay: band_card_pay,
  6317. }
  6318. err = service.CreateOrderTX(order, tx)
  6319. if err != nil {
  6320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6321. return
  6322. }
  6323. var customs []*Custom
  6324. for _, item := range prescriptions {
  6325. if item.Type == 1 { //药品a
  6326. for _, subItem := range item.HisDoctorAdviceInfo {
  6327. cus := &Custom{
  6328. AdviceId: subItem.ID,
  6329. ProjectId: 0,
  6330. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6331. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6332. FeedetlSn: subItem.FeedetlSn,
  6333. Price: fmt.Sprintf("%.4f", subItem.Price),
  6334. MedListCodg: subItem.MedListCodg,
  6335. Type: 1,
  6336. }
  6337. customs = append(customs, cus)
  6338. }
  6339. }
  6340. if item.Type == 2 { //项目
  6341. for _, subItem := range item.HisPrescriptionProject {
  6342. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6343. cus := &Custom{
  6344. AdviceId: 0,
  6345. ProjectId: subItem.ID,
  6346. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6347. Cut: fmt.Sprintf("%.4f", cnt),
  6348. FeedetlSn: subItem.FeedetlSn,
  6349. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6350. MedListCodg: subItem.MedListCodg,
  6351. Type: 2,
  6352. }
  6353. customs = append(customs, cus)
  6354. }
  6355. }
  6356. for _, item := range item.HisAdditionalCharge {
  6357. cus := &Custom{
  6358. ItemId: item.ID,
  6359. AdviceId: 0,
  6360. ProjectId: 0,
  6361. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6362. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6363. FeedetlSn: item.FeedetlSn,
  6364. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6365. MedListCodg: item.XtHisAddtionConfig.Code,
  6366. Type: 3,
  6367. }
  6368. customs = append(customs, cus)
  6369. }
  6370. }
  6371. for _, item := range customs {
  6372. var advice_id int64 = 0
  6373. var project_id int64 = 0
  6374. var item_id int64 = 0
  6375. var types int64 = 0
  6376. if item.Type == 1 {
  6377. advice_id = item.AdviceId
  6378. project_id = 0
  6379. item_id = 0
  6380. } else if item.Type == 2 {
  6381. advice_id = 0
  6382. item_id = 0
  6383. project_id = item.ProjectId
  6384. } else if item.Type == 3 {
  6385. advice_id = 0
  6386. item_id = item.ItemId
  6387. project_id = 0
  6388. }
  6389. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6390. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6391. pric, _ := strconv.ParseFloat(item.Price, 32)
  6392. info := &models.HisOrderInfo{
  6393. OrderNumber: order.Number,
  6394. UploadDate: time.Now().Unix(),
  6395. AdviceId: advice_id,
  6396. DetItemFeeSumamt: detItemFeeSumamt,
  6397. Cnt: cut,
  6398. Pric: pric,
  6399. PatientId: id,
  6400. Status: 1,
  6401. Mtime: time.Now().Unix(),
  6402. Ctime: time.Now().Unix(),
  6403. UserOrgId: adminUser.CurrentOrgId,
  6404. HisPatientId: his.ID,
  6405. OrderId: order.ID,
  6406. ProjectId: project_id,
  6407. Type: types,
  6408. ItemId: item_id,
  6409. }
  6410. service.CreateOrderInfoTX(info, tx)
  6411. }
  6412. his.Diagnosis = diagnosis_id
  6413. his.SickType = sick_type
  6414. his.RegisterType = reg_type
  6415. his.MedicalTreatmentType = reg_type
  6416. service.UpdataHisPateintTX(&his, tx)
  6417. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6418. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6419. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6420. //判断是否使用了押金
  6421. if dec_way == "true" {
  6422. tmpstring := strconv.FormatInt(order.ID, 10)
  6423. //扣押金
  6424. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6425. order.Decimal = decimal
  6426. service.UpDateOrderTwo(order, tx)
  6427. if errmsg != nil {
  6428. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6429. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6430. return
  6431. }
  6432. }
  6433. if err == nil {
  6434. for _, info := range prescriptions {
  6435. if info.Type == 1 {
  6436. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6437. }
  6438. if info.Type == 2 {
  6439. for _, sumItem := range info.HisPrescriptionProject {
  6440. if sumItem.Type == 3 {
  6441. var good models.DialysisBeforePrepareGoods
  6442. var newGood models.NewDialysisBeforePrepareGoods
  6443. var oldGood models.OldDialysisBeforePrepareGoods
  6444. good.GoodId = sumItem.GoodInfo.ID
  6445. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6446. count, _ := strconv.Atoi(sumItem.Count)
  6447. good.Count = int64(count)
  6448. good.StorehouseId = houseConfig.StorehouseOutInfo
  6449. good.ProjectId = sumItem.ID
  6450. good.PatientId = sumItem.PatientId
  6451. goods = append(goods, &good)
  6452. newGood.GoodId = sumItem.GoodInfo.ID
  6453. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6454. count2, _ := strconv.Atoi(sumItem.Count)
  6455. newGood.Count = int64(count2)
  6456. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6457. newGood.ProjectId = sumItem.ID
  6458. newGood.PatientId = sumItem.HisPatientId
  6459. newGoods = append(newGoods, &newGood)
  6460. oldGood.GoodId = sumItem.GoodInfo.ID
  6461. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6462. count3, _ := strconv.Atoi(sumItem.Count)
  6463. oldGood.Count = int64(count3)
  6464. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6465. oldGood.ProjectId = sumItem.ID
  6466. oldGood.RecordDate = sumItem.RecordDate
  6467. oldGood.PatientId = sumItem.HisPatientId
  6468. oldGoods = append(oldGoods, &oldGood)
  6469. }
  6470. }
  6471. }
  6472. }
  6473. if settConfig.IsOpen == 1 {
  6474. for _, item := range infoList {
  6475. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6476. if medical.IsUse == 2 {
  6477. //药品出库
  6478. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6479. //查询默认仓库
  6480. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6481. //查询默认仓库剩余多少库存
  6482. var sum_count int64
  6483. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6484. for _, its := range stockInfo {
  6485. if its.MaxUnit == medical.MaxUnit {
  6486. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6487. }
  6488. sum_count += its.StockMaxNumber + its.StockMinNumber
  6489. }
  6490. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6491. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6492. }
  6493. }
  6494. orgId := c.GetAdminUserInfo().CurrentOrgId
  6495. if len(oldGoods) > 0 {
  6496. timeStr := time.Now().Format("2006-01-02")
  6497. timeArr := strings.Split(timeStr, "-")
  6498. total, _ := service.FindAllWarehouseOut(orgId)
  6499. total = total + 1
  6500. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6501. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6502. number = number + total
  6503. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6504. operation_time := time.Now().Unix()
  6505. creater := c.GetAdminUserInfo().AdminUser.Id
  6506. //查询默认出库仓库库存
  6507. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6508. recordDateStr := time.Now().Format("2006-01-02")
  6509. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6510. nowtime := recordDate.Unix()
  6511. warehouseOut := models.WarehouseOut{
  6512. WarehouseOutOrderNumber: warehousing_out_order,
  6513. OperationTime: operation_time,
  6514. OrgId: orgId,
  6515. Creater: creater,
  6516. Ctime: time.Now().Unix(),
  6517. Status: 1,
  6518. WarehouseOutTime: nowtime,
  6519. Type: 1,
  6520. StorehouseId: storeConfig.StorehouseOutInfo,
  6521. IsCheck: 1,
  6522. OrderId: order.ID,
  6523. IsSys: 5,
  6524. }
  6525. //查询是否生成出库单
  6526. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6527. if out.ID == 0 {
  6528. service.AddSigleWarehouseOut(&warehouseOut)
  6529. }
  6530. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6531. for _, item := range oldGoods {
  6532. dialyPrepareOne := models.DialysisBeforePrepare{
  6533. GoodTypeId: item.GoodTypeId,
  6534. GoodId: item.GoodId,
  6535. PatientId: his.PatientId,
  6536. RecordDate: item.RecordDate,
  6537. UserOrgId: adminUser.CurrentOrgId,
  6538. Count: item.Count,
  6539. Ctime: time.Now().Unix(),
  6540. Creater: adminUser.AdminUser.Id,
  6541. CommdityCode: item.CommdityCode,
  6542. Status: 1,
  6543. StorehouseId: houseConfig.StorehouseOutInfo,
  6544. }
  6545. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6546. //非零用
  6547. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6548. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6549. //查询剩余库存
  6550. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6551. var sum_count int64
  6552. for _, item := range goodList {
  6553. sum_count += item.StockCount
  6554. }
  6555. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6556. //耗材
  6557. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6558. }
  6559. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6560. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6561. //查询剩余库存
  6562. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6563. var sum_count int64
  6564. for _, item := range goodList {
  6565. sum_count += item.StockCount
  6566. }
  6567. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6568. //耗材
  6569. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6570. }
  6571. }
  6572. }
  6573. }
  6574. c.ServeSuccessJSON(map[string]interface{}{
  6575. "msg": "结算成功",
  6576. })
  6577. }
  6578. }
  6579. }
  6580. // 退款
  6581. func (c *HisApiController) Refund() {
  6582. order_id, _ := c.GetInt64("order_id")
  6583. order, _ := service.GetHisOrderByID(order_id)
  6584. adminUser := c.GetAdminUserInfo()
  6585. orgid := c.GetAdminUserInfo().CurrentOrgId
  6586. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6587. if err != nil {
  6588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6589. return
  6590. }
  6591. tmp := strconv.FormatInt(order.ID, 10)
  6592. //当押金不为零时产生退费记录
  6593. if order.Decimal != 0 {
  6594. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6595. if err != nil {
  6596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6597. return
  6598. }
  6599. }
  6600. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6601. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6602. var goods []*models.DialysisBeforePrepareGoods
  6603. var newGoods []*models.NewDialysisBeforePrepareGoods
  6604. var infos []*models.HisDoctorAdviceInfo
  6605. for _, info := range orders {
  6606. if info.AdviceId > 0 && info.ProjectId == 0 {
  6607. infos = append(infos, &info.HisDoctorAdviceInfo)
  6608. }
  6609. if info.ProjectId > 0 && info.AdviceId == 0 {
  6610. if info.HisPrescriptionProject.Type == 3 {
  6611. var good models.DialysisBeforePrepareGoods
  6612. var newGood models.NewDialysisBeforePrepareGoods
  6613. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6614. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6615. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6616. good.Count = int64(count)
  6617. good.StorehouseId = houseConfig.StorehouseOutInfo
  6618. good.ProjectId = info.HisPrescriptionProject.ID
  6619. good.PatientId = info.PatientId
  6620. good.OrderId = order_id
  6621. goods = append(goods, &good)
  6622. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6623. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6624. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6625. newGood.Count = int64(count2)
  6626. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6627. newGood.ProjectId = info.HisPrescriptionProject.ID
  6628. newGood.RecordDate = order.SettleAccountsDate
  6629. newGood.UserOrgId = order.UserOrgId
  6630. newGood.PatientId = info.PatientId
  6631. newGood.OrderId = order_id
  6632. newGoods = append(newGoods, &newGood)
  6633. }
  6634. }
  6635. }
  6636. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6637. if settConfig.IsOpen == 1 {
  6638. for _, item := range infos {
  6639. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6640. }
  6641. for _, item := range newGoods {
  6642. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6643. }
  6644. }
  6645. c.ServeSuccessJSON(map[string]interface{}{
  6646. "msg": "退费成功",
  6647. })
  6648. }
  6649. func (c *HisApiController) RefundNumber() {
  6650. his_patient_id, _ := c.GetInt64("id")
  6651. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6652. info.Status = 0
  6653. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6654. if count > 0 {
  6655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6656. return
  6657. }
  6658. err := service.SaveHisPatient(info)
  6659. if err == nil {
  6660. c.ServeSuccessJSON(map[string]interface{}{
  6661. "msg": "退号成功",
  6662. })
  6663. } else {
  6664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6665. return
  6666. }
  6667. }
  6668. func (this *HisApiController) AdditionalCharge() {
  6669. dataBody := make(map[string]interface{}, 0)
  6670. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6671. fmt.Println(err)
  6672. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6673. patient_id := int64(dataBody["patient_id"].(float64))
  6674. medicineData, _ := dataBody["medicineData"].([]interface{})
  6675. adminUserInfo := this.GetAdminUserInfo()
  6676. orgId := adminUserInfo.CurrentOrgId
  6677. admin_user_id := adminUserInfo.AdminUser.Id
  6678. timeStr := time.Now().Format("2006-01-02")
  6679. timeLayout := "2006-01-02 15:04:05"
  6680. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6681. timenow := timeStringToTime.Unix()
  6682. var additionalCharges []*models.HisAdditionalCharge
  6683. for _, item := range medicineData {
  6684. var randNum int
  6685. randNum = rand.Intn(10000) + 1000
  6686. timestamp := time.Now().Unix()
  6687. tempTime := time.Unix(timestamp, 0)
  6688. timeFormat := tempTime.Format("20060102150405")
  6689. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6690. items := item.(map[string]interface{})
  6691. money := items["price"].(string)
  6692. item_id_str := items["item_id"].(string)
  6693. name := items["name"].(string)
  6694. id_str := items["id"].(string)
  6695. moneys, _ := strconv.ParseInt(money, 10, 64)
  6696. monStr := strconv.FormatInt(moneys, 10)
  6697. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6698. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6699. id, _ := strconv.ParseInt(id_str, 10, 64)
  6700. additionalCharge := &models.HisAdditionalCharge{
  6701. ID: id,
  6702. HisPatientId: his_patient_id,
  6703. UserOrgId: orgId,
  6704. PatientId: patient_id,
  6705. RecordDate: timenow,
  6706. Price: monneyStr,
  6707. Status: 1,
  6708. ItemName: name,
  6709. ItemId: item_id,
  6710. AdminUserId: admin_user_id,
  6711. CreatedTime: time.Now().Unix(),
  6712. OrderStatus: 0,
  6713. PrescriptionNumber: "",
  6714. BatchNumber: "",
  6715. FeedetlSn: p_number,
  6716. }
  6717. service.CreateAdditionalCharge(additionalCharge)
  6718. additionalCharges = append(additionalCharges, additionalCharge)
  6719. }
  6720. this.ServeSuccessJSON(map[string]interface{}{
  6721. "msg": "添加成功",
  6722. "additional_charges": additionalCharges,
  6723. })
  6724. }
  6725. func (this *HisApiController) DeleteAddition() {
  6726. id, _ := this.GetInt64("id")
  6727. //TODO 需要判断是否已经结算
  6728. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6729. if err == nil {
  6730. this.ServeSuccessJSON(map[string]interface{}{
  6731. "msg": "删除成功",
  6732. })
  6733. return
  6734. } else {
  6735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6736. return
  6737. }
  6738. }
  6739. func (this *HisApiController) GetAdminUsers() {
  6740. adminUser := this.GetAdminUserInfo()
  6741. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6742. this.ServeSuccessJSON(map[string]interface{}{
  6743. "doctors": doctors,
  6744. })
  6745. }
  6746. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6747. change_type, _ := this.GetInt64("type", 0)
  6748. record_date := this.GetString("record_time")
  6749. patient_id, _ := this.GetInt64("patient_id", 0)
  6750. p_type, _ := this.GetInt64("p_type", 0)
  6751. timeLayout := "2006-01-02"
  6752. loc, _ := time.LoadLocation("Local")
  6753. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6754. record_time := theAdviceRecordTime.Unix()
  6755. adminUserInfo := this.GetAdminUserInfo()
  6756. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6757. if err == nil {
  6758. if len(prescriptions) == 0 {
  6759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6760. return
  6761. } else {
  6762. this.ServeSuccessJSON(map[string]interface{}{
  6763. "prescriptions": prescriptions,
  6764. })
  6765. return
  6766. }
  6767. } else {
  6768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6769. return
  6770. }
  6771. }
  6772. func (this *HisApiController) GetCallHisPrescription() {
  6773. patient_id, _ := this.GetInt64("patient_id", 0)
  6774. timeLayout := "2006-01-02"
  6775. loc, _ := time.LoadLocation("Local")
  6776. start_time := this.GetString("start_time")
  6777. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6778. end_time := this.GetString("end_time")
  6779. p_type, _ := this.GetInt64("p_type")
  6780. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6781. adminUserInfo := this.GetAdminUserInfo()
  6782. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6783. if err == nil {
  6784. this.ServeSuccessJSON(map[string]interface{}{
  6785. "prescriptions": prescriptions,
  6786. })
  6787. return
  6788. } else {
  6789. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6790. return
  6791. }
  6792. }
  6793. func (this *HisApiController) GetHisDayPrescription() {
  6794. timeLayout := "2006-01-02"
  6795. loc, _ := time.LoadLocation("Local")
  6796. start_time := this.GetString("start_time")
  6797. patient_id, _ := this.GetInt64("patient_id", 0)
  6798. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6799. end_time := this.GetString("end_time")
  6800. p_type, _ := this.GetInt64("p_type")
  6801. order_status, _ := this.GetInt64("type")
  6802. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6803. adminUserInfo := this.GetAdminUserInfo()
  6804. var dayHisPrescription []*models.HisPrescription
  6805. var err error
  6806. if order_status == 1 || order_status == 0 {
  6807. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6808. } else if order_status == 2 {
  6809. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6810. }
  6811. var settle_total float64
  6812. for _, item := range dayHisPrescription {
  6813. if len(item.HisPrescriptionProject) > 0 {
  6814. for _, subItem := range item.HisPrescriptionProject {
  6815. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6816. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6817. settle_total = settle_total + total
  6818. }
  6819. }
  6820. if len(item.HisDoctorAdviceInfo) > 0 {
  6821. for _, subItem := range item.HisDoctorAdviceInfo {
  6822. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6823. settle_total = settle_total + total
  6824. }
  6825. }
  6826. }
  6827. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6828. if err == nil {
  6829. this.ServeSuccessJSON(map[string]interface{}{
  6830. "day_prescription": dayHisPrescription,
  6831. "settle_total": settle_total,
  6832. })
  6833. return
  6834. } else {
  6835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6836. return
  6837. }
  6838. }
  6839. func (c *HisApiController) GetHisChargePatientList() {
  6840. record_date := c.GetString("record_date")
  6841. order_status, _ := c.GetInt64("type")
  6842. timeLayout := "2006-01-02"
  6843. loc, _ := time.LoadLocation("Local")
  6844. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6845. if err != nil {
  6846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6847. return
  6848. }
  6849. recordDateTime := theTime.Unix()
  6850. adminInfo := c.GetAdminUserInfo()
  6851. var tempPatients []*service.NewTempPatients
  6852. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6853. if order_status != 2 {
  6854. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6855. } else {
  6856. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6857. }
  6858. var patients []*service.NewTempPatients
  6859. var patients_two []*service.NewTempPatients
  6860. for _, item := range tempPatients {
  6861. //过滤掉没挂号的和没开处方的
  6862. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6863. patients = append(patients, item)
  6864. }
  6865. //过滤掉没挂号的
  6866. if len(item.HisPatient) > 0 {
  6867. patients_two = append(patients_two, item)
  6868. }
  6869. }
  6870. c.ServeSuccessJSON(map[string]interface{}{
  6871. "list": patients,
  6872. "list_two": patients_two,
  6873. })
  6874. }
  6875. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6876. record_date := c.GetString("record_date")
  6877. timeLayout := "2006-01-02"
  6878. loc, _ := time.LoadLocation("Local")
  6879. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6880. if err != nil {
  6881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6882. return
  6883. }
  6884. recordDateTime := theTime.Unix()
  6885. adminUser := c.GetAdminUserInfo()
  6886. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6887. var patients []*service.Patients
  6888. for _, item := range tempPatients {
  6889. if item.HisPatient.ID == 0 {
  6890. patients = append(patients, item)
  6891. }
  6892. }
  6893. c.ServeSuccessJSON(map[string]interface{}{
  6894. "list": patients,
  6895. //"list_two": patients_two,
  6896. })
  6897. }
  6898. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6899. newArr = make([]*service.Patients, 0)
  6900. for i := 0; i < len(patient); i++ {
  6901. repeat := false
  6902. for j := i + 1; j < len(patient); j++ {
  6903. if patient[i].ID == patient[j].ID {
  6904. repeat = true
  6905. break
  6906. }
  6907. }
  6908. if !repeat {
  6909. newArr = append(newArr, patient[i])
  6910. }
  6911. }
  6912. return
  6913. }
  6914. func (c *HisApiController) GetHisChargePatientInfo() {
  6915. patient_id, _ := c.GetInt64("patient_id")
  6916. his_patient_id, _ := c.GetInt64("his_patient_id")
  6917. record_date := c.GetString("record_date")
  6918. //start_time := c.GetString("start_time")
  6919. //end_time := c.GetString("end_time")
  6920. order_status, _ := c.GetInt64("type", 0)
  6921. p_type, _ := c.GetInt64("p_type", 0)
  6922. order_id, _ := c.GetInt64("order_id", 0)
  6923. timeLayout := "2006-01-02"
  6924. loc, _ := time.LoadLocation("Local")
  6925. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6926. if err != nil {
  6927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6928. return
  6929. }
  6930. recordDateTime := theTime.Unix()
  6931. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6932. //if err != nil {
  6933. //
  6934. //}
  6935. //startRecordDateTime := startTime.Unix()
  6936. //
  6937. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6938. //if err != nil {
  6939. //
  6940. //}
  6941. //endRecordDateTime := endTime.Unix()
  6942. admin := c.GetAdminUserInfo()
  6943. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6944. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6945. var prescriptions []*models.HisPrescription
  6946. //var unChargeMonthPrescriptions []*models.HisPrescription
  6947. order, _ := service.GetHisOrderByID(order_id)
  6948. if order_status == 1 || order_status == 0 {
  6949. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6950. } else if order_status == 2 {
  6951. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6952. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6953. }
  6954. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6955. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6956. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6957. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6958. //获取所有科室信息
  6959. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6960. c.ServeSuccessJSON(map[string]interface{}{
  6961. "his_info": his_patient_info,
  6962. "xt_info": xt_patient_info,
  6963. "prescription": prescriptions,
  6964. "case_history": case_history,
  6965. "info": patientPrescriptionInfo,
  6966. "last_info": lastPatientPrescriptionInfo,
  6967. "order": order,
  6968. "doctors": doctors,
  6969. "department": department,
  6970. })
  6971. return
  6972. }
  6973. func (c *HisApiController) GetAllOrderDetail() {
  6974. order_id, _ := c.GetInt64("id", 0)
  6975. order, _ := service.GetHisOrderByID(order_id)
  6976. if order.ID == 0 {
  6977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6978. return
  6979. }
  6980. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6981. org_id := c.GetAdminUserInfo().CurrentOrgId
  6982. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6983. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6984. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6985. c.ServeSuccessJSON(map[string]interface{}{
  6986. "order": order,
  6987. "order_info": order_info,
  6988. "patient": patient,
  6989. "admin_info": adminInfo,
  6990. "hospital_record": record,
  6991. })
  6992. return
  6993. }
  6994. func (c *HisApiController) GetAllOrderDetailCollect() {
  6995. order_id, _ := c.GetInt64("id", 0)
  6996. order, _ := service.GetHisOrderByID(order_id)
  6997. if order.ID == 0 {
  6998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6999. return
  7000. }
  7001. org_id := c.GetAdminUserInfo().CurrentOrgId
  7002. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7003. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7004. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7005. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7006. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7007. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7008. var bedCostTotal float64 = 0 //床位总费
  7009. //var bedCostSelfTotal float64 = 0 //床位自费
  7010. var operationCostTotal float64 = 0 //手术费
  7011. //var operationCostSelfTotal float64 = 0 //手术费
  7012. var otherCostTotal float64 = 0 //其他费用
  7013. //var otherCostSelfTotal float64 = 0 //其他费用
  7014. var materialCostTotal float64 = 0 //材料费
  7015. //var materialCostSelfTotal float64 = 0 //材料费
  7016. var westernMedicineCostTotal float64 = 0 //西药费
  7017. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7018. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7019. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7020. var checkCostTotal float64 = 0 //检查费
  7021. //var checkCostSelfTotal float64 = 0 //检查费
  7022. var laboratoryCostTotal float64 = 0 //化验费
  7023. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7024. var treatCostTotal float64 = 0 //治疗费用
  7025. //var treatCostSelfTotal float64 = 0 //治疗费用
  7026. var zhenChaCostTotal float64 = 0 //其他费用
  7027. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7028. decimal.DivisionPrecision = 2
  7029. var BalanceAccountsType int64
  7030. if his.ID > 0 {
  7031. BalanceAccountsType = his.BalanceAccountsType
  7032. } else {
  7033. BalanceAccountsType = record.BalanceAccountsType
  7034. }
  7035. if BalanceAccountsType != 2 {
  7036. for _, item := range order_info {
  7037. if org_id == 10215 {
  7038. if item.MedChrgitmType == "01" { //床位费
  7039. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7040. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7041. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7042. }
  7043. if item.MedChrgitmType == "02" { //诊察费
  7044. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7045. //zhenChaCostSelfTotal = zhenChaCostTotal
  7046. }
  7047. if item.MedChrgitmType == "03" { //检查费
  7048. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7049. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7050. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7051. }
  7052. //if item.MedChrgitmType == "02" { //检查费
  7053. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7054. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7055. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7056. //}
  7057. if item.MedChrgitmType == "04" { //化验费
  7058. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7059. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7060. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7061. }
  7062. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7063. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7064. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7065. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7066. }
  7067. if item.MedChrgitmType == "06" { //手术费
  7068. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7069. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7070. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7071. }
  7072. if item.MedChrgitmType == "08" { //材料费
  7073. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7074. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7075. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7076. }
  7077. if item.MedChrgitmType == "09" { //西药费
  7078. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7079. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7080. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7081. }
  7082. if item.MedChrgitmType == "11" { //中成费
  7083. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7084. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7085. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7086. }
  7087. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7088. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7089. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7090. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7091. }
  7092. } else if org_id == 10188 || org_id == 10217 {
  7093. if item.MedChrgitmType == "01" { //床位费
  7094. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7095. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7096. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7097. }
  7098. if item.MedChrgitmType == "02" { //诊察费
  7099. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7100. //zhenChaCostSelfTotal = zhenChaCostTotal
  7101. }
  7102. if item.MedChrgitmType == "03" { //检查费
  7103. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7104. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7105. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7106. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7107. }
  7108. //if item.MedChrgitmType == "02" { //检查费
  7109. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7110. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7111. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7112. //}
  7113. if item.MedChrgitmType == "04" { //化验费
  7114. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7115. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7116. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7117. }
  7118. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7119. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7120. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7121. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7122. }
  7123. if item.MedChrgitmType == "06" { //手术费
  7124. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7125. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7126. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7127. }
  7128. if item.MedChrgitmType == "08" { //材料费
  7129. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7130. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7131. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7132. }
  7133. if item.MedChrgitmType == "09" { //西药费
  7134. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7135. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7136. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7137. }
  7138. if item.MedChrgitmType == "11" { //中成费
  7139. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7140. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7141. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7142. }
  7143. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7144. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7145. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7146. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7147. }
  7148. } else {
  7149. if item.MedChrgitmType == "01" { //床位费
  7150. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7151. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7152. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7153. }
  7154. //if item.MedChrgitmType == "02" { //诊察费
  7155. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7156. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7157. //}
  7158. if item.MedChrgitmType == "03" { //检查费
  7159. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7160. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7161. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7162. }
  7163. //if item.MedChrgitmType == "02" { //检查费
  7164. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7165. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7166. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7167. //}
  7168. if item.MedChrgitmType == "04" { //化验费
  7169. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7170. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7171. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7172. }
  7173. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7174. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7175. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7176. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7177. }
  7178. if item.MedChrgitmType == "06" { //手术费
  7179. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7180. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7181. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7182. }
  7183. if item.MedChrgitmType == "08" { //材料费
  7184. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7185. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7186. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7187. }
  7188. if item.MedChrgitmType == "09" { //西药费
  7189. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7190. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7191. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7192. }
  7193. if item.MedChrgitmType == "11" { //中成费
  7194. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7195. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7196. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7197. }
  7198. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7199. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7200. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7201. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7202. }
  7203. }
  7204. }
  7205. c.ServeSuccessJSON(map[string]interface{}{
  7206. "order": order,
  7207. "order_info": order_info,
  7208. "patient": patient,
  7209. "admin_info": adminInfo,
  7210. "his_hospital": record,
  7211. "bedCostTotal": bedCostTotal,
  7212. "operationCostTotal": operationCostTotal,
  7213. "otherCostTotal": otherCostTotal,
  7214. "materialCostTotal": materialCostTotal,
  7215. "westernMedicineCostTotal": westernMedicineCostTotal,
  7216. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7217. "checkCostTotal": checkCostTotal,
  7218. "zhenChaCostTotal": zhenChaCostTotal,
  7219. "laboratoryCostTotal": laboratoryCostTotal,
  7220. "treatCostTotal": treatCostTotal,
  7221. })
  7222. } else {
  7223. for _, item := range order_info {
  7224. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7225. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7226. item.MedChrgitmType = "09"
  7227. }
  7228. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7229. if item.HisPrescriptionProject.Type == 2 {
  7230. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7231. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7232. case 0:
  7233. item.MedChrgitmType = "0"
  7234. break
  7235. case 1:
  7236. item.MedChrgitmType = "14"
  7237. break
  7238. case 2:
  7239. item.MedChrgitmType = "05"
  7240. break
  7241. case 3:
  7242. item.MedChrgitmType = "03"
  7243. break
  7244. case 4:
  7245. item.MedChrgitmType = "03"
  7246. break
  7247. case 5:
  7248. item.MedChrgitmType = "08"
  7249. break
  7250. case 6:
  7251. item.MedChrgitmType = "14"
  7252. break
  7253. case 7:
  7254. item.MedChrgitmType = "14"
  7255. break
  7256. case 8:
  7257. item.MedChrgitmType = "03"
  7258. break
  7259. case 9:
  7260. item.MedChrgitmType = "14"
  7261. break
  7262. case 10:
  7263. item.MedChrgitmType = "14"
  7264. break
  7265. case 11:
  7266. item.MedChrgitmType = "06"
  7267. break
  7268. case 12:
  7269. item.MedChrgitmType = "12"
  7270. break
  7271. case 13:
  7272. item.MedChrgitmType = "01"
  7273. break
  7274. case 14:
  7275. item.MedChrgitmType = "04"
  7276. break
  7277. case 15:
  7278. item.MedChrgitmType = "14"
  7279. break
  7280. }
  7281. } else {
  7282. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7283. case 1:
  7284. item.MedChrgitmType = "14"
  7285. break
  7286. case 2:
  7287. item.MedChrgitmType = "05"
  7288. break
  7289. case 3:
  7290. item.MedChrgitmType = "04"
  7291. break
  7292. case 4:
  7293. item.MedChrgitmType = "14"
  7294. break
  7295. case 5:
  7296. item.MedChrgitmType = "08"
  7297. break
  7298. case 6:
  7299. item.MedChrgitmType = "14"
  7300. break
  7301. case 7:
  7302. item.MedChrgitmType = "14"
  7303. break
  7304. case 8:
  7305. item.MedChrgitmType = "03"
  7306. break
  7307. case 9:
  7308. item.MedChrgitmType = "14"
  7309. break
  7310. }
  7311. }
  7312. } else if item.HisPrescriptionProject.Type == 3 {
  7313. item.MedChrgitmType = "08"
  7314. }
  7315. }
  7316. }
  7317. for _, item := range order_info {
  7318. if org_id == 10215 {
  7319. if item.MedChrgitmType == "01" { //床位费
  7320. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7321. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7322. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7323. }
  7324. if item.MedChrgitmType == "02" { //诊察费
  7325. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7326. //zhenChaCostSelfTotal = zhenChaCostTotal
  7327. }
  7328. if item.MedChrgitmType == "03" { //检查费
  7329. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7330. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7331. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7332. }
  7333. //if item.MedChrgitmType == "02" { //检查费
  7334. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7336. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7337. //}
  7338. if item.MedChrgitmType == "04" { //化验费
  7339. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7340. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7341. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7342. }
  7343. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7344. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7345. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7346. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7347. }
  7348. if item.MedChrgitmType == "06" { //手术费
  7349. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7350. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7351. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7352. }
  7353. if item.MedChrgitmType == "08" { //材料费
  7354. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7355. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7356. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7357. }
  7358. if item.MedChrgitmType == "09" { //西药费
  7359. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7360. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7361. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7362. }
  7363. if item.MedChrgitmType == "11" { //中成费
  7364. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7365. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7366. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7367. }
  7368. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7369. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7370. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7371. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7372. }
  7373. } else {
  7374. if item.MedChrgitmType == "01" { //床位费
  7375. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7376. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7377. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7378. }
  7379. //if item.MedChrgitmType == "02" { //诊察费
  7380. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7381. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7382. //}
  7383. if item.MedChrgitmType == "03" { //检查费
  7384. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7385. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7386. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7387. }
  7388. //if item.MedChrgitmType == "02" { //检查费
  7389. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7390. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7391. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7392. //}
  7393. if item.MedChrgitmType == "04" { //化验费
  7394. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7395. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7396. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7397. }
  7398. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7399. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7400. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7401. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7402. }
  7403. if item.MedChrgitmType == "06" { //手术费
  7404. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7405. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7406. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7407. }
  7408. if item.MedChrgitmType == "08" { //材料费
  7409. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7410. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7411. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7412. }
  7413. if item.MedChrgitmType == "09" { //西药费
  7414. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7415. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7416. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7417. }
  7418. if item.MedChrgitmType == "11" { //中成费
  7419. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7420. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7421. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7422. }
  7423. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7424. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7425. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7426. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7427. }
  7428. }
  7429. }
  7430. c.ServeSuccessJSON(map[string]interface{}{
  7431. "order": order,
  7432. "order_info": order_info,
  7433. "patient": patient,
  7434. "admin_info": adminInfo,
  7435. "his_hospital": record,
  7436. "bedCostTotal": bedCostTotal,
  7437. "operationCostTotal": operationCostTotal,
  7438. "otherCostTotal": otherCostTotal,
  7439. "materialCostTotal": materialCostTotal,
  7440. "westernMedicineCostTotal": westernMedicineCostTotal,
  7441. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7442. "checkCostTotal": checkCostTotal,
  7443. "zhenChaCostTotal": zhenChaCostTotal,
  7444. "laboratoryCostTotal": laboratoryCostTotal,
  7445. "treatCostTotal": treatCostTotal,
  7446. })
  7447. }
  7448. }
  7449. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7450. page, _ := c.GetInt64("page")
  7451. limit, _ := c.GetInt64("limit")
  7452. keywords := c.GetString("keywords")
  7453. start_time := c.GetString("start_time")
  7454. end_time := c.GetString("end_time")
  7455. //clr_type := c.GetString("clr_type")
  7456. insutype := c.GetString("insutype")
  7457. timeLayout := "2006-01-02"
  7458. loc, _ := time.LoadLocation("Local")
  7459. var theStartTIme int64
  7460. if len(start_time) > 0 {
  7461. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7462. theStartTIme = theTime.Unix()
  7463. }
  7464. var theEndtTIme int64
  7465. if len(end_time) > 0 {
  7466. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7467. theEndtTIme = theTime.Unix()
  7468. }
  7469. if page <= 0 {
  7470. page = 1
  7471. }
  7472. if limit <= 0 {
  7473. limit = 10
  7474. }
  7475. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7476. c.ServeSuccessJSON(map[string]interface{}{
  7477. "total": total,
  7478. "list": list,
  7479. })
  7480. return
  7481. }
  7482. func (c *HisApiController) GetPutOnRecordList() {
  7483. page, _ := c.GetInt64("page")
  7484. limit, _ := c.GetInt64("limit")
  7485. keywords := c.GetString("keywords")
  7486. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7487. if page <= 0 {
  7488. page = 1
  7489. }
  7490. if limit <= 0 {
  7491. limit = 10
  7492. }
  7493. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7494. c.ServeSuccessJSON(map[string]interface{}{
  7495. "total": total,
  7496. "list": list,
  7497. })
  7498. return
  7499. }
  7500. func (c *HisApiController) GetCompareData() {
  7501. start_time := c.GetString("start_time")
  7502. end_time := c.GetString("end_time")
  7503. insutype := c.GetString("insutype")
  7504. clr_type := c.GetString("clr_type")
  7505. timeLayout := "2006-01-02"
  7506. loc, _ := time.LoadLocation("Local")
  7507. var theStartTIme int64
  7508. if len(start_time) > 0 {
  7509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7510. if err != nil {
  7511. theStartTIme = 0
  7512. }
  7513. theStartTIme = theTime.Unix()
  7514. }
  7515. var theEndtTIme int64
  7516. if len(end_time) > 0 {
  7517. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7518. if err != nil {
  7519. theEndtTIme = 0
  7520. }
  7521. theEndtTIme = theTime.Unix()
  7522. }
  7523. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7524. fmt.Println(err)
  7525. if err == nil {
  7526. c.ServeSuccessJSON(map[string]interface{}{
  7527. "list": formData,
  7528. })
  7529. } else {
  7530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7531. return
  7532. }
  7533. }
  7534. func (c *HisApiController) GetFaPiaoData() {
  7535. order_id, _ := c.GetInt64("order_id")
  7536. patient_id, _ := c.GetInt64("patient_id")
  7537. //number := c.GetString("number")
  7538. adminUser := c.GetAdminUserInfo()
  7539. order, _ := service.GetHisOrderByID(order_id)
  7540. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7541. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7542. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7543. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7544. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7545. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7546. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7547. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7548. var bedCostTotal float64 = 0 //床位总费
  7549. var bedCostSelfTotal float64 = 0 //床位自费
  7550. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7551. var operationCostTotal float64 = 0 //手术费
  7552. var operationCostSelfTotal float64 = 0 //手术费
  7553. var operationCostPartSelfTotal float64 = 0 //手术费
  7554. var otherCostTotal float64 = 0 //其他费用
  7555. var otherCostSelfTotal float64 = 0 //其他费用
  7556. var otherCostPartSelfTotal float64 = 0 //其他费用
  7557. var materialCostTotal float64 = 0 //材料费
  7558. var materialCostSelfTotal float64 = 0 //材料费
  7559. var materialCostPartSelfTotal float64 = 0 //材料费
  7560. var westernMedicineCostTotal float64 = 0 //西药费
  7561. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7562. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7563. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7564. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7565. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7566. var checkCostTotal float64 = 0 //检查费
  7567. var checkCostSelfTotal float64 = 0 //检查费
  7568. var checkCostPartSelfTotal float64 = 0 //检查费
  7569. var hiliCostTotal float64 = 0 //护理费
  7570. var hiliCostSelfTotal float64 = 0 //护理费
  7571. var hiliCostPartSelfTotal float64 = 0 //护理费
  7572. var laboratoryCostTotal float64 = 0 //化验费
  7573. var laboratoryCostSelfTotal float64 = 0 //化验费
  7574. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7575. var treatCostTotal float64 = 0 //治疗费用
  7576. var treatCostSelfTotal float64 = 0 //治疗费用
  7577. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7578. var zhenChaCostTotal float64 = 0 //其他费用
  7579. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7580. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7581. decimal.DivisionPrecision = 2
  7582. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7583. var balanceAccountsType int64
  7584. if his.ID > 0 {
  7585. balanceAccountsType = his.BalanceAccountsType
  7586. } else {
  7587. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7588. }
  7589. if balanceAccountsType == 2 {
  7590. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7591. for _, item := range orderInfos_two {
  7592. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7593. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7594. item.MedChrgitmType = "09"
  7595. }
  7596. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7597. if item.HisPrescriptionProject.Type == 2 {
  7598. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7599. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7600. case 0:
  7601. item.MedChrgitmType = "0"
  7602. break
  7603. case 1:
  7604. item.MedChrgitmType = "14"
  7605. break
  7606. case 2:
  7607. item.MedChrgitmType = "05"
  7608. break
  7609. case 3:
  7610. item.MedChrgitmType = "03"
  7611. break
  7612. case 4:
  7613. item.MedChrgitmType = "03"
  7614. break
  7615. case 5:
  7616. item.MedChrgitmType = "08"
  7617. break
  7618. case 6:
  7619. item.MedChrgitmType = "14"
  7620. break
  7621. case 7:
  7622. item.MedChrgitmType = "14"
  7623. break
  7624. case 8:
  7625. item.MedChrgitmType = "03"
  7626. break
  7627. case 9:
  7628. item.MedChrgitmType = "14"
  7629. break
  7630. case 10:
  7631. item.MedChrgitmType = "14"
  7632. break
  7633. case 11:
  7634. item.MedChrgitmType = "06"
  7635. break
  7636. case 12:
  7637. item.MedChrgitmType = "12"
  7638. break
  7639. case 13:
  7640. item.MedChrgitmType = "01"
  7641. break
  7642. case 14:
  7643. item.MedChrgitmType = "04"
  7644. break
  7645. case 15:
  7646. item.MedChrgitmType = "02"
  7647. break
  7648. }
  7649. } else {
  7650. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7651. case 1:
  7652. item.MedChrgitmType = "14"
  7653. break
  7654. case 2:
  7655. item.MedChrgitmType = "05"
  7656. break
  7657. case 3:
  7658. item.MedChrgitmType = "03"
  7659. break
  7660. case 4:
  7661. item.MedChrgitmType = "03"
  7662. break
  7663. case 5:
  7664. item.MedChrgitmType = "08"
  7665. break
  7666. case 6:
  7667. item.MedChrgitmType = "14"
  7668. break
  7669. case 7:
  7670. item.MedChrgitmType = "14"
  7671. break
  7672. case 8:
  7673. item.MedChrgitmType = "03"
  7674. break
  7675. case 9:
  7676. item.MedChrgitmType = "14"
  7677. break
  7678. }
  7679. }
  7680. } else if item.HisPrescriptionProject.Type == 3 {
  7681. item.MedChrgitmType = "08"
  7682. }
  7683. }
  7684. }
  7685. for _, item := range orderInfos_two {
  7686. fmt.Println(item.MedChrgitmType)
  7687. if item.MedChrgitmType == "07" { //床位费
  7688. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7689. hiliCostSelfTotal = hiliCostTotal
  7690. }
  7691. if item.MedChrgitmType == "01" { //床位费
  7692. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7693. bedCostSelfTotal = bedCostTotal
  7694. }
  7695. if item.MedChrgitmType == "02" { //诊察费
  7696. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7697. zhenChaCostSelfTotal = zhenChaCostTotal
  7698. }
  7699. if item.MedChrgitmType == "03" { //检查费
  7700. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7701. checkCostSelfTotal = checkCostTotal
  7702. }
  7703. if item.MedChrgitmType == "04" { //化验费
  7704. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7705. laboratoryCostSelfTotal = laboratoryCostTotal
  7706. }
  7707. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7708. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7709. treatCostSelfTotal = treatCostTotal
  7710. }
  7711. if item.MedChrgitmType == "06" { //手术费
  7712. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7713. operationCostSelfTotal = treatCostTotal
  7714. }
  7715. if item.MedChrgitmType == "08" { //材料费
  7716. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7717. materialCostSelfTotal = materialCostTotal
  7718. }
  7719. if item.MedChrgitmType == "09" { //西药费
  7720. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7721. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7722. }
  7723. if item.MedChrgitmType == "11" { //中成费
  7724. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7725. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7726. }
  7727. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7728. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7729. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7730. otherCostSelfTotal = otherCostTotal
  7731. }
  7732. } else {
  7733. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7734. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7735. otherCostSelfTotal = otherCostTotal
  7736. }
  7737. }
  7738. }
  7739. } else {
  7740. for _, item := range orderInfos {
  7741. if item.MedChrgitmType == "01" { //床位费
  7742. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7743. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7744. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7745. }
  7746. if item.MedChrgitmType == "02" { //诊察费
  7747. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7748. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7749. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7750. }
  7751. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7752. if item.MedChrgitmType == "03" { //检查费
  7753. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7754. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7755. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7756. }
  7757. } else {
  7758. if item.MedChrgitmType == "03" { //检查费
  7759. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7760. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7761. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7762. }
  7763. }
  7764. if item.MedChrgitmType == "04" { //化验费
  7765. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7766. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7767. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7768. }
  7769. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7770. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7771. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7772. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7773. }
  7774. if item.MedChrgitmType == "06" { //手术费
  7775. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7776. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7777. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7778. }
  7779. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7780. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7781. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7782. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7783. }
  7784. if item.MedChrgitmType == "07" { //西药费
  7785. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7786. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7787. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7788. }
  7789. if item.MedChrgitmType == "09" { //西药费
  7790. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7791. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7792. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7793. }
  7794. if item.MedChrgitmType == "11" { //中成费
  7795. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7796. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7797. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7798. }
  7799. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7800. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7801. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7802. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7803. }
  7804. }
  7805. }
  7806. timeLayout := "2006-01-02"
  7807. loc, _ := time.LoadLocation("Local")
  7808. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7809. if err != nil {
  7810. }
  7811. startRecordDateTime := startTime.Unix()
  7812. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7813. if err != nil {
  7814. }
  7815. endRecordDateTime := endTime.Unix()
  7816. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7817. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7818. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7819. c.ServeSuccessJSON(map[string]interface{}{
  7820. "order_number": order.Number, //业务流水号
  7821. "id_card_no": his.IdCardNo, //社会保障号
  7822. "department_name": department.Name, //科室
  7823. "number": his.Number, //门诊号
  7824. "date": order.SettleAccountsDate, //结算日期
  7825. "name": order.PsnName, //姓名
  7826. "gender": patient.Gender, //性别
  7827. "psn_cash_money": order.PsnCashPay, //个人支付
  7828. "pay_way": "门诊", //结算方式
  7829. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7830. "admin_user_name": admin.UserName, //收款员
  7831. "order": order,
  7832. "order_info": orderInfos_two,
  7833. "his": his,
  7834. "bedCostTotal": bedCostTotal,
  7835. "bedCostSelfTotal": bedCostSelfTotal,
  7836. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7837. "operationCostTotal": operationCostTotal,
  7838. "operationCostSelfTotal": operationCostSelfTotal,
  7839. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7840. "otherCostTotal": otherCostTotal,
  7841. "otherCostSelfTotal": otherCostSelfTotal,
  7842. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7843. "materialCostTotal": materialCostTotal,
  7844. "materialCostSelfTotal": materialCostSelfTotal,
  7845. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7846. "westernMedicineCostTotal": westernMedicineCostTotal,
  7847. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7848. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7849. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7850. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7851. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7852. "checkCostTotal": checkCostTotal,
  7853. "checkCostSelfTotal": checkCostSelfTotal,
  7854. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7855. "laboratoryCostTotal": laboratoryCostTotal,
  7856. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7857. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7858. "treatCostTotal": treatCostTotal,
  7859. "treatCostSelfTotal": treatCostSelfTotal,
  7860. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7861. "zhenChaCostTotal": zhenChaCostTotal,
  7862. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7863. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7864. "his_hospital_record": his_hospital_record,
  7865. "pre_pay_money": pre_pay_money,
  7866. "refund_sum": sum,
  7867. "doctor_info": doctor_info,
  7868. "hiliCostTotal": hiliCostTotal,
  7869. "hiliCostSelfTotal": hiliCostSelfTotal,
  7870. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  7871. })
  7872. }
  7873. //func (c *HisApiController) GetFaPiaoDatas() {
  7874. // order_ids := c.GetString("order_ids")
  7875. // patient_id, _ := c.GetInt64("patient_id")
  7876. // adminUser := c.GetAdminUserInfo()
  7877. //
  7878. // orders := strings.Split(order_ids, ",")
  7879. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7880. //
  7881. // for _, item := range orders {
  7882. // order_id, _ := strconv.ParseInt(item, 10, 64)
  7883. // order, _ := service.GetHisOrderByID(order_id)
  7884. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7885. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7886. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7887. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7888. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7889. //
  7890. // }
  7891. //
  7892. // var bedCostTotal float64 = 0 //床位总费
  7893. // var bedCostSelfTotal float64 = 0 //床位自费
  7894. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7895. //
  7896. // var operationCostTotal float64 = 0 //手术费
  7897. // var operationCostSelfTotal float64 = 0 //手术费
  7898. // var operationCostPartSelfTotal float64 = 0 //手术费
  7899. //
  7900. // var otherCostTotal float64 = 0 //其他费用
  7901. // var otherCostSelfTotal float64 = 0 //其他费用
  7902. // var otherCostPartSelfTotal float64 = 0 //其他费用
  7903. //
  7904. // var materialCostTotal float64 = 0 //材料费
  7905. // var materialCostSelfTotal float64 = 0 //材料费
  7906. // var materialCostPartSelfTotal float64 = 0 //材料费
  7907. //
  7908. // var westernMedicineCostTotal float64 = 0 //西药费
  7909. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  7910. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7911. //
  7912. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7913. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7914. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7915. //
  7916. // var checkCostTotal float64 = 0 //检查费
  7917. // var checkCostSelfTotal float64 = 0 //检查费
  7918. // var checkCostPartSelfTotal float64 = 0 //检查费
  7919. //
  7920. // var laboratoryCostTotal float64 = 0 //化验费
  7921. // var laboratoryCostSelfTotal float64 = 0 //化验费
  7922. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7923. //
  7924. // var treatCostTotal float64 = 0 //治疗费用
  7925. // var treatCostSelfTotal float64 = 0 //治疗费用
  7926. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  7927. //
  7928. // var zhenChaCostTotal float64 = 0 //其他费用
  7929. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  7930. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7931. //
  7932. // decimal.DivisionPrecision = 2
  7933. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7934. //
  7935. // var balanceAccountsType int64
  7936. // if his.ID > 0 {
  7937. // balanceAccountsType = his.BalanceAccountsType
  7938. // } else {
  7939. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  7940. // }
  7941. // if balanceAccountsType == 2 {
  7942. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7943. // for _, item := range orderInfos_two {
  7944. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7945. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7946. // item.MedChrgitmType = "09"
  7947. // }
  7948. //
  7949. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7950. // if item.HisPrescriptionProject.Type == 2 {
  7951. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7952. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7953. // case 0:
  7954. // item.MedChrgitmType = "0"
  7955. // break
  7956. // case 1:
  7957. // item.MedChrgitmType = "14"
  7958. // break
  7959. // case 2:
  7960. // item.MedChrgitmType = "05"
  7961. //
  7962. // break
  7963. // case 3:
  7964. // item.MedChrgitmType = "03"
  7965. //
  7966. // break
  7967. // case 4:
  7968. // item.MedChrgitmType = "03"
  7969. //
  7970. // break
  7971. // case 5:
  7972. // item.MedChrgitmType = "08"
  7973. //
  7974. // break
  7975. // case 6:
  7976. // item.MedChrgitmType = "14"
  7977. //
  7978. // break
  7979. // case 7:
  7980. // item.MedChrgitmType = "14"
  7981. //
  7982. // break
  7983. // case 8:
  7984. // item.MedChrgitmType = "03"
  7985. // break
  7986. // case 9:
  7987. // item.MedChrgitmType = "14"
  7988. // break
  7989. // case 10:
  7990. // item.MedChrgitmType = "14"
  7991. // break
  7992. // case 11:
  7993. // item.MedChrgitmType = "06"
  7994. // break
  7995. // case 12:
  7996. // item.MedChrgitmType = "12"
  7997. // break
  7998. // case 13:
  7999. // item.MedChrgitmType = "01"
  8000. // break
  8001. // case 14:
  8002. // item.MedChrgitmType = "04"
  8003. // break
  8004. // case 15:
  8005. // item.MedChrgitmType = "02"
  8006. // break
  8007. //
  8008. // }
  8009. //
  8010. // } else {
  8011. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8012. //
  8013. // case 1:
  8014. // item.MedChrgitmType = "14"
  8015. // break
  8016. // case 2:
  8017. // item.MedChrgitmType = "05"
  8018. //
  8019. // break
  8020. // case 3:
  8021. // item.MedChrgitmType = "03"
  8022. //
  8023. // break
  8024. // case 4:
  8025. // item.MedChrgitmType = "03"
  8026. //
  8027. // break
  8028. // case 5:
  8029. // item.MedChrgitmType = "08"
  8030. //
  8031. // break
  8032. // case 6:
  8033. // item.MedChrgitmType = "14"
  8034. //
  8035. // break
  8036. // case 7:
  8037. // item.MedChrgitmType = "14"
  8038. //
  8039. // break
  8040. // case 8:
  8041. // item.MedChrgitmType = "03"
  8042. // break
  8043. // case 9:
  8044. // item.MedChrgitmType = "14"
  8045. // break
  8046. //
  8047. // }
  8048. //
  8049. // }
  8050. //
  8051. // } else if item.HisPrescriptionProject.Type == 3 {
  8052. // item.MedChrgitmType = "08"
  8053. // }
  8054. // }
  8055. // }
  8056. //
  8057. // for _, item := range orderInfos_two {
  8058. // fmt.Println(item.MedChrgitmType)
  8059. // if item.MedChrgitmType == "01" { //床位费
  8060. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8061. // bedCostSelfTotal = bedCostTotal
  8062. // }
  8063. //
  8064. // if item.MedChrgitmType == "02" { //诊察费
  8065. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8066. // zhenChaCostSelfTotal = zhenChaCostTotal
  8067. // }
  8068. //
  8069. // if item.MedChrgitmType == "03" { //检查费
  8070. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8071. // checkCostSelfTotal = checkCostTotal
  8072. // }
  8073. //
  8074. // if item.MedChrgitmType == "04" { //化验费
  8075. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8076. // laboratoryCostSelfTotal = laboratoryCostTotal
  8077. // }
  8078. //
  8079. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8080. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8081. // treatCostSelfTotal = treatCostTotal
  8082. // }
  8083. //
  8084. // if item.MedChrgitmType == "06" { //手术费
  8085. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8086. // operationCostSelfTotal = treatCostTotal
  8087. // }
  8088. //
  8089. // if item.MedChrgitmType == "08" { //材料费
  8090. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8091. // materialCostSelfTotal = materialCostTotal
  8092. // }
  8093. //
  8094. // if item.MedChrgitmType == "09" { //西药费
  8095. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8096. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8097. // }
  8098. //
  8099. // if item.MedChrgitmType == "11" { //中成费
  8100. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8101. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8102. // }
  8103. //
  8104. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8105. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8106. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8107. // otherCostSelfTotal = otherCostTotal
  8108. // }
  8109. // } else {
  8110. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8111. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8112. // otherCostSelfTotal = otherCostTotal
  8113. // }
  8114. //
  8115. // }
  8116. //
  8117. // }
  8118. //
  8119. // } else {
  8120. // for _, item := range orderInfos {
  8121. // if item.MedChrgitmType == "01" { //床位费
  8122. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8123. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8124. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8125. // }
  8126. //
  8127. // if item.MedChrgitmType == "02" { //诊察费
  8128. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8129. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8130. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8131. // }
  8132. //
  8133. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8134. // if item.MedChrgitmType == "03" { //检查费
  8135. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8136. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8137. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8138. //
  8139. // }
  8140. // } else {
  8141. // if item.MedChrgitmType == "03" { //检查费
  8142. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8143. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8144. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8145. // }
  8146. //
  8147. // }
  8148. //
  8149. // if item.MedChrgitmType == "04" { //化验费
  8150. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8151. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8152. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8153. //
  8154. // }
  8155. //
  8156. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8157. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8158. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8159. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8160. //
  8161. // }
  8162. //
  8163. // if item.MedChrgitmType == "06" { //手术费
  8164. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8165. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8166. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8167. // }
  8168. //
  8169. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8170. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8171. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8172. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8173. // }
  8174. //
  8175. // if item.MedChrgitmType == "09" { //西药费
  8176. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8177. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8178. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8179. // }
  8180. //
  8181. // if item.MedChrgitmType == "11" { //中成费
  8182. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8183. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8184. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8185. // }
  8186. //
  8187. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8188. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8189. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8190. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8191. // }
  8192. //
  8193. // }
  8194. // }
  8195. // timeLayout := "2006-01-02"
  8196. // loc, _ := time.LoadLocation("Local")
  8197. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8198. // if err != nil {
  8199. // }
  8200. // startRecordDateTime := startTime.Unix()
  8201. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8202. // if err != nil {
  8203. // }
  8204. // endRecordDateTime := endTime.Unix()
  8205. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8206. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8207. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8208. //
  8209. // c.ServeSuccessJSON(map[string]interface{}{
  8210. // "order_number": order.Number, //业务流水号
  8211. // "id_card_no": his.IdCardNo, //社会保障号
  8212. // "department_name": department.Name, //科室
  8213. // "number": his.Number, //门诊号
  8214. // "date": order.SettleAccountsDate, //结算日期
  8215. // "name": order.PsnName, //姓名
  8216. // "gender": patient.Gender, //性别
  8217. // "psn_cash_money": order.PsnCashPay, //个人支付
  8218. // "pay_way": "门诊", //结算方式
  8219. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8220. // "admin_user_name": admin.UserName, //收款员
  8221. // "order": order,
  8222. // "order_info": orderInfos_two,
  8223. // "his": his,
  8224. // "bedCostTotal": bedCostTotal,
  8225. // "bedCostSelfTotal": bedCostSelfTotal,
  8226. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8227. // "operationCostTotal": operationCostTotal,
  8228. // "operationCostSelfTotal": operationCostSelfTotal,
  8229. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8230. // "otherCostTotal": otherCostTotal,
  8231. // "otherCostSelfTotal": otherCostSelfTotal,
  8232. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8233. // "materialCostTotal": materialCostTotal,
  8234. // "materialCostSelfTotal": materialCostSelfTotal,
  8235. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8236. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8237. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8238. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8239. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8240. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8241. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8242. // "checkCostTotal": checkCostTotal,
  8243. // "checkCostSelfTotal": checkCostSelfTotal,
  8244. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8245. // "laboratoryCostTotal": laboratoryCostTotal,
  8246. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8247. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8248. // "treatCostTotal": treatCostTotal,
  8249. // "treatCostSelfTotal": treatCostSelfTotal,
  8250. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8251. // "zhenChaCostTotal": zhenChaCostTotal,
  8252. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8253. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8254. // "his_hospital_record": his_hospital_record,
  8255. // "pre_pay_money": pre_pay_money,
  8256. // "refund_sum": sum,
  8257. // })
  8258. //
  8259. //}
  8260. func (this *HisApiController) GetIncomeStatisticsData() {
  8261. start_time := this.GetString("start_time")
  8262. end_time := this.GetString("end_time")
  8263. key_words := this.GetString("key_words")
  8264. limit, _ := this.GetInt64("limit")
  8265. page, _ := this.GetInt64("page")
  8266. if page <= 0 {
  8267. page = 1
  8268. }
  8269. if limit <= 0 {
  8270. limit = 10
  8271. }
  8272. statistics_type, _ := this.GetInt64("statistics_type")
  8273. admin := this.GetAdminUserInfo()
  8274. timeLayout := "2006-01-02"
  8275. loc, _ := time.LoadLocation("Local")
  8276. var theStartTIme int64
  8277. if len(start_time) > 0 {
  8278. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8279. if err != nil {
  8280. theStartTIme = 0
  8281. }
  8282. theStartTIme = theTime.Unix()
  8283. }
  8284. var theEndtTIme int64
  8285. if len(end_time) > 0 {
  8286. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8287. if err != nil {
  8288. theEndtTIme = 0
  8289. }
  8290. theEndtTIme = theTime.Unix()
  8291. }
  8292. if statistics_type == 1 {
  8293. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8294. this.ServeSuccessJSON(map[string]interface{}{
  8295. "list": list,
  8296. "total": total,
  8297. })
  8298. } else {
  8299. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8300. this.ServeSuccessJSON(map[string]interface{}{
  8301. "list": list,
  8302. "total": total,
  8303. })
  8304. }
  8305. }
  8306. func (c *HisApiController) PostProjectInformation() {
  8307. adminUser := c.GetAdminUserInfo()
  8308. orgId := adminUser.CurrentOrgId
  8309. dataBody := make(map[string]interface{}, 0)
  8310. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8311. if err != nil {
  8312. utils.ErrorLog(err.Error())
  8313. return
  8314. }
  8315. utils.ErrorLog("%v", dataBody)
  8316. var projectList []*models.HisProject
  8317. var total_goods []interface{}
  8318. tempProjects := dataBody["projects"].([]interface{})
  8319. total_goods = tempProjects
  8320. for index, projectMap := range tempProjects {
  8321. projectM := projectMap.(map[string]interface{})
  8322. var project models.HisProject
  8323. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8324. utils.ErrorLog("project_name")
  8325. return
  8326. }
  8327. project_name, _ := projectM["project_name"].(string)
  8328. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8329. err_log := models.ExportErrLog{
  8330. LogType: 6,
  8331. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8332. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8333. Status: 1,
  8334. CreateTime: time.Now().Unix(),
  8335. UpdateTime: time.Now().Unix(),
  8336. ExportTime: time.Now().Unix(),
  8337. }
  8338. service.CreateExportErrLog(&err_log)
  8339. continue
  8340. }
  8341. project.ProjectName = project_name
  8342. prices := projectM["price"].(string)
  8343. price, _ := strconv.ParseFloat(prices, 64)
  8344. if price <= 0 { //名字为空则生成一条导入错误日志
  8345. err_log := models.ExportErrLog{
  8346. LogType: 6,
  8347. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8348. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8349. Status: 1,
  8350. CreateTime: time.Now().Unix(),
  8351. UpdateTime: time.Now().Unix(),
  8352. ExportTime: time.Now().Unix(),
  8353. }
  8354. service.CreateExportErrLog(&err_log)
  8355. continue
  8356. }
  8357. project.Price = price
  8358. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8359. utils.ErrorLog("unit_id")
  8360. return
  8361. }
  8362. unit := projectM["unit"].(string)
  8363. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8364. err_log := models.ExportErrLog{
  8365. LogType: 6,
  8366. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8367. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8368. Status: 1,
  8369. CreateTime: time.Now().Unix(),
  8370. UpdateTime: time.Now().Unix(),
  8371. ExportTime: time.Now().Unix(),
  8372. }
  8373. service.CreateExportErrLog(&err_log)
  8374. continue
  8375. }
  8376. project.Unit = unit
  8377. cost_classify := projectM["cost_classify"].(string)
  8378. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8379. err_log := models.ExportErrLog{
  8380. LogType: 6,
  8381. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8382. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8383. Status: 1,
  8384. CreateTime: time.Now().Unix(),
  8385. UpdateTime: time.Now().Unix(),
  8386. ExportTime: time.Now().Unix(),
  8387. }
  8388. service.CreateExportErrLog(&err_log)
  8389. continue
  8390. }
  8391. var costClassify = "费用类别"
  8392. var cost_classify_id int64
  8393. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8394. if len(cost_classify) != 0 {
  8395. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8396. if errcode == gorm.ErrRecordNotFound {
  8397. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8398. dataconfig := models.DictDataconfig{
  8399. ParentId: costClassifyConfig.ID,
  8400. Module: "system",
  8401. OrgId: orgId,
  8402. Name: cost_classify,
  8403. FieldName: "",
  8404. Value: costConfig.Value + 1,
  8405. CreatedTime: "",
  8406. UpdatedTime: "",
  8407. CreateUserId: adminUser.AdminUser.Id,
  8408. Status: 1,
  8409. Remark: "",
  8410. DeleteIdSystem: 0,
  8411. Title: "",
  8412. Content: "",
  8413. Order: 0,
  8414. Code: "",
  8415. }
  8416. service.CreatedDicConfig(&dataconfig)
  8417. }
  8418. }
  8419. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8420. for _, it := range costClassList {
  8421. if cost_classify == it.Name {
  8422. cost_classify_id = int64(it.Value)
  8423. }
  8424. }
  8425. project.CostClassify = cost_classify_id
  8426. executive_section := projectM["executive_section"].(string)
  8427. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8428. err_log := models.ExportErrLog{
  8429. LogType: 6,
  8430. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8431. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8432. Status: 1,
  8433. CreateTime: time.Now().Unix(),
  8434. UpdateTime: time.Now().Unix(),
  8435. ExportTime: time.Now().Unix(),
  8436. }
  8437. service.CreateExportErrLog(&err_log)
  8438. continue
  8439. }
  8440. if len(executive_section) != 0 {
  8441. //查找科室是否有内容
  8442. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8443. if errcodedepart == gorm.ErrRecordNotFound {
  8444. department := models.XtHisDepartment{
  8445. Name: executive_section,
  8446. Status: 1,
  8447. UserOrgId: adminUser.CurrentOrgId,
  8448. CreatedTime: time.Now().Unix(),
  8449. }
  8450. service.CreateDePartment(&department)
  8451. }
  8452. }
  8453. var executive_section_id int64
  8454. departMentList, _ := service.GetAllDepartMent(orgId)
  8455. for _, it := range departMentList {
  8456. if executive_section == it.Name {
  8457. executive_section_id = it.ID
  8458. }
  8459. }
  8460. project.ExecutiveSection = executive_section_id
  8461. medical_coverage := projectM["medical_coverage"].(string)
  8462. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8463. err_log := models.ExportErrLog{
  8464. LogType: 6,
  8465. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8466. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8467. Status: 1,
  8468. CreateTime: time.Now().Unix(),
  8469. UpdateTime: time.Now().Unix(),
  8470. ExportTime: time.Now().Unix(),
  8471. }
  8472. service.CreateExportErrLog(&err_log)
  8473. continue
  8474. }
  8475. var medicalCoverage = "医保等级"
  8476. var medical_coverage_id int64
  8477. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8478. if len(medical_coverage) != 0 {
  8479. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8480. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8481. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8482. dataconfig := models.DictDataconfig{
  8483. ParentId: medicalCoverageConfig.ID,
  8484. Module: "system",
  8485. OrgId: orgId,
  8486. Name: medical_coverage,
  8487. FieldName: "",
  8488. Value: medicalCoverageConfig.Value + 1,
  8489. CreatedTime: "",
  8490. UpdatedTime: "",
  8491. CreateUserId: adminUser.AdminUser.Id,
  8492. Status: 1,
  8493. Remark: "",
  8494. DeleteIdSystem: 0,
  8495. Title: "",
  8496. Content: "",
  8497. Order: 0,
  8498. Code: "",
  8499. }
  8500. service.CreatedDicConfig(&dataconfig)
  8501. }
  8502. }
  8503. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8504. for _, it := range medicalCoverageList {
  8505. if medical_coverage == it.Name {
  8506. medical_coverage_id = int64(it.Value)
  8507. }
  8508. }
  8509. project.MedicalCoverage = medical_coverage_id
  8510. pinyin := projectM["pinyin"].(string)
  8511. project.Pinyin = pinyin
  8512. wubi := projectM["wubi"].(string)
  8513. project.Wubi = wubi
  8514. statistical_classification := projectM["statistical_classification"].(string)
  8515. var statisticalClassification = "统计分类"
  8516. var statistical_classification_id int64
  8517. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8518. if len(statistical_classification) != 0 {
  8519. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8520. if classificationerrcodes == gorm.ErrRecordNotFound {
  8521. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8522. dataconfig := models.DictDataconfig{
  8523. ParentId: classiFication.ID,
  8524. Module: "system",
  8525. OrgId: orgId,
  8526. Name: statistical_classification,
  8527. FieldName: "",
  8528. Value: classiFicationConfig.Value + 1,
  8529. CreatedTime: "",
  8530. UpdatedTime: "",
  8531. CreateUserId: adminUser.AdminUser.Id,
  8532. Status: 1,
  8533. Remark: "",
  8534. DeleteIdSystem: 0,
  8535. Title: "",
  8536. Content: "",
  8537. Order: 0,
  8538. Code: "",
  8539. }
  8540. service.CreatedDicConfig(&dataconfig)
  8541. }
  8542. }
  8543. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8544. for _, it := range classiFicationList {
  8545. if statistical_classification == it.Name {
  8546. statistical_classification_id = int64(it.Value)
  8547. }
  8548. }
  8549. project.StatisticalClassification = statistical_classification_id
  8550. disease_directory := int64(projectM["disease_directory"].(float64))
  8551. project.DiseaseDirectory = disease_directory
  8552. is_record := int64(projectM["is_record"].(float64))
  8553. project.IsRecord = is_record
  8554. medical_code := projectM["medical_code"].(string)
  8555. project.MedicalCode = medical_code
  8556. tube_color := projectM["tube_color"].(string)
  8557. var tubeColor = "试管颜色"
  8558. var tube_color_id int64
  8559. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8560. if len(tube_color) != 0 {
  8561. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8562. if errcodetube == gorm.ErrRecordNotFound {
  8563. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8564. dataconfig := models.DictDataconfig{
  8565. ParentId: tubeColorConfig.ID,
  8566. Module: "system",
  8567. OrgId: orgId,
  8568. Name: tube_color,
  8569. FieldName: "",
  8570. Value: tubeConfig.Value + 1,
  8571. CreatedTime: "",
  8572. UpdatedTime: "",
  8573. CreateUserId: adminUser.AdminUser.Id,
  8574. Status: 1,
  8575. Remark: "",
  8576. DeleteIdSystem: 0,
  8577. Title: "",
  8578. Content: "",
  8579. Order: 0,
  8580. Code: "",
  8581. }
  8582. service.CreatedDicConfig(&dataconfig)
  8583. }
  8584. }
  8585. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8586. for _, it := range tubeColorList {
  8587. if tube_color == it.Name {
  8588. tube_color_id = int64(it.Value)
  8589. }
  8590. }
  8591. project.TubeColor = tube_color_id
  8592. single_dose := projectM["single_dose"].(string)
  8593. project.SingleDose = single_dose
  8594. execution_frequency := projectM["execution_frequency"].(string)
  8595. project.ExecutionFrequency = execution_frequency
  8596. delivery_way := projectM["delivery_way"].(string)
  8597. project.DeliveryWay = delivery_way
  8598. number_days := projectM["number_days"].(string)
  8599. project.NumberDays = number_days
  8600. total := projectM["total"].(string)
  8601. project.Total = total
  8602. medical_status := int64(projectM["medical_status"].(float64))
  8603. project.MedicalStatus = medical_status
  8604. category := int64(projectM["category"].(float64))
  8605. project.Category = category
  8606. specail_project := int64(projectM["specail_project"].(float64))
  8607. project.SpecailProject = specail_project
  8608. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8609. project.SocialSecurityDirectoryCode = social_security_directory_code
  8610. remark := projectM["remark"].(string)
  8611. project.Remark = remark
  8612. record_date := projectM["record_date"].(string)
  8613. timeLayout := "2006-01-02"
  8614. loc, _ := time.LoadLocation("Local")
  8615. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8616. project.RecordDate = theTime.Unix()
  8617. projectList = append(projectList, &project)
  8618. }
  8619. export_time := time.Now().Unix()
  8620. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8621. if len(projectList) > 0 {
  8622. for _, item := range projectList {
  8623. project := models.HisProject{
  8624. ProjectName: item.ProjectName,
  8625. Price: item.Price,
  8626. Unit: item.Unit,
  8627. CostClassify: item.CostClassify,
  8628. ExecutiveSection: item.ExecutiveSection,
  8629. MedicalCoverage: item.MedicalCoverage,
  8630. UserOrgId: orgId,
  8631. Status: 1,
  8632. CreatedTime: time.Now().Unix(),
  8633. Pinyin: item.Pinyin,
  8634. Wubi: item.Wubi,
  8635. StatisticalClassification: item.StatisticalClassification,
  8636. DiseaseDirectory: item.DiseaseDirectory,
  8637. IsRecord: item.IsRecord,
  8638. MedicalCode: item.MedicalCode,
  8639. TubeColor: item.TubeColor,
  8640. SingleDose: item.SingleDose,
  8641. DeliveryWay: item.DeliveryWay,
  8642. NumberDays: item.NumberDays,
  8643. Total: item.Total,
  8644. Category: item.Category,
  8645. MedicalStatus: item.MedicalStatus,
  8646. SpecailProject: item.SpecailProject,
  8647. RecordDate: item.RecordDate,
  8648. Remark: item.Remark,
  8649. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8650. ExecutionFrequency: item.ExecutionFrequency,
  8651. }
  8652. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8653. if errcodeproject == gorm.ErrRecordNotFound {
  8654. service.CreateProjectInfomation(&project)
  8655. } else if errcodeproject == nil {
  8656. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8657. }
  8658. log := models.ExportLog{
  8659. LogType: 6,
  8660. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8661. TotalNum: int64(len(total_goods)),
  8662. FailNum: int64(len(errLogs)),
  8663. SuccessNum: int64(len(projectList)),
  8664. CreateTime: time.Now().Unix(),
  8665. UpdateTime: time.Now().Unix(),
  8666. ExportTime: export_time,
  8667. Status: 1,
  8668. }
  8669. service.CreateExportLog(&log)
  8670. c.ServeSuccessJSON(map[string]interface{}{
  8671. "msg": "导入成功",
  8672. "total_num": len(total_goods),
  8673. "success_num": len(projectList),
  8674. "fail_num": int64(len(errLogs)),
  8675. })
  8676. }
  8677. } else {
  8678. log := models.ExportLog{
  8679. LogType: 6,
  8680. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8681. TotalNum: int64(len(total_goods)),
  8682. FailNum: int64(len(errLogs)),
  8683. SuccessNum: int64(len(projectList)),
  8684. CreateTime: time.Now().Unix(),
  8685. UpdateTime: time.Now().Unix(),
  8686. ExportTime: export_time,
  8687. Status: 1,
  8688. }
  8689. service.CreateExportLog(&log)
  8690. c.ServeSuccessJSON(map[string]interface{}{
  8691. "msg": "导入成功",
  8692. "total_num": len(total_goods),
  8693. "success_num": len(projectList),
  8694. "fail_num": int64(len(errLogs)),
  8695. })
  8696. }
  8697. }
  8698. //func (this *HisApiController) EditProjectInformation(){
  8699. //
  8700. // id, _ := this.GetInt64("id")
  8701. // project_team := this.GetString("project_team")
  8702. // price := this.GetString("price")
  8703. // price_float, _ := strconv.ParseFloat(price, 64)
  8704. // pinyin := this.GetString("pinyin")
  8705. // wubi := this.GetString("wubi")
  8706. // tube_color, _ := this.GetInt64("tube_color")
  8707. // team_type, _ := this.GetInt64("team_type")
  8708. // remark := this.GetString("remark")
  8709. // ids := this.GetString("ids")
  8710. // item_id := this.GetString("item_id")
  8711. // projectTeam := models.XtHisProjectTeam{
  8712. // ProjectTeam: project_team,
  8713. // Price: price_float,
  8714. // Pinyin: pinyin,
  8715. // Wubi: wubi,
  8716. // TubeColor: tube_color,
  8717. // TeamType: team_type,
  8718. // Remark: remark,
  8719. // ProjectId: ids,
  8720. // ItemId: item_id,
  8721. // }
  8722. //
  8723. //
  8724. // dataBody := make(map[string]interface{}, 0)
  8725. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8726. // if err != nil {
  8727. // utils.ErrorLog(err.Error())
  8728. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8729. // return
  8730. // }
  8731. //
  8732. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8733. //
  8734. //
  8735. // if err != nil {
  8736. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8737. // return
  8738. // }
  8739. //
  8740. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8741. // infos, _ := dataBody["info"].([]interface{})
  8742. // if len(infos) > 0 {
  8743. // var ids []string
  8744. //
  8745. // for _, item := range infos {
  8746. // items := item.(map[string]interface{})
  8747. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8748. // utils.ErrorLog("id")
  8749. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8750. // return
  8751. // }
  8752. // id := int64(items["id"].(float64))
  8753. //
  8754. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8755. // utils.ErrorLog("type")
  8756. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8757. // return
  8758. // }
  8759. // types := int64(items["type"].(float64))
  8760. //
  8761. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8762. // utils.ErrorLog("number")
  8763. // }
  8764. //
  8765. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8766. //
  8767. // projectList := models.XtHisProjectList{
  8768. // Number: number,
  8769. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8770. // ProjectId: id,
  8771. // Status: 1,
  8772. // CreatedTime: time.Now().Unix(),
  8773. // UpdatedTime: time.Now().Unix(),
  8774. // TeamId: projectTeam.ID,
  8775. // Type: types,
  8776. // }
  8777. // list := projectList
  8778. //
  8779. // service.CreateProjectList(&list)
  8780. //
  8781. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8782. //
  8783. // }
  8784. // ids_str := strings.Join(ids, ",")
  8785. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8786. // service.SaveProjectTeam(&projectTeam)
  8787. // this.ServeSuccessJSON(map[string]interface{}{
  8788. // "projectTeam": projectTeam,
  8789. // })
  8790. // }
  8791. // }
  8792. //}
  8793. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8794. name := c.GetString("name")
  8795. mode_id, _ := c.GetInt64("mode", 0)
  8796. types, _ := c.GetInt64("type", 0)
  8797. patient_id, _ := c.GetInt64("patient_id", 0)
  8798. types = 1
  8799. adminInfo := c.GetAdminUserInfo()
  8800. template := &models.HisPrescriptionTemplate{
  8801. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8802. PatientId: patient_id,
  8803. Type: types,
  8804. Status: 1,
  8805. Ctime: time.Now().Unix(),
  8806. Mtime: time.Now().Unix(),
  8807. Name: name,
  8808. Mode: mode_id,
  8809. }
  8810. dataBody := make(map[string]interface{}, 0)
  8811. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8812. if err != nil {
  8813. utils.ErrorLog(err.Error())
  8814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8815. return
  8816. }
  8817. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8818. //如果已经存在记录则删除处方
  8819. if template_one.ID > 0 {
  8820. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8821. for _, item := range ps {
  8822. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8823. }
  8824. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8825. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8826. if len(prescriptions) > 0 {
  8827. for _, item := range prescriptions {
  8828. items := item.(map[string]interface{})
  8829. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8830. utils.ErrorLog("type")
  8831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8832. return
  8833. }
  8834. types := int64(items["type"].(float64))
  8835. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8836. utils.ErrorLog("med_type")
  8837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8838. return
  8839. }
  8840. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8841. ctime := time.Now().Unix()
  8842. prescription := &models.HisPrescriptionInfoTemplate{
  8843. PatientId: patient_id,
  8844. UserOrgId: adminInfo.CurrentOrgId,
  8845. Ctime: ctime,
  8846. Mtime: ctime,
  8847. Type: types,
  8848. Modifier: adminInfo.AdminUser.Id,
  8849. Creator: adminInfo.AdminUser.Id,
  8850. Status: 1,
  8851. PTemplateId: template_one.ID,
  8852. MedType: med_type,
  8853. }
  8854. service.CreateHisPrescriptionInfoTemplate(prescription)
  8855. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8856. advices := items["advices"].([]interface{})
  8857. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8858. ctime := time.Now().Unix()
  8859. mtime := ctime
  8860. if len(advices) > 0 {
  8861. for _, advice := range advices {
  8862. var s models.HisPrescriptionAdviceTemplate
  8863. s.PrescriptionId = prescription.ID
  8864. s.AdviceType = 2
  8865. s.StopState = 2
  8866. s.ExecutionState = 2
  8867. s.Status = 1
  8868. s.UserOrgId = adminInfo.CurrentOrgId
  8869. s.CreatedTime = ctime
  8870. s.UpdatedTime = mtime
  8871. s.PatientId = patient_id
  8872. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8873. if errcode > 0 {
  8874. c.ServeFailJSONWithSGJErrorCode(errcode)
  8875. return
  8876. }
  8877. service.CreateHisPrescriptionAdviceTemplate(&s)
  8878. }
  8879. }
  8880. }
  8881. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8882. projects := items["project"].([]interface{})
  8883. if len(projects) > 0 {
  8884. for _, project := range projects {
  8885. var p models.HisPrescriptionProjectTemplate
  8886. p.PrescriptionId = prescription.ID
  8887. p.Ctime = time.Now().Unix()
  8888. p.Mtime = time.Now().Unix()
  8889. p.PatientId = patient_id
  8890. p.UserOrgId = adminInfo.CurrentOrgId
  8891. p.Status = 1
  8892. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8893. if errcode > 0 {
  8894. c.ServeFailJSONWithSGJErrorCode(errcode)
  8895. return
  8896. }
  8897. service.CreateHisPrescriptionProjectTemplate(&p)
  8898. }
  8899. }
  8900. }
  8901. }
  8902. c.ServeSuccessJSON(map[string]interface{}{
  8903. "msg": "创建成功",
  8904. })
  8905. }
  8906. }
  8907. } else {
  8908. err = service.CreateHisPrescriptionTemplate(template)
  8909. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8910. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8911. if len(prescriptions) > 0 {
  8912. for _, item := range prescriptions {
  8913. items := item.(map[string]interface{})
  8914. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8915. utils.ErrorLog("type")
  8916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8917. return
  8918. }
  8919. types := int64(items["type"].(float64))
  8920. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8921. utils.ErrorLog("med_type")
  8922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8923. return
  8924. }
  8925. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8926. ctime := time.Now().Unix()
  8927. prescription := &models.HisPrescriptionInfoTemplate{
  8928. PatientId: patient_id,
  8929. UserOrgId: adminInfo.CurrentOrgId,
  8930. Ctime: ctime,
  8931. Mtime: ctime,
  8932. Type: types,
  8933. Modifier: adminInfo.AdminUser.Id,
  8934. Creator: adminInfo.AdminUser.Id,
  8935. Status: 1,
  8936. PTemplateId: template.ID,
  8937. MedType: med_type,
  8938. }
  8939. service.CreateHisPrescriptionInfoTemplate(prescription)
  8940. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8941. advices := items["advices"].([]interface{})
  8942. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8943. ctime := time.Now().Unix()
  8944. mtime := ctime
  8945. if len(advices) > 0 {
  8946. for _, advice := range advices {
  8947. var s models.HisPrescriptionAdviceTemplate
  8948. s.PrescriptionId = prescription.ID
  8949. s.AdviceType = 2
  8950. s.StopState = 2
  8951. s.ExecutionState = 2
  8952. s.Status = 1
  8953. s.UserOrgId = adminInfo.CurrentOrgId
  8954. s.CreatedTime = ctime
  8955. s.UpdatedTime = mtime
  8956. s.PatientId = patient_id
  8957. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8958. if errcode > 0 {
  8959. c.ServeFailJSONWithSGJErrorCode(errcode)
  8960. return
  8961. }
  8962. service.CreateHisPrescriptionAdviceTemplate(&s)
  8963. }
  8964. }
  8965. }
  8966. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8967. projects := items["project"].([]interface{})
  8968. if len(projects) > 0 {
  8969. for _, project := range projects {
  8970. var p models.HisPrescriptionProjectTemplate
  8971. p.PrescriptionId = prescription.ID
  8972. p.Ctime = time.Now().Unix()
  8973. p.Mtime = time.Now().Unix()
  8974. p.PatientId = patient_id
  8975. p.UserOrgId = adminInfo.CurrentOrgId
  8976. p.Status = 1
  8977. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8978. if errcode > 0 {
  8979. c.ServeFailJSONWithSGJErrorCode(errcode)
  8980. return
  8981. }
  8982. service.CreateHisPrescriptionProjectTemplate(&p)
  8983. }
  8984. }
  8985. }
  8986. }
  8987. c.ServeSuccessJSON(map[string]interface{}{
  8988. "msg": "创建成功",
  8989. })
  8990. }
  8991. }
  8992. }
  8993. }
  8994. func (c *HisApiController) PreSettle() {
  8995. id, _ := c.GetInt64("id")
  8996. record_time := c.GetString("record_time")
  8997. his_patient_id, _ := c.GetInt64("his_patient_id")
  8998. timeLayout := "2006-01-02"
  8999. loc, _ := time.LoadLocation("Local")
  9000. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9001. diagnosis_id := c.GetString("diagnosis")
  9002. sick_type, _ := c.GetInt64("sick_type")
  9003. reg_type, _ := c.GetInt64("p_type")
  9004. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9005. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9006. if err != nil {
  9007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9008. return
  9009. }
  9010. recordDateTime := theTime.Unix()
  9011. adminUser := c.GetAdminUserInfo()
  9012. var prescriptions []*models.HisPrescription
  9013. var start_time int64
  9014. var end_time int64
  9015. ids_str := c.GetString("ids")
  9016. ids_arr := strings.Split(ids_str, ",")
  9017. fmt.Println(reg_type)
  9018. if settle_accounts_type == 1 { //日结
  9019. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9020. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9021. } else {
  9022. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9023. }
  9024. fmt.Println(prescriptions)
  9025. } else { //月结
  9026. start_time_str := c.GetString("start_time")
  9027. end_time_str := c.GetString("end_time")
  9028. timeLayout := "2006-01-02"
  9029. loc, _ := time.LoadLocation("Local")
  9030. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9031. if err != nil {
  9032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9033. return
  9034. }
  9035. recordStartTime := theStartTime.Unix()
  9036. start_time = recordStartTime
  9037. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9038. if err != nil {
  9039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9040. return
  9041. }
  9042. recordEndTime := theEndTime.Unix()
  9043. end_time = recordEndTime
  9044. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9045. }
  9046. if reg_type == 1111 || reg_type == 1112 {
  9047. reg_type = 11
  9048. }
  9049. timestamp := time.Now().Unix()
  9050. tempTime := time.Unix(timestamp, 0)
  9051. timeFormat := tempTime.Format("20060102150405")
  9052. chrgBchno := rand.Intn(100000) + 10000
  9053. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9054. strconv.FormatInt(his.PatientId, 10)
  9055. var ids []int64
  9056. for _, item := range prescriptions {
  9057. ids = append(ids, item.ID)
  9058. }
  9059. fmt.Println(ids)
  9060. var total float64
  9061. for _, item := range prescriptions {
  9062. fmt.Println(item)
  9063. if item.Type == 1 { //药品
  9064. for _, subItem := range item.HisDoctorAdviceInfo {
  9065. total = total + (subItem.Price * subItem.PrescribingNumber)
  9066. }
  9067. }
  9068. if item.Type == 2 { //项目
  9069. for _, subItem := range item.HisPrescriptionProject {
  9070. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9071. total = total + (subItem.Price * cnt)
  9072. }
  9073. }
  9074. for _, subItem := range item.HisAdditionalCharge {
  9075. total = total + (subItem.Price * float64(subItem.Count))
  9076. }
  9077. }
  9078. allTotal := fmt.Sprintf("%.2f", total)
  9079. totals, _ := strconv.ParseFloat(allTotal, 64)
  9080. order := &models.HisOrder{
  9081. UserOrgId: adminUser.CurrentOrgId,
  9082. HisPatientId: his.ID,
  9083. PatientId: id,
  9084. SettleAccountsDate: recordDateTime,
  9085. Ctime: time.Now().Unix(),
  9086. Mtime: time.Now().Unix(),
  9087. Status: 1,
  9088. OrderStatus: 1,
  9089. MdtrtId: his.Number,
  9090. Number: chrg_bchno,
  9091. MedfeeSumamt: totals,
  9092. SettleEndTime: end_time,
  9093. SettleStartTime: start_time,
  9094. SettleType: settle_accounts_type,
  9095. PsnPartAmt: totals,
  9096. PsnCashPay: totals,
  9097. PType: 2,
  9098. IsPre: 1,
  9099. MedType: strconv.Itoa(int(reg_type)),
  9100. Diagnosis: diagnosis_id,
  9101. }
  9102. err = service.CreateOrder(order)
  9103. if err != nil {
  9104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9105. return
  9106. }
  9107. var customs []*Custom
  9108. for _, item := range prescriptions {
  9109. fmt.Println(item.Type)
  9110. if item.Type == 1 { //药品
  9111. for _, subItem := range item.HisDoctorAdviceInfo {
  9112. cus := &Custom{
  9113. AdviceId: subItem.ID,
  9114. ProjectId: 0,
  9115. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9116. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9117. FeedetlSn: subItem.FeedetlSn,
  9118. Price: fmt.Sprintf("%.2f", subItem.Price),
  9119. MedListCodg: subItem.MedListCodg,
  9120. Type: 1,
  9121. }
  9122. customs = append(customs, cus)
  9123. }
  9124. }
  9125. if item.Type == 2 { //项目
  9126. for _, subItem := range item.HisPrescriptionProject {
  9127. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9128. cus := &Custom{
  9129. AdviceId: 0,
  9130. ProjectId: subItem.ID,
  9131. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9132. Cut: fmt.Sprintf("%.2f", cnt),
  9133. FeedetlSn: subItem.FeedetlSn,
  9134. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9135. MedListCodg: subItem.MedListCodg,
  9136. Type: 2,
  9137. }
  9138. customs = append(customs, cus)
  9139. }
  9140. }
  9141. for _, item := range item.HisAdditionalCharge {
  9142. cus := &Custom{
  9143. ItemId: item.ID,
  9144. AdviceId: 0,
  9145. ProjectId: 0,
  9146. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9147. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9148. FeedetlSn: item.FeedetlSn,
  9149. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9150. MedListCodg: item.XtHisAddtionConfig.Code,
  9151. Type: 3,
  9152. }
  9153. customs = append(customs, cus)
  9154. }
  9155. }
  9156. fmt.Println(customs)
  9157. for _, item := range customs {
  9158. var advice_id int64 = 0
  9159. var project_id int64 = 0
  9160. var item_id int64 = 0
  9161. var types int64 = 0
  9162. if item.Type == 1 {
  9163. advice_id = item.AdviceId
  9164. project_id = 0
  9165. item_id = 0
  9166. } else if item.Type == 2 {
  9167. advice_id = 0
  9168. item_id = 0
  9169. project_id = item.ProjectId
  9170. } else if item.Type == 3 {
  9171. advice_id = 0
  9172. item_id = item.ItemId
  9173. project_id = 0
  9174. }
  9175. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9176. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9177. pric, _ := strconv.ParseFloat(item.Price, 32)
  9178. info := &models.HisOrderInfo{
  9179. OrderNumber: order.Number,
  9180. UploadDate: time.Now().Unix(),
  9181. AdviceId: advice_id,
  9182. DetItemFeeSumamt: detItemFeeSumamt,
  9183. Cnt: cut,
  9184. Pric: pric,
  9185. PatientId: id,
  9186. Status: 1,
  9187. Mtime: time.Now().Unix(),
  9188. Ctime: time.Now().Unix(),
  9189. UserOrgId: adminUser.CurrentOrgId,
  9190. HisPatientId: his.ID,
  9191. OrderId: order.ID,
  9192. ProjectId: project_id,
  9193. Type: types,
  9194. ItemId: item_id,
  9195. }
  9196. service.CreateOrderInfo(info)
  9197. }
  9198. his.SickType = sick_type
  9199. service.UpdataHisPateint(&his)
  9200. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9201. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9202. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9203. if err == nil {
  9204. c.ServeSuccessJSON(map[string]interface{}{
  9205. "msg": "结算成功",
  9206. })
  9207. }
  9208. }
  9209. type CustomOrderInfo struct {
  9210. Name string
  9211. Spec string
  9212. Unit string
  9213. Count float64
  9214. Price float64
  9215. Total float64
  9216. }
  9217. func (c *HisApiController) GetPrivateExpensesInfo() {
  9218. order_id, _ := c.GetInt64("id", 0)
  9219. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9220. order, _ := service.GetHisOrderByID(order_id)
  9221. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9222. if order.ID == 0 {
  9223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9224. return
  9225. }
  9226. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9227. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9228. org_id := c.GetAdminUserInfo().CurrentOrgId
  9229. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9230. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9231. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9232. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9233. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9234. //var orderInfos_four []*models.HisOrderInfoTwo
  9235. //for _, item := range orderInfos_three {
  9236. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9237. // item.HisPrescriptionProject.IsCheckTeam = 1
  9238. // orderInfos_four = append(orderInfos_four, item)
  9239. //
  9240. // }
  9241. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9242. // item.HisPrescriptionProject.IsCheckTeam = 2
  9243. // orderInfos_two = append(orderInfos_two, item)
  9244. // }
  9245. //}
  9246. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9247. //var cus_slice []CustomOrderInfo
  9248. //for _, item := range new_order_info {
  9249. // var cus CustomOrderInfo
  9250. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9251. // cus.Unit = ""
  9252. // cus.Spec = ""
  9253. // var total float64
  9254. // for _, subItem := range orderInfos_four {
  9255. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9256. // total = total + subItem.DetItemFeeSumamt
  9257. // fmt.Println(subItem.DetItemFeeSumamt)
  9258. // }
  9259. // }
  9260. // cus.Count = 1
  9261. // cus.Total = total
  9262. // cus_slice = append(cus_slice, cus)
  9263. //}
  9264. orderInfos = append(orderInfos, orderInfos_two...)
  9265. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9266. //orderInfos = append(orderInfos, orderInfos_three...)
  9267. //}/**/
  9268. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9269. c.ServeSuccessJSON(map[string]interface{}{
  9270. "order": order,
  9271. "order_info": orderInfos,
  9272. "patient": patient,
  9273. "admin_info": adminInfo,
  9274. "his": his,
  9275. "current_admin": role,
  9276. "org_config": miConfig,
  9277. //"new_order_info": cus_slice,
  9278. })
  9279. }
  9280. func (this *HisApiController) ChangeMedType() {
  9281. med_type := this.GetString("med_type")
  9282. old_med_type := this.GetString("old_med_type")
  9283. ids := this.GetString("ids")
  9284. settle_type, _ := this.GetInt64("settle_type")
  9285. start_time := this.GetString("start_time")
  9286. end_time := this.GetString("end_time")
  9287. ids_arr := strings.Split(ids, ",")
  9288. if settle_type == 1 { //日结
  9289. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9290. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9291. prescription.MedType = med_type
  9292. err := service.SaveHisPrescription(&prescription)
  9293. if err == nil {
  9294. this.ServeSuccessJSON(map[string]interface{}{
  9295. "msg": "修改成功",
  9296. })
  9297. } else {
  9298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9299. return
  9300. }
  9301. } else if settle_type == 2 {
  9302. timeLayout := "2006-01-02"
  9303. loc, _ := time.LoadLocation("Local")
  9304. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9305. if err != nil {
  9306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9307. return
  9308. }
  9309. recordStartTime := theStartTime.Unix()
  9310. start_time_timestamp := recordStartTime
  9311. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9312. if err != nil {
  9313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9314. return
  9315. }
  9316. recordEndTime := theEndTime.Unix()
  9317. end_time_timestamp := recordEndTime
  9318. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9319. if updateErr == nil {
  9320. this.ServeSuccessJSON(map[string]interface{}{
  9321. "msg": "修改成功",
  9322. })
  9323. } else {
  9324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9325. return
  9326. }
  9327. }
  9328. }
  9329. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9330. patient_id, _ := c.GetInt64("patient_id")
  9331. his_patient_id, _ := c.GetInt64("his_patient_id")
  9332. record_date := c.GetString("record_date")
  9333. start_time := c.GetString("start_time")
  9334. end_time := c.GetString("end_time")
  9335. order_status, _ := c.GetInt64("type", 0)
  9336. p_type, _ := c.GetInt64("p_type", 0)
  9337. order_id, _ := c.GetInt64("order_id", 0)
  9338. timeLayout := "2006-01-02"
  9339. loc, _ := time.LoadLocation("Local")
  9340. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9341. if err != nil {
  9342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9343. return
  9344. }
  9345. recordDateTime := theTime.Unix()
  9346. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9347. if err != nil {
  9348. }
  9349. startRecordDateTime := startTime.Unix()
  9350. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9351. if err != nil {
  9352. }
  9353. endRecordDateTime := endTime.Unix()
  9354. admin := c.GetAdminUserInfo()
  9355. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9356. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9357. order, _ := service.GetHisOrderByID(order_id)
  9358. var monthPrescriptions []*models.HisPrescription
  9359. if order_status == 1 || order_status == 0 {
  9360. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9361. } else if order_status == 2 {
  9362. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9363. }
  9364. var settle_total float64
  9365. for _, item := range monthPrescriptions {
  9366. if len(item.HisPrescriptionProject) > 0 {
  9367. for _, subItem := range item.HisPrescriptionProject {
  9368. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9369. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9370. settle_total = settle_total + total
  9371. }
  9372. }
  9373. if len(item.HisDoctorAdviceInfo) > 0 {
  9374. for _, subItem := range item.HisDoctorAdviceInfo {
  9375. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9376. settle_total = settle_total + total
  9377. }
  9378. }
  9379. }
  9380. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9381. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9382. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9383. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9384. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9385. //获取所有科室信息
  9386. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9387. c.ServeSuccessJSON(map[string]interface{}{
  9388. "his_info": his_patient_info,
  9389. "xt_info": xt_patient_info,
  9390. "case_history": case_history,
  9391. "info": patientPrescriptionInfo,
  9392. "last_info": lastPatientPrescriptionInfo,
  9393. "month_prescriptions": monthPrescriptions,
  9394. "order": order,
  9395. "doctors": doctors,
  9396. "department": department,
  9397. "settle_total": settle_total,
  9398. })
  9399. return
  9400. }
  9401. func (c *HisApiController) GetHisMonthPatientInfo() {
  9402. patient_id, _ := c.GetInt64("patient_id")
  9403. his_patient_id, _ := c.GetInt64("his_patient_id")
  9404. record_date := c.GetString("record_date")
  9405. number := c.GetString("number")
  9406. start_time := c.GetString("start_time")
  9407. end_time := c.GetString("end_time")
  9408. p_type, _ := c.GetInt64("p_type")
  9409. timeLayout := "2006-01-02"
  9410. loc, _ := time.LoadLocation("Local")
  9411. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9412. if err != nil {
  9413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9414. return
  9415. }
  9416. recordDateTime := theTime.Unix()
  9417. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9418. if err != nil {
  9419. }
  9420. startRecordDateTime := startTime.Unix()
  9421. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9422. if err != nil {
  9423. }
  9424. endRecordDateTime := endTime.Unix()
  9425. admin := c.GetAdminUserInfo()
  9426. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9427. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9428. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9429. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9430. var settle_total float64
  9431. for _, item := range monthPrescriptions {
  9432. if len(item.HisPrescriptionProject) > 0 {
  9433. for _, subItem := range item.HisPrescriptionProject {
  9434. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9435. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9436. settle_total = settle_total + total
  9437. }
  9438. }
  9439. if len(item.HisDoctorAdviceInfo) > 0 {
  9440. for _, subItem := range item.HisDoctorAdviceInfo {
  9441. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9442. settle_total = settle_total + total
  9443. }
  9444. }
  9445. }
  9446. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9447. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9448. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9449. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9450. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9451. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9452. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9453. //获取所有科室信息
  9454. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9455. c.ServeSuccessJSON(map[string]interface{}{
  9456. "his_info": his_patient_info,
  9457. "xt_info": xt_patient_info,
  9458. "case_history": case_history,
  9459. "info": patientPrescriptionInfo,
  9460. "month_prescriptions": monthPrescriptions,
  9461. "order": order,
  9462. "doctors": doctors,
  9463. "department": department,
  9464. "count": count,
  9465. "drugStockConfig": drugStockConfig,
  9466. "last_info": lastPatientPrescriptionInfo,
  9467. "settle_total": settle_total,
  9468. })
  9469. return
  9470. }
  9471. func (c *HisApiController) GetAllOrder() {
  9472. org_id := c.GetAdminUserInfo().CurrentOrgId
  9473. orders, _ := service.GetNewHisOrderList(org_id)
  9474. c.ServeSuccessJSON(map[string]interface{}{
  9475. "order": orders,
  9476. })
  9477. return
  9478. }
  9479. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9480. newArr = make([]*models.HisOrderInfoTwo, 0)
  9481. for i := 0; i < len(arr); i++ {
  9482. repeat := false
  9483. for j := i + 1; j < len(arr); j++ {
  9484. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9485. repeat = true
  9486. break
  9487. }
  9488. }
  9489. if !repeat {
  9490. newArr = append(newArr, arr[i])
  9491. }
  9492. }
  9493. return
  9494. }
  9495. // 修改处方退库操作 参数传修改之前的处方数据
  9496. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9497. if advice.ExecutionState == 1 {
  9498. //查询该病人该药品是否有库存记录
  9499. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9500. if errcode == gorm.ErrRecordNotFound {
  9501. } else {
  9502. //退库
  9503. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9504. if advice.PrescribingNumberUnit == drug.MinUnit {
  9505. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9506. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9507. //退库
  9508. warehouseInfo := models.DrugWarehouseInfo{
  9509. StockMinNumber: prescribingNumber,
  9510. }
  9511. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9512. operation_time := time.Now().Unix()
  9513. creater := advice.AdviceDoctor
  9514. ctime := time.Now().Unix()
  9515. timeStr := time.Now().Format("2006-01-02")
  9516. timeArr := strings.Split(timeStr, "-")
  9517. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9518. total = total + 1
  9519. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9520. cancelStock := models.DrugCancelStock{
  9521. OrderNumber: orderNumber,
  9522. OperaTime: operation_time,
  9523. OrgId: advice.UserOrgId,
  9524. Creater: creater,
  9525. Ctime: ctime,
  9526. Status: 1,
  9527. ReturnTime: advice.AdviceDate,
  9528. Dealer: info.Dealer,
  9529. Manufacturer: info.Manufacturer,
  9530. Type: 1,
  9531. }
  9532. service.AddSigleDrugCancelStock(&cancelStock)
  9533. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9534. dealer, _ := service.GetDealerById(info.Dealer)
  9535. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9536. cancelStockInfo := models.DrugCancelStockInfo{
  9537. OrderNumber: cancelInfo.OrderNumber,
  9538. CancelStockId: cancelInfo.ID,
  9539. DrugId: info.DrugId,
  9540. Count: info.Count,
  9541. Status: 1,
  9542. Ctime: ctime,
  9543. OrgId: advice.UserOrgId,
  9544. Type: 1,
  9545. Manufacturer: manufactureName.ManufacturerName,
  9546. Dealer: dealer.DealerName,
  9547. Total: 0,
  9548. RetailPrice: info.RetailPrice,
  9549. RetailTotalPrice: info.RetailTotalPrice,
  9550. Price: info.Price,
  9551. RegisterAccount: "",
  9552. Remark: info.Remark,
  9553. BatchNumber: info.BatchNumber,
  9554. MaxUnit: info.CountUnit,
  9555. ProductDate: info.ProductDate,
  9556. ExpiryDate: info.ExpiryDate,
  9557. BatchNumberId: info.WarehouseInfoId,
  9558. }
  9559. flow := models.DrugFlow{
  9560. WarehousingId: 0,
  9561. DrugId: info.DrugId,
  9562. Number: "",
  9563. BatchNumber: info.BatchNumber,
  9564. Count: info.Count,
  9565. UserOrgId: advice.UserOrgId,
  9566. PatientId: 0,
  9567. SystemTime: ctime,
  9568. ConsumableType: 4,
  9569. IsSys: 0,
  9570. WarehousingOrder: "",
  9571. WarehouseOutId: 0,
  9572. WarehouseOutOrderNumber: "",
  9573. IsEdit: 0,
  9574. CancelStockId: cancelStock.ID,
  9575. CancelOrderNumber: cancelStock.OrderNumber,
  9576. Manufacturer: info.Manufacturer,
  9577. Dealer: info.Dealer,
  9578. Creator: advice.UserOrgId,
  9579. UpdateCreator: 0,
  9580. Status: 1,
  9581. Ctime: time.Now().Unix(),
  9582. Mtime: 0,
  9583. Price: info.Price,
  9584. WarehousingDetailId: 0,
  9585. WarehouseOutDetailId: 0,
  9586. CancelOutDetailId: 0,
  9587. ExpireDate: info.ExpiryDate,
  9588. ProductDate: info.ProductDate,
  9589. MaxUnit: info.CountUnit,
  9590. MinUnit: "",
  9591. }
  9592. service.CreatedCancelStock(cancelStockInfo)
  9593. service.CreateDrugFlowOne(flow)
  9594. } else {
  9595. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9596. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9597. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9598. warehouseInfo := models.DrugWarehouseInfo{
  9599. StockMinNumber: prescribingNumber,
  9600. }
  9601. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9602. }
  9603. operation_time := time.Now().Unix()
  9604. creater := advice.AdviceDoctor
  9605. ctime := time.Now().Unix()
  9606. timeStr := time.Now().Format("2006-01-02")
  9607. timeArr := strings.Split(timeStr, "-")
  9608. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9609. total = total + 1
  9610. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9611. cancelStock := models.DrugCancelStock{
  9612. OrderNumber: orderNumber,
  9613. OperaTime: operation_time,
  9614. OrgId: advice.UserOrgId,
  9615. Creater: creater,
  9616. Ctime: ctime,
  9617. Status: 1,
  9618. ReturnTime: advice.AdviceDate,
  9619. Dealer: info.Dealer,
  9620. Manufacturer: info.Manufacturer,
  9621. Type: 1,
  9622. }
  9623. service.AddSigleDrugCancelStock(&cancelStock)
  9624. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9625. dealer, _ := service.GetDealerById(info.Dealer)
  9626. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9627. cancelStockInfo := models.DrugCancelStockInfo{
  9628. OrderNumber: cancelInfo.OrderNumber,
  9629. CancelStockId: cancelInfo.ID,
  9630. DrugId: info.DrugId,
  9631. Count: info.Count,
  9632. Status: 1,
  9633. Ctime: ctime,
  9634. OrgId: advice.UserOrgId,
  9635. Type: 1,
  9636. Manufacturer: manufactureName.ManufacturerName,
  9637. Dealer: dealer.DealerName,
  9638. Total: 0,
  9639. RetailPrice: info.RetailPrice,
  9640. RetailTotalPrice: info.RetailTotalPrice,
  9641. Price: info.Price,
  9642. RegisterAccount: "",
  9643. Remark: info.Remark,
  9644. BatchNumber: info.BatchNumber,
  9645. MaxUnit: info.CountUnit,
  9646. ProductDate: info.ProductDate,
  9647. ExpiryDate: info.ExpiryDate,
  9648. BatchNumberId: info.WarehouseInfoId,
  9649. }
  9650. flow := models.DrugFlow{
  9651. WarehousingId: 0,
  9652. DrugId: info.DrugId,
  9653. Number: "",
  9654. BatchNumber: info.BatchNumber,
  9655. Count: info.Count,
  9656. UserOrgId: advice.UserOrgId,
  9657. PatientId: 0,
  9658. SystemTime: ctime,
  9659. ConsumableType: 4,
  9660. IsSys: 0,
  9661. WarehousingOrder: "",
  9662. WarehouseOutId: 0,
  9663. WarehouseOutOrderNumber: "",
  9664. IsEdit: 0,
  9665. CancelStockId: cancelStock.ID,
  9666. CancelOrderNumber: cancelStock.OrderNumber,
  9667. Manufacturer: info.Manufacturer,
  9668. Dealer: info.Dealer,
  9669. Creator: advice.AdviceDoctor,
  9670. UpdateCreator: 0,
  9671. Status: 1,
  9672. Ctime: time.Now().Unix(),
  9673. Mtime: 0,
  9674. Price: info.Price,
  9675. WarehousingDetailId: 0,
  9676. WarehouseOutDetailId: 0,
  9677. CancelOutDetailId: 0,
  9678. ExpireDate: info.ExpiryDate,
  9679. ProductDate: info.ProductDate,
  9680. MaxUnit: info.CountUnit,
  9681. MinUnit: "",
  9682. }
  9683. service.CreatedCancelStock(cancelStockInfo)
  9684. service.CreateDrugFlowOne(flow)
  9685. }
  9686. }
  9687. }
  9688. return err
  9689. }
  9690. func (this *HisApiController) DeleteNCDS() {
  9691. id, _ := this.GetInt64("id", 0)
  9692. if id > 0 {
  9693. service.DeletePsnNCDSRecordById(id)
  9694. this.ServeSuccessJSON(map[string]interface{}{
  9695. "msg": "删除成功",
  9696. })
  9697. } else {
  9698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9699. return
  9700. }
  9701. }
  9702. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9703. id, _ := c.GetInt64("id")
  9704. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9705. c.ServeSuccessJSON(map[string]interface{}{
  9706. "advice": advice,
  9707. })
  9708. return
  9709. }
  9710. func (c *HisApiController) GetHisMonthChargePatientList() {
  9711. record_date := c.GetString("record_date")
  9712. start_time := c.GetString("start_time")
  9713. end_time := c.GetString("end_time")
  9714. timeLayout := "2006-01-02"
  9715. loc, _ := time.LoadLocation("Local")
  9716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9717. if err != nil {
  9718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9719. return
  9720. }
  9721. if err != nil {
  9722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9723. return
  9724. }
  9725. recordDateTime := theTime.Unix()
  9726. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9727. if err != nil {
  9728. }
  9729. startRecordDateTime := startTime.Unix()
  9730. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9731. if err != nil {
  9732. }
  9733. endRecordDateTime := endTime.Unix()
  9734. adminInfo := c.GetAdminUserInfo()
  9735. var tempMonthChargePatients []*service.MonthChargePatients
  9736. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9737. for _, item := range tempPatients {
  9738. //过滤没有处方的
  9739. if len(item.HisPrescription) == 0 {
  9740. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9741. }
  9742. }
  9743. c.ServeSuccessJSON(map[string]interface{}{
  9744. "list": tempMonthChargePatients,
  9745. })
  9746. }