his_api_controller.go 506KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. if number >= 1000 {
  188. zero = "0000" + strconv.FormatInt(number, 10)
  189. } else if number >= 10000 {
  190. zero = "000" + strconv.FormatInt(number, 10)
  191. } else if number >= 100000 {
  192. zero = "00" + strconv.FormatInt(number, 10)
  193. } else if number >= 1000000 {
  194. zero = "0" + strconv.FormatInt(number, 10)
  195. } else {
  196. zero = strconv.FormatInt(number, 10)
  197. }
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. for _, item := range orderInfos {
  1023. if item.MedChrgitmType == "01" { //床位费
  1024. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1025. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1026. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1027. }
  1028. if item.MedChrgitmType == "02" { //诊察费
  1029. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1030. //zhenChaCostSelfTotal = zhenChaCostTotal
  1031. }
  1032. if item.MedChrgitmType == "03" { //检查费
  1033. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1034. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1035. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1036. }
  1037. if item.MedChrgitmType == "02" { //检查费
  1038. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1039. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1040. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1041. }
  1042. if item.MedChrgitmType == "04" { //化验费
  1043. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1044. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1045. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1046. }
  1047. if item.MedChrgitmType == "05" { //治疗费
  1048. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1049. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1050. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1051. }
  1052. if item.MedChrgitmType == "06" { //手术费
  1053. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1054. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1055. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1056. }
  1057. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1058. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1059. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1060. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1061. }
  1062. if item.MedChrgitmType == "09" { //西药费
  1063. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1064. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1065. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1066. }
  1067. if item.MedChrgitmType == "11" { //中成费
  1068. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1069. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1070. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1073. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. }
  1077. }
  1078. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1079. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1080. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1081. var dia_config []*models.HisXtDiagnoseConfig
  1082. var diagnosis_ids []string
  1083. if his.ID > 0 {
  1084. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1085. } else {
  1086. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1087. }
  1088. for _, item := range diagnosis_ids {
  1089. id, _ := strconv.ParseInt(item, 10, 64)
  1090. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1091. dia_config = append(dia_config, diagnosisConfig)
  1092. }
  1093. var rf []CustomFundPay
  1094. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1095. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1096. c.ServeSuccessJSON(map[string]interface{}{
  1097. "patient": patient,
  1098. "order_infos": orderInfos,
  1099. "diagnosis": name,
  1100. "bedCostTotal": bedCostTotal,
  1101. "bedCostSelfTotal": bedCostTotal,
  1102. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1103. "operationCostTotal": operationCostTotal,
  1104. "operationCostSelfTotal": operationCostTotal,
  1105. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1106. "otherCostTotal": otherCostTotal,
  1107. "otherCostSelfTotal": otherCostTotal,
  1108. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1109. "materialCostTotal": materialCostTotal,
  1110. "materialCostSelfTotal": materialCostTotal,
  1111. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1112. "westernMedicineCostTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1115. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1118. "checkCostTotal": checkCostTotal,
  1119. "checkCostSelfTotal": checkCostTotal,
  1120. "zhenChaCostTotal": zhenChaCostTotal,
  1121. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1122. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1123. "laboratoryCostTotal": laboratoryCostTotal,
  1124. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1125. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1126. "treatCostTotal": treatCostTotal,
  1127. "treatCostSelfTotal": treatCostTotal,
  1128. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1129. "charge_admin": charge_admin,
  1130. "printor_admin": printor_admin,
  1131. "org_name": org.OrgName,
  1132. "org_code": miConfig.Code,
  1133. "name": patient.Name,
  1134. "number": order.MdtrtId,
  1135. "date": order.SettleAccountsDate,
  1136. "info": order,
  1137. "new_order": order,
  1138. "his_hospital": his_hospital,
  1139. "his": his,
  1140. "funds": rf,
  1141. "dia_config": dia_config,
  1142. })
  1143. }
  1144. func (c *HisApiController) RefudDetail() {
  1145. order_id, _ := c.GetInt64("order_id")
  1146. order, _ := service.GetHisOrderByID(order_id)
  1147. adminUser := c.GetAdminUserInfo()
  1148. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1149. c.ServeSuccessJSON(map[string]interface{}{
  1150. "msg": "撤销成功",
  1151. })
  1152. }
  1153. func (c *HisApiController) Sscard() {
  1154. //r := CardInit()
  1155. //if r == 0 {
  1156. // GetBaseInfo()
  1157. //}
  1158. //c.ServeSuccessJSON(map[string]interface{}{
  1159. // "list": "11",
  1160. //})
  1161. }
  1162. func GetBaseInfo() error {
  1163. //handle := syscall.MustLoadDLL("SSCard.dll")
  1164. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1165. //
  1166. //str := make([]byte, 256)
  1167. //str1 := make([]byte, 256)
  1168. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1169. //if ferr != nil {
  1170. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1171. // return ferr
  1172. //}
  1173. //
  1174. //fmt.Println(string(str))
  1175. //
  1176. //fmt.Println(r)
  1177. return nil
  1178. }
  1179. func CardInit() int {
  1180. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1181. //add := DllTestDef.MustFindProc("Init")
  1182. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1183. //if err != nil {
  1184. // fmt.Println("SSCard的运算结果为:", ret)
  1185. //}
  1186. //result := int(ret)
  1187. return 0
  1188. }
  1189. func IntPtr(n int) uintptr {
  1190. return uintptr(n)
  1191. }
  1192. func StrPtr(s string) uintptr {
  1193. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1194. }
  1195. func (c *HisApiController) GetHisPatientList() {
  1196. //types, _ := c.GetInt64("type", 0)
  1197. record_date := c.GetString("record_date")
  1198. sch_type, _ := c.GetInt64("sch_type")
  1199. timeLayout := "2006-01-02"
  1200. loc, _ := time.LoadLocation("Local")
  1201. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1202. if err != nil {
  1203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. recordDateTime := theTime.Unix()
  1207. adminInfo := c.GetAdminUserInfo()
  1208. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1209. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1210. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1211. //获取当前用户的信息
  1212. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1213. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1214. //获取所有科室信息
  1215. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1216. c.ServeSuccessJSON(map[string]interface{}{
  1217. "list": patients,
  1218. "list_two": patients_two,
  1219. "info": adminUserInfo,
  1220. "doctors": doctors,
  1221. "department": department,
  1222. })
  1223. }
  1224. type CustomTemplate struct {
  1225. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1226. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1227. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1228. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1229. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1230. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1231. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1232. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1233. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1234. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1235. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1236. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1237. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1238. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1239. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1240. }
  1241. func (c *HisApiController) GetHisPatientInfo() {
  1242. patient_id, _ := c.GetInt64("patient_id")
  1243. his_patient_id, _ := c.GetInt64("his_patient_id")
  1244. record_date := c.GetString("record_date")
  1245. number := c.GetString("number")
  1246. //start_time := c.GetString("start_time")
  1247. //end_time := c.GetString("end_time")
  1248. p_type, _ := c.GetInt64("p_type")
  1249. timeLayout := "2006-01-02"
  1250. loc, _ := time.LoadLocation("Local")
  1251. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1252. if err != nil {
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. recordDateTime := theTime.Unix()
  1257. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1258. //if err != nil {
  1259. //
  1260. //}
  1261. //startRecordDateTime := startTime.Unix()
  1262. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1263. //if err != nil {
  1264. //
  1265. //}
  1266. //endRecordDateTime := endTime.Unix()
  1267. admin := c.GetAdminUserInfo()
  1268. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1270. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1271. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1272. var prescriptions []*models.HisPrescription
  1273. var last_prescriptions []*models.HisPrescription
  1274. var sch_prescriptions []CustomTemplate
  1275. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1276. if p_type == 1 { //住院
  1277. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1278. for _, item := range prescriptions {
  1279. for _, subItem := range item.HisDoctorAdviceInfo {
  1280. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1281. if info.RetailPrice > 0 {
  1282. subItem.Drug.MinPrice = info.RetailPrice
  1283. }
  1284. }
  1285. }
  1286. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1287. } else { //门诊
  1288. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1289. for _, item := range prescriptions {
  1290. for _, subItem := range item.HisDoctorAdviceInfo {
  1291. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1292. if info.RetailPrice > 0 {
  1293. subItem.Drug.MinPrice = info.RetailPrice
  1294. }
  1295. }
  1296. }
  1297. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1298. }
  1299. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1300. if sch.ID > 0 {
  1301. var week string
  1302. t := time.Now()
  1303. switch t.Weekday().String() {
  1304. case "Monday":
  1305. week = "周一"
  1306. break
  1307. case "Tuesday":
  1308. week = "周二"
  1309. break
  1310. case "Wednesday":
  1311. week = "周三"
  1312. break
  1313. case "Thursday":
  1314. week = "周四"
  1315. break
  1316. case "Friday":
  1317. week = "周五"
  1318. break
  1319. case "Saturday":
  1320. week = "周六"
  1321. break
  1322. case "Sunday":
  1323. week = "周日"
  1324. break
  1325. }
  1326. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1327. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1328. //根据推送频率组装新的数组
  1329. for _, item := range temp_sch_prescriptions {
  1330. var cus CustomTemplate
  1331. cus.ID = item.ID
  1332. cus.UserOrgId = item.UserOrgId
  1333. cus.PatientId = item.PatientId
  1334. cus.MedType = item.MedType
  1335. cus.RecordDate = item.RecordDate
  1336. cus.Type = item.Type
  1337. cus.PType = item.PType
  1338. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1339. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1340. if subItem.FrequencyType == 1 { //每次必推
  1341. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1342. }
  1343. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1344. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1345. }
  1346. if subItem.FrequencyType == 2 { //按照天数频率
  1347. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1348. now := p.Unix()
  1349. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1350. dayStr2 := "-" + dayStr
  1351. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1352. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1353. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1354. if len(advices) == 0 {
  1355. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1356. }
  1357. }
  1358. }
  1359. }
  1360. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1361. if subItem.Type == 2 {
  1362. if subItem.XtHisProject.MedicalStatus != 1 {
  1363. if subItem.FrequencyType == 1 {
  1364. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1365. }
  1366. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1367. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1368. }
  1369. if subItem.FrequencyType == 2 {
  1370. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1371. now := p.Unix()
  1372. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1373. dayStr2 := "-" + dayStr
  1374. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1375. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1376. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1377. if len(projects) == 0 {
  1378. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1379. }
  1380. }
  1381. }
  1382. } else if subItem.Type == 3 {
  1383. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1384. if subItem.FrequencyType == 1 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1388. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1389. }
  1390. if subItem.FrequencyType == 2 {
  1391. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1392. now := p.Unix()
  1393. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1394. dayStr2 := "-" + dayStr
  1395. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1396. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1397. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1398. if len(projects) == 0 {
  1399. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. sch_prescriptions = append(sch_prescriptions, cus)
  1406. }
  1407. for _, item := range sch_prescriptions {
  1408. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1409. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1410. }
  1411. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1412. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1413. }
  1414. }
  1415. }
  1416. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1417. if config.ID > 0 && config.IsOpen == 1 {
  1418. for _, item := range sch_prescriptions {
  1419. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1420. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1421. if info.RetailPrice > 0 {
  1422. subItem.Drug.MinPrice = info.RetailPrice
  1423. }
  1424. }
  1425. }
  1426. }
  1427. if config.ID > 0 && config.IsOpen == 1 {
  1428. for _, item := range sch_prescriptions {
  1429. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1430. if subItem.Type == 3 {
  1431. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1432. if info.Price > 0 {
  1433. subItem.GoodInfo.PackingPrice = info.Price
  1434. }
  1435. }
  1436. }
  1437. }
  1438. }
  1439. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1440. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1441. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1442. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1443. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1444. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1445. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1446. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1447. //获取所有科室信息
  1448. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1449. c.ServeSuccessJSON(map[string]interface{}{
  1450. "his_info": his_patient_info,
  1451. "xt_info": xt_patient_info,
  1452. "prescription": prescriptions,
  1453. "case_history": case_history,
  1454. "info": patientPrescriptionInfo,
  1455. //"month_prescriptions": monthPrescriptions,
  1456. "order": order,
  1457. "doctors": doctors,
  1458. "department": department,
  1459. "sch_prescriptions": sch_prescriptions,
  1460. "last_prescriptions": last_prescriptions,
  1461. "schedule": sch,
  1462. "count": count,
  1463. "drugStockConfig": drugStockConfig,
  1464. "last_info": lastPatientPrescriptionInfo,
  1465. })
  1466. return
  1467. }
  1468. func (c *HisApiController) GetHisPrescriptionConfig() {
  1469. adminInfo := c.GetAdminUserInfo()
  1470. //获取医嘱模版
  1471. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1472. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1473. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1474. //获取所有基础药
  1475. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1476. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1477. if config.ID > 0 && config.IsOpen == 1 {
  1478. for _, item := range drugs {
  1479. var index = 0
  1480. for _, subItem := range item.OtherDrugWarehouseInfo {
  1481. if index == 0 {
  1482. index = index + 1
  1483. if subItem.RetailPrice > 0 {
  1484. item.MinPrice = subItem.RetailPrice
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1491. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1492. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1493. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1494. //获取所有科室信息
  1495. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1496. //获取诊断信息
  1497. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1498. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1499. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1500. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1501. //获取是否开启保存耗材出库的开关
  1502. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1503. c.ServeSuccessJSON(map[string]interface{}{
  1504. "drugs": drugs,
  1505. "advices_template": advices,
  1506. "drugways": drugways,
  1507. "efs": efs,
  1508. "doctors": doctors,
  1509. "department": department,
  1510. "sick": sick,
  1511. "additions": additions,
  1512. "diagnose": diagnose,
  1513. "manufacturers": manufacturers,
  1514. "goodOutOpen": goodOutOpen,
  1515. "patientDiagnose": patientDiagnose,
  1516. })
  1517. }
  1518. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1519. //获取所有基础药
  1520. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1521. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1522. if config.ID > 0 && config.IsOpen == 1 {
  1523. for _, item := range drugs {
  1524. var index = 0
  1525. for _, subItem := range item.OtherDrugWarehouseInfo {
  1526. if index == 0 {
  1527. index = index + 1
  1528. if subItem.RetailPrice > 0 {
  1529. item.MinPrice = subItem.RetailPrice
  1530. }
  1531. }
  1532. }
  1533. }
  1534. }
  1535. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1536. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1537. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1538. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1539. //获取所有科室信息
  1540. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1541. //获取诊断信息
  1542. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1543. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1544. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1545. //获取是否开启保存耗材出库的开关
  1546. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1547. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1548. c.ServeSuccessJSON(map[string]interface{}{
  1549. "drugs": drugs,
  1550. "advices_template": advices,
  1551. "drugways": drugways,
  1552. "efs": efs,
  1553. "doctors": doctors,
  1554. "department": department,
  1555. "sick": sick,
  1556. "additions": additions,
  1557. "diagnose": diagnose,
  1558. "manufacturers": manufacturers,
  1559. "goodOutOpen": goodOutOpen,
  1560. "patientDiagnose": patientDiagnose,
  1561. })
  1562. }
  1563. }
  1564. func (c *HisApiController) CreateHisPrescription() {
  1565. record_date := c.GetString("record_date")
  1566. patient_id, _ := c.GetInt64("patient_id")
  1567. reg_type, _ := c.GetInt64("reg_type")
  1568. diagnose := c.GetString("diagnose")
  1569. sick_type, _ := c.GetInt64("sick_type")
  1570. sick_history := c.GetString("sick_history")
  1571. doctor_id, _ := c.GetInt64("doctor", 0)
  1572. department, _ := c.GetInt64("department", 0)
  1573. his_patient_id, _ := c.GetInt64("his_patient_id")
  1574. p_type, _ := c.GetInt64("p_type")
  1575. patient_diagnose := c.GetString("patient_diagnose")
  1576. dataBody := make(map[string]interface{}, 0)
  1577. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1578. if err != nil {
  1579. utils.ErrorLog(err.Error())
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1581. return
  1582. }
  1583. //edit, src := GetCompareData(dataBody)
  1584. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1585. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1586. //fmt.Println(drugResult)
  1587. //fmt.Println(goodResult)
  1588. timeLayout := "2006-01-02"
  1589. loc, _ := time.LoadLocation("Local")
  1590. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1591. if err != nil {
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. adminInfo := c.GetAdminUserInfo()
  1596. recordDateTime := theTime.Unix()
  1597. //查询默认出库仓库库存
  1598. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1599. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1600. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1601. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1602. if len(lists) == 1 {
  1603. his_patient_id = lists[0].ID
  1604. }
  1605. }
  1606. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1607. //保存处方出库
  1608. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1609. //自动出库
  1610. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1611. //耗材保存处方出库
  1612. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1614. //已发药和已收费限制逻辑
  1615. isMidicine := false
  1616. isCharge := false
  1617. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1618. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1619. if len(prescriptions) > 0 {
  1620. for _, item := range prescriptions {
  1621. items := item.(map[string]interface{})
  1622. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1623. utils.ErrorLog("id")
  1624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1625. return
  1626. }
  1627. id := int64(items["id"].(float64))
  1628. if id > 0 {
  1629. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1630. if err != nil {
  1631. if new_prescription.OrderStatus == 4 {
  1632. isCharge = true
  1633. }
  1634. }
  1635. }
  1636. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1637. advices := items["advices"].([]interface{})
  1638. if len(advices) > 0 {
  1639. for _, advice := range advices {
  1640. var adviceId int64
  1641. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1642. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1643. }
  1644. if adviceId > 0 {
  1645. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1646. if err == nil {
  1647. if his_advice_info.IsMedicine == 1 {
  1648. isMidicine = true
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. if isMidicine == true {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1660. return
  1661. }
  1662. if isCharge == true {
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1664. return
  1665. }
  1666. // 开始主事务
  1667. db := service.XTWriteDB()
  1668. tx := db.Begin()
  1669. // 在函数结束时处理事务回滚
  1670. defer func() {
  1671. if r := recover(); r != nil {
  1672. tx.Rollback()
  1673. }
  1674. }()
  1675. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1676. //药品发药出库
  1677. if pharmacyConfig.IsOpen == 1 {
  1678. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1679. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1680. if len(prescriptions) > 0 {
  1681. for _, item := range prescriptions {
  1682. items := item.(map[string]interface{})
  1683. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1684. advices := items["advices"].([]interface{})
  1685. if len(advices) > 0 {
  1686. for _, advice := range advices {
  1687. var drug_id int64
  1688. var prescribing_number float64
  1689. var prescribingNumberUnit string
  1690. var adviceId int64
  1691. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1692. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1693. }
  1694. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1695. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1696. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1697. }
  1698. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1699. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1700. }
  1701. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1702. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1703. }
  1704. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1705. if drug.ID == 0 {
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. //查询药品的所有库存
  1710. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1711. var total_count int64
  1712. for _, it := range list {
  1713. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1714. }
  1715. totals := strconv.FormatInt(total_count, 10)
  1716. //查询该药品是否存在开药记录
  1717. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1718. //新增处方
  1719. if advicelist.ID == 0 {
  1720. all_count, _ := strconv.ParseFloat(totals, 64)
  1721. if prescribingNumberUnit == drug.MinUnit {
  1722. if drug.IsUse != 1 {
  1723. if drug.IsProject == 0 || drug.IsProject == 2 {
  1724. if all_count == 0 {
  1725. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1726. return
  1727. }
  1728. if prescribing_number > all_count {
  1729. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1730. return
  1731. }
  1732. }
  1733. }
  1734. }
  1735. if prescribingNumberUnit == drug.MaxUnit {
  1736. num := prescribing_number * float64(drug.MinNumber)
  1737. if drug.IsUse != 1 {
  1738. if drug.IsProject == 0 || drug.IsProject == 2 {
  1739. if all_count == 0 {
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1741. return
  1742. }
  1743. if num > all_count {
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1752. if drugOutConfig.IsOpen != 1 {
  1753. //修改处方
  1754. for _, advice := range advices {
  1755. var drug_id int64
  1756. var prescribing_number float64
  1757. var prescribingNumberUnit string
  1758. var prescribingNumber string
  1759. var adviceId int64
  1760. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1761. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1762. }
  1763. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1764. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1765. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1766. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1767. }
  1768. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1769. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1770. }
  1771. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1772. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1773. }
  1774. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1775. if drug.ID == 0 {
  1776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1777. return
  1778. }
  1779. //查询药品的所有库存
  1780. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1781. var total_count int64
  1782. for _, it := range list {
  1783. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1784. }
  1785. totals := strconv.FormatInt(total_count, 10)
  1786. //查询该药品是否存在开药记录
  1787. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1788. //新增处方
  1789. if advicelist.ID == 0 {
  1790. all_count, _ := strconv.ParseFloat(totals, 64)
  1791. if prescribingNumberUnit == drug.MinUnit {
  1792. if drug.IsUse != 1 {
  1793. if drug.IsProject == 0 || drug.IsProject == 2 {
  1794. if all_count == 0 {
  1795. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1796. return
  1797. }
  1798. if prescribing_number > all_count {
  1799. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1800. return
  1801. }
  1802. }
  1803. }
  1804. } else {
  1805. if prescribingNumberUnit == drug.MaxUnit {
  1806. num := prescribing_number * float64(drug.MinNumber)
  1807. if drug.IsUse != 1 {
  1808. if drug.IsProject == 0 || drug.IsProject == 2 {
  1809. if all_count == 0 {
  1810. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1811. return
  1812. }
  1813. if num > all_count {
  1814. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1815. return
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. }
  1822. //修改处方
  1823. if advicelist.ID > 0 {
  1824. var device_number int64
  1825. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1826. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1827. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1828. device_number = prescribingNumberInt * drug.MinNumber
  1829. }
  1830. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1831. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1832. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1833. device_number = prescribingNumberInt
  1834. }
  1835. var number_count int64
  1836. if prescribingNumberUnit == drug.MaxUnit {
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1838. number_count = prescribingNumberInt * drug.MinNumber
  1839. }
  1840. if prescribingNumberUnit == drug.MinUnit {
  1841. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1842. number_count = prescribingNumberInt
  1843. }
  1844. //如果修改的数量大于之前修改的数量
  1845. if (number_count - device_number) > 0 {
  1846. //如果修改的差数量 大于库存数量
  1847. if drug.IsUse != 1 {
  1848. if (number_count - device_number) > total_count {
  1849. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1850. return
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. //已发药和已收费限制逻辑
  1865. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1866. //校验库存总量
  1867. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1868. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1869. if len(prescriptions) > 0 {
  1870. for _, item := range prescriptions {
  1871. items := item.(map[string]interface{})
  1872. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1873. advices := items["advices"].([]interface{})
  1874. if len(advices) > 0 {
  1875. for _, advice := range advices {
  1876. var drug_id int64
  1877. var prescribing_number float64
  1878. var prescribingNumberUnit string
  1879. var adviceId int64
  1880. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1881. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1882. }
  1883. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1884. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1885. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1886. }
  1887. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1888. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1889. }
  1890. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1891. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1892. }
  1893. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1894. if drug.ID == 0 {
  1895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1896. return
  1897. }
  1898. //查询药品的所有库存
  1899. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1900. var total_count int64
  1901. for _, it := range list {
  1902. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1903. }
  1904. totals := strconv.FormatInt(total_count, 10)
  1905. //查询该药品是否存在开药记录
  1906. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1907. //查询最新批次库存
  1908. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1909. var batch_number_count int64
  1910. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1911. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1912. //新增处方
  1913. if advicelist.ID == 0 {
  1914. all_count, _ := strconv.ParseFloat(totals, 64)
  1915. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1916. if prescribingNumberUnit == drug.MinUnit {
  1917. if drug.IsUse != 1 {
  1918. if drug.IsProject == 0 || drug.IsProject == 2 {
  1919. if all_count == 0 {
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1921. return
  1922. }
  1923. if prescribing_number > all_count {
  1924. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1925. return
  1926. }
  1927. }
  1928. if adminInfo.CurrentOrgId == 10215 {
  1929. if prescribing_number > batch_number_all_count {
  1930. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1931. return
  1932. }
  1933. }
  1934. }
  1935. }
  1936. if prescribingNumberUnit == drug.MaxUnit {
  1937. num := prescribing_number * float64(drug.MinNumber)
  1938. if drug.IsUse != 1 {
  1939. if drug.IsProject == 0 || drug.IsProject == 2 {
  1940. if all_count == 0 {
  1941. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1942. return
  1943. }
  1944. if num > all_count {
  1945. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1946. return
  1947. }
  1948. }
  1949. if adminInfo.CurrentOrgId == 10215 {
  1950. if num > batch_number_all_count {
  1951. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1952. return
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1959. if drugOutConfig.IsOpen != 1 {
  1960. //修改处方
  1961. for _, advice := range advices {
  1962. var drug_id int64
  1963. var prescribing_number float64
  1964. var prescribingNumberUnit string
  1965. var prescribingNumber string
  1966. var adviceId int64
  1967. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1968. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1969. }
  1970. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1971. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1972. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1973. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1974. }
  1975. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1976. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1977. }
  1978. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1979. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1980. }
  1981. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1982. if drug.ID == 0 {
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1984. return
  1985. }
  1986. //查询药品的所有库存
  1987. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1988. var total_count int64
  1989. for _, it := range list {
  1990. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1991. }
  1992. totals := strconv.FormatInt(total_count, 10)
  1993. //查询该药品是否存在开药记录
  1994. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1995. //新增处方
  1996. if advicelist.ID == 0 {
  1997. //查询最新批次库存
  1998. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1999. var batch_number_count int64
  2000. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2001. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2002. all_count, _ := strconv.ParseFloat(totals, 64)
  2003. if prescribingNumberUnit == drug.MinUnit {
  2004. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2005. if drug.IsUse != 1 {
  2006. if drug.IsProject == 0 || drug.IsProject == 2 {
  2007. if all_count == 0 {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2009. return
  2010. }
  2011. if prescribing_number > all_count {
  2012. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2013. return
  2014. }
  2015. }
  2016. if adminInfo.CurrentOrgId == 10215 {
  2017. if prescribing_number > batch_number_all_count {
  2018. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2019. return
  2020. }
  2021. }
  2022. }
  2023. } else {
  2024. if prescribingNumberUnit == drug.MaxUnit {
  2025. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2026. num := prescribing_number * float64(drug.MinNumber)
  2027. if drug.IsUse != 1 {
  2028. if drug.IsProject == 0 || drug.IsProject == 2 {
  2029. if all_count == 0 {
  2030. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2031. return
  2032. }
  2033. if num > all_count {
  2034. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2035. return
  2036. }
  2037. }
  2038. if adminInfo.CurrentOrgId == 10215 {
  2039. if prescribing_number > batch_number_all_count {
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2041. return
  2042. }
  2043. }
  2044. }
  2045. }
  2046. }
  2047. }
  2048. //修改处方
  2049. if advicelist.ID > 0 {
  2050. //查询最新批次库存
  2051. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2052. var batch_number_count int64
  2053. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2054. var device_number int64
  2055. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2056. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2057. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2058. device_number = prescribingNumberInt * drug.MinNumber
  2059. }
  2060. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2061. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2062. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2063. device_number = prescribingNumberInt
  2064. }
  2065. var number_count int64
  2066. if prescribingNumberUnit == drug.MaxUnit {
  2067. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2068. number_count = prescribingNumberInt * drug.MinNumber
  2069. }
  2070. if prescribingNumberUnit == drug.MinUnit {
  2071. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2072. number_count = prescribingNumberInt
  2073. }
  2074. //如果修改的数量大于之前修改的数量
  2075. if (number_count - device_number) > 0 {
  2076. //如果修改的差数量 大于库存数量
  2077. if drug.IsUse != 1 {
  2078. if drug.IsProject == 0 || drug.IsProject == 2 {
  2079. if total_count == 0 {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2081. return
  2082. }
  2083. if (number_count - device_number) > total_count {
  2084. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2085. return
  2086. }
  2087. if (number_count - device_number) > batch_number_count {
  2088. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2089. return
  2090. }
  2091. }
  2092. if adminInfo.CurrentOrgId == 10215 {
  2093. // 查询该药品最后一次出库记录
  2094. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2095. var out_count int64
  2096. var in_count int64
  2097. var stock_max_number int64
  2098. var stock_min_number int64
  2099. for _, it := range outInfo {
  2100. if it.CountUnit == drug.MaxUnit {
  2101. it.Count = it.Count * drug.MinNumber
  2102. }
  2103. out_count += it.Count
  2104. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2105. stock_max_number = warehouseInfoList.StockMaxNumber
  2106. stock_min_number = warehouseInfoList.StockMinNumber
  2107. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2108. }
  2109. if out_count > 0 {
  2110. if (number_count - device_number) > in_count {
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2112. return
  2113. }
  2114. }
  2115. // 未出库
  2116. if out_count == 0 {
  2117. var sum_in_count int64
  2118. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2119. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2120. fmt.Println("sum_in_count", sum_in_count)
  2121. //如果修改的数量大于有库存的第一个批次
  2122. if number_count > sum_in_count {
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2124. return
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2131. if pharmacyConfig.IsOpen != 1 {
  2132. if device_number != number_count {
  2133. // 查询该药品最后一次出库记录
  2134. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2135. //回退库存
  2136. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2137. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2138. }
  2139. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2140. var stock_max_number int64
  2141. var stock_min_number int64
  2142. if number_count >= drug.MinNumber {
  2143. stock_max_number = device_number / drug.MinNumber
  2144. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2145. stock_min_number = device_number % drug.MinNumber
  2146. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2147. } else {
  2148. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2149. }
  2150. }
  2151. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2152. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2153. }
  2154. //删除记录
  2155. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2156. //查询默认仓库剩余多少库存
  2157. var sum_count int64
  2158. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2159. for _, its := range stockInfo {
  2160. if its.MaxUnit == drug.MaxUnit {
  2161. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2162. }
  2163. sum_count += its.StockMaxNumber + its.StockMinNumber
  2164. }
  2165. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //保存处方开药
  2172. if drugOutConfig.IsOpen == 1 {
  2173. //修改处方
  2174. for _, advice := range advices {
  2175. var drug_id int64
  2176. var prescribing_number float64
  2177. var prescribingNumberUnit string
  2178. var prescribingNumber string
  2179. var adviceId int64
  2180. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2181. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2182. }
  2183. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2184. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2185. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2186. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2187. }
  2188. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2189. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2190. }
  2191. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2192. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2193. }
  2194. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2195. if drug.ID == 0 {
  2196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2197. return
  2198. }
  2199. //查询药品的所有库存
  2200. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2201. var total_count int64
  2202. for _, it := range list {
  2203. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2204. }
  2205. totals := strconv.FormatInt(total_count, 10)
  2206. //查询该药品是否存在开药记录
  2207. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2208. //新增处方
  2209. if advicelist.ID == 0 {
  2210. //查询最新批次库存
  2211. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2212. var batch_number_count int64
  2213. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2214. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2215. all_count, _ := strconv.ParseFloat(totals, 64)
  2216. if prescribingNumberUnit == drug.MinUnit {
  2217. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2218. if drug.IsUse != 1 {
  2219. if drug.IsProject == 0 || drug.IsProject == 2 {
  2220. if all_count == 0 {
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2222. return
  2223. }
  2224. if prescribing_number > all_count {
  2225. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2226. return
  2227. }
  2228. }
  2229. if adminInfo.CurrentOrgId == 10215 {
  2230. if prescribing_number > batch_number_all_count {
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2232. return
  2233. }
  2234. }
  2235. }
  2236. } else {
  2237. if prescribingNumberUnit == drug.MaxUnit {
  2238. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2239. num := prescribing_number * float64(drug.MinNumber)
  2240. if drug.IsUse != 1 {
  2241. if drug.IsProject == 0 || drug.IsProject == 2 {
  2242. if all_count == 0 {
  2243. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2244. return
  2245. }
  2246. if num > all_count {
  2247. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2248. return
  2249. }
  2250. }
  2251. if adminInfo.CurrentOrgId == 10215 {
  2252. if prescribing_number > batch_number_all_count {
  2253. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2254. return
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. }
  2261. //修改处方
  2262. if advicelist.ID > 0 {
  2263. //查询最新批次库存
  2264. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2265. var batch_number_count int64
  2266. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2267. var device_number int64
  2268. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2269. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2270. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2271. device_number = prescribingNumberInt * drug.MinNumber
  2272. }
  2273. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2274. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2275. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2276. device_number = prescribingNumberInt
  2277. }
  2278. var number_count int64
  2279. if prescribingNumberUnit == drug.MaxUnit {
  2280. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2281. number_count = prescribingNumberInt * drug.MinNumber
  2282. }
  2283. if prescribingNumberUnit == drug.MinUnit {
  2284. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2285. number_count = prescribingNumberInt
  2286. }
  2287. //如果修改的数量大于之前修改的数量
  2288. if (number_count - device_number) > 0 {
  2289. //如果修改的差数量 大于库存数量
  2290. if drug.IsUse != 1 {
  2291. if drug.IsProject == 0 || drug.IsProject == 2 {
  2292. if total_count == 0 {
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. if (number_count - device_number) > total_count {
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2298. return
  2299. }
  2300. }
  2301. if adminInfo.CurrentOrgId == 10215 {
  2302. if (number_count - device_number) > batch_number_count {
  2303. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2304. return
  2305. }
  2306. }
  2307. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2308. //查询历史出库数据总批次
  2309. // 查询该药品最后一次出库记录
  2310. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2311. var out_count int64
  2312. var in_count int64
  2313. var stock_max_number int64
  2314. var stock_min_number int64
  2315. for _, it := range outInfo {
  2316. if it.CountUnit == drug.MaxUnit {
  2317. it.Count = it.Count * drug.MinNumber
  2318. }
  2319. out_count += it.Count
  2320. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2321. stock_max_number = warehouseInfoList.StockMaxNumber
  2322. stock_min_number = warehouseInfoList.StockMinNumber
  2323. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2324. }
  2325. if out_count > 0 {
  2326. if (number_count - device_number) > in_count {
  2327. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2328. return
  2329. }
  2330. }
  2331. // 未出库
  2332. if out_count == 0 {
  2333. var sum_in_count int64
  2334. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2336. if sum_in_count == 0 {
  2337. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2338. return
  2339. }
  2340. //如果修改的数量大于有库存的第一个批次
  2341. if number_count > sum_in_count {
  2342. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2343. return
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. }
  2359. //校验耗材库存
  2360. if goodOutConfig.IsOpen == 1 {
  2361. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2362. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2363. if len(prescriptions) > 0 {
  2364. for _, item := range prescriptions {
  2365. items := item.(map[string]interface{})
  2366. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2367. projects := items["project"].([]interface{})
  2368. if len(projects) > 0 {
  2369. for _, project := range projects {
  2370. var project_id int64
  2371. var project_type int64
  2372. var totals float64
  2373. var project_name string
  2374. var parsetotal int64
  2375. var id int64
  2376. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2377. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2378. }
  2379. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2380. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2381. }
  2382. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2383. total, _ := project.(map[string]interface{})["total"].(string)
  2384. totals, _ = strconv.ParseFloat(total, 64)
  2385. }
  2386. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2387. project_name = project.(map[string]interface{})["project_name"].(string)
  2388. }
  2389. if project_type == 3 {
  2390. //查找该耗材的出库记录
  2391. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2392. if len(goodWarehouseInfo) == 0 {
  2393. //查询耗材库存
  2394. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2395. var stock_count int64
  2396. for _, it := range list {
  2397. stock_count += it.StockCount
  2398. }
  2399. stock_counts := strconv.FormatInt(stock_count, 10)
  2400. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2401. if stock_total_count == 0 {
  2402. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2403. return
  2404. }
  2405. if totals > stock_total_count {
  2406. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2407. return
  2408. }
  2409. }
  2410. if len(goodWarehouseInfo) > 0 {
  2411. //查询该患者耗材的历史数据
  2412. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2413. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2414. //数量发生改变
  2415. if parsetotal != count {
  2416. //如果现在的数量大于历史数量,就要看库存是否足够
  2417. if parsetotal > count {
  2418. //查询耗材所有库存
  2419. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2420. var stock_count int64
  2421. for _, it := range list {
  2422. stock_count += it.StockCount
  2423. }
  2424. //库存不足
  2425. if stock_count == 0 {
  2426. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2427. return
  2428. }
  2429. if (parsetotal - count) > stock_count {
  2430. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2431. return
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. }
  2444. //不使用耗材保存处方出库
  2445. if goodOutConfig.IsOpen != 1 {
  2446. if stockConfig.IsOpen == 1 {
  2447. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2448. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2449. if len(prescriptions) > 0 {
  2450. for _, item := range prescriptions {
  2451. items := item.(map[string]interface{})
  2452. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2453. projects := items["project"].([]interface{})
  2454. if len(projects) > 0 {
  2455. for _, project := range projects {
  2456. var project_id int64
  2457. var project_type int64
  2458. var totals float64
  2459. var project_name string
  2460. var parsetotal int64
  2461. var id int64
  2462. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2463. id = int64(project.(map[string]interface{})["id"].(float64))
  2464. }
  2465. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2466. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2467. }
  2468. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2469. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2470. }
  2471. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2472. total, _ := project.(map[string]interface{})["total"].(string)
  2473. totals, _ = strconv.ParseFloat(total, 64)
  2474. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2475. }
  2476. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2477. project_name = project.(map[string]interface{})["project_name"].(string)
  2478. }
  2479. if project_type == 3 {
  2480. //查找该耗材的出库记录
  2481. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2482. //没有出库记录
  2483. if len(goodWarehouseInfo) == 0 {
  2484. //查询耗材库存
  2485. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2486. var stock_count int64
  2487. for _, it := range list {
  2488. stock_count += it.StockCount
  2489. }
  2490. stock_counts := strconv.FormatInt(stock_count, 10)
  2491. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2492. if stock_total_count == 0 {
  2493. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2494. return
  2495. }
  2496. if totals > stock_total_count {
  2497. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2498. return
  2499. }
  2500. //查找今日该患者已经出库的所有耗材
  2501. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2502. for _, item := range goodList {
  2503. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2504. var flush_count int64
  2505. for _, it := range goodListSix {
  2506. flush_count += it.StockCount
  2507. }
  2508. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2509. creater := adminInfo.AdminUser.Id
  2510. if errs != nil {
  2511. goodErrcode := models.XtGoodErrcode{
  2512. UserOrgId: item.OrgId,
  2513. Errcode: "手动出库更新剩余出库失败",
  2514. GoodId: item.GoodId,
  2515. Status: 1,
  2516. Ctime: time.Now().Unix(),
  2517. Mtime: 0,
  2518. Count: 0,
  2519. StockCount: 0,
  2520. Creater: creater,
  2521. BatchNumberId: 0,
  2522. WarehouseOutId: 0,
  2523. }
  2524. service.CreateGoodErrcode(goodErrcode)
  2525. }
  2526. }
  2527. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2528. }
  2529. //有出库记录
  2530. if len(goodWarehouseInfo) > 0 {
  2531. //查询该患者耗材的历史数据
  2532. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2533. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2534. //数量发生改变
  2535. if parsetotal != count {
  2536. //查找今日该患者已经出库的所有耗材
  2537. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2538. for _, item := range goodList {
  2539. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2540. var flush_count int64
  2541. for _, it := range goodListSix {
  2542. flush_count += it.StockCount
  2543. }
  2544. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2545. //减少出库数量
  2546. creater := adminInfo.AdminUser.Id
  2547. if errs != nil {
  2548. goodErrcode := models.XtGoodErrcode{
  2549. UserOrgId: item.OrgId,
  2550. Errcode: "手动出库更新剩余出库失败",
  2551. GoodId: item.GoodId,
  2552. Status: 1,
  2553. Ctime: time.Now().Unix(),
  2554. Mtime: 0,
  2555. Count: 0,
  2556. StockCount: 0,
  2557. Creater: creater,
  2558. BatchNumberId: 0,
  2559. WarehouseOutId: 0,
  2560. }
  2561. service.CreateGoodErrcode(goodErrcode)
  2562. }
  2563. //查询默认仓库
  2564. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2565. var total_count int64
  2566. for _, it := range stockList {
  2567. total_count += it.StockCount
  2568. }
  2569. //基础库插入数据
  2570. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2571. }
  2572. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2573. }
  2574. }
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2585. var hpInfo models.HisPrescriptionInfo
  2586. if info.ID == 0 {
  2587. var randNum int
  2588. randNum = rand.Intn(10000) + 1000
  2589. timestamp := time.Now().Unix()
  2590. tempTime := time.Unix(timestamp, 0)
  2591. timeFormat := tempTime.Format("20060102150405")
  2592. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2593. hpInfo = models.HisPrescriptionInfo{
  2594. HisPatientId: his_patient_id,
  2595. UserOrgId: adminInfo.CurrentOrgId,
  2596. RecordDate: theTime.Unix(),
  2597. PatientId: patient_id,
  2598. Status: 1,
  2599. Ctime: time.Now().Unix(),
  2600. Mtime: time.Now().Unix(),
  2601. Creator: adminInfo.AdminUser.Id,
  2602. Modifier: adminInfo.AdminUser.Id,
  2603. Diagnosis: diagnose,
  2604. SickHistory: sick_history,
  2605. Departments: department,
  2606. RegisterType: reg_type,
  2607. PrescriptionNumber: p_number,
  2608. PrescriptionStatus: 1,
  2609. Doctor: role.UserName,
  2610. DoctorId: doctor_id,
  2611. SickType: sick_type,
  2612. PType: p_type,
  2613. PatientDiagnosis: patient_diagnose,
  2614. }
  2615. service.SavePatientPrescriptionInfo(hpInfo)
  2616. //创建步骤表
  2617. finish := models.XtDialysisFinish{
  2618. IsFinish: 1,
  2619. UserOrgId: adminInfo.CurrentOrgId,
  2620. Status: 1,
  2621. Ctime: time.Now().Unix(),
  2622. Mtime: 0,
  2623. Module: 4,
  2624. RecordDate: theTime.Unix(),
  2625. Sourse: 1,
  2626. PatientId: patient_id,
  2627. }
  2628. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2629. if dialysisFinish.ID == 0 {
  2630. service.CreateDialysisFinish(finish)
  2631. }
  2632. redis := service.RedisClient()
  2633. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2634. redis.Set(key, "", time.Second)
  2635. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2636. redis.Set(keyOne, "", time.Second)
  2637. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2638. redis.Set(keySeven, "", time.Second)
  2639. defer redis.Close()
  2640. } else {
  2641. hpInfo = models.HisPrescriptionInfo{
  2642. ID: info.ID,
  2643. UserOrgId: adminInfo.CurrentOrgId,
  2644. RecordDate: info.RecordDate,
  2645. PatientId: info.PatientId,
  2646. Status: 1,
  2647. Ctime: info.Ctime,
  2648. Mtime: time.Now().Unix(),
  2649. Creator: info.Creator,
  2650. Modifier: adminInfo.AdminUser.Id,
  2651. Diagnosis: diagnose,
  2652. SickHistory: sick_history,
  2653. Departments: department,
  2654. RegisterType: reg_type,
  2655. PrescriptionNumber: info.PrescriptionNumber,
  2656. Doctor: role.UserName,
  2657. PrescriptionStatus: info.PrescriptionStatus,
  2658. DoctorId: doctor_id,
  2659. SickType: sick_type,
  2660. PType: info.PType,
  2661. HisPatientId: info.HisPatientId,
  2662. PatientDiagnosis: patient_diagnose,
  2663. }
  2664. service.SavePatientPrescriptionInfo(hpInfo)
  2665. //创建步骤表
  2666. finish := models.XtDialysisFinish{
  2667. IsFinish: 1,
  2668. UserOrgId: adminInfo.CurrentOrgId,
  2669. Status: 1,
  2670. Ctime: time.Now().Unix(),
  2671. Mtime: 0,
  2672. Module: 4,
  2673. RecordDate: info.RecordDate,
  2674. Sourse: 1,
  2675. PatientId: info.PatientId,
  2676. }
  2677. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2678. if dialysisFinish.ID == 0 {
  2679. service.CreateDialysisFinish(finish)
  2680. }
  2681. redis := service.RedisClient()
  2682. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2683. redis.Set(key, "", time.Second)
  2684. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2685. redis.Set(keyOne, "", time.Second)
  2686. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2687. redis.Set(keySeven, "", time.Second)
  2688. defer redis.Close()
  2689. }
  2690. //定义切片
  2691. var adviceList []models.HisDoctorAdviceInfo
  2692. var projectList []models.HisPrescriptionProject
  2693. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 {
  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. fmt.Println("preTime", preTime)
  2739. timeLayout := "2006-01-02"
  2740. loc, _ := time.LoadLocation("Local")
  2741. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2742. result := strings.Split(preTime, " ")
  2743. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2744. if err != nil {
  2745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2746. return
  2747. }
  2748. pTime := theTime2.Unix()
  2749. ctime := time.Now().Unix()
  2750. if tempPrescription.ID == 0 {
  2751. prescription := &models.HisPrescription{
  2752. ID: 0,
  2753. PatientId: patient_id,
  2754. UserOrgId: adminInfo.CurrentOrgId,
  2755. RecordDate: recordDateTime,
  2756. Ctime: ctime,
  2757. Mtime: ctime,
  2758. Type: types,
  2759. Modifier: adminInfo.AdminUser.Id,
  2760. Creator: adminInfo.AdminUser.Id,
  2761. Status: 1,
  2762. Doctor: role.UserName,
  2763. HisPatientId: his_patient_id,
  2764. OrderStatus: 1,
  2765. BatchNumber: "",
  2766. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2767. PreTime: pTime,
  2768. PType: p_type,
  2769. MedType: med_type,
  2770. }
  2771. tempPrescription = prescription
  2772. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2773. redis := service.RedisClient()
  2774. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2775. redis.Set(key, "", time.Second)
  2776. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2777. redis.Set(keyOne, "", time.Second)
  2778. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2779. redis.Set(keySeven, "", time.Second)
  2780. defer redis.Close()
  2781. } else {
  2782. tempPrescription.ID = id
  2783. tempPrescription.Type = types
  2784. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2785. tempPrescription.Mtime = time.Now().Unix()
  2786. tempPrescription.Doctor = role.UserName
  2787. //tempPrescription.OrderStatus = order_status
  2788. tempPrescription.PreTime = pTime
  2789. tempPrescription.MedType = med_type
  2790. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2791. redis := service.RedisClient()
  2792. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2793. redis.Set(key, "", time.Second)
  2794. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2795. redis.Set(keyOne, "", time.Second)
  2796. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2797. redis.Set(keySeven, "", time.Second)
  2798. defer redis.Close()
  2799. }
  2800. //service.SaveHisPrescription(prescription)
  2801. //更改患者挂号状态
  2802. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2803. fmt.Println("更改失败", err2)
  2804. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2805. advices := items["advices"].([]interface{})
  2806. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2807. groupNo := int64(0)
  2808. ctime := time.Now().Unix()
  2809. mtime := ctime
  2810. if len(advices) > 0 {
  2811. for _, advice := range advices {
  2812. tx := db.Begin()
  2813. // 在函数结束时处理事务回滚
  2814. defer func() {
  2815. if r := recover(); r != nil {
  2816. tx.Rollback()
  2817. }
  2818. }()
  2819. var s models.HisDoctorAdviceInfo
  2820. s.PrescriptionId = tempPrescription.ID
  2821. s.AdviceType = 2
  2822. s.AdviceDoctor = doctor_id
  2823. s.StopState = 2
  2824. s.ExecutionState = 2
  2825. s.AdviceDate = theTime3.Unix()
  2826. s.Status = 1
  2827. s.UserOrgId = adminInfo.CurrentOrgId
  2828. s.RecordDate = theTime3.Unix()
  2829. s.StartTime = tempPrescription.PreTime
  2830. s.Groupno = groupNo
  2831. s.CreatedTime = ctime
  2832. s.UpdatedTime = mtime
  2833. s.PatientId = patient_id
  2834. s.HisPatientId = his_patient_id
  2835. s.StartTime = pTime
  2836. s.IsSettle = 2
  2837. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2838. if errcode > 0 {
  2839. c.ServeFailJSONWithSGJErrorCode(errcode)
  2840. return
  2841. }
  2842. s.StartTime = pTime
  2843. var total_count int64 //处方总库存
  2844. //查询改药品信息
  2845. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2846. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2847. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2848. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2849. total_count += prescribingNumberSeven * medical.MinNumber
  2850. }
  2851. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2852. total_count += prescribingNumberSeven
  2853. }
  2854. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2855. total_count += prescribingNumberSeven
  2856. }
  2857. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2858. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2859. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2860. if s.Price != lastWarehouse.RetailPrice {
  2861. s.Price = lastWarehouse.RetailPrice
  2862. }
  2863. if s.Price == 0 {
  2864. s.Price = lastWarehouse.RetailPrice
  2865. }
  2866. }
  2867. //查询保存处方出库开关是否打开
  2868. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2869. if drugOutConfig.IsOpen == 1 {
  2870. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2871. // 查询该药品最后一次出库记录
  2872. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2873. if len(druginfo) > 0 {
  2874. //回退库存
  2875. for _, it := range druginfo {
  2876. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2877. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2878. }
  2879. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2880. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2881. }
  2882. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2883. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2884. }
  2885. }
  2886. //删除记录
  2887. service.DeleteDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2888. }
  2889. service.CreateHisDoctorAdviceOne(&s, tx)
  2890. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2891. //出库
  2892. if drug.IsUse == 2 {
  2893. creater := adminInfo.AdminUser.Id
  2894. newadviceInfo := &models.HisDoctorAdviceInfo{
  2895. ID: advicelast.ID,
  2896. UserOrgId: s.UserOrgId,
  2897. PatientId: s.PatientId,
  2898. HisPatientId: s.HisPatientId,
  2899. AdviceType: s.AdviceType,
  2900. AdviceDate: s.AdviceDate,
  2901. StartTime: s.StartTime,
  2902. AdviceName: s.AdviceName,
  2903. AdviceDesc: s.AdviceDesc,
  2904. ReminderDate: s.ReminderDate,
  2905. SingleDose: s.SingleDose,
  2906. SingleDoseUnit: s.SingleDoseUnit,
  2907. PrescribingNumber: s.PrescribingNumber,
  2908. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2909. DeliveryWay: s.DeliveryWay,
  2910. ExecutionFrequency: s.ExecutionFrequency,
  2911. AdviceDoctor: s.AdviceDoctor,
  2912. Status: s.Status,
  2913. CreatedTime: s.CreatedTime,
  2914. UpdatedTime: s.UpdatedTime,
  2915. AdviceAffirm: s.AdviceAffirm,
  2916. Remark: s.Remark,
  2917. StopTime: s.StopTime,
  2918. StopReason: s.StopReason,
  2919. StopDoctor: s.StopDoctor,
  2920. StopState: s.StopState,
  2921. ParentId: s.ParentId,
  2922. ExecutionTime: s.ExecutionTime,
  2923. ExecutionStaff: s.ExecutionStaff,
  2924. ExecutionState: s.ExecutionState,
  2925. Checker: s.Checker,
  2926. RecordDate: s.RecordDate,
  2927. DialysisOrderId: s.DialysisOrderId,
  2928. CheckTime: s.CheckTime,
  2929. CheckState: s.CheckState,
  2930. DrugSpec: s.DrugSpec,
  2931. DrugSpecUnit: s.DrugSpecUnit,
  2932. Groupno: s.Groupno,
  2933. RemindType: s.RemindType,
  2934. FrequencyType: s.FrequencyType,
  2935. DayCount: s.DayCount,
  2936. WeekDay: s.WeekDay,
  2937. TemplateId: s.TemplateId,
  2938. Modifier: s.Modifier,
  2939. DrugId: s.DrugId,
  2940. Price: s.Price,
  2941. PrescriptionId: s.PrescriptionId,
  2942. MedListCodg: s.MedListCodg,
  2943. FeedetlSn: s.FeedetlSn,
  2944. Day: s.DayCount,
  2945. ChildDoctorAdvice: nil,
  2946. Drug: models.Drug{},
  2947. Diagnosis: s.Diagnosis,
  2948. Way: s.Way,
  2949. HospApprFlag: s.HospApprFlag,
  2950. LmtUsedFlag: s.LmtUsedFlag,
  2951. HisOrderInfo: models.HisOrderInfo{},
  2952. IsMedicine: s.IsMedicine,
  2953. ExecutionFrequencyId: s.ExecutionFrequencyId,
  2954. Child: nil,
  2955. IsSettle: s.IsSettle,
  2956. IsMobile: s.IsMobile,
  2957. IsSelfDrug: s.IsSelfDrug,
  2958. DrugWayCount: s.DrugWayCount,
  2959. }
  2960. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  2961. }
  2962. //更新字典里面的库存
  2963. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  2964. var sum_count int64
  2965. for _, its := range stockInfo {
  2966. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  2967. if its.MaxUnit == baseDrug.MaxUnit {
  2968. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2969. }
  2970. sum_count += its.StockMaxNumber + its.StockMinNumber
  2971. }
  2972. //更新基础库存
  2973. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  2974. //剩余库存
  2975. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  2976. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  2977. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  2978. }
  2979. //记录日志
  2980. byterequest, _ := json.Marshal(s)
  2981. adviceLog := models.XtDoctorAdviceLog{
  2982. UserOrgId: s.UserOrgId,
  2983. PatientId: s.PatientId,
  2984. AdminUserId: adminInfo.AdminUser.Id,
  2985. Module: 1,
  2986. ErrLog: string(byterequest),
  2987. Status: 1,
  2988. Ctime: time.Now().Unix(),
  2989. Mtime: 0,
  2990. Source: "电脑端新建his医嘱",
  2991. RecordDate: s.AdviceDate,
  2992. }
  2993. service.CreateDoctorAdviceLog(adviceLog)
  2994. //存储切片中
  2995. adviceList = append(adviceList, s)
  2996. redis := service.RedisClient()
  2997. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2998. redis.Set(key, "", time.Second)
  2999. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3000. redis.Set(keyOne, "", time.Second)
  3001. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3002. redis.Set(keySeven, "", time.Second)
  3003. var randNum int
  3004. randNum = rand.Intn(10000) + 1000
  3005. timestamp := time.Now().Unix()
  3006. tempTime := time.Unix(timestamp, 0)
  3007. timeFormat := tempTime.Format("20060102150405")
  3008. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3009. service.CreateHisDoctorAdviceOne(&s, tx)
  3010. tx.Commit()
  3011. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3012. redis.Set(keySix, "", time.Second)
  3013. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3014. redis.Set(keyFive, "", time.Second)
  3015. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3016. redis.Set(keyEight, "", time.Second)
  3017. defer redis.Close()
  3018. }
  3019. }
  3020. }
  3021. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3022. projects := items["project"].([]interface{})
  3023. if len(projects) > 0 {
  3024. for _, project := range projects {
  3025. tx := db.Begin()
  3026. // 在函数结束时处理事务回滚
  3027. defer func() {
  3028. if r := recover(); r != nil {
  3029. tx.Rollback()
  3030. }
  3031. }()
  3032. var p models.HisPrescriptionProject
  3033. p.PrescriptionId = tempPrescription.ID
  3034. p.Ctime = time.Now().Unix()
  3035. p.Mtime = time.Now().Unix()
  3036. p.PatientId = patient_id
  3037. p.RecordDate = theTime3.Unix()
  3038. p.Doctor = doctor_id
  3039. p.UserOrgId = adminInfo.CurrentOrgId
  3040. p.HisPatientId = his_patient_id
  3041. p.Status = 1
  3042. p.StartTime = pTime
  3043. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3044. if errcode > 0 {
  3045. c.ServeFailJSONWithSGJErrorCode(errcode)
  3046. return
  3047. }
  3048. if p.ID == 0 {
  3049. p.IsOut = 2
  3050. }
  3051. if p.ID > 0 {
  3052. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3053. p.IsOut = projectDetail.IsOut
  3054. }
  3055. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3056. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3057. if p.Type == 3 {
  3058. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3059. if p.Price != lastWarehouse.PackingPrice {
  3060. p.Price = lastWarehouse.PackingPrice
  3061. }
  3062. if p.Unit == "" {
  3063. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3064. p.Unit = goodInfoOne.PackingUnit
  3065. }
  3066. }
  3067. }
  3068. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3069. //
  3070. // if p.Type == 3 {
  3071. // //查询该耗材是否停用
  3072. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3073. // //表示该耗材已经停用,不能保存
  3074. // if goodInfoSeven.ID == 0 {
  3075. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3076. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3077. // return
  3078. // }
  3079. // }
  3080. //
  3081. //}
  3082. service.CreateNewHisProjectTwo(&p, tx)
  3083. //查询保存耗材出库开关是否打开
  3084. if goodOutConfig.IsOpen == 1 {
  3085. //耗材出库
  3086. if p.Type == 3 {
  3087. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3088. //查询历史出库数据
  3089. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3090. var out_count_five int64
  3091. for _, item := range flowGood {
  3092. out_count_five += item.Count
  3093. }
  3094. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3095. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3096. if out_count_five != parseIntCount {
  3097. //查询耗材最后一次出库记录
  3098. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3099. //查询默认出库仓库库存
  3100. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3101. if len(wareOut) > 0 {
  3102. for _, it := range wareOut {
  3103. //回退库存
  3104. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3105. //删除出库记录
  3106. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3107. }
  3108. }
  3109. timeStr := time.Now().Format("2006-01-02")
  3110. timeArr := strings.Split(timeStr, "-")
  3111. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3112. total = total + 1
  3113. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3114. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3115. number = number + total
  3116. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3117. operation_time := time.Now().Unix()
  3118. creater := c.GetAdminUserInfo().AdminUser.Id
  3119. recordDateStr := time.Now().Format("2006-01-02")
  3120. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3121. nowtime := recordDate.Unix()
  3122. warehouseOut := models.WarehouseOut{
  3123. WarehouseOutOrderNumber: warehousing_out_order,
  3124. OperationTime: operation_time,
  3125. OrgId: adminInfo.CurrentOrgId,
  3126. Creater: creater,
  3127. Ctime: time.Now().Unix(),
  3128. Status: 1,
  3129. WarehouseOutTime: nowtime,
  3130. Type: 1,
  3131. StorehouseId: storeConfig.StorehouseOutInfo,
  3132. IsCheck: 1,
  3133. IsSys: 1,
  3134. }
  3135. //查询是否生成出库单
  3136. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3137. if out.ID == 0 {
  3138. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3139. }
  3140. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3141. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3142. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3143. dialyPrepareOne := models.DialysisBeforePrepare{
  3144. GoodTypeId: goodObj.GoodTypeId,
  3145. GoodId: p.ProjectId,
  3146. PatientId: p.PatientId,
  3147. RecordDate: p.RecordDate,
  3148. UserOrgId: adminInfo.CurrentOrgId,
  3149. Count: parseIntCount,
  3150. Ctime: time.Now().Unix(),
  3151. Creater: creater,
  3152. Status: 1,
  3153. StorehouseId: houseConfig.StorehouseOutInfo,
  3154. ProjectId: lastHisProject.ID,
  3155. }
  3156. //判断是否是零用耗材(非零用)
  3157. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3158. //查询历史出库数据
  3159. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3160. var out_count int64
  3161. for _, item := range flowGood {
  3162. out_count += item.Count
  3163. }
  3164. //如果历史数和当前数据不想等才进行退库出库
  3165. if out_count != parseIntCount {
  3166. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3167. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3168. detail := models.AutomaticReduceDetail{
  3169. WarehouseOutId: 0,
  3170. WarehouseOutOrderNumber: "",
  3171. PatientId: p.PatientId,
  3172. Ctime: time.Now().Unix(),
  3173. Mtime: 0,
  3174. Status: 1,
  3175. RecordTime: p.RecordDate,
  3176. OrgId: p.UserOrgId,
  3177. GoodId: p.ProjectId,
  3178. GoodTypeId: 0,
  3179. Count: parseIntCount,
  3180. Type: 0,
  3181. ProjectId: lastHisProject.ID,
  3182. StorehouseId: 0,
  3183. }
  3184. service.CreateNewAutoDetail(detail, tx)
  3185. //查询剩余库存
  3186. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3187. var sum_count int64
  3188. for _, item := range goodList {
  3189. sum_count += item.StockCount
  3190. }
  3191. //更新剩余库存
  3192. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3193. //耗材
  3194. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3195. }
  3196. //判断是否是零用耗材(零用但是是出库耗材)
  3197. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3198. //查询历史出库数据
  3199. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3200. var out_count int64
  3201. for _, item := range flowGood {
  3202. out_count += item.Count
  3203. }
  3204. //如果历史数和当前数据不想等才进行退库出库
  3205. if out_count != parseIntCount {
  3206. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3207. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3208. detail := models.AutomaticReduceDetail{
  3209. WarehouseOutId: 0,
  3210. WarehouseOutOrderNumber: "",
  3211. PatientId: p.PatientId,
  3212. Ctime: time.Now().Unix(),
  3213. Mtime: 0,
  3214. Status: 1,
  3215. RecordTime: p.RecordDate,
  3216. OrgId: p.UserOrgId,
  3217. GoodId: p.ProjectId,
  3218. GoodTypeId: 0,
  3219. Count: parseIntCount,
  3220. Type: 0,
  3221. ProjectId: p.ID,
  3222. StorehouseId: 0,
  3223. }
  3224. service.CreateNewAutoDetail(detail, tx)
  3225. //查询剩余库存
  3226. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3227. var sum_count int64
  3228. for _, item := range goodList {
  3229. sum_count += item.StockCount
  3230. }
  3231. //更新剩余库存
  3232. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3233. //耗材
  3234. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3235. }
  3236. }
  3237. }
  3238. }
  3239. //记录日志
  3240. byterequest, _ := json.Marshal(p)
  3241. adviceLog := models.XtDoctorAdviceLog{
  3242. UserOrgId: p.UserOrgId,
  3243. PatientId: p.PatientId,
  3244. AdminUserId: adminInfo.AdminUser.Id,
  3245. Module: 1,
  3246. ErrLog: string(byterequest),
  3247. Status: 1,
  3248. Ctime: time.Now().Unix(),
  3249. Mtime: 0,
  3250. Source: "电脑端新建his项目",
  3251. RecordDate: p.RecordDate,
  3252. }
  3253. service.CreateDoctorAdviceLog(adviceLog)
  3254. projectList = append(projectList, p)
  3255. var randNum int
  3256. randNum = rand.Intn(10000) + 1000
  3257. timestamp := time.Now().Unix()
  3258. tempTime := time.Unix(timestamp, 0)
  3259. timeFormat := tempTime.Format("20060102150405")
  3260. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3261. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3262. //新增或者编辑项目,修改对应的标签数据
  3263. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3264. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3265. var label models.HisLabelPrintInfo
  3266. project, _ := service.GetProjectDetail(p.ProjectId)
  3267. if project.CostClassify == 3 { //类别为检验检查
  3268. if p.TeamId > 0 { //检验检查组套
  3269. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3270. if tempLabel.ID == 0 {
  3271. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3272. label.Number = tempPrescription.PrescriptionNumber
  3273. label.ProjectId = project.ID
  3274. label.Status = 1
  3275. label.IsPrint = 2
  3276. label.DoctorId = info.DoctorId
  3277. label.UserOrgId = p.UserOrgId
  3278. label.PatientId = patient_id
  3279. label.RecordDate = recordDateTime
  3280. label.Ctime = time.Now().Unix()
  3281. label.Mtime = time.Now().Unix()
  3282. label.ItemId = p.TeamId
  3283. label.FeedetlSn = p.FeedetlSn
  3284. label.PProjectId = p.ID
  3285. label.ProjectName = team.ProjectTeam
  3286. label.PatientName = patient.Name
  3287. service.CreateNewHisLabelRecord(&label, tx)
  3288. }
  3289. } else { //单条检验检查项目
  3290. label.Number = tempPrescription.PrescriptionNumber
  3291. label.ProjectId = project.ID
  3292. label.Status = 1
  3293. label.DoctorId = info.DoctorId
  3294. label.UserOrgId = p.UserOrgId
  3295. label.PatientId = patient_id
  3296. label.RecordDate = recordDateTime
  3297. label.IsPrint = 2
  3298. label.Ctime = time.Now().Unix()
  3299. label.Mtime = time.Now().Unix()
  3300. label.FeedetlSn = p.FeedetlSn
  3301. label.PProjectId = p.ID
  3302. label.ItemId = p.TeamId
  3303. label.ProjectName = project.ProjectName
  3304. label.PatientName = patient.Name
  3305. service.CreateNewHisLabelRecord(&label, tx)
  3306. }
  3307. }
  3308. }
  3309. }
  3310. service.SaveNewHisProjectTwo(&p, tx)
  3311. }
  3312. }
  3313. tx.Commit()
  3314. }
  3315. }
  3316. }
  3317. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3318. // addition := items["addition"].([]interface{})
  3319. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3320. // ctime := time.Now().Unix()
  3321. // mtime := ctime
  3322. // if len(addition) > 0 {
  3323. // for _, item := range addition {
  3324. // var s models.HisAdditionalCharge
  3325. // s.PrescriptionId = tempPrescription.ID
  3326. // s.Status = 1
  3327. // s.UserOrgId = adminInfo.CurrentOrgId
  3328. // s.RecordDate = recordDateTime
  3329. // s.CreatedTime = ctime
  3330. // s.UpdatedTime = mtime
  3331. // s.PatientId = patient_id
  3332. // s.HisPatientId = his_patient_id
  3333. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3334. // if errcode > 0 {
  3335. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3336. // return
  3337. // }
  3338. // service.CreateAdditionalCharge(&s)
  3339. // var randNum int
  3340. // randNum = rand.Intn(10000) + 1000
  3341. // timestamp := time.Now().Unix()
  3342. // tempTime := time.Unix(timestamp, 0)
  3343. // timeFormat := tempTime.Format("20060102150405")
  3344. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3345. // service.CreateAdditionalCharge(&s)
  3346. //
  3347. // }
  3348. // }
  3349. //}
  3350. }
  3351. }
  3352. //查询今日该患者开的药品处方
  3353. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3354. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3355. //药品出库
  3356. //if drugOutConfig.IsOpen == 1 {
  3357. // for _, item := range hisdoctorlist {
  3358. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3359. //
  3360. // // 查询该药品最后一次出库记录
  3361. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3362. //
  3363. // if len(druginfo) > 0 {
  3364. // //回退库存
  3365. // for _, it := range druginfo {
  3366. //
  3367. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3368. //
  3369. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3370. //
  3371. // }
  3372. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3373. //
  3374. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3375. //
  3376. // }
  3377. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3378. //
  3379. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3380. //
  3381. // }
  3382. // }
  3383. // }
  3384. //
  3385. // //删除记录
  3386. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3387. // //查询最后一次数据
  3388. // if drugOutConfig.IsOpen == 1 {
  3389. // //出库
  3390. // if drug.IsUse == 2 {
  3391. // creater := adminInfo.AdminUser.Id
  3392. //
  3393. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3394. //
  3395. // }
  3396. //
  3397. // //更新字典里面的库存
  3398. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3399. // var sum_count int64
  3400. // for _, its := range stockInfo {
  3401. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3402. // if its.MaxUnit == baseDrug.MaxUnit {
  3403. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3404. // }
  3405. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3406. // }
  3407. // //更新基础库存
  3408. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3409. // //剩余库存
  3410. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3411. //
  3412. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3413. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3414. //
  3415. // }
  3416. // }
  3417. //}
  3418. //耗材保存处方出库
  3419. //if goodOutConfig.IsOpen == 1 {
  3420. //
  3421. // //查询今日耗材出库数量
  3422. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3423. //
  3424. // for _, item := range hisgoodlist {
  3425. //
  3426. // //查询历史出库数据
  3427. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3428. // var out_count_five int64
  3429. // for _, item := range flowGood {
  3430. // out_count_five += item.Count
  3431. // }
  3432. //
  3433. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3434. //
  3435. // if out_count_five != parseIntCount {
  3436. //
  3437. // //查询耗材最后一次出库记录
  3438. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3439. // //查询默认出库仓库库存
  3440. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3441. // if len(wareOut) > 0 {
  3442. //
  3443. // for _, it := range wareOut {
  3444. // //回退库存
  3445. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3446. //
  3447. // //删除出库记录
  3448. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3449. //
  3450. // }
  3451. // }
  3452. //
  3453. // timeStr := time.Now().Format("2006-01-02")
  3454. // timeArr := strings.Split(timeStr, "-")
  3455. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3456. //
  3457. // total = total + 1
  3458. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3459. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3460. // number = number + total
  3461. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3462. //
  3463. // operation_time := time.Now().Unix()
  3464. // creater := c.GetAdminUserInfo().AdminUser.Id
  3465. //
  3466. // recordDateStr := time.Now().Format("2006-01-02")
  3467. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3468. // nowtime := recordDate.Unix()
  3469. // warehouseOut := models.WarehouseOut{
  3470. // WarehouseOutOrderNumber: warehousing_out_order,
  3471. // OperationTime: operation_time,
  3472. // OrgId: adminInfo.CurrentOrgId,
  3473. // Creater: creater,
  3474. // Ctime: time.Now().Unix(),
  3475. // Status: 1,
  3476. // WarehouseOutTime: nowtime,
  3477. // Type: 1,
  3478. // StorehouseId: storeConfig.StorehouseOutInfo,
  3479. // IsCheck: 1,
  3480. // IsSys: 1,
  3481. // }
  3482. // //查询是否生成出库单
  3483. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3484. //
  3485. // if out.ID == 0 {
  3486. // service.AddSigleWarehouseOut(&warehouseOut)
  3487. // }
  3488. //
  3489. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3490. //
  3491. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3492. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3493. //
  3494. // dialyPrepareOne := models.DialysisBeforePrepare{
  3495. // GoodTypeId: goodObj.GoodTypeId,
  3496. // GoodId: item.ProjectId,
  3497. // PatientId: item.PatientId,
  3498. // RecordDate: item.RecordDate,
  3499. // UserOrgId: adminInfo.CurrentOrgId,
  3500. // Count: parseIntCount,
  3501. // Ctime: time.Now().Unix(),
  3502. // Creater: creater,
  3503. // Status: 1,
  3504. // StorehouseId: houseConfig.StorehouseOutInfo,
  3505. // ProjectId: item.ID,
  3506. // }
  3507. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3508. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3509. //
  3510. // //查询历史出库数据
  3511. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3512. // var out_count int64
  3513. // for _, item := range flowGood {
  3514. // out_count += item.Count
  3515. // }
  3516. //
  3517. // //如果历史数和当前数据不想等才进行退库出库
  3518. // if out_count != parseIntCount {
  3519. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3520. //
  3521. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3522. // detail := models.AutomaticReduceDetail{
  3523. // WarehouseOutId: 0,
  3524. // WarehouseOutOrderNumber: "",
  3525. // PatientId: item.PatientId,
  3526. // Ctime: time.Now().Unix(),
  3527. // Mtime: 0,
  3528. // Status: 1,
  3529. // RecordTime: item.RecordDate,
  3530. // OrgId: item.UserOrgId,
  3531. // GoodId: item.ProjectId,
  3532. // GoodTypeId: 0,
  3533. // Count: parseIntCount,
  3534. // Type: 0,
  3535. // ProjectId: item.ID,
  3536. // StorehouseId: 0,
  3537. // }
  3538. //
  3539. // service.CreateAutoDetail(detail)
  3540. //
  3541. // //查询剩余库存
  3542. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3543. // var sum_count int64
  3544. // for _, item := range goodList {
  3545. // sum_count += item.StockCount
  3546. // }
  3547. //
  3548. // //更新剩余库存
  3549. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3550. //
  3551. // //耗材
  3552. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3553. // }
  3554. //
  3555. // }
  3556. //
  3557. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3558. // //查询历史出库数据
  3559. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3560. // var out_count int64
  3561. // for _, item := range flowGood {
  3562. // out_count += item.Count
  3563. // }
  3564. // //如果历史数和当前数据不想等才进行退库出库
  3565. // if out_count != parseIntCount {
  3566. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3567. //
  3568. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3569. // detail := models.AutomaticReduceDetail{
  3570. // WarehouseOutId: 0,
  3571. // WarehouseOutOrderNumber: "",
  3572. // PatientId: item.PatientId,
  3573. // Ctime: time.Now().Unix(),
  3574. // Mtime: 0,
  3575. // Status: 1,
  3576. // RecordTime: item.RecordDate,
  3577. // OrgId: item.UserOrgId,
  3578. // GoodId: item.ProjectId,
  3579. // GoodTypeId: 0,
  3580. // Count: parseIntCount,
  3581. // Type: 0,
  3582. // ProjectId: item.ID,
  3583. // StorehouseId: 0,
  3584. // }
  3585. //
  3586. // service.CreateAutoDetail(detail)
  3587. //
  3588. // //查询剩余库存
  3589. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3590. // var sum_count int64
  3591. // for _, item := range goodList {
  3592. // sum_count += item.StockCount
  3593. // }
  3594. //
  3595. // //更新剩余库存
  3596. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3597. //
  3598. // //耗材
  3599. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3600. // }
  3601. //
  3602. // }
  3603. //
  3604. // }
  3605. // }
  3606. //}
  3607. }
  3608. tx.Commit()
  3609. if err == nil {
  3610. c.ServeSuccessJSON(map[string]interface{}{
  3611. "msg": "保存成功",
  3612. })
  3613. return
  3614. } else {
  3615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3616. return
  3617. }
  3618. } else {
  3619. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3620. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3621. var tempPrescription *models.HisPrescription
  3622. if len(prescriptions) > 0 {
  3623. for _, item := range prescriptions {
  3624. items := item.(map[string]interface{})
  3625. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3626. utils.ErrorLog("id")
  3627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3628. return
  3629. }
  3630. id := int64(items["id"].(float64))
  3631. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3632. tempPrescription = &new_prescription
  3633. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3634. utils.ErrorLog("type")
  3635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3636. return
  3637. }
  3638. types := int64(items["type"].(float64))
  3639. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3640. utils.ErrorLog("med_type")
  3641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3642. return
  3643. }
  3644. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3645. if med_type == "0" {
  3646. med_type = "14"
  3647. }
  3648. //if order_status == 0 {
  3649. // order_status = 1
  3650. //}
  3651. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3652. utils.ErrorLog("pre_time")
  3653. }
  3654. preTime, _ := items["pre_time"].(string)
  3655. timeLayout := "2006-01-02"
  3656. loc, _ := time.LoadLocation("Local")
  3657. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3658. result := strings.Split(preTime, " ")
  3659. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3660. if err != nil {
  3661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3662. return
  3663. }
  3664. pTime := theTime2.Unix()
  3665. ctime := time.Now().Unix()
  3666. if tempPrescription.ID == 0 {
  3667. prescription := &models.HisPrescription{
  3668. ID: 0,
  3669. PatientId: patient_id,
  3670. UserOrgId: adminInfo.CurrentOrgId,
  3671. RecordDate: recordDateTime,
  3672. Ctime: ctime,
  3673. Mtime: ctime,
  3674. Type: types,
  3675. Modifier: adminInfo.AdminUser.Id,
  3676. Creator: adminInfo.AdminUser.Id,
  3677. Status: 1,
  3678. Doctor: role.UserName,
  3679. HisPatientId: his_patient_id,
  3680. OrderStatus: 1,
  3681. BatchNumber: "",
  3682. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3683. PreTime: pTime,
  3684. PType: p_type,
  3685. MedType: med_type,
  3686. }
  3687. tempPrescription = prescription
  3688. service.SaveHisPrescription(tempPrescription)
  3689. redis := service.RedisClient()
  3690. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3691. redis.Set(key, "", time.Second)
  3692. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3693. redis.Set(keyOne, "", time.Second)
  3694. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3695. redis.Set(keySeven, "", time.Second)
  3696. defer redis.Close()
  3697. } else {
  3698. tempPrescription.ID = id
  3699. tempPrescription.Type = types
  3700. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3701. tempPrescription.Mtime = time.Now().Unix()
  3702. tempPrescription.Doctor = role.UserName
  3703. //tempPrescription.OrderStatus = order_status
  3704. tempPrescription.PreTime = pTime
  3705. tempPrescription.MedType = med_type
  3706. service.SaveHisPrescription(tempPrescription)
  3707. redis := service.RedisClient()
  3708. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3709. redis.Set(key, "", time.Second)
  3710. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3711. redis.Set(keyOne, "", time.Second)
  3712. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3713. redis.Set(keySeven, "", time.Second)
  3714. defer redis.Close()
  3715. }
  3716. //service.SaveHisPrescription(prescription)
  3717. //更改患者挂号状态
  3718. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3719. fmt.Println("更改失败", err2)
  3720. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3721. advices := items["advices"].([]interface{})
  3722. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3723. groupNo := int64(0)
  3724. ctime := time.Now().Unix()
  3725. mtime := ctime
  3726. if len(advices) > 0 {
  3727. for _, advice := range advices {
  3728. var s models.HisDoctorAdviceInfo
  3729. s.PrescriptionId = tempPrescription.ID
  3730. s.AdviceType = 2
  3731. s.AdviceDoctor = doctor_id
  3732. s.StopState = 2
  3733. s.ExecutionState = 2
  3734. s.AdviceDate = theTime3.Unix()
  3735. s.Status = 1
  3736. s.UserOrgId = adminInfo.CurrentOrgId
  3737. s.RecordDate = theTime3.Unix()
  3738. s.StartTime = tempPrescription.PreTime
  3739. s.Groupno = groupNo
  3740. s.CreatedTime = ctime
  3741. s.UpdatedTime = mtime
  3742. s.PatientId = patient_id
  3743. s.HisPatientId = his_patient_id
  3744. s.StartTime = pTime
  3745. s.IsSettle = 2
  3746. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3747. if errcode > 0 {
  3748. c.ServeFailJSONWithSGJErrorCode(errcode)
  3749. return
  3750. }
  3751. s.StartTime = pTime
  3752. var total_count int64 //处方总库存
  3753. //查询改药品信息
  3754. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3755. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3756. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3757. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3758. total_count += prescribingNumberSeven * medical.MinNumber
  3759. }
  3760. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3761. total_count += prescribingNumberSeven
  3762. }
  3763. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3764. total_count += prescribingNumberSeven
  3765. }
  3766. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3767. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3768. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3769. if s.Price != lastWarehouse.RetailPrice {
  3770. s.Price = lastWarehouse.RetailPrice
  3771. }
  3772. if s.Price == 0 {
  3773. s.Price = lastWarehouse.RetailPrice
  3774. }
  3775. }
  3776. service.CreateHisDoctorAdvice(&s)
  3777. //记录日志
  3778. byterequest, _ := json.Marshal(s)
  3779. adviceLog := models.XtDoctorAdviceLog{
  3780. UserOrgId: s.UserOrgId,
  3781. PatientId: s.PatientId,
  3782. AdminUserId: adminInfo.AdminUser.Id,
  3783. Module: 1,
  3784. ErrLog: string(byterequest),
  3785. Status: 1,
  3786. Ctime: time.Now().Unix(),
  3787. Mtime: 0,
  3788. Source: "电脑端新建his医嘱",
  3789. RecordDate: s.AdviceDate,
  3790. }
  3791. service.CreateDoctorAdviceLog(adviceLog)
  3792. //存储切片中
  3793. adviceList = append(adviceList, s)
  3794. redis := service.RedisClient()
  3795. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3796. redis.Set(key, "", time.Second)
  3797. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3798. redis.Set(keyOne, "", time.Second)
  3799. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3800. redis.Set(keySeven, "", time.Second)
  3801. var randNum int
  3802. randNum = rand.Intn(10000) + 1000
  3803. timestamp := time.Now().Unix()
  3804. tempTime := time.Unix(timestamp, 0)
  3805. timeFormat := tempTime.Format("20060102150405")
  3806. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3807. service.CreateHisDoctorAdvice(&s)
  3808. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3809. redis.Set(keySix, "", time.Second)
  3810. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3811. redis.Set(keyFive, "", time.Second)
  3812. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3813. redis.Set(keyEight, "", time.Second)
  3814. defer redis.Close()
  3815. }
  3816. }
  3817. }
  3818. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3819. projects := items["project"].([]interface{})
  3820. if len(projects) > 0 {
  3821. for _, project := range projects {
  3822. var p models.HisPrescriptionProject
  3823. p.PrescriptionId = tempPrescription.ID
  3824. p.Ctime = time.Now().Unix()
  3825. p.Mtime = time.Now().Unix()
  3826. p.PatientId = patient_id
  3827. p.RecordDate = theTime3.Unix()
  3828. p.Doctor = doctor_id
  3829. p.UserOrgId = adminInfo.CurrentOrgId
  3830. p.HisPatientId = his_patient_id
  3831. p.Status = 1
  3832. p.StartTime = pTime
  3833. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3834. if errcode > 0 {
  3835. c.ServeFailJSONWithSGJErrorCode(errcode)
  3836. return
  3837. }
  3838. if p.ID == 0 {
  3839. p.IsOut = 2
  3840. }
  3841. if p.ID > 0 {
  3842. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3843. p.IsOut = projectDetail.IsOut
  3844. }
  3845. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3846. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3847. if p.Type == 3 {
  3848. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3849. if p.Price != lastWarehouse.PackingPrice {
  3850. p.Price = lastWarehouse.PackingPrice
  3851. }
  3852. if p.Unit == "" {
  3853. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3854. p.Unit = goodInfoOne.PackingUnit
  3855. }
  3856. }
  3857. }
  3858. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3859. //
  3860. // if p.Type == 3 {
  3861. // //查询该耗材是否停用
  3862. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3863. // //表示该耗材已经停用,不能保存
  3864. // if goodInfoSeven.ID == 0 {
  3865. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3866. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3867. // return
  3868. // }
  3869. // }
  3870. //
  3871. //}
  3872. service.CreateHisProjectTwo(&p)
  3873. //记录日志
  3874. byterequest, _ := json.Marshal(p)
  3875. adviceLog := models.XtDoctorAdviceLog{
  3876. UserOrgId: p.UserOrgId,
  3877. PatientId: p.PatientId,
  3878. AdminUserId: adminInfo.AdminUser.Id,
  3879. Module: 1,
  3880. ErrLog: string(byterequest),
  3881. Status: 1,
  3882. Ctime: time.Now().Unix(),
  3883. Mtime: 0,
  3884. Source: "电脑端新建his项目",
  3885. RecordDate: p.RecordDate,
  3886. }
  3887. service.CreateDoctorAdviceLog(adviceLog)
  3888. projectList = append(projectList, p)
  3889. var randNum int
  3890. randNum = rand.Intn(10000) + 1000
  3891. timestamp := time.Now().Unix()
  3892. tempTime := time.Unix(timestamp, 0)
  3893. timeFormat := tempTime.Format("20060102150405")
  3894. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3895. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3896. //新增或者编辑项目,修改对应的标签数据
  3897. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3898. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3899. var label models.HisLabelPrintInfo
  3900. project, _ := service.GetProjectDetail(p.ProjectId)
  3901. if project.CostClassify == 3 { //类别为检验检查
  3902. if p.TeamId > 0 { //检验检查组套
  3903. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3904. if tempLabel.ID == 0 {
  3905. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3906. label.Number = tempPrescription.PrescriptionNumber
  3907. label.ProjectId = project.ID
  3908. label.Status = 1
  3909. label.IsPrint = 2
  3910. label.DoctorId = info.DoctorId
  3911. label.UserOrgId = p.UserOrgId
  3912. label.PatientId = patient_id
  3913. label.RecordDate = recordDateTime
  3914. label.Ctime = time.Now().Unix()
  3915. label.Mtime = time.Now().Unix()
  3916. label.ItemId = p.TeamId
  3917. label.FeedetlSn = p.FeedetlSn
  3918. label.PProjectId = p.ID
  3919. label.ProjectName = team.ProjectTeam
  3920. label.PatientName = patient.Name
  3921. service.CreateHisLabelRecord(&label)
  3922. }
  3923. } else { //单条检验检查项目
  3924. label.Number = tempPrescription.PrescriptionNumber
  3925. label.ProjectId = project.ID
  3926. label.Status = 1
  3927. label.DoctorId = info.DoctorId
  3928. label.UserOrgId = p.UserOrgId
  3929. label.PatientId = patient_id
  3930. label.RecordDate = recordDateTime
  3931. label.IsPrint = 2
  3932. label.Ctime = time.Now().Unix()
  3933. label.Mtime = time.Now().Unix()
  3934. label.FeedetlSn = p.FeedetlSn
  3935. label.PProjectId = p.ID
  3936. label.ItemId = p.TeamId
  3937. label.ProjectName = project.ProjectName
  3938. label.PatientName = patient.Name
  3939. service.CreateHisLabelRecord(&label)
  3940. }
  3941. }
  3942. }
  3943. }
  3944. service.SaveHisProjectTwo(&p)
  3945. }
  3946. }
  3947. }
  3948. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3949. // addition := items["addition"].([]interface{})
  3950. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3951. // ctime := time.Now().Unix()
  3952. // mtime := ctime
  3953. // if len(addition) > 0 {
  3954. // for _, item := range addition {
  3955. // var s models.HisAdditionalCharge
  3956. // s.PrescriptionId = tempPrescription.ID
  3957. // s.Status = 1
  3958. // s.UserOrgId = adminInfo.CurrentOrgId
  3959. // s.RecordDate = recordDateTime
  3960. // s.CreatedTime = ctime
  3961. // s.UpdatedTime = mtime
  3962. // s.PatientId = patient_id
  3963. // s.HisPatientId = his_patient_id
  3964. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3965. // if errcode > 0 {
  3966. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3967. // return
  3968. // }
  3969. // service.CreateAdditionalCharge(&s)
  3970. // var randNum int
  3971. // randNum = rand.Intn(10000) + 1000
  3972. // timestamp := time.Now().Unix()
  3973. // tempTime := time.Unix(timestamp, 0)
  3974. // timeFormat := tempTime.Format("20060102150405")
  3975. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3976. // service.CreateAdditionalCharge(&s)
  3977. //
  3978. // }
  3979. // }
  3980. //}
  3981. }
  3982. }
  3983. //查询今日该患者开的药品处方
  3984. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3985. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3986. //药品出库
  3987. if drugOutConfig.IsOpen == 1 {
  3988. for _, item := range hisdoctorlist {
  3989. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3990. // 查询该药品最后一次出库记录
  3991. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3992. if len(druginfo) > 0 {
  3993. //回退库存
  3994. for _, it := range druginfo {
  3995. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3996. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3997. }
  3998. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3999. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4000. }
  4001. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4002. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4003. }
  4004. }
  4005. }
  4006. //删除记录
  4007. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4008. //查询最后一次数据
  4009. if drugOutConfig.IsOpen == 1 {
  4010. //出库
  4011. if drug.IsUse == 2 {
  4012. creater := adminInfo.AdminUser.Id
  4013. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4014. }
  4015. //更新字典里面的库存
  4016. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4017. var sum_count int64
  4018. for _, its := range stockInfo {
  4019. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4020. if its.MaxUnit == baseDrug.MaxUnit {
  4021. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4022. }
  4023. sum_count += its.StockMaxNumber + its.StockMinNumber
  4024. }
  4025. //更新基础库存
  4026. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4027. //剩余库存
  4028. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4029. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4030. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4031. }
  4032. }
  4033. }
  4034. //耗材保存处方出库
  4035. if goodOutConfig.IsOpen == 1 {
  4036. //查询今日耗材出库数量
  4037. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4038. for _, item := range hisgoodlist {
  4039. //查询历史出库数据
  4040. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4041. var out_count_five int64
  4042. for _, item := range flowGood {
  4043. out_count_five += item.Count
  4044. }
  4045. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4046. if out_count_five != parseIntCount {
  4047. //查询耗材最后一次出库记录
  4048. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4049. //查询默认出库仓库库存
  4050. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4051. if len(wareOut) > 0 {
  4052. for _, it := range wareOut {
  4053. //回退库存
  4054. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4055. //删除出库记录
  4056. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4057. }
  4058. }
  4059. timeStr := time.Now().Format("2006-01-02")
  4060. timeArr := strings.Split(timeStr, "-")
  4061. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4062. total = total + 1
  4063. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4064. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4065. number = number + total
  4066. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4067. operation_time := time.Now().Unix()
  4068. creater := c.GetAdminUserInfo().AdminUser.Id
  4069. recordDateStr := time.Now().Format("2006-01-02")
  4070. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4071. nowtime := recordDate.Unix()
  4072. warehouseOut := models.WarehouseOut{
  4073. WarehouseOutOrderNumber: warehousing_out_order,
  4074. OperationTime: operation_time,
  4075. OrgId: adminInfo.CurrentOrgId,
  4076. Creater: creater,
  4077. Ctime: time.Now().Unix(),
  4078. Status: 1,
  4079. WarehouseOutTime: nowtime,
  4080. Type: 1,
  4081. StorehouseId: storeConfig.StorehouseOutInfo,
  4082. IsCheck: 1,
  4083. IsSys: 1,
  4084. }
  4085. //查询是否生成出库单
  4086. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4087. if out.ID == 0 {
  4088. service.AddSigleWarehouseOut(&warehouseOut)
  4089. }
  4090. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4091. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4092. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4093. dialyPrepareOne := models.DialysisBeforePrepare{
  4094. GoodTypeId: goodObj.GoodTypeId,
  4095. GoodId: item.ProjectId,
  4096. PatientId: item.PatientId,
  4097. RecordDate: item.RecordDate,
  4098. UserOrgId: adminInfo.CurrentOrgId,
  4099. Count: parseIntCount,
  4100. Ctime: time.Now().Unix(),
  4101. Creater: creater,
  4102. Status: 1,
  4103. StorehouseId: houseConfig.StorehouseOutInfo,
  4104. ProjectId: item.ID,
  4105. }
  4106. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4107. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4108. //查询历史出库数据
  4109. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4110. var out_count int64
  4111. for _, item := range flowGood {
  4112. out_count += item.Count
  4113. }
  4114. //如果历史数和当前数据不想等才进行退库出库
  4115. if out_count != parseIntCount {
  4116. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4117. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4118. detail := models.AutomaticReduceDetail{
  4119. WarehouseOutId: 0,
  4120. WarehouseOutOrderNumber: "",
  4121. PatientId: item.PatientId,
  4122. Ctime: time.Now().Unix(),
  4123. Mtime: 0,
  4124. Status: 1,
  4125. RecordTime: item.RecordDate,
  4126. OrgId: item.UserOrgId,
  4127. GoodId: item.ProjectId,
  4128. GoodTypeId: 0,
  4129. Count: parseIntCount,
  4130. Type: 0,
  4131. ProjectId: item.ID,
  4132. StorehouseId: 0,
  4133. }
  4134. service.CreateAutoDetail(detail)
  4135. //查询剩余库存
  4136. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4137. var sum_count int64
  4138. for _, item := range goodList {
  4139. sum_count += item.StockCount
  4140. }
  4141. //更新剩余库存
  4142. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4143. //耗材
  4144. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4145. }
  4146. }
  4147. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4148. //查询历史出库数据
  4149. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4150. var out_count int64
  4151. for _, item := range flowGood {
  4152. out_count += item.Count
  4153. }
  4154. //如果历史数和当前数据不想等才进行退库出库
  4155. if out_count != parseIntCount {
  4156. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4157. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4158. detail := models.AutomaticReduceDetail{
  4159. WarehouseOutId: 0,
  4160. WarehouseOutOrderNumber: "",
  4161. PatientId: item.PatientId,
  4162. Ctime: time.Now().Unix(),
  4163. Mtime: 0,
  4164. Status: 1,
  4165. RecordTime: item.RecordDate,
  4166. OrgId: item.UserOrgId,
  4167. GoodId: item.ProjectId,
  4168. GoodTypeId: 0,
  4169. Count: parseIntCount,
  4170. Type: 0,
  4171. ProjectId: item.ID,
  4172. StorehouseId: 0,
  4173. }
  4174. service.CreateAutoDetail(detail)
  4175. //查询剩余库存
  4176. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4177. var sum_count int64
  4178. for _, item := range goodList {
  4179. sum_count += item.StockCount
  4180. }
  4181. //更新剩余库存
  4182. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4183. //耗材
  4184. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4185. }
  4186. }
  4187. }
  4188. }
  4189. }
  4190. }
  4191. tx.Commit()
  4192. if err == nil {
  4193. c.ServeSuccessJSON(map[string]interface{}{
  4194. "msg": "保存成功",
  4195. })
  4196. return
  4197. } else {
  4198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4199. return
  4200. }
  4201. }
  4202. }
  4203. //func (c *HisApiController) EditHisPrescription() {
  4204. // record_date := c.GetString("record_date")
  4205. // patient_id, _ := c.GetInt64("patient_id")
  4206. // reg_type, _ := c.GetInt64("reg_type")
  4207. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4208. // diagnose := c.GetString("diagnose")
  4209. // sick_type, _ := c.GetInt64("sick_type")
  4210. // sick_history := c.GetString("sick_history")
  4211. // doctor_id, _ := c.GetInt64("doctor", 0)
  4212. // department, _ := c.GetInt64("department", 0)
  4213. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4214. // p_type, _ := c.GetInt64("p_type")
  4215. //
  4216. // dataBody := make(map[string]interface{}, 0)
  4217. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4218. // if err != nil {
  4219. // utils.ErrorLog(err.Error())
  4220. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4221. // return
  4222. // }
  4223. //
  4224. // timeLayout := "2006-01-02"
  4225. // loc, _ := time.LoadLocation("Local")
  4226. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4227. // if err != nil {
  4228. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4229. // return
  4230. // }
  4231. // adminInfo := c.GetAdminUserInfo()
  4232. // recordDateTime := theTime.Unix()
  4233. //
  4234. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4235. //
  4236. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4237. // var hpInfo models.HisPrescriptionInfo
  4238. // if info.ID == 0 {
  4239. // var randNum int
  4240. // randNum = rand.Intn(10000) + 1000
  4241. // timestamp := time.Now().Unix()
  4242. // tempTime := time.Unix(timestamp, 0)
  4243. // timeFormat := tempTime.Format("20060102150405")
  4244. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4245. //
  4246. // hpInfo = models.HisPrescriptionInfo{
  4247. // UserOrgId: adminInfo.CurrentOrgId,
  4248. // RecordDate: theTime.Unix(),
  4249. // PatientId: patient_id,
  4250. // Status: 1,
  4251. // Ctime: time.Now().Unix(),
  4252. // Mtime: time.Now().Unix(),
  4253. // Creator: adminInfo.AdminUser.Id,
  4254. // Modifier: adminInfo.AdminUser.Id,
  4255. // Diagnosis: diagnose,
  4256. // SickHistory: sick_history,
  4257. // Departments: department,
  4258. // RegisterType: reg_type,
  4259. // PrescriptionNumber: p_number,
  4260. // PrescriptionStatus: 1,
  4261. // Doctor: role.UserName,
  4262. // DoctorId: doctor_id,
  4263. // SickType: sick_type,
  4264. // PType: p_type,
  4265. // }
  4266. // service.SavePatientPrescriptionInfo(hpInfo)
  4267. //
  4268. // } else {
  4269. // hpInfo = models.HisPrescriptionInfo{
  4270. // ID: info.ID,
  4271. // UserOrgId: adminInfo.CurrentOrgId,
  4272. // RecordDate: info.RecordDate,
  4273. // PatientId: info.PatientId,
  4274. // Status: 1,
  4275. // Ctime: info.Ctime,
  4276. // Mtime: time.Now().Unix(),
  4277. // Creator: info.Creator,
  4278. // Modifier: adminInfo.AdminUser.Id,
  4279. // Diagnosis: diagnose,
  4280. // SickHistory: sick_history,
  4281. // Departments: department,
  4282. // RegisterType: reg_type,
  4283. // PrescriptionNumber: info.PrescriptionNumber,
  4284. // Doctor: role.UserName,
  4285. // PrescriptionStatus: info.PrescriptionStatus,
  4286. // DoctorId: doctor_id,
  4287. // SickType: sick_type,
  4288. // PType: info.PType,
  4289. // }
  4290. // service.SavePatientPrescriptionInfo(hpInfo)
  4291. // }
  4292. //
  4293. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4294. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4295. //
  4296. // if len(prescriptions) > 0 {
  4297. // for _, item := range prescriptions {
  4298. // items := item.(map[string]interface{})
  4299. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4300. // utils.ErrorLog("id")
  4301. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4302. // return
  4303. // }
  4304. // id := int64(items["id"].(float64))
  4305. //
  4306. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4307. // utils.ErrorLog("type")
  4308. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4309. // return
  4310. // }
  4311. // types := int64(items["type"].(float64))
  4312. //
  4313. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4314. // utils.ErrorLog("med_type")
  4315. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4316. // return
  4317. // }
  4318. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4319. //
  4320. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4321. //
  4322. // ctime := time.Now().Unix()
  4323. //
  4324. // prescription := &models.HisPrescription{
  4325. // ID: id,
  4326. // PatientId: patient_id,
  4327. // UserOrgId: adminInfo.CurrentOrgId,
  4328. // RecordDate: recordDateTime,
  4329. // Ctime: ctime,
  4330. // Mtime: ctime,
  4331. // Type: types,
  4332. // Modifier: adminInfo.AdminUser.Id,
  4333. // Creator: adminInfo.AdminUser.Id,
  4334. // Status: 1,
  4335. // Doctor: role.UserName,
  4336. // HisPatientId: his_patient_id,
  4337. // OrderStatus: 1,
  4338. // BatchNumber: "",
  4339. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4340. // PType: hpInfo.PType,
  4341. // MedType: med_type,
  4342. // }
  4343. //
  4344. // if historyPrescription.ID > 0 {
  4345. // prescription.PreTime = historyPrescription.PreTime
  4346. //
  4347. // }
  4348. //
  4349. // service.SaveHisPrescription(prescription)
  4350. //
  4351. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4352. // advices := items["advices"].([]interface{})
  4353. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4354. // groupNo := int64(0)
  4355. // ctime := time.Now().Unix()
  4356. // mtime := ctime
  4357. // if len(advices) > 0 {
  4358. // for _, advice := range advices {
  4359. // var s models.HisDoctorAdviceInfo
  4360. // s.PrescriptionId = prescription.ID
  4361. // s.AdviceType = 2
  4362. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4363. // s.StopState = 2
  4364. // s.ExecutionState = 2
  4365. // s.AdviceDate = recordDateTime
  4366. // s.Status = 1
  4367. // s.UserOrgId = adminInfo.CurrentOrgId
  4368. // s.RecordDate = recordDateTime
  4369. // s.StartTime = prescription.PreTime
  4370. // s.Groupno = groupNo
  4371. // s.CreatedTime = ctime
  4372. // s.UpdatedTime = mtime
  4373. // s.PatientId = patient_id
  4374. // s.HisPatientId = his_patient_id
  4375. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4376. // if errcode > 0 {
  4377. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4378. // return
  4379. // }
  4380. //
  4381. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4382. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4383. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4384. // if s.Price == 0 {
  4385. // s.Price = lastWarehouse.RetailPrice
  4386. // }
  4387. // }
  4388. //
  4389. // service.CreateHisDoctorAdvice(&s)
  4390. // //记录日志
  4391. // byterequest, _ := json.Marshal(s)
  4392. // adviceLog := models.XtDoctorAdviceLog{
  4393. // UserOrgId: s.UserOrgId,
  4394. // PatientId: s.PatientId,
  4395. // AdminUserId: adminInfo.AdminUser.Id,
  4396. // Module: 1,
  4397. // ErrLog: string(byterequest),
  4398. // Status: 1,
  4399. // Ctime: time.Now().Unix(),
  4400. // Mtime: 0,
  4401. // Source: "电脑端his医嘱修改",
  4402. // RecordDate: s.AdviceDate,
  4403. // }
  4404. // service.CreateDoctorAdviceLog(adviceLog)
  4405. // redis := service.RedisClient()
  4406. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4407. // redis.Set(key, "", time.Second)
  4408. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4409. // fmt.Println("keyOne", keyOne)
  4410. // redis.Set(keyOne, "", time.Second)
  4411. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4412. // redis.Set(keySeven, "", time.Second)
  4413. // redis.Close()
  4414. //
  4415. // }
  4416. // }
  4417. // }
  4418. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4419. // projects := items["project"].([]interface{})
  4420. // if len(projects) > 0 {
  4421. // for _, project := range projects {
  4422. // var p models.HisPrescriptionProject
  4423. // p.PrescriptionId = prescription.ID
  4424. // p.Ctime = time.Now().Unix()
  4425. // p.Mtime = time.Now().Unix()
  4426. // p.PatientId = patient_id
  4427. // p.RecordDate = recordDateTime
  4428. // p.UserOrgId = adminInfo.CurrentOrgId
  4429. // p.HisPatientId = his_patient_id
  4430. // p.Status = 1
  4431. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4432. // if errcode > 0 {
  4433. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4434. // return
  4435. // }
  4436. // service.CreateHisProjectTwo(&p)
  4437. //
  4438. // //记录日志
  4439. // byterequest, _ := json.Marshal(p)
  4440. // adviceLog := models.XtDoctorAdviceLog{
  4441. // UserOrgId: p.UserOrgId,
  4442. // PatientId: p.PatientId,
  4443. // AdminUserId: adminInfo.AdminUser.Id,
  4444. // Module: 1,
  4445. // ErrLog: string(byterequest),
  4446. // Status: 1,
  4447. // Ctime: time.Now().Unix(),
  4448. // Mtime: 0,
  4449. // Source: "电脑端his项目修改",
  4450. // RecordDate: p.RecordDate,
  4451. // }
  4452. // service.CreateDoctorAdviceLog(adviceLog)
  4453. // }
  4454. // }
  4455. // }
  4456. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4457. // addition := items["addition"].([]interface{})
  4458. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4459. // ctime := time.Now().Unix()
  4460. // mtime := ctime
  4461. // if len(addition) > 0 {
  4462. // for _, item := range addition {
  4463. // var s models.HisAdditionalCharge
  4464. // s.PrescriptionId = prescription.ID
  4465. // s.Status = 1
  4466. // s.UserOrgId = adminInfo.CurrentOrgId
  4467. // s.RecordDate = recordDateTime
  4468. // s.CreatedTime = ctime
  4469. // s.UpdatedTime = mtime
  4470. // s.PatientId = patient_id
  4471. // s.HisPatientId = his_patient_id
  4472. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4473. // if errcode > 0 {
  4474. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4475. // return
  4476. // }
  4477. // service.CreateAdditionalCharge(&s)
  4478. // }
  4479. // }
  4480. // }
  4481. //
  4482. // }
  4483. // }
  4484. // }
  4485. // if err == nil {
  4486. // c.ServeSuccessJSON(map[string]interface{}{
  4487. // "msg": "保存成功",
  4488. // })
  4489. // return
  4490. //
  4491. // } else {
  4492. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4493. // return
  4494. // }
  4495. //}
  4496. func (c *HisApiController) DeletePrescription() {
  4497. prescription_id, _ := c.GetInt64("id")
  4498. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4499. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4500. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4501. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4502. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4503. //耗材保存处方出库
  4504. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4505. //已收费和已发药限制逻辑
  4506. isCharge := false
  4507. isMedicine := false
  4508. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4509. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4510. for _, item := range new_prescriptions {
  4511. if item.IsMedicine == 1 {
  4512. isMedicine = true
  4513. }
  4514. }
  4515. for _, item := range new_prescriptions {
  4516. if item.OrderStatus == 4 {
  4517. isCharge = true
  4518. }
  4519. }
  4520. if p_err != nil {
  4521. if new_prescription.ID > 0 {
  4522. if new_prescription.OrderStatus == 2 {
  4523. isCharge = true
  4524. }
  4525. }
  4526. }
  4527. for _, item := range advices {
  4528. if item.IsMedicine == 1 {
  4529. isMedicine = true
  4530. }
  4531. }
  4532. if isCharge {
  4533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4534. return
  4535. }
  4536. if isMedicine {
  4537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4538. return
  4539. }
  4540. //已收费和已发药限制逻辑
  4541. if len(projects) > 0 {
  4542. for _, item := range projects {
  4543. service.DeletePrintInfo(item.ID) //删除打印信息
  4544. if goodOutConfig.IsOpen != 1 {
  4545. if stockConfig.IsOpen == 1 {
  4546. if item.Type == 3 && item.IsOut == 1 {
  4547. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4548. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4549. good.Total = good.Total + f_count
  4550. service.UpdateGoodInfo(&good)
  4551. operation_time := time.Now().Unix()
  4552. creater := c.GetAdminUserInfo().AdminUser.Id
  4553. //创建退库单
  4554. timeStr := time.Now().Format("2006-01-02")
  4555. timeArr := strings.Split(timeStr, "-")
  4556. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4557. total = total + 1
  4558. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4559. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4560. cancelStock := models.CancelStock{
  4561. OrderNumber: orderNumber,
  4562. OperaTime: operation_time,
  4563. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4564. Creater: creater,
  4565. Ctime: time.Now().Unix(),
  4566. Status: 1,
  4567. ReturnTime: item.RecordDate,
  4568. Type: 1,
  4569. StorehouseId: houseConfig.StorehouseOutInfo,
  4570. IsCheck: 1,
  4571. }
  4572. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4573. if msgerrkonde == gorm.ErrRecordNotFound {
  4574. service.AddSigleCancelStock(&cancelStock)
  4575. }
  4576. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4577. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4578. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4579. //查询该耗材是否出库
  4580. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4581. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4582. deaerler, _ := service.GetDealerById(info.Dealer)
  4583. var total_count int64
  4584. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4585. total_count += count
  4586. if info.ID > 0 {
  4587. if info.Count >= total_count {
  4588. //回退库存
  4589. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4590. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4591. var flush_count int64
  4592. for _, it := range goodList {
  4593. flush_count += it.StockCount
  4594. }
  4595. cancelStockInfo := models.CancelStockInfo{
  4596. GoodId: item.ProjectId,
  4597. CancelStockId: cancel.ID,
  4598. GoodTypeId: good.GoodTypeId,
  4599. Count: prescribingNumber,
  4600. Price: info.Price,
  4601. Total: 0,
  4602. ProductDate: info.ProductDate,
  4603. ExpiryDate: info.ExpiryDate,
  4604. Ctime: time.Now().Unix(),
  4605. Status: 1,
  4606. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4607. OrderNumber: cancel.OrderNumber,
  4608. Type: 0,
  4609. Dealer: deaerler.DealerName,
  4610. Manufacturer: manufacturer.ManufacturerName,
  4611. Number: info.Number,
  4612. RegisterAccount: "",
  4613. Remark: "",
  4614. WarehouseInfoId: info.WarehouseInfotId,
  4615. PatientId: info.PatientId,
  4616. RecordDate: info.SysRecordTime,
  4617. StorehouseId: houseConfig.StorehouseOutInfo,
  4618. IsCheck: 1,
  4619. }
  4620. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4621. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4622. flow := models.VmStockFlow{
  4623. WarehousingId: info.WarehouseInfotId,
  4624. GoodId: item.ProjectId,
  4625. Number: info.Number,
  4626. LicenseNumber: info.LicenseNumber,
  4627. Count: prescribingNumber,
  4628. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4629. PatientId: item.PatientId,
  4630. SystemTime: info.SysRecordTime,
  4631. ConsumableType: 7,
  4632. IsSys: 0,
  4633. WarehousingOrder: "",
  4634. WarehouseOutId: info.WarehouseOutId,
  4635. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4636. IsEdit: 0,
  4637. CancelStockId: cancel.ID,
  4638. CancelOrderNumber: cancel.OrderNumber,
  4639. Manufacturer: manufacturer.ID,
  4640. Dealer: 0,
  4641. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4642. UpdateCreator: 0,
  4643. Status: 1,
  4644. Ctime: time.Now().Unix(),
  4645. Mtime: 0,
  4646. Price: info.Price,
  4647. WarehousingDetailId: info.WarehouseInfotId,
  4648. WarehouseOutDetailId: info.ID,
  4649. CancelOutDetailId: cancelInfo.ID,
  4650. ProductDate: info.ProductDate,
  4651. ExpireDate: info.ExpiryDate,
  4652. StorehouseId: houseConfig.StorehouseOutInfo,
  4653. OverCount: flush_count,
  4654. }
  4655. service.CreateStockFlowOne(flow)
  4656. //退库数量增加
  4657. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4658. //出库数量减少
  4659. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4660. }
  4661. if info.Count < total_count {
  4662. //回退库存
  4663. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4664. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4665. var flush_count int64
  4666. for _, it := range goodList {
  4667. flush_count += it.StockCount
  4668. }
  4669. cancelStockInfo := models.CancelStockInfo{
  4670. GoodId: item.ProjectId,
  4671. CancelStockId: cancel.ID,
  4672. GoodTypeId: good.GoodTypeId,
  4673. Count: info.Count,
  4674. Price: info.Price,
  4675. Total: 0,
  4676. ProductDate: info.ProductDate,
  4677. ExpiryDate: info.ExpiryDate,
  4678. Ctime: time.Now().Unix(),
  4679. Status: 1,
  4680. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4681. OrderNumber: cancel.OrderNumber,
  4682. Type: 0,
  4683. Dealer: deaerler.DealerName,
  4684. Manufacturer: manufacturer.ManufacturerName,
  4685. Number: info.Number,
  4686. RegisterAccount: "",
  4687. Remark: "",
  4688. WarehouseInfoId: info.WarehouseInfotId,
  4689. PatientId: info.PatientId,
  4690. RecordDate: info.SysRecordTime,
  4691. StorehouseId: houseConfig.StorehouseOutInfo,
  4692. IsCheck: 1,
  4693. }
  4694. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4695. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4696. flow := models.VmStockFlow{
  4697. WarehousingId: info.WarehouseInfotId,
  4698. GoodId: item.ProjectId,
  4699. Number: info.Number,
  4700. LicenseNumber: info.LicenseNumber,
  4701. Count: info.Count,
  4702. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4703. PatientId: item.PatientId,
  4704. SystemTime: info.SysRecordTime,
  4705. ConsumableType: 7,
  4706. IsSys: 0,
  4707. WarehousingOrder: "",
  4708. WarehouseOutId: info.WarehouseOutId,
  4709. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4710. IsEdit: 0,
  4711. CancelStockId: cancel.ID,
  4712. CancelOrderNumber: cancel.OrderNumber,
  4713. Manufacturer: manufacturer.ID,
  4714. Dealer: 0,
  4715. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4716. UpdateCreator: 0,
  4717. Status: 1,
  4718. Ctime: time.Now().Unix(),
  4719. Mtime: 0,
  4720. Price: info.Price,
  4721. WarehousingDetailId: info.WarehouseInfotId,
  4722. WarehouseOutDetailId: info.ID,
  4723. CancelOutDetailId: cancelInfo.ID,
  4724. ProductDate: info.ProductDate,
  4725. ExpireDate: info.ExpiryDate,
  4726. StorehouseId: houseConfig.StorehouseOutInfo,
  4727. OverCount: flush_count,
  4728. }
  4729. service.CreateStockFlowOne(flow)
  4730. //退库数量增加
  4731. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4732. //出库数量减少
  4733. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4734. }
  4735. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4736. var flush_count int64
  4737. for _, it := range goodList {
  4738. flush_count += it.StockCount
  4739. }
  4740. //查询已出库数量
  4741. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4742. if prescribingNumber < dialysisInfo.Count {
  4743. //改变数量
  4744. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4745. }
  4746. if prescribingNumber >= dialysisInfo.Count {
  4747. //删除出库表
  4748. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4749. }
  4750. //更新库存
  4751. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4752. //更新基础库库存
  4753. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4754. }
  4755. }
  4756. }
  4757. }
  4758. //保存耗材出库
  4759. if goodOutConfig.IsOpen == 1 {
  4760. if item.Type == 3 {
  4761. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4762. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4763. good.Total = good.Total + f_count
  4764. service.UpdateGoodInfo(&good)
  4765. operation_time := time.Now().Unix()
  4766. creater := c.GetAdminUserInfo().AdminUser.Id
  4767. //创建退库单
  4768. timeStr := time.Now().Format("2006-01-02")
  4769. timeArr := strings.Split(timeStr, "-")
  4770. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4771. total = total + 1
  4772. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4773. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4774. cancelStock := models.CancelStock{
  4775. OrderNumber: orderNumber,
  4776. OperaTime: operation_time,
  4777. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4778. Creater: creater,
  4779. Ctime: time.Now().Unix(),
  4780. Status: 1,
  4781. ReturnTime: item.RecordDate,
  4782. Type: 1,
  4783. StorehouseId: houseConfig.StorehouseOutInfo,
  4784. IsCheck: 1,
  4785. }
  4786. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4787. if msgerrkonde == gorm.ErrRecordNotFound {
  4788. service.AddSigleCancelStock(&cancelStock)
  4789. }
  4790. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4791. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4792. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4793. //查询该耗材是否出库
  4794. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4795. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4796. deaerler, _ := service.GetDealerById(info.Dealer)
  4797. var total_count int64
  4798. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4799. total_count += count
  4800. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4801. var flush_count int64
  4802. for _, it := range goodList {
  4803. flush_count += it.StockCount
  4804. }
  4805. fmt.Println("历史出库数据", info.Count)
  4806. fmt.Println("出库数量", total_count)
  4807. if info.ID > 0 {
  4808. cancelStockInfo := models.CancelStockInfo{
  4809. GoodId: item.ProjectId,
  4810. CancelStockId: cancel.ID,
  4811. GoodTypeId: good.GoodTypeId,
  4812. Count: prescribingNumber,
  4813. Price: info.Price,
  4814. Total: 0,
  4815. ProductDate: info.ProductDate,
  4816. ExpiryDate: info.ExpiryDate,
  4817. Ctime: time.Now().Unix(),
  4818. Status: 1,
  4819. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4820. OrderNumber: cancel.OrderNumber,
  4821. Type: 0,
  4822. Dealer: deaerler.DealerName,
  4823. Manufacturer: manufacturer.ManufacturerName,
  4824. Number: info.Number,
  4825. RegisterAccount: "",
  4826. Remark: "",
  4827. WarehouseInfoId: info.WarehouseInfotId,
  4828. PatientId: info.PatientId,
  4829. RecordDate: info.SysRecordTime,
  4830. StorehouseId: houseConfig.StorehouseOutInfo,
  4831. IsCheck: 1,
  4832. }
  4833. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4834. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4835. //查询出库数量
  4836. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4837. //出库数据 大于 退库数量
  4838. if len(list) > 0 {
  4839. for _, it := range list {
  4840. //回退库存
  4841. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4842. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4843. var flush_count_one int64
  4844. for _, it := range goodList {
  4845. flush_count_one += it.StockCount
  4846. }
  4847. //查询该批次是否有退库数据
  4848. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4849. creater := c.GetAdminUserInfo().AdminUser.Id
  4850. flow := models.VmStockFlow{
  4851. WarehousingId: it.WarehouseInfotId,
  4852. GoodId: it.GoodId,
  4853. Number: it.Number,
  4854. LicenseNumber: it.LicenseNumber,
  4855. Count: it.Count,
  4856. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4857. PatientId: it.PatientId,
  4858. SystemTime: it.SysRecordTime,
  4859. ConsumableType: 7,
  4860. IsSys: 0,
  4861. WarehousingOrder: "",
  4862. WarehouseOutId: it.WarehouseOutId,
  4863. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4864. IsEdit: 0,
  4865. CancelStockId: cancel.ID,
  4866. CancelOrderNumber: cancel.OrderNumber,
  4867. Manufacturer: manufacturer.ID,
  4868. Dealer: 0,
  4869. Creator: creater,
  4870. UpdateCreator: 0,
  4871. Status: 1,
  4872. Ctime: time.Now().Unix(),
  4873. Mtime: 0,
  4874. Price: it.Price,
  4875. WarehousingDetailId: it.WarehouseInfotId,
  4876. WarehouseOutDetailId: it.ID,
  4877. CancelOutDetailId: cancelInfo.ID,
  4878. ProductDate: it.ProductDate,
  4879. ExpireDate: it.ExpiryDate,
  4880. StorehouseId: houseConfig.StorehouseOutInfo,
  4881. OverCount: flush_count_one,
  4882. }
  4883. service.CreateStockFlowOne(flow)
  4884. //if flow.ID > 0 {
  4885. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4886. //}
  4887. }
  4888. }
  4889. //flow := models.VmStockFlow{
  4890. // WarehousingId: info.WarehouseInfotId,
  4891. // GoodId: item.ProjectId,
  4892. // Number: info.Number,
  4893. // LicenseNumber: info.LicenseNumber,
  4894. // Count: prescribingNumber,
  4895. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4896. // PatientId: item.PatientId,
  4897. // SystemTime: info.SysRecordTime,
  4898. // ConsumableType: 7,
  4899. // IsSys: 0,
  4900. // WarehousingOrder: "",
  4901. // WarehouseOutId: info.WarehouseOutId,
  4902. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4903. // IsEdit: 0,
  4904. // CancelStockId: cancel.ID,
  4905. // CancelOrderNumber: cancel.OrderNumber,
  4906. // Manufacturer: manufacturer.ID,
  4907. // Dealer: 0,
  4908. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4909. // UpdateCreator: 0,
  4910. // Status: 1,
  4911. // Ctime: time.Now().Unix(),
  4912. // Mtime: 0,
  4913. // Price: info.Price,
  4914. // WarehousingDetailId: info.WarehouseInfotId,
  4915. // WarehouseOutDetailId: info.ID,
  4916. // CancelOutDetailId: cancelInfo.ID,
  4917. // ProductDate: info.ProductDate,
  4918. // ExpireDate: info.ExpiryDate,
  4919. // StorehouseId: houseConfig.StorehouseOutInfo,
  4920. // OverCount: flush_count,
  4921. //}
  4922. //service.CreateStockFlowOne(flow)
  4923. //退库数量增加
  4924. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4925. //出库数量减少
  4926. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4927. //查询已出库数量
  4928. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4929. if prescribingNumber < dialysisInfo.Count {
  4930. //改变数量
  4931. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4932. }
  4933. if prescribingNumber >= dialysisInfo.Count {
  4934. //删除出库表
  4935. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4936. }
  4937. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4938. var flush_count_one int64
  4939. for _, it := range goodList {
  4940. flush_count_one += it.StockCount
  4941. }
  4942. //更新库存
  4943. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4944. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4945. //更新基础库库存
  4946. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4947. }
  4948. }
  4949. }
  4950. }
  4951. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4952. fmt.Println(err)
  4953. }
  4954. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4955. fmt.Println(err)
  4956. if len(advices) > 0 {
  4957. for _, item := range advices {
  4958. redis := service.RedisClient()
  4959. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4960. redis.Set(keyFive, "", time.Second)
  4961. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4962. redis.Set(keyOne, "", time.Second)
  4963. redis.Close()
  4964. }
  4965. }
  4966. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4967. if len(advices) > 0 {
  4968. for _, item := range advices {
  4969. creater := c.GetAdminUserInfo().AdminUser.Id
  4970. service.DrugAutoAddCancelInfo(item, creater)
  4971. }
  4972. }
  4973. } else {
  4974. if drugOutConfig.IsOpen == 1 {
  4975. if len(advices) > 0 {
  4976. for _, item := range advices {
  4977. creater := c.GetAdminUserInfo().AdminUser.Id
  4978. service.DrugAutoAddCancelInfo(item, creater)
  4979. }
  4980. }
  4981. } else {
  4982. if len(advices) > 0 {
  4983. for _, item := range advices {
  4984. creater := c.GetAdminUserInfo().AdminUser.Id
  4985. service.DrugAutoAddCancelInfo(item, creater)
  4986. }
  4987. }
  4988. }
  4989. }
  4990. c.ServeSuccessJSON(map[string]interface{}{
  4991. "msg": "删除成功",
  4992. })
  4993. return
  4994. }
  4995. func (c *HisApiController) DeleteDoctorAdvice() {
  4996. id, _ := c.GetInt64("id")
  4997. advice, _ := service.GetHisDoctorAdvicesById(id)
  4998. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4999. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5000. //已收费和已发药的限制逻辑
  5001. isCharge := false
  5002. isMedicine := false
  5003. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5004. //获取今天该患者所有处方,判断是否发药或者收费
  5005. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5006. for _, item := range new_prescriptions {
  5007. if item.IsMedicine == 1 {
  5008. isMedicine = true
  5009. }
  5010. }
  5011. for _, item := range new_prescriptions {
  5012. if item.OrderStatus == 4 {
  5013. isCharge = true
  5014. }
  5015. }
  5016. if isMedicine {
  5017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5018. return
  5019. }
  5020. if isCharge {
  5021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5022. return
  5023. }
  5024. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5025. for _, item := range advices {
  5026. if item.IsMedicine == 1 {
  5027. isMedicine = true
  5028. }
  5029. }
  5030. if isMedicine {
  5031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5032. return
  5033. }
  5034. if new_prescription.ID > 0 {
  5035. if new_prescription.OrderStatus == 2 {
  5036. isCharge = true
  5037. }
  5038. }
  5039. if isCharge {
  5040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5041. return
  5042. }
  5043. //已收费和已发药的限制逻辑
  5044. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5045. redis := service.RedisClient()
  5046. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5047. redis.Set(keyFive, "", time.Second)
  5048. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5049. redis.Set(keyOne, "", time.Second)
  5050. defer redis.Close()
  5051. if err == nil {
  5052. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5053. //查询是否在处方中出库
  5054. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5055. if openConfig.IsOpen != 1 {
  5056. //判断该医嘱是否执行了
  5057. if advice.ExecutionState == 1 {
  5058. creater := c.GetAdminUserInfo().AdminUser.Id
  5059. service.DrugAutoAddCancelInfo(&advice, creater)
  5060. }
  5061. }
  5062. //开启保存处方扣减功能
  5063. if openConfig.IsOpen == 1 {
  5064. creater := c.GetAdminUserInfo().AdminUser.Id
  5065. service.DrugAutoAddCancelInfo(&advice, creater)
  5066. }
  5067. } else {
  5068. if drugOutConfig.IsOpen == 1 {
  5069. //查询是否在处方中出库
  5070. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5071. if openConfig.IsOpen != 1 {
  5072. //判断该医嘱是否执行了
  5073. if advice.ExecutionState == 1 {
  5074. creater := c.GetAdminUserInfo().AdminUser.Id
  5075. service.DrugAutoAddCancelInfo(&advice, creater)
  5076. }
  5077. }
  5078. //开启保存处方扣减功能
  5079. if openConfig.IsOpen == 1 {
  5080. creater := c.GetAdminUserInfo().AdminUser.Id
  5081. service.DrugAutoAddCancelInfo(&advice, creater)
  5082. }
  5083. } else {
  5084. //判断该医嘱是否执行了
  5085. if advice.ExecutionState == 1 {
  5086. creater := c.GetAdminUserInfo().AdminUser.Id
  5087. service.DrugAutoAddCancelInfo(&advice, creater)
  5088. }
  5089. }
  5090. }
  5091. c.ServeSuccessJSON(map[string]interface{}{
  5092. "msg": "删除成功",
  5093. })
  5094. return
  5095. } else {
  5096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5097. return
  5098. }
  5099. }
  5100. func (c *HisApiController) DeleteProject() {
  5101. id, _ := c.GetInt64("id")
  5102. adminInfo := c.GetAdminUserInfo()
  5103. project, _ := service.GetHisProjectByID(id)
  5104. // var consumable models.DialysisBeforePrepare
  5105. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5106. //耗材保存处方出库
  5107. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5108. isCharge := false
  5109. isMedicine := false
  5110. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5111. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5112. for _, item := range new_prescriptions {
  5113. if item.IsMedicine == 1 {
  5114. isMedicine = true
  5115. }
  5116. }
  5117. for _, item := range new_prescriptions {
  5118. if item.OrderStatus == 4 {
  5119. isCharge = true
  5120. }
  5121. }
  5122. if isMedicine {
  5123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5124. return
  5125. }
  5126. if isCharge {
  5127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5128. return
  5129. }
  5130. if new_prescription.ID > 0 {
  5131. if new_prescription.OrderStatus == 2 {
  5132. isCharge = true
  5133. }
  5134. }
  5135. if isCharge {
  5136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5137. return
  5138. }
  5139. service.DeletePrintInfo(id)
  5140. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5141. label.Status = 0
  5142. service.CreateHisLabelRecordTwo(&label)
  5143. fmt.Println(goodOutConfig.IsOpen)
  5144. if goodOutConfig.IsOpen != 1 {
  5145. if stockConfig.IsOpen == 1 {
  5146. if project.Type == 2 {
  5147. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5148. fmt.Println(err)
  5149. }
  5150. if project.Type == 3 && project.IsOut == 1 {
  5151. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5152. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5153. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5154. operation_time := time.Now().Unix()
  5155. creater := adminInfo.AdminUser.Id
  5156. //创建退库单
  5157. timeStr := time.Now().Format("2006-01-02")
  5158. timeArr := strings.Split(timeStr, "-")
  5159. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5160. total = total + 1
  5161. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5162. cancelStock := models.CancelStock{
  5163. OrderNumber: orderNumber,
  5164. OperaTime: operation_time,
  5165. OrgId: adminInfo.CurrentOrgId,
  5166. Creater: creater,
  5167. Ctime: time.Now().Unix(),
  5168. Status: 1,
  5169. ReturnTime: project.RecordDate,
  5170. Type: 1,
  5171. StorehouseId: houseConfig.StorehouseOutInfo,
  5172. IsCheck: 1,
  5173. }
  5174. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5175. if msgerrkonde == gorm.ErrRecordNotFound {
  5176. service.AddSigleCancelStock(&cancelStock)
  5177. }
  5178. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5179. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5180. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5181. //查询是否有出库
  5182. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5183. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5184. deaerler, _ := service.GetDealerById(info.Dealer)
  5185. if info.ID > 0 {
  5186. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5187. if info.Count >= prescribingNumber {
  5188. cancelStockInfo := models.CancelStockInfo{
  5189. GoodId: project.ProjectId,
  5190. CancelStockId: cancel.ID,
  5191. GoodTypeId: good.GoodTypeId,
  5192. Count: prescribingNumber,
  5193. Price: info.Price,
  5194. Total: 0,
  5195. ProductDate: info.ProductDate,
  5196. ExpiryDate: info.ExpiryDate,
  5197. Ctime: time.Now().Unix(),
  5198. Status: 1,
  5199. OrgId: adminInfo.CurrentOrgId,
  5200. OrderNumber: cancel.OrderNumber,
  5201. Type: 0,
  5202. Dealer: deaerler.DealerName,
  5203. Manufacturer: manufacturer.ManufacturerName,
  5204. Number: info.Number,
  5205. RegisterAccount: "",
  5206. Remark: "",
  5207. WarehouseInfoId: info.WarehouseInfotId,
  5208. PatientId: info.PatientId,
  5209. RecordDate: info.SysRecordTime,
  5210. StorehouseId: houseConfig.StorehouseOutInfo,
  5211. IsCheck: 1,
  5212. }
  5213. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5214. //回退库存
  5215. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5216. //退库数量增加
  5217. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5218. //出库数量减少
  5219. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5220. }
  5221. if info.Count < prescribingNumber {
  5222. cancelStockInfo := models.CancelStockInfo{
  5223. GoodId: project.ProjectId,
  5224. CancelStockId: cancel.ID,
  5225. GoodTypeId: good.GoodTypeId,
  5226. Count: info.Count,
  5227. Price: info.Price,
  5228. Total: 0,
  5229. ProductDate: info.ProductDate,
  5230. ExpiryDate: info.ExpiryDate,
  5231. Ctime: time.Now().Unix(),
  5232. Status: 1,
  5233. OrgId: adminInfo.CurrentOrgId,
  5234. OrderNumber: cancel.OrderNumber,
  5235. Type: 0,
  5236. Dealer: deaerler.DealerName,
  5237. Manufacturer: manufacturer.ManufacturerName,
  5238. Number: info.Number,
  5239. RegisterAccount: "",
  5240. Remark: "",
  5241. WarehouseInfoId: info.WarehouseInfotId,
  5242. PatientId: info.PatientId,
  5243. RecordDate: info.SysRecordTime,
  5244. StorehouseId: houseConfig.StorehouseOutInfo,
  5245. IsCheck: 1,
  5246. }
  5247. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5248. //回退库存
  5249. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5250. //退库数量增加
  5251. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5252. //出库数量减少
  5253. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5254. }
  5255. //查询剩余库存
  5256. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5257. var over_count int64
  5258. for _, it := range goodList {
  5259. over_count += it.StockCount
  5260. }
  5261. //出库数据 大于 退库数量
  5262. if info.Count >= prescribingNumber {
  5263. flow := models.VmStockFlow{
  5264. WarehousingId: info.WarehouseInfotId,
  5265. GoodId: project.ProjectId,
  5266. Number: info.Number,
  5267. LicenseNumber: info.LicenseNumber,
  5268. Count: prescribingNumber,
  5269. UserOrgId: adminInfo.CurrentOrgId,
  5270. PatientId: project.PatientId,
  5271. SystemTime: info.SysRecordTime,
  5272. ConsumableType: 7,
  5273. IsSys: 0,
  5274. WarehousingOrder: "",
  5275. WarehouseOutId: info.WarehouseOutId,
  5276. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5277. IsEdit: 0,
  5278. CancelStockId: cancel.ID,
  5279. CancelOrderNumber: cancel.OrderNumber,
  5280. Manufacturer: manufacturer.ID,
  5281. Dealer: 0,
  5282. Creator: adminInfo.AdminUser.Id,
  5283. UpdateCreator: 0,
  5284. Status: 1,
  5285. Ctime: time.Now().Unix(),
  5286. Mtime: 0,
  5287. Price: info.Price,
  5288. WarehousingDetailId: info.WarehouseInfotId,
  5289. WarehouseOutDetailId: info.ID,
  5290. CancelOutDetailId: cancelInfo.ID,
  5291. ProductDate: info.ProductDate,
  5292. ExpireDate: info.ExpiryDate,
  5293. StorehouseId: houseConfig.StorehouseOutInfo,
  5294. OverCount: over_count,
  5295. }
  5296. service.CreateStockFlowOne(flow)
  5297. }
  5298. //出库数据小于退库数据
  5299. if info.Count < prescribingNumber {
  5300. flow := models.VmStockFlow{
  5301. WarehousingId: info.WarehouseInfotId,
  5302. GoodId: project.ProjectId,
  5303. Number: info.Number,
  5304. LicenseNumber: info.LicenseNumber,
  5305. Count: info.Count,
  5306. UserOrgId: adminInfo.CurrentOrgId,
  5307. PatientId: project.PatientId,
  5308. SystemTime: info.SysRecordTime,
  5309. ConsumableType: 7,
  5310. IsSys: 0,
  5311. WarehousingOrder: "",
  5312. WarehouseOutId: info.WarehouseOutId,
  5313. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5314. IsEdit: 0,
  5315. CancelStockId: cancel.ID,
  5316. CancelOrderNumber: cancel.OrderNumber,
  5317. Manufacturer: manufacturer.ID,
  5318. Dealer: 0,
  5319. Creator: adminInfo.AdminUser.Id,
  5320. UpdateCreator: 0,
  5321. Status: 1,
  5322. Ctime: time.Now().Unix(),
  5323. Mtime: 0,
  5324. Price: info.Price,
  5325. WarehousingDetailId: info.WarehouseInfotId,
  5326. WarehouseOutDetailId: info.ID,
  5327. CancelOutDetailId: cancelInfo.ID,
  5328. ProductDate: info.ProductDate,
  5329. ExpireDate: info.ExpiryDate,
  5330. StorehouseId: houseConfig.StorehouseOutInfo,
  5331. OverCount: over_count,
  5332. }
  5333. service.CreateStockFlowOne(flow)
  5334. }
  5335. //查询已出库数量
  5336. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5337. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5338. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5339. if prescribingNumber < dialysisInfo.Count {
  5340. //改变数量
  5341. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5342. }
  5343. if prescribingNumber >= dialysisInfo.Count {
  5344. //删除出库表
  5345. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5346. }
  5347. //更新剩余库存
  5348. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5349. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5350. var total_count_one int64
  5351. for _, it := range stockList {
  5352. total_count_one += it.StockCount
  5353. }
  5354. //基础库插入数据
  5355. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5356. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5357. var flush_count int64
  5358. for _, it := range goodListOne {
  5359. flush_count += it.StockCount
  5360. }
  5361. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5362. if errs != nil {
  5363. goodErrcode := models.XtGoodErrcode{
  5364. UserOrgId: project.UserOrgId,
  5365. Errcode: "手动出库更新剩余出库失败",
  5366. GoodId: project.ProjectId,
  5367. Status: 1,
  5368. Ctime: time.Now().Unix(),
  5369. Mtime: 0,
  5370. Count: 0,
  5371. StockCount: 0,
  5372. Creater: creater,
  5373. BatchNumberId: 0,
  5374. WarehouseOutId: 0,
  5375. }
  5376. service.CreateGoodErrcode(goodErrcode)
  5377. }
  5378. }
  5379. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5380. fmt.Println(err)
  5381. } else {
  5382. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5383. fmt.Println(err)
  5384. }
  5385. } else {
  5386. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5387. fmt.Println(err)
  5388. }
  5389. }
  5390. //保存处方出库
  5391. if goodOutConfig.IsOpen == 1 {
  5392. if project.Type == 3 {
  5393. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5394. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5395. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5396. operation_time := time.Now().Unix()
  5397. creater := adminInfo.AdminUser.Id
  5398. //创建退库单
  5399. timeStr := time.Now().Format("2006-01-02")
  5400. timeArr := strings.Split(timeStr, "-")
  5401. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5402. total = total + 1
  5403. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5404. cancelStock := models.CancelStock{
  5405. OrderNumber: orderNumber,
  5406. OperaTime: operation_time,
  5407. OrgId: adminInfo.CurrentOrgId,
  5408. Creater: creater,
  5409. Ctime: time.Now().Unix(),
  5410. Status: 1,
  5411. ReturnTime: project.RecordDate,
  5412. Type: 1,
  5413. StorehouseId: houseConfig.StorehouseOutInfo,
  5414. IsCheck: 1,
  5415. }
  5416. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5417. if msgerrkonde == gorm.ErrRecordNotFound {
  5418. service.AddSigleCancelStock(&cancelStock)
  5419. }
  5420. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5421. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5422. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5423. //获取出库数据
  5424. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5425. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5426. deaerler, _ := service.GetDealerById(info.Dealer)
  5427. if info.ID > 0 {
  5428. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5429. if info.Count >= prescribingNumber {
  5430. cancelStockInfo := models.CancelStockInfo{
  5431. GoodId: project.ProjectId,
  5432. CancelStockId: cancel.ID,
  5433. GoodTypeId: good.GoodTypeId,
  5434. Count: prescribingNumber,
  5435. Price: info.Price,
  5436. Total: 0,
  5437. ProductDate: info.ProductDate,
  5438. ExpiryDate: info.ExpiryDate,
  5439. Ctime: time.Now().Unix(),
  5440. Status: 1,
  5441. OrgId: adminInfo.CurrentOrgId,
  5442. OrderNumber: cancel.OrderNumber,
  5443. Type: 0,
  5444. Dealer: deaerler.DealerName,
  5445. Manufacturer: manufacturer.ManufacturerName,
  5446. Number: info.Number,
  5447. RegisterAccount: "",
  5448. Remark: "",
  5449. WarehouseInfoId: info.WarehouseInfotId,
  5450. PatientId: info.PatientId,
  5451. RecordDate: info.SysRecordTime,
  5452. StorehouseId: houseConfig.StorehouseOutInfo,
  5453. IsCheck: 1,
  5454. }
  5455. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5456. //退库数量增加
  5457. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5458. //出库数量减少
  5459. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5460. }
  5461. if info.Count < prescribingNumber {
  5462. cancelStockInfo := models.CancelStockInfo{
  5463. GoodId: project.ProjectId,
  5464. CancelStockId: cancel.ID,
  5465. GoodTypeId: good.GoodTypeId,
  5466. Count: prescribingNumber,
  5467. Price: info.Price,
  5468. Total: 0,
  5469. ProductDate: info.ProductDate,
  5470. ExpiryDate: info.ExpiryDate,
  5471. Ctime: time.Now().Unix(),
  5472. Status: 1,
  5473. OrgId: adminInfo.CurrentOrgId,
  5474. OrderNumber: cancel.OrderNumber,
  5475. Type: 0,
  5476. Dealer: deaerler.DealerName,
  5477. Manufacturer: manufacturer.ManufacturerName,
  5478. Number: info.Number,
  5479. RegisterAccount: "",
  5480. Remark: "",
  5481. WarehouseInfoId: info.WarehouseInfotId,
  5482. PatientId: info.PatientId,
  5483. RecordDate: info.SysRecordTime,
  5484. StorehouseId: houseConfig.StorehouseOutInfo,
  5485. IsCheck: 1,
  5486. }
  5487. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5488. //回退库存
  5489. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5490. }
  5491. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5492. var over_count int64
  5493. for _, it := range goodList {
  5494. over_count += it.StockCount
  5495. }
  5496. //查询出库数量
  5497. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5498. //出库数据 大于 退库数量
  5499. if len(list) > 0 {
  5500. for _, it := range list {
  5501. //回退库存
  5502. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5503. //退库数量增加
  5504. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5505. //出库数量减少
  5506. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5507. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5508. var over_count_one int64
  5509. for _, it := range goodList {
  5510. over_count_one += it.StockCount
  5511. }
  5512. //查询该批次是否有退库数据
  5513. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5514. flow := models.VmStockFlow{
  5515. WarehousingId: it.WarehouseInfotId,
  5516. GoodId: it.GoodId,
  5517. Number: it.Number,
  5518. LicenseNumber: it.LicenseNumber,
  5519. Count: it.Count,
  5520. UserOrgId: adminInfo.CurrentOrgId,
  5521. PatientId: it.PatientId,
  5522. SystemTime: it.SysRecordTime,
  5523. ConsumableType: 7,
  5524. IsSys: 0,
  5525. WarehousingOrder: "",
  5526. WarehouseOutId: it.WarehouseOutId,
  5527. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5528. IsEdit: 0,
  5529. CancelStockId: cancel.ID,
  5530. CancelOrderNumber: cancel.OrderNumber,
  5531. Manufacturer: manufacturer.ID,
  5532. Dealer: 0,
  5533. Creator: adminInfo.AdminUser.Id,
  5534. UpdateCreator: 0,
  5535. Status: 1,
  5536. Ctime: time.Now().Unix(),
  5537. Mtime: 0,
  5538. Price: it.Price,
  5539. WarehousingDetailId: it.WarehouseInfotId,
  5540. WarehouseOutDetailId: it.ID,
  5541. CancelOutDetailId: cancelInfo.ID,
  5542. ProductDate: it.ProductDate,
  5543. ExpireDate: it.ExpiryDate,
  5544. StorehouseId: houseConfig.StorehouseOutInfo,
  5545. OverCount: over_count_one,
  5546. }
  5547. service.CreateStockFlowOne(flow)
  5548. }
  5549. }
  5550. //查询已出库数量
  5551. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5552. if prescribingNumber < dialysisInfo.Count {
  5553. //改变数量
  5554. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5555. }
  5556. if prescribingNumber >= dialysisInfo.Count {
  5557. //删除出库表
  5558. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5559. }
  5560. //更新剩余库存
  5561. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5562. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5563. var total_count_one int64
  5564. for _, it := range stockList {
  5565. total_count_one += it.StockCount
  5566. }
  5567. //基础库插入数据
  5568. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5569. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5570. var flush_count int64
  5571. for _, it := range goodListOne {
  5572. flush_count += it.StockCount
  5573. }
  5574. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5575. if errs != nil {
  5576. goodErrcode := models.XtGoodErrcode{
  5577. UserOrgId: project.UserOrgId,
  5578. Errcode: "手动出库更新剩余出库失败",
  5579. GoodId: project.ProjectId,
  5580. Status: 1,
  5581. Ctime: time.Now().Unix(),
  5582. Mtime: 0,
  5583. Count: 0,
  5584. StockCount: 0,
  5585. Creater: creater,
  5586. BatchNumberId: 0,
  5587. WarehouseOutId: 0,
  5588. }
  5589. service.CreateGoodErrcode(goodErrcode)
  5590. }
  5591. }
  5592. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5593. fmt.Println(err)
  5594. } else {
  5595. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5596. fmt.Println(err)
  5597. }
  5598. }
  5599. c.ServeSuccessJSON(map[string]interface{}{
  5600. "msg": "删除成功",
  5601. })
  5602. return
  5603. }
  5604. func (c *HisApiController) CreateHisAdditionalCharge() {
  5605. his_patient_id, _ := c.GetInt64("his_patient_id")
  5606. patient_id, _ := c.GetInt64("patient_id")
  5607. record_date := c.GetString("record_date")
  5608. timeLayout := "2006-01-02"
  5609. loc, _ := time.LoadLocation("Local")
  5610. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5611. if err != nil {
  5612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5613. return
  5614. }
  5615. adminInfo := c.GetAdminUserInfo()
  5616. recordDateTime := theTime.Unix()
  5617. dataBody := make(map[string]interface{}, 0)
  5618. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5619. if err != nil {
  5620. utils.ErrorLog(err.Error())
  5621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5622. return
  5623. }
  5624. var additions []*models.HisAdditionalCharge
  5625. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5626. additions, _ := dataBody["addition"].([]interface{})
  5627. if len(additions) > 0 {
  5628. for _, item := range additions {
  5629. items := item.(map[string]interface{})
  5630. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5631. utils.ErrorLog("item_id")
  5632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5633. return
  5634. }
  5635. item_id := int64(items["item_id"].(float64))
  5636. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5637. utils.ErrorLog("item_name")
  5638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5639. return
  5640. }
  5641. item_name := items["item_name"].(string)
  5642. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5643. utils.ErrorLog("price")
  5644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5645. return
  5646. }
  5647. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5648. ctime := time.Now().Unix()
  5649. additional := &models.HisAdditionalCharge{
  5650. PatientId: patient_id,
  5651. HisPatientId: his_patient_id,
  5652. UserOrgId: adminInfo.CurrentOrgId,
  5653. RecordDate: recordDateTime,
  5654. CreatedTime: ctime,
  5655. UpdatedTime: ctime,
  5656. Modifier: adminInfo.AdminUser.Id,
  5657. Creator: adminInfo.AdminUser.Id,
  5658. Price: price,
  5659. ItemName: item_name,
  5660. ItemId: item_id,
  5661. Status: 1,
  5662. }
  5663. additions = append(additions, additional)
  5664. }
  5665. }
  5666. }
  5667. for _, item := range additions {
  5668. service.CreateAddtionalCharge(item)
  5669. }
  5670. c.ServeSuccessJSON(map[string]interface{}{
  5671. "msg": "创建成功",
  5672. })
  5673. }
  5674. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5675. blood_fat := c.GetString("blood_fat")
  5676. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5677. blood_sugar := c.GetString("blood_sugar")
  5678. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5679. chief_conplaint := c.GetString("chief_conplaint")
  5680. dbp := c.GetString("dbp")
  5681. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5682. delivery_way, _ := c.GetInt64("delivery_way")
  5683. diagnostic := c.GetString("diagnostic")
  5684. family_history := c.GetString("family_history")
  5685. height := c.GetString("height")
  5686. history_of_present_illness := c.GetString("history_of_present_illness")
  5687. is_infect, _ := c.GetInt64("is_infect")
  5688. past_history := c.GetString("past_history")
  5689. patient_id, _ := c.GetInt64("patient_id")
  5690. his_patient_id, _ := c.GetInt64("his_patient_id")
  5691. personal_history := c.GetString("personal_history")
  5692. pulse := c.GetString("pulse")
  5693. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5694. sbp := c.GetString("sbp")
  5695. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5696. heightfloat, _ := strconv.ParseFloat(height, 64)
  5697. sicktype := c.GetString("sick_type")
  5698. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5699. symptom := c.GetString("symptom")
  5700. sick_date := c.GetString("sick_date")
  5701. temperatures := c.GetString("temperature")
  5702. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5703. record_date := c.GetString("record_date")
  5704. breathing := c.GetString("breathing")
  5705. doctor_advice := c.GetString("doctor_advice")
  5706. remark := c.GetString("remark")
  5707. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5708. sick, _ := c.GetInt64("sick")
  5709. diagnose, _ := c.GetInt64("diagnose")
  5710. //id, _ := c.GetInt64("id")
  5711. timeLayout := "2006-01-02"
  5712. loc, _ := time.LoadLocation("Local")
  5713. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5714. allergic_history := c.GetString("allergic_history")
  5715. if err != nil {
  5716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5717. return
  5718. }
  5719. recordDateTime := theTime.Unix()
  5720. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5721. if err != nil {
  5722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5723. return
  5724. }
  5725. sickTimes := sickTime.Unix()
  5726. ctime := time.Now().Unix()
  5727. primary_disease := c.GetString("primary_disease")
  5728. confirm_failure_date := c.GetString("confirm_failure_date")
  5729. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5730. drug_allergy_history := c.GetString("drug_allergy_history")
  5731. physical_examination := c.GetString("physical_examination")
  5732. special_inspection := c.GetString("special_inspection")
  5733. lab_apparatus := c.GetString("lab_apparatus")
  5734. caseHistory := models.HisPatientCaseHistory{
  5735. HisPatientId: his_patient_id,
  5736. PatientId: patient_id,
  5737. Temperature: temperature,
  5738. BloodSugar: bloodsugarfloat,
  5739. Pulse: pulsefloat,
  5740. Sbp: sbpfloat,
  5741. Dbp: dbpfloat,
  5742. Height: heightfloat,
  5743. BloodFat: bloodfatfloat,
  5744. SickType: sick_type,
  5745. Symptom: symptom,
  5746. SickDate: sickTimes,
  5747. IsInfect: is_infect,
  5748. HistoryOfPresentIllness: history_of_present_illness,
  5749. PastHistory: past_history,
  5750. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5751. ChiefConplaint: chief_conplaint,
  5752. PersonalHistory: personal_history,
  5753. FamilyHistory: family_history,
  5754. Diagnostic: diagnostic,
  5755. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5756. Status: 1,
  5757. Ctime: ctime,
  5758. Mtime: ctime,
  5759. RecordDate: recordDateTime,
  5760. DeliveryWay: delivery_way,
  5761. Breathing: breathingfloat,
  5762. DoctorAdvice: doctor_advice,
  5763. Remark: remark,
  5764. Sick: sick,
  5765. Diagnose: diagnose,
  5766. AllergicHistory: allergic_history,
  5767. PrimaryDisease: primary_disease,
  5768. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5769. DrugAllergyHistory: drug_allergy_history,
  5770. PhysicalExamination: physical_examination,
  5771. SpecialInspection: special_inspection,
  5772. LabApparatus: lab_apparatus,
  5773. }
  5774. //查询该患者是否有病历
  5775. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5776. if errcodes == gorm.ErrRecordNotFound {
  5777. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5778. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5779. if err != nil {
  5780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5781. return
  5782. }
  5783. c.ServeSuccessJSON(map[string]interface{}{
  5784. "caseHistory": caseHistory,
  5785. "historyInfo": historyInfo,
  5786. })
  5787. return
  5788. } else if errcodes == nil {
  5789. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5790. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5791. if err != nil {
  5792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5793. return
  5794. }
  5795. c.ServeSuccessJSON(map[string]interface{}{
  5796. "caseHistory": caseHistory,
  5797. "historyInfo": historyInfo,
  5798. })
  5799. }
  5800. //查询该患者是否有病历
  5801. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5802. //if errcode == gorm.ErrRecordNotFound {
  5803. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5804. // if err != nil {
  5805. // c.ServeSuccessJSON(map[string]interface{}{
  5806. // "msg": "保存成功",
  5807. // })
  5808. // }
  5809. //} else if errcode == nil {
  5810. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5811. // return
  5812. //}
  5813. }
  5814. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5815. patient_id, _ := c.GetInt64("patient_id", 0)
  5816. adminUser := c.GetAdminUserInfo()
  5817. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5818. c.ServeSuccessJSON(map[string]interface{}{
  5819. "list": caseHistorys,
  5820. })
  5821. }
  5822. func (c *HisApiController) GetHisPatientCaseHistory() {
  5823. record_date, _ := c.GetInt64("record_date", 0)
  5824. patient_id, _ := c.GetInt64("patient_id", 0)
  5825. admin := c.GetAdminUserInfo()
  5826. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5827. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5828. c.ServeSuccessJSON(map[string]interface{}{
  5829. "info": info,
  5830. "case_history": case_history,
  5831. })
  5832. }
  5833. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5834. template_name := c.GetString("template_name")
  5835. template_remark := c.GetString("template_remark")
  5836. doctor := c.GetAdminUserInfo().AdminUser.Id
  5837. diagnostic := c.GetString("diagnostic")
  5838. chief_conplaint := c.GetString("chief_conplain")
  5839. history_of_present_illness := c.GetString("history_of_present_illness")
  5840. past_history := c.GetString("past_history")
  5841. personal_history := c.GetString("personal_history")
  5842. family_history := c.GetString("family_history")
  5843. user_name := c.GetString("user_name")
  5844. doctor_advice := c.GetString("doctor_advice")
  5845. remark := c.GetString("remark")
  5846. //record_date := c.GetString("record_date")
  5847. //fmt.Println("record_date--------",record_date)
  5848. //timeLayout := "2006-01-02"
  5849. //loc, _ := time.LoadLocation("Local")
  5850. //
  5851. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5852. //if err != nil {
  5853. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5854. // return
  5855. //}
  5856. //recordDateTime := theTime.Unix()
  5857. ctime := time.Now().Unix()
  5858. template := models.HisCaseHistoryTemplate{
  5859. HistoryOfPresentIllness: history_of_present_illness,
  5860. PastHistory: past_history,
  5861. ChiefConplaint: chief_conplaint,
  5862. PersonalHistory: personal_history,
  5863. FamilyHistory: family_history,
  5864. Diagnostic: diagnostic,
  5865. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5866. Status: 1,
  5867. Ctime: ctime,
  5868. Mtime: ctime,
  5869. RecordDate: time.Now().Unix(),
  5870. TemplateName: template_name,
  5871. TemplateRemark: template_remark,
  5872. Creator: doctor,
  5873. Modifier: doctor,
  5874. UserName: user_name,
  5875. DoctorAdvice: doctor_advice,
  5876. Remark: remark,
  5877. }
  5878. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5879. if err == nil {
  5880. c.ServeSuccessJSON(map[string]interface{}{
  5881. "msg": "保存成功",
  5882. })
  5883. } else {
  5884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5885. return
  5886. }
  5887. }
  5888. func (c *HisApiController) GetCaseHistoryTemplate() {
  5889. timeLayout := "2006-01-02"
  5890. loc, _ := time.LoadLocation("Local")
  5891. keyword := c.GetString("keyword")
  5892. start_time := c.GetString("start_time")
  5893. end_time := c.GetString("end_time")
  5894. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5895. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5896. admin := c.GetAdminUserInfo()
  5897. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5898. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5899. c.ServeSuccessJSON(map[string]interface{}{
  5900. "template": template,
  5901. //"history": history,
  5902. })
  5903. }
  5904. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5905. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5906. utils.ErrorLog("drug_name")
  5907. return enums.ErrorCodeParamWrong
  5908. }
  5909. adviceName, _ := json["drug_name"].(string)
  5910. if len(adviceName) == 0 {
  5911. utils.ErrorLog("len(advice_name) == 0")
  5912. return enums.ErrorCodeParamWrong
  5913. }
  5914. advice.AdviceName = adviceName
  5915. adviceDesc, _ := json["advice_desc"].(string)
  5916. advice.AdviceDesc = adviceDesc
  5917. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5918. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5919. advice.DrugSpec = drugSpec
  5920. }
  5921. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5922. remark, _ := json["remark"].(string)
  5923. advice.Remark = remark
  5924. }
  5925. if json["id"] == nil {
  5926. advice.DrugId = 0
  5927. } else {
  5928. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5929. drug_id := int64(json["id"].(float64))
  5930. advice.DrugId = drug_id
  5931. }
  5932. }
  5933. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5934. advice_id := int64(json["advice_id"].(float64))
  5935. advice.ID = advice_id
  5936. if advice.ID > 0 {
  5937. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5938. if err == nil {
  5939. if hisAdvice.ID > 0 {
  5940. advice.ExecutionTime = hisAdvice.ExecutionTime
  5941. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5942. advice.ExecutionState = hisAdvice.ExecutionState
  5943. advice.CheckTime = hisAdvice.CheckTime
  5944. advice.Checker = hisAdvice.Checker
  5945. advice.CheckState = hisAdvice.CheckState
  5946. advice.StartTime = hisAdvice.StartTime
  5947. advice.FeedetlSn = hisAdvice.FeedetlSn
  5948. }
  5949. }
  5950. }
  5951. }
  5952. //
  5953. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5954. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5955. // advice.ExecutionTime = execution_time
  5956. //}
  5957. //
  5958. //
  5959. //
  5960. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5961. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5962. // advice.ExecutionStaff = execution_staff
  5963. //}
  5964. //
  5965. //
  5966. //
  5967. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5968. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5969. // advice.ExecutionState = execution_state
  5970. //}
  5971. //
  5972. //
  5973. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5974. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5975. // advice.CheckTime = check_time
  5976. //}
  5977. //
  5978. //
  5979. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5980. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5981. // advice.CheckState = check_state
  5982. //}
  5983. //
  5984. //
  5985. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5986. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5987. // advice.Checker = checker
  5988. //}
  5989. //
  5990. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5991. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5992. // advice.StartTime = start_time
  5993. //}
  5994. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5995. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5996. advice.IsSelfDrug = is_self_drug
  5997. }
  5998. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5999. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6000. drug_way_count, _ := json["drug_way_count"].(string)
  6001. advice.DrugWayCount = drug_way_count
  6002. }
  6003. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6004. drugSpecUnit, _ := json["min_unit"].(string)
  6005. advice.DrugSpecUnit = drugSpecUnit
  6006. }
  6007. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6008. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6009. advice.SingleDose = singleDose
  6010. }
  6011. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6012. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6013. advice.SingleDoseUnit = singleDoseUnit
  6014. }
  6015. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6016. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6017. advice.PrescribingNumber = prescribingNumber
  6018. }
  6019. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6020. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6021. advice.PrescribingNumberUnit = prescribingNumberUnit
  6022. }
  6023. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6024. deliveryWay, _ := json["delivery_way"].(string)
  6025. advice.DeliveryWay = deliveryWay
  6026. }
  6027. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6028. executionFrequency, _ := json["execution_frequency"].(string)
  6029. advice.ExecutionFrequency = executionFrequency
  6030. }
  6031. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6032. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6033. advice.Price = price
  6034. }
  6035. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6036. med_list_codg, _ := json["medical_insurance_number"].(string)
  6037. advice.MedListCodg = med_list_codg
  6038. }
  6039. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6040. day := int64(json["day"].(float64))
  6041. advice.Day = day
  6042. }
  6043. return 0
  6044. }
  6045. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6046. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6047. id := int64(json["id"].(float64))
  6048. project.ID = id
  6049. historyProject, _ := service.GetHisProjectByID(id)
  6050. project.FeedetlSn = historyProject.FeedetlSn
  6051. }
  6052. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6053. project_id := int64(json["project_id"].(float64))
  6054. project.ProjectId = project_id
  6055. }
  6056. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6057. // price := int64(json["price"].(float64))
  6058. // formatInt_price := strconv.FormatInt(price, 10)
  6059. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6060. // project.Price = float_price
  6061. // }
  6062. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6063. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6064. project.Price = price
  6065. }
  6066. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6067. total, _ := json["total"].(string)
  6068. project.Count = total
  6069. }
  6070. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6071. medical_code, _ := json["medical_code"].(string)
  6072. project.MedListCodg = medical_code
  6073. }
  6074. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6075. single_dose, _ := json["single_dose"].(string)
  6076. project.SingleDose = single_dose
  6077. }
  6078. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6079. delivery_way, _ := json["delivery_way"].(string)
  6080. project.DeliveryWay = delivery_way
  6081. }
  6082. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6083. execution_frequency, _ := json["execution_frequency"].(string)
  6084. project.ExecutionFrequency = execution_frequency
  6085. }
  6086. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6087. remark, _ := json["remark"].(string)
  6088. project.Remark = remark
  6089. }
  6090. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6091. day, _ := json["number_days"].(string)
  6092. project.Day = day
  6093. }
  6094. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6095. unit, _ := json["unit"].(string)
  6096. project.Unit = unit
  6097. }
  6098. return 0
  6099. }
  6100. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6101. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6102. id := int64(json["id"].(float64))
  6103. historyAddtions, _ := service.GetHisAdditionByID(id)
  6104. additionalCharge.ID = id
  6105. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6106. }
  6107. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6108. item_id := int64(json["item_id"].(float64))
  6109. additionalCharge.ItemId = item_id
  6110. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6111. if config.ID > 0 {
  6112. if len(config.Code) > 0 {
  6113. additionalCharge.MedListCodg = config.Code
  6114. }
  6115. }
  6116. }
  6117. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6118. // price := int64(json["price"].(float64))
  6119. // formatInt_price := strconv.FormatInt(price, 10)
  6120. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6121. // additionalCharge.Price = float_price
  6122. // }
  6123. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6124. // price := int64(json["price"].(float64))
  6125. // formatInt_price := strconv.FormatInt(price, 10)
  6126. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6127. // additionalCharge.Price = float_price
  6128. //}
  6129. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6130. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6131. additionalCharge.Price = price
  6132. }
  6133. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6134. count, _ := json["count"].(string)
  6135. counts, _ := strconv.ParseInt(count, 10, 64)
  6136. additionalCharge.Count = counts
  6137. }
  6138. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6139. item_name, _ := json["item_name"].(string)
  6140. additionalCharge.ItemName = item_name
  6141. }
  6142. return 0
  6143. }
  6144. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6145. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6146. utils.ErrorLog("drug_name")
  6147. return enums.ErrorCodeParamWrong
  6148. }
  6149. adviceName, _ := json["drug_name"].(string)
  6150. if len(adviceName) == 0 {
  6151. utils.ErrorLog("len(advice_name) == 0")
  6152. return enums.ErrorCodeParamWrong
  6153. }
  6154. advice.AdviceName = adviceName
  6155. adviceDesc, _ := json["advice_desc"].(string)
  6156. advice.AdviceDesc = adviceDesc
  6157. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6158. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6159. advice.DrugSpec = drugSpec
  6160. }
  6161. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6162. remark, _ := json["remark"].(string)
  6163. advice.Remark = remark
  6164. }
  6165. if json["id"] == nil {
  6166. advice.DrugId = 0
  6167. } else {
  6168. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6169. drug_id := int64(json["id"].(float64))
  6170. advice.DrugId = drug_id
  6171. }
  6172. }
  6173. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6174. groupno := int64(json["groupno"].(float64))
  6175. advice.Groupno = groupno
  6176. }
  6177. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6178. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6179. advice.IsSelfDrug = is_self_drug
  6180. }
  6181. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6182. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6183. drug_way_count, _ := json["drug_way_count"].(string)
  6184. advice.DrugWayCount = drug_way_count
  6185. }
  6186. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6187. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6188. advice.HospApprFlag = hosp_appr_flag
  6189. }
  6190. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6191. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6192. advice.PrescribingNumber = prescribingNumber
  6193. }
  6194. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6195. // frequency_type := int64(json["frequency_type"].(float64))
  6196. // advice.FrequencyType = frequency_type
  6197. //}
  6198. //
  6199. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6200. // day_count := int64(json["day_count"].(float64))
  6201. // advice.DayCount = day_count
  6202. //}
  6203. //
  6204. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6205. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6206. // week_day, _ := json["week_day"].(string)
  6207. // advice.WeekDay = week_day
  6208. //}
  6209. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6210. drugSpecUnit, _ := json["min_unit"].(string)
  6211. advice.DrugSpecUnit = drugSpecUnit
  6212. }
  6213. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6214. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6215. advice.SingleDose = singleDose
  6216. }
  6217. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6218. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6219. advice.SingleDoseUnit = singleDoseUnit
  6220. }
  6221. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6222. deliveryWay, _ := json["delivery_way"].(string)
  6223. advice.DeliveryWay = deliveryWay
  6224. }
  6225. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6226. executionFrequency, _ := json["execution_frequency"].(string)
  6227. advice.ExecutionFrequency = executionFrequency
  6228. }
  6229. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6230. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6231. advice.Price = price
  6232. }
  6233. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6234. med_list_codg, _ := json["medical_insurance_number"].(string)
  6235. advice.MedListCodg = med_list_codg
  6236. }
  6237. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6238. day := int64(json["day"].(float64))
  6239. advice.Day = day
  6240. }
  6241. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6242. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6243. advice.PrescribingNumberUnit = prescribingNumberUnit
  6244. }
  6245. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6246. advice_id := int64(json["advice_id"].(float64))
  6247. advice.ID = advice_id
  6248. if advice.ID > 0 {
  6249. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6250. if err == nil {
  6251. if hisAdvice.ID > 0 {
  6252. advice.ExecutionTime = hisAdvice.ExecutionTime
  6253. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6254. advice.ExecutionState = hisAdvice.ExecutionState
  6255. advice.CheckTime = hisAdvice.CheckTime
  6256. advice.Checker = hisAdvice.Checker
  6257. advice.CheckState = hisAdvice.CheckState
  6258. advice.StartTime = hisAdvice.StartTime
  6259. advice.HospApprFlag = hisAdvice.HospApprFlag
  6260. advice.IsMedicine = hisAdvice.IsMedicine
  6261. if hisAdvice.UserOrgId == 10028 {
  6262. 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 {
  6263. advice.ExecutionTime = 0
  6264. advice.ExecutionStaff = 0
  6265. advice.ExecutionState = 2
  6266. advice.CheckTime = 0
  6267. advice.Checker = 0
  6268. advice.CheckState = 2
  6269. }
  6270. } else {
  6271. 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 {
  6272. advice.ExecutionTime = 0
  6273. advice.ExecutionStaff = 0
  6274. advice.ExecutionState = 2
  6275. advice.CheckTime = 0
  6276. advice.Checker = 0
  6277. advice.CheckState = 2
  6278. }
  6279. }
  6280. //advice.Groupno = hisAdvice.Groupno
  6281. }
  6282. }
  6283. }
  6284. }
  6285. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6286. //
  6287. //if drugStockConfig.IsOpen == 1 {
  6288. //
  6289. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6290. // if advice.ID == 0 { //医嘱不存在
  6291. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6292. // drug.Total = drug.Total - advice.PrescribingNumber
  6293. // service.UpdateBaseDrugLib(&drug)
  6294. //
  6295. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6296. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6297. // drug.Total = drug.Total - num
  6298. // service.UpdateBaseDrugLib(&drug)
  6299. // }
  6300. //
  6301. // } else if advice.ID > 0 { //医嘱存在
  6302. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6303. // var num float64
  6304. //
  6305. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6306. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6307. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6308. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6309. // drug.Total = drug.Total + num
  6310. // service.UpdateBaseDrugLib(&drug)
  6311. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6312. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6313. // drug.Total = drug.Total - num
  6314. // service.UpdateBaseDrugLib(&drug)
  6315. // }
  6316. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6317. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6318. // if num2 > advice.PrescribingNumber {
  6319. // num = num2 - advice.PrescribingNumber
  6320. // drug.Total = drug.Total + num
  6321. // service.UpdateBaseDrugLib(&drug)
  6322. // } else if num2 < advice.PrescribingNumber {
  6323. // num = advice.PrescribingNumber - num2
  6324. // drug.Total = drug.Total - num
  6325. // service.UpdateBaseDrugLib(&drug)
  6326. // }
  6327. //
  6328. // }
  6329. //
  6330. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6331. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6332. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6333. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6334. // if num1 > num2 {
  6335. // num = num1 - num2
  6336. // drug.Total = drug.Total + num
  6337. // service.UpdateBaseDrugLib(&drug)
  6338. // } else if num1 < num2 {
  6339. // num = num2 - num1
  6340. // drug.Total = drug.Total - num
  6341. // service.UpdateBaseDrugLib(&drug)
  6342. // }
  6343. //
  6344. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6345. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6346. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6347. // if hisAdvice.PrescribingNumber > num2 {
  6348. // num = hisAdvice.PrescribingNumber - num2
  6349. // drug.Total = drug.Total + num
  6350. // service.UpdateBaseDrugLib(&drug)
  6351. // } else if num2 < advice.PrescribingNumber {
  6352. // num = num2 - hisAdvice.PrescribingNumber
  6353. // drug.Total = drug.Total - num
  6354. // service.UpdateBaseDrugLib(&drug)
  6355. // }
  6356. //
  6357. // }
  6358. // }
  6359. // }
  6360. //}
  6361. //
  6362. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6363. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6364. // advice.ExecutionTime = execution_time
  6365. //}
  6366. //
  6367. //
  6368. //
  6369. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6370. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6371. // advice.ExecutionStaff = execution_staff
  6372. //}
  6373. //
  6374. //
  6375. //
  6376. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6377. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6378. // advice.ExecutionState = execution_state
  6379. //}
  6380. //
  6381. //
  6382. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6383. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6384. // advice.CheckTime = check_time
  6385. //}
  6386. //
  6387. //
  6388. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6389. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6390. // advice.CheckState = check_state
  6391. //}
  6392. //
  6393. //
  6394. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6395. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6396. // advice.Checker = checker
  6397. //}
  6398. //
  6399. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6400. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6401. // advice.StartTime = start_time
  6402. //}
  6403. return 0
  6404. }
  6405. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6406. project.ExecutionStaff = 0
  6407. project.ExecutionState = 2
  6408. project.ExecutionTime = 0
  6409. project.Checker = 0
  6410. project.CheckState = 2
  6411. project.CheckTime = 0
  6412. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6413. id := int64(json["id"].(float64))
  6414. project.ID = id
  6415. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6416. project.ExecutionStaff = temp_project.ExecutionStaff
  6417. project.ExecutionState = temp_project.ExecutionState
  6418. project.ExecutionTime = temp_project.ExecutionTime
  6419. project.Checker = temp_project.Checker
  6420. project.CheckState = temp_project.CheckState
  6421. project.CheckTime = temp_project.CheckTime
  6422. project.TeamId = temp_project.TeamId
  6423. }
  6424. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6425. types := int64(json["type"].(float64))
  6426. project.Type = types
  6427. }
  6428. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6429. project_id := int64(json["project_id"].(float64))
  6430. project.ProjectId = project_id
  6431. }
  6432. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6433. team_id := int64(json["team_id"].(float64))
  6434. project.TeamId = team_id
  6435. }
  6436. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6437. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6438. project.Price = price
  6439. }
  6440. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6441. total, _ := json["total"].(string)
  6442. //totals, _ := strconv.ParseInt(total, 10, 64)
  6443. project.Count = total
  6444. }
  6445. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6446. medical_code, _ := json["medical_code"].(string)
  6447. project.MedListCodg = medical_code
  6448. }
  6449. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6450. single_dose, _ := json["single_dose"].(string)
  6451. project.SingleDose = single_dose
  6452. }
  6453. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6454. delivery_way, _ := json["delivery_way"].(string)
  6455. project.DeliveryWay = delivery_way
  6456. }
  6457. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6458. execution_frequency, _ := json["execution_frequency"].(string)
  6459. project.ExecutionFrequency = execution_frequency
  6460. }
  6461. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6462. remark, _ := json["remark"].(string)
  6463. project.Remark = remark
  6464. }
  6465. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6466. day, _ := json["number_days"].(string)
  6467. project.Day = day
  6468. }
  6469. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6470. unit, _ := json["unit"].(string)
  6471. project.Unit = unit
  6472. }
  6473. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6474. // frequency_type := int64(json["frequency_type"].(float64))
  6475. // project.FrequencyType = frequency_type
  6476. //}
  6477. //
  6478. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6479. // day_count := int64(json["day_count"].(float64))
  6480. // project.DayCount = day_count
  6481. //}
  6482. //
  6483. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6484. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6485. // week_day, _ := json["week_day"].(string)
  6486. // project.WeekDay = week_day
  6487. //}
  6488. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6489. //
  6490. //if project.ID == 0 {
  6491. // if stockConfig.IsOpen == 1 {
  6492. // if project.Type == 3 {
  6493. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6494. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6495. // good.Total = good.Total - f_count
  6496. // service.UpdateGoodInfo(&good)
  6497. // }
  6498. // }
  6499. //
  6500. //} else {
  6501. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6502. //
  6503. // if stockConfig.IsOpen == 1 {
  6504. // if project.Type == 3 {
  6505. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6506. // if project.Count < temp_project.Count {
  6507. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6508. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6509. //
  6510. // other_count := f_count_two - f_count_one
  6511. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6512. // good.Total = good.Total + other_count_two
  6513. // service.UpdateGoodInfo(&good)
  6514. // } else if project.Count > temp_project.Count {
  6515. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6516. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6517. //
  6518. // other_count := f_count_one - f_count_two
  6519. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6520. // good.Total = good.Total - other_count_two
  6521. // service.UpdateGoodInfo(&good)
  6522. // }
  6523. //
  6524. // }
  6525. // }
  6526. //
  6527. //}
  6528. return 0
  6529. }
  6530. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6531. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6532. utils.ErrorLog("drug_name")
  6533. return enums.ErrorCodeParamWrong
  6534. }
  6535. adviceName, _ := json["drug_name"].(string)
  6536. if len(adviceName) == 0 {
  6537. utils.ErrorLog("len(advice_name) == 0")
  6538. return enums.ErrorCodeParamWrong
  6539. }
  6540. advice.AdviceName = adviceName
  6541. adviceDesc, _ := json["advice_desc"].(string)
  6542. advice.AdviceDesc = adviceDesc
  6543. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6544. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6545. advice.DrugSpec = drugSpec
  6546. }
  6547. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6548. remark, _ := json["remark"].(string)
  6549. advice.Remark = remark
  6550. }
  6551. if json["id"] == nil {
  6552. advice.DrugId = 0
  6553. } else {
  6554. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6555. drug_id := int64(json["id"].(float64))
  6556. advice.DrugId = drug_id
  6557. }
  6558. }
  6559. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6560. groupno := int64(json["groupno"].(float64))
  6561. advice.Groupno = groupno
  6562. }
  6563. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6564. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6565. advice.IsSelfDrug = is_self_drug
  6566. }
  6567. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6568. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6569. drug_way_count, _ := json["drug_way_count"].(string)
  6570. advice.DrugWayCount = drug_way_count
  6571. }
  6572. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6573. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6574. advice.HospApprFlag = hosp_appr_flag
  6575. }
  6576. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6577. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6578. advice.PrescribingNumber = prescribingNumber
  6579. }
  6580. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6581. // frequency_type := int64(json["frequency_type"].(float64))
  6582. // advice.FrequencyType = frequency_type
  6583. //}
  6584. //
  6585. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6586. // day_count := int64(json["day_count"].(float64))
  6587. // advice.DayCount = day_count
  6588. //}
  6589. //
  6590. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6591. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6592. // week_day, _ := json["week_day"].(string)
  6593. // advice.WeekDay = week_day
  6594. //}
  6595. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6596. drugSpecUnit, _ := json["min_unit"].(string)
  6597. advice.DrugSpecUnit = drugSpecUnit
  6598. }
  6599. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6600. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6601. advice.SingleDose = singleDose
  6602. }
  6603. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6604. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6605. advice.SingleDoseUnit = singleDoseUnit
  6606. }
  6607. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6608. deliveryWay, _ := json["delivery_way"].(string)
  6609. advice.DeliveryWay = deliveryWay
  6610. }
  6611. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6612. executionFrequency, _ := json["execution_frequency"].(string)
  6613. advice.ExecutionFrequency = executionFrequency
  6614. }
  6615. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6616. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6617. advice.Price = price
  6618. }
  6619. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6620. med_list_codg, _ := json["medical_insurance_number"].(string)
  6621. advice.MedListCodg = med_list_codg
  6622. }
  6623. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6624. day := int64(json["day"].(float64))
  6625. advice.Day = day
  6626. }
  6627. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6628. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6629. advice.PrescribingNumberUnit = prescribingNumberUnit
  6630. }
  6631. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6632. advice_id := int64(json["advice_id"].(float64))
  6633. advice.ID = advice_id
  6634. if advice.ID > 0 {
  6635. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6636. if err == nil {
  6637. if hisAdvice.ID > 0 {
  6638. advice.ExecutionTime = hisAdvice.ExecutionTime
  6639. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6640. advice.ExecutionState = hisAdvice.ExecutionState
  6641. advice.CheckTime = hisAdvice.CheckTime
  6642. advice.Checker = hisAdvice.Checker
  6643. advice.CheckState = hisAdvice.CheckState
  6644. advice.StartTime = hisAdvice.StartTime
  6645. advice.HospApprFlag = hisAdvice.HospApprFlag
  6646. advice.IsMedicine = hisAdvice.IsMedicine
  6647. if hisAdvice.UserOrgId == 10028 {
  6648. 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 {
  6649. advice.ExecutionTime = 0
  6650. advice.ExecutionStaff = 0
  6651. advice.ExecutionState = 2
  6652. advice.CheckTime = 0
  6653. advice.Checker = 0
  6654. advice.CheckState = 2
  6655. }
  6656. } else {
  6657. 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 {
  6658. advice.ExecutionTime = 0
  6659. advice.ExecutionStaff = 0
  6660. advice.ExecutionState = 2
  6661. advice.CheckTime = 0
  6662. advice.Checker = 0
  6663. advice.CheckState = 2
  6664. }
  6665. }
  6666. //advice.Groupno = hisAdvice.Groupno
  6667. }
  6668. }
  6669. }
  6670. }
  6671. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6672. //
  6673. //if drugStockConfig.IsOpen == 1 {
  6674. //
  6675. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6676. // if advice.ID == 0 { //医嘱不存在
  6677. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6678. // drug.Total = drug.Total - advice.PrescribingNumber
  6679. // service.UpdateBaseDrugLib(&drug)
  6680. //
  6681. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6682. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6683. // drug.Total = drug.Total - num
  6684. // service.UpdateBaseDrugLib(&drug)
  6685. // }
  6686. //
  6687. // } else if advice.ID > 0 { //医嘱存在
  6688. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6689. // var num float64
  6690. //
  6691. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6692. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6693. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6694. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6695. // drug.Total = drug.Total + num
  6696. // service.UpdateBaseDrugLib(&drug)
  6697. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6698. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6699. // drug.Total = drug.Total - num
  6700. // service.UpdateBaseDrugLib(&drug)
  6701. // }
  6702. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6703. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6704. // if num2 > advice.PrescribingNumber {
  6705. // num = num2 - advice.PrescribingNumber
  6706. // drug.Total = drug.Total + num
  6707. // service.UpdateBaseDrugLib(&drug)
  6708. // } else if num2 < advice.PrescribingNumber {
  6709. // num = advice.PrescribingNumber - num2
  6710. // drug.Total = drug.Total - num
  6711. // service.UpdateBaseDrugLib(&drug)
  6712. // }
  6713. //
  6714. // }
  6715. //
  6716. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6717. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6718. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6719. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6720. // if num1 > num2 {
  6721. // num = num1 - num2
  6722. // drug.Total = drug.Total + num
  6723. // service.UpdateBaseDrugLib(&drug)
  6724. // } else if num1 < num2 {
  6725. // num = num2 - num1
  6726. // drug.Total = drug.Total - num
  6727. // service.UpdateBaseDrugLib(&drug)
  6728. // }
  6729. //
  6730. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6731. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6732. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6733. // if hisAdvice.PrescribingNumber > num2 {
  6734. // num = hisAdvice.PrescribingNumber - num2
  6735. // drug.Total = drug.Total + num
  6736. // service.UpdateBaseDrugLib(&drug)
  6737. // } else if num2 < advice.PrescribingNumber {
  6738. // num = num2 - hisAdvice.PrescribingNumber
  6739. // drug.Total = drug.Total - num
  6740. // service.UpdateBaseDrugLib(&drug)
  6741. // }
  6742. //
  6743. // }
  6744. // }
  6745. // }
  6746. //}
  6747. //
  6748. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6749. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6750. // advice.ExecutionTime = execution_time
  6751. //}
  6752. //
  6753. //
  6754. //
  6755. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6756. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6757. // advice.ExecutionStaff = execution_staff
  6758. //}
  6759. //
  6760. //
  6761. //
  6762. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6763. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6764. // advice.ExecutionState = execution_state
  6765. //}
  6766. //
  6767. //
  6768. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6769. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6770. // advice.CheckTime = check_time
  6771. //}
  6772. //
  6773. //
  6774. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6775. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6776. // advice.CheckState = check_state
  6777. //}
  6778. //
  6779. //
  6780. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6781. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6782. // advice.Checker = checker
  6783. //}
  6784. //
  6785. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6786. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6787. // advice.StartTime = start_time
  6788. //}
  6789. return 0
  6790. }
  6791. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6792. project.ExecutionStaff = 0
  6793. project.ExecutionState = 2
  6794. project.ExecutionTime = 0
  6795. project.Checker = 0
  6796. project.CheckState = 2
  6797. project.CheckTime = 0
  6798. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6799. id := int64(json["id"].(float64))
  6800. project.ID = id
  6801. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6802. project.ExecutionStaff = temp_project.ExecutionStaff
  6803. project.ExecutionState = temp_project.ExecutionState
  6804. project.ExecutionTime = temp_project.ExecutionTime
  6805. project.Checker = temp_project.Checker
  6806. project.CheckState = temp_project.CheckState
  6807. project.CheckTime = temp_project.CheckTime
  6808. project.TeamId = temp_project.TeamId
  6809. }
  6810. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6811. types := int64(json["type"].(float64))
  6812. project.Type = types
  6813. }
  6814. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6815. project_id := int64(json["project_id"].(float64))
  6816. project.ProjectId = project_id
  6817. }
  6818. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6819. team_id := int64(json["team_id"].(float64))
  6820. project.TeamId = team_id
  6821. }
  6822. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6823. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6824. project.Price = price
  6825. }
  6826. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6827. total, _ := json["total"].(string)
  6828. //totals, _ := strconv.ParseInt(total, 10, 64)
  6829. project.Count = total
  6830. }
  6831. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6832. medical_code, _ := json["medical_code"].(string)
  6833. project.MedListCodg = medical_code
  6834. }
  6835. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6836. single_dose, _ := json["single_dose"].(string)
  6837. project.SingleDose = single_dose
  6838. }
  6839. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6840. delivery_way, _ := json["delivery_way"].(string)
  6841. project.DeliveryWay = delivery_way
  6842. }
  6843. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6844. execution_frequency, _ := json["execution_frequency"].(string)
  6845. project.ExecutionFrequency = execution_frequency
  6846. }
  6847. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6848. remark, _ := json["remark"].(string)
  6849. project.Remark = remark
  6850. }
  6851. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6852. day, _ := json["number_days"].(string)
  6853. project.Day = day
  6854. }
  6855. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6856. unit, _ := json["unit"].(string)
  6857. project.Unit = unit
  6858. }
  6859. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6860. // frequency_type := int64(json["frequency_type"].(float64))
  6861. // project.FrequencyType = frequency_type
  6862. //}
  6863. //
  6864. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6865. // day_count := int64(json["day_count"].(float64))
  6866. // project.DayCount = day_count
  6867. //}
  6868. //
  6869. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6870. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6871. // week_day, _ := json["week_day"].(string)
  6872. // project.WeekDay = week_day
  6873. //}
  6874. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6875. //
  6876. //if project.ID == 0 {
  6877. // if stockConfig.IsOpen == 1 {
  6878. // if project.Type == 3 {
  6879. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6880. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6881. // good.Total = good.Total - f_count
  6882. // service.UpdateGoodInfo(&good)
  6883. // }
  6884. // }
  6885. //
  6886. //} else {
  6887. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6888. //
  6889. // if stockConfig.IsOpen == 1 {
  6890. // if project.Type == 3 {
  6891. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6892. // if project.Count < temp_project.Count {
  6893. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6894. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6895. //
  6896. // other_count := f_count_two - f_count_one
  6897. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6898. // good.Total = good.Total + other_count_two
  6899. // service.UpdateGoodInfo(&good)
  6900. // } else if project.Count > temp_project.Count {
  6901. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6902. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6903. //
  6904. // other_count := f_count_one - f_count_two
  6905. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6906. // good.Total = good.Total - other_count_two
  6907. // service.UpdateGoodInfo(&good)
  6908. // }
  6909. //
  6910. // }
  6911. // }
  6912. //
  6913. //}
  6914. return 0
  6915. }
  6916. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6917. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6918. id := int64(json["id"].(float64))
  6919. additionalCharge.ID = id
  6920. }
  6921. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6922. item_id := int64(json["item_id"].(float64))
  6923. additionalCharge.ItemId = item_id
  6924. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6925. if config.ID > 0 {
  6926. if len(config.Code) > 0 {
  6927. additionalCharge.MedListCodg = config.Code
  6928. }
  6929. }
  6930. }
  6931. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6932. // price := int64(json["price"].(float64))
  6933. // formatInt_price := strconv.FormatInt(price, 10)
  6934. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6935. // additionalCharge.Price = float_price
  6936. // }
  6937. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6938. // price := int64(json["price"].(float64))
  6939. // formatInt_price := strconv.FormatInt(price, 10)
  6940. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6941. // additionalCharge.Price = float_price
  6942. //}
  6943. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6944. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6945. additionalCharge.Price = price
  6946. }
  6947. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6948. count, _ := json["count"].(string)
  6949. counts, _ := strconv.ParseInt(count, 10, 64)
  6950. additionalCharge.Count = counts
  6951. }
  6952. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6953. item_name, _ := json["item_name"].(string)
  6954. additionalCharge.ItemName = item_name
  6955. }
  6956. return 0
  6957. }
  6958. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6959. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6960. utils.ErrorLog("drug_name")
  6961. return enums.ErrorCodeParamWrong
  6962. }
  6963. adviceName, _ := json["drug_name"].(string)
  6964. if len(adviceName) == 0 {
  6965. utils.ErrorLog("len(advice_name) == 0")
  6966. return enums.ErrorCodeParamWrong
  6967. }
  6968. advice.AdviceName = adviceName
  6969. adviceDesc, _ := json["advice_desc"].(string)
  6970. advice.AdviceDesc = adviceDesc
  6971. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6972. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6973. advice.DrugSpec = drugSpec
  6974. }
  6975. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6976. remark, _ := json["remark"].(string)
  6977. advice.Remark = remark
  6978. }
  6979. if json["id"] == nil {
  6980. advice.DrugId = 0
  6981. } else {
  6982. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6983. drug_id := int64(json["id"].(float64))
  6984. advice.DrugId = drug_id
  6985. }
  6986. }
  6987. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6988. groupno := int64(json["groupno"].(float64))
  6989. advice.Groupno = groupno
  6990. }
  6991. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6992. drugSpecUnit, _ := json["min_unit"].(string)
  6993. advice.DrugSpecUnit = drugSpecUnit
  6994. }
  6995. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6996. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6997. advice.SingleDose = singleDose
  6998. }
  6999. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7000. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7001. advice.SingleDoseUnit = singleDoseUnit
  7002. }
  7003. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7004. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7005. advice.PrescribingNumber = prescribingNumber
  7006. }
  7007. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7008. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7009. advice.PrescribingNumberUnit = prescribingNumberUnit
  7010. }
  7011. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7012. deliveryWay, _ := json["delivery_way"].(string)
  7013. advice.DeliveryWay = deliveryWay
  7014. }
  7015. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7016. executionFrequency, _ := json["execution_frequency"].(string)
  7017. advice.ExecutionFrequency = executionFrequency
  7018. }
  7019. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7020. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7021. advice.Price = price
  7022. }
  7023. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7024. med_list_codg, _ := json["medical_insurance_number"].(string)
  7025. advice.MedListCodg = med_list_codg
  7026. }
  7027. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7028. day := int64(json["day"].(float64))
  7029. advice.Day = day
  7030. }
  7031. advice.FrequencyType = 1
  7032. return 0
  7033. }
  7034. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7035. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7036. types := int64(json["type"].(float64))
  7037. project.Type = types
  7038. }
  7039. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7040. project_id := int64(json["project_id"].(float64))
  7041. project.ProjectId = project_id
  7042. }
  7043. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7044. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7045. project.Price = price
  7046. }
  7047. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7048. total, _ := json["total"].(string)
  7049. //totals, _ := strconv.ParseInt(total, 10, 64)
  7050. project.Count = total
  7051. }
  7052. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7053. medical_code, _ := json["medical_code"].(string)
  7054. project.MedListCodg = medical_code
  7055. }
  7056. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7057. single_dose, _ := json["single_dose"].(string)
  7058. project.SingleDose = single_dose
  7059. }
  7060. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7061. delivery_way, _ := json["delivery_way"].(string)
  7062. project.DeliveryWay = delivery_way
  7063. }
  7064. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7065. execution_frequency, _ := json["execution_frequency"].(string)
  7066. project.ExecutionFrequency = execution_frequency
  7067. }
  7068. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7069. remark, _ := json["remark"].(string)
  7070. project.Remark = remark
  7071. }
  7072. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7073. day, _ := json["number_days"].(string)
  7074. project.Day = day
  7075. }
  7076. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7077. unit, _ := json["unit"].(string)
  7078. project.Unit = unit
  7079. }
  7080. project.FrequencyType = 1
  7081. return 0
  7082. }
  7083. func (c *HisApiController) GetHisOrderListTwo() {
  7084. start_time := c.GetString("start_time")
  7085. end_time := c.GetString("end_time")
  7086. timeLayout := "2006-01-02"
  7087. loc, _ := time.LoadLocation("Local")
  7088. var startTime int64
  7089. if len(start_time) > 0 {
  7090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7091. if err != nil {
  7092. //fmt.Println(err)
  7093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7094. return
  7095. }
  7096. startTime = theTime.Unix()
  7097. }
  7098. var endTime int64
  7099. if len(end_time) > 0 {
  7100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7101. if err != nil {
  7102. utils.ErrorLog(err.Error())
  7103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7104. return
  7105. }
  7106. endTime = theTime.Unix()
  7107. }
  7108. adminUser := c.GetAdminUserInfo()
  7109. org_id := adminUser.CurrentOrgId
  7110. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7111. if err == nil {
  7112. c.ServeSuccessJSON(map[string]interface{}{
  7113. "order2": order,
  7114. })
  7115. } else {
  7116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7117. return
  7118. }
  7119. }
  7120. func (c *HisApiController) GetHisOrderList() {
  7121. page, _ := c.GetInt64("page", -1)
  7122. limit, _ := c.GetInt64("limit", -1)
  7123. start_time := c.GetString("start_time")
  7124. end_time := c.GetString("end_time")
  7125. types, _ := c.GetInt64("type", 0)
  7126. keywords := c.GetString("keywords")
  7127. p_type, _ := c.GetInt64("p_type", 0)
  7128. sort_type, _ := c.GetInt64("sort_type", 0)
  7129. charge_type, _ := c.GetInt64("charge_type", 0)
  7130. sch_type, _ := c.GetInt64("sch_type", 0)
  7131. zone_type, _ := c.GetInt64("zone_type", 0)
  7132. med_type, _ := c.GetInt64("med_type", 0)
  7133. timeLayout := "2006-01-02"
  7134. loc, _ := time.LoadLocation("Local")
  7135. var startTime int64
  7136. if len(start_time) > 0 {
  7137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7138. if err != nil {
  7139. //fmt.Println(err)
  7140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7141. return
  7142. }
  7143. startTime = theTime.Unix()
  7144. }
  7145. var endTime int64
  7146. if len(end_time) > 0 {
  7147. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7148. if err != nil {
  7149. utils.ErrorLog(err.Error())
  7150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7151. return
  7152. }
  7153. endTime = theTime.Unix()
  7154. }
  7155. adminUser := c.GetAdminUserInfo()
  7156. org_id := adminUser.CurrentOrgId
  7157. 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)
  7158. for _, item := range order {
  7159. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7160. item.DoctorName = info.Doctor
  7161. item.DepartmentName = info.XtHisDepartment.Name
  7162. }
  7163. if err == nil {
  7164. c.ServeSuccessJSON(map[string]interface{}{
  7165. "order": order,
  7166. "total": total,
  7167. })
  7168. } else {
  7169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7170. return
  7171. }
  7172. }
  7173. func (c *HisApiController) GetHisOrder() {
  7174. patient_id, _ := c.GetInt64("patient_id", 0)
  7175. number := c.GetString("number")
  7176. adminInfo := c.GetAdminUserInfo()
  7177. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7178. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7179. if err == nil {
  7180. c.ServeSuccessJSON(map[string]interface{}{
  7181. "order": order,
  7182. "prescription": prescriptions,
  7183. })
  7184. } else {
  7185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7186. return
  7187. }
  7188. }
  7189. func (c *HisApiController) GetHisPrescriptionList() {
  7190. record_date := c.GetString("record_date")
  7191. keywords := c.GetString("keywords")
  7192. page, _ := c.GetInt64("page")
  7193. limit, _ := c.GetInt64("limit")
  7194. sch_type, _ := c.GetInt64("sch_type")
  7195. timeLayout := "2006-01-02"
  7196. loc, _ := time.LoadLocation("Local")
  7197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7198. if err != nil {
  7199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7200. return
  7201. }
  7202. recordDateTime := theTime.Unix()
  7203. adminInfo := c.GetAdminUserInfo()
  7204. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7205. //adminInfo := c.GetAdminUserInfo()
  7206. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7207. //fmt.Println(prescriptionOrder)
  7208. if err == nil {
  7209. c.ServeSuccessJSON(map[string]interface{}{
  7210. "order": prescriptionOrder,
  7211. "total": total,
  7212. })
  7213. } else {
  7214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7215. return
  7216. }
  7217. }
  7218. func (c *HisApiController) GetHisPrescriptionInfo() {
  7219. id, _ := c.GetInt64("id")
  7220. adminInfo := c.GetAdminUserInfo()
  7221. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7222. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7223. if err == nil {
  7224. c.ServeSuccessJSON(map[string]interface{}{
  7225. "order": prescriptionOrder,
  7226. "prescription": prescription,
  7227. })
  7228. } else {
  7229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7230. return
  7231. }
  7232. }
  7233. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7234. adminUser := c.GetAdminUserInfo()
  7235. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7236. c.ServeSuccessJSON(map[string]interface{}{
  7237. "config": config,
  7238. })
  7239. }
  7240. type ResultTwo struct {
  7241. ErrMsg interface{} `json:"err_msg"`
  7242. InfRefmsgid string `json:"inf_refmsgid"`
  7243. Infcode int64 `json:"infcode"`
  7244. Output struct {
  7245. Baseinfo struct {
  7246. Age float64 `json:"age"`
  7247. Brdy string `json:"brdy"`
  7248. Certno string `json:"certno"`
  7249. Gend string `json:"gend"`
  7250. Naty string `json:"naty"`
  7251. PsnCertType string `json:"psn_cert_type"`
  7252. PsnName string `json:"psn_name"`
  7253. PsnNo string `json:"psn_no"`
  7254. } `json:"baseinfo"`
  7255. Idetinfo []interface{} `json:"idetinfo"`
  7256. Iinfo []struct {
  7257. Balc float64 `json:"balc"`
  7258. CvlservFlag string `json:"cvlserv_flag"`
  7259. EmpName string `json:"emp_name"`
  7260. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7261. Insutype string `json:"insutype"`
  7262. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7263. PausInsuDate interface{} `json:"paus_insu_date"`
  7264. PsnInsuDate string `json:"psn_insu_date"`
  7265. PsnInsuStas string `json:"psn_insu_stas"`
  7266. PsnType string `json:"psn_type"`
  7267. } `json:"insuinfo"`
  7268. } `json:"output"`
  7269. RefmsgTime string `json:"refmsg_time"`
  7270. RespondTime string `json:"respond_time"`
  7271. Signtype interface{} `json:"signtype"`
  7272. WarnInfo interface{} `json:"warn_info"`
  7273. }
  7274. type ResultThree struct {
  7275. Cainfo interface{} `json:"cainfo"`
  7276. ErrMsg interface{} `json:"err_msg"`
  7277. InfRefmsgid string `json:"inf_refmsgid"`
  7278. Infcode int64 `json:"infcode"`
  7279. Output struct {
  7280. Data struct {
  7281. IptOtpNo string `json:"ipt_otp_no"`
  7282. MdtrtID string `json:"mdtrt_id"`
  7283. PsnNo string `json:"psn_no"`
  7284. } `json:"data"`
  7285. } `json:"output"`
  7286. RefmsgTime string `json:"refmsg_time"`
  7287. RespondTime string `json:"respond_time"`
  7288. Signtype interface{} `json:"signtype"`
  7289. WarnMsg interface{} `json:"warn_msg"`
  7290. }
  7291. type ResultFour struct {
  7292. Cainfo string `json:"cainfo"`
  7293. ErrMsg string `json:"err_msg"`
  7294. InfRefmsgid string `json:"inf_refmsgid"`
  7295. Infcode int64 `json:"infcode"`
  7296. Output struct {
  7297. Result []struct {
  7298. BasMednFlag string `json:"bas_medn_flag"`
  7299. ChldMedcFlag string `json:"chld_medc_flag"`
  7300. ChrgitmLv string `json:"chrgitm_lv"`
  7301. Cnt float64 `json:"cnt"`
  7302. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7303. DrtReimFlag string `json:"drt_reim_flag"`
  7304. FeedetlSn string `json:"feedetl_sn"`
  7305. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7306. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7307. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7308. ListSpItemFlag string `json:"list_sp_item_flag"`
  7309. LmtUsedFlag string `json:"lmt_used_flag"`
  7310. MedChrgitmType string `json:"med_chrgitm_type"`
  7311. Memo string `json:"memo"`
  7312. OverlmtAmt float64 `json:"overlmt_amt"`
  7313. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7314. Pric float64 `json:"pric"`
  7315. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7316. SelfpayProp float64 `json:"selfpay_prop"`
  7317. } `json:"result"`
  7318. } `json:"output"`
  7319. RefmsgTime string `json:"refmsg_time"`
  7320. RespondTime string `json:"respond_time"`
  7321. Signtype string `json:"signtype"`
  7322. WarnMsg string `json:"warn_msg"`
  7323. }
  7324. type ResultFive struct {
  7325. Insutype string `json:"insutype"`
  7326. }
  7327. type ResultSix struct {
  7328. Cainfo interface{} `json:"cainfo"`
  7329. ErrMsg interface{} `json:"err_msg"`
  7330. InfRefmsgid string `json:"inf_refmsgid"`
  7331. Infcode int64 `json:"infcode"`
  7332. Output struct {
  7333. } `json:"output"`
  7334. RefmsgTime string `json:"refmsg_time"`
  7335. RespondTime string `json:"respond_time"`
  7336. Signtype interface{} `json:"signtype"`
  7337. WarnMsg interface{} `json:"warn_msg"`
  7338. }
  7339. type ResultSeven struct {
  7340. Cainfo string `json:"cainfo"`
  7341. ErrMsg string `json:"err_msg"`
  7342. InfRefmsgid string `json:"inf_refmsgid"`
  7343. Infcode int64 `json:"infcode"`
  7344. Output struct {
  7345. Setldetail []interface{} `json:"setldetail"`
  7346. Setlinfo struct {
  7347. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7348. AcctPay float64 `json:"acct_pay"`
  7349. ActPayDedc float64 `json:"act_pay_dedc"`
  7350. Age float64 `json:"age"`
  7351. Balc float64 `json:"balc"`
  7352. Brdy string `json:"brdy"`
  7353. Certno string `json:"certno"`
  7354. ClrOptins string `json:"clr_optins"`
  7355. ClrType string `json:"clr_type"`
  7356. ClrWay string `json:"clr_way"`
  7357. CvlservFlag string `json:"cvlserv_flag"`
  7358. CvlservPay float64 `json:"cvlserv_pay"`
  7359. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7360. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7361. Gend string `json:"gend"`
  7362. HifesPay float64 `json:"hifes_pay"`
  7363. HifmiPay float64 `json:"hifmi_pay"`
  7364. HifobPay float64 `json:"hifob_pay"`
  7365. HifpPay float64 `json:"hifp_pay"`
  7366. HospPartAmt float64 `json:"hosp_part_amt"`
  7367. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7368. Insutype string `json:"insutype"`
  7369. MafPay float64 `json:"maf_pay"`
  7370. MdtrtCertType string `json:"mdtrt_cert_type"`
  7371. MdtrtID string `json:"mdtrt_id"`
  7372. MedType string `json:"med_type"`
  7373. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7374. MedinsSetlID string `json:"medins_setl_id"`
  7375. Naty string `json:"naty"`
  7376. OthPay float64 `json:"oth_pay"`
  7377. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7378. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7379. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7380. PsnCashPay float64 `json:"psn_cash_pay"`
  7381. PsnCertType string `json:"psn_cert_type"`
  7382. PsnName string `json:"psn_name"`
  7383. PsnNo string `json:"psn_no"`
  7384. PsnPartAmt float64 `json:"psn_part_amt"`
  7385. PsnType string `json:"psn_type"`
  7386. SetlID string `json:"setl_id"`
  7387. SetlTime string `json:"setl_time"`
  7388. } `json:"setlinfo"`
  7389. } `json:"output"`
  7390. RefmsgTime string `json:"refmsg_time"`
  7391. RespondTime string `json:"respond_time"`
  7392. Signtype interface{} `json:"signtype"`
  7393. WarnMsg interface{} `json:"warn_msg"`
  7394. }
  7395. type ResultEight struct {
  7396. Cainfo string `json:"cainfo"`
  7397. ErrMsg string `json:"err_msg"`
  7398. InfRefmsgid string `json:"inf_refmsgid"`
  7399. Infcode int64 `json:"infcode"`
  7400. Output struct {
  7401. Stmtinfo struct {
  7402. SetlOptins string `json:"setl_optins"`
  7403. StmtRslt string `json:"stmt_rslt"`
  7404. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7405. } `json:"stmtinfo"`
  7406. } `json:"output"`
  7407. RefmsgTime string `json:"refmsg_time"`
  7408. RespondTime string `json:"respond_time"`
  7409. Signtype interface{} `json:"signtype"`
  7410. WarnMsg interface{} `json:"warn_msg"`
  7411. }
  7412. type ResultNine struct {
  7413. Cainfo string `json:"cainfo"`
  7414. ErrMsg string `json:"err_msg"`
  7415. InfRefmsgid string `json:"inf_refmsgid"`
  7416. Infcode int64 `json:"infcode"`
  7417. Output struct {
  7418. FileQuryNo string `json:"file_qury_no"`
  7419. } `json:"output"`
  7420. RefmsgTime string `json:"refmsg_time"`
  7421. RespondTime string `json:"respond_time"`
  7422. Signtype interface{} `json:"signtype"`
  7423. WarnMsg interface{} `json:"warn_msg"`
  7424. }
  7425. type ResultTen struct {
  7426. Cainfo string `json:"cainfo"`
  7427. ErrMsg string `json:"err_msg"`
  7428. InfRefmsgid string `json:"inf_refmsgid"`
  7429. Infcode int64 `json:"infcode"`
  7430. Output struct {
  7431. DldEndtime string `json:"dld_endtime"`
  7432. FileQuryNo string `json:"file_qury_no"`
  7433. Filename string `json:"filename"`
  7434. } `json:"output"`
  7435. RefmsgTime string `json:"refmsg_time"`
  7436. RespondTime string `json:"respond_time"`
  7437. Signtype interface{} `json:"signtype"`
  7438. WarnMsg interface{} `json:"warn_msg"`
  7439. }
  7440. type ResultEleven struct {
  7441. Cainfo string `json:"cainfo"`
  7442. ErrMsg string `json:"err_msg"`
  7443. InfRefmsgid string `json:"inf_refmsgid"`
  7444. Infcode int64 `json:"infcode"`
  7445. Output struct {
  7446. Setlinfo struct {
  7447. FixmedinsName string `json:"fixmedins_name"`
  7448. FixmedinsCode string `json:"fixmedins_code"`
  7449. PsnNo string `json:"psn_no"`
  7450. PsnName string `json:"psn_name"`
  7451. HifobPay float64 `json:"hifob_pay"`
  7452. Gend string `json:"gend"`
  7453. Brdy string `json:"brdy"`
  7454. PsnCertType string `json:"psn_cert_type"`
  7455. PsnType string `json:"psn_type"`
  7456. EmpName string `json:"emp_name"`
  7457. Certno string `json:"certno"`
  7458. Insutype string `json:"insutype"`
  7459. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7460. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7461. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7462. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7463. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7464. ActPayDedc float64 `json:"act_pay_dedc"`
  7465. HifpPay float64 `json:"hifp_pay"`
  7466. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7467. CvlservPay float64 `json:"cvlserv_pay"`
  7468. HifesPay float64 `json:"hifes_pay"`
  7469. HifmiPay float64 `json:"hifmi_pay"`
  7470. MafPay float64 `json:"maf_pay"`
  7471. OthPay float64 `json:"oth_pay"`
  7472. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7473. PsnPay float64 `json:"psn_pay"`
  7474. AcctPay float64 `json:"acct_pay"`
  7475. CashPayamt float64 `json:"cash_payamt"`
  7476. Balc float64 `json:"balc"`
  7477. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7478. MedinsSetlId string `json:"medins_setl_id"`
  7479. RefdSetlFlag string `json:"refd_setl_flag"`
  7480. SetlTime string `json:"setl_time"`
  7481. MedType string `json:"med_type"`
  7482. } `json:"setlinfo"`
  7483. } `json:"output"`
  7484. RefmsgTime string `json:"refmsg_time"`
  7485. RespondTime string `json:"respond_time"`
  7486. Signtype interface{} `json:"signtype"`
  7487. WarnMsg interface{} `json:"warn_msg"`
  7488. }
  7489. type Custom struct {
  7490. DetItemFeeSumamt string
  7491. Cut string
  7492. FeedetlSn string
  7493. Price string
  7494. MedListCodg string
  7495. Type int64
  7496. AdviceId int64
  7497. ProjectId int64
  7498. ItemId int64
  7499. }
  7500. // 获取个人信息----挂号-----上传就诊信息
  7501. func (c *HisApiController) GetRegisterInfo() {
  7502. id, _ := c.GetInt64("id")
  7503. record_time := c.GetString("record_time")
  7504. settlementValue, _ := c.GetInt64("settlement_value")
  7505. medical_insurance_card := c.GetString("medical_insurance_card")
  7506. name := c.GetString("name")
  7507. id_card_type, _ := c.GetInt64("id_card_type")
  7508. certificates, _ := c.GetInt64("certificates")
  7509. medical_care, _ := c.GetInt64("medical_care")
  7510. birthday := c.GetString("birthday")
  7511. age, _ := c.GetInt64("age")
  7512. id_card := c.GetString("id_card")
  7513. register_type, _ := c.GetInt64("register")
  7514. doctor, _ := c.GetInt64("doctor")
  7515. department, _ := c.GetInt64("department")
  7516. gender, _ := c.GetInt64("sex")
  7517. phone := c.GetString("phone")
  7518. registration_fee, _ := c.GetFloat("registration_fee")
  7519. medical_expenses, _ := c.GetFloat("medical_expenses")
  7520. social_type, _ := c.GetInt64("social_type")
  7521. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7522. diagnosis_ids := c.GetString("diagnosis")
  7523. sick_type, _ := c.GetInt64("sick_type")
  7524. reg_type := c.GetString("p_type")
  7525. timeLayout := "2006-01-02"
  7526. loc, _ := time.LoadLocation("Local")
  7527. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7528. birthUnix := birthdays.Unix()
  7529. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7530. if err != nil {
  7531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7532. return
  7533. }
  7534. recordDateTime := theTime.Unix()
  7535. adminInfo := c.GetAdminUserInfo()
  7536. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7537. if tempPatient.ID == 0 {
  7538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7539. return
  7540. }
  7541. var patient service.Patients
  7542. if id == 0 {
  7543. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7544. } else {
  7545. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7546. }
  7547. if patient.ID == 0 {
  7548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7549. return
  7550. }
  7551. if len(patient.IdCardNo) == 0 {
  7552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7553. return
  7554. }
  7555. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7556. if len(his) >= 1 {
  7557. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7558. if len(his) >= 1 && order.ID == 0 {
  7559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7560. return
  7561. }
  7562. }
  7563. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7564. fmt.Println(timeStr)
  7565. timeArr := strings.Split(timeStr, " ")
  7566. fmt.Println(timeArr)
  7567. timeArrTwo := strings.Split(timeArr[0], "-")
  7568. timeArrThree := strings.Split(timeArr[1], ":")
  7569. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7570. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7571. if len(lists) == 0 {
  7572. var hisPatient models.XtHisPatient
  7573. hisPatient = models.XtHisPatient{
  7574. Name: name,
  7575. Age: age,
  7576. Gender: gender,
  7577. Birthday: birthUnix,
  7578. Phone: phone,
  7579. MedicalTreatmentType: medical_care,
  7580. IdType: certificates,
  7581. IdCardNo: id_card,
  7582. BalanceAccountsType: settlementValue,
  7583. SocialType: social_type,
  7584. MedicalInsuranceNumber: medical_insurance_card,
  7585. RegisterType: register_type,
  7586. RegisterCost: registration_fee,
  7587. TreatmentCost: medical_expenses,
  7588. AdminUserId: adminInfo.AdminUser.Id,
  7589. UserOrgId: adminInfo.CurrentOrgId,
  7590. Status: 1,
  7591. RecordDate: recordDateTime,
  7592. IsReturn: 1,
  7593. PatientId: patient.ID,
  7594. Ctime: time.Now().Unix(),
  7595. Mtime: time.Now().Unix(),
  7596. Number: str,
  7597. IdCardType: id_card_type,
  7598. Departments: department,
  7599. Doctor: doctor,
  7600. PType: reg_type,
  7601. Diagnosis: diagnosis_ids,
  7602. SickType: sick_type,
  7603. }
  7604. service.CreateHisPatient(&hisPatient)
  7605. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7606. c.ServeSuccessJSON(map[string]interface{}{
  7607. "his_info": hisPatient,
  7608. })
  7609. } else {
  7610. //chrgBchno := rand.Intn(1000000) + 10000
  7611. var hisPatient models.XtHisPatient
  7612. hisPatient = models.XtHisPatient{
  7613. Name: name,
  7614. Age: age,
  7615. Gender: gender,
  7616. Birthday: birthUnix,
  7617. Phone: phone,
  7618. MedicalTreatmentType: medical_care,
  7619. IdType: certificates,
  7620. IdCardNo: id_card,
  7621. BalanceAccountsType: settlementValue,
  7622. SocialType: social_type,
  7623. MedicalInsuranceNumber: medical_insurance_card,
  7624. RegisterType: register_type,
  7625. RegisterCost: registration_fee,
  7626. TreatmentCost: medical_expenses,
  7627. AdminUserId: adminInfo.AdminUser.Id,
  7628. UserOrgId: adminInfo.CurrentOrgId,
  7629. Status: 1,
  7630. RecordDate: recordDateTime,
  7631. IsReturn: 1,
  7632. PatientId: patient.ID,
  7633. Ctime: time.Now().Unix(),
  7634. Mtime: time.Now().Unix(),
  7635. Number: str,
  7636. IdCardType: id_card_type,
  7637. Departments: department,
  7638. Doctor: doctor,
  7639. PType: reg_type,
  7640. Diagnosis: diagnosis_ids,
  7641. SickType: sick_type,
  7642. }
  7643. service.CreateHisPatient(&hisPatient)
  7644. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7645. c.ServeSuccessJSON(map[string]interface{}{
  7646. "his_info": hisPatient,
  7647. })
  7648. }
  7649. }
  7650. // 上传明细----结算
  7651. func (c *HisApiController) GetUploadInfo() {
  7652. id, _ := c.GetInt64("id")
  7653. record_time := c.GetString("record_time")
  7654. his_patient_id, _ := c.GetInt64("his_patient_id")
  7655. oth_desc := c.GetString("oth_desc")
  7656. pay_way, _ := c.GetInt64("pay_way")
  7657. pay_ways := c.GetString("pay_ways")
  7658. pay_price, _ := c.GetFloat("pay_price")
  7659. pay_card_no := c.GetString("pay_card_no")
  7660. discount_price, _ := c.GetFloat("discount_price")
  7661. preferential_price, _ := c.GetFloat("preferential_price")
  7662. reality_price, _ := c.GetFloat("reality_price")
  7663. found_price, _ := c.GetFloat("found_price")
  7664. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7665. private_price, _ := c.GetFloat("private_price")
  7666. timeLayout := "2006-01-02"
  7667. loc, _ := time.LoadLocation("Local")
  7668. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7669. fapiao_code := c.GetString("fapiao_code")
  7670. fapiao_number := c.GetString("fapiao_number")
  7671. diagnosis_id := c.GetString("diagnosis")
  7672. sick_type, _ := c.GetInt64("sick_type")
  7673. reg_type, _ := c.GetInt64("p_type")
  7674. order_id, _ := c.GetInt64("order_id")
  7675. cash_pay := c.GetString("cash_pay")
  7676. wechat_pay := c.GetString("wechat_pay")
  7677. ali_pay := c.GetString("ali_pay")
  7678. jifen_pay := c.GetString("jifen_pay")
  7679. band_card_pay := c.GetString("band_card_pay")
  7680. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7681. tmp_decimal := c.GetString("tmp_decimal")
  7682. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7683. var decimal float64 //本次使用的押金
  7684. var errmsg error
  7685. tx := service.XTWriteDB().Begin() //开了事务
  7686. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7687. defer func() {
  7688. if errmsg != nil {
  7689. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7690. tx.Rollback()
  7691. } else {
  7692. tx.Commit()
  7693. }
  7694. }()
  7695. fmt.Println("dec_way", dec_way)
  7696. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7697. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7698. return
  7699. }
  7700. if len(tmp_decimal) > 0 {
  7701. if tmp_decimal[0] == 45 {
  7702. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7703. return
  7704. }
  7705. }
  7706. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7707. fmt.Println(errs)
  7708. decimal = tt
  7709. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7710. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7712. if err != nil {
  7713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7714. return
  7715. }
  7716. recordDateTime := theTime.Unix()
  7717. adminUser := c.GetAdminUserInfo()
  7718. var prescriptions []*models.HisPrescription
  7719. var prescriptionsOne []*models.HisPrescription
  7720. var start_time int64
  7721. var end_time int64
  7722. ids_str := c.GetString("ids")
  7723. ids_arr := strings.Split(ids_str, ",")
  7724. if tempOrder.ID == 0 {
  7725. if settle_accounts_type == 1 { //日结
  7726. fmt.Println(reg_type)
  7727. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7728. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7729. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7730. } else {
  7731. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7732. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7733. }
  7734. } else { //月结
  7735. start_time_str := c.GetString("start_time")
  7736. end_time_str := c.GetString("end_time")
  7737. timeLayout := "2006-01-02"
  7738. loc, _ := time.LoadLocation("Local")
  7739. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7740. if err != nil {
  7741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7742. return
  7743. }
  7744. recordStartTime := theStartTime.Unix()
  7745. start_time = recordStartTime
  7746. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7747. if err != nil {
  7748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7749. return
  7750. }
  7751. recordEndTime := theEndTime.Unix()
  7752. end_time = recordEndTime
  7753. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7754. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7755. }
  7756. var goods []*models.DialysisBeforePrepareGoods
  7757. var newGoods []*models.NewDialysisBeforePrepareGoods
  7758. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7759. var infos []*models.HisDoctorAdviceInfo
  7760. var infoList []*models.HisDoctorAdviceInfo
  7761. var hisAdvice []*models.HisDoctorAdviceInfo
  7762. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7763. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7764. //判断库存不足
  7765. //结算出库开关
  7766. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7767. if settConfig.IsOpen == 1 {
  7768. //判断库存的地方
  7769. for _, info := range prescriptions {
  7770. if info.Type == 1 {
  7771. infos = append(infos, info.HisDoctorAdviceInfo...)
  7772. }
  7773. if info.Type == 2 {
  7774. for _, sumItem := range info.HisPrescriptionProject {
  7775. if sumItem.Type == 3 {
  7776. var good models.DialysisBeforePrepareGoods
  7777. var newGood models.NewDialysisBeforePrepareGoods
  7778. good.GoodId = sumItem.GoodInfo.ID
  7779. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7780. count, _ := strconv.Atoi(sumItem.Count)
  7781. good.Count = int64(count)
  7782. good.StorehouseId = houseConfig.StorehouseOutInfo
  7783. good.ProjectId = sumItem.ID
  7784. goods = append(goods, &good)
  7785. newGood.GoodId = sumItem.GoodInfo.ID
  7786. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7787. count2, _ := strconv.Atoi(sumItem.Count)
  7788. newGood.Count = int64(count2)
  7789. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7790. newGood.ProjectId = sumItem.ID
  7791. newGoods = append(newGoods, &newGood)
  7792. }
  7793. }
  7794. }
  7795. }
  7796. for _, info := range prescriptionsOne {
  7797. if info.Type == 1 {
  7798. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7799. }
  7800. if info.Type == 2 {
  7801. for _, sumItem := range info.HisPrescriptionProject {
  7802. if sumItem.Type == 3 {
  7803. var newGood models.NewDialysisBeforePrepareGoods
  7804. newGood.GoodId = sumItem.GoodInfo.ID
  7805. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7806. count2, _ := strconv.Atoi(sumItem.Count)
  7807. newGood.Count = int64(count2)
  7808. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7809. newGood.ProjectId = sumItem.ID
  7810. newGoodOne = append(newGoodOne, &newGood)
  7811. }
  7812. }
  7813. }
  7814. }
  7815. //判断
  7816. for _, itemOne := range infos {
  7817. for _, itemTwo := range hisAdvice {
  7818. if itemOne.DrugId == itemTwo.DrugId {
  7819. itemTwo.Child = append(itemTwo.Child, itemOne)
  7820. }
  7821. }
  7822. }
  7823. for _, itemTwo := range hisAdvice {
  7824. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7825. var sum_out_count int64
  7826. for _, itemThree := range itemTwo.Child {
  7827. var prescribing_number int64
  7828. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7829. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7830. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7831. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7832. }
  7833. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7834. prescribing_number = parseIntPrescribingNumber
  7835. }
  7836. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7837. prescribing_number = parseIntPrescribingNumber
  7838. }
  7839. sum_out_count += prescribing_number
  7840. }
  7841. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7842. if sum_out_count > drugStockOut.FlushCount {
  7843. c.ServeSuccessJSON(map[string]interface{}{
  7844. "msg": "2",
  7845. "drug": medical,
  7846. })
  7847. return
  7848. }
  7849. }
  7850. for _, itemOne := range newGoods {
  7851. for _, item := range newGoodOne {
  7852. if itemOne.GoodId == item.GoodId {
  7853. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7854. }
  7855. }
  7856. }
  7857. for _, item := range newGoodOne {
  7858. var sum_out_count_one int64
  7859. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7860. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7861. sum_out_count_one += itemOne.Count
  7862. }
  7863. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7864. fmt.Println("sum_out_count_one", sum_out_count_one)
  7865. fmt.Println("list.FlushCount", list.FlushCount)
  7866. if sum_out_count_one > list.FlushCount {
  7867. c.ServeSuccessJSON(map[string]interface{}{
  7868. "msg": "3",
  7869. "good": good,
  7870. })
  7871. return
  7872. }
  7873. }
  7874. }
  7875. timestamp := time.Now().Unix()
  7876. tempTime := time.Unix(timestamp, 0)
  7877. timeFormat := tempTime.Format("20060102150405")
  7878. chrgBchno := rand.Intn(100000) + 10000
  7879. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7880. strconv.FormatInt(his.PatientId, 10)
  7881. var ids []int64
  7882. for _, item := range prescriptions {
  7883. ids = append(ids, item.ID)
  7884. }
  7885. var total float64
  7886. for _, item := range prescriptions {
  7887. fmt.Println(item)
  7888. if item.Type == 1 { //药品
  7889. for _, subItem := range item.HisDoctorAdviceInfo {
  7890. total = total + (subItem.Price * subItem.PrescribingNumber)
  7891. }
  7892. }
  7893. if item.Type == 2 { //项目
  7894. for _, subItem := range item.HisPrescriptionProject {
  7895. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7896. total = total + (subItem.Price * cnt)
  7897. }
  7898. }
  7899. for _, subItem := range item.HisAdditionalCharge {
  7900. total = total + (subItem.Price * float64(subItem.Count))
  7901. }
  7902. }
  7903. if reg_type == 1111 || reg_type == 1112 {
  7904. reg_type = 11
  7905. }
  7906. tm := time.Unix(time.Now().Unix(), 0)
  7907. allTotal := fmt.Sprintf("%.4f", total)
  7908. totals, _ := strconv.ParseFloat(allTotal, 64)
  7909. order := &models.HisOrder{
  7910. UserOrgId: adminUser.CurrentOrgId,
  7911. HisPatientId: his.ID,
  7912. PatientId: id,
  7913. SettleAccountsDate: recordDateTime,
  7914. Ctime: time.Now().Unix(),
  7915. Mtime: time.Now().Unix(),
  7916. Status: 1,
  7917. OrderStatus: 2,
  7918. MdtrtId: his.Number,
  7919. Number: chrg_bchno,
  7920. MedfeeSumamt: totals,
  7921. PayWay: pay_way,
  7922. PayWays: pay_ways,
  7923. PayPrice: pay_price,
  7924. MedType: strconv.Itoa(int(reg_type)),
  7925. PayCardNo: pay_card_no,
  7926. DiscountPrice: discount_price,
  7927. PreferentialPrice: preferential_price,
  7928. RealityPrice: reality_price,
  7929. FoundPrice: found_price,
  7930. MedicalInsurancePrice: medical_insurance_price,
  7931. PrivatePrice: private_price,
  7932. SettleEndTime: end_time,
  7933. SettleStartTime: start_time,
  7934. PsnPartAmt: totals,
  7935. PsnCashPay: totals,
  7936. SettleType: settle_accounts_type,
  7937. FaPiaoCode: fapiao_code,
  7938. FaPiaoNumber: fapiao_number,
  7939. Diagnosis: diagnosis_id,
  7940. PType: 2,
  7941. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7942. Decimal: decimal,
  7943. OthDesc: oth_desc,
  7944. CashPay: cash_pay,
  7945. WechatPay: wechat_pay,
  7946. AliPay: ali_pay,
  7947. JifenPay: jifen_pay,
  7948. BandCardPay: band_card_pay,
  7949. Creator: adminUser.AdminUser.Id,
  7950. }
  7951. err = service.CreateOrderTX(order, tx)
  7952. if err != nil {
  7953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7954. return
  7955. }
  7956. var customs []*Custom
  7957. for _, item := range prescriptions {
  7958. if item.Type == 1 { //药品a
  7959. for _, subItem := range item.HisDoctorAdviceInfo {
  7960. cus := &Custom{
  7961. AdviceId: subItem.ID,
  7962. ProjectId: 0,
  7963. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7964. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7965. FeedetlSn: subItem.FeedetlSn,
  7966. Price: fmt.Sprintf("%.4f", subItem.Price),
  7967. MedListCodg: subItem.MedListCodg,
  7968. Type: 1,
  7969. }
  7970. customs = append(customs, cus)
  7971. }
  7972. }
  7973. if item.Type == 2 { //项目
  7974. for _, subItem := range item.HisPrescriptionProject {
  7975. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7976. cus := &Custom{
  7977. AdviceId: 0,
  7978. ProjectId: subItem.ID,
  7979. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7980. Cut: fmt.Sprintf("%.4f", cnt),
  7981. FeedetlSn: subItem.FeedetlSn,
  7982. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7983. MedListCodg: subItem.MedListCodg,
  7984. Type: 2,
  7985. }
  7986. customs = append(customs, cus)
  7987. }
  7988. }
  7989. for _, item := range item.HisAdditionalCharge {
  7990. cus := &Custom{
  7991. ItemId: item.ID,
  7992. AdviceId: 0,
  7993. ProjectId: 0,
  7994. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7995. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7996. FeedetlSn: item.FeedetlSn,
  7997. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7998. MedListCodg: item.XtHisAddtionConfig.Code,
  7999. Type: 3,
  8000. }
  8001. customs = append(customs, cus)
  8002. }
  8003. }
  8004. for _, item := range customs {
  8005. var advice_id int64 = 0
  8006. var project_id int64 = 0
  8007. var item_id int64 = 0
  8008. var types int64 = 0
  8009. if item.Type == 1 {
  8010. advice_id = item.AdviceId
  8011. project_id = 0
  8012. item_id = 0
  8013. } else if item.Type == 2 {
  8014. advice_id = 0
  8015. item_id = 0
  8016. project_id = item.ProjectId
  8017. } else if item.Type == 3 {
  8018. advice_id = 0
  8019. item_id = item.ItemId
  8020. project_id = 0
  8021. }
  8022. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8023. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8024. pric, _ := strconv.ParseFloat(item.Price, 32)
  8025. info := &models.HisOrderInfo{
  8026. OrderNumber: order.Number,
  8027. UploadDate: time.Now().Unix(),
  8028. AdviceId: advice_id,
  8029. DetItemFeeSumamt: detItemFeeSumamt,
  8030. Cnt: cut,
  8031. Pric: pric,
  8032. PatientId: id,
  8033. Status: 1,
  8034. Mtime: time.Now().Unix(),
  8035. Ctime: time.Now().Unix(),
  8036. UserOrgId: adminUser.CurrentOrgId,
  8037. HisPatientId: his.ID,
  8038. OrderId: order.ID,
  8039. ProjectId: project_id,
  8040. Type: types,
  8041. ItemId: item_id,
  8042. }
  8043. service.CreateOrderInfoTX(info, tx)
  8044. }
  8045. his.Diagnosis = diagnosis_id
  8046. his.SickType = sick_type
  8047. his.RegisterType = reg_type
  8048. his.MedicalTreatmentType = reg_type
  8049. service.UpdataHisPateintTX(&his, tx)
  8050. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8051. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8052. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8053. //判断是否使用了押金
  8054. if dec_way == "true" {
  8055. tmpstring := strconv.FormatInt(order.ID, 10)
  8056. //扣押金
  8057. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8058. order.Decimal = decimal
  8059. service.UpDateOrderTwo(order, tx)
  8060. if errmsg != nil {
  8061. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8062. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8063. return
  8064. }
  8065. }
  8066. if err == nil {
  8067. for _, info := range prescriptions {
  8068. if info.Type == 1 {
  8069. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8070. }
  8071. if info.Type == 2 {
  8072. for _, sumItem := range info.HisPrescriptionProject {
  8073. if sumItem.Type == 3 {
  8074. var good models.DialysisBeforePrepareGoods
  8075. var newGood models.NewDialysisBeforePrepareGoods
  8076. var oldGood models.OldDialysisBeforePrepareGoods
  8077. good.GoodId = sumItem.GoodInfo.ID
  8078. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8079. count, _ := strconv.Atoi(sumItem.Count)
  8080. good.Count = int64(count)
  8081. good.StorehouseId = houseConfig.StorehouseOutInfo
  8082. good.ProjectId = sumItem.ID
  8083. good.PatientId = sumItem.PatientId
  8084. goods = append(goods, &good)
  8085. newGood.GoodId = sumItem.GoodInfo.ID
  8086. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8087. count2, _ := strconv.Atoi(sumItem.Count)
  8088. newGood.Count = int64(count2)
  8089. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8090. newGood.ProjectId = sumItem.ID
  8091. newGood.PatientId = sumItem.HisPatientId
  8092. newGoods = append(newGoods, &newGood)
  8093. oldGood.GoodId = sumItem.GoodInfo.ID
  8094. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8095. count3, _ := strconv.Atoi(sumItem.Count)
  8096. oldGood.Count = int64(count3)
  8097. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8098. oldGood.ProjectId = sumItem.ID
  8099. oldGood.RecordDate = sumItem.RecordDate
  8100. oldGood.PatientId = sumItem.HisPatientId
  8101. oldGoods = append(oldGoods, &oldGood)
  8102. }
  8103. }
  8104. }
  8105. }
  8106. if settConfig.IsOpen == 1 {
  8107. for _, item := range infoList {
  8108. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8109. if medical.IsUse == 2 {
  8110. //药品出库
  8111. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8112. //查询默认仓库
  8113. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8114. //查询默认仓库剩余多少库存
  8115. var sum_count int64
  8116. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8117. for _, its := range stockInfo {
  8118. if its.MaxUnit == medical.MaxUnit {
  8119. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8120. }
  8121. sum_count += its.StockMaxNumber + its.StockMinNumber
  8122. }
  8123. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8124. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8125. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8126. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8127. }
  8128. }
  8129. orgId := c.GetAdminUserInfo().CurrentOrgId
  8130. if len(oldGoods) > 0 {
  8131. timeStr := time.Now().Format("2006-01-02")
  8132. timeArr := strings.Split(timeStr, "-")
  8133. total, _ := service.FindAllWarehouseOut(orgId)
  8134. total = total + 1
  8135. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8136. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8137. number = number + total
  8138. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8139. operation_time := time.Now().Unix()
  8140. creater := c.GetAdminUserInfo().AdminUser.Id
  8141. //查询默认出库仓库库存
  8142. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8143. recordDateStr := time.Now().Format("2006-01-02")
  8144. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8145. nowtime := recordDate.Unix()
  8146. warehouseOut := models.WarehouseOut{
  8147. WarehouseOutOrderNumber: warehousing_out_order,
  8148. OperationTime: operation_time,
  8149. OrgId: orgId,
  8150. Creater: creater,
  8151. Ctime: time.Now().Unix(),
  8152. Status: 1,
  8153. WarehouseOutTime: nowtime,
  8154. Type: 1,
  8155. StorehouseId: storeConfig.StorehouseOutInfo,
  8156. IsCheck: 1,
  8157. OrderId: order.ID,
  8158. IsSys: 5,
  8159. }
  8160. //查询是否生成出库单
  8161. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8162. if out.ID == 0 {
  8163. service.AddSigleWarehouseOut(&warehouseOut)
  8164. }
  8165. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8166. for _, item := range oldGoods {
  8167. dialyPrepareOne := models.DialysisBeforePrepare{
  8168. GoodTypeId: item.GoodTypeId,
  8169. GoodId: item.GoodId,
  8170. PatientId: his.PatientId,
  8171. RecordDate: item.RecordDate,
  8172. UserOrgId: adminUser.CurrentOrgId,
  8173. Count: item.Count,
  8174. Ctime: time.Now().Unix(),
  8175. Creater: adminUser.AdminUser.Id,
  8176. CommdityCode: item.CommdityCode,
  8177. Status: 1,
  8178. StorehouseId: houseConfig.StorehouseOutInfo,
  8179. }
  8180. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8181. //非零用
  8182. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8183. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8184. //查询剩余库存
  8185. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8186. var sum_count int64
  8187. for _, item := range goodList {
  8188. sum_count += item.StockCount
  8189. }
  8190. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8191. //耗材
  8192. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8193. }
  8194. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8195. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8196. //查询剩余库存
  8197. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8198. var sum_count int64
  8199. for _, item := range goodList {
  8200. sum_count += item.StockCount
  8201. }
  8202. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8203. //耗材
  8204. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8205. }
  8206. }
  8207. }
  8208. }
  8209. c.ServeSuccessJSON(map[string]interface{}{
  8210. "msg": "结算成功",
  8211. })
  8212. }
  8213. }
  8214. }
  8215. // 退款
  8216. func (c *HisApiController) Refund() {
  8217. order_id, _ := c.GetInt64("order_id")
  8218. order, _ := service.GetHisOrderByID(order_id)
  8219. adminUser := c.GetAdminUserInfo()
  8220. orgid := c.GetAdminUserInfo().CurrentOrgId
  8221. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8222. if err != nil {
  8223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8224. return
  8225. }
  8226. tmp := strconv.FormatInt(order.ID, 10)
  8227. //当押金不为零时产生退费记录
  8228. if order.Decimal != 0 {
  8229. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8230. if err != nil {
  8231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8232. return
  8233. }
  8234. }
  8235. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8236. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8237. var goods []*models.DialysisBeforePrepareGoods
  8238. var newGoods []*models.NewDialysisBeforePrepareGoods
  8239. var infos []*models.HisDoctorAdviceInfo
  8240. for _, info := range orders {
  8241. if info.AdviceId > 0 && info.ProjectId == 0 {
  8242. infos = append(infos, &info.HisDoctorAdviceInfo)
  8243. }
  8244. if info.ProjectId > 0 && info.AdviceId == 0 {
  8245. if info.HisPrescriptionProject.Type == 3 {
  8246. var good models.DialysisBeforePrepareGoods
  8247. var newGood models.NewDialysisBeforePrepareGoods
  8248. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8249. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8250. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8251. good.Count = int64(count)
  8252. good.StorehouseId = houseConfig.StorehouseOutInfo
  8253. good.ProjectId = info.HisPrescriptionProject.ID
  8254. good.PatientId = info.PatientId
  8255. good.OrderId = order_id
  8256. goods = append(goods, &good)
  8257. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8258. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8259. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8260. newGood.Count = int64(count2)
  8261. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8262. newGood.ProjectId = info.HisPrescriptionProject.ID
  8263. newGood.RecordDate = order.SettleAccountsDate
  8264. newGood.UserOrgId = order.UserOrgId
  8265. newGood.PatientId = info.PatientId
  8266. newGood.OrderId = order_id
  8267. newGoods = append(newGoods, &newGood)
  8268. }
  8269. }
  8270. }
  8271. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8272. if settConfig.IsOpen == 1 {
  8273. for _, item := range infos {
  8274. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8275. }
  8276. for _, item := range newGoods {
  8277. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8278. }
  8279. }
  8280. c.ServeSuccessJSON(map[string]interface{}{
  8281. "msg": "退费成功",
  8282. })
  8283. }
  8284. func (c *HisApiController) RefundNumber() {
  8285. his_patient_id, _ := c.GetInt64("id")
  8286. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8287. info.Status = 0
  8288. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8289. if count > 0 {
  8290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8291. return
  8292. }
  8293. err := service.SaveHisPatient(info)
  8294. if err == nil {
  8295. c.ServeSuccessJSON(map[string]interface{}{
  8296. "msg": "退号成功",
  8297. })
  8298. } else {
  8299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8300. return
  8301. }
  8302. }
  8303. func (this *HisApiController) AdditionalCharge() {
  8304. dataBody := make(map[string]interface{}, 0)
  8305. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8306. fmt.Println(err)
  8307. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8308. patient_id := int64(dataBody["patient_id"].(float64))
  8309. medicineData, _ := dataBody["medicineData"].([]interface{})
  8310. adminUserInfo := this.GetAdminUserInfo()
  8311. orgId := adminUserInfo.CurrentOrgId
  8312. admin_user_id := adminUserInfo.AdminUser.Id
  8313. timeStr := time.Now().Format("2006-01-02")
  8314. timeLayout := "2006-01-02 15:04:05"
  8315. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8316. timenow := timeStringToTime.Unix()
  8317. var additionalCharges []*models.HisAdditionalCharge
  8318. for _, item := range medicineData {
  8319. var randNum int
  8320. randNum = rand.Intn(10000) + 1000
  8321. timestamp := time.Now().Unix()
  8322. tempTime := time.Unix(timestamp, 0)
  8323. timeFormat := tempTime.Format("20060102150405")
  8324. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8325. items := item.(map[string]interface{})
  8326. money := items["price"].(string)
  8327. item_id_str := items["item_id"].(string)
  8328. name := items["name"].(string)
  8329. id_str := items["id"].(string)
  8330. moneys, _ := strconv.ParseInt(money, 10, 64)
  8331. monStr := strconv.FormatInt(moneys, 10)
  8332. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8333. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8334. id, _ := strconv.ParseInt(id_str, 10, 64)
  8335. additionalCharge := &models.HisAdditionalCharge{
  8336. ID: id,
  8337. HisPatientId: his_patient_id,
  8338. UserOrgId: orgId,
  8339. PatientId: patient_id,
  8340. RecordDate: timenow,
  8341. Price: monneyStr,
  8342. Status: 1,
  8343. ItemName: name,
  8344. ItemId: item_id,
  8345. AdminUserId: admin_user_id,
  8346. CreatedTime: time.Now().Unix(),
  8347. OrderStatus: 0,
  8348. PrescriptionNumber: "",
  8349. BatchNumber: "",
  8350. FeedetlSn: p_number,
  8351. }
  8352. service.CreateAdditionalCharge(additionalCharge)
  8353. additionalCharges = append(additionalCharges, additionalCharge)
  8354. }
  8355. this.ServeSuccessJSON(map[string]interface{}{
  8356. "msg": "添加成功",
  8357. "additional_charges": additionalCharges,
  8358. })
  8359. }
  8360. func (this *HisApiController) DeleteAddition() {
  8361. id, _ := this.GetInt64("id")
  8362. //TODO 需要判断是否已经结算
  8363. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8364. if err == nil {
  8365. this.ServeSuccessJSON(map[string]interface{}{
  8366. "msg": "删除成功",
  8367. })
  8368. return
  8369. } else {
  8370. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8371. return
  8372. }
  8373. }
  8374. func (this *HisApiController) GetAdminUsers() {
  8375. adminUser := this.GetAdminUserInfo()
  8376. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8377. this.ServeSuccessJSON(map[string]interface{}{
  8378. "doctors": doctors,
  8379. })
  8380. }
  8381. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8382. change_type, _ := this.GetInt64("type", 0)
  8383. record_date := this.GetString("record_time")
  8384. patient_id, _ := this.GetInt64("patient_id", 0)
  8385. p_type, _ := this.GetInt64("p_type", 0)
  8386. timeLayout := "2006-01-02"
  8387. loc, _ := time.LoadLocation("Local")
  8388. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8389. record_time := theAdviceRecordTime.Unix()
  8390. adminUserInfo := this.GetAdminUserInfo()
  8391. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8392. if err == nil {
  8393. if len(prescriptions) == 0 {
  8394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8395. return
  8396. } else {
  8397. this.ServeSuccessJSON(map[string]interface{}{
  8398. "prescriptions": prescriptions,
  8399. })
  8400. return
  8401. }
  8402. } else {
  8403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8404. return
  8405. }
  8406. }
  8407. func (this *HisApiController) GetCallHisPrescription() {
  8408. patient_id, _ := this.GetInt64("patient_id", 0)
  8409. timeLayout := "2006-01-02"
  8410. loc, _ := time.LoadLocation("Local")
  8411. start_time := this.GetString("start_time")
  8412. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8413. end_time := this.GetString("end_time")
  8414. p_type, _ := this.GetInt64("p_type")
  8415. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8416. adminUserInfo := this.GetAdminUserInfo()
  8417. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8418. if err == nil {
  8419. this.ServeSuccessJSON(map[string]interface{}{
  8420. "prescriptions": prescriptions,
  8421. })
  8422. return
  8423. } else {
  8424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8425. return
  8426. }
  8427. }
  8428. func (this *HisApiController) GetHisDayPrescription() {
  8429. timeLayout := "2006-01-02"
  8430. loc, _ := time.LoadLocation("Local")
  8431. start_time := this.GetString("start_time")
  8432. patient_id, _ := this.GetInt64("patient_id", 0)
  8433. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8434. end_time := this.GetString("end_time")
  8435. p_type, _ := this.GetInt64("p_type")
  8436. order_status, _ := this.GetInt64("type")
  8437. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8438. adminUserInfo := this.GetAdminUserInfo()
  8439. var dayHisPrescription []*models.HisPrescription
  8440. var err error
  8441. if order_status == 1 || order_status == 0 {
  8442. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8443. } else if order_status == 2 {
  8444. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8445. }
  8446. var settle_total float64
  8447. for _, item := range dayHisPrescription {
  8448. if len(item.HisPrescriptionProject) > 0 {
  8449. for _, subItem := range item.HisPrescriptionProject {
  8450. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8451. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8452. settle_total = settle_total + total
  8453. }
  8454. }
  8455. if len(item.HisDoctorAdviceInfo) > 0 {
  8456. for _, subItem := range item.HisDoctorAdviceInfo {
  8457. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8458. settle_total = settle_total + total
  8459. }
  8460. }
  8461. }
  8462. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8463. if err == nil {
  8464. this.ServeSuccessJSON(map[string]interface{}{
  8465. "day_prescription": dayHisPrescription,
  8466. "settle_total": settle_total,
  8467. })
  8468. return
  8469. } else {
  8470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8471. return
  8472. }
  8473. }
  8474. func (c *HisApiController) GetHisChargePatientList() {
  8475. record_date := c.GetString("record_date")
  8476. order_status, _ := c.GetInt64("type")
  8477. sch_type, _ := c.GetInt64("sch_type")
  8478. timeLayout := "2006-01-02"
  8479. loc, _ := time.LoadLocation("Local")
  8480. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8481. if err != nil {
  8482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8483. return
  8484. }
  8485. recordDateTime := theTime.Unix()
  8486. adminInfo := c.GetAdminUserInfo()
  8487. var tempPatients []*service.NewTempPatients
  8488. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8489. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8490. if order_status != 2 {
  8491. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8492. } else {
  8493. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8494. }
  8495. } else {
  8496. if order_status != 2 {
  8497. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8498. } else {
  8499. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8500. }
  8501. }
  8502. var patients []*service.NewTempPatients
  8503. var patients_two []*service.NewTempPatients
  8504. for _, item := range tempPatients {
  8505. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8506. //过滤掉没挂号的和没开处方的
  8507. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8508. patients = append(patients, item)
  8509. }
  8510. //过滤掉没挂号的
  8511. if len(item.HisPatient) > 0 {
  8512. patients_two = append(patients_two, item)
  8513. }
  8514. } else {
  8515. if len(item.HisPrescription) > 0 {
  8516. patients = append(patients, item)
  8517. }
  8518. }
  8519. }
  8520. c.ServeSuccessJSON(map[string]interface{}{
  8521. "list": patients,
  8522. "list_two": patients_two,
  8523. })
  8524. }
  8525. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8526. record_date := c.GetString("record_date")
  8527. timeLayout := "2006-01-02"
  8528. loc, _ := time.LoadLocation("Local")
  8529. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8530. if err != nil {
  8531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8532. return
  8533. }
  8534. recordDateTime := theTime.Unix()
  8535. adminUser := c.GetAdminUserInfo()
  8536. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8537. var patients []*service.Patients
  8538. for _, item := range tempPatients {
  8539. if item.HisPatient.ID == 0 {
  8540. patients = append(patients, item)
  8541. }
  8542. }
  8543. c.ServeSuccessJSON(map[string]interface{}{
  8544. "list": patients,
  8545. //"list_two": patients_two,
  8546. })
  8547. }
  8548. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8549. newArr = make([]*service.Patients, 0)
  8550. for i := 0; i < len(patient); i++ {
  8551. repeat := false
  8552. for j := i + 1; j < len(patient); j++ {
  8553. if patient[i].ID == patient[j].ID {
  8554. repeat = true
  8555. break
  8556. }
  8557. }
  8558. if !repeat {
  8559. newArr = append(newArr, patient[i])
  8560. }
  8561. }
  8562. return
  8563. }
  8564. func (c *HisApiController) GetHisChargePatientInfo() {
  8565. patient_id, _ := c.GetInt64("patient_id")
  8566. his_patient_id, _ := c.GetInt64("his_patient_id")
  8567. record_date := c.GetString("record_date")
  8568. //start_time := c.GetString("start_time")
  8569. //end_time := c.GetString("end_time")
  8570. order_status, _ := c.GetInt64("type", 0)
  8571. p_type, _ := c.GetInt64("p_type", 0)
  8572. order_id, _ := c.GetInt64("order_id", 0)
  8573. timeLayout := "2006-01-02"
  8574. loc, _ := time.LoadLocation("Local")
  8575. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8576. if err != nil {
  8577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8578. return
  8579. }
  8580. recordDateTime := theTime.Unix()
  8581. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8582. //if err != nil {
  8583. //
  8584. //}
  8585. //startRecordDateTime := startTime.Unix()
  8586. //
  8587. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8588. //if err != nil {
  8589. //
  8590. //}
  8591. //endRecordDateTime := endTime.Unix()
  8592. admin := c.GetAdminUserInfo()
  8593. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8594. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8595. var prescriptions []*models.HisPrescription
  8596. //var unChargeMonthPrescriptions []*models.HisPrescription
  8597. order, _ := service.GetHisOrderByID(order_id)
  8598. if order_status == 1 || order_status == 0 {
  8599. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8600. } else if order_status == 2 {
  8601. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8602. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8603. }
  8604. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8605. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8606. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8607. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8608. //获取所有科室信息
  8609. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8610. c.ServeSuccessJSON(map[string]interface{}{
  8611. "his_info": his_patient_info,
  8612. "xt_info": xt_patient_info,
  8613. "prescription": prescriptions,
  8614. "case_history": case_history,
  8615. "info": patientPrescriptionInfo,
  8616. "last_info": lastPatientPrescriptionInfo,
  8617. "order": order,
  8618. "doctors": doctors,
  8619. "department": department,
  8620. })
  8621. return
  8622. }
  8623. func (c *HisApiController) GetAllOrderDetail() {
  8624. order_id, _ := c.GetInt64("id", 0)
  8625. order, _ := service.GetHisOrderByID(order_id)
  8626. if order.ID == 0 {
  8627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8628. return
  8629. }
  8630. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8631. org_id := c.GetAdminUserInfo().CurrentOrgId
  8632. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8633. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8634. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8635. c.ServeSuccessJSON(map[string]interface{}{
  8636. "order": order,
  8637. "order_info": order_info,
  8638. "patient": patient,
  8639. "admin_info": adminInfo,
  8640. "hospital_record": record,
  8641. })
  8642. return
  8643. }
  8644. func (c *HisApiController) GetAllOrderDetailCollect() {
  8645. order_id, _ := c.GetInt64("id", 0)
  8646. order, _ := service.GetHisOrderByID(order_id)
  8647. if order.ID == 0 {
  8648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8649. return
  8650. }
  8651. org_id := c.GetAdminUserInfo().CurrentOrgId
  8652. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8653. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8654. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8655. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8656. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8657. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8658. var bedCostTotal float64 = 0 //床位总费
  8659. //var bedCostSelfTotal float64 = 0 //床位自费
  8660. var operationCostTotal float64 = 0 //手术费
  8661. //var operationCostSelfTotal float64 = 0 //手术费
  8662. var otherCostTotal float64 = 0 //其他费用
  8663. //var otherCostSelfTotal float64 = 0 //其他费用
  8664. var materialCostTotal float64 = 0 //材料费
  8665. //var materialCostSelfTotal float64 = 0 //材料费
  8666. var westernMedicineCostTotal float64 = 0 //西药费
  8667. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8668. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8669. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8670. var checkCostTotal float64 = 0 //检查费
  8671. //var checkCostSelfTotal float64 = 0 //检查费
  8672. var laboratoryCostTotal float64 = 0 //化验费
  8673. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8674. var treatCostTotal float64 = 0 //治疗费用
  8675. //var treatCostSelfTotal float64 = 0 //治疗费用
  8676. var zhenChaCostTotal float64 = 0 //其他费用
  8677. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8678. decimal.DivisionPrecision = 2
  8679. var BalanceAccountsType int64
  8680. if his.ID > 0 {
  8681. BalanceAccountsType = his.BalanceAccountsType
  8682. } else {
  8683. BalanceAccountsType = record.BalanceAccountsType
  8684. }
  8685. if BalanceAccountsType != 2 {
  8686. for _, item := range order_info {
  8687. if org_id == 10215 {
  8688. if item.MedChrgitmType == "01" { //床位费
  8689. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8690. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8691. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8692. }
  8693. if item.MedChrgitmType == "02" { //诊察费
  8694. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8695. //zhenChaCostSelfTotal = zhenChaCostTotal
  8696. }
  8697. if item.MedChrgitmType == "03" { //检查费
  8698. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8699. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8700. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8701. }
  8702. //if item.MedChrgitmType == "02" { //检查费
  8703. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8704. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8705. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8706. //}
  8707. if item.MedChrgitmType == "04" { //化验费
  8708. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8709. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8710. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8711. }
  8712. if item.MedChrgitmType == "05" { //治疗费
  8713. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8714. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8715. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8716. }
  8717. if item.MedChrgitmType == "06" { //手术费
  8718. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8719. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8720. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8721. }
  8722. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8723. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8724. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8725. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8726. }
  8727. if item.MedChrgitmType == "09" { //西药费
  8728. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8729. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8730. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8731. }
  8732. if item.MedChrgitmType == "11" { //中成费
  8733. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8734. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8735. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8736. }
  8737. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8738. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8739. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8740. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8741. }
  8742. } else if org_id == 10188 || org_id == 10217 {
  8743. if item.MedChrgitmType == "01" { //床位费
  8744. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8745. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8746. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8747. }
  8748. if item.MedChrgitmType == "02" { //诊察费
  8749. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8750. //zhenChaCostSelfTotal = zhenChaCostTotal
  8751. }
  8752. if item.MedChrgitmType == "03" { //检查费
  8753. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8754. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8755. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8756. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8757. }
  8758. //if item.MedChrgitmType == "02" { //检查费
  8759. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8760. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8761. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8762. //}
  8763. if item.MedChrgitmType == "04" { //化验费
  8764. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8765. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8766. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8767. }
  8768. if item.MedChrgitmType == "05" { //治疗费
  8769. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8770. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8771. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8772. }
  8773. if item.MedChrgitmType == "06" { //手术费
  8774. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8775. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8776. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8777. }
  8778. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8779. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8780. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8781. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8782. }
  8783. if item.MedChrgitmType == "09" { //西药费
  8784. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8785. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8786. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8787. }
  8788. if item.MedChrgitmType == "11" { //中成费
  8789. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8790. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8791. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8792. }
  8793. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8794. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8795. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8796. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8797. }
  8798. } else {
  8799. if item.MedChrgitmType == "01" { //床位费
  8800. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8801. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8802. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8803. }
  8804. //if item.MedChrgitmType == "02" { //诊察费
  8805. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8806. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8807. //}
  8808. if item.MedChrgitmType == "03" { //检查费
  8809. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8810. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8811. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8812. }
  8813. //if item.MedChrgitmType == "02" { //检查费
  8814. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8815. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8816. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8817. //}
  8818. if item.MedChrgitmType == "04" { //化验费
  8819. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8820. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8821. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8822. }
  8823. if item.MedChrgitmType == "05" { //治疗费
  8824. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8825. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8826. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8827. }
  8828. if item.MedChrgitmType == "06" { //手术费
  8829. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8830. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8831. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8832. }
  8833. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8834. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8835. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8836. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8837. }
  8838. if item.MedChrgitmType == "09" { //西药费
  8839. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8840. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8841. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8842. }
  8843. if item.MedChrgitmType == "11" { //中成费
  8844. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8845. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8846. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8847. }
  8848. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8849. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8850. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8851. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8852. }
  8853. }
  8854. }
  8855. c.ServeSuccessJSON(map[string]interface{}{
  8856. "order": order,
  8857. "order_info": order_info,
  8858. "patient": patient,
  8859. "admin_info": adminInfo,
  8860. "his_hospital": record,
  8861. "bedCostTotal": bedCostTotal,
  8862. "operationCostTotal": operationCostTotal,
  8863. "otherCostTotal": otherCostTotal,
  8864. "materialCostTotal": materialCostTotal,
  8865. "westernMedicineCostTotal": westernMedicineCostTotal,
  8866. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8867. "checkCostTotal": checkCostTotal,
  8868. "zhenChaCostTotal": zhenChaCostTotal,
  8869. "laboratoryCostTotal": laboratoryCostTotal,
  8870. "treatCostTotal": treatCostTotal,
  8871. })
  8872. } else {
  8873. for _, item := range order_info {
  8874. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8875. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8876. item.MedChrgitmType = "09"
  8877. }
  8878. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8879. if item.HisPrescriptionProject.Type == 2 {
  8880. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8881. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8882. case 0:
  8883. item.MedChrgitmType = "0"
  8884. break
  8885. case 1:
  8886. item.MedChrgitmType = "14"
  8887. break
  8888. case 2:
  8889. item.MedChrgitmType = "05"
  8890. break
  8891. case 3:
  8892. item.MedChrgitmType = "03"
  8893. break
  8894. case 4:
  8895. item.MedChrgitmType = "03"
  8896. break
  8897. case 5:
  8898. item.MedChrgitmType = "08"
  8899. break
  8900. case 6:
  8901. item.MedChrgitmType = "14"
  8902. break
  8903. case 7:
  8904. item.MedChrgitmType = "14"
  8905. break
  8906. case 8:
  8907. item.MedChrgitmType = "03"
  8908. break
  8909. case 9:
  8910. item.MedChrgitmType = "14"
  8911. break
  8912. case 10:
  8913. item.MedChrgitmType = "14"
  8914. break
  8915. case 11:
  8916. item.MedChrgitmType = "06"
  8917. break
  8918. case 12:
  8919. item.MedChrgitmType = "12"
  8920. break
  8921. case 13:
  8922. item.MedChrgitmType = "01"
  8923. break
  8924. case 14:
  8925. item.MedChrgitmType = "04"
  8926. break
  8927. case 15:
  8928. item.MedChrgitmType = "14"
  8929. break
  8930. }
  8931. } else {
  8932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8933. case 1:
  8934. item.MedChrgitmType = "14"
  8935. break
  8936. case 2:
  8937. item.MedChrgitmType = "05"
  8938. break
  8939. case 3:
  8940. item.MedChrgitmType = "04"
  8941. break
  8942. case 4:
  8943. item.MedChrgitmType = "14"
  8944. break
  8945. case 5:
  8946. item.MedChrgitmType = "08"
  8947. break
  8948. case 6:
  8949. item.MedChrgitmType = "14"
  8950. break
  8951. case 7:
  8952. item.MedChrgitmType = "14"
  8953. break
  8954. case 8:
  8955. item.MedChrgitmType = "03"
  8956. break
  8957. case 9:
  8958. item.MedChrgitmType = "14"
  8959. break
  8960. }
  8961. }
  8962. } else if item.HisPrescriptionProject.Type == 3 {
  8963. item.MedChrgitmType = "08"
  8964. }
  8965. }
  8966. }
  8967. for _, item := range order_info {
  8968. if org_id == 10215 {
  8969. if item.MedChrgitmType == "01" { //床位费
  8970. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8971. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8972. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8973. }
  8974. if item.MedChrgitmType == "02" { //诊察费
  8975. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8976. //zhenChaCostSelfTotal = zhenChaCostTotal
  8977. }
  8978. if item.MedChrgitmType == "03" { //检查费
  8979. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8980. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8981. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8982. }
  8983. //if item.MedChrgitmType == "02" { //检查费
  8984. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8985. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8986. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8987. //}
  8988. if item.MedChrgitmType == "04" { //化验费
  8989. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8990. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8991. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8992. }
  8993. if item.MedChrgitmType == "05" { //治疗费
  8994. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8995. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8996. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8997. }
  8998. if item.MedChrgitmType == "06" { //手术费
  8999. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9000. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9001. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9002. }
  9003. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9004. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9005. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9006. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9007. }
  9008. if item.MedChrgitmType == "09" { //西药费
  9009. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9010. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9011. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9012. }
  9013. if item.MedChrgitmType == "11" { //中成费
  9014. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9015. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9016. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9017. }
  9018. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9019. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9020. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9021. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9022. }
  9023. } else {
  9024. if item.MedChrgitmType == "01" { //床位费
  9025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9028. }
  9029. //if item.MedChrgitmType == "02" { //诊察费
  9030. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9031. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9032. //}
  9033. if item.MedChrgitmType == "03" { //检查费
  9034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9037. }
  9038. //if item.MedChrgitmType == "02" { //检查费
  9039. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9040. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9041. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9042. //}
  9043. if item.MedChrgitmType == "04" { //化验费
  9044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9047. }
  9048. if item.MedChrgitmType == "05" { //治疗费
  9049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9052. }
  9053. if item.MedChrgitmType == "06" { //手术费
  9054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9057. }
  9058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9062. }
  9063. if item.MedChrgitmType == "09" { //西药费
  9064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9067. }
  9068. if item.MedChrgitmType == "11" { //中成费
  9069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9072. }
  9073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9077. }
  9078. }
  9079. }
  9080. c.ServeSuccessJSON(map[string]interface{}{
  9081. "order": order,
  9082. "order_info": order_info,
  9083. "patient": patient,
  9084. "admin_info": adminInfo,
  9085. "his_hospital": record,
  9086. "bedCostTotal": bedCostTotal,
  9087. "operationCostTotal": operationCostTotal,
  9088. "otherCostTotal": otherCostTotal,
  9089. "materialCostTotal": materialCostTotal,
  9090. "westernMedicineCostTotal": westernMedicineCostTotal,
  9091. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9092. "checkCostTotal": checkCostTotal,
  9093. "zhenChaCostTotal": zhenChaCostTotal,
  9094. "laboratoryCostTotal": laboratoryCostTotal,
  9095. "treatCostTotal": treatCostTotal,
  9096. })
  9097. }
  9098. }
  9099. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9100. page, _ := c.GetInt64("page")
  9101. limit, _ := c.GetInt64("limit")
  9102. keywords := c.GetString("keywords")
  9103. start_time := c.GetString("start_time")
  9104. end_time := c.GetString("end_time")
  9105. //clr_type := c.GetString("clr_type")
  9106. insutype := c.GetString("insutype")
  9107. timeLayout := "2006-01-02"
  9108. loc, _ := time.LoadLocation("Local")
  9109. var theStartTIme int64
  9110. if len(start_time) > 0 {
  9111. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9112. theStartTIme = theTime.Unix()
  9113. }
  9114. var theEndtTIme int64
  9115. if len(end_time) > 0 {
  9116. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9117. theEndtTIme = theTime.Unix()
  9118. }
  9119. if page <= 0 {
  9120. page = 1
  9121. }
  9122. if limit <= 0 {
  9123. limit = 10
  9124. }
  9125. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9126. c.ServeSuccessJSON(map[string]interface{}{
  9127. "total": total,
  9128. "list": list,
  9129. })
  9130. return
  9131. }
  9132. func (c *HisApiController) GetPutOnRecordList() {
  9133. page, _ := c.GetInt64("page")
  9134. limit, _ := c.GetInt64("limit")
  9135. keywords := c.GetString("keywords")
  9136. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9137. if page <= 0 {
  9138. page = 1
  9139. }
  9140. if limit <= 0 {
  9141. limit = 10
  9142. }
  9143. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9144. c.ServeSuccessJSON(map[string]interface{}{
  9145. "total": total,
  9146. "list": list,
  9147. })
  9148. return
  9149. }
  9150. func (c *HisApiController) GetCompareData() {
  9151. start_time := c.GetString("start_time")
  9152. end_time := c.GetString("end_time")
  9153. insutype := c.GetString("insutype")
  9154. clr_type := c.GetString("clr_type")
  9155. timeLayout := "2006-01-02"
  9156. loc, _ := time.LoadLocation("Local")
  9157. var theStartTIme int64
  9158. if len(start_time) > 0 {
  9159. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9160. if err != nil {
  9161. theStartTIme = 0
  9162. }
  9163. theStartTIme = theTime.Unix()
  9164. }
  9165. var theEndtTIme int64
  9166. if len(end_time) > 0 {
  9167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9168. if err != nil {
  9169. theEndtTIme = 0
  9170. }
  9171. theEndtTIme = theTime.Unix()
  9172. }
  9173. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9174. fmt.Println(err)
  9175. if err == nil {
  9176. c.ServeSuccessJSON(map[string]interface{}{
  9177. "list": formData,
  9178. })
  9179. } else {
  9180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9181. return
  9182. }
  9183. }
  9184. func (c *HisApiController) GetFaPiaoData() {
  9185. order_id, _ := c.GetInt64("order_id")
  9186. patient_id, _ := c.GetInt64("patient_id")
  9187. //number := c.GetString("number")
  9188. adminUser := c.GetAdminUserInfo()
  9189. order, _ := service.GetHisOrderByID(order_id)
  9190. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9191. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9192. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9193. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9194. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9195. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9196. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9197. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9198. var bedCostTotal float64 = 0 //床位总费
  9199. var bedCostSelfTotal float64 = 0 //床位自费
  9200. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9201. var operationCostTotal float64 = 0 //手术费
  9202. var operationCostSelfTotal float64 = 0 //手术费
  9203. var operationCostPartSelfTotal float64 = 0 //手术费
  9204. var otherCostTotal float64 = 0 //其他费用
  9205. var otherCostSelfTotal float64 = 0 //其他费用
  9206. var otherCostPartSelfTotal float64 = 0 //其他费用
  9207. var materialCostTotal float64 = 0 //材料费
  9208. var materialCostSelfTotal float64 = 0 //材料费
  9209. var materialCostPartSelfTotal float64 = 0 //材料费
  9210. var westernMedicineCostTotal float64 = 0 //西药费
  9211. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9212. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9213. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9214. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9215. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9216. var checkCostTotal float64 = 0 //检查费
  9217. var checkCostSelfTotal float64 = 0 //检查费
  9218. var checkCostPartSelfTotal float64 = 0 //检查费
  9219. var hiliCostTotal float64 = 0 //护理费
  9220. var hiliCostSelfTotal float64 = 0 //护理费
  9221. var hiliCostPartSelfTotal float64 = 0 //护理费
  9222. var laboratoryCostTotal float64 = 0 //化验费
  9223. var laboratoryCostSelfTotal float64 = 0 //化验费
  9224. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9225. var treatCostTotal float64 = 0 //治疗费用
  9226. var treatCostSelfTotal float64 = 0 //治疗费用
  9227. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9228. var zhenChaCostTotal float64 = 0 //其他费用
  9229. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9230. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9231. decimal.DivisionPrecision = 2
  9232. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9233. var balanceAccountsType int64
  9234. if his.ID > 0 {
  9235. balanceAccountsType = his.BalanceAccountsType
  9236. } else {
  9237. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9238. }
  9239. if balanceAccountsType == 2 {
  9240. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9241. for _, item := range orderInfos_two {
  9242. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9243. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9244. item.MedChrgitmType = "09"
  9245. }
  9246. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9247. if item.HisPrescriptionProject.Type == 2 {
  9248. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9249. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9250. case 0:
  9251. item.MedChrgitmType = "0"
  9252. break
  9253. case 1:
  9254. item.MedChrgitmType = "14"
  9255. break
  9256. case 2:
  9257. item.MedChrgitmType = "05"
  9258. break
  9259. case 3:
  9260. item.MedChrgitmType = "03"
  9261. break
  9262. case 4:
  9263. item.MedChrgitmType = "03"
  9264. break
  9265. case 5:
  9266. item.MedChrgitmType = "08"
  9267. break
  9268. case 6:
  9269. item.MedChrgitmType = "14"
  9270. break
  9271. case 7:
  9272. item.MedChrgitmType = "14"
  9273. break
  9274. case 8:
  9275. item.MedChrgitmType = "03"
  9276. break
  9277. case 9:
  9278. item.MedChrgitmType = "14"
  9279. break
  9280. case 10:
  9281. item.MedChrgitmType = "14"
  9282. break
  9283. case 11:
  9284. item.MedChrgitmType = "06"
  9285. break
  9286. case 12:
  9287. item.MedChrgitmType = "12"
  9288. break
  9289. case 13:
  9290. item.MedChrgitmType = "01"
  9291. break
  9292. case 14:
  9293. item.MedChrgitmType = "04"
  9294. break
  9295. case 15:
  9296. item.MedChrgitmType = "02"
  9297. break
  9298. }
  9299. } else {
  9300. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9301. case 1:
  9302. item.MedChrgitmType = "14"
  9303. break
  9304. case 2:
  9305. item.MedChrgitmType = "05"
  9306. break
  9307. case 3:
  9308. item.MedChrgitmType = "03"
  9309. break
  9310. case 4:
  9311. item.MedChrgitmType = "03"
  9312. break
  9313. case 5:
  9314. item.MedChrgitmType = "08"
  9315. break
  9316. case 6:
  9317. item.MedChrgitmType = "14"
  9318. break
  9319. case 7:
  9320. item.MedChrgitmType = "14"
  9321. break
  9322. case 8:
  9323. item.MedChrgitmType = "03"
  9324. break
  9325. case 9:
  9326. item.MedChrgitmType = "14"
  9327. break
  9328. }
  9329. }
  9330. } else if item.HisPrescriptionProject.Type == 3 {
  9331. item.MedChrgitmType = "08"
  9332. }
  9333. }
  9334. }
  9335. for _, item := range orderInfos_two {
  9336. fmt.Println(item.MedChrgitmType)
  9337. if item.MedChrgitmType == "07" { //床位费
  9338. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9339. hiliCostSelfTotal = hiliCostTotal
  9340. }
  9341. if item.MedChrgitmType == "01" { //床位费
  9342. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9343. bedCostSelfTotal = bedCostTotal
  9344. }
  9345. if item.MedChrgitmType == "02" { //诊察费
  9346. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9347. zhenChaCostSelfTotal = zhenChaCostTotal
  9348. }
  9349. if item.MedChrgitmType == "03" { //检查费
  9350. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9351. checkCostSelfTotal = checkCostTotal
  9352. }
  9353. if item.MedChrgitmType == "04" { //化验费
  9354. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9355. laboratoryCostSelfTotal = laboratoryCostTotal
  9356. }
  9357. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9358. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9359. treatCostSelfTotal = treatCostTotal
  9360. }
  9361. if item.MedChrgitmType == "06" { //手术费
  9362. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9363. operationCostSelfTotal = treatCostTotal
  9364. }
  9365. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9366. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9367. materialCostSelfTotal = materialCostTotal
  9368. }
  9369. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9370. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9371. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9372. }
  9373. if item.MedChrgitmType == "11" { //中成费
  9374. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9375. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9376. }
  9377. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9378. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9379. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9380. otherCostSelfTotal = otherCostTotal
  9381. }
  9382. } else {
  9383. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9384. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9385. otherCostSelfTotal = otherCostTotal
  9386. }
  9387. }
  9388. }
  9389. } else {
  9390. for _, item := range orderInfos {
  9391. if item.MedChrgitmType == "01" { //床位费
  9392. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9393. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9394. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9395. }
  9396. if item.MedChrgitmType == "02" { //诊察费
  9397. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9398. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9399. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9400. }
  9401. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9402. if item.MedChrgitmType == "03" { //检查费
  9403. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9404. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9405. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9406. }
  9407. } else {
  9408. if item.MedChrgitmType == "03" { //检查费
  9409. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9410. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9411. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9412. }
  9413. }
  9414. if item.MedChrgitmType == "04" { //化验费
  9415. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9416. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9417. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9418. }
  9419. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9420. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9421. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9422. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9423. }
  9424. if item.MedChrgitmType == "06" { //手术费
  9425. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9426. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9427. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9428. }
  9429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9433. }
  9434. if item.MedChrgitmType == "07" { //护理
  9435. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9436. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9437. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9438. }
  9439. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9440. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9441. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9442. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9443. }
  9444. if item.MedChrgitmType == "11" { //中成费
  9445. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9446. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9447. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9448. }
  9449. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9453. }
  9454. }
  9455. }
  9456. timeLayout := "2006-01-02"
  9457. loc, _ := time.LoadLocation("Local")
  9458. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9459. if err != nil {
  9460. }
  9461. startRecordDateTime := startTime.Unix()
  9462. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9463. if err != nil {
  9464. }
  9465. endRecordDateTime := endTime.Unix()
  9466. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9467. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9468. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9469. c.ServeSuccessJSON(map[string]interface{}{
  9470. "order_number": order.Number, //业务流水号
  9471. "id_card_no": his.IdCardNo, //社会保障号
  9472. "patient": patient,
  9473. "department_name": department.Name, //科室
  9474. "number": his.Number, //门诊号
  9475. "date": order.SettleAccountsDate, //结算日期
  9476. "name": order.PsnName, //姓名
  9477. "gender": patient.Gender, //性别
  9478. "psn_cash_money": order.PsnCashPay, //个人支付
  9479. "pay_way": "门诊", //结算方式
  9480. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9481. "admin_user_name": admin.UserName, //收款员
  9482. "order": order,
  9483. "order_info": orderInfos_two,
  9484. "his": his,
  9485. "bedCostTotal": bedCostTotal,
  9486. "bedCostSelfTotal": bedCostSelfTotal,
  9487. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9488. "operationCostTotal": operationCostTotal,
  9489. "operationCostSelfTotal": operationCostSelfTotal,
  9490. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9491. "otherCostTotal": otherCostTotal,
  9492. "otherCostSelfTotal": otherCostSelfTotal,
  9493. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9494. "materialCostTotal": materialCostTotal,
  9495. "materialCostSelfTotal": materialCostSelfTotal,
  9496. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9497. "westernMedicineCostTotal": westernMedicineCostTotal,
  9498. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9499. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9500. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9501. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9502. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9503. "checkCostTotal": checkCostTotal,
  9504. "checkCostSelfTotal": checkCostSelfTotal,
  9505. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9506. "laboratoryCostTotal": laboratoryCostTotal,
  9507. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9508. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9509. "treatCostTotal": treatCostTotal,
  9510. "treatCostSelfTotal": treatCostSelfTotal,
  9511. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9512. "zhenChaCostTotal": zhenChaCostTotal,
  9513. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9514. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9515. "his_hospital_record": his_hospital_record,
  9516. "pre_pay_money": pre_pay_money,
  9517. "refund_sum": sum,
  9518. "doctor_info": doctor_info,
  9519. "hiliCostTotal": hiliCostTotal,
  9520. "hiliCostSelfTotal": hiliCostSelfTotal,
  9521. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9522. })
  9523. }
  9524. //func (c *HisApiController) GetFaPiaoDatas() {
  9525. // order_ids := c.GetString("order_ids")
  9526. // patient_id, _ := c.GetInt64("patient_id")
  9527. // adminUser := c.GetAdminUserInfo()
  9528. //
  9529. // orders := strings.Split(order_ids, ",")
  9530. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9531. //
  9532. // for _, item := range orders {
  9533. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9534. // order, _ := service.GetHisOrderByID(order_id)
  9535. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9536. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9537. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9538. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9539. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9540. //
  9541. // }
  9542. //
  9543. // var bedCostTotal float64 = 0 //床位总费
  9544. // var bedCostSelfTotal float64 = 0 //床位自费
  9545. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9546. //
  9547. // var operationCostTotal float64 = 0 //手术费
  9548. // var operationCostSelfTotal float64 = 0 //手术费
  9549. // var operationCostPartSelfTotal float64 = 0 //手术费
  9550. //
  9551. // var otherCostTotal float64 = 0 //其他费用
  9552. // var otherCostSelfTotal float64 = 0 //其他费用
  9553. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9554. //
  9555. // var materialCostTotal float64 = 0 //材料费
  9556. // var materialCostSelfTotal float64 = 0 //材料费
  9557. // var materialCostPartSelfTotal float64 = 0 //材料费
  9558. //
  9559. // var westernMedicineCostTotal float64 = 0 //西药费
  9560. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9561. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9562. //
  9563. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9564. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9565. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9566. //
  9567. // var checkCostTotal float64 = 0 //检查费
  9568. // var checkCostSelfTotal float64 = 0 //检查费
  9569. // var checkCostPartSelfTotal float64 = 0 //检查费
  9570. //
  9571. // var laboratoryCostTotal float64 = 0 //化验费
  9572. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9573. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9574. //
  9575. // var treatCostTotal float64 = 0 //治疗费用
  9576. // var treatCostSelfTotal float64 = 0 //治疗费用
  9577. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9578. //
  9579. // var zhenChaCostTotal float64 = 0 //其他费用
  9580. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9581. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9582. //
  9583. // decimal.DivisionPrecision = 2
  9584. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9585. //
  9586. // var balanceAccountsType int64
  9587. // if his.ID > 0 {
  9588. // balanceAccountsType = his.BalanceAccountsType
  9589. // } else {
  9590. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9591. // }
  9592. // if balanceAccountsType == 2 {
  9593. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9594. // for _, item := range orderInfos_two {
  9595. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9596. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9597. // item.MedChrgitmType = "09"
  9598. // }
  9599. //
  9600. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9601. // if item.HisPrescriptionProject.Type == 2 {
  9602. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9603. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9604. // case 0:
  9605. // item.MedChrgitmType = "0"
  9606. // break
  9607. // case 1:
  9608. // item.MedChrgitmType = "14"
  9609. // break
  9610. // case 2:
  9611. // item.MedChrgitmType = "05"
  9612. //
  9613. // break
  9614. // case 3:
  9615. // item.MedChrgitmType = "03"
  9616. //
  9617. // break
  9618. // case 4:
  9619. // item.MedChrgitmType = "03"
  9620. //
  9621. // break
  9622. // case 5:
  9623. // item.MedChrgitmType = "08"
  9624. //
  9625. // break
  9626. // case 6:
  9627. // item.MedChrgitmType = "14"
  9628. //
  9629. // break
  9630. // case 7:
  9631. // item.MedChrgitmType = "14"
  9632. //
  9633. // break
  9634. // case 8:
  9635. // item.MedChrgitmType = "03"
  9636. // break
  9637. // case 9:
  9638. // item.MedChrgitmType = "14"
  9639. // break
  9640. // case 10:
  9641. // item.MedChrgitmType = "14"
  9642. // break
  9643. // case 11:
  9644. // item.MedChrgitmType = "06"
  9645. // break
  9646. // case 12:
  9647. // item.MedChrgitmType = "12"
  9648. // break
  9649. // case 13:
  9650. // item.MedChrgitmType = "01"
  9651. // break
  9652. // case 14:
  9653. // item.MedChrgitmType = "04"
  9654. // break
  9655. // case 15:
  9656. // item.MedChrgitmType = "02"
  9657. // break
  9658. //
  9659. // }
  9660. //
  9661. // } else {
  9662. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9663. //
  9664. // case 1:
  9665. // item.MedChrgitmType = "14"
  9666. // break
  9667. // case 2:
  9668. // item.MedChrgitmType = "05"
  9669. //
  9670. // break
  9671. // case 3:
  9672. // item.MedChrgitmType = "03"
  9673. //
  9674. // break
  9675. // case 4:
  9676. // item.MedChrgitmType = "03"
  9677. //
  9678. // break
  9679. // case 5:
  9680. // item.MedChrgitmType = "08"
  9681. //
  9682. // break
  9683. // case 6:
  9684. // item.MedChrgitmType = "14"
  9685. //
  9686. // break
  9687. // case 7:
  9688. // item.MedChrgitmType = "14"
  9689. //
  9690. // break
  9691. // case 8:
  9692. // item.MedChrgitmType = "03"
  9693. // break
  9694. // case 9:
  9695. // item.MedChrgitmType = "14"
  9696. // break
  9697. //
  9698. // }
  9699. //
  9700. // }
  9701. //
  9702. // } else if item.HisPrescriptionProject.Type == 3 {
  9703. // item.MedChrgitmType = "08"
  9704. // }
  9705. // }
  9706. // }
  9707. //
  9708. // for _, item := range orderInfos_two {
  9709. // fmt.Println(item.MedChrgitmType)
  9710. // if item.MedChrgitmType == "01" { //床位费
  9711. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9712. // bedCostSelfTotal = bedCostTotal
  9713. // }
  9714. //
  9715. // if item.MedChrgitmType == "02" { //诊察费
  9716. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9717. // zhenChaCostSelfTotal = zhenChaCostTotal
  9718. // }
  9719. //
  9720. // if item.MedChrgitmType == "03" { //检查费
  9721. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9722. // checkCostSelfTotal = checkCostTotal
  9723. // }
  9724. //
  9725. // if item.MedChrgitmType == "04" { //化验费
  9726. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9727. // laboratoryCostSelfTotal = laboratoryCostTotal
  9728. // }
  9729. //
  9730. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9731. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9732. // treatCostSelfTotal = treatCostTotal
  9733. // }
  9734. //
  9735. // if item.MedChrgitmType == "06" { //手术费
  9736. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9737. // operationCostSelfTotal = treatCostTotal
  9738. // }
  9739. //
  9740. // if item.MedChrgitmType == "08" { //材料费
  9741. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9742. // materialCostSelfTotal = materialCostTotal
  9743. // }
  9744. //
  9745. // if item.MedChrgitmType == "09" { //西药费
  9746. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9747. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9748. // }
  9749. //
  9750. // if item.MedChrgitmType == "11" { //中成费
  9751. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9752. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9753. // }
  9754. //
  9755. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9756. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9757. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9758. // otherCostSelfTotal = otherCostTotal
  9759. // }
  9760. // } else {
  9761. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9762. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9763. // otherCostSelfTotal = otherCostTotal
  9764. // }
  9765. //
  9766. // }
  9767. //
  9768. // }
  9769. //
  9770. // } else {
  9771. // for _, item := range orderInfos {
  9772. // if item.MedChrgitmType == "01" { //床位费
  9773. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9774. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9775. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9776. // }
  9777. //
  9778. // if item.MedChrgitmType == "02" { //诊察费
  9779. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9780. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9781. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9782. // }
  9783. //
  9784. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9785. // if item.MedChrgitmType == "03" { //检查费
  9786. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9787. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9788. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9789. //
  9790. // }
  9791. // } else {
  9792. // if item.MedChrgitmType == "03" { //检查费
  9793. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9794. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9795. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9796. // }
  9797. //
  9798. // }
  9799. //
  9800. // if item.MedChrgitmType == "04" { //化验费
  9801. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9802. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9803. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9804. //
  9805. // }
  9806. //
  9807. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9808. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9809. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9810. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9811. //
  9812. // }
  9813. //
  9814. // if item.MedChrgitmType == "06" { //手术费
  9815. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9816. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9817. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9818. // }
  9819. //
  9820. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9821. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9822. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9823. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9824. // }
  9825. //
  9826. // if item.MedChrgitmType == "09" { //西药费
  9827. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9828. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9829. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9830. // }
  9831. //
  9832. // if item.MedChrgitmType == "11" { //中成费
  9833. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9834. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9835. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9836. // }
  9837. //
  9838. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9839. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9840. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9841. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9842. // }
  9843. //
  9844. // }
  9845. // }
  9846. // timeLayout := "2006-01-02"
  9847. // loc, _ := time.LoadLocation("Local")
  9848. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9849. // if err != nil {
  9850. // }
  9851. // startRecordDateTime := startTime.Unix()
  9852. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9853. // if err != nil {
  9854. // }
  9855. // endRecordDateTime := endTime.Unix()
  9856. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9857. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9858. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9859. //
  9860. // c.ServeSuccessJSON(map[string]interface{}{
  9861. // "order_number": order.Number, //业务流水号
  9862. // "id_card_no": his.IdCardNo, //社会保障号
  9863. // "department_name": department.Name, //科室
  9864. // "number": his.Number, //门诊号
  9865. // "date": order.SettleAccountsDate, //结算日期
  9866. // "name": order.PsnName, //姓名
  9867. // "gender": patient.Gender, //性别
  9868. // "psn_cash_money": order.PsnCashPay, //个人支付
  9869. // "pay_way": "门诊", //结算方式
  9870. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9871. // "admin_user_name": admin.UserName, //收款员
  9872. // "order": order,
  9873. // "order_info": orderInfos_two,
  9874. // "his": his,
  9875. // "bedCostTotal": bedCostTotal,
  9876. // "bedCostSelfTotal": bedCostSelfTotal,
  9877. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9878. // "operationCostTotal": operationCostTotal,
  9879. // "operationCostSelfTotal": operationCostSelfTotal,
  9880. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9881. // "otherCostTotal": otherCostTotal,
  9882. // "otherCostSelfTotal": otherCostSelfTotal,
  9883. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9884. // "materialCostTotal": materialCostTotal,
  9885. // "materialCostSelfTotal": materialCostSelfTotal,
  9886. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9887. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9888. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9889. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9890. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9891. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9892. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9893. // "checkCostTotal": checkCostTotal,
  9894. // "checkCostSelfTotal": checkCostSelfTotal,
  9895. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9896. // "laboratoryCostTotal": laboratoryCostTotal,
  9897. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9898. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9899. // "treatCostTotal": treatCostTotal,
  9900. // "treatCostSelfTotal": treatCostSelfTotal,
  9901. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9902. // "zhenChaCostTotal": zhenChaCostTotal,
  9903. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9904. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9905. // "his_hospital_record": his_hospital_record,
  9906. // "pre_pay_money": pre_pay_money,
  9907. // "refund_sum": sum,
  9908. // })
  9909. //
  9910. //}
  9911. func (this *HisApiController) GetIncomeStatisticsData() {
  9912. start_time := this.GetString("start_time")
  9913. end_time := this.GetString("end_time")
  9914. key_words := this.GetString("key_words")
  9915. limit, _ := this.GetInt64("limit")
  9916. page, _ := this.GetInt64("page")
  9917. if page <= 0 {
  9918. page = 1
  9919. }
  9920. if limit <= 0 {
  9921. limit = 10
  9922. }
  9923. statistics_type, _ := this.GetInt64("statistics_type")
  9924. admin := this.GetAdminUserInfo()
  9925. timeLayout := "2006-01-02"
  9926. loc, _ := time.LoadLocation("Local")
  9927. var theStartTIme int64
  9928. if len(start_time) > 0 {
  9929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9930. if err != nil {
  9931. theStartTIme = 0
  9932. }
  9933. theStartTIme = theTime.Unix()
  9934. }
  9935. var theEndtTIme int64
  9936. if len(end_time) > 0 {
  9937. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9938. if err != nil {
  9939. theEndtTIme = 0
  9940. }
  9941. theEndtTIme = theTime.Unix()
  9942. }
  9943. if statistics_type == 1 {
  9944. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9945. this.ServeSuccessJSON(map[string]interface{}{
  9946. "list": list,
  9947. "total": total,
  9948. })
  9949. } else {
  9950. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9951. this.ServeSuccessJSON(map[string]interface{}{
  9952. "list": list,
  9953. "total": total,
  9954. })
  9955. }
  9956. }
  9957. func (c *HisApiController) PostProjectInformation() {
  9958. adminUser := c.GetAdminUserInfo()
  9959. orgId := adminUser.CurrentOrgId
  9960. dataBody := make(map[string]interface{}, 0)
  9961. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9962. if err != nil {
  9963. utils.ErrorLog(err.Error())
  9964. return
  9965. }
  9966. utils.ErrorLog("%v", dataBody)
  9967. var projectList []*models.HisProject
  9968. var total_goods []interface{}
  9969. tempProjects := dataBody["projects"].([]interface{})
  9970. total_goods = tempProjects
  9971. for index, projectMap := range tempProjects {
  9972. projectM := projectMap.(map[string]interface{})
  9973. var project models.HisProject
  9974. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9975. utils.ErrorLog("project_name")
  9976. return
  9977. }
  9978. project_name, _ := projectM["project_name"].(string)
  9979. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9980. err_log := models.ExportErrLog{
  9981. LogType: 6,
  9982. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9983. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9984. Status: 1,
  9985. CreateTime: time.Now().Unix(),
  9986. UpdateTime: time.Now().Unix(),
  9987. ExportTime: time.Now().Unix(),
  9988. }
  9989. service.CreateExportErrLog(&err_log)
  9990. continue
  9991. }
  9992. project.ProjectName = project_name
  9993. prices := projectM["price"].(string)
  9994. price, _ := strconv.ParseFloat(prices, 64)
  9995. if price <= 0 { //名字为空则生成一条导入错误日志
  9996. err_log := models.ExportErrLog{
  9997. LogType: 6,
  9998. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9999. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10000. Status: 1,
  10001. CreateTime: time.Now().Unix(),
  10002. UpdateTime: time.Now().Unix(),
  10003. ExportTime: time.Now().Unix(),
  10004. }
  10005. service.CreateExportErrLog(&err_log)
  10006. continue
  10007. }
  10008. project.Price = price
  10009. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10010. utils.ErrorLog("unit_id")
  10011. return
  10012. }
  10013. unit := projectM["unit"].(string)
  10014. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10015. err_log := models.ExportErrLog{
  10016. LogType: 6,
  10017. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10018. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10019. Status: 1,
  10020. CreateTime: time.Now().Unix(),
  10021. UpdateTime: time.Now().Unix(),
  10022. ExportTime: time.Now().Unix(),
  10023. }
  10024. service.CreateExportErrLog(&err_log)
  10025. continue
  10026. }
  10027. project.Unit = unit
  10028. cost_classify := projectM["cost_classify"].(string)
  10029. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10030. err_log := models.ExportErrLog{
  10031. LogType: 6,
  10032. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10033. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10034. Status: 1,
  10035. CreateTime: time.Now().Unix(),
  10036. UpdateTime: time.Now().Unix(),
  10037. ExportTime: time.Now().Unix(),
  10038. }
  10039. service.CreateExportErrLog(&err_log)
  10040. continue
  10041. }
  10042. var costClassify = "费用类别"
  10043. var cost_classify_id int64
  10044. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10045. if len(cost_classify) != 0 {
  10046. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10047. if errcode == gorm.ErrRecordNotFound {
  10048. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10049. dataconfig := models.DictDataconfig{
  10050. ParentId: costClassifyConfig.ID,
  10051. Module: "system",
  10052. OrgId: orgId,
  10053. Name: cost_classify,
  10054. FieldName: "",
  10055. Value: costConfig.Value + 1,
  10056. CreatedTime: "",
  10057. UpdatedTime: "",
  10058. CreateUserId: adminUser.AdminUser.Id,
  10059. Status: 1,
  10060. Remark: "",
  10061. DeleteIdSystem: 0,
  10062. Title: "",
  10063. Content: "",
  10064. Order: 0,
  10065. Code: "",
  10066. }
  10067. service.CreatedDicConfig(&dataconfig)
  10068. }
  10069. }
  10070. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10071. for _, it := range costClassList {
  10072. if cost_classify == it.Name {
  10073. cost_classify_id = int64(it.Value)
  10074. }
  10075. }
  10076. project.CostClassify = cost_classify_id
  10077. executive_section := projectM["executive_section"].(string)
  10078. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10079. err_log := models.ExportErrLog{
  10080. LogType: 6,
  10081. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10082. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10083. Status: 1,
  10084. CreateTime: time.Now().Unix(),
  10085. UpdateTime: time.Now().Unix(),
  10086. ExportTime: time.Now().Unix(),
  10087. }
  10088. service.CreateExportErrLog(&err_log)
  10089. continue
  10090. }
  10091. if len(executive_section) != 0 {
  10092. //查找科室是否有内容
  10093. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10094. if errcodedepart == gorm.ErrRecordNotFound {
  10095. department := models.XtHisDepartment{
  10096. Name: executive_section,
  10097. Status: 1,
  10098. UserOrgId: adminUser.CurrentOrgId,
  10099. CreatedTime: time.Now().Unix(),
  10100. }
  10101. service.CreateDePartment(&department)
  10102. }
  10103. }
  10104. var executive_section_id int64
  10105. departMentList, _ := service.GetAllDepartMent(orgId)
  10106. for _, it := range departMentList {
  10107. if executive_section == it.Name {
  10108. executive_section_id = it.ID
  10109. }
  10110. }
  10111. project.ExecutiveSection = executive_section_id
  10112. medical_coverage := projectM["medical_coverage"].(string)
  10113. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10114. err_log := models.ExportErrLog{
  10115. LogType: 6,
  10116. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10117. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10118. Status: 1,
  10119. CreateTime: time.Now().Unix(),
  10120. UpdateTime: time.Now().Unix(),
  10121. ExportTime: time.Now().Unix(),
  10122. }
  10123. service.CreateExportErrLog(&err_log)
  10124. continue
  10125. }
  10126. var medicalCoverage = "医保等级"
  10127. var medical_coverage_id int64
  10128. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10129. if len(medical_coverage) != 0 {
  10130. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10131. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10132. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10133. dataconfig := models.DictDataconfig{
  10134. ParentId: medicalCoverageConfig.ID,
  10135. Module: "system",
  10136. OrgId: orgId,
  10137. Name: medical_coverage,
  10138. FieldName: "",
  10139. Value: medicalCoverageConfig.Value + 1,
  10140. CreatedTime: "",
  10141. UpdatedTime: "",
  10142. CreateUserId: adminUser.AdminUser.Id,
  10143. Status: 1,
  10144. Remark: "",
  10145. DeleteIdSystem: 0,
  10146. Title: "",
  10147. Content: "",
  10148. Order: 0,
  10149. Code: "",
  10150. }
  10151. service.CreatedDicConfig(&dataconfig)
  10152. }
  10153. }
  10154. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10155. for _, it := range medicalCoverageList {
  10156. if medical_coverage == it.Name {
  10157. medical_coverage_id = int64(it.Value)
  10158. }
  10159. }
  10160. project.MedicalCoverage = medical_coverage_id
  10161. pinyin := projectM["pinyin"].(string)
  10162. project.Pinyin = pinyin
  10163. wubi := projectM["wubi"].(string)
  10164. project.Wubi = wubi
  10165. statistical_classification := projectM["statistical_classification"].(string)
  10166. var statisticalClassification = "统计分类"
  10167. var statistical_classification_id int64
  10168. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10169. if len(statistical_classification) != 0 {
  10170. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10171. if classificationerrcodes == gorm.ErrRecordNotFound {
  10172. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10173. dataconfig := models.DictDataconfig{
  10174. ParentId: classiFication.ID,
  10175. Module: "system",
  10176. OrgId: orgId,
  10177. Name: statistical_classification,
  10178. FieldName: "",
  10179. Value: classiFicationConfig.Value + 1,
  10180. CreatedTime: "",
  10181. UpdatedTime: "",
  10182. CreateUserId: adminUser.AdminUser.Id,
  10183. Status: 1,
  10184. Remark: "",
  10185. DeleteIdSystem: 0,
  10186. Title: "",
  10187. Content: "",
  10188. Order: 0,
  10189. Code: "",
  10190. }
  10191. service.CreatedDicConfig(&dataconfig)
  10192. }
  10193. }
  10194. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10195. for _, it := range classiFicationList {
  10196. if statistical_classification == it.Name {
  10197. statistical_classification_id = int64(it.Value)
  10198. }
  10199. }
  10200. project.StatisticalClassification = statistical_classification_id
  10201. disease_directory := int64(projectM["disease_directory"].(float64))
  10202. project.DiseaseDirectory = disease_directory
  10203. is_record := int64(projectM["is_record"].(float64))
  10204. project.IsRecord = is_record
  10205. medical_code := projectM["medical_code"].(string)
  10206. project.MedicalCode = medical_code
  10207. tube_color := projectM["tube_color"].(string)
  10208. var tubeColor = "试管颜色"
  10209. var tube_color_id int64
  10210. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10211. if len(tube_color) != 0 {
  10212. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10213. if errcodetube == gorm.ErrRecordNotFound {
  10214. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10215. dataconfig := models.DictDataconfig{
  10216. ParentId: tubeColorConfig.ID,
  10217. Module: "system",
  10218. OrgId: orgId,
  10219. Name: tube_color,
  10220. FieldName: "",
  10221. Value: tubeConfig.Value + 1,
  10222. CreatedTime: "",
  10223. UpdatedTime: "",
  10224. CreateUserId: adminUser.AdminUser.Id,
  10225. Status: 1,
  10226. Remark: "",
  10227. DeleteIdSystem: 0,
  10228. Title: "",
  10229. Content: "",
  10230. Order: 0,
  10231. Code: "",
  10232. }
  10233. service.CreatedDicConfig(&dataconfig)
  10234. }
  10235. }
  10236. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10237. for _, it := range tubeColorList {
  10238. if tube_color == it.Name {
  10239. tube_color_id = int64(it.Value)
  10240. }
  10241. }
  10242. project.TubeColor = tube_color_id
  10243. single_dose := projectM["single_dose"].(string)
  10244. project.SingleDose = single_dose
  10245. execution_frequency := projectM["execution_frequency"].(string)
  10246. project.ExecutionFrequency = execution_frequency
  10247. delivery_way := projectM["delivery_way"].(string)
  10248. project.DeliveryWay = delivery_way
  10249. number_days := projectM["number_days"].(string)
  10250. project.NumberDays = number_days
  10251. total := projectM["total"].(string)
  10252. project.Total = total
  10253. medical_status := int64(projectM["medical_status"].(float64))
  10254. project.MedicalStatus = medical_status
  10255. category := int64(projectM["category"].(float64))
  10256. project.Category = category
  10257. specail_project := int64(projectM["specail_project"].(float64))
  10258. project.SpecailProject = specail_project
  10259. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10260. project.SocialSecurityDirectoryCode = social_security_directory_code
  10261. remark := projectM["remark"].(string)
  10262. project.Remark = remark
  10263. record_date := projectM["record_date"].(string)
  10264. timeLayout := "2006-01-02"
  10265. loc, _ := time.LoadLocation("Local")
  10266. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10267. project.RecordDate = theTime.Unix()
  10268. projectList = append(projectList, &project)
  10269. }
  10270. export_time := time.Now().Unix()
  10271. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10272. if len(projectList) > 0 {
  10273. for _, item := range projectList {
  10274. hans := item.ProjectName // 要转换的汉字字符串
  10275. // 创建一个拼音转换器
  10276. p := pinyin.NewArgs()
  10277. // 将汉字转为拼音
  10278. pinyinSlice := pinyin.Pinyin(hans, p)
  10279. // 输出拼音
  10280. fmt.Println("Pinyin:", pinyinSlice)
  10281. // 获取首字母
  10282. firstLetter := ""
  10283. for _, py := range pinyinSlice {
  10284. if len(py) > 0 {
  10285. firstLetter += string(py[0][0])
  10286. }
  10287. }
  10288. item.FirstLetter = firstLetter
  10289. project := models.HisProject{
  10290. ProjectName: item.ProjectName,
  10291. Price: item.Price,
  10292. Unit: item.Unit,
  10293. CostClassify: item.CostClassify,
  10294. ExecutiveSection: item.ExecutiveSection,
  10295. MedicalCoverage: item.MedicalCoverage,
  10296. UserOrgId: orgId,
  10297. Status: 1,
  10298. CreatedTime: time.Now().Unix(),
  10299. Pinyin: item.Pinyin,
  10300. Wubi: item.Wubi,
  10301. StatisticalClassification: item.StatisticalClassification,
  10302. DiseaseDirectory: item.DiseaseDirectory,
  10303. IsRecord: item.IsRecord,
  10304. MedicalCode: item.MedicalCode,
  10305. TubeColor: item.TubeColor,
  10306. SingleDose: item.SingleDose,
  10307. DeliveryWay: item.DeliveryWay,
  10308. NumberDays: item.NumberDays,
  10309. Total: item.Total,
  10310. Category: item.Category,
  10311. MedicalStatus: item.MedicalStatus,
  10312. SpecailProject: item.SpecailProject,
  10313. RecordDate: item.RecordDate,
  10314. Remark: item.Remark,
  10315. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10316. ExecutionFrequency: item.ExecutionFrequency,
  10317. FirstLetter: item.FirstLetter,
  10318. }
  10319. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10320. if errcodeproject == gorm.ErrRecordNotFound {
  10321. service.CreateProjectInfomation(&project)
  10322. } else if errcodeproject == nil {
  10323. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10324. }
  10325. log := models.ExportLog{
  10326. LogType: 6,
  10327. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10328. TotalNum: int64(len(total_goods)),
  10329. FailNum: int64(len(errLogs)),
  10330. SuccessNum: int64(len(projectList)),
  10331. CreateTime: time.Now().Unix(),
  10332. UpdateTime: time.Now().Unix(),
  10333. ExportTime: export_time,
  10334. Status: 1,
  10335. }
  10336. service.CreateExportLog(&log)
  10337. c.ServeSuccessJSON(map[string]interface{}{
  10338. "msg": "导入成功",
  10339. "total_num": len(total_goods),
  10340. "success_num": len(projectList),
  10341. "fail_num": int64(len(errLogs)),
  10342. })
  10343. }
  10344. } else {
  10345. log := models.ExportLog{
  10346. LogType: 6,
  10347. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10348. TotalNum: int64(len(total_goods)),
  10349. FailNum: int64(len(errLogs)),
  10350. SuccessNum: int64(len(projectList)),
  10351. CreateTime: time.Now().Unix(),
  10352. UpdateTime: time.Now().Unix(),
  10353. ExportTime: export_time,
  10354. Status: 1,
  10355. }
  10356. service.CreateExportLog(&log)
  10357. c.ServeSuccessJSON(map[string]interface{}{
  10358. "msg": "导入成功",
  10359. "total_num": len(total_goods),
  10360. "success_num": len(projectList),
  10361. "fail_num": int64(len(errLogs)),
  10362. })
  10363. }
  10364. }
  10365. //func (this *HisApiController) EditProjectInformation(){
  10366. //
  10367. // id, _ := this.GetInt64("id")
  10368. // project_team := this.GetString("project_team")
  10369. // price := this.GetString("price")
  10370. // price_float, _ := strconv.ParseFloat(price, 64)
  10371. // pinyin := this.GetString("pinyin")
  10372. // wubi := this.GetString("wubi")
  10373. // tube_color, _ := this.GetInt64("tube_color")
  10374. // team_type, _ := this.GetInt64("team_type")
  10375. // remark := this.GetString("remark")
  10376. // ids := this.GetString("ids")
  10377. // item_id := this.GetString("item_id")
  10378. // projectTeam := models.XtHisProjectTeam{
  10379. // ProjectTeam: project_team,
  10380. // Price: price_float,
  10381. // Pinyin: pinyin,
  10382. // Wubi: wubi,
  10383. // TubeColor: tube_color,
  10384. // TeamType: team_type,
  10385. // Remark: remark,
  10386. // ProjectId: ids,
  10387. // ItemId: item_id,
  10388. // }
  10389. //
  10390. //
  10391. // dataBody := make(map[string]interface{}, 0)
  10392. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10393. // if err != nil {
  10394. // utils.ErrorLog(err.Error())
  10395. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10396. // return
  10397. // }
  10398. //
  10399. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10400. //
  10401. //
  10402. // if err != nil {
  10403. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10404. // return
  10405. // }
  10406. //
  10407. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10408. // infos, _ := dataBody["info"].([]interface{})
  10409. // if len(infos) > 0 {
  10410. // var ids []string
  10411. //
  10412. // for _, item := range infos {
  10413. // items := item.(map[string]interface{})
  10414. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10415. // utils.ErrorLog("id")
  10416. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10417. // return
  10418. // }
  10419. // id := int64(items["id"].(float64))
  10420. //
  10421. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10422. // utils.ErrorLog("type")
  10423. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10424. // return
  10425. // }
  10426. // types := int64(items["type"].(float64))
  10427. //
  10428. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10429. // utils.ErrorLog("number")
  10430. // }
  10431. //
  10432. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10433. //
  10434. // projectList := models.XtHisProjectList{
  10435. // Number: number,
  10436. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10437. // ProjectId: id,
  10438. // Status: 1,
  10439. // CreatedTime: time.Now().Unix(),
  10440. // UpdatedTime: time.Now().Unix(),
  10441. // TeamId: projectTeam.ID,
  10442. // Type: types,
  10443. // }
  10444. // list := projectList
  10445. //
  10446. // service.CreateProjectList(&list)
  10447. //
  10448. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10449. //
  10450. // }
  10451. // ids_str := strings.Join(ids, ",")
  10452. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10453. // service.SaveProjectTeam(&projectTeam)
  10454. // this.ServeSuccessJSON(map[string]interface{}{
  10455. // "projectTeam": projectTeam,
  10456. // })
  10457. // }
  10458. // }
  10459. //}
  10460. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10461. name := c.GetString("name")
  10462. mode_id, _ := c.GetInt64("mode", 0)
  10463. types, _ := c.GetInt64("type", 0)
  10464. patient_id, _ := c.GetInt64("patient_id", 0)
  10465. types = 1
  10466. adminInfo := c.GetAdminUserInfo()
  10467. template := &models.HisPrescriptionTemplate{
  10468. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10469. PatientId: patient_id,
  10470. Type: types,
  10471. Status: 1,
  10472. Ctime: time.Now().Unix(),
  10473. Mtime: time.Now().Unix(),
  10474. Name: name,
  10475. Mode: mode_id,
  10476. }
  10477. dataBody := make(map[string]interface{}, 0)
  10478. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10479. if err != nil {
  10480. utils.ErrorLog(err.Error())
  10481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10482. return
  10483. }
  10484. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10485. //如果已经存在记录则删除处方
  10486. if template_one.ID > 0 {
  10487. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10488. var ids []int64
  10489. var org_id int64
  10490. for _, item := range ps {
  10491. org_id = c.GetAdminUserInfo().CurrentOrgId
  10492. ids = append(ids, item.ID)
  10493. }
  10494. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10495. if err2 == nil {
  10496. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10497. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10498. if len(prescriptions) > 0 {
  10499. for _, item := range prescriptions {
  10500. items := item.(map[string]interface{})
  10501. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10502. utils.ErrorLog("type")
  10503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10504. return
  10505. }
  10506. types := int64(items["type"].(float64))
  10507. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10508. utils.ErrorLog("med_type")
  10509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10510. return
  10511. }
  10512. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10513. ctime := time.Now().Unix()
  10514. prescription := &models.HisPrescriptionInfoTemplate{
  10515. PatientId: patient_id,
  10516. UserOrgId: adminInfo.CurrentOrgId,
  10517. Ctime: ctime,
  10518. Mtime: ctime,
  10519. Type: types,
  10520. Modifier: adminInfo.AdminUser.Id,
  10521. Creator: adminInfo.AdminUser.Id,
  10522. Status: 1,
  10523. PTemplateId: template_one.ID,
  10524. MedType: med_type,
  10525. }
  10526. service.CreateHisPrescriptionInfoTemplate(prescription)
  10527. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10528. advices := items["advices"].([]interface{})
  10529. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10530. ctime := time.Now().Unix()
  10531. mtime := ctime
  10532. if len(advices) > 0 {
  10533. for _, advice := range advices {
  10534. var s models.HisPrescriptionAdviceTemplate
  10535. s.PrescriptionId = prescription.ID
  10536. s.AdviceType = 2
  10537. s.StopState = 2
  10538. s.ExecutionState = 2
  10539. s.Status = 1
  10540. s.UserOrgId = adminInfo.CurrentOrgId
  10541. s.CreatedTime = ctime
  10542. s.UpdatedTime = mtime
  10543. s.PatientId = patient_id
  10544. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10545. if errcode > 0 {
  10546. c.ServeFailJSONWithSGJErrorCode(errcode)
  10547. return
  10548. }
  10549. service.CreateHisPrescriptionAdviceTemplate(&s)
  10550. }
  10551. }
  10552. }
  10553. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10554. projects := items["project"].([]interface{})
  10555. if len(projects) > 0 {
  10556. for _, project := range projects {
  10557. var p models.HisPrescriptionProjectTemplate
  10558. p.PrescriptionId = prescription.ID
  10559. p.Ctime = time.Now().Unix()
  10560. p.Mtime = time.Now().Unix()
  10561. p.PatientId = patient_id
  10562. p.UserOrgId = adminInfo.CurrentOrgId
  10563. p.Status = 1
  10564. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10565. if errcode > 0 {
  10566. c.ServeFailJSONWithSGJErrorCode(errcode)
  10567. return
  10568. }
  10569. service.CreateHisPrescriptionProjectTemplate(&p)
  10570. }
  10571. }
  10572. }
  10573. }
  10574. c.ServeSuccessJSON(map[string]interface{}{
  10575. "msg": "创建成功",
  10576. })
  10577. }
  10578. }
  10579. } else {
  10580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10581. return
  10582. }
  10583. } else {
  10584. err3 := service.CreateHisPrescriptionTemplate(template)
  10585. if err3 == nil {
  10586. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10587. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10588. if len(prescriptions) > 0 {
  10589. for _, item := range prescriptions {
  10590. items := item.(map[string]interface{})
  10591. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10592. utils.ErrorLog("type")
  10593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10594. return
  10595. }
  10596. types := int64(items["type"].(float64))
  10597. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10598. utils.ErrorLog("med_type")
  10599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10600. return
  10601. }
  10602. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10603. ctime := time.Now().Unix()
  10604. prescription := &models.HisPrescriptionInfoTemplate{
  10605. PatientId: patient_id,
  10606. UserOrgId: adminInfo.CurrentOrgId,
  10607. Ctime: ctime,
  10608. Mtime: ctime,
  10609. Type: types,
  10610. Modifier: adminInfo.AdminUser.Id,
  10611. Creator: adminInfo.AdminUser.Id,
  10612. Status: 1,
  10613. PTemplateId: template.ID,
  10614. MedType: med_type,
  10615. }
  10616. service.CreateHisPrescriptionInfoTemplate(prescription)
  10617. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10618. advices := items["advices"].([]interface{})
  10619. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10620. ctime := time.Now().Unix()
  10621. mtime := ctime
  10622. if len(advices) > 0 {
  10623. for _, advice := range advices {
  10624. var s models.HisPrescriptionAdviceTemplate
  10625. s.PrescriptionId = prescription.ID
  10626. s.AdviceType = 2
  10627. s.StopState = 2
  10628. s.ExecutionState = 2
  10629. s.Status = 1
  10630. s.UserOrgId = adminInfo.CurrentOrgId
  10631. s.CreatedTime = ctime
  10632. s.UpdatedTime = mtime
  10633. s.PatientId = patient_id
  10634. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10635. if errcode > 0 {
  10636. c.ServeFailJSONWithSGJErrorCode(errcode)
  10637. return
  10638. }
  10639. service.CreateHisPrescriptionAdviceTemplate(&s)
  10640. }
  10641. }
  10642. }
  10643. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10644. projects := items["project"].([]interface{})
  10645. if len(projects) > 0 {
  10646. for _, project := range projects {
  10647. var p models.HisPrescriptionProjectTemplate
  10648. p.PrescriptionId = prescription.ID
  10649. p.Ctime = time.Now().Unix()
  10650. p.Mtime = time.Now().Unix()
  10651. p.PatientId = patient_id
  10652. p.UserOrgId = adminInfo.CurrentOrgId
  10653. p.Status = 1
  10654. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10655. if errcode > 0 {
  10656. c.ServeFailJSONWithSGJErrorCode(errcode)
  10657. return
  10658. }
  10659. service.CreateHisPrescriptionProjectTemplate(&p)
  10660. }
  10661. }
  10662. }
  10663. }
  10664. c.ServeSuccessJSON(map[string]interface{}{
  10665. "msg": "创建成功",
  10666. })
  10667. }
  10668. }
  10669. } else {
  10670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10671. return
  10672. }
  10673. }
  10674. }
  10675. func (c *HisApiController) PreSettle() {
  10676. id, _ := c.GetInt64("id")
  10677. record_time := c.GetString("record_time")
  10678. his_patient_id, _ := c.GetInt64("his_patient_id")
  10679. timeLayout := "2006-01-02"
  10680. loc, _ := time.LoadLocation("Local")
  10681. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10682. diagnosis_id := c.GetString("diagnosis")
  10683. sick_type, _ := c.GetInt64("sick_type")
  10684. reg_type, _ := c.GetInt64("p_type")
  10685. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10686. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10687. if err != nil {
  10688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10689. return
  10690. }
  10691. recordDateTime := theTime.Unix()
  10692. adminUser := c.GetAdminUserInfo()
  10693. var prescriptions []*models.HisPrescription
  10694. var start_time int64
  10695. var end_time int64
  10696. ids_str := c.GetString("ids")
  10697. ids_arr := strings.Split(ids_str, ",")
  10698. fmt.Println(reg_type)
  10699. if settle_accounts_type == 1 { //日结
  10700. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10701. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10702. } else {
  10703. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10704. }
  10705. fmt.Println(prescriptions)
  10706. } else { //月结
  10707. start_time_str := c.GetString("start_time")
  10708. end_time_str := c.GetString("end_time")
  10709. timeLayout := "2006-01-02"
  10710. loc, _ := time.LoadLocation("Local")
  10711. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10712. if err != nil {
  10713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10714. return
  10715. }
  10716. recordStartTime := theStartTime.Unix()
  10717. start_time = recordStartTime
  10718. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10719. if err != nil {
  10720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10721. return
  10722. }
  10723. recordEndTime := theEndTime.Unix()
  10724. end_time = recordEndTime
  10725. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10726. }
  10727. if reg_type == 1111 || reg_type == 1112 {
  10728. reg_type = 11
  10729. }
  10730. timestamp := time.Now().Unix()
  10731. tempTime := time.Unix(timestamp, 0)
  10732. timeFormat := tempTime.Format("20060102150405")
  10733. chrgBchno := rand.Intn(100000) + 10000
  10734. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10735. strconv.FormatInt(his.PatientId, 10)
  10736. var ids []int64
  10737. for _, item := range prescriptions {
  10738. ids = append(ids, item.ID)
  10739. }
  10740. fmt.Println(ids)
  10741. var total float64
  10742. for _, item := range prescriptions {
  10743. fmt.Println(item)
  10744. if item.Type == 1 { //药品
  10745. for _, subItem := range item.HisDoctorAdviceInfo {
  10746. total = total + (subItem.Price * subItem.PrescribingNumber)
  10747. }
  10748. }
  10749. if item.Type == 2 { //项目
  10750. for _, subItem := range item.HisPrescriptionProject {
  10751. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10752. total = total + (subItem.Price * cnt)
  10753. }
  10754. }
  10755. for _, subItem := range item.HisAdditionalCharge {
  10756. total = total + (subItem.Price * float64(subItem.Count))
  10757. }
  10758. }
  10759. allTotal := fmt.Sprintf("%.2f", total)
  10760. totals, _ := strconv.ParseFloat(allTotal, 64)
  10761. order := &models.HisOrder{
  10762. UserOrgId: adminUser.CurrentOrgId,
  10763. HisPatientId: his.ID,
  10764. PatientId: id,
  10765. SettleAccountsDate: recordDateTime,
  10766. Ctime: time.Now().Unix(),
  10767. Mtime: time.Now().Unix(),
  10768. Status: 1,
  10769. OrderStatus: 1,
  10770. MdtrtId: his.Number,
  10771. Number: chrg_bchno,
  10772. MedfeeSumamt: totals,
  10773. SettleEndTime: end_time,
  10774. SettleStartTime: start_time,
  10775. SettleType: settle_accounts_type,
  10776. PsnPartAmt: totals,
  10777. PsnCashPay: totals,
  10778. PType: 2,
  10779. IsPre: 1,
  10780. MedType: strconv.Itoa(int(reg_type)),
  10781. Diagnosis: diagnosis_id,
  10782. }
  10783. err = service.CreateOrder(order)
  10784. if err != nil {
  10785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10786. return
  10787. }
  10788. var customs []*Custom
  10789. for _, item := range prescriptions {
  10790. fmt.Println(item.Type)
  10791. if item.Type == 1 { //药品
  10792. for _, subItem := range item.HisDoctorAdviceInfo {
  10793. cus := &Custom{
  10794. AdviceId: subItem.ID,
  10795. ProjectId: 0,
  10796. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10797. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10798. FeedetlSn: subItem.FeedetlSn,
  10799. Price: fmt.Sprintf("%.2f", subItem.Price),
  10800. MedListCodg: subItem.MedListCodg,
  10801. Type: 1,
  10802. }
  10803. customs = append(customs, cus)
  10804. }
  10805. }
  10806. if item.Type == 2 { //项目
  10807. for _, subItem := range item.HisPrescriptionProject {
  10808. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10809. cus := &Custom{
  10810. AdviceId: 0,
  10811. ProjectId: subItem.ID,
  10812. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10813. Cut: fmt.Sprintf("%.2f", cnt),
  10814. FeedetlSn: subItem.FeedetlSn,
  10815. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10816. MedListCodg: subItem.MedListCodg,
  10817. Type: 2,
  10818. }
  10819. customs = append(customs, cus)
  10820. }
  10821. }
  10822. for _, item := range item.HisAdditionalCharge {
  10823. cus := &Custom{
  10824. ItemId: item.ID,
  10825. AdviceId: 0,
  10826. ProjectId: 0,
  10827. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10828. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10829. FeedetlSn: item.FeedetlSn,
  10830. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10831. MedListCodg: item.XtHisAddtionConfig.Code,
  10832. Type: 3,
  10833. }
  10834. customs = append(customs, cus)
  10835. }
  10836. }
  10837. fmt.Println(customs)
  10838. for _, item := range customs {
  10839. var advice_id int64 = 0
  10840. var project_id int64 = 0
  10841. var item_id int64 = 0
  10842. var types int64 = 0
  10843. if item.Type == 1 {
  10844. advice_id = item.AdviceId
  10845. project_id = 0
  10846. item_id = 0
  10847. } else if item.Type == 2 {
  10848. advice_id = 0
  10849. item_id = 0
  10850. project_id = item.ProjectId
  10851. } else if item.Type == 3 {
  10852. advice_id = 0
  10853. item_id = item.ItemId
  10854. project_id = 0
  10855. }
  10856. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10857. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10858. pric, _ := strconv.ParseFloat(item.Price, 32)
  10859. info := &models.HisOrderInfo{
  10860. OrderNumber: order.Number,
  10861. UploadDate: time.Now().Unix(),
  10862. AdviceId: advice_id,
  10863. DetItemFeeSumamt: detItemFeeSumamt,
  10864. Cnt: cut,
  10865. Pric: pric,
  10866. PatientId: id,
  10867. Status: 1,
  10868. Mtime: time.Now().Unix(),
  10869. Ctime: time.Now().Unix(),
  10870. UserOrgId: adminUser.CurrentOrgId,
  10871. HisPatientId: his.ID,
  10872. OrderId: order.ID,
  10873. ProjectId: project_id,
  10874. Type: types,
  10875. ItemId: item_id,
  10876. }
  10877. service.CreateOrderInfo(info)
  10878. }
  10879. his.SickType = sick_type
  10880. service.UpdataHisPateint(&his)
  10881. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10882. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10883. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10884. if err == nil {
  10885. c.ServeSuccessJSON(map[string]interface{}{
  10886. "msg": "结算成功",
  10887. })
  10888. }
  10889. }
  10890. type CustomOrderInfo struct {
  10891. Name string
  10892. Spec string
  10893. Unit string
  10894. Count float64
  10895. Price float64
  10896. Total float64
  10897. }
  10898. func (c *HisApiController) GetPrivateExpensesInfo() {
  10899. order_id, _ := c.GetInt64("id", 0)
  10900. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10901. order, _ := service.GetHisOrderByID(order_id)
  10902. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10903. if order.ID == 0 {
  10904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10905. return
  10906. }
  10907. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10908. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10909. org_id := c.GetAdminUserInfo().CurrentOrgId
  10910. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10911. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10912. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10913. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10914. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10915. //var orderInfos_four []*models.HisOrderInfoTwo
  10916. //for _, item := range orderInfos_three {
  10917. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10918. // item.HisPrescriptionProject.IsCheckTeam = 1
  10919. // orderInfos_four = append(orderInfos_four, item)
  10920. //
  10921. // }
  10922. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10923. // item.HisPrescriptionProject.IsCheckTeam = 2
  10924. // orderInfos_two = append(orderInfos_two, item)
  10925. // }
  10926. //}
  10927. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10928. //var cus_slice []CustomOrderInfo
  10929. //for _, item := range new_order_info {
  10930. // var cus CustomOrderInfo
  10931. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10932. // cus.Unit = ""
  10933. // cus.Spec = ""
  10934. // var total float64
  10935. // for _, subItem := range orderInfos_four {
  10936. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10937. // total = total + subItem.DetItemFeeSumamt
  10938. // fmt.Println(subItem.DetItemFeeSumamt)
  10939. // }
  10940. // }
  10941. // cus.Count = 1
  10942. // cus.Total = total
  10943. // cus_slice = append(cus_slice, cus)
  10944. //}
  10945. orderInfos = append(orderInfos, orderInfos_two...)
  10946. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10947. //orderInfos = append(orderInfos, orderInfos_three...)
  10948. //}/**/
  10949. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10950. c.ServeSuccessJSON(map[string]interface{}{
  10951. "order": order,
  10952. "order_info": orderInfos,
  10953. "patient": patient,
  10954. "admin_info": adminInfo,
  10955. "his": his,
  10956. "current_admin": role,
  10957. "org_config": miConfig,
  10958. //"new_order_info": cus_slice,
  10959. })
  10960. }
  10961. func (this *HisApiController) ChangeMedType() {
  10962. med_type := this.GetString("med_type")
  10963. old_med_type := this.GetString("old_med_type")
  10964. ids := this.GetString("ids")
  10965. settle_type, _ := this.GetInt64("settle_type")
  10966. start_time := this.GetString("start_time")
  10967. end_time := this.GetString("end_time")
  10968. ids_arr := strings.Split(ids, ",")
  10969. if settle_type == 1 { //日结
  10970. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10971. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10972. prescription.MedType = med_type
  10973. err := service.SaveHisPrescriptionTwo(&prescription)
  10974. if err == nil {
  10975. this.ServeSuccessJSON(map[string]interface{}{
  10976. "msg": "修改成功",
  10977. })
  10978. } else {
  10979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10980. return
  10981. }
  10982. } else if settle_type == 2 {
  10983. timeLayout := "2006-01-02"
  10984. loc, _ := time.LoadLocation("Local")
  10985. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10986. if err != nil {
  10987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10988. return
  10989. }
  10990. recordStartTime := theStartTime.Unix()
  10991. start_time_timestamp := recordStartTime
  10992. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10993. if err != nil {
  10994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10995. return
  10996. }
  10997. recordEndTime := theEndTime.Unix()
  10998. end_time_timestamp := recordEndTime
  10999. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11000. if updateErr == nil {
  11001. this.ServeSuccessJSON(map[string]interface{}{
  11002. "msg": "修改成功",
  11003. })
  11004. } else {
  11005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11006. return
  11007. }
  11008. }
  11009. }
  11010. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11011. patient_id, _ := c.GetInt64("patient_id")
  11012. his_patient_id, _ := c.GetInt64("his_patient_id")
  11013. record_date := c.GetString("record_date")
  11014. start_time := c.GetString("start_time")
  11015. end_time := c.GetString("end_time")
  11016. order_status, _ := c.GetInt64("type", 0)
  11017. p_type, _ := c.GetInt64("p_type", 0)
  11018. order_id, _ := c.GetInt64("order_id", 0)
  11019. timeLayout := "2006-01-02"
  11020. loc, _ := time.LoadLocation("Local")
  11021. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11022. if err != nil {
  11023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11024. return
  11025. }
  11026. recordDateTime := theTime.Unix()
  11027. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11028. if err != nil {
  11029. }
  11030. startRecordDateTime := startTime.Unix()
  11031. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11032. if err != nil {
  11033. }
  11034. endRecordDateTime := endTime.Unix()
  11035. admin := c.GetAdminUserInfo()
  11036. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11037. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11038. order, _ := service.GetHisOrderByID(order_id)
  11039. var monthPrescriptions []*models.HisPrescription
  11040. if order_status == 1 || order_status == 0 {
  11041. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11042. } else if order_status == 2 {
  11043. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11044. }
  11045. var settle_total float64
  11046. for _, item := range monthPrescriptions {
  11047. if len(item.HisPrescriptionProject) > 0 {
  11048. for _, subItem := range item.HisPrescriptionProject {
  11049. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11050. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11051. settle_total = settle_total + total
  11052. }
  11053. }
  11054. if len(item.HisDoctorAdviceInfo) > 0 {
  11055. for _, subItem := range item.HisDoctorAdviceInfo {
  11056. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11057. settle_total = settle_total + total
  11058. }
  11059. }
  11060. }
  11061. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11062. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11063. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11064. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11065. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11066. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11067. //获取所有科室信息
  11068. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11069. var dia string
  11070. for _, item := range month_p_info {
  11071. if len(dia) == 0 {
  11072. dia = item.Diagnosis
  11073. } else {
  11074. dia = dia + "," + item.Diagnosis
  11075. }
  11076. }
  11077. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11078. dia_arr = removeEmptyStrings(dia_arr)
  11079. c.ServeSuccessJSON(map[string]interface{}{
  11080. "his_info": his_patient_info,
  11081. "xt_info": xt_patient_info,
  11082. "case_history": case_history,
  11083. "info": patientPrescriptionInfo,
  11084. "last_info": lastPatientPrescriptionInfo,
  11085. "month_prescriptions": monthPrescriptions,
  11086. "order": order,
  11087. "doctors": doctors,
  11088. "department": department,
  11089. "settle_total": settle_total,
  11090. "dia_arr": dia_arr,
  11091. })
  11092. return
  11093. }
  11094. func removeEmptyStrings(input []string) []string {
  11095. var output []string
  11096. for _, s := range input {
  11097. if s != "" {
  11098. output = append(output, s)
  11099. }
  11100. }
  11101. return output
  11102. }
  11103. func removeDuplicates(input []string) []string {
  11104. seen := make(map[string]bool)
  11105. output := []string{}
  11106. for _, s := range input {
  11107. if _, exists := seen[s]; !exists {
  11108. seen[s] = true
  11109. output = append(output, s)
  11110. }
  11111. }
  11112. return output
  11113. }
  11114. func (c *HisApiController) GetHisMonthPatientInfo() {
  11115. patient_id, _ := c.GetInt64("patient_id")
  11116. his_patient_id, _ := c.GetInt64("his_patient_id")
  11117. record_date := c.GetString("record_date")
  11118. number := c.GetString("number")
  11119. start_time := c.GetString("start_time")
  11120. end_time := c.GetString("end_time")
  11121. p_type, _ := c.GetInt64("p_type")
  11122. timeLayout := "2006-01-02"
  11123. loc, _ := time.LoadLocation("Local")
  11124. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11125. if err != nil {
  11126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11127. return
  11128. }
  11129. recordDateTime := theTime.Unix()
  11130. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11131. if err != nil {
  11132. }
  11133. startRecordDateTime := startTime.Unix()
  11134. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11135. if err != nil {
  11136. }
  11137. endRecordDateTime := endTime.Unix()
  11138. admin := c.GetAdminUserInfo()
  11139. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11140. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11141. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11142. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11143. var settle_total float64
  11144. for _, item := range monthPrescriptions {
  11145. if len(item.HisPrescriptionProject) > 0 {
  11146. for _, subItem := range item.HisPrescriptionProject {
  11147. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11148. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11149. settle_total = settle_total + total
  11150. }
  11151. }
  11152. if len(item.HisDoctorAdviceInfo) > 0 {
  11153. for _, subItem := range item.HisDoctorAdviceInfo {
  11154. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11155. settle_total = settle_total + total
  11156. }
  11157. }
  11158. }
  11159. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11160. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11161. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11162. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11163. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11164. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11165. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11166. //获取所有科室信息
  11167. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11168. c.ServeSuccessJSON(map[string]interface{}{
  11169. "his_info": his_patient_info,
  11170. "xt_info": xt_patient_info,
  11171. "case_history": case_history,
  11172. "info": patientPrescriptionInfo,
  11173. "month_prescriptions": monthPrescriptions,
  11174. "order": order,
  11175. "doctors": doctors,
  11176. "department": department,
  11177. "count": count,
  11178. "drugStockConfig": drugStockConfig,
  11179. "last_info": lastPatientPrescriptionInfo,
  11180. "settle_total": settle_total,
  11181. })
  11182. return
  11183. }
  11184. func (c *HisApiController) GetAllOrder() {
  11185. org_id := c.GetAdminUserInfo().CurrentOrgId
  11186. orders, _ := service.GetNewHisOrderList(org_id)
  11187. c.ServeSuccessJSON(map[string]interface{}{
  11188. "order": orders,
  11189. })
  11190. return
  11191. }
  11192. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11193. newArr = make([]*models.HisOrderInfoTwo, 0)
  11194. for i := 0; i < len(arr); i++ {
  11195. repeat := false
  11196. for j := i + 1; j < len(arr); j++ {
  11197. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11198. repeat = true
  11199. break
  11200. }
  11201. }
  11202. if !repeat {
  11203. newArr = append(newArr, arr[i])
  11204. }
  11205. }
  11206. return
  11207. }
  11208. // 修改处方退库操作 参数传修改之前的处方数据
  11209. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11210. if advice.ExecutionState == 1 {
  11211. //查询该病人该药品是否有库存记录
  11212. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11213. if errcode == gorm.ErrRecordNotFound {
  11214. } else {
  11215. //退库
  11216. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11217. if advice.PrescribingNumberUnit == drug.MinUnit {
  11218. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11219. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11220. //退库
  11221. warehouseInfo := models.DrugWarehouseInfo{
  11222. StockMinNumber: prescribingNumber,
  11223. }
  11224. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11225. operation_time := time.Now().Unix()
  11226. creater := advice.AdviceDoctor
  11227. ctime := time.Now().Unix()
  11228. timeStr := time.Now().Format("2006-01-02")
  11229. timeArr := strings.Split(timeStr, "-")
  11230. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11231. total = total + 1
  11232. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11233. cancelStock := models.DrugCancelStock{
  11234. OrderNumber: orderNumber,
  11235. OperaTime: operation_time,
  11236. OrgId: advice.UserOrgId,
  11237. Creater: creater,
  11238. Ctime: ctime,
  11239. Status: 1,
  11240. ReturnTime: advice.AdviceDate,
  11241. Dealer: info.Dealer,
  11242. Manufacturer: info.Manufacturer,
  11243. Type: 1,
  11244. }
  11245. service.AddSigleDrugCancelStock(&cancelStock)
  11246. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11247. dealer, _ := service.GetDealerById(info.Dealer)
  11248. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11249. cancelStockInfo := models.DrugCancelStockInfo{
  11250. OrderNumber: cancelInfo.OrderNumber,
  11251. CancelStockId: cancelInfo.ID,
  11252. DrugId: info.DrugId,
  11253. Count: info.Count,
  11254. Status: 1,
  11255. Ctime: ctime,
  11256. OrgId: advice.UserOrgId,
  11257. Type: 1,
  11258. Manufacturer: manufactureName.ManufacturerName,
  11259. Dealer: dealer.DealerName,
  11260. Total: 0,
  11261. RetailPrice: info.RetailPrice,
  11262. RetailTotalPrice: info.RetailTotalPrice,
  11263. Price: info.Price,
  11264. RegisterAccount: "",
  11265. Remark: info.Remark,
  11266. BatchNumber: info.BatchNumber,
  11267. MaxUnit: info.CountUnit,
  11268. ProductDate: info.ProductDate,
  11269. ExpiryDate: info.ExpiryDate,
  11270. BatchNumberId: info.WarehouseInfoId,
  11271. }
  11272. flow := models.DrugFlow{
  11273. WarehousingId: 0,
  11274. DrugId: info.DrugId,
  11275. Number: "",
  11276. BatchNumber: info.BatchNumber,
  11277. Count: info.Count,
  11278. UserOrgId: advice.UserOrgId,
  11279. PatientId: 0,
  11280. SystemTime: ctime,
  11281. ConsumableType: 4,
  11282. IsSys: 0,
  11283. WarehousingOrder: "",
  11284. WarehouseOutId: 0,
  11285. WarehouseOutOrderNumber: "",
  11286. IsEdit: 0,
  11287. CancelStockId: cancelStock.ID,
  11288. CancelOrderNumber: cancelStock.OrderNumber,
  11289. Manufacturer: info.Manufacturer,
  11290. Dealer: info.Dealer,
  11291. Creator: advice.UserOrgId,
  11292. UpdateCreator: 0,
  11293. Status: 1,
  11294. Ctime: time.Now().Unix(),
  11295. Mtime: 0,
  11296. Price: info.Price,
  11297. WarehousingDetailId: 0,
  11298. WarehouseOutDetailId: 0,
  11299. CancelOutDetailId: 0,
  11300. ExpireDate: info.ExpiryDate,
  11301. ProductDate: info.ProductDate,
  11302. MaxUnit: info.CountUnit,
  11303. MinUnit: "",
  11304. }
  11305. service.CreatedCancelStock(cancelStockInfo)
  11306. service.CreateDrugFlowOne(flow)
  11307. } else {
  11308. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11309. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11310. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11311. warehouseInfo := models.DrugWarehouseInfo{
  11312. StockMinNumber: prescribingNumber,
  11313. }
  11314. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11315. }
  11316. operation_time := time.Now().Unix()
  11317. creater := advice.AdviceDoctor
  11318. ctime := time.Now().Unix()
  11319. timeStr := time.Now().Format("2006-01-02")
  11320. timeArr := strings.Split(timeStr, "-")
  11321. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11322. total = total + 1
  11323. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11324. cancelStock := models.DrugCancelStock{
  11325. OrderNumber: orderNumber,
  11326. OperaTime: operation_time,
  11327. OrgId: advice.UserOrgId,
  11328. Creater: creater,
  11329. Ctime: ctime,
  11330. Status: 1,
  11331. ReturnTime: advice.AdviceDate,
  11332. Dealer: info.Dealer,
  11333. Manufacturer: info.Manufacturer,
  11334. Type: 1,
  11335. }
  11336. service.AddSigleDrugCancelStock(&cancelStock)
  11337. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11338. dealer, _ := service.GetDealerById(info.Dealer)
  11339. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11340. cancelStockInfo := models.DrugCancelStockInfo{
  11341. OrderNumber: cancelInfo.OrderNumber,
  11342. CancelStockId: cancelInfo.ID,
  11343. DrugId: info.DrugId,
  11344. Count: info.Count,
  11345. Status: 1,
  11346. Ctime: ctime,
  11347. OrgId: advice.UserOrgId,
  11348. Type: 1,
  11349. Manufacturer: manufactureName.ManufacturerName,
  11350. Dealer: dealer.DealerName,
  11351. Total: 0,
  11352. RetailPrice: info.RetailPrice,
  11353. RetailTotalPrice: info.RetailTotalPrice,
  11354. Price: info.Price,
  11355. RegisterAccount: "",
  11356. Remark: info.Remark,
  11357. BatchNumber: info.BatchNumber,
  11358. MaxUnit: info.CountUnit,
  11359. ProductDate: info.ProductDate,
  11360. ExpiryDate: info.ExpiryDate,
  11361. BatchNumberId: info.WarehouseInfoId,
  11362. }
  11363. flow := models.DrugFlow{
  11364. WarehousingId: 0,
  11365. DrugId: info.DrugId,
  11366. Number: "",
  11367. BatchNumber: info.BatchNumber,
  11368. Count: info.Count,
  11369. UserOrgId: advice.UserOrgId,
  11370. PatientId: 0,
  11371. SystemTime: ctime,
  11372. ConsumableType: 4,
  11373. IsSys: 0,
  11374. WarehousingOrder: "",
  11375. WarehouseOutId: 0,
  11376. WarehouseOutOrderNumber: "",
  11377. IsEdit: 0,
  11378. CancelStockId: cancelStock.ID,
  11379. CancelOrderNumber: cancelStock.OrderNumber,
  11380. Manufacturer: info.Manufacturer,
  11381. Dealer: info.Dealer,
  11382. Creator: advice.AdviceDoctor,
  11383. UpdateCreator: 0,
  11384. Status: 1,
  11385. Ctime: time.Now().Unix(),
  11386. Mtime: 0,
  11387. Price: info.Price,
  11388. WarehousingDetailId: 0,
  11389. WarehouseOutDetailId: 0,
  11390. CancelOutDetailId: 0,
  11391. ExpireDate: info.ExpiryDate,
  11392. ProductDate: info.ProductDate,
  11393. MaxUnit: info.CountUnit,
  11394. MinUnit: "",
  11395. }
  11396. service.CreatedCancelStock(cancelStockInfo)
  11397. service.CreateDrugFlowOne(flow)
  11398. }
  11399. }
  11400. }
  11401. return err
  11402. }
  11403. func (this *HisApiController) DeleteNCDS() {
  11404. id, _ := this.GetInt64("id", 0)
  11405. if id > 0 {
  11406. service.DeletePsnNCDSRecordById(id)
  11407. this.ServeSuccessJSON(map[string]interface{}{
  11408. "msg": "删除成功",
  11409. })
  11410. } else {
  11411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11412. return
  11413. }
  11414. }
  11415. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11416. id, _ := c.GetInt64("id")
  11417. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11418. c.ServeSuccessJSON(map[string]interface{}{
  11419. "advice": advice,
  11420. })
  11421. return
  11422. }
  11423. func (c *HisApiController) GetHisMonthChargePatientList() {
  11424. record_date := c.GetString("record_date")
  11425. start_time := c.GetString("start_time")
  11426. end_time := c.GetString("end_time")
  11427. timeLayout := "2006-01-02"
  11428. loc, _ := time.LoadLocation("Local")
  11429. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11430. if err != nil {
  11431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11432. return
  11433. }
  11434. if err != nil {
  11435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11436. return
  11437. }
  11438. recordDateTime := theTime.Unix()
  11439. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11440. if err != nil {
  11441. }
  11442. startRecordDateTime := startTime.Unix()
  11443. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11444. if err != nil {
  11445. }
  11446. endRecordDateTime := endTime.Unix()
  11447. adminInfo := c.GetAdminUserInfo()
  11448. var tempMonthChargePatients []*service.MonthChargePatients
  11449. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11450. for _, item := range tempPatients {
  11451. //过滤没有处方的
  11452. if len(item.HisPrescription) == 0 {
  11453. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11454. }
  11455. }
  11456. c.ServeSuccessJSON(map[string]interface{}{
  11457. "list": tempMonthChargePatients,
  11458. })
  11459. }
  11460. // PrescriptionDifference 医嘱数量差值结构体
  11461. type PrescriptionDrugDifference struct {
  11462. DrugID int64 //基础库药品id
  11463. ID int64 //医嘱id
  11464. Difference float64 //差值
  11465. Unit string //单位
  11466. }
  11467. type PrescriptionGoodDifference struct {
  11468. GoodID int64 //基础库项目耗材id
  11469. ID int64 //医嘱id
  11470. Difference int64 //差值
  11471. Unit string //单位
  11472. Type int64 //类型
  11473. }
  11474. type EditCustomData struct {
  11475. adviceList []*models.HisDoctorAdviceInfo
  11476. projectList []*models.HisPrescriptionProject
  11477. }
  11478. type SrcCustomData struct {
  11479. adviceList []*models.HisDoctorAdviceInfo
  11480. projectList []*models.HisPrescriptionProject
  11481. }
  11482. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11483. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11484. differences := make([]*PrescriptionDrugDifference, 0)
  11485. // 创建一个 map 来存储第一个切片中的药品信息
  11486. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11487. for _, advice := range firstPrescription {
  11488. firstMap[advice.DrugId] = advice
  11489. }
  11490. // 遍历第二个切片中的药品信息,并比较数量差值
  11491. for _, advice := range secondPrescription {
  11492. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11493. diff := &PrescriptionDrugDifference{
  11494. DrugID: advice.DrugId,
  11495. ID: firstAdvice.ID,
  11496. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11497. Unit: firstAdvice.PrescribingNumberUnit,
  11498. }
  11499. differences = append(differences, diff)
  11500. }
  11501. }
  11502. return differences
  11503. }
  11504. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11505. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11506. differences := make([]*PrescriptionGoodDifference, 0)
  11507. // 创建一个 map 来存储第一个切片中的耗材信息
  11508. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11509. for _, good := range firstPrescription {
  11510. firstMap[good.ProjectId] = good
  11511. }
  11512. // 遍历第二个切片中的耗材信息,并比较数量差值
  11513. for _, good := range secondPrescription {
  11514. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11515. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11516. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11517. diff := &PrescriptionGoodDifference{
  11518. GoodID: good.ProjectId,
  11519. ID: firstGood.ID,
  11520. Difference: count - firstCount,
  11521. Unit: firstGood.Unit,
  11522. Type: firstGood.Type,
  11523. }
  11524. differences = append(differences, diff)
  11525. }
  11526. }
  11527. return differences
  11528. }
  11529. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11530. var adviceList []*models.HisDoctorAdviceInfo
  11531. var projectList []*models.HisPrescriptionProject
  11532. var advice_ids []int64
  11533. var project_ids []int64
  11534. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11535. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11536. //var tempPrescription *models.HisPrescriptionProjectscription
  11537. if len(prescriptions) > 0 {
  11538. for _, item := range prescriptions {
  11539. items := item.(map[string]interface{})
  11540. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11541. advices := items["advices"].([]interface{})
  11542. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11543. groupNo := int64(0)
  11544. ctime := time.Now().Unix()
  11545. mtime := ctime
  11546. if len(advices) > 0 {
  11547. for _, advice := range advices {
  11548. var s models.HisDoctorAdviceInfo
  11549. s.AdviceType = 2
  11550. s.StopState = 2
  11551. s.ExecutionState = 2
  11552. s.Status = 1
  11553. s.Groupno = groupNo
  11554. s.CreatedTime = ctime
  11555. s.UpdatedTime = mtime
  11556. s.IsSettle = 2
  11557. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11558. //存储切片中
  11559. if s.ID > 0 {
  11560. advice_ids = append(advice_ids, s.ID)
  11561. adviceList = append(adviceList, &s)
  11562. }
  11563. }
  11564. }
  11565. }
  11566. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11567. projects := items["project"].([]interface{})
  11568. if len(projects) > 0 {
  11569. for _, project := range projects {
  11570. var p models.HisPrescriptionProject
  11571. p.Ctime = time.Now().Unix()
  11572. p.Mtime = time.Now().Unix()
  11573. p.Status = 1
  11574. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11575. if p.ID > 0 {
  11576. project_ids = append(project_ids, p.ID)
  11577. projectList = append(projectList, &p)
  11578. }
  11579. }
  11580. }
  11581. }
  11582. }
  11583. }
  11584. }
  11585. editCustomData.projectList = projectList
  11586. editCustomData.adviceList = adviceList
  11587. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11588. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11589. srcCustomData.adviceList = list
  11590. srcCustomData.projectList = list2
  11591. return
  11592. }