his_api_controller.go 464KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006
  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. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. if number >= 1000 {
  187. zero = "0000" + strconv.FormatInt(number, 10)
  188. } else if number >= 10000 {
  189. zero = "000" + strconv.FormatInt(number, 10)
  190. } else if number >= 100000 {
  191. zero = "00" + strconv.FormatInt(number, 10)
  192. } else if number >= 1000000 {
  193. zero = "0" + strconv.FormatInt(number, 10)
  194. } else {
  195. zero = strconv.FormatInt(number, 10)
  196. }
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. order.PsnCashPay = order.MedfeeSumamt
  1021. for _, item := range orderInfos {
  1022. if item.MedChrgitmType == "01" { //床位费
  1023. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1024. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1025. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1026. }
  1027. if item.MedChrgitmType == "02" { //诊察费
  1028. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1029. //zhenChaCostSelfTotal = zhenChaCostTotal
  1030. }
  1031. if item.MedChrgitmType == "03" { //检查费
  1032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //检查费
  1037. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "04" { //化验费
  1042. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "05" { //治疗费
  1047. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "06" { //手术费
  1052. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1057. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "09" { //西药费
  1062. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1064. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1065. }
  1066. if item.MedChrgitmType == "11" { //中成费
  1067. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. }
  1071. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1072. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. }
  1076. }
  1077. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1078. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1080. var dia_config []*models.HisXtDiagnoseConfig
  1081. var diagnosis_ids []string
  1082. if his.ID > 0 {
  1083. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1084. } else {
  1085. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1086. }
  1087. for _, item := range diagnosis_ids {
  1088. id, _ := strconv.ParseInt(item, 10, 64)
  1089. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1090. dia_config = append(dia_config, diagnosisConfig)
  1091. }
  1092. var rf []CustomFundPay
  1093. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1094. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "patient": patient,
  1097. "order_infos": orderInfos,
  1098. "diagnosis": name,
  1099. "bedCostTotal": bedCostTotal,
  1100. "bedCostSelfTotal": bedCostTotal,
  1101. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1102. "operationCostTotal": operationCostTotal,
  1103. "operationCostSelfTotal": operationCostTotal,
  1104. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1105. "otherCostTotal": otherCostTotal,
  1106. "otherCostSelfTotal": otherCostTotal,
  1107. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1108. "materialCostTotal": materialCostTotal,
  1109. "materialCostSelfTotal": materialCostTotal,
  1110. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1111. "westernMedicineCostTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1117. "checkCostTotal": checkCostTotal,
  1118. "checkCostSelfTotal": checkCostTotal,
  1119. "zhenChaCostTotal": zhenChaCostTotal,
  1120. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1121. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1122. "laboratoryCostTotal": laboratoryCostTotal,
  1123. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1124. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1125. "treatCostTotal": treatCostTotal,
  1126. "treatCostSelfTotal": treatCostTotal,
  1127. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1128. "charge_admin": charge_admin,
  1129. "printor_admin": printor_admin,
  1130. "org_name": org.OrgName,
  1131. "org_code": miConfig.Code,
  1132. "name": patient.Name,
  1133. "number": order.MdtrtId,
  1134. "date": order.SettleAccountsDate,
  1135. "info": order,
  1136. "new_order": order,
  1137. "his_hospital": his_hospital,
  1138. "his": his,
  1139. "funds": rf,
  1140. "dia_config": dia_config,
  1141. })
  1142. }
  1143. func (c *HisApiController) RefudDetail() {
  1144. order_id, _ := c.GetInt64("order_id")
  1145. order, _ := service.GetHisOrderByID(order_id)
  1146. adminUser := c.GetAdminUserInfo()
  1147. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "msg": "撤销成功",
  1150. })
  1151. }
  1152. func (c *HisApiController) Sscard() {
  1153. //r := CardInit()
  1154. //if r == 0 {
  1155. // GetBaseInfo()
  1156. //}
  1157. //c.ServeSuccessJSON(map[string]interface{}{
  1158. // "list": "11",
  1159. //})
  1160. }
  1161. func GetBaseInfo() error {
  1162. //handle := syscall.MustLoadDLL("SSCard.dll")
  1163. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1164. //
  1165. //str := make([]byte, 256)
  1166. //str1 := make([]byte, 256)
  1167. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1168. //if ferr != nil {
  1169. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1170. // return ferr
  1171. //}
  1172. //
  1173. //fmt.Println(string(str))
  1174. //
  1175. //fmt.Println(r)
  1176. return nil
  1177. }
  1178. func CardInit() int {
  1179. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1180. //add := DllTestDef.MustFindProc("Init")
  1181. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1182. //if err != nil {
  1183. // fmt.Println("SSCard的运算结果为:", ret)
  1184. //}
  1185. //result := int(ret)
  1186. return 0
  1187. }
  1188. func IntPtr(n int) uintptr {
  1189. return uintptr(n)
  1190. }
  1191. func StrPtr(s string) uintptr {
  1192. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1193. }
  1194. func (c *HisApiController) GetHisPatientList() {
  1195. //types, _ := c.GetInt64("type", 0)
  1196. record_date := c.GetString("record_date")
  1197. sch_type, _ := c.GetInt64("sch_type")
  1198. timeLayout := "2006-01-02"
  1199. loc, _ := time.LoadLocation("Local")
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. recordDateTime := theTime.Unix()
  1206. adminInfo := c.GetAdminUserInfo()
  1207. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1208. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1209. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1210. //获取当前用户的信息
  1211. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1212. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1213. //获取所有科室信息
  1214. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "list": patients,
  1217. "list_two": patients_two,
  1218. "info": adminUserInfo,
  1219. "doctors": doctors,
  1220. "department": department,
  1221. })
  1222. }
  1223. type CustomTemplate struct {
  1224. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1225. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1228. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1229. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1230. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1231. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1232. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1235. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1236. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1237. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1238. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1239. }
  1240. func (c *HisApiController) GetHisPatientInfo() {
  1241. patient_id, _ := c.GetInt64("patient_id")
  1242. his_patient_id, _ := c.GetInt64("his_patient_id")
  1243. record_date := c.GetString("record_date")
  1244. number := c.GetString("number")
  1245. //start_time := c.GetString("start_time")
  1246. //end_time := c.GetString("end_time")
  1247. p_type, _ := c.GetInt64("p_type")
  1248. timeLayout := "2006-01-02"
  1249. loc, _ := time.LoadLocation("Local")
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. recordDateTime := theTime.Unix()
  1256. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1257. //if err != nil {
  1258. //
  1259. //}
  1260. //startRecordDateTime := startTime.Unix()
  1261. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1262. //if err != nil {
  1263. //
  1264. //}
  1265. //endRecordDateTime := endTime.Unix()
  1266. admin := c.GetAdminUserInfo()
  1267. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1271. var prescriptions []*models.HisPrescription
  1272. var last_prescriptions []*models.HisPrescription
  1273. var sch_prescriptions []CustomTemplate
  1274. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1275. if p_type == 1 { //住院
  1276. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1277. for _, item := range prescriptions {
  1278. for _, subItem := range item.HisDoctorAdviceInfo {
  1279. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1280. if info.RetailPrice > 0 {
  1281. subItem.Drug.MinPrice = info.RetailPrice
  1282. }
  1283. }
  1284. }
  1285. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1286. } else { //门诊
  1287. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1288. for _, item := range prescriptions {
  1289. for _, subItem := range item.HisDoctorAdviceInfo {
  1290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1291. if info.RetailPrice > 0 {
  1292. subItem.Drug.MinPrice = info.RetailPrice
  1293. }
  1294. }
  1295. }
  1296. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1297. }
  1298. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1299. if sch.ID > 0 {
  1300. var week string
  1301. t := time.Now()
  1302. switch t.Weekday().String() {
  1303. case "Monday":
  1304. week = "周一"
  1305. break
  1306. case "Tuesday":
  1307. week = "周二"
  1308. break
  1309. case "Wednesday":
  1310. week = "周三"
  1311. break
  1312. case "Thursday":
  1313. week = "周四"
  1314. break
  1315. case "Friday":
  1316. week = "周五"
  1317. break
  1318. case "Saturday":
  1319. week = "周六"
  1320. break
  1321. case "Sunday":
  1322. week = "周日"
  1323. break
  1324. }
  1325. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1326. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1327. //根据推送频率组装新的数组
  1328. for _, item := range temp_sch_prescriptions {
  1329. var cus CustomTemplate
  1330. cus.ID = item.ID
  1331. cus.UserOrgId = item.UserOrgId
  1332. cus.PatientId = item.PatientId
  1333. cus.MedType = item.MedType
  1334. cus.RecordDate = item.RecordDate
  1335. cus.Type = item.Type
  1336. cus.PType = item.PType
  1337. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1338. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1339. if subItem.FrequencyType == 1 { //每次必推
  1340. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 { //按照天数频率
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1353. if len(advices) == 0 {
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. }
  1359. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1360. if subItem.Type == 2 {
  1361. if subItem.XtHisProject.MedicalStatus != 1 {
  1362. if subItem.FrequencyType == 1 {
  1363. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1364. }
  1365. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 2 {
  1369. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1370. now := p.Unix()
  1371. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1372. dayStr2 := "-" + dayStr
  1373. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1374. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1375. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1376. if len(projects) == 0 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. }
  1380. }
  1381. } else if subItem.Type == 3 {
  1382. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1383. if subItem.FrequencyType == 1 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 2 {
  1390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1391. now := p.Unix()
  1392. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1393. dayStr2 := "-" + dayStr
  1394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1396. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1397. if len(projects) == 0 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. sch_prescriptions = append(sch_prescriptions, cus)
  1405. }
  1406. for _, item := range sch_prescriptions {
  1407. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1408. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1409. }
  1410. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1411. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1412. }
  1413. }
  1414. }
  1415. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1416. if config.ID > 0 && config.IsOpen == 1 {
  1417. for _, item := range sch_prescriptions {
  1418. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1419. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1420. if info.RetailPrice > 0 {
  1421. subItem.Drug.MinPrice = info.RetailPrice
  1422. }
  1423. }
  1424. }
  1425. }
  1426. if config.ID > 0 && config.IsOpen == 1 {
  1427. for _, item := range sch_prescriptions {
  1428. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1429. if subItem.Type == 3 {
  1430. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1431. if info.Price > 0 {
  1432. subItem.GoodInfo.PackingPrice = info.Price
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1439. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1440. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1441. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1442. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1443. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1444. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1445. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1446. //获取所有科室信息
  1447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1448. c.ServeSuccessJSON(map[string]interface{}{
  1449. "his_info": his_patient_info,
  1450. "xt_info": xt_patient_info,
  1451. "prescription": prescriptions,
  1452. "case_history": case_history,
  1453. "info": patientPrescriptionInfo,
  1454. //"month_prescriptions": monthPrescriptions,
  1455. "order": order,
  1456. "doctors": doctors,
  1457. "department": department,
  1458. "sch_prescriptions": sch_prescriptions,
  1459. "last_prescriptions": last_prescriptions,
  1460. "schedule": sch,
  1461. "count": count,
  1462. "drugStockConfig": drugStockConfig,
  1463. "last_info": lastPatientPrescriptionInfo,
  1464. })
  1465. return
  1466. }
  1467. func (c *HisApiController) GetHisPrescriptionConfig() {
  1468. adminInfo := c.GetAdminUserInfo()
  1469. //获取医嘱模版
  1470. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1472. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1473. //获取所有基础药
  1474. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1475. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1476. if config.ID > 0 && config.IsOpen == 1 {
  1477. for _, item := range drugs {
  1478. var index = 0
  1479. for _, subItem := range item.OtherDrugWarehouseInfo {
  1480. if index == 0 {
  1481. index = index + 1
  1482. if subItem.RetailPrice > 0 {
  1483. item.MinPrice = subItem.RetailPrice
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1490. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1491. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1492. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1493. //获取所有科室信息
  1494. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1495. //获取诊断信息
  1496. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1497. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1498. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1499. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1500. //获取是否开启保存耗材出库的开关
  1501. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "drugs": drugs,
  1504. "advices_template": advices,
  1505. "drugways": drugways,
  1506. "efs": efs,
  1507. "doctors": doctors,
  1508. "department": department,
  1509. "sick": sick,
  1510. "additions": additions,
  1511. "diagnose": diagnose,
  1512. "manufacturers": manufacturers,
  1513. "goodOutOpen": goodOutOpen,
  1514. "patientDiagnose": patientDiagnose,
  1515. })
  1516. }
  1517. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1518. //获取所有基础药
  1519. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1520. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1521. if config.ID > 0 && config.IsOpen == 1 {
  1522. for _, item := range drugs {
  1523. var index = 0
  1524. for _, subItem := range item.OtherDrugWarehouseInfo {
  1525. if index == 0 {
  1526. index = index + 1
  1527. if subItem.RetailPrice > 0 {
  1528. item.MinPrice = subItem.RetailPrice
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1535. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1536. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1537. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1538. //获取所有科室信息
  1539. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1540. //获取诊断信息
  1541. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1542. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1543. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1544. //获取是否开启保存耗材出库的开关
  1545. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1546. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "drugs": drugs,
  1549. "advices_template": advices,
  1550. "drugways": drugways,
  1551. "efs": efs,
  1552. "doctors": doctors,
  1553. "department": department,
  1554. "sick": sick,
  1555. "additions": additions,
  1556. "diagnose": diagnose,
  1557. "manufacturers": manufacturers,
  1558. "goodOutOpen": goodOutOpen,
  1559. "patientDiagnose": patientDiagnose,
  1560. })
  1561. }
  1562. }
  1563. func (c *HisApiController) CreateHisPrescription() {
  1564. record_date := c.GetString("record_date")
  1565. patient_id, _ := c.GetInt64("patient_id")
  1566. reg_type, _ := c.GetInt64("reg_type")
  1567. diagnose := c.GetString("diagnose")
  1568. sick_type, _ := c.GetInt64("sick_type")
  1569. sick_history := c.GetString("sick_history")
  1570. doctor_id, _ := c.GetInt64("doctor", 0)
  1571. department, _ := c.GetInt64("department", 0)
  1572. his_patient_id, _ := c.GetInt64("his_patient_id")
  1573. p_type, _ := c.GetInt64("p_type")
  1574. patient_diagnose := c.GetString("patient_diagnose")
  1575. dataBody := make(map[string]interface{}, 0)
  1576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1577. if err != nil {
  1578. utils.ErrorLog(err.Error())
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. //edit, src := GetCompareData(dataBody)
  1583. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1584. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1585. //fmt.Println(drugResult)
  1586. //fmt.Println(goodResult)
  1587. timeLayout := "2006-01-02"
  1588. loc, _ := time.LoadLocation("Local")
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. if err != nil {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminInfo := c.GetAdminUserInfo()
  1595. recordDateTime := theTime.Unix()
  1596. //查询默认出库仓库库存
  1597. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1598. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1599. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1600. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1601. if len(lists) == 1 {
  1602. his_patient_id = lists[0].ID
  1603. }
  1604. }
  1605. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1606. //保存处方出库
  1607. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1608. //自动出库
  1609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1610. //耗材保存处方出库
  1611. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1612. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. //已发药和已收费限制逻辑
  1614. isMidicine := false
  1615. isCharge := false
  1616. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1617. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1618. if len(prescriptions) > 0 {
  1619. for _, item := range prescriptions {
  1620. items := item.(map[string]interface{})
  1621. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1622. utils.ErrorLog("id")
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. id := int64(items["id"].(float64))
  1627. if id > 0 {
  1628. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. if new_prescription.OrderStatus == 4 {
  1631. isCharge = true
  1632. }
  1633. }
  1634. }
  1635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1636. advices := items["advices"].([]interface{})
  1637. if len(advices) > 0 {
  1638. for _, advice := range advices {
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1641. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1642. }
  1643. if adviceId > 0 {
  1644. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1645. if err == nil {
  1646. if his_advice_info.IsMedicine == 1 {
  1647. isMidicine = true
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1706. return
  1707. }
  1708. //查询药品的所有库存
  1709. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1710. var total_count int64
  1711. for _, it := range list {
  1712. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1713. }
  1714. totals := strconv.FormatInt(total_count, 10)
  1715. //查询该药品是否存在开药记录
  1716. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1717. //新增处方
  1718. if advicelist.ID == 0 {
  1719. all_count, _ := strconv.ParseFloat(totals, 64)
  1720. if prescribingNumberUnit == drug.MinUnit {
  1721. fmt.Println("prescribing_number", prescribing_number)
  1722. fmt.Println("all_count", all_count)
  1723. if drug.IsUse != 1 {
  1724. if drug.IsProject == 0 || drug.IsProject == 2 {
  1725. if all_count == 0 {
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1727. return
  1728. }
  1729. if prescribing_number > all_count {
  1730. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1731. return
  1732. }
  1733. }
  1734. }
  1735. }
  1736. if prescribingNumberUnit == drug.MaxUnit {
  1737. num := prescribing_number * float64(drug.MinNumber)
  1738. if drug.IsUse != 1 {
  1739. if drug.IsProject == 0 || drug.IsProject == 2 {
  1740. if all_count == 0 {
  1741. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1742. return
  1743. }
  1744. if num > all_count {
  1745. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1746. return
  1747. }
  1748. }
  1749. }
  1750. }
  1751. }
  1752. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1753. if drugOutConfig.IsOpen != 1 {
  1754. //修改处方
  1755. for _, advice := range advices {
  1756. var drug_id int64
  1757. var prescribing_number float64
  1758. var prescribingNumberUnit string
  1759. var prescribingNumber string
  1760. var adviceId int64
  1761. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1762. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1765. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1766. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1767. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1768. }
  1769. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1770. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1771. }
  1772. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1773. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1774. }
  1775. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1776. if drug.ID == 0 {
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1778. return
  1779. }
  1780. //查询药品的所有库存
  1781. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1782. var total_count int64
  1783. for _, it := range list {
  1784. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1785. }
  1786. totals := strconv.FormatInt(total_count, 10)
  1787. //查询该药品是否存在开药记录
  1788. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1789. //新增处方
  1790. if advicelist.ID == 0 {
  1791. all_count, _ := strconv.ParseFloat(totals, 64)
  1792. if prescribingNumberUnit == drug.MinUnit {
  1793. if drug.IsUse != 1 {
  1794. if drug.IsProject == 0 || drug.IsProject == 2 {
  1795. if all_count == 0 {
  1796. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1797. return
  1798. }
  1799. if prescribing_number > all_count {
  1800. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1801. return
  1802. }
  1803. }
  1804. }
  1805. } else {
  1806. if prescribingNumberUnit == drug.MaxUnit {
  1807. num := prescribing_number * float64(drug.MinNumber)
  1808. if drug.IsUse != 1 {
  1809. if drug.IsProject == 0 || drug.IsProject == 2 {
  1810. if all_count == 0 {
  1811. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1812. return
  1813. }
  1814. if num > all_count {
  1815. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1816. return
  1817. }
  1818. }
  1819. }
  1820. }
  1821. }
  1822. }
  1823. //修改处方
  1824. if advicelist.ID > 0 {
  1825. var device_number int64
  1826. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1827. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1828. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1829. device_number = prescribingNumberInt * drug.MinNumber
  1830. }
  1831. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1832. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1833. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1834. device_number = prescribingNumberInt
  1835. }
  1836. var number_count int64
  1837. if prescribingNumberUnit == drug.MaxUnit {
  1838. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1839. number_count = prescribingNumberInt * drug.MinNumber
  1840. }
  1841. if prescribingNumberUnit == drug.MinUnit {
  1842. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1843. number_count = prescribingNumberInt
  1844. }
  1845. //如果修改的数量大于之前修改的数量
  1846. if (number_count - device_number) > 0 {
  1847. //如果修改的差数量 大于库存数量
  1848. if drug.IsUse != 1 {
  1849. if (number_count - device_number) > total_count {
  1850. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1851. return
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. }
  1865. //已发药和已收费限制逻辑
  1866. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1867. //校验库存总量
  1868. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1869. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1870. if len(prescriptions) > 0 {
  1871. for _, item := range prescriptions {
  1872. items := item.(map[string]interface{})
  1873. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1874. advices := items["advices"].([]interface{})
  1875. if len(advices) > 0 {
  1876. for _, advice := range advices {
  1877. var drug_id int64
  1878. var prescribing_number float64
  1879. var prescribingNumberUnit string
  1880. var adviceId int64
  1881. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1882. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1883. }
  1884. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1885. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1886. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1887. }
  1888. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1889. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1890. }
  1891. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1892. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1893. }
  1894. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1895. if drug.ID == 0 {
  1896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1897. return
  1898. }
  1899. //查询药品的所有库存
  1900. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1901. var total_count int64
  1902. for _, it := range list {
  1903. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1904. }
  1905. totals := strconv.FormatInt(total_count, 10)
  1906. //查询该药品是否存在开药记录
  1907. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1908. //查询最新批次库存
  1909. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1910. var batch_number_count int64
  1911. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1912. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1913. //新增处方
  1914. if advicelist.ID == 0 {
  1915. all_count, _ := strconv.ParseFloat(totals, 64)
  1916. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1917. if prescribingNumberUnit == drug.MinUnit {
  1918. if drug.IsUse != 1 {
  1919. if drug.IsProject == 0 || drug.IsProject == 2 {
  1920. if all_count == 0 {
  1921. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1922. return
  1923. }
  1924. if prescribing_number > all_count {
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1926. return
  1927. }
  1928. }
  1929. if adminInfo.CurrentOrgId == 10215 {
  1930. if prescribing_number > batch_number_all_count {
  1931. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1932. return
  1933. }
  1934. }
  1935. }
  1936. }
  1937. if prescribingNumberUnit == drug.MaxUnit {
  1938. num := prescribing_number * float64(drug.MinNumber)
  1939. if drug.IsUse != 1 {
  1940. if drug.IsProject == 0 || drug.IsProject == 2 {
  1941. if all_count == 0 {
  1942. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1943. return
  1944. }
  1945. if num > all_count {
  1946. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1947. return
  1948. }
  1949. }
  1950. if adminInfo.CurrentOrgId == 10215 {
  1951. if num > batch_number_all_count {
  1952. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1953. return
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1960. if drugOutConfig.IsOpen != 1 {
  1961. //修改处方
  1962. for _, advice := range advices {
  1963. var drug_id int64
  1964. var prescribing_number float64
  1965. var prescribingNumberUnit string
  1966. var prescribingNumber string
  1967. var adviceId int64
  1968. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1969. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1970. }
  1971. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1972. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1973. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1974. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1975. }
  1976. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1977. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1978. }
  1979. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1980. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1981. }
  1982. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1983. if drug.ID == 0 {
  1984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1985. return
  1986. }
  1987. //查询药品的所有库存
  1988. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1989. var total_count int64
  1990. for _, it := range list {
  1991. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1992. }
  1993. totals := strconv.FormatInt(total_count, 10)
  1994. //查询该药品是否存在开药记录
  1995. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1996. //新增处方
  1997. if advicelist.ID == 0 {
  1998. //查询最新批次库存
  1999. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2000. var batch_number_count int64
  2001. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2002. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2003. all_count, _ := strconv.ParseFloat(totals, 64)
  2004. if prescribingNumberUnit == drug.MinUnit {
  2005. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2006. if drug.IsUse != 1 {
  2007. if drug.IsProject == 0 || drug.IsProject == 2 {
  2008. if all_count == 0 {
  2009. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2010. return
  2011. }
  2012. if prescribing_number > all_count {
  2013. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2014. return
  2015. }
  2016. }
  2017. if adminInfo.CurrentOrgId == 10215 {
  2018. if prescribing_number > batch_number_all_count {
  2019. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2020. return
  2021. }
  2022. }
  2023. }
  2024. } else {
  2025. if prescribingNumberUnit == drug.MaxUnit {
  2026. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2027. num := prescribing_number * float64(drug.MinNumber)
  2028. if drug.IsUse != 1 {
  2029. if drug.IsProject == 0 || drug.IsProject == 2 {
  2030. if all_count == 0 {
  2031. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2032. return
  2033. }
  2034. if num > all_count {
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2036. return
  2037. }
  2038. }
  2039. if adminInfo.CurrentOrgId == 10215 {
  2040. if prescribing_number > batch_number_all_count {
  2041. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2042. return
  2043. }
  2044. }
  2045. }
  2046. }
  2047. }
  2048. }
  2049. //修改处方
  2050. if advicelist.ID > 0 {
  2051. //查询最新批次库存
  2052. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2053. var batch_number_count int64
  2054. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2055. var device_number int64
  2056. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2057. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2058. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2059. device_number = prescribingNumberInt * drug.MinNumber
  2060. }
  2061. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2062. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2063. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2064. device_number = prescribingNumberInt
  2065. }
  2066. var number_count int64
  2067. if prescribingNumberUnit == drug.MaxUnit {
  2068. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2069. number_count = prescribingNumberInt * drug.MinNumber
  2070. }
  2071. if prescribingNumberUnit == drug.MinUnit {
  2072. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2073. number_count = prescribingNumberInt
  2074. }
  2075. //如果修改的数量大于之前修改的数量
  2076. if (number_count - device_number) > 0 {
  2077. //如果修改的差数量 大于库存数量
  2078. if drug.IsUse != 1 {
  2079. if drug.IsProject == 0 || drug.IsProject == 2 {
  2080. if total_count == 0 {
  2081. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2082. return
  2083. }
  2084. if (number_count - device_number) > total_count {
  2085. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2086. return
  2087. }
  2088. if (number_count - device_number) > batch_number_count {
  2089. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2090. return
  2091. }
  2092. }
  2093. if adminInfo.CurrentOrgId == 10215 {
  2094. // 查询该药品最后一次出库记录
  2095. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2096. var out_count int64
  2097. var in_count int64
  2098. var stock_max_number int64
  2099. var stock_min_number int64
  2100. for _, it := range outInfo {
  2101. if it.CountUnit == drug.MaxUnit {
  2102. it.Count = it.Count * drug.MinNumber
  2103. }
  2104. out_count += it.Count
  2105. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2106. stock_max_number = warehouseInfoList.StockMaxNumber
  2107. stock_min_number = warehouseInfoList.StockMinNumber
  2108. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2109. }
  2110. if out_count > 0 {
  2111. if (number_count - device_number) > in_count {
  2112. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2113. return
  2114. }
  2115. }
  2116. // 未出库
  2117. if out_count == 0 {
  2118. var sum_in_count int64
  2119. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2120. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2121. fmt.Println("sum_in_count", sum_in_count)
  2122. //如果修改的数量大于有库存的第一个批次
  2123. if number_count > sum_in_count {
  2124. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2125. return
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2132. if pharmacyConfig.IsOpen != 1 {
  2133. if device_number != number_count {
  2134. // 查询该药品最后一次出库记录
  2135. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2136. //回退库存
  2137. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2138. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2139. }
  2140. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2141. var stock_max_number int64
  2142. var stock_min_number int64
  2143. if number_count >= drug.MinNumber {
  2144. stock_max_number = device_number / drug.MinNumber
  2145. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2146. stock_min_number = device_number % drug.MinNumber
  2147. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2148. } else {
  2149. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2150. }
  2151. }
  2152. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2153. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2154. }
  2155. //删除记录
  2156. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2157. //查询默认仓库剩余多少库存
  2158. var sum_count int64
  2159. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2160. for _, its := range stockInfo {
  2161. if its.MaxUnit == drug.MaxUnit {
  2162. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2163. }
  2164. sum_count += its.StockMaxNumber + its.StockMinNumber
  2165. }
  2166. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2167. }
  2168. }
  2169. }
  2170. }
  2171. }
  2172. //保存处方开药
  2173. if drugOutConfig.IsOpen == 1 {
  2174. //修改处方
  2175. for _, advice := range advices {
  2176. var drug_id int64
  2177. var prescribing_number float64
  2178. var prescribingNumberUnit string
  2179. var prescribingNumber string
  2180. var adviceId int64
  2181. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2182. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2183. }
  2184. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2185. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2186. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2187. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2188. }
  2189. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2190. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2191. }
  2192. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2193. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2194. }
  2195. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2196. if drug.ID == 0 {
  2197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2198. return
  2199. }
  2200. //查询药品的所有库存
  2201. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2202. var total_count int64
  2203. for _, it := range list {
  2204. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2205. }
  2206. totals := strconv.FormatInt(total_count, 10)
  2207. //查询该药品是否存在开药记录
  2208. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2209. //新增处方
  2210. if advicelist.ID == 0 {
  2211. //查询最新批次库存
  2212. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2213. var batch_number_count int64
  2214. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2215. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2216. all_count, _ := strconv.ParseFloat(totals, 64)
  2217. if prescribingNumberUnit == drug.MinUnit {
  2218. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2219. if drug.IsUse != 1 {
  2220. if drug.IsProject == 0 || drug.IsProject == 2 {
  2221. if all_count == 0 {
  2222. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2223. return
  2224. }
  2225. if prescribing_number > all_count {
  2226. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2227. return
  2228. }
  2229. }
  2230. if adminInfo.CurrentOrgId == 10215 {
  2231. if prescribing_number > batch_number_all_count {
  2232. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2233. return
  2234. }
  2235. }
  2236. }
  2237. } else {
  2238. if prescribingNumberUnit == drug.MaxUnit {
  2239. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2240. num := prescribing_number * float64(drug.MinNumber)
  2241. if drug.IsUse != 1 {
  2242. if drug.IsProject == 0 || drug.IsProject == 2 {
  2243. if all_count == 0 {
  2244. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2245. return
  2246. }
  2247. if num > all_count {
  2248. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2249. return
  2250. }
  2251. }
  2252. if adminInfo.CurrentOrgId == 10215 {
  2253. if prescribing_number > batch_number_all_count {
  2254. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2255. return
  2256. }
  2257. }
  2258. }
  2259. }
  2260. }
  2261. }
  2262. //修改处方
  2263. if advicelist.ID > 0 {
  2264. //查询最新批次库存
  2265. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2266. var batch_number_count int64
  2267. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2268. var device_number int64
  2269. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2270. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2271. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2272. device_number = prescribingNumberInt * drug.MinNumber
  2273. }
  2274. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2275. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2276. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2277. device_number = prescribingNumberInt
  2278. }
  2279. var number_count int64
  2280. if prescribingNumberUnit == drug.MaxUnit {
  2281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2282. number_count = prescribingNumberInt * drug.MinNumber
  2283. }
  2284. if prescribingNumberUnit == drug.MinUnit {
  2285. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2286. number_count = prescribingNumberInt
  2287. }
  2288. //如果修改的数量大于之前修改的数量
  2289. if (number_count - device_number) > 0 {
  2290. //如果修改的差数量 大于库存数量
  2291. if drug.IsUse != 1 {
  2292. if drug.IsProject == 0 || drug.IsProject == 2 {
  2293. if total_count == 0 {
  2294. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2295. return
  2296. }
  2297. if (number_count - device_number) > total_count {
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2299. return
  2300. }
  2301. }
  2302. if adminInfo.CurrentOrgId == 10215 {
  2303. if (number_count - device_number) > batch_number_count {
  2304. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2305. return
  2306. }
  2307. }
  2308. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2309. //查询历史出库数据总批次
  2310. // 查询该药品最后一次出库记录
  2311. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2312. var out_count int64
  2313. var in_count int64
  2314. var stock_max_number int64
  2315. var stock_min_number int64
  2316. for _, it := range outInfo {
  2317. if it.CountUnit == drug.MaxUnit {
  2318. it.Count = it.Count * drug.MinNumber
  2319. }
  2320. out_count += it.Count
  2321. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2322. stock_max_number = warehouseInfoList.StockMaxNumber
  2323. stock_min_number = warehouseInfoList.StockMinNumber
  2324. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2325. }
  2326. if out_count > 0 {
  2327. if (number_count - device_number) > in_count {
  2328. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2329. return
  2330. }
  2331. }
  2332. // 未出库
  2333. if out_count == 0 {
  2334. var sum_in_count int64
  2335. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2336. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2337. if sum_in_count == 0 {
  2338. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2339. return
  2340. }
  2341. //如果修改的数量大于有库存的第一个批次
  2342. if number_count > sum_in_count {
  2343. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2344. return
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. }
  2359. }
  2360. //校验耗材库存
  2361. if goodOutConfig.IsOpen == 1 {
  2362. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2363. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2364. if len(prescriptions) > 0 {
  2365. for _, item := range prescriptions {
  2366. items := item.(map[string]interface{})
  2367. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2368. projects := items["project"].([]interface{})
  2369. if len(projects) > 0 {
  2370. for _, project := range projects {
  2371. var project_id int64
  2372. var project_type int64
  2373. var totals float64
  2374. var project_name string
  2375. var parsetotal int64
  2376. var id int64
  2377. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2378. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2379. }
  2380. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2381. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2382. }
  2383. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2384. total, _ := project.(map[string]interface{})["total"].(string)
  2385. totals, _ = strconv.ParseFloat(total, 64)
  2386. }
  2387. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2388. project_name = project.(map[string]interface{})["project_name"].(string)
  2389. }
  2390. if project_type == 3 {
  2391. //查找该耗材的出库记录
  2392. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2393. if len(goodWarehouseInfo) == 0 {
  2394. //查询耗材库存
  2395. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2396. var stock_count int64
  2397. for _, it := range list {
  2398. stock_count += it.StockCount
  2399. }
  2400. stock_counts := strconv.FormatInt(stock_count, 10)
  2401. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2402. if stock_total_count == 0 {
  2403. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2404. return
  2405. }
  2406. if totals > stock_total_count {
  2407. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2408. return
  2409. }
  2410. }
  2411. if len(goodWarehouseInfo) > 0 {
  2412. //查询该患者耗材的历史数据
  2413. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2414. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2415. //数量发生改变
  2416. if parsetotal != count {
  2417. //如果现在的数量大于历史数量,就要看库存是否足够
  2418. if parsetotal > count {
  2419. //查询耗材所有库存
  2420. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2421. var stock_count int64
  2422. for _, it := range list {
  2423. stock_count += it.StockCount
  2424. }
  2425. //库存不足
  2426. if stock_count == 0 {
  2427. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2428. return
  2429. }
  2430. if (parsetotal - count) > stock_count {
  2431. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2432. return
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. }
  2444. }
  2445. //不使用耗材保存处方出库
  2446. if goodOutConfig.IsOpen != 1 {
  2447. if stockConfig.IsOpen == 1 {
  2448. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2449. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2450. if len(prescriptions) > 0 {
  2451. for _, item := range prescriptions {
  2452. items := item.(map[string]interface{})
  2453. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2454. projects := items["project"].([]interface{})
  2455. if len(projects) > 0 {
  2456. for _, project := range projects {
  2457. var project_id int64
  2458. var project_type int64
  2459. var totals float64
  2460. var project_name string
  2461. var parsetotal int64
  2462. var id int64
  2463. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2464. id = int64(project.(map[string]interface{})["id"].(float64))
  2465. }
  2466. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2467. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2468. }
  2469. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2470. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2471. }
  2472. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2473. total, _ := project.(map[string]interface{})["total"].(string)
  2474. totals, _ = strconv.ParseFloat(total, 64)
  2475. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2476. }
  2477. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2478. project_name = project.(map[string]interface{})["project_name"].(string)
  2479. }
  2480. if project_type == 3 {
  2481. //查找该耗材的出库记录
  2482. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2483. //没有出库记录
  2484. if len(goodWarehouseInfo) == 0 {
  2485. //查询耗材库存
  2486. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2487. var stock_count int64
  2488. for _, it := range list {
  2489. stock_count += it.StockCount
  2490. }
  2491. stock_counts := strconv.FormatInt(stock_count, 10)
  2492. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2493. if stock_total_count == 0 {
  2494. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2495. return
  2496. }
  2497. if totals > stock_total_count {
  2498. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2499. return
  2500. }
  2501. //查找今日该患者已经出库的所有耗材
  2502. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2503. for _, item := range goodList {
  2504. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2505. var flush_count int64
  2506. for _, it := range goodListSix {
  2507. flush_count += it.StockCount
  2508. }
  2509. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2510. creater := adminInfo.AdminUser.Id
  2511. if errs != nil {
  2512. goodErrcode := models.XtGoodErrcode{
  2513. UserOrgId: item.OrgId,
  2514. Errcode: "手动出库更新剩余出库失败",
  2515. GoodId: item.GoodId,
  2516. Status: 1,
  2517. Ctime: time.Now().Unix(),
  2518. Mtime: 0,
  2519. Count: 0,
  2520. StockCount: 0,
  2521. Creater: creater,
  2522. BatchNumberId: 0,
  2523. WarehouseOutId: 0,
  2524. }
  2525. service.CreateGoodErrcode(goodErrcode)
  2526. }
  2527. }
  2528. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2529. }
  2530. //有出库记录
  2531. if len(goodWarehouseInfo) > 0 {
  2532. //查询该患者耗材的历史数据
  2533. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2534. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2535. //数量发生改变
  2536. if parsetotal != count {
  2537. //查找今日该患者已经出库的所有耗材
  2538. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2539. for _, item := range goodList {
  2540. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2541. var flush_count int64
  2542. for _, it := range goodListSix {
  2543. flush_count += it.StockCount
  2544. }
  2545. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2546. //减少出库数量
  2547. creater := adminInfo.AdminUser.Id
  2548. if errs != nil {
  2549. goodErrcode := models.XtGoodErrcode{
  2550. UserOrgId: item.OrgId,
  2551. Errcode: "手动出库更新剩余出库失败",
  2552. GoodId: item.GoodId,
  2553. Status: 1,
  2554. Ctime: time.Now().Unix(),
  2555. Mtime: 0,
  2556. Count: 0,
  2557. StockCount: 0,
  2558. Creater: creater,
  2559. BatchNumberId: 0,
  2560. WarehouseOutId: 0,
  2561. }
  2562. service.CreateGoodErrcode(goodErrcode)
  2563. }
  2564. //查询默认仓库
  2565. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2566. var total_count int64
  2567. for _, it := range stockList {
  2568. total_count += it.StockCount
  2569. }
  2570. //基础库插入数据
  2571. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2572. }
  2573. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2574. }
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. }
  2585. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2586. var hpInfo models.HisPrescriptionInfo
  2587. if info.ID == 0 {
  2588. var randNum int
  2589. randNum = rand.Intn(10000) + 1000
  2590. timestamp := time.Now().Unix()
  2591. tempTime := time.Unix(timestamp, 0)
  2592. timeFormat := tempTime.Format("20060102150405")
  2593. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2594. hpInfo = models.HisPrescriptionInfo{
  2595. HisPatientId: his_patient_id,
  2596. UserOrgId: adminInfo.CurrentOrgId,
  2597. RecordDate: theTime.Unix(),
  2598. PatientId: patient_id,
  2599. Status: 1,
  2600. Ctime: time.Now().Unix(),
  2601. Mtime: time.Now().Unix(),
  2602. Creator: adminInfo.AdminUser.Id,
  2603. Modifier: adminInfo.AdminUser.Id,
  2604. Diagnosis: diagnose,
  2605. SickHistory: sick_history,
  2606. Departments: department,
  2607. RegisterType: reg_type,
  2608. PrescriptionNumber: p_number,
  2609. PrescriptionStatus: 1,
  2610. Doctor: role.UserName,
  2611. DoctorId: doctor_id,
  2612. SickType: sick_type,
  2613. PType: p_type,
  2614. PatientDiagnosis: patient_diagnose,
  2615. }
  2616. service.SavePatientPrescriptionInfo(hpInfo)
  2617. //创建步骤表
  2618. finish := models.XtDialysisFinish{
  2619. IsFinish: 1,
  2620. UserOrgId: adminInfo.CurrentOrgId,
  2621. Status: 1,
  2622. Ctime: time.Now().Unix(),
  2623. Mtime: 0,
  2624. Module: 4,
  2625. RecordDate: theTime.Unix(),
  2626. Sourse: 1,
  2627. PatientId: patient_id,
  2628. }
  2629. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2630. if dialysisFinish.ID == 0 {
  2631. service.CreateDialysisFinish(finish)
  2632. }
  2633. redis := service.RedisClient()
  2634. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2635. redis.Set(key, "", time.Second)
  2636. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2637. redis.Set(keyOne, "", time.Second)
  2638. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2639. redis.Set(keySeven, "", time.Second)
  2640. defer redis.Close()
  2641. } else {
  2642. hpInfo = models.HisPrescriptionInfo{
  2643. ID: info.ID,
  2644. UserOrgId: adminInfo.CurrentOrgId,
  2645. RecordDate: info.RecordDate,
  2646. PatientId: info.PatientId,
  2647. Status: 1,
  2648. Ctime: info.Ctime,
  2649. Mtime: time.Now().Unix(),
  2650. Creator: info.Creator,
  2651. Modifier: adminInfo.AdminUser.Id,
  2652. Diagnosis: diagnose,
  2653. SickHistory: sick_history,
  2654. Departments: department,
  2655. RegisterType: reg_type,
  2656. PrescriptionNumber: info.PrescriptionNumber,
  2657. Doctor: role.UserName,
  2658. PrescriptionStatus: info.PrescriptionStatus,
  2659. DoctorId: doctor_id,
  2660. SickType: sick_type,
  2661. PType: info.PType,
  2662. HisPatientId: info.HisPatientId,
  2663. PatientDiagnosis: patient_diagnose,
  2664. }
  2665. service.SavePatientPrescriptionInfo(hpInfo)
  2666. //创建步骤表
  2667. finish := models.XtDialysisFinish{
  2668. IsFinish: 1,
  2669. UserOrgId: adminInfo.CurrentOrgId,
  2670. Status: 1,
  2671. Ctime: time.Now().Unix(),
  2672. Mtime: 0,
  2673. Module: 4,
  2674. RecordDate: info.RecordDate,
  2675. Sourse: 1,
  2676. PatientId: info.PatientId,
  2677. }
  2678. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2679. if dialysisFinish.ID == 0 {
  2680. service.CreateDialysisFinish(finish)
  2681. }
  2682. redis := service.RedisClient()
  2683. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2684. redis.Set(key, "", time.Second)
  2685. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2686. redis.Set(keyOne, "", time.Second)
  2687. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2688. redis.Set(keySeven, "", time.Second)
  2689. defer redis.Close()
  2690. }
  2691. //定义切片
  2692. var adviceList []models.HisDoctorAdviceInfo
  2693. var projectList []models.HisPrescriptionProject
  2694. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2695. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2696. var tempPrescription *models.HisPrescription
  2697. if len(prescriptions) > 0 {
  2698. for _, item := range prescriptions {
  2699. // 开始外部循环的事务
  2700. tx := db.Begin()
  2701. // 在函数结束时处理事务回滚
  2702. defer func() {
  2703. if r := recover(); r != nil {
  2704. tx.Rollback()
  2705. }
  2706. }()
  2707. items := item.(map[string]interface{})
  2708. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2709. utils.ErrorLog("id")
  2710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2711. return
  2712. }
  2713. id := int64(items["id"].(float64))
  2714. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2715. tempPrescription = &new_prescription
  2716. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2717. utils.ErrorLog("type")
  2718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2719. return
  2720. }
  2721. types := int64(items["type"].(float64))
  2722. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2723. utils.ErrorLog("med_type")
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2725. return
  2726. }
  2727. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2728. if med_type == "0" {
  2729. med_type = "14"
  2730. }
  2731. //if order_status == 0 {
  2732. // order_status = 1
  2733. //}
  2734. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2735. utils.ErrorLog("pre_time")
  2736. }
  2737. preTime, _ := items["pre_time"].(string)
  2738. timeLayout := "2006-01-02"
  2739. loc, _ := time.LoadLocation("Local")
  2740. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2741. if err != nil {
  2742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2743. return
  2744. }
  2745. pTime := theTime2.Unix()
  2746. ctime := time.Now().Unix()
  2747. if tempPrescription.ID == 0 {
  2748. prescription := &models.HisPrescription{
  2749. ID: 0,
  2750. PatientId: patient_id,
  2751. UserOrgId: adminInfo.CurrentOrgId,
  2752. RecordDate: recordDateTime,
  2753. Ctime: ctime,
  2754. Mtime: ctime,
  2755. Type: types,
  2756. Modifier: adminInfo.AdminUser.Id,
  2757. Creator: adminInfo.AdminUser.Id,
  2758. Status: 1,
  2759. Doctor: role.UserName,
  2760. HisPatientId: his_patient_id,
  2761. OrderStatus: 1,
  2762. BatchNumber: "",
  2763. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2764. PreTime: pTime,
  2765. PType: p_type,
  2766. MedType: med_type,
  2767. }
  2768. tempPrescription = prescription
  2769. service.SaveHisPrescription(tx, tempPrescription)
  2770. redis := service.RedisClient()
  2771. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2772. redis.Set(key, "", time.Second)
  2773. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2774. redis.Set(keyOne, "", time.Second)
  2775. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2776. redis.Set(keySeven, "", time.Second)
  2777. defer redis.Close()
  2778. } else {
  2779. tempPrescription.ID = id
  2780. tempPrescription.Type = types
  2781. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2782. tempPrescription.Mtime = time.Now().Unix()
  2783. tempPrescription.Doctor = role.UserName
  2784. //tempPrescription.OrderStatus = order_status
  2785. tempPrescription.PreTime = pTime
  2786. tempPrescription.MedType = med_type
  2787. service.SaveHisPrescription(tx, tempPrescription)
  2788. redis := service.RedisClient()
  2789. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2790. redis.Set(key, "", time.Second)
  2791. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2792. redis.Set(keyOne, "", time.Second)
  2793. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2794. redis.Set(keySeven, "", time.Second)
  2795. defer redis.Close()
  2796. }
  2797. //service.SaveHisPrescription(prescription)
  2798. //更改患者挂号状态
  2799. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2800. fmt.Println("更改失败", err2)
  2801. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2802. advices := items["advices"].([]interface{})
  2803. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2804. groupNo := int64(0)
  2805. ctime := time.Now().Unix()
  2806. mtime := ctime
  2807. if len(advices) > 0 {
  2808. for _, advice := range advices {
  2809. tx := db.Begin()
  2810. // 在函数结束时处理事务回滚
  2811. defer func() {
  2812. if r := recover(); r != nil {
  2813. tx.Rollback()
  2814. }
  2815. }()
  2816. var s models.HisDoctorAdviceInfo
  2817. s.PrescriptionId = tempPrescription.ID
  2818. s.AdviceType = 2
  2819. s.AdviceDoctor = doctor_id
  2820. s.StopState = 2
  2821. s.ExecutionState = 2
  2822. s.AdviceDate = recordDateTime
  2823. s.Status = 1
  2824. s.UserOrgId = adminInfo.CurrentOrgId
  2825. s.RecordDate = recordDateTime
  2826. s.StartTime = tempPrescription.PreTime
  2827. s.Groupno = groupNo
  2828. s.CreatedTime = ctime
  2829. s.UpdatedTime = mtime
  2830. s.PatientId = patient_id
  2831. s.HisPatientId = his_patient_id
  2832. s.StartTime = pTime
  2833. s.IsSettle = 2
  2834. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2835. if errcode > 0 {
  2836. c.ServeFailJSONWithSGJErrorCode(errcode)
  2837. return
  2838. }
  2839. s.StartTime = pTime
  2840. var total_count int64 //处方总库存
  2841. //查询改药品信息
  2842. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2843. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2844. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2845. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2846. total_count += prescribingNumberSeven * medical.MinNumber
  2847. }
  2848. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2849. total_count += prescribingNumberSeven
  2850. }
  2851. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2852. total_count += prescribingNumberSeven
  2853. }
  2854. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2855. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2856. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2857. if s.Price != lastWarehouse.RetailPrice {
  2858. s.Price = lastWarehouse.RetailPrice
  2859. }
  2860. if s.Price == 0 {
  2861. s.Price = lastWarehouse.RetailPrice
  2862. }
  2863. }
  2864. service.CreateHisDoctorAdvice(&s, tx)
  2865. //记录日志
  2866. byterequest, _ := json.Marshal(s)
  2867. adviceLog := models.XtDoctorAdviceLog{
  2868. UserOrgId: s.UserOrgId,
  2869. PatientId: s.PatientId,
  2870. AdminUserId: adminInfo.AdminUser.Id,
  2871. Module: 1,
  2872. ErrLog: string(byterequest),
  2873. Status: 1,
  2874. Ctime: time.Now().Unix(),
  2875. Mtime: 0,
  2876. Source: "电脑端新建his医嘱",
  2877. RecordDate: s.AdviceDate,
  2878. }
  2879. service.CreateDoctorAdviceLog(adviceLog)
  2880. //存储切片中
  2881. adviceList = append(adviceList, s)
  2882. redis := service.RedisClient()
  2883. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2884. redis.Set(key, "", time.Second)
  2885. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2886. redis.Set(keyOne, "", time.Second)
  2887. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2888. redis.Set(keySeven, "", time.Second)
  2889. var randNum int
  2890. randNum = rand.Intn(10000) + 1000
  2891. timestamp := time.Now().Unix()
  2892. tempTime := time.Unix(timestamp, 0)
  2893. timeFormat := tempTime.Format("20060102150405")
  2894. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2895. service.CreateHisDoctorAdvice(&s, tx)
  2896. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2897. redis.Set(keySix, "", time.Second)
  2898. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2899. redis.Set(keyFive, "", time.Second)
  2900. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2901. redis.Set(keyEight, "", time.Second)
  2902. defer redis.Close()
  2903. }
  2904. }
  2905. }
  2906. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2907. projects := items["project"].([]interface{})
  2908. if len(projects) > 0 {
  2909. for _, project := range projects {
  2910. tx := db.Begin()
  2911. // 在函数结束时处理事务回滚
  2912. defer func() {
  2913. if r := recover(); r != nil {
  2914. tx.Rollback()
  2915. }
  2916. }()
  2917. var p models.HisPrescriptionProject
  2918. p.PrescriptionId = tempPrescription.ID
  2919. p.Ctime = time.Now().Unix()
  2920. p.Mtime = time.Now().Unix()
  2921. p.PatientId = patient_id
  2922. p.RecordDate = recordDateTime
  2923. p.Doctor = doctor_id
  2924. p.UserOrgId = adminInfo.CurrentOrgId
  2925. p.HisPatientId = his_patient_id
  2926. p.Status = 1
  2927. p.StartTime = pTime
  2928. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2929. if errcode > 0 {
  2930. c.ServeFailJSONWithSGJErrorCode(errcode)
  2931. return
  2932. }
  2933. if p.ID == 0 {
  2934. p.IsOut = 2
  2935. }
  2936. if p.ID > 0 {
  2937. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2938. p.IsOut = projectDetail.IsOut
  2939. }
  2940. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2941. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2942. if p.Type == 3 {
  2943. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2944. if p.Price != lastWarehouse.PackingPrice {
  2945. p.Price = lastWarehouse.PackingPrice
  2946. }
  2947. if p.Unit == "" {
  2948. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2949. p.Unit = goodInfoOne.PackingUnit
  2950. }
  2951. }
  2952. }
  2953. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2954. //
  2955. // if p.Type == 3 {
  2956. // //查询该耗材是否停用
  2957. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2958. // //表示该耗材已经停用,不能保存
  2959. // if goodInfoSeven.ID == 0 {
  2960. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2961. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2962. // return
  2963. // }
  2964. // }
  2965. //
  2966. //}
  2967. service.CreateHisProjectTwo(&p, tx)
  2968. //记录日志
  2969. byterequest, _ := json.Marshal(p)
  2970. adviceLog := models.XtDoctorAdviceLog{
  2971. UserOrgId: p.UserOrgId,
  2972. PatientId: p.PatientId,
  2973. AdminUserId: adminInfo.AdminUser.Id,
  2974. Module: 1,
  2975. ErrLog: string(byterequest),
  2976. Status: 1,
  2977. Ctime: time.Now().Unix(),
  2978. Mtime: 0,
  2979. Source: "电脑端新建his项目",
  2980. RecordDate: p.RecordDate,
  2981. }
  2982. service.CreateDoctorAdviceLog(adviceLog)
  2983. projectList = append(projectList, p)
  2984. var randNum int
  2985. randNum = rand.Intn(10000) + 1000
  2986. timestamp := time.Now().Unix()
  2987. tempTime := time.Unix(timestamp, 0)
  2988. timeFormat := tempTime.Format("20060102150405")
  2989. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2990. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2991. //新增或者编辑项目,修改对应的标签数据
  2992. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2993. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2994. var label models.HisLabelPrintInfo
  2995. project, _ := service.GetProjectDetail(p.ProjectId)
  2996. if project.CostClassify == 3 { //类别为检验检查
  2997. if p.TeamId > 0 { //检验检查组套
  2998. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2999. if tempLabel.ID == 0 {
  3000. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3001. label.Number = tempPrescription.PrescriptionNumber
  3002. label.ProjectId = project.ID
  3003. label.Status = 1
  3004. label.IsPrint = 2
  3005. label.DoctorId = info.DoctorId
  3006. label.UserOrgId = p.UserOrgId
  3007. label.PatientId = patient_id
  3008. label.RecordDate = recordDateTime
  3009. label.Ctime = time.Now().Unix()
  3010. label.Mtime = time.Now().Unix()
  3011. label.ItemId = p.TeamId
  3012. label.FeedetlSn = p.FeedetlSn
  3013. label.PProjectId = p.ID
  3014. label.ProjectName = team.ProjectTeam
  3015. label.PatientName = patient.Name
  3016. service.CreateHisLabelRecord(&label, tx)
  3017. }
  3018. } else { //单条检验检查项目
  3019. label.Number = tempPrescription.PrescriptionNumber
  3020. label.ProjectId = project.ID
  3021. label.Status = 1
  3022. label.DoctorId = info.DoctorId
  3023. label.UserOrgId = p.UserOrgId
  3024. label.PatientId = patient_id
  3025. label.RecordDate = recordDateTime
  3026. label.IsPrint = 2
  3027. label.Ctime = time.Now().Unix()
  3028. label.Mtime = time.Now().Unix()
  3029. label.FeedetlSn = p.FeedetlSn
  3030. label.PProjectId = p.ID
  3031. label.ItemId = p.TeamId
  3032. label.ProjectName = project.ProjectName
  3033. label.PatientName = patient.Name
  3034. service.CreateHisLabelRecord(&label, tx)
  3035. }
  3036. }
  3037. }
  3038. }
  3039. service.SaveHisProjectTwo(&p, tx)
  3040. }
  3041. }
  3042. }
  3043. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3044. // addition := items["addition"].([]interface{})
  3045. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3046. // ctime := time.Now().Unix()
  3047. // mtime := ctime
  3048. // if len(addition) > 0 {
  3049. // for _, item := range addition {
  3050. // var s models.HisAdditionalCharge
  3051. // s.PrescriptionId = tempPrescription.ID
  3052. // s.Status = 1
  3053. // s.UserOrgId = adminInfo.CurrentOrgId
  3054. // s.RecordDate = recordDateTime
  3055. // s.CreatedTime = ctime
  3056. // s.UpdatedTime = mtime
  3057. // s.PatientId = patient_id
  3058. // s.HisPatientId = his_patient_id
  3059. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3060. // if errcode > 0 {
  3061. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3062. // return
  3063. // }
  3064. // service.CreateAdditionalCharge(&s)
  3065. // var randNum int
  3066. // randNum = rand.Intn(10000) + 1000
  3067. // timestamp := time.Now().Unix()
  3068. // tempTime := time.Unix(timestamp, 0)
  3069. // timeFormat := tempTime.Format("20060102150405")
  3070. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3071. // service.CreateAdditionalCharge(&s)
  3072. //
  3073. // }
  3074. // }
  3075. //}
  3076. }
  3077. }
  3078. //查询今日该患者开的药品处方
  3079. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3080. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3081. //药品出库
  3082. if drugOutConfig.IsOpen == 1 {
  3083. for _, item := range hisdoctorlist {
  3084. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3085. // 查询该药品最后一次出库记录
  3086. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3087. if len(druginfo) > 0 {
  3088. //回退库存
  3089. for _, it := range druginfo {
  3090. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3091. service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3092. }
  3093. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3094. service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3095. }
  3096. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3097. service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3098. }
  3099. }
  3100. }
  3101. //删除记录
  3102. service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3103. //查询最后一次数据
  3104. if drugOutConfig.IsOpen == 1 {
  3105. //出库
  3106. if drug.IsUse == 2 {
  3107. creater := adminInfo.AdminUser.Id
  3108. service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3109. }
  3110. //更新字典里面的库存
  3111. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3112. var sum_count int64
  3113. for _, its := range stockInfo {
  3114. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3115. if its.MaxUnit == baseDrug.MaxUnit {
  3116. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3117. }
  3118. sum_count += its.StockMaxNumber + its.StockMinNumber
  3119. }
  3120. //更新基础库存
  3121. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3122. //剩余库存
  3123. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3124. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3125. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3126. }
  3127. }
  3128. }
  3129. //耗材保存处方出库
  3130. if goodOutConfig.IsOpen == 1 {
  3131. //查询今日耗材出库数量
  3132. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3133. for _, item := range hisgoodlist {
  3134. //查询历史出库数据
  3135. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3136. var out_count_five int64
  3137. for _, item := range flowGood {
  3138. out_count_five += item.Count
  3139. }
  3140. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3141. if out_count_five != parseIntCount {
  3142. //查询耗材最后一次出库记录
  3143. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3144. //查询默认出库仓库库存
  3145. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3146. if len(wareOut) > 0 {
  3147. for _, it := range wareOut {
  3148. //回退库存
  3149. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3150. //删除出库记录
  3151. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3152. }
  3153. }
  3154. timeStr := time.Now().Format("2006-01-02")
  3155. timeArr := strings.Split(timeStr, "-")
  3156. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3157. total = total + 1
  3158. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3159. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3160. number = number + total
  3161. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3162. operation_time := time.Now().Unix()
  3163. creater := c.GetAdminUserInfo().AdminUser.Id
  3164. recordDateStr := time.Now().Format("2006-01-02")
  3165. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3166. nowtime := recordDate.Unix()
  3167. warehouseOut := models.WarehouseOut{
  3168. WarehouseOutOrderNumber: warehousing_out_order,
  3169. OperationTime: operation_time,
  3170. OrgId: adminInfo.CurrentOrgId,
  3171. Creater: creater,
  3172. Ctime: time.Now().Unix(),
  3173. Status: 1,
  3174. WarehouseOutTime: nowtime,
  3175. Type: 1,
  3176. StorehouseId: storeConfig.StorehouseOutInfo,
  3177. IsCheck: 1,
  3178. IsSys: 1,
  3179. }
  3180. //查询是否生成出库单
  3181. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3182. if out.ID == 0 {
  3183. service.AddSigleWarehouseOut(&warehouseOut)
  3184. }
  3185. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3186. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3187. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3188. dialyPrepareOne := models.DialysisBeforePrepare{
  3189. GoodTypeId: goodObj.GoodTypeId,
  3190. GoodId: item.ProjectId,
  3191. PatientId: item.PatientId,
  3192. RecordDate: item.RecordDate,
  3193. UserOrgId: adminInfo.CurrentOrgId,
  3194. Count: parseIntCount,
  3195. Ctime: time.Now().Unix(),
  3196. Creater: creater,
  3197. Status: 1,
  3198. StorehouseId: houseConfig.StorehouseOutInfo,
  3199. ProjectId: item.ID,
  3200. }
  3201. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3202. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3203. //查询历史出库数据
  3204. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3205. var out_count int64
  3206. for _, item := range flowGood {
  3207. out_count += item.Count
  3208. }
  3209. //如果历史数和当前数据不想等才进行退库出库
  3210. if out_count != parseIntCount {
  3211. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3212. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3213. detail := models.AutomaticReduceDetail{
  3214. WarehouseOutId: 0,
  3215. WarehouseOutOrderNumber: "",
  3216. PatientId: item.PatientId,
  3217. Ctime: time.Now().Unix(),
  3218. Mtime: 0,
  3219. Status: 1,
  3220. RecordTime: item.RecordDate,
  3221. OrgId: item.UserOrgId,
  3222. GoodId: item.ProjectId,
  3223. GoodTypeId: 0,
  3224. Count: parseIntCount,
  3225. Type: 0,
  3226. ProjectId: item.ID,
  3227. StorehouseId: 0,
  3228. }
  3229. service.CreateAutoDetail(detail)
  3230. //查询剩余库存
  3231. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3232. var sum_count int64
  3233. for _, item := range goodList {
  3234. sum_count += item.StockCount
  3235. }
  3236. //更新剩余库存
  3237. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3238. //耗材
  3239. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3240. }
  3241. }
  3242. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3243. //查询历史出库数据
  3244. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3245. var out_count int64
  3246. for _, item := range flowGood {
  3247. out_count += item.Count
  3248. }
  3249. //如果历史数和当前数据不想等才进行退库出库
  3250. if out_count != parseIntCount {
  3251. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3252. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3253. detail := models.AutomaticReduceDetail{
  3254. WarehouseOutId: 0,
  3255. WarehouseOutOrderNumber: "",
  3256. PatientId: item.PatientId,
  3257. Ctime: time.Now().Unix(),
  3258. Mtime: 0,
  3259. Status: 1,
  3260. RecordTime: item.RecordDate,
  3261. OrgId: item.UserOrgId,
  3262. GoodId: item.ProjectId,
  3263. GoodTypeId: 0,
  3264. Count: parseIntCount,
  3265. Type: 0,
  3266. ProjectId: item.ID,
  3267. StorehouseId: 0,
  3268. }
  3269. service.CreateAutoDetail(detail)
  3270. //查询剩余库存
  3271. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3272. var sum_count int64
  3273. for _, item := range goodList {
  3274. sum_count += item.StockCount
  3275. }
  3276. //更新剩余库存
  3277. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3278. //耗材
  3279. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3280. }
  3281. }
  3282. }
  3283. }
  3284. }
  3285. }
  3286. tx.Commit()
  3287. if err == nil {
  3288. c.ServeSuccessJSON(map[string]interface{}{
  3289. "msg": "保存成功",
  3290. })
  3291. return
  3292. } else {
  3293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3294. return
  3295. }
  3296. }
  3297. //func (c *HisApiController) EditHisPrescription() {
  3298. // record_date := c.GetString("record_date")
  3299. // patient_id, _ := c.GetInt64("patient_id")
  3300. // reg_type, _ := c.GetInt64("reg_type")
  3301. // //diagnose, _ := c.GetInt64("diagnose", 0)
  3302. // diagnose := c.GetString("diagnose")
  3303. // sick_type, _ := c.GetInt64("sick_type")
  3304. // sick_history := c.GetString("sick_history")
  3305. // doctor_id, _ := c.GetInt64("doctor", 0)
  3306. // department, _ := c.GetInt64("department", 0)
  3307. // his_patient_id, _ := c.GetInt64("his_patient_id")
  3308. // p_type, _ := c.GetInt64("p_type")
  3309. //
  3310. // dataBody := make(map[string]interface{}, 0)
  3311. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3312. // if err != nil {
  3313. // utils.ErrorLog(err.Error())
  3314. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3315. // return
  3316. // }
  3317. //
  3318. // timeLayout := "2006-01-02"
  3319. // loc, _ := time.LoadLocation("Local")
  3320. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3321. // if err != nil {
  3322. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3323. // return
  3324. // }
  3325. // adminInfo := c.GetAdminUserInfo()
  3326. // recordDateTime := theTime.Unix()
  3327. //
  3328. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3329. //
  3330. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3331. // var hpInfo models.HisPrescriptionInfo
  3332. // if info.ID == 0 {
  3333. // var randNum int
  3334. // randNum = rand.Intn(10000) + 1000
  3335. // timestamp := time.Now().Unix()
  3336. // tempTime := time.Unix(timestamp, 0)
  3337. // timeFormat := tempTime.Format("20060102150405")
  3338. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3339. //
  3340. // hpInfo = models.HisPrescriptionInfo{
  3341. // UserOrgId: adminInfo.CurrentOrgId,
  3342. // RecordDate: theTime.Unix(),
  3343. // PatientId: patient_id,
  3344. // Status: 1,
  3345. // Ctime: time.Now().Unix(),
  3346. // Mtime: time.Now().Unix(),
  3347. // Creator: adminInfo.AdminUser.Id,
  3348. // Modifier: adminInfo.AdminUser.Id,
  3349. // Diagnosis: diagnose,
  3350. // SickHistory: sick_history,
  3351. // Departments: department,
  3352. // RegisterType: reg_type,
  3353. // PrescriptionNumber: p_number,
  3354. // PrescriptionStatus: 1,
  3355. // Doctor: role.UserName,
  3356. // DoctorId: doctor_id,
  3357. // SickType: sick_type,
  3358. // PType: p_type,
  3359. // }
  3360. // service.SavePatientPrescriptionInfo(hpInfo)
  3361. //
  3362. // } else {
  3363. // hpInfo = models.HisPrescriptionInfo{
  3364. // ID: info.ID,
  3365. // UserOrgId: adminInfo.CurrentOrgId,
  3366. // RecordDate: info.RecordDate,
  3367. // PatientId: info.PatientId,
  3368. // Status: 1,
  3369. // Ctime: info.Ctime,
  3370. // Mtime: time.Now().Unix(),
  3371. // Creator: info.Creator,
  3372. // Modifier: adminInfo.AdminUser.Id,
  3373. // Diagnosis: diagnose,
  3374. // SickHistory: sick_history,
  3375. // Departments: department,
  3376. // RegisterType: reg_type,
  3377. // PrescriptionNumber: info.PrescriptionNumber,
  3378. // Doctor: role.UserName,
  3379. // PrescriptionStatus: info.PrescriptionStatus,
  3380. // DoctorId: doctor_id,
  3381. // SickType: sick_type,
  3382. // PType: info.PType,
  3383. // }
  3384. // service.SavePatientPrescriptionInfo(hpInfo)
  3385. // }
  3386. //
  3387. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3388. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3389. //
  3390. // if len(prescriptions) > 0 {
  3391. // for _, item := range prescriptions {
  3392. // items := item.(map[string]interface{})
  3393. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3394. // utils.ErrorLog("id")
  3395. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3396. // return
  3397. // }
  3398. // id := int64(items["id"].(float64))
  3399. //
  3400. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3401. // utils.ErrorLog("type")
  3402. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3403. // return
  3404. // }
  3405. // types := int64(items["type"].(float64))
  3406. //
  3407. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3408. // utils.ErrorLog("med_type")
  3409. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3410. // return
  3411. // }
  3412. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3413. //
  3414. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3415. //
  3416. // ctime := time.Now().Unix()
  3417. //
  3418. // prescription := &models.HisPrescription{
  3419. // ID: id,
  3420. // PatientId: patient_id,
  3421. // UserOrgId: adminInfo.CurrentOrgId,
  3422. // RecordDate: recordDateTime,
  3423. // Ctime: ctime,
  3424. // Mtime: ctime,
  3425. // Type: types,
  3426. // Modifier: adminInfo.AdminUser.Id,
  3427. // Creator: adminInfo.AdminUser.Id,
  3428. // Status: 1,
  3429. // Doctor: role.UserName,
  3430. // HisPatientId: his_patient_id,
  3431. // OrderStatus: 1,
  3432. // BatchNumber: "",
  3433. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  3434. // PType: hpInfo.PType,
  3435. // MedType: med_type,
  3436. // }
  3437. //
  3438. // if historyPrescription.ID > 0 {
  3439. // prescription.PreTime = historyPrescription.PreTime
  3440. //
  3441. // }
  3442. //
  3443. // service.SaveHisPrescription(prescription)
  3444. //
  3445. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3446. // advices := items["advices"].([]interface{})
  3447. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3448. // groupNo := int64(0)
  3449. // ctime := time.Now().Unix()
  3450. // mtime := ctime
  3451. // if len(advices) > 0 {
  3452. // for _, advice := range advices {
  3453. // var s models.HisDoctorAdviceInfo
  3454. // s.PrescriptionId = prescription.ID
  3455. // s.AdviceType = 2
  3456. // s.AdviceDoctor = adminInfo.AdminUser.Id
  3457. // s.StopState = 2
  3458. // s.ExecutionState = 2
  3459. // s.AdviceDate = recordDateTime
  3460. // s.Status = 1
  3461. // s.UserOrgId = adminInfo.CurrentOrgId
  3462. // s.RecordDate = recordDateTime
  3463. // s.StartTime = prescription.PreTime
  3464. // s.Groupno = groupNo
  3465. // s.CreatedTime = ctime
  3466. // s.UpdatedTime = mtime
  3467. // s.PatientId = patient_id
  3468. // s.HisPatientId = his_patient_id
  3469. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3470. // if errcode > 0 {
  3471. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3472. // return
  3473. // }
  3474. //
  3475. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3476. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3477. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3478. // if s.Price == 0 {
  3479. // s.Price = lastWarehouse.RetailPrice
  3480. // }
  3481. // }
  3482. //
  3483. // service.CreateHisDoctorAdvice(&s)
  3484. // //记录日志
  3485. // byterequest, _ := json.Marshal(s)
  3486. // adviceLog := models.XtDoctorAdviceLog{
  3487. // UserOrgId: s.UserOrgId,
  3488. // PatientId: s.PatientId,
  3489. // AdminUserId: adminInfo.AdminUser.Id,
  3490. // Module: 1,
  3491. // ErrLog: string(byterequest),
  3492. // Status: 1,
  3493. // Ctime: time.Now().Unix(),
  3494. // Mtime: 0,
  3495. // Source: "电脑端his医嘱修改",
  3496. // RecordDate: s.AdviceDate,
  3497. // }
  3498. // service.CreateDoctorAdviceLog(adviceLog)
  3499. // redis := service.RedisClient()
  3500. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3501. // redis.Set(key, "", time.Second)
  3502. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3503. // fmt.Println("keyOne", keyOne)
  3504. // redis.Set(keyOne, "", time.Second)
  3505. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3506. // redis.Set(keySeven, "", time.Second)
  3507. // redis.Close()
  3508. //
  3509. // }
  3510. // }
  3511. // }
  3512. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3513. // projects := items["project"].([]interface{})
  3514. // if len(projects) > 0 {
  3515. // for _, project := range projects {
  3516. // var p models.HisPrescriptionProject
  3517. // p.PrescriptionId = prescription.ID
  3518. // p.Ctime = time.Now().Unix()
  3519. // p.Mtime = time.Now().Unix()
  3520. // p.PatientId = patient_id
  3521. // p.RecordDate = recordDateTime
  3522. // p.UserOrgId = adminInfo.CurrentOrgId
  3523. // p.HisPatientId = his_patient_id
  3524. // p.Status = 1
  3525. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3526. // if errcode > 0 {
  3527. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3528. // return
  3529. // }
  3530. // service.CreateHisProjectTwo(&p)
  3531. //
  3532. // //记录日志
  3533. // byterequest, _ := json.Marshal(p)
  3534. // adviceLog := models.XtDoctorAdviceLog{
  3535. // UserOrgId: p.UserOrgId,
  3536. // PatientId: p.PatientId,
  3537. // AdminUserId: adminInfo.AdminUser.Id,
  3538. // Module: 1,
  3539. // ErrLog: string(byterequest),
  3540. // Status: 1,
  3541. // Ctime: time.Now().Unix(),
  3542. // Mtime: 0,
  3543. // Source: "电脑端his项目修改",
  3544. // RecordDate: p.RecordDate,
  3545. // }
  3546. // service.CreateDoctorAdviceLog(adviceLog)
  3547. // }
  3548. // }
  3549. // }
  3550. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3551. // addition := items["addition"].([]interface{})
  3552. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3553. // ctime := time.Now().Unix()
  3554. // mtime := ctime
  3555. // if len(addition) > 0 {
  3556. // for _, item := range addition {
  3557. // var s models.HisAdditionalCharge
  3558. // s.PrescriptionId = prescription.ID
  3559. // s.Status = 1
  3560. // s.UserOrgId = adminInfo.CurrentOrgId
  3561. // s.RecordDate = recordDateTime
  3562. // s.CreatedTime = ctime
  3563. // s.UpdatedTime = mtime
  3564. // s.PatientId = patient_id
  3565. // s.HisPatientId = his_patient_id
  3566. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3567. // if errcode > 0 {
  3568. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3569. // return
  3570. // }
  3571. // service.CreateAdditionalCharge(&s)
  3572. // }
  3573. // }
  3574. // }
  3575. //
  3576. // }
  3577. // }
  3578. // }
  3579. // if err == nil {
  3580. // c.ServeSuccessJSON(map[string]interface{}{
  3581. // "msg": "保存成功",
  3582. // })
  3583. // return
  3584. //
  3585. // } else {
  3586. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3587. // return
  3588. // }
  3589. //}
  3590. func (c *HisApiController) DeletePrescription() {
  3591. prescription_id, _ := c.GetInt64("id")
  3592. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3593. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3594. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3595. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3596. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3597. //耗材保存处方出库
  3598. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3599. //已收费和已发药限制逻辑
  3600. isCharge := false
  3601. isMedicine := false
  3602. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3603. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3604. for _, item := range new_prescriptions {
  3605. if item.IsMedicine == 1 {
  3606. isMedicine = true
  3607. }
  3608. }
  3609. for _, item := range new_prescriptions {
  3610. if item.OrderStatus == 4 {
  3611. isCharge = true
  3612. }
  3613. }
  3614. if p_err != nil {
  3615. if new_prescription.ID > 0 {
  3616. if new_prescription.OrderStatus == 2 {
  3617. isCharge = true
  3618. }
  3619. }
  3620. }
  3621. for _, item := range advices {
  3622. if item.IsMedicine == 1 {
  3623. isMedicine = true
  3624. }
  3625. }
  3626. if isCharge {
  3627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3628. return
  3629. }
  3630. if isMedicine {
  3631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3632. return
  3633. }
  3634. //已收费和已发药限制逻辑
  3635. if len(projects) > 0 {
  3636. for _, item := range projects {
  3637. service.DeletePrintInfo(item.ID) //删除打印信息
  3638. if goodOutConfig.IsOpen != 1 {
  3639. if stockConfig.IsOpen == 1 {
  3640. if item.Type == 3 && item.IsOut == 1 {
  3641. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3642. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3643. good.Total = good.Total + f_count
  3644. service.UpdateGoodInfo(&good)
  3645. operation_time := time.Now().Unix()
  3646. creater := c.GetAdminUserInfo().AdminUser.Id
  3647. //创建退库单
  3648. timeStr := time.Now().Format("2006-01-02")
  3649. timeArr := strings.Split(timeStr, "-")
  3650. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3651. total = total + 1
  3652. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3653. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3654. cancelStock := models.CancelStock{
  3655. OrderNumber: orderNumber,
  3656. OperaTime: operation_time,
  3657. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3658. Creater: creater,
  3659. Ctime: time.Now().Unix(),
  3660. Status: 1,
  3661. ReturnTime: item.RecordDate,
  3662. Type: 1,
  3663. StorehouseId: houseConfig.StorehouseOutInfo,
  3664. IsCheck: 1,
  3665. }
  3666. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3667. if msgerrkonde == gorm.ErrRecordNotFound {
  3668. service.AddSigleCancelStock(&cancelStock)
  3669. }
  3670. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3671. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3672. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3673. //查询该耗材是否出库
  3674. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3675. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3676. deaerler, _ := service.GetDealerById(info.Dealer)
  3677. var total_count int64
  3678. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3679. total_count += count
  3680. if info.ID > 0 {
  3681. if info.Count >= total_count {
  3682. //回退库存
  3683. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3684. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3685. var flush_count int64
  3686. for _, it := range goodList {
  3687. flush_count += it.StockCount
  3688. }
  3689. cancelStockInfo := models.CancelStockInfo{
  3690. GoodId: item.ProjectId,
  3691. CancelStockId: cancel.ID,
  3692. GoodTypeId: good.GoodTypeId,
  3693. Count: prescribingNumber,
  3694. Price: info.Price,
  3695. Total: 0,
  3696. ProductDate: info.ProductDate,
  3697. ExpiryDate: info.ExpiryDate,
  3698. Ctime: time.Now().Unix(),
  3699. Status: 1,
  3700. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3701. OrderNumber: cancel.OrderNumber,
  3702. Type: 0,
  3703. Dealer: deaerler.DealerName,
  3704. Manufacturer: manufacturer.ManufacturerName,
  3705. Number: info.Number,
  3706. RegisterAccount: "",
  3707. Remark: "",
  3708. WarehouseInfoId: info.WarehouseInfotId,
  3709. PatientId: info.PatientId,
  3710. RecordDate: info.SysRecordTime,
  3711. StorehouseId: houseConfig.StorehouseOutInfo,
  3712. IsCheck: 1,
  3713. }
  3714. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3715. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3716. flow := models.VmStockFlow{
  3717. WarehousingId: info.WarehouseInfotId,
  3718. GoodId: item.ProjectId,
  3719. Number: info.Number,
  3720. LicenseNumber: info.LicenseNumber,
  3721. Count: prescribingNumber,
  3722. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3723. PatientId: item.PatientId,
  3724. SystemTime: info.SysRecordTime,
  3725. ConsumableType: 7,
  3726. IsSys: 0,
  3727. WarehousingOrder: "",
  3728. WarehouseOutId: info.WarehouseOutId,
  3729. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3730. IsEdit: 0,
  3731. CancelStockId: cancel.ID,
  3732. CancelOrderNumber: cancel.OrderNumber,
  3733. Manufacturer: manufacturer.ID,
  3734. Dealer: 0,
  3735. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3736. UpdateCreator: 0,
  3737. Status: 1,
  3738. Ctime: time.Now().Unix(),
  3739. Mtime: 0,
  3740. Price: info.Price,
  3741. WarehousingDetailId: info.WarehouseInfotId,
  3742. WarehouseOutDetailId: info.ID,
  3743. CancelOutDetailId: cancelInfo.ID,
  3744. ProductDate: info.ProductDate,
  3745. ExpireDate: info.ExpiryDate,
  3746. StorehouseId: houseConfig.StorehouseOutInfo,
  3747. OverCount: flush_count,
  3748. }
  3749. service.CreateStockFlowOne(flow)
  3750. //退库数量增加
  3751. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3752. //出库数量减少
  3753. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3754. }
  3755. if info.Count < total_count {
  3756. //回退库存
  3757. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3758. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3759. var flush_count int64
  3760. for _, it := range goodList {
  3761. flush_count += it.StockCount
  3762. }
  3763. cancelStockInfo := models.CancelStockInfo{
  3764. GoodId: item.ProjectId,
  3765. CancelStockId: cancel.ID,
  3766. GoodTypeId: good.GoodTypeId,
  3767. Count: info.Count,
  3768. Price: info.Price,
  3769. Total: 0,
  3770. ProductDate: info.ProductDate,
  3771. ExpiryDate: info.ExpiryDate,
  3772. Ctime: time.Now().Unix(),
  3773. Status: 1,
  3774. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3775. OrderNumber: cancel.OrderNumber,
  3776. Type: 0,
  3777. Dealer: deaerler.DealerName,
  3778. Manufacturer: manufacturer.ManufacturerName,
  3779. Number: info.Number,
  3780. RegisterAccount: "",
  3781. Remark: "",
  3782. WarehouseInfoId: info.WarehouseInfotId,
  3783. PatientId: info.PatientId,
  3784. RecordDate: info.SysRecordTime,
  3785. StorehouseId: houseConfig.StorehouseOutInfo,
  3786. IsCheck: 1,
  3787. }
  3788. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3789. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3790. flow := models.VmStockFlow{
  3791. WarehousingId: info.WarehouseInfotId,
  3792. GoodId: item.ProjectId,
  3793. Number: info.Number,
  3794. LicenseNumber: info.LicenseNumber,
  3795. Count: info.Count,
  3796. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3797. PatientId: item.PatientId,
  3798. SystemTime: info.SysRecordTime,
  3799. ConsumableType: 7,
  3800. IsSys: 0,
  3801. WarehousingOrder: "",
  3802. WarehouseOutId: info.WarehouseOutId,
  3803. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3804. IsEdit: 0,
  3805. CancelStockId: cancel.ID,
  3806. CancelOrderNumber: cancel.OrderNumber,
  3807. Manufacturer: manufacturer.ID,
  3808. Dealer: 0,
  3809. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3810. UpdateCreator: 0,
  3811. Status: 1,
  3812. Ctime: time.Now().Unix(),
  3813. Mtime: 0,
  3814. Price: info.Price,
  3815. WarehousingDetailId: info.WarehouseInfotId,
  3816. WarehouseOutDetailId: info.ID,
  3817. CancelOutDetailId: cancelInfo.ID,
  3818. ProductDate: info.ProductDate,
  3819. ExpireDate: info.ExpiryDate,
  3820. StorehouseId: houseConfig.StorehouseOutInfo,
  3821. OverCount: flush_count,
  3822. }
  3823. service.CreateStockFlowOne(flow)
  3824. //退库数量增加
  3825. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3826. //出库数量减少
  3827. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3828. }
  3829. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3830. var flush_count int64
  3831. for _, it := range goodList {
  3832. flush_count += it.StockCount
  3833. }
  3834. //查询已出库数量
  3835. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3836. if prescribingNumber < dialysisInfo.Count {
  3837. //改变数量
  3838. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3839. }
  3840. if prescribingNumber >= dialysisInfo.Count {
  3841. //删除出库表
  3842. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3843. }
  3844. //更新库存
  3845. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3846. //更新基础库库存
  3847. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3848. }
  3849. }
  3850. }
  3851. }
  3852. //保存耗材出库
  3853. if goodOutConfig.IsOpen == 1 {
  3854. if item.Type == 3 {
  3855. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3856. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3857. good.Total = good.Total + f_count
  3858. service.UpdateGoodInfo(&good)
  3859. operation_time := time.Now().Unix()
  3860. creater := c.GetAdminUserInfo().AdminUser.Id
  3861. //创建退库单
  3862. timeStr := time.Now().Format("2006-01-02")
  3863. timeArr := strings.Split(timeStr, "-")
  3864. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3865. total = total + 1
  3866. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3867. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3868. cancelStock := models.CancelStock{
  3869. OrderNumber: orderNumber,
  3870. OperaTime: operation_time,
  3871. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3872. Creater: creater,
  3873. Ctime: time.Now().Unix(),
  3874. Status: 1,
  3875. ReturnTime: item.RecordDate,
  3876. Type: 1,
  3877. StorehouseId: houseConfig.StorehouseOutInfo,
  3878. IsCheck: 1,
  3879. }
  3880. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3881. if msgerrkonde == gorm.ErrRecordNotFound {
  3882. service.AddSigleCancelStock(&cancelStock)
  3883. }
  3884. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3885. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3886. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3887. //查询该耗材是否出库
  3888. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3889. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3890. deaerler, _ := service.GetDealerById(info.Dealer)
  3891. var total_count int64
  3892. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3893. total_count += count
  3894. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3895. var flush_count int64
  3896. for _, it := range goodList {
  3897. flush_count += it.StockCount
  3898. }
  3899. fmt.Println("历史出库数据", info.Count)
  3900. fmt.Println("出库数量", total_count)
  3901. if info.ID > 0 {
  3902. cancelStockInfo := models.CancelStockInfo{
  3903. GoodId: item.ProjectId,
  3904. CancelStockId: cancel.ID,
  3905. GoodTypeId: good.GoodTypeId,
  3906. Count: prescribingNumber,
  3907. Price: info.Price,
  3908. Total: 0,
  3909. ProductDate: info.ProductDate,
  3910. ExpiryDate: info.ExpiryDate,
  3911. Ctime: time.Now().Unix(),
  3912. Status: 1,
  3913. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3914. OrderNumber: cancel.OrderNumber,
  3915. Type: 0,
  3916. Dealer: deaerler.DealerName,
  3917. Manufacturer: manufacturer.ManufacturerName,
  3918. Number: info.Number,
  3919. RegisterAccount: "",
  3920. Remark: "",
  3921. WarehouseInfoId: info.WarehouseInfotId,
  3922. PatientId: info.PatientId,
  3923. RecordDate: info.SysRecordTime,
  3924. StorehouseId: houseConfig.StorehouseOutInfo,
  3925. IsCheck: 1,
  3926. }
  3927. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3928. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3929. //查询出库数量
  3930. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3931. //出库数据 大于 退库数量
  3932. if len(list) > 0 {
  3933. for _, it := range list {
  3934. //回退库存
  3935. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3936. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3937. var flush_count_one int64
  3938. for _, it := range goodList {
  3939. flush_count_one += it.StockCount
  3940. }
  3941. //查询该批次是否有退库数据
  3942. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3943. creater := c.GetAdminUserInfo().AdminUser.Id
  3944. flow := models.VmStockFlow{
  3945. WarehousingId: it.WarehouseInfotId,
  3946. GoodId: it.GoodId,
  3947. Number: it.Number,
  3948. LicenseNumber: it.LicenseNumber,
  3949. Count: it.Count,
  3950. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3951. PatientId: it.PatientId,
  3952. SystemTime: it.SysRecordTime,
  3953. ConsumableType: 7,
  3954. IsSys: 0,
  3955. WarehousingOrder: "",
  3956. WarehouseOutId: it.WarehouseOutId,
  3957. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3958. IsEdit: 0,
  3959. CancelStockId: cancel.ID,
  3960. CancelOrderNumber: cancel.OrderNumber,
  3961. Manufacturer: manufacturer.ID,
  3962. Dealer: 0,
  3963. Creator: creater,
  3964. UpdateCreator: 0,
  3965. Status: 1,
  3966. Ctime: time.Now().Unix(),
  3967. Mtime: 0,
  3968. Price: it.Price,
  3969. WarehousingDetailId: it.WarehouseInfotId,
  3970. WarehouseOutDetailId: it.ID,
  3971. CancelOutDetailId: cancelInfo.ID,
  3972. ProductDate: it.ProductDate,
  3973. ExpireDate: it.ExpiryDate,
  3974. StorehouseId: houseConfig.StorehouseOutInfo,
  3975. OverCount: flush_count_one,
  3976. }
  3977. service.CreateStockFlowOne(flow)
  3978. //if flow.ID > 0 {
  3979. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3980. //}
  3981. }
  3982. }
  3983. //flow := models.VmStockFlow{
  3984. // WarehousingId: info.WarehouseInfotId,
  3985. // GoodId: item.ProjectId,
  3986. // Number: info.Number,
  3987. // LicenseNumber: info.LicenseNumber,
  3988. // Count: prescribingNumber,
  3989. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3990. // PatientId: item.PatientId,
  3991. // SystemTime: info.SysRecordTime,
  3992. // ConsumableType: 7,
  3993. // IsSys: 0,
  3994. // WarehousingOrder: "",
  3995. // WarehouseOutId: info.WarehouseOutId,
  3996. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3997. // IsEdit: 0,
  3998. // CancelStockId: cancel.ID,
  3999. // CancelOrderNumber: cancel.OrderNumber,
  4000. // Manufacturer: manufacturer.ID,
  4001. // Dealer: 0,
  4002. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4003. // UpdateCreator: 0,
  4004. // Status: 1,
  4005. // Ctime: time.Now().Unix(),
  4006. // Mtime: 0,
  4007. // Price: info.Price,
  4008. // WarehousingDetailId: info.WarehouseInfotId,
  4009. // WarehouseOutDetailId: info.ID,
  4010. // CancelOutDetailId: cancelInfo.ID,
  4011. // ProductDate: info.ProductDate,
  4012. // ExpireDate: info.ExpiryDate,
  4013. // StorehouseId: houseConfig.StorehouseOutInfo,
  4014. // OverCount: flush_count,
  4015. //}
  4016. //service.CreateStockFlowOne(flow)
  4017. //退库数量增加
  4018. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4019. //出库数量减少
  4020. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4021. //查询已出库数量
  4022. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4023. if prescribingNumber < dialysisInfo.Count {
  4024. //改变数量
  4025. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4026. }
  4027. if prescribingNumber >= dialysisInfo.Count {
  4028. //删除出库表
  4029. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4030. }
  4031. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4032. var flush_count_one int64
  4033. for _, it := range goodList {
  4034. flush_count_one += it.StockCount
  4035. }
  4036. //更新库存
  4037. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4038. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4039. //更新基础库库存
  4040. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4041. }
  4042. }
  4043. }
  4044. }
  4045. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4046. fmt.Println(err)
  4047. }
  4048. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4049. fmt.Println(err)
  4050. if len(advices) > 0 {
  4051. for _, item := range advices {
  4052. redis := service.RedisClient()
  4053. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4054. redis.Set(keyFive, "", time.Second)
  4055. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4056. redis.Set(keyOne, "", time.Second)
  4057. redis.Close()
  4058. }
  4059. }
  4060. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4061. if len(advices) > 0 {
  4062. for _, item := range advices {
  4063. creater := c.GetAdminUserInfo().AdminUser.Id
  4064. service.DrugAutoAddCancelInfo(item, creater)
  4065. }
  4066. }
  4067. } else {
  4068. if drugOutConfig.IsOpen == 1 {
  4069. if len(advices) > 0 {
  4070. for _, item := range advices {
  4071. creater := c.GetAdminUserInfo().AdminUser.Id
  4072. service.DrugAutoAddCancelInfo(item, creater)
  4073. }
  4074. }
  4075. } else {
  4076. if len(advices) > 0 {
  4077. for _, item := range advices {
  4078. creater := c.GetAdminUserInfo().AdminUser.Id
  4079. service.DrugAutoAddCancelInfo(item, creater)
  4080. }
  4081. }
  4082. }
  4083. }
  4084. c.ServeSuccessJSON(map[string]interface{}{
  4085. "msg": "删除成功",
  4086. })
  4087. return
  4088. }
  4089. func (c *HisApiController) DeleteDoctorAdvice() {
  4090. id, _ := c.GetInt64("id")
  4091. advice, _ := service.GetHisDoctorAdvicesById(id)
  4092. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4093. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4094. //已收费和已发药的限制逻辑
  4095. isCharge := false
  4096. isMedicine := false
  4097. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4098. //获取今天该患者所有处方,判断是否发药或者收费
  4099. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4100. for _, item := range new_prescriptions {
  4101. if item.IsMedicine == 1 {
  4102. isMedicine = true
  4103. }
  4104. }
  4105. for _, item := range new_prescriptions {
  4106. if item.OrderStatus == 4 {
  4107. isCharge = true
  4108. }
  4109. }
  4110. if isMedicine {
  4111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4112. return
  4113. }
  4114. if isCharge {
  4115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4116. return
  4117. }
  4118. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4119. for _, item := range advices {
  4120. if item.IsMedicine == 1 {
  4121. isMedicine = true
  4122. }
  4123. }
  4124. if isMedicine {
  4125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4126. return
  4127. }
  4128. if new_prescription.ID > 0 {
  4129. if new_prescription.OrderStatus == 2 {
  4130. isCharge = true
  4131. }
  4132. }
  4133. if isCharge {
  4134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4135. return
  4136. }
  4137. //已收费和已发药的限制逻辑
  4138. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4139. redis := service.RedisClient()
  4140. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4141. redis.Set(keyFive, "", time.Second)
  4142. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4143. redis.Set(keyOne, "", time.Second)
  4144. defer redis.Close()
  4145. if err == nil {
  4146. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4147. //查询是否在处方中出库
  4148. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4149. if openConfig.IsOpen != 1 {
  4150. //判断该医嘱是否执行了
  4151. if advice.ExecutionState == 1 {
  4152. creater := c.GetAdminUserInfo().AdminUser.Id
  4153. service.DrugAutoAddCancelInfo(&advice, creater)
  4154. }
  4155. }
  4156. //开启保存处方扣减功能
  4157. if openConfig.IsOpen == 1 {
  4158. creater := c.GetAdminUserInfo().AdminUser.Id
  4159. service.DrugAutoAddCancelInfo(&advice, creater)
  4160. }
  4161. } else {
  4162. if drugOutConfig.IsOpen == 1 {
  4163. //查询是否在处方中出库
  4164. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4165. if openConfig.IsOpen != 1 {
  4166. //判断该医嘱是否执行了
  4167. if advice.ExecutionState == 1 {
  4168. creater := c.GetAdminUserInfo().AdminUser.Id
  4169. service.DrugAutoAddCancelInfo(&advice, creater)
  4170. }
  4171. }
  4172. //开启保存处方扣减功能
  4173. if openConfig.IsOpen == 1 {
  4174. creater := c.GetAdminUserInfo().AdminUser.Id
  4175. service.DrugAutoAddCancelInfo(&advice, creater)
  4176. }
  4177. } else {
  4178. //判断该医嘱是否执行了
  4179. if advice.ExecutionState == 1 {
  4180. creater := c.GetAdminUserInfo().AdminUser.Id
  4181. service.DrugAutoAddCancelInfo(&advice, creater)
  4182. }
  4183. }
  4184. }
  4185. c.ServeSuccessJSON(map[string]interface{}{
  4186. "msg": "删除成功",
  4187. })
  4188. return
  4189. } else {
  4190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4191. return
  4192. }
  4193. }
  4194. func (c *HisApiController) DeleteProject() {
  4195. id, _ := c.GetInt64("id")
  4196. adminInfo := c.GetAdminUserInfo()
  4197. project, _ := service.GetHisProjectByID(id)
  4198. // var consumable models.DialysisBeforePrepare
  4199. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4200. //耗材保存处方出库
  4201. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4202. isCharge := false
  4203. isMedicine := false
  4204. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4205. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4206. for _, item := range new_prescriptions {
  4207. if item.IsMedicine == 1 {
  4208. isMedicine = true
  4209. }
  4210. }
  4211. for _, item := range new_prescriptions {
  4212. if item.OrderStatus == 4 {
  4213. isCharge = true
  4214. }
  4215. }
  4216. if isMedicine {
  4217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4218. return
  4219. }
  4220. if isCharge {
  4221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4222. return
  4223. }
  4224. if new_prescription.ID > 0 {
  4225. if new_prescription.OrderStatus == 2 {
  4226. isCharge = true
  4227. }
  4228. }
  4229. if isCharge {
  4230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4231. return
  4232. }
  4233. service.DeletePrintInfo(id)
  4234. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4235. label.Status = 0
  4236. service.CreateHisLabelRecordTwo(&label)
  4237. fmt.Println(goodOutConfig.IsOpen)
  4238. if goodOutConfig.IsOpen != 1 {
  4239. if stockConfig.IsOpen == 1 {
  4240. if project.Type == 2 {
  4241. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4242. fmt.Println(err)
  4243. }
  4244. if project.Type == 3 && project.IsOut == 1 {
  4245. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4246. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4247. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4248. operation_time := time.Now().Unix()
  4249. creater := adminInfo.AdminUser.Id
  4250. //创建退库单
  4251. timeStr := time.Now().Format("2006-01-02")
  4252. timeArr := strings.Split(timeStr, "-")
  4253. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4254. total = total + 1
  4255. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4256. cancelStock := models.CancelStock{
  4257. OrderNumber: orderNumber,
  4258. OperaTime: operation_time,
  4259. OrgId: adminInfo.CurrentOrgId,
  4260. Creater: creater,
  4261. Ctime: time.Now().Unix(),
  4262. Status: 1,
  4263. ReturnTime: project.RecordDate,
  4264. Type: 1,
  4265. StorehouseId: houseConfig.StorehouseOutInfo,
  4266. IsCheck: 1,
  4267. }
  4268. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4269. if msgerrkonde == gorm.ErrRecordNotFound {
  4270. service.AddSigleCancelStock(&cancelStock)
  4271. }
  4272. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4273. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4274. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4275. //查询是否有出库
  4276. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4277. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4278. deaerler, _ := service.GetDealerById(info.Dealer)
  4279. if info.ID > 0 {
  4280. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4281. if info.Count >= prescribingNumber {
  4282. cancelStockInfo := models.CancelStockInfo{
  4283. GoodId: project.ProjectId,
  4284. CancelStockId: cancel.ID,
  4285. GoodTypeId: good.GoodTypeId,
  4286. Count: prescribingNumber,
  4287. Price: info.Price,
  4288. Total: 0,
  4289. ProductDate: info.ProductDate,
  4290. ExpiryDate: info.ExpiryDate,
  4291. Ctime: time.Now().Unix(),
  4292. Status: 1,
  4293. OrgId: adminInfo.CurrentOrgId,
  4294. OrderNumber: cancel.OrderNumber,
  4295. Type: 0,
  4296. Dealer: deaerler.DealerName,
  4297. Manufacturer: manufacturer.ManufacturerName,
  4298. Number: info.Number,
  4299. RegisterAccount: "",
  4300. Remark: "",
  4301. WarehouseInfoId: info.WarehouseInfotId,
  4302. PatientId: info.PatientId,
  4303. RecordDate: info.SysRecordTime,
  4304. StorehouseId: houseConfig.StorehouseOutInfo,
  4305. IsCheck: 1,
  4306. }
  4307. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4308. //回退库存
  4309. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4310. //退库数量增加
  4311. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4312. //出库数量减少
  4313. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4314. }
  4315. if info.Count < prescribingNumber {
  4316. cancelStockInfo := models.CancelStockInfo{
  4317. GoodId: project.ProjectId,
  4318. CancelStockId: cancel.ID,
  4319. GoodTypeId: good.GoodTypeId,
  4320. Count: info.Count,
  4321. Price: info.Price,
  4322. Total: 0,
  4323. ProductDate: info.ProductDate,
  4324. ExpiryDate: info.ExpiryDate,
  4325. Ctime: time.Now().Unix(),
  4326. Status: 1,
  4327. OrgId: adminInfo.CurrentOrgId,
  4328. OrderNumber: cancel.OrderNumber,
  4329. Type: 0,
  4330. Dealer: deaerler.DealerName,
  4331. Manufacturer: manufacturer.ManufacturerName,
  4332. Number: info.Number,
  4333. RegisterAccount: "",
  4334. Remark: "",
  4335. WarehouseInfoId: info.WarehouseInfotId,
  4336. PatientId: info.PatientId,
  4337. RecordDate: info.SysRecordTime,
  4338. StorehouseId: houseConfig.StorehouseOutInfo,
  4339. IsCheck: 1,
  4340. }
  4341. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4342. //回退库存
  4343. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4344. //退库数量增加
  4345. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4346. //出库数量减少
  4347. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4348. }
  4349. //查询剩余库存
  4350. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4351. var over_count int64
  4352. for _, it := range goodList {
  4353. over_count += it.StockCount
  4354. }
  4355. //出库数据 大于 退库数量
  4356. if info.Count >= prescribingNumber {
  4357. flow := models.VmStockFlow{
  4358. WarehousingId: info.WarehouseInfotId,
  4359. GoodId: project.ProjectId,
  4360. Number: info.Number,
  4361. LicenseNumber: info.LicenseNumber,
  4362. Count: prescribingNumber,
  4363. UserOrgId: adminInfo.CurrentOrgId,
  4364. PatientId: project.PatientId,
  4365. SystemTime: info.SysRecordTime,
  4366. ConsumableType: 7,
  4367. IsSys: 0,
  4368. WarehousingOrder: "",
  4369. WarehouseOutId: info.WarehouseOutId,
  4370. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4371. IsEdit: 0,
  4372. CancelStockId: cancel.ID,
  4373. CancelOrderNumber: cancel.OrderNumber,
  4374. Manufacturer: manufacturer.ID,
  4375. Dealer: 0,
  4376. Creator: adminInfo.AdminUser.Id,
  4377. UpdateCreator: 0,
  4378. Status: 1,
  4379. Ctime: time.Now().Unix(),
  4380. Mtime: 0,
  4381. Price: info.Price,
  4382. WarehousingDetailId: info.WarehouseInfotId,
  4383. WarehouseOutDetailId: info.ID,
  4384. CancelOutDetailId: cancelInfo.ID,
  4385. ProductDate: info.ProductDate,
  4386. ExpireDate: info.ExpiryDate,
  4387. StorehouseId: houseConfig.StorehouseOutInfo,
  4388. OverCount: over_count,
  4389. }
  4390. service.CreateStockFlowOne(flow)
  4391. }
  4392. //出库数据小于退库数据
  4393. if info.Count < prescribingNumber {
  4394. flow := models.VmStockFlow{
  4395. WarehousingId: info.WarehouseInfotId,
  4396. GoodId: project.ProjectId,
  4397. Number: info.Number,
  4398. LicenseNumber: info.LicenseNumber,
  4399. Count: info.Count,
  4400. UserOrgId: adminInfo.CurrentOrgId,
  4401. PatientId: project.PatientId,
  4402. SystemTime: info.SysRecordTime,
  4403. ConsumableType: 7,
  4404. IsSys: 0,
  4405. WarehousingOrder: "",
  4406. WarehouseOutId: info.WarehouseOutId,
  4407. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4408. IsEdit: 0,
  4409. CancelStockId: cancel.ID,
  4410. CancelOrderNumber: cancel.OrderNumber,
  4411. Manufacturer: manufacturer.ID,
  4412. Dealer: 0,
  4413. Creator: adminInfo.AdminUser.Id,
  4414. UpdateCreator: 0,
  4415. Status: 1,
  4416. Ctime: time.Now().Unix(),
  4417. Mtime: 0,
  4418. Price: info.Price,
  4419. WarehousingDetailId: info.WarehouseInfotId,
  4420. WarehouseOutDetailId: info.ID,
  4421. CancelOutDetailId: cancelInfo.ID,
  4422. ProductDate: info.ProductDate,
  4423. ExpireDate: info.ExpiryDate,
  4424. StorehouseId: houseConfig.StorehouseOutInfo,
  4425. OverCount: over_count,
  4426. }
  4427. service.CreateStockFlowOne(flow)
  4428. }
  4429. //查询已出库数量
  4430. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4431. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4432. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4433. if prescribingNumber < dialysisInfo.Count {
  4434. //改变数量
  4435. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4436. }
  4437. if prescribingNumber >= dialysisInfo.Count {
  4438. //删除出库表
  4439. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4440. }
  4441. //更新剩余库存
  4442. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4443. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4444. var total_count_one int64
  4445. for _, it := range stockList {
  4446. total_count_one += it.StockCount
  4447. }
  4448. //基础库插入数据
  4449. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4450. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4451. var flush_count int64
  4452. for _, it := range goodListOne {
  4453. flush_count += it.StockCount
  4454. }
  4455. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4456. if errs != nil {
  4457. goodErrcode := models.XtGoodErrcode{
  4458. UserOrgId: project.UserOrgId,
  4459. Errcode: "手动出库更新剩余出库失败",
  4460. GoodId: project.ProjectId,
  4461. Status: 1,
  4462. Ctime: time.Now().Unix(),
  4463. Mtime: 0,
  4464. Count: 0,
  4465. StockCount: 0,
  4466. Creater: creater,
  4467. BatchNumberId: 0,
  4468. WarehouseOutId: 0,
  4469. }
  4470. service.CreateGoodErrcode(goodErrcode)
  4471. }
  4472. }
  4473. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4474. fmt.Println(err)
  4475. } else {
  4476. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4477. fmt.Println(err)
  4478. }
  4479. } else {
  4480. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4481. fmt.Println(err)
  4482. }
  4483. }
  4484. //保存处方出库
  4485. if goodOutConfig.IsOpen == 1 {
  4486. if project.Type == 3 {
  4487. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4488. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4489. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4490. operation_time := time.Now().Unix()
  4491. creater := adminInfo.AdminUser.Id
  4492. //创建退库单
  4493. timeStr := time.Now().Format("2006-01-02")
  4494. timeArr := strings.Split(timeStr, "-")
  4495. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4496. total = total + 1
  4497. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4498. cancelStock := models.CancelStock{
  4499. OrderNumber: orderNumber,
  4500. OperaTime: operation_time,
  4501. OrgId: adminInfo.CurrentOrgId,
  4502. Creater: creater,
  4503. Ctime: time.Now().Unix(),
  4504. Status: 1,
  4505. ReturnTime: project.RecordDate,
  4506. Type: 1,
  4507. StorehouseId: houseConfig.StorehouseOutInfo,
  4508. IsCheck: 1,
  4509. }
  4510. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4511. if msgerrkonde == gorm.ErrRecordNotFound {
  4512. service.AddSigleCancelStock(&cancelStock)
  4513. }
  4514. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4515. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4516. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4517. //获取出库数据
  4518. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4519. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4520. deaerler, _ := service.GetDealerById(info.Dealer)
  4521. if info.ID > 0 {
  4522. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4523. if info.Count >= prescribingNumber {
  4524. cancelStockInfo := models.CancelStockInfo{
  4525. GoodId: project.ProjectId,
  4526. CancelStockId: cancel.ID,
  4527. GoodTypeId: good.GoodTypeId,
  4528. Count: prescribingNumber,
  4529. Price: info.Price,
  4530. Total: 0,
  4531. ProductDate: info.ProductDate,
  4532. ExpiryDate: info.ExpiryDate,
  4533. Ctime: time.Now().Unix(),
  4534. Status: 1,
  4535. OrgId: adminInfo.CurrentOrgId,
  4536. OrderNumber: cancel.OrderNumber,
  4537. Type: 0,
  4538. Dealer: deaerler.DealerName,
  4539. Manufacturer: manufacturer.ManufacturerName,
  4540. Number: info.Number,
  4541. RegisterAccount: "",
  4542. Remark: "",
  4543. WarehouseInfoId: info.WarehouseInfotId,
  4544. PatientId: info.PatientId,
  4545. RecordDate: info.SysRecordTime,
  4546. StorehouseId: houseConfig.StorehouseOutInfo,
  4547. IsCheck: 1,
  4548. }
  4549. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4550. //退库数量增加
  4551. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4552. //出库数量减少
  4553. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4554. }
  4555. if info.Count < prescribingNumber {
  4556. cancelStockInfo := models.CancelStockInfo{
  4557. GoodId: project.ProjectId,
  4558. CancelStockId: cancel.ID,
  4559. GoodTypeId: good.GoodTypeId,
  4560. Count: prescribingNumber,
  4561. Price: info.Price,
  4562. Total: 0,
  4563. ProductDate: info.ProductDate,
  4564. ExpiryDate: info.ExpiryDate,
  4565. Ctime: time.Now().Unix(),
  4566. Status: 1,
  4567. OrgId: adminInfo.CurrentOrgId,
  4568. OrderNumber: cancel.OrderNumber,
  4569. Type: 0,
  4570. Dealer: deaerler.DealerName,
  4571. Manufacturer: manufacturer.ManufacturerName,
  4572. Number: info.Number,
  4573. RegisterAccount: "",
  4574. Remark: "",
  4575. WarehouseInfoId: info.WarehouseInfotId,
  4576. PatientId: info.PatientId,
  4577. RecordDate: info.SysRecordTime,
  4578. StorehouseId: houseConfig.StorehouseOutInfo,
  4579. IsCheck: 1,
  4580. }
  4581. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4582. //回退库存
  4583. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4584. }
  4585. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4586. var over_count int64
  4587. for _, it := range goodList {
  4588. over_count += it.StockCount
  4589. }
  4590. //查询出库数量
  4591. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4592. //出库数据 大于 退库数量
  4593. if len(list) > 0 {
  4594. for _, it := range list {
  4595. //回退库存
  4596. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4597. //退库数量增加
  4598. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4599. //出库数量减少
  4600. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4601. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4602. var over_count_one int64
  4603. for _, it := range goodList {
  4604. over_count_one += it.StockCount
  4605. }
  4606. //查询该批次是否有退库数据
  4607. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4608. flow := models.VmStockFlow{
  4609. WarehousingId: it.WarehouseInfotId,
  4610. GoodId: it.GoodId,
  4611. Number: it.Number,
  4612. LicenseNumber: it.LicenseNumber,
  4613. Count: it.Count,
  4614. UserOrgId: adminInfo.CurrentOrgId,
  4615. PatientId: it.PatientId,
  4616. SystemTime: it.SysRecordTime,
  4617. ConsumableType: 7,
  4618. IsSys: 0,
  4619. WarehousingOrder: "",
  4620. WarehouseOutId: it.WarehouseOutId,
  4621. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4622. IsEdit: 0,
  4623. CancelStockId: cancel.ID,
  4624. CancelOrderNumber: cancel.OrderNumber,
  4625. Manufacturer: manufacturer.ID,
  4626. Dealer: 0,
  4627. Creator: adminInfo.AdminUser.Id,
  4628. UpdateCreator: 0,
  4629. Status: 1,
  4630. Ctime: time.Now().Unix(),
  4631. Mtime: 0,
  4632. Price: it.Price,
  4633. WarehousingDetailId: it.WarehouseInfotId,
  4634. WarehouseOutDetailId: it.ID,
  4635. CancelOutDetailId: cancelInfo.ID,
  4636. ProductDate: it.ProductDate,
  4637. ExpireDate: it.ExpiryDate,
  4638. StorehouseId: houseConfig.StorehouseOutInfo,
  4639. OverCount: over_count_one,
  4640. }
  4641. service.CreateStockFlowOne(flow)
  4642. }
  4643. }
  4644. //查询已出库数量
  4645. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4646. if prescribingNumber < dialysisInfo.Count {
  4647. //改变数量
  4648. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4649. }
  4650. if prescribingNumber >= dialysisInfo.Count {
  4651. //删除出库表
  4652. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4653. }
  4654. //更新剩余库存
  4655. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4656. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4657. var total_count_one int64
  4658. for _, it := range stockList {
  4659. total_count_one += it.StockCount
  4660. }
  4661. //基础库插入数据
  4662. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4663. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4664. var flush_count int64
  4665. for _, it := range goodListOne {
  4666. flush_count += it.StockCount
  4667. }
  4668. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4669. if errs != nil {
  4670. goodErrcode := models.XtGoodErrcode{
  4671. UserOrgId: project.UserOrgId,
  4672. Errcode: "手动出库更新剩余出库失败",
  4673. GoodId: project.ProjectId,
  4674. Status: 1,
  4675. Ctime: time.Now().Unix(),
  4676. Mtime: 0,
  4677. Count: 0,
  4678. StockCount: 0,
  4679. Creater: creater,
  4680. BatchNumberId: 0,
  4681. WarehouseOutId: 0,
  4682. }
  4683. service.CreateGoodErrcode(goodErrcode)
  4684. }
  4685. }
  4686. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4687. fmt.Println(err)
  4688. } else {
  4689. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4690. fmt.Println(err)
  4691. }
  4692. }
  4693. c.ServeSuccessJSON(map[string]interface{}{
  4694. "msg": "删除成功",
  4695. })
  4696. return
  4697. }
  4698. func (c *HisApiController) CreateHisAdditionalCharge() {
  4699. his_patient_id, _ := c.GetInt64("his_patient_id")
  4700. patient_id, _ := c.GetInt64("patient_id")
  4701. record_date := c.GetString("record_date")
  4702. timeLayout := "2006-01-02"
  4703. loc, _ := time.LoadLocation("Local")
  4704. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4705. if err != nil {
  4706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4707. return
  4708. }
  4709. adminInfo := c.GetAdminUserInfo()
  4710. recordDateTime := theTime.Unix()
  4711. dataBody := make(map[string]interface{}, 0)
  4712. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4713. if err != nil {
  4714. utils.ErrorLog(err.Error())
  4715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4716. return
  4717. }
  4718. var additions []*models.HisAdditionalCharge
  4719. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4720. additions, _ := dataBody["addition"].([]interface{})
  4721. if len(additions) > 0 {
  4722. for _, item := range additions {
  4723. items := item.(map[string]interface{})
  4724. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4725. utils.ErrorLog("item_id")
  4726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4727. return
  4728. }
  4729. item_id := int64(items["item_id"].(float64))
  4730. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4731. utils.ErrorLog("item_name")
  4732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4733. return
  4734. }
  4735. item_name := items["item_name"].(string)
  4736. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4737. utils.ErrorLog("price")
  4738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4739. return
  4740. }
  4741. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4742. ctime := time.Now().Unix()
  4743. additional := &models.HisAdditionalCharge{
  4744. PatientId: patient_id,
  4745. HisPatientId: his_patient_id,
  4746. UserOrgId: adminInfo.CurrentOrgId,
  4747. RecordDate: recordDateTime,
  4748. CreatedTime: ctime,
  4749. UpdatedTime: ctime,
  4750. Modifier: adminInfo.AdminUser.Id,
  4751. Creator: adminInfo.AdminUser.Id,
  4752. Price: price,
  4753. ItemName: item_name,
  4754. ItemId: item_id,
  4755. Status: 1,
  4756. }
  4757. additions = append(additions, additional)
  4758. }
  4759. }
  4760. }
  4761. for _, item := range additions {
  4762. service.CreateAddtionalCharge(item)
  4763. }
  4764. c.ServeSuccessJSON(map[string]interface{}{
  4765. "msg": "创建成功",
  4766. })
  4767. }
  4768. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4769. blood_fat := c.GetString("blood_fat")
  4770. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4771. blood_sugar := c.GetString("blood_sugar")
  4772. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4773. chief_conplaint := c.GetString("chief_conplaint")
  4774. dbp := c.GetString("dbp")
  4775. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4776. delivery_way, _ := c.GetInt64("delivery_way")
  4777. diagnostic := c.GetString("diagnostic")
  4778. family_history := c.GetString("family_history")
  4779. height := c.GetString("height")
  4780. history_of_present_illness := c.GetString("history_of_present_illness")
  4781. is_infect, _ := c.GetInt64("is_infect")
  4782. past_history := c.GetString("past_history")
  4783. patient_id, _ := c.GetInt64("patient_id")
  4784. his_patient_id, _ := c.GetInt64("his_patient_id")
  4785. personal_history := c.GetString("personal_history")
  4786. pulse := c.GetString("pulse")
  4787. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4788. sbp := c.GetString("sbp")
  4789. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4790. heightfloat, _ := strconv.ParseFloat(height, 64)
  4791. sicktype := c.GetString("sick_type")
  4792. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4793. symptom := c.GetString("symptom")
  4794. sick_date := c.GetString("sick_date")
  4795. temperatures := c.GetString("temperature")
  4796. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4797. record_date := c.GetString("record_date")
  4798. breathing := c.GetString("breathing")
  4799. doctor_advice := c.GetString("doctor_advice")
  4800. remark := c.GetString("remark")
  4801. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4802. sick, _ := c.GetInt64("sick")
  4803. diagnose, _ := c.GetInt64("diagnose")
  4804. //id, _ := c.GetInt64("id")
  4805. timeLayout := "2006-01-02"
  4806. loc, _ := time.LoadLocation("Local")
  4807. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4808. allergic_history := c.GetString("allergic_history")
  4809. if err != nil {
  4810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4811. return
  4812. }
  4813. recordDateTime := theTime.Unix()
  4814. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4815. if err != nil {
  4816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4817. return
  4818. }
  4819. sickTimes := sickTime.Unix()
  4820. ctime := time.Now().Unix()
  4821. primary_disease := c.GetString("primary_disease")
  4822. confirm_failure_date := c.GetString("confirm_failure_date")
  4823. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4824. drug_allergy_history := c.GetString("drug_allergy_history")
  4825. physical_examination := c.GetString("physical_examination")
  4826. special_inspection := c.GetString("special_inspection")
  4827. lab_apparatus := c.GetString("lab_apparatus")
  4828. caseHistory := models.HisPatientCaseHistory{
  4829. HisPatientId: his_patient_id,
  4830. PatientId: patient_id,
  4831. Temperature: temperature,
  4832. BloodSugar: bloodsugarfloat,
  4833. Pulse: pulsefloat,
  4834. Sbp: sbpfloat,
  4835. Dbp: dbpfloat,
  4836. Height: heightfloat,
  4837. BloodFat: bloodfatfloat,
  4838. SickType: sick_type,
  4839. Symptom: symptom,
  4840. SickDate: sickTimes,
  4841. IsInfect: is_infect,
  4842. HistoryOfPresentIllness: history_of_present_illness,
  4843. PastHistory: past_history,
  4844. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4845. ChiefConplaint: chief_conplaint,
  4846. PersonalHistory: personal_history,
  4847. FamilyHistory: family_history,
  4848. Diagnostic: diagnostic,
  4849. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4850. Status: 1,
  4851. Ctime: ctime,
  4852. Mtime: ctime,
  4853. RecordDate: recordDateTime,
  4854. DeliveryWay: delivery_way,
  4855. Breathing: breathingfloat,
  4856. DoctorAdvice: doctor_advice,
  4857. Remark: remark,
  4858. Sick: sick,
  4859. Diagnose: diagnose,
  4860. AllergicHistory: allergic_history,
  4861. PrimaryDisease: primary_disease,
  4862. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4863. DrugAllergyHistory: drug_allergy_history,
  4864. PhysicalExamination: physical_examination,
  4865. SpecialInspection: special_inspection,
  4866. LabApparatus: lab_apparatus,
  4867. }
  4868. //查询该患者是否有病历
  4869. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4870. if errcodes == gorm.ErrRecordNotFound {
  4871. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4872. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4873. if err != nil {
  4874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4875. return
  4876. }
  4877. c.ServeSuccessJSON(map[string]interface{}{
  4878. "caseHistory": caseHistory,
  4879. "historyInfo": historyInfo,
  4880. })
  4881. return
  4882. } else if errcodes == nil {
  4883. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4884. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4885. if err != nil {
  4886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4887. return
  4888. }
  4889. c.ServeSuccessJSON(map[string]interface{}{
  4890. "caseHistory": caseHistory,
  4891. "historyInfo": historyInfo,
  4892. })
  4893. }
  4894. //查询该患者是否有病历
  4895. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4896. //if errcode == gorm.ErrRecordNotFound {
  4897. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4898. // if err != nil {
  4899. // c.ServeSuccessJSON(map[string]interface{}{
  4900. // "msg": "保存成功",
  4901. // })
  4902. // }
  4903. //} else if errcode == nil {
  4904. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4905. // return
  4906. //}
  4907. }
  4908. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4909. patient_id, _ := c.GetInt64("patient_id", 0)
  4910. adminUser := c.GetAdminUserInfo()
  4911. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4912. c.ServeSuccessJSON(map[string]interface{}{
  4913. "list": caseHistorys,
  4914. })
  4915. }
  4916. func (c *HisApiController) GetHisPatientCaseHistory() {
  4917. record_date, _ := c.GetInt64("record_date", 0)
  4918. patient_id, _ := c.GetInt64("patient_id", 0)
  4919. admin := c.GetAdminUserInfo()
  4920. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4921. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4922. c.ServeSuccessJSON(map[string]interface{}{
  4923. "info": info,
  4924. "case_history": case_history,
  4925. })
  4926. }
  4927. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4928. template_name := c.GetString("template_name")
  4929. template_remark := c.GetString("template_remark")
  4930. doctor := c.GetAdminUserInfo().AdminUser.Id
  4931. diagnostic := c.GetString("diagnostic")
  4932. chief_conplaint := c.GetString("chief_conplain")
  4933. history_of_present_illness := c.GetString("history_of_present_illness")
  4934. past_history := c.GetString("past_history")
  4935. personal_history := c.GetString("personal_history")
  4936. family_history := c.GetString("family_history")
  4937. user_name := c.GetString("user_name")
  4938. doctor_advice := c.GetString("doctor_advice")
  4939. remark := c.GetString("remark")
  4940. //record_date := c.GetString("record_date")
  4941. //fmt.Println("record_date--------",record_date)
  4942. //timeLayout := "2006-01-02"
  4943. //loc, _ := time.LoadLocation("Local")
  4944. //
  4945. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4946. //if err != nil {
  4947. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4948. // return
  4949. //}
  4950. //recordDateTime := theTime.Unix()
  4951. ctime := time.Now().Unix()
  4952. template := models.HisCaseHistoryTemplate{
  4953. HistoryOfPresentIllness: history_of_present_illness,
  4954. PastHistory: past_history,
  4955. ChiefConplaint: chief_conplaint,
  4956. PersonalHistory: personal_history,
  4957. FamilyHistory: family_history,
  4958. Diagnostic: diagnostic,
  4959. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4960. Status: 1,
  4961. Ctime: ctime,
  4962. Mtime: ctime,
  4963. RecordDate: time.Now().Unix(),
  4964. TemplateName: template_name,
  4965. TemplateRemark: template_remark,
  4966. Creator: doctor,
  4967. Modifier: doctor,
  4968. UserName: user_name,
  4969. DoctorAdvice: doctor_advice,
  4970. Remark: remark,
  4971. }
  4972. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4973. if err == nil {
  4974. c.ServeSuccessJSON(map[string]interface{}{
  4975. "msg": "保存成功",
  4976. })
  4977. } else {
  4978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4979. return
  4980. }
  4981. }
  4982. func (c *HisApiController) GetCaseHistoryTemplate() {
  4983. timeLayout := "2006-01-02"
  4984. loc, _ := time.LoadLocation("Local")
  4985. keyword := c.GetString("keyword")
  4986. start_time := c.GetString("start_time")
  4987. end_time := c.GetString("end_time")
  4988. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4989. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4990. admin := c.GetAdminUserInfo()
  4991. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4992. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4993. c.ServeSuccessJSON(map[string]interface{}{
  4994. "template": template,
  4995. //"history": history,
  4996. })
  4997. }
  4998. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4999. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5000. utils.ErrorLog("drug_name")
  5001. return enums.ErrorCodeParamWrong
  5002. }
  5003. adviceName, _ := json["drug_name"].(string)
  5004. if len(adviceName) == 0 {
  5005. utils.ErrorLog("len(advice_name) == 0")
  5006. return enums.ErrorCodeParamWrong
  5007. }
  5008. advice.AdviceName = adviceName
  5009. adviceDesc, _ := json["advice_desc"].(string)
  5010. advice.AdviceDesc = adviceDesc
  5011. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5012. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5013. advice.DrugSpec = drugSpec
  5014. }
  5015. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5016. remark, _ := json["remark"].(string)
  5017. advice.Remark = remark
  5018. }
  5019. if json["id"] == nil {
  5020. advice.DrugId = 0
  5021. } else {
  5022. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5023. drug_id := int64(json["id"].(float64))
  5024. advice.DrugId = drug_id
  5025. }
  5026. }
  5027. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5028. advice_id := int64(json["advice_id"].(float64))
  5029. advice.ID = advice_id
  5030. if advice.ID > 0 {
  5031. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5032. if err == nil {
  5033. if hisAdvice.ID > 0 {
  5034. advice.ExecutionTime = hisAdvice.ExecutionTime
  5035. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5036. advice.ExecutionState = hisAdvice.ExecutionState
  5037. advice.CheckTime = hisAdvice.CheckTime
  5038. advice.Checker = hisAdvice.Checker
  5039. advice.CheckState = hisAdvice.CheckState
  5040. advice.StartTime = hisAdvice.StartTime
  5041. advice.FeedetlSn = hisAdvice.FeedetlSn
  5042. }
  5043. }
  5044. }
  5045. }
  5046. //
  5047. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5048. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5049. // advice.ExecutionTime = execution_time
  5050. //}
  5051. //
  5052. //
  5053. //
  5054. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5055. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5056. // advice.ExecutionStaff = execution_staff
  5057. //}
  5058. //
  5059. //
  5060. //
  5061. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5062. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5063. // advice.ExecutionState = execution_state
  5064. //}
  5065. //
  5066. //
  5067. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5068. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5069. // advice.CheckTime = check_time
  5070. //}
  5071. //
  5072. //
  5073. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5074. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5075. // advice.CheckState = check_state
  5076. //}
  5077. //
  5078. //
  5079. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5080. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5081. // advice.Checker = checker
  5082. //}
  5083. //
  5084. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5085. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5086. // advice.StartTime = start_time
  5087. //}
  5088. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5089. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5090. advice.IsSelfDrug = is_self_drug
  5091. }
  5092. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5093. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5094. drug_way_count, _ := json["drug_way_count"].(string)
  5095. advice.DrugWayCount = drug_way_count
  5096. }
  5097. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5098. drugSpecUnit, _ := json["min_unit"].(string)
  5099. advice.DrugSpecUnit = drugSpecUnit
  5100. }
  5101. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5102. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5103. advice.SingleDose = singleDose
  5104. }
  5105. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5106. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5107. advice.SingleDoseUnit = singleDoseUnit
  5108. }
  5109. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5110. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5111. advice.PrescribingNumber = prescribingNumber
  5112. }
  5113. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5114. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5115. advice.PrescribingNumberUnit = prescribingNumberUnit
  5116. }
  5117. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5118. deliveryWay, _ := json["delivery_way"].(string)
  5119. advice.DeliveryWay = deliveryWay
  5120. }
  5121. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5122. executionFrequency, _ := json["execution_frequency"].(string)
  5123. advice.ExecutionFrequency = executionFrequency
  5124. }
  5125. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5126. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5127. advice.Price = price
  5128. }
  5129. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5130. med_list_codg, _ := json["medical_insurance_number"].(string)
  5131. advice.MedListCodg = med_list_codg
  5132. }
  5133. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5134. day := int64(json["day"].(float64))
  5135. advice.Day = day
  5136. }
  5137. return 0
  5138. }
  5139. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5140. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5141. id := int64(json["id"].(float64))
  5142. project.ID = id
  5143. historyProject, _ := service.GetHisProjectByID(id)
  5144. project.FeedetlSn = historyProject.FeedetlSn
  5145. }
  5146. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5147. project_id := int64(json["project_id"].(float64))
  5148. project.ProjectId = project_id
  5149. }
  5150. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5151. // price := int64(json["price"].(float64))
  5152. // formatInt_price := strconv.FormatInt(price, 10)
  5153. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5154. // project.Price = float_price
  5155. // }
  5156. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5157. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5158. project.Price = price
  5159. }
  5160. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5161. total, _ := json["total"].(string)
  5162. project.Count = total
  5163. }
  5164. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5165. medical_code, _ := json["medical_code"].(string)
  5166. project.MedListCodg = medical_code
  5167. }
  5168. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5169. single_dose, _ := json["single_dose"].(string)
  5170. project.SingleDose = single_dose
  5171. }
  5172. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5173. delivery_way, _ := json["delivery_way"].(string)
  5174. project.DeliveryWay = delivery_way
  5175. }
  5176. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5177. execution_frequency, _ := json["execution_frequency"].(string)
  5178. project.ExecutionFrequency = execution_frequency
  5179. }
  5180. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5181. remark, _ := json["remark"].(string)
  5182. project.Remark = remark
  5183. }
  5184. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5185. day, _ := json["number_days"].(string)
  5186. project.Day = day
  5187. }
  5188. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5189. unit, _ := json["unit"].(string)
  5190. project.Unit = unit
  5191. }
  5192. return 0
  5193. }
  5194. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5195. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5196. id := int64(json["id"].(float64))
  5197. historyAddtions, _ := service.GetHisAdditionByID(id)
  5198. additionalCharge.ID = id
  5199. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5200. }
  5201. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5202. item_id := int64(json["item_id"].(float64))
  5203. additionalCharge.ItemId = item_id
  5204. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5205. if config.ID > 0 {
  5206. if len(config.Code) > 0 {
  5207. additionalCharge.MedListCodg = config.Code
  5208. }
  5209. }
  5210. }
  5211. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5212. // price := int64(json["price"].(float64))
  5213. // formatInt_price := strconv.FormatInt(price, 10)
  5214. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5215. // additionalCharge.Price = float_price
  5216. // }
  5217. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5218. // price := int64(json["price"].(float64))
  5219. // formatInt_price := strconv.FormatInt(price, 10)
  5220. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5221. // additionalCharge.Price = float_price
  5222. //}
  5223. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5224. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5225. additionalCharge.Price = price
  5226. }
  5227. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5228. count, _ := json["count"].(string)
  5229. counts, _ := strconv.ParseInt(count, 10, 64)
  5230. additionalCharge.Count = counts
  5231. }
  5232. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5233. item_name, _ := json["item_name"].(string)
  5234. additionalCharge.ItemName = item_name
  5235. }
  5236. return 0
  5237. }
  5238. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5239. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5240. utils.ErrorLog("drug_name")
  5241. return enums.ErrorCodeParamWrong
  5242. }
  5243. adviceName, _ := json["drug_name"].(string)
  5244. if len(adviceName) == 0 {
  5245. utils.ErrorLog("len(advice_name) == 0")
  5246. return enums.ErrorCodeParamWrong
  5247. }
  5248. advice.AdviceName = adviceName
  5249. adviceDesc, _ := json["advice_desc"].(string)
  5250. advice.AdviceDesc = adviceDesc
  5251. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5252. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5253. advice.DrugSpec = drugSpec
  5254. }
  5255. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5256. remark, _ := json["remark"].(string)
  5257. advice.Remark = remark
  5258. }
  5259. if json["id"] == nil {
  5260. advice.DrugId = 0
  5261. } else {
  5262. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5263. drug_id := int64(json["id"].(float64))
  5264. advice.DrugId = drug_id
  5265. }
  5266. }
  5267. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5268. groupno := int64(json["groupno"].(float64))
  5269. advice.Groupno = groupno
  5270. }
  5271. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5272. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5273. advice.IsSelfDrug = is_self_drug
  5274. }
  5275. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5276. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5277. drug_way_count, _ := json["drug_way_count"].(string)
  5278. advice.DrugWayCount = drug_way_count
  5279. }
  5280. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5281. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5282. advice.HospApprFlag = hosp_appr_flag
  5283. }
  5284. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5285. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5286. advice.PrescribingNumber = prescribingNumber
  5287. }
  5288. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5289. // frequency_type := int64(json["frequency_type"].(float64))
  5290. // advice.FrequencyType = frequency_type
  5291. //}
  5292. //
  5293. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5294. // day_count := int64(json["day_count"].(float64))
  5295. // advice.DayCount = day_count
  5296. //}
  5297. //
  5298. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5299. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5300. // week_day, _ := json["week_day"].(string)
  5301. // advice.WeekDay = week_day
  5302. //}
  5303. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5304. drugSpecUnit, _ := json["min_unit"].(string)
  5305. advice.DrugSpecUnit = drugSpecUnit
  5306. }
  5307. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5308. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5309. advice.SingleDose = singleDose
  5310. }
  5311. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5312. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5313. advice.SingleDoseUnit = singleDoseUnit
  5314. }
  5315. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5316. deliveryWay, _ := json["delivery_way"].(string)
  5317. advice.DeliveryWay = deliveryWay
  5318. }
  5319. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5320. executionFrequency, _ := json["execution_frequency"].(string)
  5321. advice.ExecutionFrequency = executionFrequency
  5322. }
  5323. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5324. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5325. advice.Price = price
  5326. }
  5327. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5328. med_list_codg, _ := json["medical_insurance_number"].(string)
  5329. advice.MedListCodg = med_list_codg
  5330. }
  5331. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5332. day := int64(json["day"].(float64))
  5333. advice.Day = day
  5334. }
  5335. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5336. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5337. advice.PrescribingNumberUnit = prescribingNumberUnit
  5338. }
  5339. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5340. advice_id := int64(json["advice_id"].(float64))
  5341. advice.ID = advice_id
  5342. if advice.ID > 0 {
  5343. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5344. if err == nil {
  5345. if hisAdvice.ID > 0 {
  5346. advice.ExecutionTime = hisAdvice.ExecutionTime
  5347. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5348. advice.ExecutionState = hisAdvice.ExecutionState
  5349. advice.CheckTime = hisAdvice.CheckTime
  5350. advice.Checker = hisAdvice.Checker
  5351. advice.CheckState = hisAdvice.CheckState
  5352. advice.StartTime = hisAdvice.StartTime
  5353. advice.HospApprFlag = hisAdvice.HospApprFlag
  5354. advice.IsMedicine = hisAdvice.IsMedicine
  5355. if hisAdvice.UserOrgId == 10028 {
  5356. 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 {
  5357. advice.ExecutionTime = 0
  5358. advice.ExecutionStaff = 0
  5359. advice.ExecutionState = 2
  5360. advice.CheckTime = 0
  5361. advice.Checker = 0
  5362. advice.CheckState = 2
  5363. }
  5364. } else {
  5365. 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 {
  5366. advice.ExecutionTime = 0
  5367. advice.ExecutionStaff = 0
  5368. advice.ExecutionState = 2
  5369. advice.CheckTime = 0
  5370. advice.Checker = 0
  5371. advice.CheckState = 2
  5372. }
  5373. }
  5374. //advice.Groupno = hisAdvice.Groupno
  5375. }
  5376. }
  5377. }
  5378. }
  5379. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5380. //
  5381. //if drugStockConfig.IsOpen == 1 {
  5382. //
  5383. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5384. // if advice.ID == 0 { //医嘱不存在
  5385. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5386. // drug.Total = drug.Total - advice.PrescribingNumber
  5387. // service.UpdateBaseDrugLib(&drug)
  5388. //
  5389. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5390. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5391. // drug.Total = drug.Total - num
  5392. // service.UpdateBaseDrugLib(&drug)
  5393. // }
  5394. //
  5395. // } else if advice.ID > 0 { //医嘱存在
  5396. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5397. // var num float64
  5398. //
  5399. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5400. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5401. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5402. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5403. // drug.Total = drug.Total + num
  5404. // service.UpdateBaseDrugLib(&drug)
  5405. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5406. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5407. // drug.Total = drug.Total - num
  5408. // service.UpdateBaseDrugLib(&drug)
  5409. // }
  5410. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5411. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5412. // if num2 > advice.PrescribingNumber {
  5413. // num = num2 - advice.PrescribingNumber
  5414. // drug.Total = drug.Total + num
  5415. // service.UpdateBaseDrugLib(&drug)
  5416. // } else if num2 < advice.PrescribingNumber {
  5417. // num = advice.PrescribingNumber - num2
  5418. // drug.Total = drug.Total - num
  5419. // service.UpdateBaseDrugLib(&drug)
  5420. // }
  5421. //
  5422. // }
  5423. //
  5424. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5425. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5426. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5427. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5428. // if num1 > num2 {
  5429. // num = num1 - num2
  5430. // drug.Total = drug.Total + num
  5431. // service.UpdateBaseDrugLib(&drug)
  5432. // } else if num1 < num2 {
  5433. // num = num2 - num1
  5434. // drug.Total = drug.Total - num
  5435. // service.UpdateBaseDrugLib(&drug)
  5436. // }
  5437. //
  5438. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5439. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5440. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5441. // if hisAdvice.PrescribingNumber > num2 {
  5442. // num = hisAdvice.PrescribingNumber - num2
  5443. // drug.Total = drug.Total + num
  5444. // service.UpdateBaseDrugLib(&drug)
  5445. // } else if num2 < advice.PrescribingNumber {
  5446. // num = num2 - hisAdvice.PrescribingNumber
  5447. // drug.Total = drug.Total - num
  5448. // service.UpdateBaseDrugLib(&drug)
  5449. // }
  5450. //
  5451. // }
  5452. // }
  5453. // }
  5454. //}
  5455. //
  5456. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5457. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5458. // advice.ExecutionTime = execution_time
  5459. //}
  5460. //
  5461. //
  5462. //
  5463. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5464. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5465. // advice.ExecutionStaff = execution_staff
  5466. //}
  5467. //
  5468. //
  5469. //
  5470. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5471. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5472. // advice.ExecutionState = execution_state
  5473. //}
  5474. //
  5475. //
  5476. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5477. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5478. // advice.CheckTime = check_time
  5479. //}
  5480. //
  5481. //
  5482. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5483. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5484. // advice.CheckState = check_state
  5485. //}
  5486. //
  5487. //
  5488. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5489. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5490. // advice.Checker = checker
  5491. //}
  5492. //
  5493. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5494. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5495. // advice.StartTime = start_time
  5496. //}
  5497. return 0
  5498. }
  5499. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5500. project.ExecutionStaff = 0
  5501. project.ExecutionState = 2
  5502. project.ExecutionTime = 0
  5503. project.Checker = 0
  5504. project.CheckState = 2
  5505. project.CheckTime = 0
  5506. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5507. id := int64(json["id"].(float64))
  5508. project.ID = id
  5509. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5510. project.ExecutionStaff = temp_project.ExecutionStaff
  5511. project.ExecutionState = temp_project.ExecutionState
  5512. project.ExecutionTime = temp_project.ExecutionTime
  5513. project.Checker = temp_project.Checker
  5514. project.CheckState = temp_project.CheckState
  5515. project.CheckTime = temp_project.CheckTime
  5516. project.TeamId = temp_project.TeamId
  5517. }
  5518. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5519. types := int64(json["type"].(float64))
  5520. project.Type = types
  5521. }
  5522. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5523. project_id := int64(json["project_id"].(float64))
  5524. project.ProjectId = project_id
  5525. }
  5526. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5527. team_id := int64(json["team_id"].(float64))
  5528. project.TeamId = team_id
  5529. }
  5530. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5531. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5532. project.Price = price
  5533. }
  5534. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5535. total, _ := json["total"].(string)
  5536. //totals, _ := strconv.ParseInt(total, 10, 64)
  5537. project.Count = total
  5538. }
  5539. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5540. medical_code, _ := json["medical_code"].(string)
  5541. project.MedListCodg = medical_code
  5542. }
  5543. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5544. single_dose, _ := json["single_dose"].(string)
  5545. project.SingleDose = single_dose
  5546. }
  5547. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5548. delivery_way, _ := json["delivery_way"].(string)
  5549. project.DeliveryWay = delivery_way
  5550. }
  5551. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5552. execution_frequency, _ := json["execution_frequency"].(string)
  5553. project.ExecutionFrequency = execution_frequency
  5554. }
  5555. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5556. remark, _ := json["remark"].(string)
  5557. project.Remark = remark
  5558. }
  5559. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5560. day, _ := json["number_days"].(string)
  5561. project.Day = day
  5562. }
  5563. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5564. unit, _ := json["unit"].(string)
  5565. project.Unit = unit
  5566. }
  5567. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5568. // frequency_type := int64(json["frequency_type"].(float64))
  5569. // project.FrequencyType = frequency_type
  5570. //}
  5571. //
  5572. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5573. // day_count := int64(json["day_count"].(float64))
  5574. // project.DayCount = day_count
  5575. //}
  5576. //
  5577. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5578. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5579. // week_day, _ := json["week_day"].(string)
  5580. // project.WeekDay = week_day
  5581. //}
  5582. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5583. //
  5584. //if project.ID == 0 {
  5585. // if stockConfig.IsOpen == 1 {
  5586. // if project.Type == 3 {
  5587. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5588. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5589. // good.Total = good.Total - f_count
  5590. // service.UpdateGoodInfo(&good)
  5591. // }
  5592. // }
  5593. //
  5594. //} else {
  5595. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5596. //
  5597. // if stockConfig.IsOpen == 1 {
  5598. // if project.Type == 3 {
  5599. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5600. // if project.Count < temp_project.Count {
  5601. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5602. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5603. //
  5604. // other_count := f_count_two - f_count_one
  5605. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5606. // good.Total = good.Total + other_count_two
  5607. // service.UpdateGoodInfo(&good)
  5608. // } else if project.Count > temp_project.Count {
  5609. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5610. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5611. //
  5612. // other_count := f_count_one - f_count_two
  5613. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5614. // good.Total = good.Total - other_count_two
  5615. // service.UpdateGoodInfo(&good)
  5616. // }
  5617. //
  5618. // }
  5619. // }
  5620. //
  5621. //}
  5622. return 0
  5623. }
  5624. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5625. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5626. utils.ErrorLog("drug_name")
  5627. return enums.ErrorCodeParamWrong
  5628. }
  5629. adviceName, _ := json["drug_name"].(string)
  5630. if len(adviceName) == 0 {
  5631. utils.ErrorLog("len(advice_name) == 0")
  5632. return enums.ErrorCodeParamWrong
  5633. }
  5634. advice.AdviceName = adviceName
  5635. adviceDesc, _ := json["advice_desc"].(string)
  5636. advice.AdviceDesc = adviceDesc
  5637. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5638. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5639. advice.DrugSpec = drugSpec
  5640. }
  5641. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5642. remark, _ := json["remark"].(string)
  5643. advice.Remark = remark
  5644. }
  5645. if json["id"] == nil {
  5646. advice.DrugId = 0
  5647. } else {
  5648. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5649. drug_id := int64(json["id"].(float64))
  5650. advice.DrugId = drug_id
  5651. }
  5652. }
  5653. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5654. groupno := int64(json["groupno"].(float64))
  5655. advice.Groupno = groupno
  5656. }
  5657. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5658. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5659. advice.IsSelfDrug = is_self_drug
  5660. }
  5661. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5662. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5663. drug_way_count, _ := json["drug_way_count"].(string)
  5664. advice.DrugWayCount = drug_way_count
  5665. }
  5666. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5667. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5668. advice.HospApprFlag = hosp_appr_flag
  5669. }
  5670. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5671. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5672. advice.PrescribingNumber = prescribingNumber
  5673. }
  5674. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5675. // frequency_type := int64(json["frequency_type"].(float64))
  5676. // advice.FrequencyType = frequency_type
  5677. //}
  5678. //
  5679. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5680. // day_count := int64(json["day_count"].(float64))
  5681. // advice.DayCount = day_count
  5682. //}
  5683. //
  5684. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5685. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5686. // week_day, _ := json["week_day"].(string)
  5687. // advice.WeekDay = week_day
  5688. //}
  5689. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5690. drugSpecUnit, _ := json["min_unit"].(string)
  5691. advice.DrugSpecUnit = drugSpecUnit
  5692. }
  5693. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5694. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5695. advice.SingleDose = singleDose
  5696. }
  5697. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5698. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5699. advice.SingleDoseUnit = singleDoseUnit
  5700. }
  5701. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5702. deliveryWay, _ := json["delivery_way"].(string)
  5703. advice.DeliveryWay = deliveryWay
  5704. }
  5705. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5706. executionFrequency, _ := json["execution_frequency"].(string)
  5707. advice.ExecutionFrequency = executionFrequency
  5708. }
  5709. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5710. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5711. advice.Price = price
  5712. }
  5713. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5714. med_list_codg, _ := json["medical_insurance_number"].(string)
  5715. advice.MedListCodg = med_list_codg
  5716. }
  5717. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5718. day := int64(json["day"].(float64))
  5719. advice.Day = day
  5720. }
  5721. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5722. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5723. advice.PrescribingNumberUnit = prescribingNumberUnit
  5724. }
  5725. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5726. advice_id := int64(json["advice_id"].(float64))
  5727. advice.ID = advice_id
  5728. if advice.ID > 0 {
  5729. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5730. if err == nil {
  5731. if hisAdvice.ID > 0 {
  5732. advice.ExecutionTime = hisAdvice.ExecutionTime
  5733. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5734. advice.ExecutionState = hisAdvice.ExecutionState
  5735. advice.CheckTime = hisAdvice.CheckTime
  5736. advice.Checker = hisAdvice.Checker
  5737. advice.CheckState = hisAdvice.CheckState
  5738. advice.StartTime = hisAdvice.StartTime
  5739. advice.HospApprFlag = hisAdvice.HospApprFlag
  5740. advice.IsMedicine = hisAdvice.IsMedicine
  5741. if hisAdvice.UserOrgId == 10028 {
  5742. 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 {
  5743. advice.ExecutionTime = 0
  5744. advice.ExecutionStaff = 0
  5745. advice.ExecutionState = 2
  5746. advice.CheckTime = 0
  5747. advice.Checker = 0
  5748. advice.CheckState = 2
  5749. }
  5750. } else {
  5751. 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 {
  5752. advice.ExecutionTime = 0
  5753. advice.ExecutionStaff = 0
  5754. advice.ExecutionState = 2
  5755. advice.CheckTime = 0
  5756. advice.Checker = 0
  5757. advice.CheckState = 2
  5758. }
  5759. }
  5760. //advice.Groupno = hisAdvice.Groupno
  5761. }
  5762. }
  5763. }
  5764. }
  5765. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5766. //
  5767. //if drugStockConfig.IsOpen == 1 {
  5768. //
  5769. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5770. // if advice.ID == 0 { //医嘱不存在
  5771. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5772. // drug.Total = drug.Total - advice.PrescribingNumber
  5773. // service.UpdateBaseDrugLib(&drug)
  5774. //
  5775. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5776. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5777. // drug.Total = drug.Total - num
  5778. // service.UpdateBaseDrugLib(&drug)
  5779. // }
  5780. //
  5781. // } else if advice.ID > 0 { //医嘱存在
  5782. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5783. // var num float64
  5784. //
  5785. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5786. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5787. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5788. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5789. // drug.Total = drug.Total + num
  5790. // service.UpdateBaseDrugLib(&drug)
  5791. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5792. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5793. // drug.Total = drug.Total - num
  5794. // service.UpdateBaseDrugLib(&drug)
  5795. // }
  5796. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5797. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5798. // if num2 > advice.PrescribingNumber {
  5799. // num = num2 - advice.PrescribingNumber
  5800. // drug.Total = drug.Total + num
  5801. // service.UpdateBaseDrugLib(&drug)
  5802. // } else if num2 < advice.PrescribingNumber {
  5803. // num = advice.PrescribingNumber - num2
  5804. // drug.Total = drug.Total - num
  5805. // service.UpdateBaseDrugLib(&drug)
  5806. // }
  5807. //
  5808. // }
  5809. //
  5810. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5811. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5812. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5813. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5814. // if num1 > num2 {
  5815. // num = num1 - num2
  5816. // drug.Total = drug.Total + num
  5817. // service.UpdateBaseDrugLib(&drug)
  5818. // } else if num1 < num2 {
  5819. // num = num2 - num1
  5820. // drug.Total = drug.Total - num
  5821. // service.UpdateBaseDrugLib(&drug)
  5822. // }
  5823. //
  5824. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5825. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5826. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5827. // if hisAdvice.PrescribingNumber > num2 {
  5828. // num = hisAdvice.PrescribingNumber - num2
  5829. // drug.Total = drug.Total + num
  5830. // service.UpdateBaseDrugLib(&drug)
  5831. // } else if num2 < advice.PrescribingNumber {
  5832. // num = num2 - hisAdvice.PrescribingNumber
  5833. // drug.Total = drug.Total - num
  5834. // service.UpdateBaseDrugLib(&drug)
  5835. // }
  5836. //
  5837. // }
  5838. // }
  5839. // }
  5840. //}
  5841. //
  5842. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5843. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5844. // advice.ExecutionTime = execution_time
  5845. //}
  5846. //
  5847. //
  5848. //
  5849. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5850. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5851. // advice.ExecutionStaff = execution_staff
  5852. //}
  5853. //
  5854. //
  5855. //
  5856. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5857. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5858. // advice.ExecutionState = execution_state
  5859. //}
  5860. //
  5861. //
  5862. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5863. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5864. // advice.CheckTime = check_time
  5865. //}
  5866. //
  5867. //
  5868. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5869. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5870. // advice.CheckState = check_state
  5871. //}
  5872. //
  5873. //
  5874. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5875. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5876. // advice.Checker = checker
  5877. //}
  5878. //
  5879. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5880. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5881. // advice.StartTime = start_time
  5882. //}
  5883. return 0
  5884. }
  5885. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5886. project.ExecutionStaff = 0
  5887. project.ExecutionState = 2
  5888. project.ExecutionTime = 0
  5889. project.Checker = 0
  5890. project.CheckState = 2
  5891. project.CheckTime = 0
  5892. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5893. id := int64(json["id"].(float64))
  5894. project.ID = id
  5895. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5896. project.ExecutionStaff = temp_project.ExecutionStaff
  5897. project.ExecutionState = temp_project.ExecutionState
  5898. project.ExecutionTime = temp_project.ExecutionTime
  5899. project.Checker = temp_project.Checker
  5900. project.CheckState = temp_project.CheckState
  5901. project.CheckTime = temp_project.CheckTime
  5902. project.TeamId = temp_project.TeamId
  5903. }
  5904. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5905. types := int64(json["type"].(float64))
  5906. project.Type = types
  5907. }
  5908. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5909. project_id := int64(json["project_id"].(float64))
  5910. project.ProjectId = project_id
  5911. }
  5912. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5913. team_id := int64(json["team_id"].(float64))
  5914. project.TeamId = team_id
  5915. }
  5916. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5917. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5918. project.Price = price
  5919. }
  5920. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5921. total, _ := json["total"].(string)
  5922. //totals, _ := strconv.ParseInt(total, 10, 64)
  5923. project.Count = total
  5924. }
  5925. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5926. medical_code, _ := json["medical_code"].(string)
  5927. project.MedListCodg = medical_code
  5928. }
  5929. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5930. single_dose, _ := json["single_dose"].(string)
  5931. project.SingleDose = single_dose
  5932. }
  5933. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5934. delivery_way, _ := json["delivery_way"].(string)
  5935. project.DeliveryWay = delivery_way
  5936. }
  5937. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5938. execution_frequency, _ := json["execution_frequency"].(string)
  5939. project.ExecutionFrequency = execution_frequency
  5940. }
  5941. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5942. remark, _ := json["remark"].(string)
  5943. project.Remark = remark
  5944. }
  5945. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5946. day, _ := json["number_days"].(string)
  5947. project.Day = day
  5948. }
  5949. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5950. unit, _ := json["unit"].(string)
  5951. project.Unit = unit
  5952. }
  5953. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5954. // frequency_type := int64(json["frequency_type"].(float64))
  5955. // project.FrequencyType = frequency_type
  5956. //}
  5957. //
  5958. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5959. // day_count := int64(json["day_count"].(float64))
  5960. // project.DayCount = day_count
  5961. //}
  5962. //
  5963. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5964. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5965. // week_day, _ := json["week_day"].(string)
  5966. // project.WeekDay = week_day
  5967. //}
  5968. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5969. //
  5970. //if project.ID == 0 {
  5971. // if stockConfig.IsOpen == 1 {
  5972. // if project.Type == 3 {
  5973. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5974. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5975. // good.Total = good.Total - f_count
  5976. // service.UpdateGoodInfo(&good)
  5977. // }
  5978. // }
  5979. //
  5980. //} else {
  5981. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5982. //
  5983. // if stockConfig.IsOpen == 1 {
  5984. // if project.Type == 3 {
  5985. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5986. // if project.Count < temp_project.Count {
  5987. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5988. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5989. //
  5990. // other_count := f_count_two - f_count_one
  5991. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5992. // good.Total = good.Total + other_count_two
  5993. // service.UpdateGoodInfo(&good)
  5994. // } else if project.Count > temp_project.Count {
  5995. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5996. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5997. //
  5998. // other_count := f_count_one - f_count_two
  5999. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6000. // good.Total = good.Total - other_count_two
  6001. // service.UpdateGoodInfo(&good)
  6002. // }
  6003. //
  6004. // }
  6005. // }
  6006. //
  6007. //}
  6008. return 0
  6009. }
  6010. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6011. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6012. id := int64(json["id"].(float64))
  6013. additionalCharge.ID = id
  6014. }
  6015. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6016. item_id := int64(json["item_id"].(float64))
  6017. additionalCharge.ItemId = item_id
  6018. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6019. if config.ID > 0 {
  6020. if len(config.Code) > 0 {
  6021. additionalCharge.MedListCodg = config.Code
  6022. }
  6023. }
  6024. }
  6025. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6026. // price := int64(json["price"].(float64))
  6027. // formatInt_price := strconv.FormatInt(price, 10)
  6028. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6029. // additionalCharge.Price = float_price
  6030. // }
  6031. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6032. // price := int64(json["price"].(float64))
  6033. // formatInt_price := strconv.FormatInt(price, 10)
  6034. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6035. // additionalCharge.Price = float_price
  6036. //}
  6037. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6038. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6039. additionalCharge.Price = price
  6040. }
  6041. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6042. count, _ := json["count"].(string)
  6043. counts, _ := strconv.ParseInt(count, 10, 64)
  6044. additionalCharge.Count = counts
  6045. }
  6046. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6047. item_name, _ := json["item_name"].(string)
  6048. additionalCharge.ItemName = item_name
  6049. }
  6050. return 0
  6051. }
  6052. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6053. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6054. utils.ErrorLog("drug_name")
  6055. return enums.ErrorCodeParamWrong
  6056. }
  6057. adviceName, _ := json["drug_name"].(string)
  6058. if len(adviceName) == 0 {
  6059. utils.ErrorLog("len(advice_name) == 0")
  6060. return enums.ErrorCodeParamWrong
  6061. }
  6062. advice.AdviceName = adviceName
  6063. adviceDesc, _ := json["advice_desc"].(string)
  6064. advice.AdviceDesc = adviceDesc
  6065. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6066. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6067. advice.DrugSpec = drugSpec
  6068. }
  6069. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6070. remark, _ := json["remark"].(string)
  6071. advice.Remark = remark
  6072. }
  6073. if json["id"] == nil {
  6074. advice.DrugId = 0
  6075. } else {
  6076. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6077. drug_id := int64(json["id"].(float64))
  6078. advice.DrugId = drug_id
  6079. }
  6080. }
  6081. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6082. groupno := int64(json["groupno"].(float64))
  6083. advice.Groupno = groupno
  6084. }
  6085. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6086. drugSpecUnit, _ := json["min_unit"].(string)
  6087. advice.DrugSpecUnit = drugSpecUnit
  6088. }
  6089. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6090. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6091. advice.SingleDose = singleDose
  6092. }
  6093. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6094. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6095. advice.SingleDoseUnit = singleDoseUnit
  6096. }
  6097. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6098. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6099. advice.PrescribingNumber = prescribingNumber
  6100. }
  6101. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6102. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6103. advice.PrescribingNumberUnit = prescribingNumberUnit
  6104. }
  6105. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6106. deliveryWay, _ := json["delivery_way"].(string)
  6107. advice.DeliveryWay = deliveryWay
  6108. }
  6109. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6110. executionFrequency, _ := json["execution_frequency"].(string)
  6111. advice.ExecutionFrequency = executionFrequency
  6112. }
  6113. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6114. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6115. advice.Price = price
  6116. }
  6117. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6118. med_list_codg, _ := json["medical_insurance_number"].(string)
  6119. advice.MedListCodg = med_list_codg
  6120. }
  6121. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6122. day := int64(json["day"].(float64))
  6123. advice.Day = day
  6124. }
  6125. advice.FrequencyType = 1
  6126. return 0
  6127. }
  6128. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  6129. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6130. types := int64(json["type"].(float64))
  6131. project.Type = types
  6132. }
  6133. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6134. project_id := int64(json["project_id"].(float64))
  6135. project.ProjectId = project_id
  6136. }
  6137. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6138. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6139. project.Price = price
  6140. }
  6141. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6142. total, _ := json["total"].(string)
  6143. //totals, _ := strconv.ParseInt(total, 10, 64)
  6144. project.Count = total
  6145. }
  6146. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6147. medical_code, _ := json["medical_code"].(string)
  6148. project.MedListCodg = medical_code
  6149. }
  6150. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6151. single_dose, _ := json["single_dose"].(string)
  6152. project.SingleDose = single_dose
  6153. }
  6154. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6155. delivery_way, _ := json["delivery_way"].(string)
  6156. project.DeliveryWay = delivery_way
  6157. }
  6158. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6159. execution_frequency, _ := json["execution_frequency"].(string)
  6160. project.ExecutionFrequency = execution_frequency
  6161. }
  6162. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6163. remark, _ := json["remark"].(string)
  6164. project.Remark = remark
  6165. }
  6166. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6167. day, _ := json["number_days"].(string)
  6168. project.Day = day
  6169. }
  6170. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6171. unit, _ := json["unit"].(string)
  6172. project.Unit = unit
  6173. }
  6174. project.FrequencyType = 1
  6175. return 0
  6176. }
  6177. func (c *HisApiController) GetHisOrderListTwo() {
  6178. start_time := c.GetString("start_time")
  6179. end_time := c.GetString("end_time")
  6180. timeLayout := "2006-01-02"
  6181. loc, _ := time.LoadLocation("Local")
  6182. var startTime int64
  6183. if len(start_time) > 0 {
  6184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6185. if err != nil {
  6186. //fmt.Println(err)
  6187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6188. return
  6189. }
  6190. startTime = theTime.Unix()
  6191. }
  6192. var endTime int64
  6193. if len(end_time) > 0 {
  6194. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6195. if err != nil {
  6196. utils.ErrorLog(err.Error())
  6197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6198. return
  6199. }
  6200. endTime = theTime.Unix()
  6201. }
  6202. adminUser := c.GetAdminUserInfo()
  6203. org_id := adminUser.CurrentOrgId
  6204. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  6205. if err == nil {
  6206. c.ServeSuccessJSON(map[string]interface{}{
  6207. "order2": order,
  6208. })
  6209. } else {
  6210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6211. return
  6212. }
  6213. }
  6214. func (c *HisApiController) GetHisOrderList() {
  6215. page, _ := c.GetInt64("page", -1)
  6216. limit, _ := c.GetInt64("limit", -1)
  6217. start_time := c.GetString("start_time")
  6218. end_time := c.GetString("end_time")
  6219. types, _ := c.GetInt64("type", 0)
  6220. keywords := c.GetString("keywords")
  6221. p_type, _ := c.GetInt64("p_type", 0)
  6222. sort_type, _ := c.GetInt64("sort_type", 0)
  6223. charge_type, _ := c.GetInt64("charge_type", 0)
  6224. sch_type, _ := c.GetInt64("sch_type", 0)
  6225. zone_type, _ := c.GetInt64("zone_type", 0)
  6226. med_type, _ := c.GetInt64("med_type", 0)
  6227. timeLayout := "2006-01-02"
  6228. loc, _ := time.LoadLocation("Local")
  6229. var startTime int64
  6230. if len(start_time) > 0 {
  6231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6232. if err != nil {
  6233. //fmt.Println(err)
  6234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6235. return
  6236. }
  6237. startTime = theTime.Unix()
  6238. }
  6239. var endTime int64
  6240. if len(end_time) > 0 {
  6241. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6242. if err != nil {
  6243. utils.ErrorLog(err.Error())
  6244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6245. return
  6246. }
  6247. endTime = theTime.Unix()
  6248. }
  6249. adminUser := c.GetAdminUserInfo()
  6250. org_id := adminUser.CurrentOrgId
  6251. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  6252. for _, item := range order {
  6253. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  6254. item.DoctorName = info.Doctor
  6255. item.DepartmentName = info.XtHisDepartment.Name
  6256. }
  6257. if err == nil {
  6258. c.ServeSuccessJSON(map[string]interface{}{
  6259. "order": order,
  6260. "total": total,
  6261. })
  6262. } else {
  6263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6264. return
  6265. }
  6266. }
  6267. func (c *HisApiController) GetHisOrder() {
  6268. patient_id, _ := c.GetInt64("patient_id", 0)
  6269. number := c.GetString("number")
  6270. adminInfo := c.GetAdminUserInfo()
  6271. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  6272. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  6273. if err == nil {
  6274. c.ServeSuccessJSON(map[string]interface{}{
  6275. "order": order,
  6276. "prescription": prescriptions,
  6277. })
  6278. } else {
  6279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6280. return
  6281. }
  6282. }
  6283. func (c *HisApiController) GetHisPrescriptionList() {
  6284. record_date := c.GetString("record_date")
  6285. keywords := c.GetString("keywords")
  6286. page, _ := c.GetInt64("page")
  6287. limit, _ := c.GetInt64("limit")
  6288. sch_type, _ := c.GetInt64("sch_type")
  6289. timeLayout := "2006-01-02"
  6290. loc, _ := time.LoadLocation("Local")
  6291. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6292. if err != nil {
  6293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6294. return
  6295. }
  6296. recordDateTime := theTime.Unix()
  6297. adminInfo := c.GetAdminUserInfo()
  6298. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  6299. //adminInfo := c.GetAdminUserInfo()
  6300. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  6301. //fmt.Println(prescriptionOrder)
  6302. if err == nil {
  6303. c.ServeSuccessJSON(map[string]interface{}{
  6304. "order": prescriptionOrder,
  6305. "total": total,
  6306. })
  6307. } else {
  6308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6309. return
  6310. }
  6311. }
  6312. func (c *HisApiController) GetHisPrescriptionInfo() {
  6313. id, _ := c.GetInt64("id")
  6314. adminInfo := c.GetAdminUserInfo()
  6315. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  6316. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  6317. if err == nil {
  6318. c.ServeSuccessJSON(map[string]interface{}{
  6319. "order": prescriptionOrder,
  6320. "prescription": prescription,
  6321. })
  6322. } else {
  6323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6324. return
  6325. }
  6326. }
  6327. func (c *HisApiController) GetMedicalInsuranceConfig() {
  6328. adminUser := c.GetAdminUserInfo()
  6329. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  6330. c.ServeSuccessJSON(map[string]interface{}{
  6331. "config": config,
  6332. })
  6333. }
  6334. type ResultTwo struct {
  6335. ErrMsg interface{} `json:"err_msg"`
  6336. InfRefmsgid string `json:"inf_refmsgid"`
  6337. Infcode int64 `json:"infcode"`
  6338. Output struct {
  6339. Baseinfo struct {
  6340. Age float64 `json:"age"`
  6341. Brdy string `json:"brdy"`
  6342. Certno string `json:"certno"`
  6343. Gend string `json:"gend"`
  6344. Naty string `json:"naty"`
  6345. PsnCertType string `json:"psn_cert_type"`
  6346. PsnName string `json:"psn_name"`
  6347. PsnNo string `json:"psn_no"`
  6348. } `json:"baseinfo"`
  6349. Idetinfo []interface{} `json:"idetinfo"`
  6350. Iinfo []struct {
  6351. Balc float64 `json:"balc"`
  6352. CvlservFlag string `json:"cvlserv_flag"`
  6353. EmpName string `json:"emp_name"`
  6354. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  6355. Insutype string `json:"insutype"`
  6356. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  6357. PausInsuDate interface{} `json:"paus_insu_date"`
  6358. PsnInsuDate string `json:"psn_insu_date"`
  6359. PsnInsuStas string `json:"psn_insu_stas"`
  6360. PsnType string `json:"psn_type"`
  6361. } `json:"insuinfo"`
  6362. } `json:"output"`
  6363. RefmsgTime string `json:"refmsg_time"`
  6364. RespondTime string `json:"respond_time"`
  6365. Signtype interface{} `json:"signtype"`
  6366. WarnInfo interface{} `json:"warn_info"`
  6367. }
  6368. type ResultThree struct {
  6369. Cainfo interface{} `json:"cainfo"`
  6370. ErrMsg interface{} `json:"err_msg"`
  6371. InfRefmsgid string `json:"inf_refmsgid"`
  6372. Infcode int64 `json:"infcode"`
  6373. Output struct {
  6374. Data struct {
  6375. IptOtpNo string `json:"ipt_otp_no"`
  6376. MdtrtID string `json:"mdtrt_id"`
  6377. PsnNo string `json:"psn_no"`
  6378. } `json:"data"`
  6379. } `json:"output"`
  6380. RefmsgTime string `json:"refmsg_time"`
  6381. RespondTime string `json:"respond_time"`
  6382. Signtype interface{} `json:"signtype"`
  6383. WarnMsg interface{} `json:"warn_msg"`
  6384. }
  6385. type ResultFour struct {
  6386. Cainfo string `json:"cainfo"`
  6387. ErrMsg string `json:"err_msg"`
  6388. InfRefmsgid string `json:"inf_refmsgid"`
  6389. Infcode int64 `json:"infcode"`
  6390. Output struct {
  6391. Result []struct {
  6392. BasMednFlag string `json:"bas_medn_flag"`
  6393. ChldMedcFlag string `json:"chld_medc_flag"`
  6394. ChrgitmLv string `json:"chrgitm_lv"`
  6395. Cnt float64 `json:"cnt"`
  6396. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  6397. DrtReimFlag string `json:"drt_reim_flag"`
  6398. FeedetlSn string `json:"feedetl_sn"`
  6399. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6400. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  6401. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6402. ListSpItemFlag string `json:"list_sp_item_flag"`
  6403. LmtUsedFlag string `json:"lmt_used_flag"`
  6404. MedChrgitmType string `json:"med_chrgitm_type"`
  6405. Memo string `json:"memo"`
  6406. OverlmtAmt float64 `json:"overlmt_amt"`
  6407. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6408. Pric float64 `json:"pric"`
  6409. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  6410. SelfpayProp float64 `json:"selfpay_prop"`
  6411. } `json:"result"`
  6412. } `json:"output"`
  6413. RefmsgTime string `json:"refmsg_time"`
  6414. RespondTime string `json:"respond_time"`
  6415. Signtype string `json:"signtype"`
  6416. WarnMsg string `json:"warn_msg"`
  6417. }
  6418. type ResultFive struct {
  6419. Insutype string `json:"insutype"`
  6420. }
  6421. type ResultSix struct {
  6422. Cainfo interface{} `json:"cainfo"`
  6423. ErrMsg interface{} `json:"err_msg"`
  6424. InfRefmsgid string `json:"inf_refmsgid"`
  6425. Infcode int64 `json:"infcode"`
  6426. Output struct {
  6427. } `json:"output"`
  6428. RefmsgTime string `json:"refmsg_time"`
  6429. RespondTime string `json:"respond_time"`
  6430. Signtype interface{} `json:"signtype"`
  6431. WarnMsg interface{} `json:"warn_msg"`
  6432. }
  6433. type ResultSeven struct {
  6434. Cainfo string `json:"cainfo"`
  6435. ErrMsg string `json:"err_msg"`
  6436. InfRefmsgid string `json:"inf_refmsgid"`
  6437. Infcode int64 `json:"infcode"`
  6438. Output struct {
  6439. Setldetail []interface{} `json:"setldetail"`
  6440. Setlinfo struct {
  6441. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6442. AcctPay float64 `json:"acct_pay"`
  6443. ActPayDedc float64 `json:"act_pay_dedc"`
  6444. Age float64 `json:"age"`
  6445. Balc float64 `json:"balc"`
  6446. Brdy string `json:"brdy"`
  6447. Certno string `json:"certno"`
  6448. ClrOptins string `json:"clr_optins"`
  6449. ClrType string `json:"clr_type"`
  6450. ClrWay string `json:"clr_way"`
  6451. CvlservFlag string `json:"cvlserv_flag"`
  6452. CvlservPay float64 `json:"cvlserv_pay"`
  6453. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6454. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6455. Gend string `json:"gend"`
  6456. HifesPay float64 `json:"hifes_pay"`
  6457. HifmiPay float64 `json:"hifmi_pay"`
  6458. HifobPay float64 `json:"hifob_pay"`
  6459. HifpPay float64 `json:"hifp_pay"`
  6460. HospPartAmt float64 `json:"hosp_part_amt"`
  6461. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6462. Insutype string `json:"insutype"`
  6463. MafPay float64 `json:"maf_pay"`
  6464. MdtrtCertType string `json:"mdtrt_cert_type"`
  6465. MdtrtID string `json:"mdtrt_id"`
  6466. MedType string `json:"med_type"`
  6467. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6468. MedinsSetlID string `json:"medins_setl_id"`
  6469. Naty string `json:"naty"`
  6470. OthPay float64 `json:"oth_pay"`
  6471. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6472. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6473. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6474. PsnCashPay float64 `json:"psn_cash_pay"`
  6475. PsnCertType string `json:"psn_cert_type"`
  6476. PsnName string `json:"psn_name"`
  6477. PsnNo string `json:"psn_no"`
  6478. PsnPartAmt float64 `json:"psn_part_amt"`
  6479. PsnType string `json:"psn_type"`
  6480. SetlID string `json:"setl_id"`
  6481. SetlTime string `json:"setl_time"`
  6482. } `json:"setlinfo"`
  6483. } `json:"output"`
  6484. RefmsgTime string `json:"refmsg_time"`
  6485. RespondTime string `json:"respond_time"`
  6486. Signtype interface{} `json:"signtype"`
  6487. WarnMsg interface{} `json:"warn_msg"`
  6488. }
  6489. type ResultEight struct {
  6490. Cainfo string `json:"cainfo"`
  6491. ErrMsg string `json:"err_msg"`
  6492. InfRefmsgid string `json:"inf_refmsgid"`
  6493. Infcode int64 `json:"infcode"`
  6494. Output struct {
  6495. Stmtinfo struct {
  6496. SetlOptins string `json:"setl_optins"`
  6497. StmtRslt string `json:"stmt_rslt"`
  6498. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6499. } `json:"stmtinfo"`
  6500. } `json:"output"`
  6501. RefmsgTime string `json:"refmsg_time"`
  6502. RespondTime string `json:"respond_time"`
  6503. Signtype interface{} `json:"signtype"`
  6504. WarnMsg interface{} `json:"warn_msg"`
  6505. }
  6506. type ResultNine struct {
  6507. Cainfo string `json:"cainfo"`
  6508. ErrMsg string `json:"err_msg"`
  6509. InfRefmsgid string `json:"inf_refmsgid"`
  6510. Infcode int64 `json:"infcode"`
  6511. Output struct {
  6512. FileQuryNo string `json:"file_qury_no"`
  6513. } `json:"output"`
  6514. RefmsgTime string `json:"refmsg_time"`
  6515. RespondTime string `json:"respond_time"`
  6516. Signtype interface{} `json:"signtype"`
  6517. WarnMsg interface{} `json:"warn_msg"`
  6518. }
  6519. type ResultTen struct {
  6520. Cainfo string `json:"cainfo"`
  6521. ErrMsg string `json:"err_msg"`
  6522. InfRefmsgid string `json:"inf_refmsgid"`
  6523. Infcode int64 `json:"infcode"`
  6524. Output struct {
  6525. DldEndtime string `json:"dld_endtime"`
  6526. FileQuryNo string `json:"file_qury_no"`
  6527. Filename string `json:"filename"`
  6528. } `json:"output"`
  6529. RefmsgTime string `json:"refmsg_time"`
  6530. RespondTime string `json:"respond_time"`
  6531. Signtype interface{} `json:"signtype"`
  6532. WarnMsg interface{} `json:"warn_msg"`
  6533. }
  6534. type ResultEleven struct {
  6535. Cainfo string `json:"cainfo"`
  6536. ErrMsg string `json:"err_msg"`
  6537. InfRefmsgid string `json:"inf_refmsgid"`
  6538. Infcode int64 `json:"infcode"`
  6539. Output struct {
  6540. Setlinfo struct {
  6541. FixmedinsName string `json:"fixmedins_name"`
  6542. FixmedinsCode string `json:"fixmedins_code"`
  6543. PsnNo string `json:"psn_no"`
  6544. PsnName string `json:"psn_name"`
  6545. HifobPay float64 `json:"hifob_pay"`
  6546. Gend string `json:"gend"`
  6547. Brdy string `json:"brdy"`
  6548. PsnCertType string `json:"psn_cert_type"`
  6549. PsnType string `json:"psn_type"`
  6550. EmpName string `json:"emp_name"`
  6551. Certno string `json:"certno"`
  6552. Insutype string `json:"insutype"`
  6553. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6554. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6555. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6556. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6557. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6558. ActPayDedc float64 `json:"act_pay_dedc"`
  6559. HifpPay float64 `json:"hifp_pay"`
  6560. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6561. CvlservPay float64 `json:"cvlserv_pay"`
  6562. HifesPay float64 `json:"hifes_pay"`
  6563. HifmiPay float64 `json:"hifmi_pay"`
  6564. MafPay float64 `json:"maf_pay"`
  6565. OthPay float64 `json:"oth_pay"`
  6566. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6567. PsnPay float64 `json:"psn_pay"`
  6568. AcctPay float64 `json:"acct_pay"`
  6569. CashPayamt float64 `json:"cash_payamt"`
  6570. Balc float64 `json:"balc"`
  6571. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6572. MedinsSetlId string `json:"medins_setl_id"`
  6573. RefdSetlFlag string `json:"refd_setl_flag"`
  6574. SetlTime string `json:"setl_time"`
  6575. MedType string `json:"med_type"`
  6576. } `json:"setlinfo"`
  6577. } `json:"output"`
  6578. RefmsgTime string `json:"refmsg_time"`
  6579. RespondTime string `json:"respond_time"`
  6580. Signtype interface{} `json:"signtype"`
  6581. WarnMsg interface{} `json:"warn_msg"`
  6582. }
  6583. type Custom struct {
  6584. DetItemFeeSumamt string
  6585. Cut string
  6586. FeedetlSn string
  6587. Price string
  6588. MedListCodg string
  6589. Type int64
  6590. AdviceId int64
  6591. ProjectId int64
  6592. ItemId int64
  6593. }
  6594. // 获取个人信息----挂号-----上传就诊信息
  6595. func (c *HisApiController) GetRegisterInfo() {
  6596. id, _ := c.GetInt64("id")
  6597. record_time := c.GetString("record_time")
  6598. settlementValue, _ := c.GetInt64("settlement_value")
  6599. medical_insurance_card := c.GetString("medical_insurance_card")
  6600. name := c.GetString("name")
  6601. id_card_type, _ := c.GetInt64("id_card_type")
  6602. certificates, _ := c.GetInt64("certificates")
  6603. medical_care, _ := c.GetInt64("medical_care")
  6604. birthday := c.GetString("birthday")
  6605. age, _ := c.GetInt64("age")
  6606. id_card := c.GetString("id_card")
  6607. register_type, _ := c.GetInt64("register")
  6608. doctor, _ := c.GetInt64("doctor")
  6609. department, _ := c.GetInt64("department")
  6610. gender, _ := c.GetInt64("sex")
  6611. phone := c.GetString("phone")
  6612. registration_fee, _ := c.GetFloat("registration_fee")
  6613. medical_expenses, _ := c.GetFloat("medical_expenses")
  6614. social_type, _ := c.GetInt64("social_type")
  6615. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6616. diagnosis_ids := c.GetString("diagnosis")
  6617. sick_type, _ := c.GetInt64("sick_type")
  6618. reg_type := c.GetString("p_type")
  6619. timeLayout := "2006-01-02"
  6620. loc, _ := time.LoadLocation("Local")
  6621. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6622. birthUnix := birthdays.Unix()
  6623. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6624. if err != nil {
  6625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6626. return
  6627. }
  6628. recordDateTime := theTime.Unix()
  6629. adminInfo := c.GetAdminUserInfo()
  6630. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6631. if tempPatient.ID == 0 {
  6632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6633. return
  6634. }
  6635. var patient service.Patients
  6636. if id == 0 {
  6637. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6638. } else {
  6639. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6640. }
  6641. if patient.ID == 0 {
  6642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6643. return
  6644. }
  6645. if len(patient.IdCardNo) == 0 {
  6646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6647. return
  6648. }
  6649. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6650. if len(his) >= 1 {
  6651. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6652. if len(his) >= 1 && order.ID == 0 {
  6653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6654. return
  6655. }
  6656. }
  6657. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6658. fmt.Println(timeStr)
  6659. timeArr := strings.Split(timeStr, " ")
  6660. fmt.Println(timeArr)
  6661. timeArrTwo := strings.Split(timeArr[0], "-")
  6662. timeArrThree := strings.Split(timeArr[1], ":")
  6663. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6664. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6665. if len(lists) == 0 {
  6666. var hisPatient models.XtHisPatient
  6667. hisPatient = models.XtHisPatient{
  6668. Name: name,
  6669. Age: age,
  6670. Gender: gender,
  6671. Birthday: birthUnix,
  6672. Phone: phone,
  6673. MedicalTreatmentType: medical_care,
  6674. IdType: certificates,
  6675. IdCardNo: id_card,
  6676. BalanceAccountsType: settlementValue,
  6677. SocialType: social_type,
  6678. MedicalInsuranceNumber: medical_insurance_card,
  6679. RegisterType: register_type,
  6680. RegisterCost: registration_fee,
  6681. TreatmentCost: medical_expenses,
  6682. AdminUserId: adminInfo.AdminUser.Id,
  6683. UserOrgId: adminInfo.CurrentOrgId,
  6684. Status: 1,
  6685. RecordDate: recordDateTime,
  6686. IsReturn: 1,
  6687. PatientId: patient.ID,
  6688. Ctime: time.Now().Unix(),
  6689. Mtime: time.Now().Unix(),
  6690. Number: str,
  6691. IdCardType: id_card_type,
  6692. Departments: department,
  6693. Doctor: doctor,
  6694. PType: reg_type,
  6695. Diagnosis: diagnosis_ids,
  6696. SickType: sick_type,
  6697. }
  6698. service.CreateHisPatient(&hisPatient)
  6699. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6700. c.ServeSuccessJSON(map[string]interface{}{
  6701. "his_info": hisPatient,
  6702. })
  6703. } else {
  6704. //chrgBchno := rand.Intn(1000000) + 10000
  6705. var hisPatient models.XtHisPatient
  6706. hisPatient = models.XtHisPatient{
  6707. Name: name,
  6708. Age: age,
  6709. Gender: gender,
  6710. Birthday: birthUnix,
  6711. Phone: phone,
  6712. MedicalTreatmentType: medical_care,
  6713. IdType: certificates,
  6714. IdCardNo: id_card,
  6715. BalanceAccountsType: settlementValue,
  6716. SocialType: social_type,
  6717. MedicalInsuranceNumber: medical_insurance_card,
  6718. RegisterType: register_type,
  6719. RegisterCost: registration_fee,
  6720. TreatmentCost: medical_expenses,
  6721. AdminUserId: adminInfo.AdminUser.Id,
  6722. UserOrgId: adminInfo.CurrentOrgId,
  6723. Status: 1,
  6724. RecordDate: recordDateTime,
  6725. IsReturn: 1,
  6726. PatientId: patient.ID,
  6727. Ctime: time.Now().Unix(),
  6728. Mtime: time.Now().Unix(),
  6729. Number: str,
  6730. IdCardType: id_card_type,
  6731. Departments: department,
  6732. Doctor: doctor,
  6733. PType: reg_type,
  6734. Diagnosis: diagnosis_ids,
  6735. SickType: sick_type,
  6736. }
  6737. service.CreateHisPatient(&hisPatient)
  6738. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6739. c.ServeSuccessJSON(map[string]interface{}{
  6740. "his_info": hisPatient,
  6741. })
  6742. }
  6743. }
  6744. // 上传明细----结算
  6745. func (c *HisApiController) GetUploadInfo() {
  6746. id, _ := c.GetInt64("id")
  6747. record_time := c.GetString("record_time")
  6748. his_patient_id, _ := c.GetInt64("his_patient_id")
  6749. oth_desc := c.GetString("oth_desc")
  6750. pay_way, _ := c.GetInt64("pay_way")
  6751. pay_ways := c.GetString("pay_ways")
  6752. pay_price, _ := c.GetFloat("pay_price")
  6753. pay_card_no := c.GetString("pay_card_no")
  6754. discount_price, _ := c.GetFloat("discount_price")
  6755. preferential_price, _ := c.GetFloat("preferential_price")
  6756. reality_price, _ := c.GetFloat("reality_price")
  6757. found_price, _ := c.GetFloat("found_price")
  6758. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6759. private_price, _ := c.GetFloat("private_price")
  6760. timeLayout := "2006-01-02"
  6761. loc, _ := time.LoadLocation("Local")
  6762. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6763. fapiao_code := c.GetString("fapiao_code")
  6764. fapiao_number := c.GetString("fapiao_number")
  6765. diagnosis_id := c.GetString("diagnosis")
  6766. sick_type, _ := c.GetInt64("sick_type")
  6767. reg_type, _ := c.GetInt64("p_type")
  6768. order_id, _ := c.GetInt64("order_id")
  6769. cash_pay := c.GetString("cash_pay")
  6770. wechat_pay := c.GetString("wechat_pay")
  6771. ali_pay := c.GetString("ali_pay")
  6772. jifen_pay := c.GetString("jifen_pay")
  6773. band_card_pay := c.GetString("band_card_pay")
  6774. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6775. tmp_decimal := c.GetString("tmp_decimal")
  6776. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6777. var decimal float64 //本次使用的押金
  6778. var errmsg error
  6779. tx := service.XTWriteDB().Begin() //开了事务
  6780. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6781. defer func() {
  6782. if errmsg != nil {
  6783. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6784. tx.Rollback()
  6785. } else {
  6786. tx.Commit()
  6787. }
  6788. }()
  6789. fmt.Println("dec_way", dec_way)
  6790. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6791. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6792. return
  6793. }
  6794. if len(tmp_decimal) > 0 {
  6795. if tmp_decimal[0] == 45 {
  6796. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6797. return
  6798. }
  6799. }
  6800. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6801. fmt.Println(errs)
  6802. decimal = tt
  6803. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6804. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6805. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6806. if err != nil {
  6807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6808. return
  6809. }
  6810. recordDateTime := theTime.Unix()
  6811. adminUser := c.GetAdminUserInfo()
  6812. var prescriptions []*models.HisPrescription
  6813. var prescriptionsOne []*models.HisPrescription
  6814. var start_time int64
  6815. var end_time int64
  6816. ids_str := c.GetString("ids")
  6817. ids_arr := strings.Split(ids_str, ",")
  6818. if tempOrder.ID == 0 {
  6819. if settle_accounts_type == 1 { //日结
  6820. fmt.Println(reg_type)
  6821. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6822. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6823. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6824. } else {
  6825. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6826. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6827. }
  6828. } else { //月结
  6829. start_time_str := c.GetString("start_time")
  6830. end_time_str := c.GetString("end_time")
  6831. timeLayout := "2006-01-02"
  6832. loc, _ := time.LoadLocation("Local")
  6833. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6834. if err != nil {
  6835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6836. return
  6837. }
  6838. recordStartTime := theStartTime.Unix()
  6839. start_time = recordStartTime
  6840. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6841. if err != nil {
  6842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6843. return
  6844. }
  6845. recordEndTime := theEndTime.Unix()
  6846. end_time = recordEndTime
  6847. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6848. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6849. }
  6850. var goods []*models.DialysisBeforePrepareGoods
  6851. var newGoods []*models.NewDialysisBeforePrepareGoods
  6852. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6853. var infos []*models.HisDoctorAdviceInfo
  6854. var infoList []*models.HisDoctorAdviceInfo
  6855. var hisAdvice []*models.HisDoctorAdviceInfo
  6856. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6857. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6858. //判断库存不足
  6859. //结算出库开关
  6860. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6861. if settConfig.IsOpen == 1 {
  6862. //判断库存的地方
  6863. for _, info := range prescriptions {
  6864. if info.Type == 1 {
  6865. infos = append(infos, info.HisDoctorAdviceInfo...)
  6866. }
  6867. if info.Type == 2 {
  6868. for _, sumItem := range info.HisPrescriptionProject {
  6869. if sumItem.Type == 3 {
  6870. var good models.DialysisBeforePrepareGoods
  6871. var newGood models.NewDialysisBeforePrepareGoods
  6872. good.GoodId = sumItem.GoodInfo.ID
  6873. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6874. count, _ := strconv.Atoi(sumItem.Count)
  6875. good.Count = int64(count)
  6876. good.StorehouseId = houseConfig.StorehouseOutInfo
  6877. good.ProjectId = sumItem.ID
  6878. goods = append(goods, &good)
  6879. newGood.GoodId = sumItem.GoodInfo.ID
  6880. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6881. count2, _ := strconv.Atoi(sumItem.Count)
  6882. newGood.Count = int64(count2)
  6883. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6884. newGood.ProjectId = sumItem.ID
  6885. newGoods = append(newGoods, &newGood)
  6886. }
  6887. }
  6888. }
  6889. }
  6890. for _, info := range prescriptionsOne {
  6891. if info.Type == 1 {
  6892. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6893. }
  6894. if info.Type == 2 {
  6895. for _, sumItem := range info.HisPrescriptionProject {
  6896. if sumItem.Type == 3 {
  6897. var newGood models.NewDialysisBeforePrepareGoods
  6898. newGood.GoodId = sumItem.GoodInfo.ID
  6899. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6900. count2, _ := strconv.Atoi(sumItem.Count)
  6901. newGood.Count = int64(count2)
  6902. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6903. newGood.ProjectId = sumItem.ID
  6904. newGoodOne = append(newGoodOne, &newGood)
  6905. }
  6906. }
  6907. }
  6908. }
  6909. //判断
  6910. for _, itemOne := range infos {
  6911. for _, itemTwo := range hisAdvice {
  6912. if itemOne.DrugId == itemTwo.DrugId {
  6913. itemTwo.Child = append(itemTwo.Child, itemOne)
  6914. }
  6915. }
  6916. }
  6917. for _, itemTwo := range hisAdvice {
  6918. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6919. var sum_out_count int64
  6920. for _, itemThree := range itemTwo.Child {
  6921. var prescribing_number int64
  6922. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6923. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6924. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6925. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6926. }
  6927. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6928. prescribing_number = parseIntPrescribingNumber
  6929. }
  6930. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6931. prescribing_number = parseIntPrescribingNumber
  6932. }
  6933. sum_out_count += prescribing_number
  6934. }
  6935. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6936. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6937. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6938. if sum_out_count > drugStockOut.FlushCount {
  6939. c.ServeSuccessJSON(map[string]interface{}{
  6940. "msg": "2",
  6941. "drug": medical,
  6942. })
  6943. return
  6944. }
  6945. }
  6946. fmt.Println("newGoods99999988882os", newGoods)
  6947. for _, itemOne := range newGoods {
  6948. for _, item := range newGoodOne {
  6949. if itemOne.GoodId == item.GoodId {
  6950. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6951. }
  6952. }
  6953. }
  6954. for _, item := range newGoodOne {
  6955. var sum_out_count_one int64
  6956. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6957. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6958. sum_out_count_one += itemOne.Count
  6959. }
  6960. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6961. fmt.Println("sum_out_count_one", sum_out_count_one)
  6962. fmt.Println("list.FlushCount", list.FlushCount)
  6963. if sum_out_count_one > list.FlushCount {
  6964. c.ServeSuccessJSON(map[string]interface{}{
  6965. "msg": "3",
  6966. "good": good,
  6967. })
  6968. return
  6969. }
  6970. }
  6971. }
  6972. timestamp := time.Now().Unix()
  6973. tempTime := time.Unix(timestamp, 0)
  6974. timeFormat := tempTime.Format("20060102150405")
  6975. chrgBchno := rand.Intn(100000) + 10000
  6976. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6977. strconv.FormatInt(his.PatientId, 10)
  6978. var ids []int64
  6979. for _, item := range prescriptions {
  6980. ids = append(ids, item.ID)
  6981. }
  6982. var total float64
  6983. for _, item := range prescriptions {
  6984. fmt.Println(item)
  6985. if item.Type == 1 { //药品
  6986. for _, subItem := range item.HisDoctorAdviceInfo {
  6987. total = total + (subItem.Price * subItem.PrescribingNumber)
  6988. }
  6989. }
  6990. if item.Type == 2 { //项目
  6991. for _, subItem := range item.HisPrescriptionProject {
  6992. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6993. total = total + (subItem.Price * cnt)
  6994. }
  6995. }
  6996. for _, subItem := range item.HisAdditionalCharge {
  6997. total = total + (subItem.Price * float64(subItem.Count))
  6998. }
  6999. }
  7000. if reg_type == 1111 || reg_type == 1112 {
  7001. reg_type = 11
  7002. }
  7003. tm := time.Unix(time.Now().Unix(), 0)
  7004. allTotal := fmt.Sprintf("%.4f", total)
  7005. totals, _ := strconv.ParseFloat(allTotal, 64)
  7006. order := &models.HisOrder{
  7007. UserOrgId: adminUser.CurrentOrgId,
  7008. HisPatientId: his.ID,
  7009. PatientId: id,
  7010. SettleAccountsDate: recordDateTime,
  7011. Ctime: time.Now().Unix(),
  7012. Mtime: time.Now().Unix(),
  7013. Status: 1,
  7014. OrderStatus: 2,
  7015. MdtrtId: his.Number,
  7016. Number: chrg_bchno,
  7017. MedfeeSumamt: totals,
  7018. PayWay: pay_way,
  7019. PayWays: pay_ways,
  7020. PayPrice: pay_price,
  7021. MedType: strconv.Itoa(int(reg_type)),
  7022. PayCardNo: pay_card_no,
  7023. DiscountPrice: discount_price,
  7024. PreferentialPrice: preferential_price,
  7025. RealityPrice: reality_price,
  7026. FoundPrice: found_price,
  7027. MedicalInsurancePrice: medical_insurance_price,
  7028. PrivatePrice: private_price,
  7029. SettleEndTime: end_time,
  7030. SettleStartTime: start_time,
  7031. PsnPartAmt: totals,
  7032. PsnCashPay: totals,
  7033. SettleType: settle_accounts_type,
  7034. FaPiaoCode: fapiao_code,
  7035. FaPiaoNumber: fapiao_number,
  7036. Diagnosis: diagnosis_id,
  7037. PType: 2,
  7038. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7039. Decimal: decimal,
  7040. OthDesc: oth_desc,
  7041. CashPay: cash_pay,
  7042. WechatPay: wechat_pay,
  7043. AliPay: ali_pay,
  7044. JifenPay: jifen_pay,
  7045. BandCardPay: band_card_pay,
  7046. Creator: adminUser.AdminUser.Id,
  7047. }
  7048. err = service.CreateOrderTX(order, tx)
  7049. if err != nil {
  7050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7051. return
  7052. }
  7053. var customs []*Custom
  7054. for _, item := range prescriptions {
  7055. if item.Type == 1 { //药品a
  7056. for _, subItem := range item.HisDoctorAdviceInfo {
  7057. cus := &Custom{
  7058. AdviceId: subItem.ID,
  7059. ProjectId: 0,
  7060. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7061. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7062. FeedetlSn: subItem.FeedetlSn,
  7063. Price: fmt.Sprintf("%.4f", subItem.Price),
  7064. MedListCodg: subItem.MedListCodg,
  7065. Type: 1,
  7066. }
  7067. customs = append(customs, cus)
  7068. }
  7069. }
  7070. if item.Type == 2 { //项目
  7071. for _, subItem := range item.HisPrescriptionProject {
  7072. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7073. cus := &Custom{
  7074. AdviceId: 0,
  7075. ProjectId: subItem.ID,
  7076. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7077. Cut: fmt.Sprintf("%.4f", cnt),
  7078. FeedetlSn: subItem.FeedetlSn,
  7079. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7080. MedListCodg: subItem.MedListCodg,
  7081. Type: 2,
  7082. }
  7083. customs = append(customs, cus)
  7084. }
  7085. }
  7086. for _, item := range item.HisAdditionalCharge {
  7087. cus := &Custom{
  7088. ItemId: item.ID,
  7089. AdviceId: 0,
  7090. ProjectId: 0,
  7091. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7092. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7093. FeedetlSn: item.FeedetlSn,
  7094. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7095. MedListCodg: item.XtHisAddtionConfig.Code,
  7096. Type: 3,
  7097. }
  7098. customs = append(customs, cus)
  7099. }
  7100. }
  7101. for _, item := range customs {
  7102. var advice_id int64 = 0
  7103. var project_id int64 = 0
  7104. var item_id int64 = 0
  7105. var types int64 = 0
  7106. if item.Type == 1 {
  7107. advice_id = item.AdviceId
  7108. project_id = 0
  7109. item_id = 0
  7110. } else if item.Type == 2 {
  7111. advice_id = 0
  7112. item_id = 0
  7113. project_id = item.ProjectId
  7114. } else if item.Type == 3 {
  7115. advice_id = 0
  7116. item_id = item.ItemId
  7117. project_id = 0
  7118. }
  7119. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7120. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7121. pric, _ := strconv.ParseFloat(item.Price, 32)
  7122. info := &models.HisOrderInfo{
  7123. OrderNumber: order.Number,
  7124. UploadDate: time.Now().Unix(),
  7125. AdviceId: advice_id,
  7126. DetItemFeeSumamt: detItemFeeSumamt,
  7127. Cnt: cut,
  7128. Pric: pric,
  7129. PatientId: id,
  7130. Status: 1,
  7131. Mtime: time.Now().Unix(),
  7132. Ctime: time.Now().Unix(),
  7133. UserOrgId: adminUser.CurrentOrgId,
  7134. HisPatientId: his.ID,
  7135. OrderId: order.ID,
  7136. ProjectId: project_id,
  7137. Type: types,
  7138. ItemId: item_id,
  7139. }
  7140. service.CreateOrderInfoTX(info, tx)
  7141. }
  7142. his.Diagnosis = diagnosis_id
  7143. his.SickType = sick_type
  7144. his.RegisterType = reg_type
  7145. his.MedicalTreatmentType = reg_type
  7146. service.UpdataHisPateintTX(&his, tx)
  7147. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  7148. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  7149. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  7150. //判断是否使用了押金
  7151. if dec_way == "true" {
  7152. tmpstring := strconv.FormatInt(order.ID, 10)
  7153. //扣押金
  7154. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  7155. order.Decimal = decimal
  7156. service.UpDateOrderTwo(order, tx)
  7157. if errmsg != nil {
  7158. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  7159. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7160. return
  7161. }
  7162. }
  7163. if err == nil {
  7164. for _, info := range prescriptions {
  7165. if info.Type == 1 {
  7166. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  7167. }
  7168. if info.Type == 2 {
  7169. for _, sumItem := range info.HisPrescriptionProject {
  7170. if sumItem.Type == 3 {
  7171. var good models.DialysisBeforePrepareGoods
  7172. var newGood models.NewDialysisBeforePrepareGoods
  7173. var oldGood models.OldDialysisBeforePrepareGoods
  7174. good.GoodId = sumItem.GoodInfo.ID
  7175. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7176. count, _ := strconv.Atoi(sumItem.Count)
  7177. good.Count = int64(count)
  7178. good.StorehouseId = houseConfig.StorehouseOutInfo
  7179. good.ProjectId = sumItem.ID
  7180. good.PatientId = sumItem.PatientId
  7181. goods = append(goods, &good)
  7182. newGood.GoodId = sumItem.GoodInfo.ID
  7183. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7184. count2, _ := strconv.Atoi(sumItem.Count)
  7185. newGood.Count = int64(count2)
  7186. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7187. newGood.ProjectId = sumItem.ID
  7188. newGood.PatientId = sumItem.HisPatientId
  7189. newGoods = append(newGoods, &newGood)
  7190. oldGood.GoodId = sumItem.GoodInfo.ID
  7191. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7192. count3, _ := strconv.Atoi(sumItem.Count)
  7193. oldGood.Count = int64(count3)
  7194. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  7195. oldGood.ProjectId = sumItem.ID
  7196. oldGood.RecordDate = sumItem.RecordDate
  7197. oldGood.PatientId = sumItem.HisPatientId
  7198. oldGoods = append(oldGoods, &oldGood)
  7199. }
  7200. }
  7201. }
  7202. }
  7203. if settConfig.IsOpen == 1 {
  7204. for _, item := range infoList {
  7205. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7206. if medical.IsUse == 2 {
  7207. //药品出库
  7208. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  7209. //查询默认仓库
  7210. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  7211. //查询默认仓库剩余多少库存
  7212. var sum_count int64
  7213. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7214. for _, its := range stockInfo {
  7215. if its.MaxUnit == medical.MaxUnit {
  7216. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7217. }
  7218. sum_count += its.StockMaxNumber + its.StockMinNumber
  7219. }
  7220. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7221. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7222. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  7223. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  7224. }
  7225. }
  7226. orgId := c.GetAdminUserInfo().CurrentOrgId
  7227. if len(oldGoods) > 0 {
  7228. timeStr := time.Now().Format("2006-01-02")
  7229. timeArr := strings.Split(timeStr, "-")
  7230. total, _ := service.FindAllWarehouseOut(orgId)
  7231. total = total + 1
  7232. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7233. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7234. number = number + total
  7235. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7236. operation_time := time.Now().Unix()
  7237. creater := c.GetAdminUserInfo().AdminUser.Id
  7238. //查询默认出库仓库库存
  7239. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7240. recordDateStr := time.Now().Format("2006-01-02")
  7241. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7242. nowtime := recordDate.Unix()
  7243. warehouseOut := models.WarehouseOut{
  7244. WarehouseOutOrderNumber: warehousing_out_order,
  7245. OperationTime: operation_time,
  7246. OrgId: orgId,
  7247. Creater: creater,
  7248. Ctime: time.Now().Unix(),
  7249. Status: 1,
  7250. WarehouseOutTime: nowtime,
  7251. Type: 1,
  7252. StorehouseId: storeConfig.StorehouseOutInfo,
  7253. IsCheck: 1,
  7254. OrderId: order.ID,
  7255. IsSys: 5,
  7256. }
  7257. //查询是否生成出库单
  7258. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7259. if out.ID == 0 {
  7260. service.AddSigleWarehouseOut(&warehouseOut)
  7261. }
  7262. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7263. for _, item := range oldGoods {
  7264. dialyPrepareOne := models.DialysisBeforePrepare{
  7265. GoodTypeId: item.GoodTypeId,
  7266. GoodId: item.GoodId,
  7267. PatientId: his.PatientId,
  7268. RecordDate: item.RecordDate,
  7269. UserOrgId: adminUser.CurrentOrgId,
  7270. Count: item.Count,
  7271. Ctime: time.Now().Unix(),
  7272. Creater: adminUser.AdminUser.Id,
  7273. CommdityCode: item.CommdityCode,
  7274. Status: 1,
  7275. StorehouseId: houseConfig.StorehouseOutInfo,
  7276. }
  7277. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  7278. //非零用
  7279. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  7280. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7281. //查询剩余库存
  7282. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7283. var sum_count int64
  7284. for _, item := range goodList {
  7285. sum_count += item.StockCount
  7286. }
  7287. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7288. //耗材
  7289. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7290. }
  7291. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  7292. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7293. //查询剩余库存
  7294. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7295. var sum_count int64
  7296. for _, item := range goodList {
  7297. sum_count += item.StockCount
  7298. }
  7299. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7300. //耗材
  7301. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7302. }
  7303. }
  7304. }
  7305. }
  7306. c.ServeSuccessJSON(map[string]interface{}{
  7307. "msg": "结算成功",
  7308. })
  7309. }
  7310. }
  7311. }
  7312. // 退款
  7313. func (c *HisApiController) Refund() {
  7314. order_id, _ := c.GetInt64("order_id")
  7315. order, _ := service.GetHisOrderByID(order_id)
  7316. adminUser := c.GetAdminUserInfo()
  7317. orgid := c.GetAdminUserInfo().CurrentOrgId
  7318. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  7319. if err != nil {
  7320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7321. return
  7322. }
  7323. tmp := strconv.FormatInt(order.ID, 10)
  7324. //当押金不为零时产生退费记录
  7325. if order.Decimal != 0 {
  7326. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  7327. if err != nil {
  7328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7329. return
  7330. }
  7331. }
  7332. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  7333. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  7334. var goods []*models.DialysisBeforePrepareGoods
  7335. var newGoods []*models.NewDialysisBeforePrepareGoods
  7336. var infos []*models.HisDoctorAdviceInfo
  7337. for _, info := range orders {
  7338. if info.AdviceId > 0 && info.ProjectId == 0 {
  7339. infos = append(infos, &info.HisDoctorAdviceInfo)
  7340. }
  7341. if info.ProjectId > 0 && info.AdviceId == 0 {
  7342. if info.HisPrescriptionProject.Type == 3 {
  7343. var good models.DialysisBeforePrepareGoods
  7344. var newGood models.NewDialysisBeforePrepareGoods
  7345. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7346. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7347. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7348. good.Count = int64(count)
  7349. good.StorehouseId = houseConfig.StorehouseOutInfo
  7350. good.ProjectId = info.HisPrescriptionProject.ID
  7351. good.PatientId = info.PatientId
  7352. good.OrderId = order_id
  7353. goods = append(goods, &good)
  7354. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7355. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7356. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7357. newGood.Count = int64(count2)
  7358. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7359. newGood.ProjectId = info.HisPrescriptionProject.ID
  7360. newGood.RecordDate = order.SettleAccountsDate
  7361. newGood.UserOrgId = order.UserOrgId
  7362. newGood.PatientId = info.PatientId
  7363. newGood.OrderId = order_id
  7364. newGoods = append(newGoods, &newGood)
  7365. }
  7366. }
  7367. }
  7368. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7369. if settConfig.IsOpen == 1 {
  7370. for _, item := range infos {
  7371. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7372. }
  7373. for _, item := range newGoods {
  7374. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7375. }
  7376. }
  7377. c.ServeSuccessJSON(map[string]interface{}{
  7378. "msg": "退费成功",
  7379. })
  7380. }
  7381. func (c *HisApiController) RefundNumber() {
  7382. his_patient_id, _ := c.GetInt64("id")
  7383. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7384. info.Status = 0
  7385. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  7386. if count > 0 {
  7387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  7388. return
  7389. }
  7390. err := service.SaveHisPatient(info)
  7391. if err == nil {
  7392. c.ServeSuccessJSON(map[string]interface{}{
  7393. "msg": "退号成功",
  7394. })
  7395. } else {
  7396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7397. return
  7398. }
  7399. }
  7400. func (this *HisApiController) AdditionalCharge() {
  7401. dataBody := make(map[string]interface{}, 0)
  7402. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7403. fmt.Println(err)
  7404. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  7405. patient_id := int64(dataBody["patient_id"].(float64))
  7406. medicineData, _ := dataBody["medicineData"].([]interface{})
  7407. adminUserInfo := this.GetAdminUserInfo()
  7408. orgId := adminUserInfo.CurrentOrgId
  7409. admin_user_id := adminUserInfo.AdminUser.Id
  7410. timeStr := time.Now().Format("2006-01-02")
  7411. timeLayout := "2006-01-02 15:04:05"
  7412. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  7413. timenow := timeStringToTime.Unix()
  7414. var additionalCharges []*models.HisAdditionalCharge
  7415. for _, item := range medicineData {
  7416. var randNum int
  7417. randNum = rand.Intn(10000) + 1000
  7418. timestamp := time.Now().Unix()
  7419. tempTime := time.Unix(timestamp, 0)
  7420. timeFormat := tempTime.Format("20060102150405")
  7421. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  7422. items := item.(map[string]interface{})
  7423. money := items["price"].(string)
  7424. item_id_str := items["item_id"].(string)
  7425. name := items["name"].(string)
  7426. id_str := items["id"].(string)
  7427. moneys, _ := strconv.ParseInt(money, 10, 64)
  7428. monStr := strconv.FormatInt(moneys, 10)
  7429. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  7430. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  7431. id, _ := strconv.ParseInt(id_str, 10, 64)
  7432. additionalCharge := &models.HisAdditionalCharge{
  7433. ID: id,
  7434. HisPatientId: his_patient_id,
  7435. UserOrgId: orgId,
  7436. PatientId: patient_id,
  7437. RecordDate: timenow,
  7438. Price: monneyStr,
  7439. Status: 1,
  7440. ItemName: name,
  7441. ItemId: item_id,
  7442. AdminUserId: admin_user_id,
  7443. CreatedTime: time.Now().Unix(),
  7444. OrderStatus: 0,
  7445. PrescriptionNumber: "",
  7446. BatchNumber: "",
  7447. FeedetlSn: p_number,
  7448. }
  7449. service.CreateAdditionalCharge(additionalCharge)
  7450. additionalCharges = append(additionalCharges, additionalCharge)
  7451. }
  7452. this.ServeSuccessJSON(map[string]interface{}{
  7453. "msg": "添加成功",
  7454. "additional_charges": additionalCharges,
  7455. })
  7456. }
  7457. func (this *HisApiController) DeleteAddition() {
  7458. id, _ := this.GetInt64("id")
  7459. //TODO 需要判断是否已经结算
  7460. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  7461. if err == nil {
  7462. this.ServeSuccessJSON(map[string]interface{}{
  7463. "msg": "删除成功",
  7464. })
  7465. return
  7466. } else {
  7467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7468. return
  7469. }
  7470. }
  7471. func (this *HisApiController) GetAdminUsers() {
  7472. adminUser := this.GetAdminUserInfo()
  7473. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  7474. this.ServeSuccessJSON(map[string]interface{}{
  7475. "doctors": doctors,
  7476. })
  7477. }
  7478. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7479. change_type, _ := this.GetInt64("type", 0)
  7480. record_date := this.GetString("record_time")
  7481. patient_id, _ := this.GetInt64("patient_id", 0)
  7482. p_type, _ := this.GetInt64("p_type", 0)
  7483. timeLayout := "2006-01-02"
  7484. loc, _ := time.LoadLocation("Local")
  7485. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7486. record_time := theAdviceRecordTime.Unix()
  7487. adminUserInfo := this.GetAdminUserInfo()
  7488. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7489. if err == nil {
  7490. if len(prescriptions) == 0 {
  7491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7492. return
  7493. } else {
  7494. this.ServeSuccessJSON(map[string]interface{}{
  7495. "prescriptions": prescriptions,
  7496. })
  7497. return
  7498. }
  7499. } else {
  7500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7501. return
  7502. }
  7503. }
  7504. func (this *HisApiController) GetCallHisPrescription() {
  7505. patient_id, _ := this.GetInt64("patient_id", 0)
  7506. timeLayout := "2006-01-02"
  7507. loc, _ := time.LoadLocation("Local")
  7508. start_time := this.GetString("start_time")
  7509. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7510. end_time := this.GetString("end_time")
  7511. p_type, _ := this.GetInt64("p_type")
  7512. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7513. adminUserInfo := this.GetAdminUserInfo()
  7514. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7515. if err == nil {
  7516. this.ServeSuccessJSON(map[string]interface{}{
  7517. "prescriptions": prescriptions,
  7518. })
  7519. return
  7520. } else {
  7521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7522. return
  7523. }
  7524. }
  7525. func (this *HisApiController) GetHisDayPrescription() {
  7526. timeLayout := "2006-01-02"
  7527. loc, _ := time.LoadLocation("Local")
  7528. start_time := this.GetString("start_time")
  7529. patient_id, _ := this.GetInt64("patient_id", 0)
  7530. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7531. end_time := this.GetString("end_time")
  7532. p_type, _ := this.GetInt64("p_type")
  7533. order_status, _ := this.GetInt64("type")
  7534. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7535. adminUserInfo := this.GetAdminUserInfo()
  7536. var dayHisPrescription []*models.HisPrescription
  7537. var err error
  7538. if order_status == 1 || order_status == 0 {
  7539. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7540. } else if order_status == 2 {
  7541. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7542. }
  7543. var settle_total float64
  7544. for _, item := range dayHisPrescription {
  7545. if len(item.HisPrescriptionProject) > 0 {
  7546. for _, subItem := range item.HisPrescriptionProject {
  7547. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7548. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7549. settle_total = settle_total + total
  7550. }
  7551. }
  7552. if len(item.HisDoctorAdviceInfo) > 0 {
  7553. for _, subItem := range item.HisDoctorAdviceInfo {
  7554. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7555. settle_total = settle_total + total
  7556. }
  7557. }
  7558. }
  7559. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7560. if err == nil {
  7561. this.ServeSuccessJSON(map[string]interface{}{
  7562. "day_prescription": dayHisPrescription,
  7563. "settle_total": settle_total,
  7564. })
  7565. return
  7566. } else {
  7567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7568. return
  7569. }
  7570. }
  7571. func (c *HisApiController) GetHisChargePatientList() {
  7572. record_date := c.GetString("record_date")
  7573. order_status, _ := c.GetInt64("type")
  7574. sch_type, _ := c.GetInt64("sch_type")
  7575. timeLayout := "2006-01-02"
  7576. loc, _ := time.LoadLocation("Local")
  7577. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7578. if err != nil {
  7579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7580. return
  7581. }
  7582. recordDateTime := theTime.Unix()
  7583. adminInfo := c.GetAdminUserInfo()
  7584. var tempPatients []*service.NewTempPatients
  7585. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7586. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7587. if order_status != 2 {
  7588. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7589. } else {
  7590. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7591. }
  7592. } else {
  7593. if order_status != 2 {
  7594. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7595. } else {
  7596. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7597. }
  7598. }
  7599. var patients []*service.NewTempPatients
  7600. var patients_two []*service.NewTempPatients
  7601. for _, item := range tempPatients {
  7602. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7603. //过滤掉没挂号的和没开处方的
  7604. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7605. patients = append(patients, item)
  7606. }
  7607. //过滤掉没挂号的
  7608. if len(item.HisPatient) > 0 {
  7609. patients_two = append(patients_two, item)
  7610. }
  7611. } else {
  7612. if len(item.HisPrescription) > 0 {
  7613. patients = append(patients, item)
  7614. }
  7615. }
  7616. }
  7617. c.ServeSuccessJSON(map[string]interface{}{
  7618. "list": patients,
  7619. "list_two": patients_two,
  7620. })
  7621. }
  7622. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7623. record_date := c.GetString("record_date")
  7624. timeLayout := "2006-01-02"
  7625. loc, _ := time.LoadLocation("Local")
  7626. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7627. if err != nil {
  7628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7629. return
  7630. }
  7631. recordDateTime := theTime.Unix()
  7632. adminUser := c.GetAdminUserInfo()
  7633. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7634. var patients []*service.Patients
  7635. for _, item := range tempPatients {
  7636. if item.HisPatient.ID == 0 {
  7637. patients = append(patients, item)
  7638. }
  7639. }
  7640. c.ServeSuccessJSON(map[string]interface{}{
  7641. "list": patients,
  7642. //"list_two": patients_two,
  7643. })
  7644. }
  7645. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7646. newArr = make([]*service.Patients, 0)
  7647. for i := 0; i < len(patient); i++ {
  7648. repeat := false
  7649. for j := i + 1; j < len(patient); j++ {
  7650. if patient[i].ID == patient[j].ID {
  7651. repeat = true
  7652. break
  7653. }
  7654. }
  7655. if !repeat {
  7656. newArr = append(newArr, patient[i])
  7657. }
  7658. }
  7659. return
  7660. }
  7661. func (c *HisApiController) GetHisChargePatientInfo() {
  7662. patient_id, _ := c.GetInt64("patient_id")
  7663. his_patient_id, _ := c.GetInt64("his_patient_id")
  7664. record_date := c.GetString("record_date")
  7665. //start_time := c.GetString("start_time")
  7666. //end_time := c.GetString("end_time")
  7667. order_status, _ := c.GetInt64("type", 0)
  7668. p_type, _ := c.GetInt64("p_type", 0)
  7669. order_id, _ := c.GetInt64("order_id", 0)
  7670. timeLayout := "2006-01-02"
  7671. loc, _ := time.LoadLocation("Local")
  7672. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7673. if err != nil {
  7674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7675. return
  7676. }
  7677. recordDateTime := theTime.Unix()
  7678. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7679. //if err != nil {
  7680. //
  7681. //}
  7682. //startRecordDateTime := startTime.Unix()
  7683. //
  7684. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7685. //if err != nil {
  7686. //
  7687. //}
  7688. //endRecordDateTime := endTime.Unix()
  7689. admin := c.GetAdminUserInfo()
  7690. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7691. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7692. var prescriptions []*models.HisPrescription
  7693. //var unChargeMonthPrescriptions []*models.HisPrescription
  7694. order, _ := service.GetHisOrderByID(order_id)
  7695. if order_status == 1 || order_status == 0 {
  7696. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7697. } else if order_status == 2 {
  7698. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7699. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7700. }
  7701. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7702. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7703. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7704. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7705. //获取所有科室信息
  7706. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7707. c.ServeSuccessJSON(map[string]interface{}{
  7708. "his_info": his_patient_info,
  7709. "xt_info": xt_patient_info,
  7710. "prescription": prescriptions,
  7711. "case_history": case_history,
  7712. "info": patientPrescriptionInfo,
  7713. "last_info": lastPatientPrescriptionInfo,
  7714. "order": order,
  7715. "doctors": doctors,
  7716. "department": department,
  7717. })
  7718. return
  7719. }
  7720. func (c *HisApiController) GetAllOrderDetail() {
  7721. order_id, _ := c.GetInt64("id", 0)
  7722. order, _ := service.GetHisOrderByID(order_id)
  7723. if order.ID == 0 {
  7724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7725. return
  7726. }
  7727. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7728. org_id := c.GetAdminUserInfo().CurrentOrgId
  7729. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7730. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7731. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7732. c.ServeSuccessJSON(map[string]interface{}{
  7733. "order": order,
  7734. "order_info": order_info,
  7735. "patient": patient,
  7736. "admin_info": adminInfo,
  7737. "hospital_record": record,
  7738. })
  7739. return
  7740. }
  7741. func (c *HisApiController) GetAllOrderDetailCollect() {
  7742. order_id, _ := c.GetInt64("id", 0)
  7743. order, _ := service.GetHisOrderByID(order_id)
  7744. if order.ID == 0 {
  7745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7746. return
  7747. }
  7748. org_id := c.GetAdminUserInfo().CurrentOrgId
  7749. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7750. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7751. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7752. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7753. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7754. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7755. var bedCostTotal float64 = 0 //床位总费
  7756. //var bedCostSelfTotal float64 = 0 //床位自费
  7757. var operationCostTotal float64 = 0 //手术费
  7758. //var operationCostSelfTotal float64 = 0 //手术费
  7759. var otherCostTotal float64 = 0 //其他费用
  7760. //var otherCostSelfTotal float64 = 0 //其他费用
  7761. var materialCostTotal float64 = 0 //材料费
  7762. //var materialCostSelfTotal float64 = 0 //材料费
  7763. var westernMedicineCostTotal float64 = 0 //西药费
  7764. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7765. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7766. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7767. var checkCostTotal float64 = 0 //检查费
  7768. //var checkCostSelfTotal float64 = 0 //检查费
  7769. var laboratoryCostTotal float64 = 0 //化验费
  7770. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7771. var treatCostTotal float64 = 0 //治疗费用
  7772. //var treatCostSelfTotal float64 = 0 //治疗费用
  7773. var zhenChaCostTotal float64 = 0 //其他费用
  7774. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7775. decimal.DivisionPrecision = 2
  7776. var BalanceAccountsType int64
  7777. if his.ID > 0 {
  7778. BalanceAccountsType = his.BalanceAccountsType
  7779. } else {
  7780. BalanceAccountsType = record.BalanceAccountsType
  7781. }
  7782. if BalanceAccountsType != 2 {
  7783. for _, item := range order_info {
  7784. if org_id == 10215 {
  7785. if item.MedChrgitmType == "01" { //床位费
  7786. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7787. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7788. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7789. }
  7790. if item.MedChrgitmType == "02" { //诊察费
  7791. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7792. //zhenChaCostSelfTotal = zhenChaCostTotal
  7793. }
  7794. if item.MedChrgitmType == "03" { //检查费
  7795. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7796. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7797. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7798. }
  7799. //if item.MedChrgitmType == "02" { //检查费
  7800. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7801. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7802. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7803. //}
  7804. if item.MedChrgitmType == "04" { //化验费
  7805. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7806. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7807. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7808. }
  7809. if item.MedChrgitmType == "05" { //治疗费
  7810. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7811. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7812. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7813. }
  7814. if item.MedChrgitmType == "06" { //手术费
  7815. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7816. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7817. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7818. }
  7819. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7820. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7821. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7822. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7823. }
  7824. if item.MedChrgitmType == "09" { //西药费
  7825. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7826. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7827. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7828. }
  7829. if item.MedChrgitmType == "11" { //中成费
  7830. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7831. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7832. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7833. }
  7834. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7835. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7836. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7837. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7838. }
  7839. } else if org_id == 10188 || org_id == 10217 {
  7840. if item.MedChrgitmType == "01" { //床位费
  7841. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7842. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7843. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7844. }
  7845. if item.MedChrgitmType == "02" { //诊察费
  7846. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7847. //zhenChaCostSelfTotal = zhenChaCostTotal
  7848. }
  7849. if item.MedChrgitmType == "03" { //检查费
  7850. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7851. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7852. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7853. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7854. }
  7855. //if item.MedChrgitmType == "02" { //检查费
  7856. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7857. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7858. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7859. //}
  7860. if item.MedChrgitmType == "04" { //化验费
  7861. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7862. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7863. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7864. }
  7865. if item.MedChrgitmType == "05" { //治疗费
  7866. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7867. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7868. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7869. }
  7870. if item.MedChrgitmType == "06" { //手术费
  7871. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7872. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7873. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7874. }
  7875. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7876. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7877. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7878. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7879. }
  7880. if item.MedChrgitmType == "09" { //西药费
  7881. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7882. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7883. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7884. }
  7885. if item.MedChrgitmType == "11" { //中成费
  7886. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7887. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7888. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7889. }
  7890. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7891. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7892. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7893. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7894. }
  7895. } else {
  7896. if item.MedChrgitmType == "01" { //床位费
  7897. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7898. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7899. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7900. }
  7901. //if item.MedChrgitmType == "02" { //诊察费
  7902. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7903. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7904. //}
  7905. if item.MedChrgitmType == "03" { //检查费
  7906. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7907. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7908. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7909. }
  7910. //if item.MedChrgitmType == "02" { //检查费
  7911. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7912. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7913. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7914. //}
  7915. if item.MedChrgitmType == "04" { //化验费
  7916. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7917. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7918. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7919. }
  7920. if item.MedChrgitmType == "05" { //治疗费
  7921. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7922. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7923. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7924. }
  7925. if item.MedChrgitmType == "06" { //手术费
  7926. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7927. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7928. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7929. }
  7930. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7931. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7932. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7933. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7934. }
  7935. if item.MedChrgitmType == "09" { //西药费
  7936. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7937. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7938. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7939. }
  7940. if item.MedChrgitmType == "11" { //中成费
  7941. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7942. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7943. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7944. }
  7945. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7946. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7947. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7948. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7949. }
  7950. }
  7951. }
  7952. c.ServeSuccessJSON(map[string]interface{}{
  7953. "order": order,
  7954. "order_info": order_info,
  7955. "patient": patient,
  7956. "admin_info": adminInfo,
  7957. "his_hospital": record,
  7958. "bedCostTotal": bedCostTotal,
  7959. "operationCostTotal": operationCostTotal,
  7960. "otherCostTotal": otherCostTotal,
  7961. "materialCostTotal": materialCostTotal,
  7962. "westernMedicineCostTotal": westernMedicineCostTotal,
  7963. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7964. "checkCostTotal": checkCostTotal,
  7965. "zhenChaCostTotal": zhenChaCostTotal,
  7966. "laboratoryCostTotal": laboratoryCostTotal,
  7967. "treatCostTotal": treatCostTotal,
  7968. })
  7969. } else {
  7970. for _, item := range order_info {
  7971. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7972. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7973. item.MedChrgitmType = "09"
  7974. }
  7975. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7976. if item.HisPrescriptionProject.Type == 2 {
  7977. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7978. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7979. case 0:
  7980. item.MedChrgitmType = "0"
  7981. break
  7982. case 1:
  7983. item.MedChrgitmType = "14"
  7984. break
  7985. case 2:
  7986. item.MedChrgitmType = "05"
  7987. break
  7988. case 3:
  7989. item.MedChrgitmType = "03"
  7990. break
  7991. case 4:
  7992. item.MedChrgitmType = "03"
  7993. break
  7994. case 5:
  7995. item.MedChrgitmType = "08"
  7996. break
  7997. case 6:
  7998. item.MedChrgitmType = "14"
  7999. break
  8000. case 7:
  8001. item.MedChrgitmType = "14"
  8002. break
  8003. case 8:
  8004. item.MedChrgitmType = "03"
  8005. break
  8006. case 9:
  8007. item.MedChrgitmType = "14"
  8008. break
  8009. case 10:
  8010. item.MedChrgitmType = "14"
  8011. break
  8012. case 11:
  8013. item.MedChrgitmType = "06"
  8014. break
  8015. case 12:
  8016. item.MedChrgitmType = "12"
  8017. break
  8018. case 13:
  8019. item.MedChrgitmType = "01"
  8020. break
  8021. case 14:
  8022. item.MedChrgitmType = "04"
  8023. break
  8024. case 15:
  8025. item.MedChrgitmType = "14"
  8026. break
  8027. }
  8028. } else {
  8029. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8030. case 1:
  8031. item.MedChrgitmType = "14"
  8032. break
  8033. case 2:
  8034. item.MedChrgitmType = "05"
  8035. break
  8036. case 3:
  8037. item.MedChrgitmType = "04"
  8038. break
  8039. case 4:
  8040. item.MedChrgitmType = "14"
  8041. break
  8042. case 5:
  8043. item.MedChrgitmType = "08"
  8044. break
  8045. case 6:
  8046. item.MedChrgitmType = "14"
  8047. break
  8048. case 7:
  8049. item.MedChrgitmType = "14"
  8050. break
  8051. case 8:
  8052. item.MedChrgitmType = "03"
  8053. break
  8054. case 9:
  8055. item.MedChrgitmType = "14"
  8056. break
  8057. }
  8058. }
  8059. } else if item.HisPrescriptionProject.Type == 3 {
  8060. item.MedChrgitmType = "08"
  8061. }
  8062. }
  8063. }
  8064. for _, item := range order_info {
  8065. if org_id == 10215 {
  8066. if item.MedChrgitmType == "01" { //床位费
  8067. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8068. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8069. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8070. }
  8071. if item.MedChrgitmType == "02" { //诊察费
  8072. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8073. //zhenChaCostSelfTotal = zhenChaCostTotal
  8074. }
  8075. if item.MedChrgitmType == "03" { //检查费
  8076. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8077. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8078. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8079. }
  8080. //if item.MedChrgitmType == "02" { //检查费
  8081. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8082. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8083. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8084. //}
  8085. if item.MedChrgitmType == "04" { //化验费
  8086. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8087. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8088. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8089. }
  8090. if item.MedChrgitmType == "05" { //治疗费
  8091. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8092. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8093. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8094. }
  8095. if item.MedChrgitmType == "06" { //手术费
  8096. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8097. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8098. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8099. }
  8100. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8102. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8103. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8104. }
  8105. if item.MedChrgitmType == "09" { //西药费
  8106. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8107. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8108. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8109. }
  8110. if item.MedChrgitmType == "11" { //中成费
  8111. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8112. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8113. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8114. }
  8115. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8116. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8117. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8118. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8119. }
  8120. } else {
  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. //if item.MedChrgitmType == "02" { //诊察费
  8127. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8128. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8129. //}
  8130. if item.MedChrgitmType == "03" { //检查费
  8131. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8132. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8133. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8134. }
  8135. //if item.MedChrgitmType == "02" { //检查费
  8136. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8137. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8138. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8139. //}
  8140. if item.MedChrgitmType == "04" { //化验费
  8141. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8142. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8143. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8144. }
  8145. if item.MedChrgitmType == "05" { //治疗费
  8146. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8147. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8148. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8149. }
  8150. if item.MedChrgitmType == "06" { //手术费
  8151. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8152. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8153. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8154. }
  8155. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8156. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8157. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8158. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8159. }
  8160. if item.MedChrgitmType == "09" { //西药费
  8161. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8162. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8163. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8164. }
  8165. if item.MedChrgitmType == "11" { //中成费
  8166. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8167. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8168. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8169. }
  8170. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8171. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8172. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8173. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8174. }
  8175. }
  8176. }
  8177. c.ServeSuccessJSON(map[string]interface{}{
  8178. "order": order,
  8179. "order_info": order_info,
  8180. "patient": patient,
  8181. "admin_info": adminInfo,
  8182. "his_hospital": record,
  8183. "bedCostTotal": bedCostTotal,
  8184. "operationCostTotal": operationCostTotal,
  8185. "otherCostTotal": otherCostTotal,
  8186. "materialCostTotal": materialCostTotal,
  8187. "westernMedicineCostTotal": westernMedicineCostTotal,
  8188. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8189. "checkCostTotal": checkCostTotal,
  8190. "zhenChaCostTotal": zhenChaCostTotal,
  8191. "laboratoryCostTotal": laboratoryCostTotal,
  8192. "treatCostTotal": treatCostTotal,
  8193. })
  8194. }
  8195. }
  8196. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  8197. page, _ := c.GetInt64("page")
  8198. limit, _ := c.GetInt64("limit")
  8199. keywords := c.GetString("keywords")
  8200. start_time := c.GetString("start_time")
  8201. end_time := c.GetString("end_time")
  8202. //clr_type := c.GetString("clr_type")
  8203. insutype := c.GetString("insutype")
  8204. timeLayout := "2006-01-02"
  8205. loc, _ := time.LoadLocation("Local")
  8206. var theStartTIme int64
  8207. if len(start_time) > 0 {
  8208. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8209. theStartTIme = theTime.Unix()
  8210. }
  8211. var theEndtTIme int64
  8212. if len(end_time) > 0 {
  8213. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8214. theEndtTIme = theTime.Unix()
  8215. }
  8216. if page <= 0 {
  8217. page = 1
  8218. }
  8219. if limit <= 0 {
  8220. limit = 10
  8221. }
  8222. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  8223. c.ServeSuccessJSON(map[string]interface{}{
  8224. "total": total,
  8225. "list": list,
  8226. })
  8227. return
  8228. }
  8229. func (c *HisApiController) GetPutOnRecordList() {
  8230. page, _ := c.GetInt64("page")
  8231. limit, _ := c.GetInt64("limit")
  8232. keywords := c.GetString("keywords")
  8233. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  8234. if page <= 0 {
  8235. page = 1
  8236. }
  8237. if limit <= 0 {
  8238. limit = 10
  8239. }
  8240. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  8241. c.ServeSuccessJSON(map[string]interface{}{
  8242. "total": total,
  8243. "list": list,
  8244. })
  8245. return
  8246. }
  8247. func (c *HisApiController) GetCompareData() {
  8248. start_time := c.GetString("start_time")
  8249. end_time := c.GetString("end_time")
  8250. insutype := c.GetString("insutype")
  8251. clr_type := c.GetString("clr_type")
  8252. timeLayout := "2006-01-02"
  8253. loc, _ := time.LoadLocation("Local")
  8254. var theStartTIme int64
  8255. if len(start_time) > 0 {
  8256. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8257. if err != nil {
  8258. theStartTIme = 0
  8259. }
  8260. theStartTIme = theTime.Unix()
  8261. }
  8262. var theEndtTIme int64
  8263. if len(end_time) > 0 {
  8264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8265. if err != nil {
  8266. theEndtTIme = 0
  8267. }
  8268. theEndtTIme = theTime.Unix()
  8269. }
  8270. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  8271. fmt.Println(err)
  8272. if err == nil {
  8273. c.ServeSuccessJSON(map[string]interface{}{
  8274. "list": formData,
  8275. })
  8276. } else {
  8277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8278. return
  8279. }
  8280. }
  8281. func (c *HisApiController) GetFaPiaoData() {
  8282. order_id, _ := c.GetInt64("order_id")
  8283. patient_id, _ := c.GetInt64("patient_id")
  8284. //number := c.GetString("number")
  8285. adminUser := c.GetAdminUserInfo()
  8286. order, _ := service.GetHisOrderByID(order_id)
  8287. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8288. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8289. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8290. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8291. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  8292. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  8293. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8294. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8295. var bedCostTotal float64 = 0 //床位总费
  8296. var bedCostSelfTotal float64 = 0 //床位自费
  8297. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8298. var operationCostTotal float64 = 0 //手术费
  8299. var operationCostSelfTotal float64 = 0 //手术费
  8300. var operationCostPartSelfTotal float64 = 0 //手术费
  8301. var otherCostTotal float64 = 0 //其他费用
  8302. var otherCostSelfTotal float64 = 0 //其他费用
  8303. var otherCostPartSelfTotal float64 = 0 //其他费用
  8304. var materialCostTotal float64 = 0 //材料费
  8305. var materialCostSelfTotal float64 = 0 //材料费
  8306. var materialCostPartSelfTotal float64 = 0 //材料费
  8307. var westernMedicineCostTotal float64 = 0 //西药费
  8308. var westernMedicineCostSelfTotal float64 = 0 //西药费
  8309. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8310. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8311. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8312. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8313. var checkCostTotal float64 = 0 //检查费
  8314. var checkCostSelfTotal float64 = 0 //检查费
  8315. var checkCostPartSelfTotal float64 = 0 //检查费
  8316. var hiliCostTotal float64 = 0 //护理费
  8317. var hiliCostSelfTotal float64 = 0 //护理费
  8318. var hiliCostPartSelfTotal float64 = 0 //护理费
  8319. var laboratoryCostTotal float64 = 0 //化验费
  8320. var laboratoryCostSelfTotal float64 = 0 //化验费
  8321. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8322. var treatCostTotal float64 = 0 //治疗费用
  8323. var treatCostSelfTotal float64 = 0 //治疗费用
  8324. var treatCostPartSelfTotal float64 = 0 //治疗费用
  8325. var zhenChaCostTotal float64 = 0 //其他费用
  8326. var zhenChaCostSelfTotal float64 = 0 //其他费用
  8327. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8328. decimal.DivisionPrecision = 2
  8329. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8330. var balanceAccountsType int64
  8331. if his.ID > 0 {
  8332. balanceAccountsType = his.BalanceAccountsType
  8333. } else {
  8334. balanceAccountsType = his_hospital_record.BalanceAccountsType
  8335. }
  8336. if balanceAccountsType == 2 {
  8337. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8338. for _, item := range orderInfos_two {
  8339. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8340. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8341. item.MedChrgitmType = "09"
  8342. }
  8343. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8344. if item.HisPrescriptionProject.Type == 2 {
  8345. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8346. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8347. case 0:
  8348. item.MedChrgitmType = "0"
  8349. break
  8350. case 1:
  8351. item.MedChrgitmType = "14"
  8352. break
  8353. case 2:
  8354. item.MedChrgitmType = "05"
  8355. break
  8356. case 3:
  8357. item.MedChrgitmType = "03"
  8358. break
  8359. case 4:
  8360. item.MedChrgitmType = "03"
  8361. break
  8362. case 5:
  8363. item.MedChrgitmType = "08"
  8364. break
  8365. case 6:
  8366. item.MedChrgitmType = "14"
  8367. break
  8368. case 7:
  8369. item.MedChrgitmType = "14"
  8370. break
  8371. case 8:
  8372. item.MedChrgitmType = "03"
  8373. break
  8374. case 9:
  8375. item.MedChrgitmType = "14"
  8376. break
  8377. case 10:
  8378. item.MedChrgitmType = "14"
  8379. break
  8380. case 11:
  8381. item.MedChrgitmType = "06"
  8382. break
  8383. case 12:
  8384. item.MedChrgitmType = "12"
  8385. break
  8386. case 13:
  8387. item.MedChrgitmType = "01"
  8388. break
  8389. case 14:
  8390. item.MedChrgitmType = "04"
  8391. break
  8392. case 15:
  8393. item.MedChrgitmType = "02"
  8394. break
  8395. }
  8396. } else {
  8397. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8398. case 1:
  8399. item.MedChrgitmType = "14"
  8400. break
  8401. case 2:
  8402. item.MedChrgitmType = "05"
  8403. break
  8404. case 3:
  8405. item.MedChrgitmType = "03"
  8406. break
  8407. case 4:
  8408. item.MedChrgitmType = "03"
  8409. break
  8410. case 5:
  8411. item.MedChrgitmType = "08"
  8412. break
  8413. case 6:
  8414. item.MedChrgitmType = "14"
  8415. break
  8416. case 7:
  8417. item.MedChrgitmType = "14"
  8418. break
  8419. case 8:
  8420. item.MedChrgitmType = "03"
  8421. break
  8422. case 9:
  8423. item.MedChrgitmType = "14"
  8424. break
  8425. }
  8426. }
  8427. } else if item.HisPrescriptionProject.Type == 3 {
  8428. item.MedChrgitmType = "08"
  8429. }
  8430. }
  8431. }
  8432. for _, item := range orderInfos_two {
  8433. fmt.Println(item.MedChrgitmType)
  8434. if item.MedChrgitmType == "07" { //床位费
  8435. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8436. hiliCostSelfTotal = hiliCostTotal
  8437. }
  8438. if item.MedChrgitmType == "01" { //床位费
  8439. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8440. bedCostSelfTotal = bedCostTotal
  8441. }
  8442. if item.MedChrgitmType == "02" { //诊察费
  8443. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8444. zhenChaCostSelfTotal = zhenChaCostTotal
  8445. }
  8446. if item.MedChrgitmType == "03" { //检查费
  8447. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8448. checkCostSelfTotal = checkCostTotal
  8449. }
  8450. if item.MedChrgitmType == "04" { //化验费
  8451. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8452. laboratoryCostSelfTotal = laboratoryCostTotal
  8453. }
  8454. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8455. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8456. treatCostSelfTotal = treatCostTotal
  8457. }
  8458. if item.MedChrgitmType == "06" { //手术费
  8459. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8460. operationCostSelfTotal = treatCostTotal
  8461. }
  8462. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8463. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8464. materialCostSelfTotal = materialCostTotal
  8465. }
  8466. if item.MedChrgitmType == "09" { //西药费
  8467. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8468. westernMedicineCostSelfTotal = westernMedicineCostTotal
  8469. }
  8470. if item.MedChrgitmType == "11" { //中成费
  8471. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8472. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8473. }
  8474. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8475. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8476. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8477. otherCostSelfTotal = otherCostTotal
  8478. }
  8479. } else {
  8480. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8481. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8482. otherCostSelfTotal = otherCostTotal
  8483. }
  8484. }
  8485. }
  8486. } else {
  8487. for _, item := range orderInfos {
  8488. if item.MedChrgitmType == "01" { //床位费
  8489. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8490. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8491. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8492. }
  8493. if item.MedChrgitmType == "02" { //诊察费
  8494. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8495. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8496. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8497. }
  8498. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8499. if item.MedChrgitmType == "03" { //检查费
  8500. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8501. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8502. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8503. }
  8504. } else {
  8505. if item.MedChrgitmType == "03" { //检查费
  8506. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8507. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8508. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8509. }
  8510. }
  8511. if item.MedChrgitmType == "04" { //化验费
  8512. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8513. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8514. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8515. }
  8516. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8517. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8518. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8519. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8520. }
  8521. if item.MedChrgitmType == "06" { //手术费
  8522. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8523. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8524. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8525. }
  8526. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8527. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8528. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8529. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8530. }
  8531. if item.MedChrgitmType == "07" { //西药费
  8532. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8533. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8534. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8535. }
  8536. if item.MedChrgitmType == "09" { //西药费
  8537. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8538. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8539. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8540. }
  8541. if item.MedChrgitmType == "11" { //中成费
  8542. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8543. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8544. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8545. }
  8546. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8547. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8548. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8549. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8550. }
  8551. }
  8552. }
  8553. timeLayout := "2006-01-02"
  8554. loc, _ := time.LoadLocation("Local")
  8555. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8556. if err != nil {
  8557. }
  8558. startRecordDateTime := startTime.Unix()
  8559. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8560. if err != nil {
  8561. }
  8562. endRecordDateTime := endTime.Unix()
  8563. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8564. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8565. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8566. c.ServeSuccessJSON(map[string]interface{}{
  8567. "order_number": order.Number, //业务流水号
  8568. "id_card_no": his.IdCardNo, //社会保障号
  8569. "patient": patient,
  8570. "department_name": department.Name, //科室
  8571. "number": his.Number, //门诊号
  8572. "date": order.SettleAccountsDate, //结算日期
  8573. "name": order.PsnName, //姓名
  8574. "gender": patient.Gender, //性别
  8575. "psn_cash_money": order.PsnCashPay, //个人支付
  8576. "pay_way": "门诊", //结算方式
  8577. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8578. "admin_user_name": admin.UserName, //收款员
  8579. "order": order,
  8580. "order_info": orderInfos_two,
  8581. "his": his,
  8582. "bedCostTotal": bedCostTotal,
  8583. "bedCostSelfTotal": bedCostSelfTotal,
  8584. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8585. "operationCostTotal": operationCostTotal,
  8586. "operationCostSelfTotal": operationCostSelfTotal,
  8587. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8588. "otherCostTotal": otherCostTotal,
  8589. "otherCostSelfTotal": otherCostSelfTotal,
  8590. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8591. "materialCostTotal": materialCostTotal,
  8592. "materialCostSelfTotal": materialCostSelfTotal,
  8593. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8594. "westernMedicineCostTotal": westernMedicineCostTotal,
  8595. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8596. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8597. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8598. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8599. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8600. "checkCostTotal": checkCostTotal,
  8601. "checkCostSelfTotal": checkCostSelfTotal,
  8602. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8603. "laboratoryCostTotal": laboratoryCostTotal,
  8604. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8605. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8606. "treatCostTotal": treatCostTotal,
  8607. "treatCostSelfTotal": treatCostSelfTotal,
  8608. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8609. "zhenChaCostTotal": zhenChaCostTotal,
  8610. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8611. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8612. "his_hospital_record": his_hospital_record,
  8613. "pre_pay_money": pre_pay_money,
  8614. "refund_sum": sum,
  8615. "doctor_info": doctor_info,
  8616. "hiliCostTotal": hiliCostTotal,
  8617. "hiliCostSelfTotal": hiliCostSelfTotal,
  8618. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8619. })
  8620. }
  8621. //func (c *HisApiController) GetFaPiaoDatas() {
  8622. // order_ids := c.GetString("order_ids")
  8623. // patient_id, _ := c.GetInt64("patient_id")
  8624. // adminUser := c.GetAdminUserInfo()
  8625. //
  8626. // orders := strings.Split(order_ids, ",")
  8627. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8628. //
  8629. // for _, item := range orders {
  8630. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8631. // order, _ := service.GetHisOrderByID(order_id)
  8632. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8633. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8634. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8635. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8636. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8637. //
  8638. // }
  8639. //
  8640. // var bedCostTotal float64 = 0 //床位总费
  8641. // var bedCostSelfTotal float64 = 0 //床位自费
  8642. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8643. //
  8644. // var operationCostTotal float64 = 0 //手术费
  8645. // var operationCostSelfTotal float64 = 0 //手术费
  8646. // var operationCostPartSelfTotal float64 = 0 //手术费
  8647. //
  8648. // var otherCostTotal float64 = 0 //其他费用
  8649. // var otherCostSelfTotal float64 = 0 //其他费用
  8650. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8651. //
  8652. // var materialCostTotal float64 = 0 //材料费
  8653. // var materialCostSelfTotal float64 = 0 //材料费
  8654. // var materialCostPartSelfTotal float64 = 0 //材料费
  8655. //
  8656. // var westernMedicineCostTotal float64 = 0 //西药费
  8657. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8658. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8659. //
  8660. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8661. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8662. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8663. //
  8664. // var checkCostTotal float64 = 0 //检查费
  8665. // var checkCostSelfTotal float64 = 0 //检查费
  8666. // var checkCostPartSelfTotal float64 = 0 //检查费
  8667. //
  8668. // var laboratoryCostTotal float64 = 0 //化验费
  8669. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8670. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8671. //
  8672. // var treatCostTotal float64 = 0 //治疗费用
  8673. // var treatCostSelfTotal float64 = 0 //治疗费用
  8674. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8675. //
  8676. // var zhenChaCostTotal float64 = 0 //其他费用
  8677. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8678. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8679. //
  8680. // decimal.DivisionPrecision = 2
  8681. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8682. //
  8683. // var balanceAccountsType int64
  8684. // if his.ID > 0 {
  8685. // balanceAccountsType = his.BalanceAccountsType
  8686. // } else {
  8687. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8688. // }
  8689. // if balanceAccountsType == 2 {
  8690. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8691. // for _, item := range orderInfos_two {
  8692. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8693. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8694. // item.MedChrgitmType = "09"
  8695. // }
  8696. //
  8697. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8698. // if item.HisPrescriptionProject.Type == 2 {
  8699. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8700. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8701. // case 0:
  8702. // item.MedChrgitmType = "0"
  8703. // break
  8704. // case 1:
  8705. // item.MedChrgitmType = "14"
  8706. // break
  8707. // case 2:
  8708. // item.MedChrgitmType = "05"
  8709. //
  8710. // break
  8711. // case 3:
  8712. // item.MedChrgitmType = "03"
  8713. //
  8714. // break
  8715. // case 4:
  8716. // item.MedChrgitmType = "03"
  8717. //
  8718. // break
  8719. // case 5:
  8720. // item.MedChrgitmType = "08"
  8721. //
  8722. // break
  8723. // case 6:
  8724. // item.MedChrgitmType = "14"
  8725. //
  8726. // break
  8727. // case 7:
  8728. // item.MedChrgitmType = "14"
  8729. //
  8730. // break
  8731. // case 8:
  8732. // item.MedChrgitmType = "03"
  8733. // break
  8734. // case 9:
  8735. // item.MedChrgitmType = "14"
  8736. // break
  8737. // case 10:
  8738. // item.MedChrgitmType = "14"
  8739. // break
  8740. // case 11:
  8741. // item.MedChrgitmType = "06"
  8742. // break
  8743. // case 12:
  8744. // item.MedChrgitmType = "12"
  8745. // break
  8746. // case 13:
  8747. // item.MedChrgitmType = "01"
  8748. // break
  8749. // case 14:
  8750. // item.MedChrgitmType = "04"
  8751. // break
  8752. // case 15:
  8753. // item.MedChrgitmType = "02"
  8754. // break
  8755. //
  8756. // }
  8757. //
  8758. // } else {
  8759. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8760. //
  8761. // case 1:
  8762. // item.MedChrgitmType = "14"
  8763. // break
  8764. // case 2:
  8765. // item.MedChrgitmType = "05"
  8766. //
  8767. // break
  8768. // case 3:
  8769. // item.MedChrgitmType = "03"
  8770. //
  8771. // break
  8772. // case 4:
  8773. // item.MedChrgitmType = "03"
  8774. //
  8775. // break
  8776. // case 5:
  8777. // item.MedChrgitmType = "08"
  8778. //
  8779. // break
  8780. // case 6:
  8781. // item.MedChrgitmType = "14"
  8782. //
  8783. // break
  8784. // case 7:
  8785. // item.MedChrgitmType = "14"
  8786. //
  8787. // break
  8788. // case 8:
  8789. // item.MedChrgitmType = "03"
  8790. // break
  8791. // case 9:
  8792. // item.MedChrgitmType = "14"
  8793. // break
  8794. //
  8795. // }
  8796. //
  8797. // }
  8798. //
  8799. // } else if item.HisPrescriptionProject.Type == 3 {
  8800. // item.MedChrgitmType = "08"
  8801. // }
  8802. // }
  8803. // }
  8804. //
  8805. // for _, item := range orderInfos_two {
  8806. // fmt.Println(item.MedChrgitmType)
  8807. // if item.MedChrgitmType == "01" { //床位费
  8808. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8809. // bedCostSelfTotal = bedCostTotal
  8810. // }
  8811. //
  8812. // if item.MedChrgitmType == "02" { //诊察费
  8813. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8814. // zhenChaCostSelfTotal = zhenChaCostTotal
  8815. // }
  8816. //
  8817. // if item.MedChrgitmType == "03" { //检查费
  8818. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8819. // checkCostSelfTotal = checkCostTotal
  8820. // }
  8821. //
  8822. // if item.MedChrgitmType == "04" { //化验费
  8823. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8824. // laboratoryCostSelfTotal = laboratoryCostTotal
  8825. // }
  8826. //
  8827. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8828. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8829. // treatCostSelfTotal = treatCostTotal
  8830. // }
  8831. //
  8832. // if item.MedChrgitmType == "06" { //手术费
  8833. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8834. // operationCostSelfTotal = treatCostTotal
  8835. // }
  8836. //
  8837. // if item.MedChrgitmType == "08" { //材料费
  8838. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8839. // materialCostSelfTotal = materialCostTotal
  8840. // }
  8841. //
  8842. // if item.MedChrgitmType == "09" { //西药费
  8843. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8844. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8845. // }
  8846. //
  8847. // if item.MedChrgitmType == "11" { //中成费
  8848. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8849. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8850. // }
  8851. //
  8852. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8853. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8854. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8855. // otherCostSelfTotal = otherCostTotal
  8856. // }
  8857. // } else {
  8858. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8859. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8860. // otherCostSelfTotal = otherCostTotal
  8861. // }
  8862. //
  8863. // }
  8864. //
  8865. // }
  8866. //
  8867. // } else {
  8868. // for _, item := range orderInfos {
  8869. // if item.MedChrgitmType == "01" { //床位费
  8870. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8871. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8872. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8873. // }
  8874. //
  8875. // if item.MedChrgitmType == "02" { //诊察费
  8876. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8877. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8878. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8879. // }
  8880. //
  8881. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8882. // if item.MedChrgitmType == "03" { //检查费
  8883. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8884. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8885. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8886. //
  8887. // }
  8888. // } else {
  8889. // if item.MedChrgitmType == "03" { //检查费
  8890. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8891. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8892. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8893. // }
  8894. //
  8895. // }
  8896. //
  8897. // if item.MedChrgitmType == "04" { //化验费
  8898. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8899. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8900. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8901. //
  8902. // }
  8903. //
  8904. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8905. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8906. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8907. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8908. //
  8909. // }
  8910. //
  8911. // if item.MedChrgitmType == "06" { //手术费
  8912. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8913. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8914. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8915. // }
  8916. //
  8917. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8918. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8919. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8920. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8921. // }
  8922. //
  8923. // if item.MedChrgitmType == "09" { //西药费
  8924. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8925. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8926. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8927. // }
  8928. //
  8929. // if item.MedChrgitmType == "11" { //中成费
  8930. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8931. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8932. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8933. // }
  8934. //
  8935. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8936. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8937. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8938. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8939. // }
  8940. //
  8941. // }
  8942. // }
  8943. // timeLayout := "2006-01-02"
  8944. // loc, _ := time.LoadLocation("Local")
  8945. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8946. // if err != nil {
  8947. // }
  8948. // startRecordDateTime := startTime.Unix()
  8949. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8950. // if err != nil {
  8951. // }
  8952. // endRecordDateTime := endTime.Unix()
  8953. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8954. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8955. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8956. //
  8957. // c.ServeSuccessJSON(map[string]interface{}{
  8958. // "order_number": order.Number, //业务流水号
  8959. // "id_card_no": his.IdCardNo, //社会保障号
  8960. // "department_name": department.Name, //科室
  8961. // "number": his.Number, //门诊号
  8962. // "date": order.SettleAccountsDate, //结算日期
  8963. // "name": order.PsnName, //姓名
  8964. // "gender": patient.Gender, //性别
  8965. // "psn_cash_money": order.PsnCashPay, //个人支付
  8966. // "pay_way": "门诊", //结算方式
  8967. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8968. // "admin_user_name": admin.UserName, //收款员
  8969. // "order": order,
  8970. // "order_info": orderInfos_two,
  8971. // "his": his,
  8972. // "bedCostTotal": bedCostTotal,
  8973. // "bedCostSelfTotal": bedCostSelfTotal,
  8974. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8975. // "operationCostTotal": operationCostTotal,
  8976. // "operationCostSelfTotal": operationCostSelfTotal,
  8977. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8978. // "otherCostTotal": otherCostTotal,
  8979. // "otherCostSelfTotal": otherCostSelfTotal,
  8980. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8981. // "materialCostTotal": materialCostTotal,
  8982. // "materialCostSelfTotal": materialCostSelfTotal,
  8983. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8984. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8985. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8986. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8987. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8988. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8989. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8990. // "checkCostTotal": checkCostTotal,
  8991. // "checkCostSelfTotal": checkCostSelfTotal,
  8992. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8993. // "laboratoryCostTotal": laboratoryCostTotal,
  8994. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8995. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8996. // "treatCostTotal": treatCostTotal,
  8997. // "treatCostSelfTotal": treatCostSelfTotal,
  8998. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8999. // "zhenChaCostTotal": zhenChaCostTotal,
  9000. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9001. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9002. // "his_hospital_record": his_hospital_record,
  9003. // "pre_pay_money": pre_pay_money,
  9004. // "refund_sum": sum,
  9005. // })
  9006. //
  9007. //}
  9008. func (this *HisApiController) GetIncomeStatisticsData() {
  9009. start_time := this.GetString("start_time")
  9010. end_time := this.GetString("end_time")
  9011. key_words := this.GetString("key_words")
  9012. limit, _ := this.GetInt64("limit")
  9013. page, _ := this.GetInt64("page")
  9014. if page <= 0 {
  9015. page = 1
  9016. }
  9017. if limit <= 0 {
  9018. limit = 10
  9019. }
  9020. statistics_type, _ := this.GetInt64("statistics_type")
  9021. admin := this.GetAdminUserInfo()
  9022. timeLayout := "2006-01-02"
  9023. loc, _ := time.LoadLocation("Local")
  9024. var theStartTIme int64
  9025. if len(start_time) > 0 {
  9026. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9027. if err != nil {
  9028. theStartTIme = 0
  9029. }
  9030. theStartTIme = theTime.Unix()
  9031. }
  9032. var theEndtTIme int64
  9033. if len(end_time) > 0 {
  9034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9035. if err != nil {
  9036. theEndtTIme = 0
  9037. }
  9038. theEndtTIme = theTime.Unix()
  9039. }
  9040. if statistics_type == 1 {
  9041. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9042. this.ServeSuccessJSON(map[string]interface{}{
  9043. "list": list,
  9044. "total": total,
  9045. })
  9046. } else {
  9047. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9048. this.ServeSuccessJSON(map[string]interface{}{
  9049. "list": list,
  9050. "total": total,
  9051. })
  9052. }
  9053. }
  9054. func (c *HisApiController) PostProjectInformation() {
  9055. adminUser := c.GetAdminUserInfo()
  9056. orgId := adminUser.CurrentOrgId
  9057. dataBody := make(map[string]interface{}, 0)
  9058. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9059. if err != nil {
  9060. utils.ErrorLog(err.Error())
  9061. return
  9062. }
  9063. utils.ErrorLog("%v", dataBody)
  9064. var projectList []*models.HisProject
  9065. var total_goods []interface{}
  9066. tempProjects := dataBody["projects"].([]interface{})
  9067. total_goods = tempProjects
  9068. for index, projectMap := range tempProjects {
  9069. projectM := projectMap.(map[string]interface{})
  9070. var project models.HisProject
  9071. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9072. utils.ErrorLog("project_name")
  9073. return
  9074. }
  9075. project_name, _ := projectM["project_name"].(string)
  9076. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9077. err_log := models.ExportErrLog{
  9078. LogType: 6,
  9079. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9080. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9081. Status: 1,
  9082. CreateTime: time.Now().Unix(),
  9083. UpdateTime: time.Now().Unix(),
  9084. ExportTime: time.Now().Unix(),
  9085. }
  9086. service.CreateExportErrLog(&err_log)
  9087. continue
  9088. }
  9089. project.ProjectName = project_name
  9090. prices := projectM["price"].(string)
  9091. price, _ := strconv.ParseFloat(prices, 64)
  9092. if price <= 0 { //名字为空则生成一条导入错误日志
  9093. err_log := models.ExportErrLog{
  9094. LogType: 6,
  9095. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9096. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  9097. Status: 1,
  9098. CreateTime: time.Now().Unix(),
  9099. UpdateTime: time.Now().Unix(),
  9100. ExportTime: time.Now().Unix(),
  9101. }
  9102. service.CreateExportErrLog(&err_log)
  9103. continue
  9104. }
  9105. project.Price = price
  9106. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  9107. utils.ErrorLog("unit_id")
  9108. return
  9109. }
  9110. unit := projectM["unit"].(string)
  9111. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  9112. err_log := models.ExportErrLog{
  9113. LogType: 6,
  9114. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9115. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  9116. Status: 1,
  9117. CreateTime: time.Now().Unix(),
  9118. UpdateTime: time.Now().Unix(),
  9119. ExportTime: time.Now().Unix(),
  9120. }
  9121. service.CreateExportErrLog(&err_log)
  9122. continue
  9123. }
  9124. project.Unit = unit
  9125. cost_classify := projectM["cost_classify"].(string)
  9126. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  9127. err_log := models.ExportErrLog{
  9128. LogType: 6,
  9129. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9130. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9131. Status: 1,
  9132. CreateTime: time.Now().Unix(),
  9133. UpdateTime: time.Now().Unix(),
  9134. ExportTime: time.Now().Unix(),
  9135. }
  9136. service.CreateExportErrLog(&err_log)
  9137. continue
  9138. }
  9139. var costClassify = "费用类别"
  9140. var cost_classify_id int64
  9141. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  9142. if len(cost_classify) != 0 {
  9143. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  9144. if errcode == gorm.ErrRecordNotFound {
  9145. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  9146. dataconfig := models.DictDataconfig{
  9147. ParentId: costClassifyConfig.ID,
  9148. Module: "system",
  9149. OrgId: orgId,
  9150. Name: cost_classify,
  9151. FieldName: "",
  9152. Value: costConfig.Value + 1,
  9153. CreatedTime: "",
  9154. UpdatedTime: "",
  9155. CreateUserId: adminUser.AdminUser.Id,
  9156. Status: 1,
  9157. Remark: "",
  9158. DeleteIdSystem: 0,
  9159. Title: "",
  9160. Content: "",
  9161. Order: 0,
  9162. Code: "",
  9163. }
  9164. service.CreatedDicConfig(&dataconfig)
  9165. }
  9166. }
  9167. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  9168. for _, it := range costClassList {
  9169. if cost_classify == it.Name {
  9170. cost_classify_id = int64(it.Value)
  9171. }
  9172. }
  9173. project.CostClassify = cost_classify_id
  9174. executive_section := projectM["executive_section"].(string)
  9175. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  9176. err_log := models.ExportErrLog{
  9177. LogType: 6,
  9178. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9179. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  9180. Status: 1,
  9181. CreateTime: time.Now().Unix(),
  9182. UpdateTime: time.Now().Unix(),
  9183. ExportTime: time.Now().Unix(),
  9184. }
  9185. service.CreateExportErrLog(&err_log)
  9186. continue
  9187. }
  9188. if len(executive_section) != 0 {
  9189. //查找科室是否有内容
  9190. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  9191. if errcodedepart == gorm.ErrRecordNotFound {
  9192. department := models.XtHisDepartment{
  9193. Name: executive_section,
  9194. Status: 1,
  9195. UserOrgId: adminUser.CurrentOrgId,
  9196. CreatedTime: time.Now().Unix(),
  9197. }
  9198. service.CreateDePartment(&department)
  9199. }
  9200. }
  9201. var executive_section_id int64
  9202. departMentList, _ := service.GetAllDepartMent(orgId)
  9203. for _, it := range departMentList {
  9204. if executive_section == it.Name {
  9205. executive_section_id = it.ID
  9206. }
  9207. }
  9208. project.ExecutiveSection = executive_section_id
  9209. medical_coverage := projectM["medical_coverage"].(string)
  9210. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  9211. err_log := models.ExportErrLog{
  9212. LogType: 6,
  9213. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9214. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9215. Status: 1,
  9216. CreateTime: time.Now().Unix(),
  9217. UpdateTime: time.Now().Unix(),
  9218. ExportTime: time.Now().Unix(),
  9219. }
  9220. service.CreateExportErrLog(&err_log)
  9221. continue
  9222. }
  9223. var medicalCoverage = "医保等级"
  9224. var medical_coverage_id int64
  9225. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  9226. if len(medical_coverage) != 0 {
  9227. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  9228. if errormedicalcoverage == gorm.ErrRecordNotFound {
  9229. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  9230. dataconfig := models.DictDataconfig{
  9231. ParentId: medicalCoverageConfig.ID,
  9232. Module: "system",
  9233. OrgId: orgId,
  9234. Name: medical_coverage,
  9235. FieldName: "",
  9236. Value: medicalCoverageConfig.Value + 1,
  9237. CreatedTime: "",
  9238. UpdatedTime: "",
  9239. CreateUserId: adminUser.AdminUser.Id,
  9240. Status: 1,
  9241. Remark: "",
  9242. DeleteIdSystem: 0,
  9243. Title: "",
  9244. Content: "",
  9245. Order: 0,
  9246. Code: "",
  9247. }
  9248. service.CreatedDicConfig(&dataconfig)
  9249. }
  9250. }
  9251. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  9252. for _, it := range medicalCoverageList {
  9253. if medical_coverage == it.Name {
  9254. medical_coverage_id = int64(it.Value)
  9255. }
  9256. }
  9257. project.MedicalCoverage = medical_coverage_id
  9258. pinyin := projectM["pinyin"].(string)
  9259. project.Pinyin = pinyin
  9260. wubi := projectM["wubi"].(string)
  9261. project.Wubi = wubi
  9262. statistical_classification := projectM["statistical_classification"].(string)
  9263. var statisticalClassification = "统计分类"
  9264. var statistical_classification_id int64
  9265. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  9266. if len(statistical_classification) != 0 {
  9267. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  9268. if classificationerrcodes == gorm.ErrRecordNotFound {
  9269. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  9270. dataconfig := models.DictDataconfig{
  9271. ParentId: classiFication.ID,
  9272. Module: "system",
  9273. OrgId: orgId,
  9274. Name: statistical_classification,
  9275. FieldName: "",
  9276. Value: classiFicationConfig.Value + 1,
  9277. CreatedTime: "",
  9278. UpdatedTime: "",
  9279. CreateUserId: adminUser.AdminUser.Id,
  9280. Status: 1,
  9281. Remark: "",
  9282. DeleteIdSystem: 0,
  9283. Title: "",
  9284. Content: "",
  9285. Order: 0,
  9286. Code: "",
  9287. }
  9288. service.CreatedDicConfig(&dataconfig)
  9289. }
  9290. }
  9291. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  9292. for _, it := range classiFicationList {
  9293. if statistical_classification == it.Name {
  9294. statistical_classification_id = int64(it.Value)
  9295. }
  9296. }
  9297. project.StatisticalClassification = statistical_classification_id
  9298. disease_directory := int64(projectM["disease_directory"].(float64))
  9299. project.DiseaseDirectory = disease_directory
  9300. is_record := int64(projectM["is_record"].(float64))
  9301. project.IsRecord = is_record
  9302. medical_code := projectM["medical_code"].(string)
  9303. project.MedicalCode = medical_code
  9304. tube_color := projectM["tube_color"].(string)
  9305. var tubeColor = "试管颜色"
  9306. var tube_color_id int64
  9307. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  9308. if len(tube_color) != 0 {
  9309. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  9310. if errcodetube == gorm.ErrRecordNotFound {
  9311. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  9312. dataconfig := models.DictDataconfig{
  9313. ParentId: tubeColorConfig.ID,
  9314. Module: "system",
  9315. OrgId: orgId,
  9316. Name: tube_color,
  9317. FieldName: "",
  9318. Value: tubeConfig.Value + 1,
  9319. CreatedTime: "",
  9320. UpdatedTime: "",
  9321. CreateUserId: adminUser.AdminUser.Id,
  9322. Status: 1,
  9323. Remark: "",
  9324. DeleteIdSystem: 0,
  9325. Title: "",
  9326. Content: "",
  9327. Order: 0,
  9328. Code: "",
  9329. }
  9330. service.CreatedDicConfig(&dataconfig)
  9331. }
  9332. }
  9333. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  9334. for _, it := range tubeColorList {
  9335. if tube_color == it.Name {
  9336. tube_color_id = int64(it.Value)
  9337. }
  9338. }
  9339. project.TubeColor = tube_color_id
  9340. single_dose := projectM["single_dose"].(string)
  9341. project.SingleDose = single_dose
  9342. execution_frequency := projectM["execution_frequency"].(string)
  9343. project.ExecutionFrequency = execution_frequency
  9344. delivery_way := projectM["delivery_way"].(string)
  9345. project.DeliveryWay = delivery_way
  9346. number_days := projectM["number_days"].(string)
  9347. project.NumberDays = number_days
  9348. total := projectM["total"].(string)
  9349. project.Total = total
  9350. medical_status := int64(projectM["medical_status"].(float64))
  9351. project.MedicalStatus = medical_status
  9352. category := int64(projectM["category"].(float64))
  9353. project.Category = category
  9354. specail_project := int64(projectM["specail_project"].(float64))
  9355. project.SpecailProject = specail_project
  9356. social_security_directory_code := projectM["social_security_directory_code"].(string)
  9357. project.SocialSecurityDirectoryCode = social_security_directory_code
  9358. remark := projectM["remark"].(string)
  9359. project.Remark = remark
  9360. record_date := projectM["record_date"].(string)
  9361. timeLayout := "2006-01-02"
  9362. loc, _ := time.LoadLocation("Local")
  9363. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9364. project.RecordDate = theTime.Unix()
  9365. projectList = append(projectList, &project)
  9366. }
  9367. export_time := time.Now().Unix()
  9368. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  9369. if len(projectList) > 0 {
  9370. for _, item := range projectList {
  9371. project := models.HisProject{
  9372. ProjectName: item.ProjectName,
  9373. Price: item.Price,
  9374. Unit: item.Unit,
  9375. CostClassify: item.CostClassify,
  9376. ExecutiveSection: item.ExecutiveSection,
  9377. MedicalCoverage: item.MedicalCoverage,
  9378. UserOrgId: orgId,
  9379. Status: 1,
  9380. CreatedTime: time.Now().Unix(),
  9381. Pinyin: item.Pinyin,
  9382. Wubi: item.Wubi,
  9383. StatisticalClassification: item.StatisticalClassification,
  9384. DiseaseDirectory: item.DiseaseDirectory,
  9385. IsRecord: item.IsRecord,
  9386. MedicalCode: item.MedicalCode,
  9387. TubeColor: item.TubeColor,
  9388. SingleDose: item.SingleDose,
  9389. DeliveryWay: item.DeliveryWay,
  9390. NumberDays: item.NumberDays,
  9391. Total: item.Total,
  9392. Category: item.Category,
  9393. MedicalStatus: item.MedicalStatus,
  9394. SpecailProject: item.SpecailProject,
  9395. RecordDate: item.RecordDate,
  9396. Remark: item.Remark,
  9397. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  9398. ExecutionFrequency: item.ExecutionFrequency,
  9399. }
  9400. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  9401. if errcodeproject == gorm.ErrRecordNotFound {
  9402. service.CreateProjectInfomation(&project)
  9403. } else if errcodeproject == nil {
  9404. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  9405. }
  9406. log := models.ExportLog{
  9407. LogType: 6,
  9408. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9409. TotalNum: int64(len(total_goods)),
  9410. FailNum: int64(len(errLogs)),
  9411. SuccessNum: int64(len(projectList)),
  9412. CreateTime: time.Now().Unix(),
  9413. UpdateTime: time.Now().Unix(),
  9414. ExportTime: export_time,
  9415. Status: 1,
  9416. }
  9417. service.CreateExportLog(&log)
  9418. c.ServeSuccessJSON(map[string]interface{}{
  9419. "msg": "导入成功",
  9420. "total_num": len(total_goods),
  9421. "success_num": len(projectList),
  9422. "fail_num": int64(len(errLogs)),
  9423. })
  9424. }
  9425. } else {
  9426. log := models.ExportLog{
  9427. LogType: 6,
  9428. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9429. TotalNum: int64(len(total_goods)),
  9430. FailNum: int64(len(errLogs)),
  9431. SuccessNum: int64(len(projectList)),
  9432. CreateTime: time.Now().Unix(),
  9433. UpdateTime: time.Now().Unix(),
  9434. ExportTime: export_time,
  9435. Status: 1,
  9436. }
  9437. service.CreateExportLog(&log)
  9438. c.ServeSuccessJSON(map[string]interface{}{
  9439. "msg": "导入成功",
  9440. "total_num": len(total_goods),
  9441. "success_num": len(projectList),
  9442. "fail_num": int64(len(errLogs)),
  9443. })
  9444. }
  9445. }
  9446. //func (this *HisApiController) EditProjectInformation(){
  9447. //
  9448. // id, _ := this.GetInt64("id")
  9449. // project_team := this.GetString("project_team")
  9450. // price := this.GetString("price")
  9451. // price_float, _ := strconv.ParseFloat(price, 64)
  9452. // pinyin := this.GetString("pinyin")
  9453. // wubi := this.GetString("wubi")
  9454. // tube_color, _ := this.GetInt64("tube_color")
  9455. // team_type, _ := this.GetInt64("team_type")
  9456. // remark := this.GetString("remark")
  9457. // ids := this.GetString("ids")
  9458. // item_id := this.GetString("item_id")
  9459. // projectTeam := models.XtHisProjectTeam{
  9460. // ProjectTeam: project_team,
  9461. // Price: price_float,
  9462. // Pinyin: pinyin,
  9463. // Wubi: wubi,
  9464. // TubeColor: tube_color,
  9465. // TeamType: team_type,
  9466. // Remark: remark,
  9467. // ProjectId: ids,
  9468. // ItemId: item_id,
  9469. // }
  9470. //
  9471. //
  9472. // dataBody := make(map[string]interface{}, 0)
  9473. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9474. // if err != nil {
  9475. // utils.ErrorLog(err.Error())
  9476. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9477. // return
  9478. // }
  9479. //
  9480. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9481. //
  9482. //
  9483. // if err != nil {
  9484. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9485. // return
  9486. // }
  9487. //
  9488. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9489. // infos, _ := dataBody["info"].([]interface{})
  9490. // if len(infos) > 0 {
  9491. // var ids []string
  9492. //
  9493. // for _, item := range infos {
  9494. // items := item.(map[string]interface{})
  9495. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9496. // utils.ErrorLog("id")
  9497. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9498. // return
  9499. // }
  9500. // id := int64(items["id"].(float64))
  9501. //
  9502. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9503. // utils.ErrorLog("type")
  9504. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9505. // return
  9506. // }
  9507. // types := int64(items["type"].(float64))
  9508. //
  9509. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9510. // utils.ErrorLog("number")
  9511. // }
  9512. //
  9513. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9514. //
  9515. // projectList := models.XtHisProjectList{
  9516. // Number: number,
  9517. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9518. // ProjectId: id,
  9519. // Status: 1,
  9520. // CreatedTime: time.Now().Unix(),
  9521. // UpdatedTime: time.Now().Unix(),
  9522. // TeamId: projectTeam.ID,
  9523. // Type: types,
  9524. // }
  9525. // list := projectList
  9526. //
  9527. // service.CreateProjectList(&list)
  9528. //
  9529. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9530. //
  9531. // }
  9532. // ids_str := strings.Join(ids, ",")
  9533. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9534. // service.SaveProjectTeam(&projectTeam)
  9535. // this.ServeSuccessJSON(map[string]interface{}{
  9536. // "projectTeam": projectTeam,
  9537. // })
  9538. // }
  9539. // }
  9540. //}
  9541. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9542. name := c.GetString("name")
  9543. mode_id, _ := c.GetInt64("mode", 0)
  9544. types, _ := c.GetInt64("type", 0)
  9545. patient_id, _ := c.GetInt64("patient_id", 0)
  9546. types = 1
  9547. adminInfo := c.GetAdminUserInfo()
  9548. template := &models.HisPrescriptionTemplate{
  9549. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9550. PatientId: patient_id,
  9551. Type: types,
  9552. Status: 1,
  9553. Ctime: time.Now().Unix(),
  9554. Mtime: time.Now().Unix(),
  9555. Name: name,
  9556. Mode: mode_id,
  9557. }
  9558. dataBody := make(map[string]interface{}, 0)
  9559. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9560. if err != nil {
  9561. utils.ErrorLog(err.Error())
  9562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9563. return
  9564. }
  9565. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9566. //如果已经存在记录则删除处方
  9567. if template_one.ID > 0 {
  9568. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9569. var ids []int64
  9570. var org_id int64
  9571. for _, item := range ps {
  9572. org_id = c.GetAdminUserInfo().CurrentOrgId
  9573. ids = append(ids, item.ID)
  9574. }
  9575. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  9576. if err2 == nil {
  9577. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9578. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9579. if len(prescriptions) > 0 {
  9580. for _, item := range prescriptions {
  9581. items := item.(map[string]interface{})
  9582. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9583. utils.ErrorLog("type")
  9584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9585. return
  9586. }
  9587. types := int64(items["type"].(float64))
  9588. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9589. utils.ErrorLog("med_type")
  9590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9591. return
  9592. }
  9593. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9594. ctime := time.Now().Unix()
  9595. prescription := &models.HisPrescriptionInfoTemplate{
  9596. PatientId: patient_id,
  9597. UserOrgId: adminInfo.CurrentOrgId,
  9598. Ctime: ctime,
  9599. Mtime: ctime,
  9600. Type: types,
  9601. Modifier: adminInfo.AdminUser.Id,
  9602. Creator: adminInfo.AdminUser.Id,
  9603. Status: 1,
  9604. PTemplateId: template_one.ID,
  9605. MedType: med_type,
  9606. }
  9607. service.CreateHisPrescriptionInfoTemplate(prescription)
  9608. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9609. advices := items["advices"].([]interface{})
  9610. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9611. ctime := time.Now().Unix()
  9612. mtime := ctime
  9613. if len(advices) > 0 {
  9614. for _, advice := range advices {
  9615. var s models.HisPrescriptionAdviceTemplate
  9616. s.PrescriptionId = prescription.ID
  9617. s.AdviceType = 2
  9618. s.StopState = 2
  9619. s.ExecutionState = 2
  9620. s.Status = 1
  9621. s.UserOrgId = adminInfo.CurrentOrgId
  9622. s.CreatedTime = ctime
  9623. s.UpdatedTime = mtime
  9624. s.PatientId = patient_id
  9625. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9626. if errcode > 0 {
  9627. c.ServeFailJSONWithSGJErrorCode(errcode)
  9628. return
  9629. }
  9630. service.CreateHisPrescriptionAdviceTemplate(&s)
  9631. }
  9632. }
  9633. }
  9634. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9635. projects := items["project"].([]interface{})
  9636. if len(projects) > 0 {
  9637. for _, project := range projects {
  9638. var p models.HisPrescriptionProjectTemplate
  9639. p.PrescriptionId = prescription.ID
  9640. p.Ctime = time.Now().Unix()
  9641. p.Mtime = time.Now().Unix()
  9642. p.PatientId = patient_id
  9643. p.UserOrgId = adminInfo.CurrentOrgId
  9644. p.Status = 1
  9645. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9646. if errcode > 0 {
  9647. c.ServeFailJSONWithSGJErrorCode(errcode)
  9648. return
  9649. }
  9650. service.CreateHisPrescriptionProjectTemplate(&p)
  9651. }
  9652. }
  9653. }
  9654. }
  9655. c.ServeSuccessJSON(map[string]interface{}{
  9656. "msg": "创建成功",
  9657. })
  9658. }
  9659. }
  9660. } else {
  9661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9662. return
  9663. }
  9664. } else {
  9665. err3 := service.CreateHisPrescriptionTemplate(template)
  9666. if err3 == nil {
  9667. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9668. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9669. if len(prescriptions) > 0 {
  9670. for _, item := range prescriptions {
  9671. items := item.(map[string]interface{})
  9672. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9673. utils.ErrorLog("type")
  9674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9675. return
  9676. }
  9677. types := int64(items["type"].(float64))
  9678. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9679. utils.ErrorLog("med_type")
  9680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9681. return
  9682. }
  9683. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9684. ctime := time.Now().Unix()
  9685. prescription := &models.HisPrescriptionInfoTemplate{
  9686. PatientId: patient_id,
  9687. UserOrgId: adminInfo.CurrentOrgId,
  9688. Ctime: ctime,
  9689. Mtime: ctime,
  9690. Type: types,
  9691. Modifier: adminInfo.AdminUser.Id,
  9692. Creator: adminInfo.AdminUser.Id,
  9693. Status: 1,
  9694. PTemplateId: template.ID,
  9695. MedType: med_type,
  9696. }
  9697. service.CreateHisPrescriptionInfoTemplate(prescription)
  9698. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9699. advices := items["advices"].([]interface{})
  9700. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9701. ctime := time.Now().Unix()
  9702. mtime := ctime
  9703. if len(advices) > 0 {
  9704. for _, advice := range advices {
  9705. var s models.HisPrescriptionAdviceTemplate
  9706. s.PrescriptionId = prescription.ID
  9707. s.AdviceType = 2
  9708. s.StopState = 2
  9709. s.ExecutionState = 2
  9710. s.Status = 1
  9711. s.UserOrgId = adminInfo.CurrentOrgId
  9712. s.CreatedTime = ctime
  9713. s.UpdatedTime = mtime
  9714. s.PatientId = patient_id
  9715. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9716. if errcode > 0 {
  9717. c.ServeFailJSONWithSGJErrorCode(errcode)
  9718. return
  9719. }
  9720. service.CreateHisPrescriptionAdviceTemplate(&s)
  9721. }
  9722. }
  9723. }
  9724. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9725. projects := items["project"].([]interface{})
  9726. if len(projects) > 0 {
  9727. for _, project := range projects {
  9728. var p models.HisPrescriptionProjectTemplate
  9729. p.PrescriptionId = prescription.ID
  9730. p.Ctime = time.Now().Unix()
  9731. p.Mtime = time.Now().Unix()
  9732. p.PatientId = patient_id
  9733. p.UserOrgId = adminInfo.CurrentOrgId
  9734. p.Status = 1
  9735. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9736. if errcode > 0 {
  9737. c.ServeFailJSONWithSGJErrorCode(errcode)
  9738. return
  9739. }
  9740. service.CreateHisPrescriptionProjectTemplate(&p)
  9741. }
  9742. }
  9743. }
  9744. }
  9745. c.ServeSuccessJSON(map[string]interface{}{
  9746. "msg": "创建成功",
  9747. })
  9748. }
  9749. }
  9750. } else {
  9751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9752. return
  9753. }
  9754. }
  9755. }
  9756. func (c *HisApiController) PreSettle() {
  9757. id, _ := c.GetInt64("id")
  9758. record_time := c.GetString("record_time")
  9759. his_patient_id, _ := c.GetInt64("his_patient_id")
  9760. timeLayout := "2006-01-02"
  9761. loc, _ := time.LoadLocation("Local")
  9762. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9763. diagnosis_id := c.GetString("diagnosis")
  9764. sick_type, _ := c.GetInt64("sick_type")
  9765. reg_type, _ := c.GetInt64("p_type")
  9766. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9767. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9768. if err != nil {
  9769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9770. return
  9771. }
  9772. recordDateTime := theTime.Unix()
  9773. adminUser := c.GetAdminUserInfo()
  9774. var prescriptions []*models.HisPrescription
  9775. var start_time int64
  9776. var end_time int64
  9777. ids_str := c.GetString("ids")
  9778. ids_arr := strings.Split(ids_str, ",")
  9779. fmt.Println(reg_type)
  9780. if settle_accounts_type == 1 { //日结
  9781. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9782. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9783. } else {
  9784. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9785. }
  9786. fmt.Println(prescriptions)
  9787. } else { //月结
  9788. start_time_str := c.GetString("start_time")
  9789. end_time_str := c.GetString("end_time")
  9790. timeLayout := "2006-01-02"
  9791. loc, _ := time.LoadLocation("Local")
  9792. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9793. if err != nil {
  9794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9795. return
  9796. }
  9797. recordStartTime := theStartTime.Unix()
  9798. start_time = recordStartTime
  9799. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9800. if err != nil {
  9801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9802. return
  9803. }
  9804. recordEndTime := theEndTime.Unix()
  9805. end_time = recordEndTime
  9806. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9807. }
  9808. if reg_type == 1111 || reg_type == 1112 {
  9809. reg_type = 11
  9810. }
  9811. timestamp := time.Now().Unix()
  9812. tempTime := time.Unix(timestamp, 0)
  9813. timeFormat := tempTime.Format("20060102150405")
  9814. chrgBchno := rand.Intn(100000) + 10000
  9815. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9816. strconv.FormatInt(his.PatientId, 10)
  9817. var ids []int64
  9818. for _, item := range prescriptions {
  9819. ids = append(ids, item.ID)
  9820. }
  9821. fmt.Println(ids)
  9822. var total float64
  9823. for _, item := range prescriptions {
  9824. fmt.Println(item)
  9825. if item.Type == 1 { //药品
  9826. for _, subItem := range item.HisDoctorAdviceInfo {
  9827. total = total + (subItem.Price * subItem.PrescribingNumber)
  9828. }
  9829. }
  9830. if item.Type == 2 { //项目
  9831. for _, subItem := range item.HisPrescriptionProject {
  9832. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9833. total = total + (subItem.Price * cnt)
  9834. }
  9835. }
  9836. for _, subItem := range item.HisAdditionalCharge {
  9837. total = total + (subItem.Price * float64(subItem.Count))
  9838. }
  9839. }
  9840. allTotal := fmt.Sprintf("%.2f", total)
  9841. totals, _ := strconv.ParseFloat(allTotal, 64)
  9842. order := &models.HisOrder{
  9843. UserOrgId: adminUser.CurrentOrgId,
  9844. HisPatientId: his.ID,
  9845. PatientId: id,
  9846. SettleAccountsDate: recordDateTime,
  9847. Ctime: time.Now().Unix(),
  9848. Mtime: time.Now().Unix(),
  9849. Status: 1,
  9850. OrderStatus: 1,
  9851. MdtrtId: his.Number,
  9852. Number: chrg_bchno,
  9853. MedfeeSumamt: totals,
  9854. SettleEndTime: end_time,
  9855. SettleStartTime: start_time,
  9856. SettleType: settle_accounts_type,
  9857. PsnPartAmt: totals,
  9858. PsnCashPay: totals,
  9859. PType: 2,
  9860. IsPre: 1,
  9861. MedType: strconv.Itoa(int(reg_type)),
  9862. Diagnosis: diagnosis_id,
  9863. }
  9864. err = service.CreateOrder(order)
  9865. if err != nil {
  9866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9867. return
  9868. }
  9869. var customs []*Custom
  9870. for _, item := range prescriptions {
  9871. fmt.Println(item.Type)
  9872. if item.Type == 1 { //药品
  9873. for _, subItem := range item.HisDoctorAdviceInfo {
  9874. cus := &Custom{
  9875. AdviceId: subItem.ID,
  9876. ProjectId: 0,
  9877. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9878. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9879. FeedetlSn: subItem.FeedetlSn,
  9880. Price: fmt.Sprintf("%.2f", subItem.Price),
  9881. MedListCodg: subItem.MedListCodg,
  9882. Type: 1,
  9883. }
  9884. customs = append(customs, cus)
  9885. }
  9886. }
  9887. if item.Type == 2 { //项目
  9888. for _, subItem := range item.HisPrescriptionProject {
  9889. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9890. cus := &Custom{
  9891. AdviceId: 0,
  9892. ProjectId: subItem.ID,
  9893. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9894. Cut: fmt.Sprintf("%.2f", cnt),
  9895. FeedetlSn: subItem.FeedetlSn,
  9896. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9897. MedListCodg: subItem.MedListCodg,
  9898. Type: 2,
  9899. }
  9900. customs = append(customs, cus)
  9901. }
  9902. }
  9903. for _, item := range item.HisAdditionalCharge {
  9904. cus := &Custom{
  9905. ItemId: item.ID,
  9906. AdviceId: 0,
  9907. ProjectId: 0,
  9908. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9909. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9910. FeedetlSn: item.FeedetlSn,
  9911. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9912. MedListCodg: item.XtHisAddtionConfig.Code,
  9913. Type: 3,
  9914. }
  9915. customs = append(customs, cus)
  9916. }
  9917. }
  9918. fmt.Println(customs)
  9919. for _, item := range customs {
  9920. var advice_id int64 = 0
  9921. var project_id int64 = 0
  9922. var item_id int64 = 0
  9923. var types int64 = 0
  9924. if item.Type == 1 {
  9925. advice_id = item.AdviceId
  9926. project_id = 0
  9927. item_id = 0
  9928. } else if item.Type == 2 {
  9929. advice_id = 0
  9930. item_id = 0
  9931. project_id = item.ProjectId
  9932. } else if item.Type == 3 {
  9933. advice_id = 0
  9934. item_id = item.ItemId
  9935. project_id = 0
  9936. }
  9937. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9938. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9939. pric, _ := strconv.ParseFloat(item.Price, 32)
  9940. info := &models.HisOrderInfo{
  9941. OrderNumber: order.Number,
  9942. UploadDate: time.Now().Unix(),
  9943. AdviceId: advice_id,
  9944. DetItemFeeSumamt: detItemFeeSumamt,
  9945. Cnt: cut,
  9946. Pric: pric,
  9947. PatientId: id,
  9948. Status: 1,
  9949. Mtime: time.Now().Unix(),
  9950. Ctime: time.Now().Unix(),
  9951. UserOrgId: adminUser.CurrentOrgId,
  9952. HisPatientId: his.ID,
  9953. OrderId: order.ID,
  9954. ProjectId: project_id,
  9955. Type: types,
  9956. ItemId: item_id,
  9957. }
  9958. service.CreateOrderInfo(info)
  9959. }
  9960. his.SickType = sick_type
  9961. service.UpdataHisPateint(&his)
  9962. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9963. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9964. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9965. if err == nil {
  9966. c.ServeSuccessJSON(map[string]interface{}{
  9967. "msg": "结算成功",
  9968. })
  9969. }
  9970. }
  9971. type CustomOrderInfo struct {
  9972. Name string
  9973. Spec string
  9974. Unit string
  9975. Count float64
  9976. Price float64
  9977. Total float64
  9978. }
  9979. func (c *HisApiController) GetPrivateExpensesInfo() {
  9980. order_id, _ := c.GetInt64("id", 0)
  9981. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9982. order, _ := service.GetHisOrderByID(order_id)
  9983. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9984. if order.ID == 0 {
  9985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9986. return
  9987. }
  9988. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9989. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9990. org_id := c.GetAdminUserInfo().CurrentOrgId
  9991. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9992. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9993. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9994. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9995. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9996. //var orderInfos_four []*models.HisOrderInfoTwo
  9997. //for _, item := range orderInfos_three {
  9998. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9999. // item.HisPrescriptionProject.IsCheckTeam = 1
  10000. // orderInfos_four = append(orderInfos_four, item)
  10001. //
  10002. // }
  10003. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10004. // item.HisPrescriptionProject.IsCheckTeam = 2
  10005. // orderInfos_two = append(orderInfos_two, item)
  10006. // }
  10007. //}
  10008. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10009. //var cus_slice []CustomOrderInfo
  10010. //for _, item := range new_order_info {
  10011. // var cus CustomOrderInfo
  10012. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10013. // cus.Unit = ""
  10014. // cus.Spec = ""
  10015. // var total float64
  10016. // for _, subItem := range orderInfos_four {
  10017. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10018. // total = total + subItem.DetItemFeeSumamt
  10019. // fmt.Println(subItem.DetItemFeeSumamt)
  10020. // }
  10021. // }
  10022. // cus.Count = 1
  10023. // cus.Total = total
  10024. // cus_slice = append(cus_slice, cus)
  10025. //}
  10026. orderInfos = append(orderInfos, orderInfos_two...)
  10027. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10028. //orderInfos = append(orderInfos, orderInfos_three...)
  10029. //}/**/
  10030. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10031. c.ServeSuccessJSON(map[string]interface{}{
  10032. "order": order,
  10033. "order_info": orderInfos,
  10034. "patient": patient,
  10035. "admin_info": adminInfo,
  10036. "his": his,
  10037. "current_admin": role,
  10038. "org_config": miConfig,
  10039. //"new_order_info": cus_slice,
  10040. })
  10041. }
  10042. func (this *HisApiController) ChangeMedType() {
  10043. med_type := this.GetString("med_type")
  10044. old_med_type := this.GetString("old_med_type")
  10045. ids := this.GetString("ids")
  10046. settle_type, _ := this.GetInt64("settle_type")
  10047. start_time := this.GetString("start_time")
  10048. end_time := this.GetString("end_time")
  10049. ids_arr := strings.Split(ids, ",")
  10050. if settle_type == 1 { //日结
  10051. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10052. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10053. prescription.MedType = med_type
  10054. err := service.SaveHisPrescriptionTwo(&prescription)
  10055. if err == nil {
  10056. this.ServeSuccessJSON(map[string]interface{}{
  10057. "msg": "修改成功",
  10058. })
  10059. } else {
  10060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10061. return
  10062. }
  10063. } else if settle_type == 2 {
  10064. timeLayout := "2006-01-02"
  10065. loc, _ := time.LoadLocation("Local")
  10066. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10067. if err != nil {
  10068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10069. return
  10070. }
  10071. recordStartTime := theStartTime.Unix()
  10072. start_time_timestamp := recordStartTime
  10073. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10074. if err != nil {
  10075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10076. return
  10077. }
  10078. recordEndTime := theEndTime.Unix()
  10079. end_time_timestamp := recordEndTime
  10080. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10081. if updateErr == nil {
  10082. this.ServeSuccessJSON(map[string]interface{}{
  10083. "msg": "修改成功",
  10084. })
  10085. } else {
  10086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10087. return
  10088. }
  10089. }
  10090. }
  10091. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10092. patient_id, _ := c.GetInt64("patient_id")
  10093. his_patient_id, _ := c.GetInt64("his_patient_id")
  10094. record_date := c.GetString("record_date")
  10095. start_time := c.GetString("start_time")
  10096. end_time := c.GetString("end_time")
  10097. order_status, _ := c.GetInt64("type", 0)
  10098. p_type, _ := c.GetInt64("p_type", 0)
  10099. order_id, _ := c.GetInt64("order_id", 0)
  10100. timeLayout := "2006-01-02"
  10101. loc, _ := time.LoadLocation("Local")
  10102. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10103. if err != nil {
  10104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10105. return
  10106. }
  10107. recordDateTime := theTime.Unix()
  10108. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10109. if err != nil {
  10110. }
  10111. startRecordDateTime := startTime.Unix()
  10112. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10113. if err != nil {
  10114. }
  10115. endRecordDateTime := endTime.Unix()
  10116. admin := c.GetAdminUserInfo()
  10117. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10118. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10119. order, _ := service.GetHisOrderByID(order_id)
  10120. var monthPrescriptions []*models.HisPrescription
  10121. if order_status == 1 || order_status == 0 {
  10122. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10123. } else if order_status == 2 {
  10124. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10125. }
  10126. var settle_total float64
  10127. for _, item := range monthPrescriptions {
  10128. if len(item.HisPrescriptionProject) > 0 {
  10129. for _, subItem := range item.HisPrescriptionProject {
  10130. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10131. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10132. settle_total = settle_total + total
  10133. }
  10134. }
  10135. if len(item.HisDoctorAdviceInfo) > 0 {
  10136. for _, subItem := range item.HisDoctorAdviceInfo {
  10137. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10138. settle_total = settle_total + total
  10139. }
  10140. }
  10141. }
  10142. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10143. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10144. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10145. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10146. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10147. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10148. //获取所有科室信息
  10149. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10150. var dia string
  10151. for _, item := range month_p_info {
  10152. if len(dia) == 0 {
  10153. dia = item.Diagnosis
  10154. } else {
  10155. dia = dia + "," + item.Diagnosis
  10156. }
  10157. }
  10158. dia_arr := removeDuplicates(strings.Split(dia, ","))
  10159. dia_arr = removeEmptyStrings(dia_arr)
  10160. c.ServeSuccessJSON(map[string]interface{}{
  10161. "his_info": his_patient_info,
  10162. "xt_info": xt_patient_info,
  10163. "case_history": case_history,
  10164. "info": patientPrescriptionInfo,
  10165. "last_info": lastPatientPrescriptionInfo,
  10166. "month_prescriptions": monthPrescriptions,
  10167. "order": order,
  10168. "doctors": doctors,
  10169. "department": department,
  10170. "settle_total": settle_total,
  10171. "dia_arr": dia_arr,
  10172. })
  10173. return
  10174. }
  10175. func removeEmptyStrings(input []string) []string {
  10176. var output []string
  10177. for _, s := range input {
  10178. if s != "" {
  10179. output = append(output, s)
  10180. }
  10181. }
  10182. return output
  10183. }
  10184. func removeDuplicates(input []string) []string {
  10185. seen := make(map[string]bool)
  10186. output := []string{}
  10187. for _, s := range input {
  10188. if _, exists := seen[s]; !exists {
  10189. seen[s] = true
  10190. output = append(output, s)
  10191. }
  10192. }
  10193. return output
  10194. }
  10195. func (c *HisApiController) GetHisMonthPatientInfo() {
  10196. patient_id, _ := c.GetInt64("patient_id")
  10197. his_patient_id, _ := c.GetInt64("his_patient_id")
  10198. record_date := c.GetString("record_date")
  10199. number := c.GetString("number")
  10200. start_time := c.GetString("start_time")
  10201. end_time := c.GetString("end_time")
  10202. p_type, _ := c.GetInt64("p_type")
  10203. timeLayout := "2006-01-02"
  10204. loc, _ := time.LoadLocation("Local")
  10205. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10206. if err != nil {
  10207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10208. return
  10209. }
  10210. recordDateTime := theTime.Unix()
  10211. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10212. if err != nil {
  10213. }
  10214. startRecordDateTime := startTime.Unix()
  10215. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10216. if err != nil {
  10217. }
  10218. endRecordDateTime := endTime.Unix()
  10219. admin := c.GetAdminUserInfo()
  10220. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  10221. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10222. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  10223. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10224. var settle_total float64
  10225. for _, item := range monthPrescriptions {
  10226. if len(item.HisPrescriptionProject) > 0 {
  10227. for _, subItem := range item.HisPrescriptionProject {
  10228. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10229. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10230. settle_total = settle_total + total
  10231. }
  10232. }
  10233. if len(item.HisDoctorAdviceInfo) > 0 {
  10234. for _, subItem := range item.HisDoctorAdviceInfo {
  10235. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10236. settle_total = settle_total + total
  10237. }
  10238. }
  10239. }
  10240. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10241. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10242. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10243. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10244. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  10245. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10246. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  10247. //获取所有科室信息
  10248. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10249. c.ServeSuccessJSON(map[string]interface{}{
  10250. "his_info": his_patient_info,
  10251. "xt_info": xt_patient_info,
  10252. "case_history": case_history,
  10253. "info": patientPrescriptionInfo,
  10254. "month_prescriptions": monthPrescriptions,
  10255. "order": order,
  10256. "doctors": doctors,
  10257. "department": department,
  10258. "count": count,
  10259. "drugStockConfig": drugStockConfig,
  10260. "last_info": lastPatientPrescriptionInfo,
  10261. "settle_total": settle_total,
  10262. })
  10263. return
  10264. }
  10265. func (c *HisApiController) GetAllOrder() {
  10266. org_id := c.GetAdminUserInfo().CurrentOrgId
  10267. orders, _ := service.GetNewHisOrderList(org_id)
  10268. c.ServeSuccessJSON(map[string]interface{}{
  10269. "order": orders,
  10270. })
  10271. return
  10272. }
  10273. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  10274. newArr = make([]*models.HisOrderInfoTwo, 0)
  10275. for i := 0; i < len(arr); i++ {
  10276. repeat := false
  10277. for j := i + 1; j < len(arr); j++ {
  10278. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  10279. repeat = true
  10280. break
  10281. }
  10282. }
  10283. if !repeat {
  10284. newArr = append(newArr, arr[i])
  10285. }
  10286. }
  10287. return
  10288. }
  10289. // 修改处方退库操作 参数传修改之前的处方数据
  10290. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  10291. if advice.ExecutionState == 1 {
  10292. //查询该病人该药品是否有库存记录
  10293. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  10294. if errcode == gorm.ErrRecordNotFound {
  10295. } else {
  10296. //退库
  10297. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  10298. if advice.PrescribingNumberUnit == drug.MinUnit {
  10299. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10300. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10301. //退库
  10302. warehouseInfo := models.DrugWarehouseInfo{
  10303. StockMinNumber: prescribingNumber,
  10304. }
  10305. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  10306. operation_time := time.Now().Unix()
  10307. creater := advice.AdviceDoctor
  10308. ctime := time.Now().Unix()
  10309. timeStr := time.Now().Format("2006-01-02")
  10310. timeArr := strings.Split(timeStr, "-")
  10311. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10312. total = total + 1
  10313. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10314. cancelStock := models.DrugCancelStock{
  10315. OrderNumber: orderNumber,
  10316. OperaTime: operation_time,
  10317. OrgId: advice.UserOrgId,
  10318. Creater: creater,
  10319. Ctime: ctime,
  10320. Status: 1,
  10321. ReturnTime: advice.AdviceDate,
  10322. Dealer: info.Dealer,
  10323. Manufacturer: info.Manufacturer,
  10324. Type: 1,
  10325. }
  10326. service.AddSigleDrugCancelStock(&cancelStock)
  10327. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10328. dealer, _ := service.GetDealerById(info.Dealer)
  10329. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10330. cancelStockInfo := models.DrugCancelStockInfo{
  10331. OrderNumber: cancelInfo.OrderNumber,
  10332. CancelStockId: cancelInfo.ID,
  10333. DrugId: info.DrugId,
  10334. Count: info.Count,
  10335. Status: 1,
  10336. Ctime: ctime,
  10337. OrgId: advice.UserOrgId,
  10338. Type: 1,
  10339. Manufacturer: manufactureName.ManufacturerName,
  10340. Dealer: dealer.DealerName,
  10341. Total: 0,
  10342. RetailPrice: info.RetailPrice,
  10343. RetailTotalPrice: info.RetailTotalPrice,
  10344. Price: info.Price,
  10345. RegisterAccount: "",
  10346. Remark: info.Remark,
  10347. BatchNumber: info.BatchNumber,
  10348. MaxUnit: info.CountUnit,
  10349. ProductDate: info.ProductDate,
  10350. ExpiryDate: info.ExpiryDate,
  10351. BatchNumberId: info.WarehouseInfoId,
  10352. }
  10353. flow := models.DrugFlow{
  10354. WarehousingId: 0,
  10355. DrugId: info.DrugId,
  10356. Number: "",
  10357. BatchNumber: info.BatchNumber,
  10358. Count: info.Count,
  10359. UserOrgId: advice.UserOrgId,
  10360. PatientId: 0,
  10361. SystemTime: ctime,
  10362. ConsumableType: 4,
  10363. IsSys: 0,
  10364. WarehousingOrder: "",
  10365. WarehouseOutId: 0,
  10366. WarehouseOutOrderNumber: "",
  10367. IsEdit: 0,
  10368. CancelStockId: cancelStock.ID,
  10369. CancelOrderNumber: cancelStock.OrderNumber,
  10370. Manufacturer: info.Manufacturer,
  10371. Dealer: info.Dealer,
  10372. Creator: advice.UserOrgId,
  10373. UpdateCreator: 0,
  10374. Status: 1,
  10375. Ctime: time.Now().Unix(),
  10376. Mtime: 0,
  10377. Price: info.Price,
  10378. WarehousingDetailId: 0,
  10379. WarehouseOutDetailId: 0,
  10380. CancelOutDetailId: 0,
  10381. ExpireDate: info.ExpiryDate,
  10382. ProductDate: info.ProductDate,
  10383. MaxUnit: info.CountUnit,
  10384. MinUnit: "",
  10385. }
  10386. service.CreatedCancelStock(cancelStockInfo)
  10387. service.CreateDrugFlowOne(flow)
  10388. } else {
  10389. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10390. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10391. if advice.PrescribingNumberUnit == drug.MaxUnit {
  10392. warehouseInfo := models.DrugWarehouseInfo{
  10393. StockMinNumber: prescribingNumber,
  10394. }
  10395. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  10396. }
  10397. operation_time := time.Now().Unix()
  10398. creater := advice.AdviceDoctor
  10399. ctime := time.Now().Unix()
  10400. timeStr := time.Now().Format("2006-01-02")
  10401. timeArr := strings.Split(timeStr, "-")
  10402. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10403. total = total + 1
  10404. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10405. cancelStock := models.DrugCancelStock{
  10406. OrderNumber: orderNumber,
  10407. OperaTime: operation_time,
  10408. OrgId: advice.UserOrgId,
  10409. Creater: creater,
  10410. Ctime: ctime,
  10411. Status: 1,
  10412. ReturnTime: advice.AdviceDate,
  10413. Dealer: info.Dealer,
  10414. Manufacturer: info.Manufacturer,
  10415. Type: 1,
  10416. }
  10417. service.AddSigleDrugCancelStock(&cancelStock)
  10418. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10419. dealer, _ := service.GetDealerById(info.Dealer)
  10420. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10421. cancelStockInfo := models.DrugCancelStockInfo{
  10422. OrderNumber: cancelInfo.OrderNumber,
  10423. CancelStockId: cancelInfo.ID,
  10424. DrugId: info.DrugId,
  10425. Count: info.Count,
  10426. Status: 1,
  10427. Ctime: ctime,
  10428. OrgId: advice.UserOrgId,
  10429. Type: 1,
  10430. Manufacturer: manufactureName.ManufacturerName,
  10431. Dealer: dealer.DealerName,
  10432. Total: 0,
  10433. RetailPrice: info.RetailPrice,
  10434. RetailTotalPrice: info.RetailTotalPrice,
  10435. Price: info.Price,
  10436. RegisterAccount: "",
  10437. Remark: info.Remark,
  10438. BatchNumber: info.BatchNumber,
  10439. MaxUnit: info.CountUnit,
  10440. ProductDate: info.ProductDate,
  10441. ExpiryDate: info.ExpiryDate,
  10442. BatchNumberId: info.WarehouseInfoId,
  10443. }
  10444. flow := models.DrugFlow{
  10445. WarehousingId: 0,
  10446. DrugId: info.DrugId,
  10447. Number: "",
  10448. BatchNumber: info.BatchNumber,
  10449. Count: info.Count,
  10450. UserOrgId: advice.UserOrgId,
  10451. PatientId: 0,
  10452. SystemTime: ctime,
  10453. ConsumableType: 4,
  10454. IsSys: 0,
  10455. WarehousingOrder: "",
  10456. WarehouseOutId: 0,
  10457. WarehouseOutOrderNumber: "",
  10458. IsEdit: 0,
  10459. CancelStockId: cancelStock.ID,
  10460. CancelOrderNumber: cancelStock.OrderNumber,
  10461. Manufacturer: info.Manufacturer,
  10462. Dealer: info.Dealer,
  10463. Creator: advice.AdviceDoctor,
  10464. UpdateCreator: 0,
  10465. Status: 1,
  10466. Ctime: time.Now().Unix(),
  10467. Mtime: 0,
  10468. Price: info.Price,
  10469. WarehousingDetailId: 0,
  10470. WarehouseOutDetailId: 0,
  10471. CancelOutDetailId: 0,
  10472. ExpireDate: info.ExpiryDate,
  10473. ProductDate: info.ProductDate,
  10474. MaxUnit: info.CountUnit,
  10475. MinUnit: "",
  10476. }
  10477. service.CreatedCancelStock(cancelStockInfo)
  10478. service.CreateDrugFlowOne(flow)
  10479. }
  10480. }
  10481. }
  10482. return err
  10483. }
  10484. func (this *HisApiController) DeleteNCDS() {
  10485. id, _ := this.GetInt64("id", 0)
  10486. if id > 0 {
  10487. service.DeletePsnNCDSRecordById(id)
  10488. this.ServeSuccessJSON(map[string]interface{}{
  10489. "msg": "删除成功",
  10490. })
  10491. } else {
  10492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10493. return
  10494. }
  10495. }
  10496. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10497. id, _ := c.GetInt64("id")
  10498. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10499. c.ServeSuccessJSON(map[string]interface{}{
  10500. "advice": advice,
  10501. })
  10502. return
  10503. }
  10504. func (c *HisApiController) GetHisMonthChargePatientList() {
  10505. record_date := c.GetString("record_date")
  10506. start_time := c.GetString("start_time")
  10507. end_time := c.GetString("end_time")
  10508. timeLayout := "2006-01-02"
  10509. loc, _ := time.LoadLocation("Local")
  10510. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10511. if err != nil {
  10512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10513. return
  10514. }
  10515. if err != nil {
  10516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10517. return
  10518. }
  10519. recordDateTime := theTime.Unix()
  10520. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10521. if err != nil {
  10522. }
  10523. startRecordDateTime := startTime.Unix()
  10524. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10525. if err != nil {
  10526. }
  10527. endRecordDateTime := endTime.Unix()
  10528. adminInfo := c.GetAdminUserInfo()
  10529. var tempMonthChargePatients []*service.MonthChargePatients
  10530. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10531. for _, item := range tempPatients {
  10532. //过滤没有处方的
  10533. if len(item.HisPrescription) == 0 {
  10534. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10535. }
  10536. }
  10537. c.ServeSuccessJSON(map[string]interface{}{
  10538. "list": tempMonthChargePatients,
  10539. })
  10540. }
  10541. // PrescriptionDifference 医嘱数量差值结构体
  10542. type PrescriptionDrugDifference struct {
  10543. DrugID int64 //基础库药品id
  10544. ID int64 //医嘱id
  10545. Difference float64 //差值
  10546. Unit string //单位
  10547. }
  10548. type PrescriptionGoodDifference struct {
  10549. GoodID int64 //基础库项目耗材id
  10550. ID int64 //医嘱id
  10551. Difference int64 //差值
  10552. Unit string //单位
  10553. Type int64 //类型
  10554. }
  10555. type EditCustomData struct {
  10556. adviceList []*models.HisDoctorAdviceInfo
  10557. projectList []*models.HisPrescriptionProject
  10558. }
  10559. type SrcCustomData struct {
  10560. adviceList []*models.HisDoctorAdviceInfo
  10561. projectList []*models.HisPrescriptionProject
  10562. }
  10563. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  10564. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  10565. differences := make([]*PrescriptionDrugDifference, 0)
  10566. // 创建一个 map 来存储第一个切片中的药品信息
  10567. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  10568. for _, advice := range firstPrescription {
  10569. firstMap[advice.DrugId] = advice
  10570. }
  10571. // 遍历第二个切片中的药品信息,并比较数量差值
  10572. for _, advice := range secondPrescription {
  10573. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  10574. diff := &PrescriptionDrugDifference{
  10575. DrugID: advice.DrugId,
  10576. ID: firstAdvice.ID,
  10577. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  10578. Unit: firstAdvice.PrescribingNumberUnit,
  10579. }
  10580. differences = append(differences, diff)
  10581. }
  10582. }
  10583. return differences
  10584. }
  10585. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  10586. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  10587. differences := make([]*PrescriptionGoodDifference, 0)
  10588. // 创建一个 map 来存储第一个切片中的耗材信息
  10589. firstMap := make(map[int64]*models.HisPrescriptionProject)
  10590. for _, good := range firstPrescription {
  10591. firstMap[good.ProjectId] = good
  10592. }
  10593. // 遍历第二个切片中的耗材信息,并比较数量差值
  10594. for _, good := range secondPrescription {
  10595. if firstGood, ok := firstMap[good.ProjectId]; ok {
  10596. count, _ := strconv.ParseInt(good.Count, 10, 64)
  10597. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  10598. diff := &PrescriptionGoodDifference{
  10599. GoodID: good.ProjectId,
  10600. ID: firstGood.ID,
  10601. Difference: count - firstCount,
  10602. Unit: firstGood.Unit,
  10603. Type: firstGood.Type,
  10604. }
  10605. differences = append(differences, diff)
  10606. }
  10607. }
  10608. return differences
  10609. }
  10610. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  10611. var adviceList []*models.HisDoctorAdviceInfo
  10612. var projectList []*models.HisPrescriptionProject
  10613. var advice_ids []int64
  10614. var project_ids []int64
  10615. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10616. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10617. //var tempPrescription *models.HisPrescriptionProjectscription
  10618. if len(prescriptions) > 0 {
  10619. for _, item := range prescriptions {
  10620. items := item.(map[string]interface{})
  10621. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10622. advices := items["advices"].([]interface{})
  10623. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10624. groupNo := int64(0)
  10625. ctime := time.Now().Unix()
  10626. mtime := ctime
  10627. if len(advices) > 0 {
  10628. for _, advice := range advices {
  10629. var s models.HisDoctorAdviceInfo
  10630. s.AdviceType = 2
  10631. s.StopState = 2
  10632. s.ExecutionState = 2
  10633. s.Status = 1
  10634. s.Groupno = groupNo
  10635. s.CreatedTime = ctime
  10636. s.UpdatedTime = mtime
  10637. s.IsSettle = 2
  10638. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  10639. //存储切片中
  10640. if s.ID > 0 {
  10641. advice_ids = append(advice_ids, s.ID)
  10642. adviceList = append(adviceList, &s)
  10643. }
  10644. }
  10645. }
  10646. }
  10647. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10648. projects := items["project"].([]interface{})
  10649. if len(projects) > 0 {
  10650. for _, project := range projects {
  10651. var p models.HisPrescriptionProject
  10652. p.Ctime = time.Now().Unix()
  10653. p.Mtime = time.Now().Unix()
  10654. p.Status = 1
  10655. SetProjectWithJSON(&p, project.(map[string]interface{}))
  10656. if p.ID > 0 {
  10657. project_ids = append(project_ids, p.ID)
  10658. projectList = append(projectList, &p)
  10659. }
  10660. }
  10661. }
  10662. }
  10663. }
  10664. }
  10665. }
  10666. editCustomData.projectList = projectList
  10667. editCustomData.adviceList = adviceList
  10668. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  10669. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  10670. srcCustomData.adviceList = list
  10671. srcCustomData.projectList = list2
  10672. return
  10673. }