his_api_controller.go 505KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993
  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/shopspring/decimal"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. if number >= 1000 {
  187. zero = "0000" + strconv.FormatInt(number, 10)
  188. } else if number >= 10000 {
  189. zero = "000" + strconv.FormatInt(number, 10)
  190. } else if number >= 100000 {
  191. zero = "00" + strconv.FormatInt(number, 10)
  192. } else if number >= 1000000 {
  193. zero = "0" + strconv.FormatInt(number, 10)
  194. } else {
  195. zero = strconv.FormatInt(number, 10)
  196. }
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. order.PsnCashPay = order.MedfeeSumamt
  1021. for _, item := range orderInfos {
  1022. if item.MedChrgitmType == "01" { //床位费
  1023. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1024. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1025. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1026. }
  1027. if item.MedChrgitmType == "02" { //诊察费
  1028. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1029. //zhenChaCostSelfTotal = zhenChaCostTotal
  1030. }
  1031. if item.MedChrgitmType == "03" { //检查费
  1032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //检查费
  1037. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "04" { //化验费
  1042. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "05" { //治疗费
  1047. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "06" { //手术费
  1052. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1057. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "09" { //西药费
  1062. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1064. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1065. }
  1066. if item.MedChrgitmType == "11" { //中成费
  1067. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. }
  1071. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1072. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. }
  1076. }
  1077. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1078. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1080. var dia_config []*models.HisXtDiagnoseConfig
  1081. var diagnosis_ids []string
  1082. if his.ID > 0 {
  1083. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1084. } else {
  1085. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1086. }
  1087. for _, item := range diagnosis_ids {
  1088. id, _ := strconv.ParseInt(item, 10, 64)
  1089. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1090. dia_config = append(dia_config, diagnosisConfig)
  1091. }
  1092. var rf []CustomFundPay
  1093. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1094. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "patient": patient,
  1097. "order_infos": orderInfos,
  1098. "diagnosis": name,
  1099. "bedCostTotal": bedCostTotal,
  1100. "bedCostSelfTotal": bedCostTotal,
  1101. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1102. "operationCostTotal": operationCostTotal,
  1103. "operationCostSelfTotal": operationCostTotal,
  1104. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1105. "otherCostTotal": otherCostTotal,
  1106. "otherCostSelfTotal": otherCostTotal,
  1107. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1108. "materialCostTotal": materialCostTotal,
  1109. "materialCostSelfTotal": materialCostTotal,
  1110. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1111. "westernMedicineCostTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1117. "checkCostTotal": checkCostTotal,
  1118. "checkCostSelfTotal": checkCostTotal,
  1119. "zhenChaCostTotal": zhenChaCostTotal,
  1120. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1121. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1122. "laboratoryCostTotal": laboratoryCostTotal,
  1123. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1124. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1125. "treatCostTotal": treatCostTotal,
  1126. "treatCostSelfTotal": treatCostTotal,
  1127. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1128. "charge_admin": charge_admin,
  1129. "printor_admin": printor_admin,
  1130. "org_name": org.OrgName,
  1131. "org_code": miConfig.Code,
  1132. "name": patient.Name,
  1133. "number": order.MdtrtId,
  1134. "date": order.SettleAccountsDate,
  1135. "info": order,
  1136. "new_order": order,
  1137. "his_hospital": his_hospital,
  1138. "his": his,
  1139. "funds": rf,
  1140. "dia_config": dia_config,
  1141. })
  1142. }
  1143. func (c *HisApiController) RefudDetail() {
  1144. order_id, _ := c.GetInt64("order_id")
  1145. order, _ := service.GetHisOrderByID(order_id)
  1146. adminUser := c.GetAdminUserInfo()
  1147. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "msg": "撤销成功",
  1150. })
  1151. }
  1152. func (c *HisApiController) Sscard() {
  1153. //r := CardInit()
  1154. //if r == 0 {
  1155. // GetBaseInfo()
  1156. //}
  1157. //c.ServeSuccessJSON(map[string]interface{}{
  1158. // "list": "11",
  1159. //})
  1160. }
  1161. func GetBaseInfo() error {
  1162. //handle := syscall.MustLoadDLL("SSCard.dll")
  1163. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1164. //
  1165. //str := make([]byte, 256)
  1166. //str1 := make([]byte, 256)
  1167. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1168. //if ferr != nil {
  1169. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1170. // return ferr
  1171. //}
  1172. //
  1173. //fmt.Println(string(str))
  1174. //
  1175. //fmt.Println(r)
  1176. return nil
  1177. }
  1178. func CardInit() int {
  1179. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1180. //add := DllTestDef.MustFindProc("Init")
  1181. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1182. //if err != nil {
  1183. // fmt.Println("SSCard的运算结果为:", ret)
  1184. //}
  1185. //result := int(ret)
  1186. return 0
  1187. }
  1188. func IntPtr(n int) uintptr {
  1189. return uintptr(n)
  1190. }
  1191. func StrPtr(s string) uintptr {
  1192. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1193. }
  1194. func (c *HisApiController) GetHisPatientList() {
  1195. //types, _ := c.GetInt64("type", 0)
  1196. record_date := c.GetString("record_date")
  1197. sch_type, _ := c.GetInt64("sch_type")
  1198. timeLayout := "2006-01-02"
  1199. loc, _ := time.LoadLocation("Local")
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. recordDateTime := theTime.Unix()
  1206. adminInfo := c.GetAdminUserInfo()
  1207. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1208. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1209. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1210. //获取当前用户的信息
  1211. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1212. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1213. //获取所有科室信息
  1214. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "list": patients,
  1217. "list_two": patients_two,
  1218. "info": adminUserInfo,
  1219. "doctors": doctors,
  1220. "department": department,
  1221. })
  1222. }
  1223. type CustomTemplate struct {
  1224. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1225. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1228. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1229. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1230. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1231. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1232. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1235. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1236. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1237. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1238. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1239. }
  1240. func (c *HisApiController) GetHisPatientInfo() {
  1241. patient_id, _ := c.GetInt64("patient_id")
  1242. his_patient_id, _ := c.GetInt64("his_patient_id")
  1243. record_date := c.GetString("record_date")
  1244. number := c.GetString("number")
  1245. //start_time := c.GetString("start_time")
  1246. //end_time := c.GetString("end_time")
  1247. p_type, _ := c.GetInt64("p_type")
  1248. timeLayout := "2006-01-02"
  1249. loc, _ := time.LoadLocation("Local")
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. recordDateTime := theTime.Unix()
  1256. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1257. //if err != nil {
  1258. //
  1259. //}
  1260. //startRecordDateTime := startTime.Unix()
  1261. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1262. //if err != nil {
  1263. //
  1264. //}
  1265. //endRecordDateTime := endTime.Unix()
  1266. admin := c.GetAdminUserInfo()
  1267. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1271. var prescriptions []*models.HisPrescription
  1272. var last_prescriptions []*models.HisPrescription
  1273. var sch_prescriptions []CustomTemplate
  1274. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1275. if p_type == 1 { //住院
  1276. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1277. for _, item := range prescriptions {
  1278. for _, subItem := range item.HisDoctorAdviceInfo {
  1279. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1280. if info.RetailPrice > 0 {
  1281. subItem.Drug.MinPrice = info.RetailPrice
  1282. }
  1283. }
  1284. }
  1285. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1286. } else { //门诊
  1287. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1288. for _, item := range prescriptions {
  1289. for _, subItem := range item.HisDoctorAdviceInfo {
  1290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1291. if info.RetailPrice > 0 {
  1292. subItem.Drug.MinPrice = info.RetailPrice
  1293. }
  1294. }
  1295. }
  1296. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1297. }
  1298. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1299. if sch.ID > 0 {
  1300. var week string
  1301. t := time.Now()
  1302. switch t.Weekday().String() {
  1303. case "Monday":
  1304. week = "周一"
  1305. break
  1306. case "Tuesday":
  1307. week = "周二"
  1308. break
  1309. case "Wednesday":
  1310. week = "周三"
  1311. break
  1312. case "Thursday":
  1313. week = "周四"
  1314. break
  1315. case "Friday":
  1316. week = "周五"
  1317. break
  1318. case "Saturday":
  1319. week = "周六"
  1320. break
  1321. case "Sunday":
  1322. week = "周日"
  1323. break
  1324. }
  1325. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1326. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1327. //根据推送频率组装新的数组
  1328. for _, item := range temp_sch_prescriptions {
  1329. var cus CustomTemplate
  1330. cus.ID = item.ID
  1331. cus.UserOrgId = item.UserOrgId
  1332. cus.PatientId = item.PatientId
  1333. cus.MedType = item.MedType
  1334. cus.RecordDate = item.RecordDate
  1335. cus.Type = item.Type
  1336. cus.PType = item.PType
  1337. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1338. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1339. if subItem.FrequencyType == 1 { //每次必推
  1340. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 { //按照天数频率
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1353. if len(advices) == 0 {
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. }
  1359. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1360. if subItem.Type == 2 {
  1361. if subItem.XtHisProject.MedicalStatus != 1 {
  1362. if subItem.FrequencyType == 1 {
  1363. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1364. }
  1365. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 2 {
  1369. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1370. now := p.Unix()
  1371. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1372. dayStr2 := "-" + dayStr
  1373. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1374. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1375. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1376. if len(projects) == 0 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. }
  1380. }
  1381. } else if subItem.Type == 3 {
  1382. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1383. if subItem.FrequencyType == 1 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 2 {
  1390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1391. now := p.Unix()
  1392. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1393. dayStr2 := "-" + dayStr
  1394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1396. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1397. if len(projects) == 0 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. sch_prescriptions = append(sch_prescriptions, cus)
  1405. }
  1406. for _, item := range sch_prescriptions {
  1407. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1408. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1409. }
  1410. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1411. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1412. }
  1413. }
  1414. }
  1415. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1416. if config.ID > 0 && config.IsOpen == 1 {
  1417. for _, item := range sch_prescriptions {
  1418. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1419. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1420. if info.RetailPrice > 0 {
  1421. subItem.Drug.MinPrice = info.RetailPrice
  1422. }
  1423. }
  1424. }
  1425. }
  1426. if config.ID > 0 && config.IsOpen == 1 {
  1427. for _, item := range sch_prescriptions {
  1428. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1429. if subItem.Type == 3 {
  1430. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1431. if info.Price > 0 {
  1432. subItem.GoodInfo.PackingPrice = info.Price
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1439. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1440. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1441. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1442. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1443. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1444. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1445. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1446. //获取所有科室信息
  1447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1448. c.ServeSuccessJSON(map[string]interface{}{
  1449. "his_info": his_patient_info,
  1450. "xt_info": xt_patient_info,
  1451. "prescription": prescriptions,
  1452. "case_history": case_history,
  1453. "info": patientPrescriptionInfo,
  1454. //"month_prescriptions": monthPrescriptions,
  1455. "order": order,
  1456. "doctors": doctors,
  1457. "department": department,
  1458. "sch_prescriptions": sch_prescriptions,
  1459. "last_prescriptions": last_prescriptions,
  1460. "schedule": sch,
  1461. "count": count,
  1462. "drugStockConfig": drugStockConfig,
  1463. "last_info": lastPatientPrescriptionInfo,
  1464. })
  1465. return
  1466. }
  1467. func (c *HisApiController) GetHisPrescriptionConfig() {
  1468. adminInfo := c.GetAdminUserInfo()
  1469. //获取医嘱模版
  1470. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1472. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1473. //获取所有基础药
  1474. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1475. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1476. if config.ID > 0 && config.IsOpen == 1 {
  1477. for _, item := range drugs {
  1478. var index = 0
  1479. for _, subItem := range item.OtherDrugWarehouseInfo {
  1480. if index == 0 {
  1481. index = index + 1
  1482. if subItem.RetailPrice > 0 {
  1483. item.MinPrice = subItem.RetailPrice
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1490. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1491. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1492. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1493. //获取所有科室信息
  1494. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1495. //获取诊断信息
  1496. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1497. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1498. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1499. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1500. //获取是否开启保存耗材出库的开关
  1501. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "drugs": drugs,
  1504. "advices_template": advices,
  1505. "drugways": drugways,
  1506. "efs": efs,
  1507. "doctors": doctors,
  1508. "department": department,
  1509. "sick": sick,
  1510. "additions": additions,
  1511. "diagnose": diagnose,
  1512. "manufacturers": manufacturers,
  1513. "goodOutOpen": goodOutOpen,
  1514. "patientDiagnose": patientDiagnose,
  1515. })
  1516. }
  1517. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1518. //获取所有基础药
  1519. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1520. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1521. if config.ID > 0 && config.IsOpen == 1 {
  1522. for _, item := range drugs {
  1523. var index = 0
  1524. for _, subItem := range item.OtherDrugWarehouseInfo {
  1525. if index == 0 {
  1526. index = index + 1
  1527. if subItem.RetailPrice > 0 {
  1528. item.MinPrice = subItem.RetailPrice
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1535. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1536. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1537. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1538. //获取所有科室信息
  1539. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1540. //获取诊断信息
  1541. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1542. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1543. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1544. //获取是否开启保存耗材出库的开关
  1545. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1546. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "drugs": drugs,
  1549. "advices_template": advices,
  1550. "drugways": drugways,
  1551. "efs": efs,
  1552. "doctors": doctors,
  1553. "department": department,
  1554. "sick": sick,
  1555. "additions": additions,
  1556. "diagnose": diagnose,
  1557. "manufacturers": manufacturers,
  1558. "goodOutOpen": goodOutOpen,
  1559. "patientDiagnose": patientDiagnose,
  1560. })
  1561. }
  1562. }
  1563. func (c *HisApiController) CreateHisPrescription() {
  1564. record_date := c.GetString("record_date")
  1565. patient_id, _ := c.GetInt64("patient_id")
  1566. reg_type, _ := c.GetInt64("reg_type")
  1567. diagnose := c.GetString("diagnose")
  1568. sick_type, _ := c.GetInt64("sick_type")
  1569. sick_history := c.GetString("sick_history")
  1570. doctor_id, _ := c.GetInt64("doctor", 0)
  1571. department, _ := c.GetInt64("department", 0)
  1572. his_patient_id, _ := c.GetInt64("his_patient_id")
  1573. p_type, _ := c.GetInt64("p_type")
  1574. patient_diagnose := c.GetString("patient_diagnose")
  1575. dataBody := make(map[string]interface{}, 0)
  1576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1577. if err != nil {
  1578. utils.ErrorLog(err.Error())
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. //edit, src := GetCompareData(dataBody)
  1583. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1584. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1585. //fmt.Println(drugResult)
  1586. //fmt.Println(goodResult)
  1587. timeLayout := "2006-01-02"
  1588. loc, _ := time.LoadLocation("Local")
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. if err != nil {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminInfo := c.GetAdminUserInfo()
  1595. recordDateTime := theTime.Unix()
  1596. //查询默认出库仓库库存
  1597. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1598. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1599. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1600. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1601. if len(lists) == 1 {
  1602. his_patient_id = lists[0].ID
  1603. }
  1604. }
  1605. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1606. //保存处方出库
  1607. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1608. //自动出库
  1609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1610. //耗材保存处方出库
  1611. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1612. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. //已发药和已收费限制逻辑
  1614. isMidicine := false
  1615. isCharge := false
  1616. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1617. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1618. if len(prescriptions) > 0 {
  1619. for _, item := range prescriptions {
  1620. items := item.(map[string]interface{})
  1621. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1622. utils.ErrorLog("id")
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. id := int64(items["id"].(float64))
  1627. if id > 0 {
  1628. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. if new_prescription.OrderStatus == 4 {
  1631. isCharge = true
  1632. }
  1633. }
  1634. }
  1635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1636. advices := items["advices"].([]interface{})
  1637. if len(advices) > 0 {
  1638. for _, advice := range advices {
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1641. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1642. }
  1643. if adviceId > 0 {
  1644. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1645. if err == nil {
  1646. if his_advice_info.IsMedicine == 1 {
  1647. isMidicine = true
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1706. return
  1707. }
  1708. //查询药品的所有库存
  1709. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1710. var total_count int64
  1711. for _, it := range list {
  1712. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1713. }
  1714. totals := strconv.FormatInt(total_count, 10)
  1715. //查询该药品是否存在开药记录
  1716. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1717. //新增处方
  1718. if advicelist.ID == 0 {
  1719. all_count, _ := strconv.ParseFloat(totals, 64)
  1720. if prescribingNumberUnit == drug.MinUnit {
  1721. if drug.IsUse != 1 {
  1722. if drug.IsProject == 0 || drug.IsProject == 2 {
  1723. if all_count == 0 {
  1724. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1725. return
  1726. }
  1727. if prescribing_number > all_count {
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1729. return
  1730. }
  1731. }
  1732. }
  1733. }
  1734. if prescribingNumberUnit == drug.MaxUnit {
  1735. num := prescribing_number * float64(drug.MinNumber)
  1736. if drug.IsUse != 1 {
  1737. if drug.IsProject == 0 || drug.IsProject == 2 {
  1738. if all_count == 0 {
  1739. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1740. return
  1741. }
  1742. if num > all_count {
  1743. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1744. return
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1751. if drugOutConfig.IsOpen != 1 {
  1752. //修改处方
  1753. for _, advice := range advices {
  1754. var drug_id int64
  1755. var prescribing_number float64
  1756. var prescribingNumberUnit string
  1757. var prescribingNumber string
  1758. var adviceId int64
  1759. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1760. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1761. }
  1762. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1763. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1764. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1765. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1768. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1769. }
  1770. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1771. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1772. }
  1773. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1774. if drug.ID == 0 {
  1775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1776. return
  1777. }
  1778. //查询药品的所有库存
  1779. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1780. var total_count int64
  1781. for _, it := range list {
  1782. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1783. }
  1784. totals := strconv.FormatInt(total_count, 10)
  1785. //查询该药品是否存在开药记录
  1786. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1787. //新增处方
  1788. if advicelist.ID == 0 {
  1789. all_count, _ := strconv.ParseFloat(totals, 64)
  1790. if prescribingNumberUnit == drug.MinUnit {
  1791. if drug.IsUse != 1 {
  1792. if drug.IsProject == 0 || drug.IsProject == 2 {
  1793. if all_count == 0 {
  1794. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1795. return
  1796. }
  1797. if prescribing_number > all_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1799. return
  1800. }
  1801. }
  1802. }
  1803. } else {
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. num := prescribing_number * float64(drug.MinNumber)
  1806. if drug.IsUse != 1 {
  1807. if drug.IsProject == 0 || drug.IsProject == 2 {
  1808. if all_count == 0 {
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1810. return
  1811. }
  1812. if num > all_count {
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. //修改处方
  1822. if advicelist.ID > 0 {
  1823. var device_number int64
  1824. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1825. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1826. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1827. device_number = prescribingNumberInt * drug.MinNumber
  1828. }
  1829. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1830. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1831. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1832. device_number = prescribingNumberInt
  1833. }
  1834. var number_count int64
  1835. if prescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1837. number_count = prescribingNumberInt * drug.MinNumber
  1838. }
  1839. if prescribingNumberUnit == drug.MinUnit {
  1840. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1841. number_count = prescribingNumberInt
  1842. }
  1843. //如果修改的数量大于之前修改的数量
  1844. if (number_count - device_number) > 0 {
  1845. //如果修改的差数量 大于库存数量
  1846. if drug.IsUse != 1 {
  1847. if (number_count - device_number) > total_count {
  1848. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1849. return
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. //已发药和已收费限制逻辑
  1864. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1865. //校验库存总量
  1866. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1867. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1868. if len(prescriptions) > 0 {
  1869. for _, item := range prescriptions {
  1870. items := item.(map[string]interface{})
  1871. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1872. advices := items["advices"].([]interface{})
  1873. if len(advices) > 0 {
  1874. for _, advice := range advices {
  1875. var drug_id int64
  1876. var prescribing_number float64
  1877. var prescribingNumberUnit string
  1878. var adviceId int64
  1879. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1880. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1881. }
  1882. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1883. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1884. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1885. }
  1886. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1887. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1888. }
  1889. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1890. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1891. }
  1892. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1893. if drug.ID == 0 {
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1895. return
  1896. }
  1897. //查询药品的所有库存
  1898. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1899. var total_count int64
  1900. for _, it := range list {
  1901. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1902. }
  1903. totals := strconv.FormatInt(total_count, 10)
  1904. //查询该药品是否存在开药记录
  1905. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1906. //查询最新批次库存
  1907. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1908. var batch_number_count int64
  1909. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1910. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1911. //新增处方
  1912. if advicelist.ID == 0 {
  1913. all_count, _ := strconv.ParseFloat(totals, 64)
  1914. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1915. if prescribingNumberUnit == drug.MinUnit {
  1916. if drug.IsUse != 1 {
  1917. if drug.IsProject == 0 || drug.IsProject == 2 {
  1918. if all_count == 0 {
  1919. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1920. return
  1921. }
  1922. if prescribing_number > all_count {
  1923. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1924. return
  1925. }
  1926. }
  1927. if adminInfo.CurrentOrgId == 10215 {
  1928. if prescribing_number > batch_number_all_count {
  1929. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1930. return
  1931. }
  1932. }
  1933. }
  1934. }
  1935. if prescribingNumberUnit == drug.MaxUnit {
  1936. num := prescribing_number * float64(drug.MinNumber)
  1937. if drug.IsUse != 1 {
  1938. if drug.IsProject == 0 || drug.IsProject == 2 {
  1939. if all_count == 0 {
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1941. return
  1942. }
  1943. if num > all_count {
  1944. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1945. return
  1946. }
  1947. }
  1948. if adminInfo.CurrentOrgId == 10215 {
  1949. if num > batch_number_all_count {
  1950. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1951. return
  1952. }
  1953. }
  1954. }
  1955. }
  1956. }
  1957. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1958. if drugOutConfig.IsOpen != 1 {
  1959. //修改处方
  1960. for _, advice := range advices {
  1961. var drug_id int64
  1962. var prescribing_number float64
  1963. var prescribingNumberUnit string
  1964. var prescribingNumber string
  1965. var adviceId int64
  1966. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1967. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1968. }
  1969. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1970. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1971. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1972. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1973. }
  1974. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1975. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1976. }
  1977. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1978. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1979. }
  1980. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1981. if drug.ID == 0 {
  1982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1983. return
  1984. }
  1985. //查询药品的所有库存
  1986. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1987. var total_count int64
  1988. for _, it := range list {
  1989. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1990. }
  1991. totals := strconv.FormatInt(total_count, 10)
  1992. //查询该药品是否存在开药记录
  1993. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1994. //新增处方
  1995. if advicelist.ID == 0 {
  1996. //查询最新批次库存
  1997. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1998. var batch_number_count int64
  1999. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2000. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2001. all_count, _ := strconv.ParseFloat(totals, 64)
  2002. if prescribingNumberUnit == drug.MinUnit {
  2003. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2004. if drug.IsUse != 1 {
  2005. if drug.IsProject == 0 || drug.IsProject == 2 {
  2006. if all_count == 0 {
  2007. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2008. return
  2009. }
  2010. if prescribing_number > all_count {
  2011. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2012. return
  2013. }
  2014. }
  2015. if adminInfo.CurrentOrgId == 10215 {
  2016. if prescribing_number > batch_number_all_count {
  2017. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2018. return
  2019. }
  2020. }
  2021. }
  2022. } else {
  2023. if prescribingNumberUnit == drug.MaxUnit {
  2024. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2025. num := prescribing_number * float64(drug.MinNumber)
  2026. if drug.IsUse != 1 {
  2027. if drug.IsProject == 0 || drug.IsProject == 2 {
  2028. if all_count == 0 {
  2029. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2030. return
  2031. }
  2032. if num > all_count {
  2033. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2034. return
  2035. }
  2036. }
  2037. if adminInfo.CurrentOrgId == 10215 {
  2038. if prescribing_number > batch_number_all_count {
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2040. return
  2041. }
  2042. }
  2043. }
  2044. }
  2045. }
  2046. }
  2047. //修改处方
  2048. if advicelist.ID > 0 {
  2049. //查询最新批次库存
  2050. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2051. var batch_number_count int64
  2052. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2053. var device_number int64
  2054. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2055. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2056. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2057. device_number = prescribingNumberInt * drug.MinNumber
  2058. }
  2059. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2060. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2061. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2062. device_number = prescribingNumberInt
  2063. }
  2064. var number_count int64
  2065. if prescribingNumberUnit == drug.MaxUnit {
  2066. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2067. number_count = prescribingNumberInt * drug.MinNumber
  2068. }
  2069. if prescribingNumberUnit == drug.MinUnit {
  2070. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2071. number_count = prescribingNumberInt
  2072. }
  2073. //如果修改的数量大于之前修改的数量
  2074. if (number_count - device_number) > 0 {
  2075. //如果修改的差数量 大于库存数量
  2076. if drug.IsUse != 1 {
  2077. if drug.IsProject == 0 || drug.IsProject == 2 {
  2078. if total_count == 0 {
  2079. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2080. return
  2081. }
  2082. if (number_count - device_number) > total_count {
  2083. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2084. return
  2085. }
  2086. if (number_count - device_number) > batch_number_count {
  2087. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2088. return
  2089. }
  2090. }
  2091. if adminInfo.CurrentOrgId == 10215 {
  2092. // 查询该药品最后一次出库记录
  2093. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2094. var out_count int64
  2095. var in_count int64
  2096. var stock_max_number int64
  2097. var stock_min_number int64
  2098. for _, it := range outInfo {
  2099. if it.CountUnit == drug.MaxUnit {
  2100. it.Count = it.Count * drug.MinNumber
  2101. }
  2102. out_count += it.Count
  2103. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2104. stock_max_number = warehouseInfoList.StockMaxNumber
  2105. stock_min_number = warehouseInfoList.StockMinNumber
  2106. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2107. }
  2108. if out_count > 0 {
  2109. if (number_count - device_number) > in_count {
  2110. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2111. return
  2112. }
  2113. }
  2114. // 未出库
  2115. if out_count == 0 {
  2116. var sum_in_count int64
  2117. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2118. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2119. fmt.Println("sum_in_count", sum_in_count)
  2120. //如果修改的数量大于有库存的第一个批次
  2121. if number_count > sum_in_count {
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2123. return
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2130. if pharmacyConfig.IsOpen != 1 {
  2131. if device_number != number_count {
  2132. // 查询该药品最后一次出库记录
  2133. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2134. //回退库存
  2135. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2136. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2137. }
  2138. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2139. var stock_max_number int64
  2140. var stock_min_number int64
  2141. if number_count >= drug.MinNumber {
  2142. stock_max_number = device_number / drug.MinNumber
  2143. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2144. stock_min_number = device_number % drug.MinNumber
  2145. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2146. } else {
  2147. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2148. }
  2149. }
  2150. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2151. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2152. }
  2153. //删除记录
  2154. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2155. //查询默认仓库剩余多少库存
  2156. var sum_count int64
  2157. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2158. for _, its := range stockInfo {
  2159. if its.MaxUnit == drug.MaxUnit {
  2160. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2161. }
  2162. sum_count += its.StockMaxNumber + its.StockMinNumber
  2163. }
  2164. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //保存处方开药
  2171. if drugOutConfig.IsOpen == 1 {
  2172. //修改处方
  2173. for _, advice := range advices {
  2174. var drug_id int64
  2175. var prescribing_number float64
  2176. var prescribingNumberUnit string
  2177. var prescribingNumber string
  2178. var adviceId int64
  2179. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2180. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2181. }
  2182. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2183. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2184. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2185. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2186. }
  2187. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2188. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2189. }
  2190. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2191. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2192. }
  2193. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2194. if drug.ID == 0 {
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. //查询药品的所有库存
  2199. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2200. var total_count int64
  2201. for _, it := range list {
  2202. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2203. }
  2204. totals := strconv.FormatInt(total_count, 10)
  2205. //查询该药品是否存在开药记录
  2206. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2207. //新增处方
  2208. if advicelist.ID == 0 {
  2209. //查询最新批次库存
  2210. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2211. var batch_number_count int64
  2212. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2213. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2214. all_count, _ := strconv.ParseFloat(totals, 64)
  2215. if prescribingNumberUnit == drug.MinUnit {
  2216. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2217. if drug.IsUse != 1 {
  2218. if drug.IsProject == 0 || drug.IsProject == 2 {
  2219. if all_count == 0 {
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. if prescribing_number > all_count {
  2224. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2225. return
  2226. }
  2227. }
  2228. if adminInfo.CurrentOrgId == 10215 {
  2229. if prescribing_number > batch_number_all_count {
  2230. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2231. return
  2232. }
  2233. }
  2234. }
  2235. } else {
  2236. if prescribingNumberUnit == drug.MaxUnit {
  2237. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2238. num := prescribing_number * float64(drug.MinNumber)
  2239. if drug.IsUse != 1 {
  2240. if drug.IsProject == 0 || drug.IsProject == 2 {
  2241. if all_count == 0 {
  2242. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2243. return
  2244. }
  2245. if num > all_count {
  2246. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2247. return
  2248. }
  2249. }
  2250. if adminInfo.CurrentOrgId == 10215 {
  2251. if prescribing_number > batch_number_all_count {
  2252. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2253. return
  2254. }
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. //修改处方
  2261. if advicelist.ID > 0 {
  2262. //查询最新批次库存
  2263. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2264. var batch_number_count int64
  2265. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2266. var device_number int64
  2267. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2268. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2269. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2270. device_number = prescribingNumberInt * drug.MinNumber
  2271. }
  2272. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2273. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2274. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2275. device_number = prescribingNumberInt
  2276. }
  2277. var number_count int64
  2278. if prescribingNumberUnit == drug.MaxUnit {
  2279. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2280. number_count = prescribingNumberInt * drug.MinNumber
  2281. }
  2282. if prescribingNumberUnit == drug.MinUnit {
  2283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2284. number_count = prescribingNumberInt
  2285. }
  2286. //如果修改的数量大于之前修改的数量
  2287. if (number_count - device_number) > 0 {
  2288. //如果修改的差数量 大于库存数量
  2289. if drug.IsUse != 1 {
  2290. if drug.IsProject == 0 || drug.IsProject == 2 {
  2291. if total_count == 0 {
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. if (number_count - device_number) > total_count {
  2296. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2297. return
  2298. }
  2299. }
  2300. if adminInfo.CurrentOrgId == 10215 {
  2301. if (number_count - device_number) > batch_number_count {
  2302. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2303. return
  2304. }
  2305. }
  2306. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2307. //查询历史出库数据总批次
  2308. // 查询该药品最后一次出库记录
  2309. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2310. var out_count int64
  2311. var in_count int64
  2312. var stock_max_number int64
  2313. var stock_min_number int64
  2314. for _, it := range outInfo {
  2315. if it.CountUnit == drug.MaxUnit {
  2316. it.Count = it.Count * drug.MinNumber
  2317. }
  2318. out_count += it.Count
  2319. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2320. stock_max_number = warehouseInfoList.StockMaxNumber
  2321. stock_min_number = warehouseInfoList.StockMinNumber
  2322. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2323. }
  2324. if out_count > 0 {
  2325. if (number_count - device_number) > in_count {
  2326. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2327. return
  2328. }
  2329. }
  2330. // 未出库
  2331. if out_count == 0 {
  2332. var sum_in_count int64
  2333. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2334. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2335. if sum_in_count == 0 {
  2336. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2337. return
  2338. }
  2339. //如果修改的数量大于有库存的第一个批次
  2340. if number_count > sum_in_count {
  2341. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2342. return
  2343. }
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. //校验耗材库存
  2359. if goodOutConfig.IsOpen == 1 {
  2360. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2361. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2362. if len(prescriptions) > 0 {
  2363. for _, item := range prescriptions {
  2364. items := item.(map[string]interface{})
  2365. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2366. projects := items["project"].([]interface{})
  2367. if len(projects) > 0 {
  2368. for _, project := range projects {
  2369. var project_id int64
  2370. var project_type int64
  2371. var totals float64
  2372. var project_name string
  2373. var parsetotal int64
  2374. var id int64
  2375. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2376. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2377. }
  2378. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2379. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2380. }
  2381. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2382. total, _ := project.(map[string]interface{})["total"].(string)
  2383. totals, _ = strconv.ParseFloat(total, 64)
  2384. }
  2385. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2386. project_name = project.(map[string]interface{})["project_name"].(string)
  2387. }
  2388. if project_type == 3 {
  2389. //查找该耗材的出库记录
  2390. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2391. if len(goodWarehouseInfo) == 0 {
  2392. //查询耗材库存
  2393. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2394. var stock_count int64
  2395. for _, it := range list {
  2396. stock_count += it.StockCount
  2397. }
  2398. stock_counts := strconv.FormatInt(stock_count, 10)
  2399. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2400. if stock_total_count == 0 {
  2401. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2402. return
  2403. }
  2404. if totals > stock_total_count {
  2405. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2406. return
  2407. }
  2408. }
  2409. if len(goodWarehouseInfo) > 0 {
  2410. //查询该患者耗材的历史数据
  2411. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2412. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2413. //数量发生改变
  2414. if parsetotal != count {
  2415. //如果现在的数量大于历史数量,就要看库存是否足够
  2416. if parsetotal > count {
  2417. //查询耗材所有库存
  2418. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2419. var stock_count int64
  2420. for _, it := range list {
  2421. stock_count += it.StockCount
  2422. }
  2423. //库存不足
  2424. if stock_count == 0 {
  2425. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2426. return
  2427. }
  2428. if (parsetotal - count) > stock_count {
  2429. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2430. return
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. //不使用耗材保存处方出库
  2444. if goodOutConfig.IsOpen != 1 {
  2445. if stockConfig.IsOpen == 1 {
  2446. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2447. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2448. if len(prescriptions) > 0 {
  2449. for _, item := range prescriptions {
  2450. items := item.(map[string]interface{})
  2451. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2452. projects := items["project"].([]interface{})
  2453. if len(projects) > 0 {
  2454. for _, project := range projects {
  2455. var project_id int64
  2456. var project_type int64
  2457. var totals float64
  2458. var project_name string
  2459. var parsetotal int64
  2460. var id int64
  2461. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2462. id = int64(project.(map[string]interface{})["id"].(float64))
  2463. }
  2464. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2465. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2466. }
  2467. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2468. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2469. }
  2470. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2471. total, _ := project.(map[string]interface{})["total"].(string)
  2472. totals, _ = strconv.ParseFloat(total, 64)
  2473. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2474. }
  2475. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2476. project_name = project.(map[string]interface{})["project_name"].(string)
  2477. }
  2478. if project_type == 3 {
  2479. //查找该耗材的出库记录
  2480. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2481. //没有出库记录
  2482. if len(goodWarehouseInfo) == 0 {
  2483. //查询耗材库存
  2484. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2485. var stock_count int64
  2486. for _, it := range list {
  2487. stock_count += it.StockCount
  2488. }
  2489. stock_counts := strconv.FormatInt(stock_count, 10)
  2490. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2491. if stock_total_count == 0 {
  2492. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2493. return
  2494. }
  2495. if totals > stock_total_count {
  2496. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2497. return
  2498. }
  2499. //查找今日该患者已经出库的所有耗材
  2500. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2501. for _, item := range goodList {
  2502. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2503. var flush_count int64
  2504. for _, it := range goodListSix {
  2505. flush_count += it.StockCount
  2506. }
  2507. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2508. creater := adminInfo.AdminUser.Id
  2509. if errs != nil {
  2510. goodErrcode := models.XtGoodErrcode{
  2511. UserOrgId: item.OrgId,
  2512. Errcode: "手动出库更新剩余出库失败",
  2513. GoodId: item.GoodId,
  2514. Status: 1,
  2515. Ctime: time.Now().Unix(),
  2516. Mtime: 0,
  2517. Count: 0,
  2518. StockCount: 0,
  2519. Creater: creater,
  2520. BatchNumberId: 0,
  2521. WarehouseOutId: 0,
  2522. }
  2523. service.CreateGoodErrcode(goodErrcode)
  2524. }
  2525. }
  2526. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2527. }
  2528. //有出库记录
  2529. if len(goodWarehouseInfo) > 0 {
  2530. //查询该患者耗材的历史数据
  2531. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2532. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2533. //数量发生改变
  2534. if parsetotal != count {
  2535. //查找今日该患者已经出库的所有耗材
  2536. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2537. for _, item := range goodList {
  2538. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2539. var flush_count int64
  2540. for _, it := range goodListSix {
  2541. flush_count += it.StockCount
  2542. }
  2543. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2544. //减少出库数量
  2545. creater := adminInfo.AdminUser.Id
  2546. if errs != nil {
  2547. goodErrcode := models.XtGoodErrcode{
  2548. UserOrgId: item.OrgId,
  2549. Errcode: "手动出库更新剩余出库失败",
  2550. GoodId: item.GoodId,
  2551. Status: 1,
  2552. Ctime: time.Now().Unix(),
  2553. Mtime: 0,
  2554. Count: 0,
  2555. StockCount: 0,
  2556. Creater: creater,
  2557. BatchNumberId: 0,
  2558. WarehouseOutId: 0,
  2559. }
  2560. service.CreateGoodErrcode(goodErrcode)
  2561. }
  2562. //查询默认仓库
  2563. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2564. var total_count int64
  2565. for _, it := range stockList {
  2566. total_count += it.StockCount
  2567. }
  2568. //基础库插入数据
  2569. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2570. }
  2571. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2572. }
  2573. }
  2574. }
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2584. var hpInfo models.HisPrescriptionInfo
  2585. if info.ID == 0 {
  2586. var randNum int
  2587. randNum = rand.Intn(10000) + 1000
  2588. timestamp := time.Now().Unix()
  2589. tempTime := time.Unix(timestamp, 0)
  2590. timeFormat := tempTime.Format("20060102150405")
  2591. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2592. hpInfo = models.HisPrescriptionInfo{
  2593. HisPatientId: his_patient_id,
  2594. UserOrgId: adminInfo.CurrentOrgId,
  2595. RecordDate: theTime.Unix(),
  2596. PatientId: patient_id,
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: time.Now().Unix(),
  2600. Creator: adminInfo.AdminUser.Id,
  2601. Modifier: adminInfo.AdminUser.Id,
  2602. Diagnosis: diagnose,
  2603. SickHistory: sick_history,
  2604. Departments: department,
  2605. RegisterType: reg_type,
  2606. PrescriptionNumber: p_number,
  2607. PrescriptionStatus: 1,
  2608. Doctor: role.UserName,
  2609. DoctorId: doctor_id,
  2610. SickType: sick_type,
  2611. PType: p_type,
  2612. PatientDiagnosis: patient_diagnose,
  2613. }
  2614. service.SavePatientPrescriptionInfo(hpInfo)
  2615. //创建步骤表
  2616. finish := models.XtDialysisFinish{
  2617. IsFinish: 1,
  2618. UserOrgId: adminInfo.CurrentOrgId,
  2619. Status: 1,
  2620. Ctime: time.Now().Unix(),
  2621. Mtime: 0,
  2622. Module: 4,
  2623. RecordDate: theTime.Unix(),
  2624. Sourse: 1,
  2625. PatientId: patient_id,
  2626. }
  2627. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2628. if dialysisFinish.ID == 0 {
  2629. service.CreateDialysisFinish(finish)
  2630. }
  2631. redis := service.RedisClient()
  2632. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2633. redis.Set(key, "", time.Second)
  2634. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2635. redis.Set(keyOne, "", time.Second)
  2636. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2637. redis.Set(keySeven, "", time.Second)
  2638. defer redis.Close()
  2639. } else {
  2640. hpInfo = models.HisPrescriptionInfo{
  2641. ID: info.ID,
  2642. UserOrgId: adminInfo.CurrentOrgId,
  2643. RecordDate: info.RecordDate,
  2644. PatientId: info.PatientId,
  2645. Status: 1,
  2646. Ctime: info.Ctime,
  2647. Mtime: time.Now().Unix(),
  2648. Creator: info.Creator,
  2649. Modifier: adminInfo.AdminUser.Id,
  2650. Diagnosis: diagnose,
  2651. SickHistory: sick_history,
  2652. Departments: department,
  2653. RegisterType: reg_type,
  2654. PrescriptionNumber: info.PrescriptionNumber,
  2655. Doctor: role.UserName,
  2656. PrescriptionStatus: info.PrescriptionStatus,
  2657. DoctorId: doctor_id,
  2658. SickType: sick_type,
  2659. PType: info.PType,
  2660. HisPatientId: info.HisPatientId,
  2661. PatientDiagnosis: patient_diagnose,
  2662. }
  2663. service.SavePatientPrescriptionInfo(hpInfo)
  2664. //创建步骤表
  2665. finish := models.XtDialysisFinish{
  2666. IsFinish: 1,
  2667. UserOrgId: adminInfo.CurrentOrgId,
  2668. Status: 1,
  2669. Ctime: time.Now().Unix(),
  2670. Mtime: 0,
  2671. Module: 4,
  2672. RecordDate: info.RecordDate,
  2673. Sourse: 1,
  2674. PatientId: info.PatientId,
  2675. }
  2676. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2677. if dialysisFinish.ID == 0 {
  2678. service.CreateDialysisFinish(finish)
  2679. }
  2680. redis := service.RedisClient()
  2681. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2682. redis.Set(key, "", time.Second)
  2683. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2684. redis.Set(keyOne, "", time.Second)
  2685. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2686. redis.Set(keySeven, "", time.Second)
  2687. defer redis.Close()
  2688. }
  2689. //定义切片
  2690. var adviceList []models.HisDoctorAdviceInfo
  2691. var projectList []models.HisPrescriptionProject
  2692. if adminInfo.CurrentOrgId == 10489 {
  2693. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2694. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2695. var tempPrescription *models.HisPrescription
  2696. if len(prescriptions) > 0 {
  2697. for _, item := range prescriptions {
  2698. // 开始外部循环的事务
  2699. tx := db.Begin()
  2700. // 在函数结束时处理事务回滚
  2701. defer func() {
  2702. if r := recover(); r != nil {
  2703. tx.Rollback()
  2704. }
  2705. }()
  2706. items := item.(map[string]interface{})
  2707. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2708. utils.ErrorLog("id")
  2709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2710. return
  2711. }
  2712. id := int64(items["id"].(float64))
  2713. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2714. tempPrescription = &new_prescription
  2715. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2716. utils.ErrorLog("type")
  2717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2718. return
  2719. }
  2720. types := int64(items["type"].(float64))
  2721. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2722. utils.ErrorLog("med_type")
  2723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2724. return
  2725. }
  2726. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2727. if med_type == "0" {
  2728. med_type = "14"
  2729. }
  2730. //if order_status == 0 {
  2731. // order_status = 1
  2732. //}
  2733. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2734. utils.ErrorLog("pre_time")
  2735. }
  2736. preTime, _ := items["pre_time"].(string)
  2737. fmt.Println("preTime", preTime)
  2738. timeLayout := "2006-01-02"
  2739. loc, _ := time.LoadLocation("Local")
  2740. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2741. result := strings.Split(preTime, " ")
  2742. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2743. if err != nil {
  2744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2745. return
  2746. }
  2747. pTime := theTime2.Unix()
  2748. ctime := time.Now().Unix()
  2749. if tempPrescription.ID == 0 {
  2750. prescription := &models.HisPrescription{
  2751. ID: 0,
  2752. PatientId: patient_id,
  2753. UserOrgId: adminInfo.CurrentOrgId,
  2754. RecordDate: recordDateTime,
  2755. Ctime: ctime,
  2756. Mtime: ctime,
  2757. Type: types,
  2758. Modifier: adminInfo.AdminUser.Id,
  2759. Creator: adminInfo.AdminUser.Id,
  2760. Status: 1,
  2761. Doctor: role.UserName,
  2762. HisPatientId: his_patient_id,
  2763. OrderStatus: 1,
  2764. BatchNumber: "",
  2765. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2766. PreTime: pTime,
  2767. PType: p_type,
  2768. MedType: med_type,
  2769. }
  2770. tempPrescription = prescription
  2771. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2772. redis := service.RedisClient()
  2773. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2774. redis.Set(key, "", time.Second)
  2775. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2776. redis.Set(keyOne, "", time.Second)
  2777. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2778. redis.Set(keySeven, "", time.Second)
  2779. defer redis.Close()
  2780. } else {
  2781. tempPrescription.ID = id
  2782. tempPrescription.Type = types
  2783. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2784. tempPrescription.Mtime = time.Now().Unix()
  2785. tempPrescription.Doctor = role.UserName
  2786. //tempPrescription.OrderStatus = order_status
  2787. tempPrescription.PreTime = pTime
  2788. tempPrescription.MedType = med_type
  2789. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2790. redis := service.RedisClient()
  2791. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2792. redis.Set(key, "", time.Second)
  2793. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2794. redis.Set(keyOne, "", time.Second)
  2795. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2796. redis.Set(keySeven, "", time.Second)
  2797. defer redis.Close()
  2798. }
  2799. //service.SaveHisPrescription(prescription)
  2800. //更改患者挂号状态
  2801. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2802. fmt.Println("更改失败", err2)
  2803. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2804. advices := items["advices"].([]interface{})
  2805. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2806. groupNo := int64(0)
  2807. ctime := time.Now().Unix()
  2808. mtime := ctime
  2809. if len(advices) > 0 {
  2810. for _, advice := range advices {
  2811. tx := db.Begin()
  2812. // 在函数结束时处理事务回滚
  2813. defer func() {
  2814. if r := recover(); r != nil {
  2815. tx.Rollback()
  2816. }
  2817. }()
  2818. var s models.HisDoctorAdviceInfo
  2819. s.PrescriptionId = tempPrescription.ID
  2820. s.AdviceType = 2
  2821. s.AdviceDoctor = doctor_id
  2822. s.StopState = 2
  2823. s.ExecutionState = 2
  2824. s.AdviceDate = theTime3.Unix()
  2825. s.Status = 1
  2826. s.UserOrgId = adminInfo.CurrentOrgId
  2827. s.RecordDate = theTime3.Unix()
  2828. s.StartTime = tempPrescription.PreTime
  2829. s.Groupno = groupNo
  2830. s.CreatedTime = ctime
  2831. s.UpdatedTime = mtime
  2832. s.PatientId = patient_id
  2833. s.HisPatientId = his_patient_id
  2834. s.StartTime = pTime
  2835. s.IsSettle = 2
  2836. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2837. if errcode > 0 {
  2838. c.ServeFailJSONWithSGJErrorCode(errcode)
  2839. return
  2840. }
  2841. s.StartTime = pTime
  2842. var total_count int64 //处方总库存
  2843. //查询改药品信息
  2844. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2845. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2846. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2847. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2848. total_count += prescribingNumberSeven * medical.MinNumber
  2849. }
  2850. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2851. total_count += prescribingNumberSeven
  2852. }
  2853. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2854. total_count += prescribingNumberSeven
  2855. }
  2856. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2857. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2858. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2859. if s.Price != lastWarehouse.RetailPrice {
  2860. s.Price = lastWarehouse.RetailPrice
  2861. }
  2862. if s.Price == 0 {
  2863. s.Price = lastWarehouse.RetailPrice
  2864. }
  2865. }
  2866. //查询保存处方出库开关是否打开
  2867. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2868. if drugOutConfig.IsOpen == 1 {
  2869. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2870. // 查询该药品最后一次出库记录
  2871. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2872. if len(druginfo) > 0 {
  2873. //回退库存
  2874. for _, it := range druginfo {
  2875. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2876. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2877. }
  2878. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2879. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2880. }
  2881. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2882. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2883. }
  2884. }
  2885. //删除记录
  2886. service.DeleteDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2887. }
  2888. service.CreateHisDoctorAdviceOne(&s, tx)
  2889. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2890. //出库
  2891. if drug.IsUse == 2 {
  2892. creater := adminInfo.AdminUser.Id
  2893. newadviceInfo := &models.HisDoctorAdviceInfo{
  2894. ID: advicelast.ID,
  2895. UserOrgId: s.UserOrgId,
  2896. PatientId: s.PatientId,
  2897. HisPatientId: s.HisPatientId,
  2898. AdviceType: s.AdviceType,
  2899. AdviceDate: s.AdviceDate,
  2900. StartTime: s.StartTime,
  2901. AdviceName: s.AdviceName,
  2902. AdviceDesc: s.AdviceDesc,
  2903. ReminderDate: s.ReminderDate,
  2904. SingleDose: s.SingleDose,
  2905. SingleDoseUnit: s.SingleDoseUnit,
  2906. PrescribingNumber: s.PrescribingNumber,
  2907. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2908. DeliveryWay: s.DeliveryWay,
  2909. ExecutionFrequency: s.ExecutionFrequency,
  2910. AdviceDoctor: s.AdviceDoctor,
  2911. Status: s.Status,
  2912. CreatedTime: s.CreatedTime,
  2913. UpdatedTime: s.UpdatedTime,
  2914. AdviceAffirm: s.AdviceAffirm,
  2915. Remark: s.Remark,
  2916. StopTime: s.StopTime,
  2917. StopReason: s.StopReason,
  2918. StopDoctor: s.StopDoctor,
  2919. StopState: s.StopState,
  2920. ParentId: s.ParentId,
  2921. ExecutionTime: s.ExecutionTime,
  2922. ExecutionStaff: s.ExecutionStaff,
  2923. ExecutionState: s.ExecutionState,
  2924. Checker: s.Checker,
  2925. RecordDate: s.RecordDate,
  2926. DialysisOrderId: s.DialysisOrderId,
  2927. CheckTime: s.CheckTime,
  2928. CheckState: s.CheckState,
  2929. DrugSpec: s.DrugSpec,
  2930. DrugSpecUnit: s.DrugSpecUnit,
  2931. Groupno: s.Groupno,
  2932. RemindType: s.RemindType,
  2933. FrequencyType: s.FrequencyType,
  2934. DayCount: s.DayCount,
  2935. WeekDay: s.WeekDay,
  2936. TemplateId: s.TemplateId,
  2937. Modifier: s.Modifier,
  2938. DrugId: s.DrugId,
  2939. Price: s.Price,
  2940. PrescriptionId: s.PrescriptionId,
  2941. MedListCodg: s.MedListCodg,
  2942. FeedetlSn: s.FeedetlSn,
  2943. Day: s.DayCount,
  2944. ChildDoctorAdvice: nil,
  2945. Drug: models.Drug{},
  2946. Diagnosis: s.Diagnosis,
  2947. Way: s.Way,
  2948. HospApprFlag: s.HospApprFlag,
  2949. LmtUsedFlag: s.LmtUsedFlag,
  2950. HisOrderInfo: models.HisOrderInfo{},
  2951. IsMedicine: s.IsMedicine,
  2952. ExecutionFrequencyId: s.ExecutionFrequencyId,
  2953. Child: nil,
  2954. IsSettle: s.IsSettle,
  2955. IsMobile: s.IsMobile,
  2956. IsSelfDrug: s.IsSelfDrug,
  2957. DrugWayCount: s.DrugWayCount,
  2958. }
  2959. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  2960. }
  2961. //更新字典里面的库存
  2962. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  2963. var sum_count int64
  2964. for _, its := range stockInfo {
  2965. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  2966. if its.MaxUnit == baseDrug.MaxUnit {
  2967. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2968. }
  2969. sum_count += its.StockMaxNumber + its.StockMinNumber
  2970. }
  2971. //更新基础库存
  2972. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  2973. //剩余库存
  2974. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  2975. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  2976. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  2977. }
  2978. //记录日志
  2979. byterequest, _ := json.Marshal(s)
  2980. adviceLog := models.XtDoctorAdviceLog{
  2981. UserOrgId: s.UserOrgId,
  2982. PatientId: s.PatientId,
  2983. AdminUserId: adminInfo.AdminUser.Id,
  2984. Module: 1,
  2985. ErrLog: string(byterequest),
  2986. Status: 1,
  2987. Ctime: time.Now().Unix(),
  2988. Mtime: 0,
  2989. Source: "电脑端新建his医嘱",
  2990. RecordDate: s.AdviceDate,
  2991. }
  2992. service.CreateDoctorAdviceLog(adviceLog)
  2993. //存储切片中
  2994. adviceList = append(adviceList, s)
  2995. redis := service.RedisClient()
  2996. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2997. redis.Set(key, "", time.Second)
  2998. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2999. redis.Set(keyOne, "", time.Second)
  3000. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3001. redis.Set(keySeven, "", time.Second)
  3002. var randNum int
  3003. randNum = rand.Intn(10000) + 1000
  3004. timestamp := time.Now().Unix()
  3005. tempTime := time.Unix(timestamp, 0)
  3006. timeFormat := tempTime.Format("20060102150405")
  3007. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3008. service.CreateHisDoctorAdviceOne(&s, tx)
  3009. tx.Commit()
  3010. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3011. redis.Set(keySix, "", time.Second)
  3012. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3013. redis.Set(keyFive, "", time.Second)
  3014. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3015. redis.Set(keyEight, "", time.Second)
  3016. defer redis.Close()
  3017. }
  3018. }
  3019. }
  3020. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3021. projects := items["project"].([]interface{})
  3022. if len(projects) > 0 {
  3023. for _, project := range projects {
  3024. tx := db.Begin()
  3025. // 在函数结束时处理事务回滚
  3026. defer func() {
  3027. if r := recover(); r != nil {
  3028. tx.Rollback()
  3029. }
  3030. }()
  3031. var p models.HisPrescriptionProject
  3032. p.PrescriptionId = tempPrescription.ID
  3033. p.Ctime = time.Now().Unix()
  3034. p.Mtime = time.Now().Unix()
  3035. p.PatientId = patient_id
  3036. p.RecordDate = theTime3.Unix()
  3037. p.Doctor = doctor_id
  3038. p.UserOrgId = adminInfo.CurrentOrgId
  3039. p.HisPatientId = his_patient_id
  3040. p.Status = 1
  3041. p.StartTime = pTime
  3042. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3043. if errcode > 0 {
  3044. c.ServeFailJSONWithSGJErrorCode(errcode)
  3045. return
  3046. }
  3047. if p.ID == 0 {
  3048. p.IsOut = 2
  3049. }
  3050. if p.ID > 0 {
  3051. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3052. p.IsOut = projectDetail.IsOut
  3053. }
  3054. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3055. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3056. if p.Type == 3 {
  3057. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3058. if p.Price != lastWarehouse.PackingPrice {
  3059. p.Price = lastWarehouse.PackingPrice
  3060. }
  3061. if p.Unit == "" {
  3062. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3063. p.Unit = goodInfoOne.PackingUnit
  3064. }
  3065. }
  3066. }
  3067. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3068. //
  3069. // if p.Type == 3 {
  3070. // //查询该耗材是否停用
  3071. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3072. // //表示该耗材已经停用,不能保存
  3073. // if goodInfoSeven.ID == 0 {
  3074. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3075. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3076. // return
  3077. // }
  3078. // }
  3079. //
  3080. //}
  3081. service.CreateNewHisProjectTwo(&p, tx)
  3082. //查询保存耗材出库开关是否打开
  3083. if goodOutConfig.IsOpen == 1 {
  3084. //耗材出库
  3085. if p.Type == 3 {
  3086. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3087. //查询历史出库数据
  3088. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3089. var out_count_five int64
  3090. for _, item := range flowGood {
  3091. out_count_five += item.Count
  3092. }
  3093. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3094. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3095. if out_count_five != parseIntCount {
  3096. //查询耗材最后一次出库记录
  3097. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3098. //查询默认出库仓库库存
  3099. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3100. if len(wareOut) > 0 {
  3101. for _, it := range wareOut {
  3102. //回退库存
  3103. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3104. //删除出库记录
  3105. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3106. }
  3107. }
  3108. timeStr := time.Now().Format("2006-01-02")
  3109. timeArr := strings.Split(timeStr, "-")
  3110. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3111. total = total + 1
  3112. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3113. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3114. number = number + total
  3115. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3116. operation_time := time.Now().Unix()
  3117. creater := c.GetAdminUserInfo().AdminUser.Id
  3118. recordDateStr := time.Now().Format("2006-01-02")
  3119. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3120. nowtime := recordDate.Unix()
  3121. warehouseOut := models.WarehouseOut{
  3122. WarehouseOutOrderNumber: warehousing_out_order,
  3123. OperationTime: operation_time,
  3124. OrgId: adminInfo.CurrentOrgId,
  3125. Creater: creater,
  3126. Ctime: time.Now().Unix(),
  3127. Status: 1,
  3128. WarehouseOutTime: nowtime,
  3129. Type: 1,
  3130. StorehouseId: storeConfig.StorehouseOutInfo,
  3131. IsCheck: 1,
  3132. IsSys: 1,
  3133. }
  3134. //查询是否生成出库单
  3135. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3136. if out.ID == 0 {
  3137. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3138. }
  3139. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3140. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3141. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3142. dialyPrepareOne := models.DialysisBeforePrepare{
  3143. GoodTypeId: goodObj.GoodTypeId,
  3144. GoodId: p.ProjectId,
  3145. PatientId: p.PatientId,
  3146. RecordDate: p.RecordDate,
  3147. UserOrgId: adminInfo.CurrentOrgId,
  3148. Count: parseIntCount,
  3149. Ctime: time.Now().Unix(),
  3150. Creater: creater,
  3151. Status: 1,
  3152. StorehouseId: houseConfig.StorehouseOutInfo,
  3153. ProjectId: lastHisProject.ID,
  3154. }
  3155. //判断是否是零用耗材(非零用)
  3156. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3157. //查询历史出库数据
  3158. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3159. var out_count int64
  3160. for _, item := range flowGood {
  3161. out_count += item.Count
  3162. }
  3163. //如果历史数和当前数据不想等才进行退库出库
  3164. if out_count != parseIntCount {
  3165. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3166. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3167. detail := models.AutomaticReduceDetail{
  3168. WarehouseOutId: 0,
  3169. WarehouseOutOrderNumber: "",
  3170. PatientId: p.PatientId,
  3171. Ctime: time.Now().Unix(),
  3172. Mtime: 0,
  3173. Status: 1,
  3174. RecordTime: p.RecordDate,
  3175. OrgId: p.UserOrgId,
  3176. GoodId: p.ProjectId,
  3177. GoodTypeId: 0,
  3178. Count: parseIntCount,
  3179. Type: 0,
  3180. ProjectId: lastHisProject.ID,
  3181. StorehouseId: 0,
  3182. }
  3183. service.CreateNewAutoDetail(detail, tx)
  3184. //查询剩余库存
  3185. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3186. var sum_count int64
  3187. for _, item := range goodList {
  3188. sum_count += item.StockCount
  3189. }
  3190. //更新剩余库存
  3191. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3192. //耗材
  3193. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3194. }
  3195. //判断是否是零用耗材(零用但是是出库耗材)
  3196. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3197. //查询历史出库数据
  3198. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3199. var out_count int64
  3200. for _, item := range flowGood {
  3201. out_count += item.Count
  3202. }
  3203. //如果历史数和当前数据不想等才进行退库出库
  3204. if out_count != parseIntCount {
  3205. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3206. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3207. detail := models.AutomaticReduceDetail{
  3208. WarehouseOutId: 0,
  3209. WarehouseOutOrderNumber: "",
  3210. PatientId: p.PatientId,
  3211. Ctime: time.Now().Unix(),
  3212. Mtime: 0,
  3213. Status: 1,
  3214. RecordTime: p.RecordDate,
  3215. OrgId: p.UserOrgId,
  3216. GoodId: p.ProjectId,
  3217. GoodTypeId: 0,
  3218. Count: parseIntCount,
  3219. Type: 0,
  3220. ProjectId: p.ID,
  3221. StorehouseId: 0,
  3222. }
  3223. service.CreateNewAutoDetail(detail, tx)
  3224. //查询剩余库存
  3225. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3226. var sum_count int64
  3227. for _, item := range goodList {
  3228. sum_count += item.StockCount
  3229. }
  3230. //更新剩余库存
  3231. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3232. //耗材
  3233. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3234. }
  3235. }
  3236. }
  3237. }
  3238. //记录日志
  3239. byterequest, _ := json.Marshal(p)
  3240. adviceLog := models.XtDoctorAdviceLog{
  3241. UserOrgId: p.UserOrgId,
  3242. PatientId: p.PatientId,
  3243. AdminUserId: adminInfo.AdminUser.Id,
  3244. Module: 1,
  3245. ErrLog: string(byterequest),
  3246. Status: 1,
  3247. Ctime: time.Now().Unix(),
  3248. Mtime: 0,
  3249. Source: "电脑端新建his项目",
  3250. RecordDate: p.RecordDate,
  3251. }
  3252. service.CreateDoctorAdviceLog(adviceLog)
  3253. projectList = append(projectList, p)
  3254. var randNum int
  3255. randNum = rand.Intn(10000) + 1000
  3256. timestamp := time.Now().Unix()
  3257. tempTime := time.Unix(timestamp, 0)
  3258. timeFormat := tempTime.Format("20060102150405")
  3259. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3260. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3261. //新增或者编辑项目,修改对应的标签数据
  3262. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3263. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3264. var label models.HisLabelPrintInfo
  3265. project, _ := service.GetProjectDetail(p.ProjectId)
  3266. if project.CostClassify == 3 { //类别为检验检查
  3267. if p.TeamId > 0 { //检验检查组套
  3268. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3269. if tempLabel.ID == 0 {
  3270. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3271. label.Number = tempPrescription.PrescriptionNumber
  3272. label.ProjectId = project.ID
  3273. label.Status = 1
  3274. label.IsPrint = 2
  3275. label.DoctorId = info.DoctorId
  3276. label.UserOrgId = p.UserOrgId
  3277. label.PatientId = patient_id
  3278. label.RecordDate = recordDateTime
  3279. label.Ctime = time.Now().Unix()
  3280. label.Mtime = time.Now().Unix()
  3281. label.ItemId = p.TeamId
  3282. label.FeedetlSn = p.FeedetlSn
  3283. label.PProjectId = p.ID
  3284. label.ProjectName = team.ProjectTeam
  3285. label.PatientName = patient.Name
  3286. service.CreateNewHisLabelRecord(&label, tx)
  3287. }
  3288. } else { //单条检验检查项目
  3289. label.Number = tempPrescription.PrescriptionNumber
  3290. label.ProjectId = project.ID
  3291. label.Status = 1
  3292. label.DoctorId = info.DoctorId
  3293. label.UserOrgId = p.UserOrgId
  3294. label.PatientId = patient_id
  3295. label.RecordDate = recordDateTime
  3296. label.IsPrint = 2
  3297. label.Ctime = time.Now().Unix()
  3298. label.Mtime = time.Now().Unix()
  3299. label.FeedetlSn = p.FeedetlSn
  3300. label.PProjectId = p.ID
  3301. label.ItemId = p.TeamId
  3302. label.ProjectName = project.ProjectName
  3303. label.PatientName = patient.Name
  3304. service.CreateNewHisLabelRecord(&label, tx)
  3305. }
  3306. }
  3307. }
  3308. }
  3309. service.SaveNewHisProjectTwo(&p, tx)
  3310. }
  3311. }
  3312. tx.Commit()
  3313. }
  3314. }
  3315. }
  3316. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3317. // addition := items["addition"].([]interface{})
  3318. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3319. // ctime := time.Now().Unix()
  3320. // mtime := ctime
  3321. // if len(addition) > 0 {
  3322. // for _, item := range addition {
  3323. // var s models.HisAdditionalCharge
  3324. // s.PrescriptionId = tempPrescription.ID
  3325. // s.Status = 1
  3326. // s.UserOrgId = adminInfo.CurrentOrgId
  3327. // s.RecordDate = recordDateTime
  3328. // s.CreatedTime = ctime
  3329. // s.UpdatedTime = mtime
  3330. // s.PatientId = patient_id
  3331. // s.HisPatientId = his_patient_id
  3332. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3333. // if errcode > 0 {
  3334. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3335. // return
  3336. // }
  3337. // service.CreateAdditionalCharge(&s)
  3338. // var randNum int
  3339. // randNum = rand.Intn(10000) + 1000
  3340. // timestamp := time.Now().Unix()
  3341. // tempTime := time.Unix(timestamp, 0)
  3342. // timeFormat := tempTime.Format("20060102150405")
  3343. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3344. // service.CreateAdditionalCharge(&s)
  3345. //
  3346. // }
  3347. // }
  3348. //}
  3349. }
  3350. }
  3351. //查询今日该患者开的药品处方
  3352. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3353. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3354. //药品出库
  3355. //if drugOutConfig.IsOpen == 1 {
  3356. // for _, item := range hisdoctorlist {
  3357. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3358. //
  3359. // // 查询该药品最后一次出库记录
  3360. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3361. //
  3362. // if len(druginfo) > 0 {
  3363. // //回退库存
  3364. // for _, it := range druginfo {
  3365. //
  3366. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3367. //
  3368. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3369. //
  3370. // }
  3371. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3372. //
  3373. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3374. //
  3375. // }
  3376. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3377. //
  3378. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3379. //
  3380. // }
  3381. // }
  3382. // }
  3383. //
  3384. // //删除记录
  3385. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3386. // //查询最后一次数据
  3387. // if drugOutConfig.IsOpen == 1 {
  3388. // //出库
  3389. // if drug.IsUse == 2 {
  3390. // creater := adminInfo.AdminUser.Id
  3391. //
  3392. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3393. //
  3394. // }
  3395. //
  3396. // //更新字典里面的库存
  3397. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3398. // var sum_count int64
  3399. // for _, its := range stockInfo {
  3400. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3401. // if its.MaxUnit == baseDrug.MaxUnit {
  3402. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3403. // }
  3404. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3405. // }
  3406. // //更新基础库存
  3407. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3408. // //剩余库存
  3409. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3410. //
  3411. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3412. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3413. //
  3414. // }
  3415. // }
  3416. //}
  3417. //耗材保存处方出库
  3418. //if goodOutConfig.IsOpen == 1 {
  3419. //
  3420. // //查询今日耗材出库数量
  3421. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3422. //
  3423. // for _, item := range hisgoodlist {
  3424. //
  3425. // //查询历史出库数据
  3426. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3427. // var out_count_five int64
  3428. // for _, item := range flowGood {
  3429. // out_count_five += item.Count
  3430. // }
  3431. //
  3432. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3433. //
  3434. // if out_count_five != parseIntCount {
  3435. //
  3436. // //查询耗材最后一次出库记录
  3437. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3438. // //查询默认出库仓库库存
  3439. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3440. // if len(wareOut) > 0 {
  3441. //
  3442. // for _, it := range wareOut {
  3443. // //回退库存
  3444. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3445. //
  3446. // //删除出库记录
  3447. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3448. //
  3449. // }
  3450. // }
  3451. //
  3452. // timeStr := time.Now().Format("2006-01-02")
  3453. // timeArr := strings.Split(timeStr, "-")
  3454. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3455. //
  3456. // total = total + 1
  3457. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3458. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3459. // number = number + total
  3460. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3461. //
  3462. // operation_time := time.Now().Unix()
  3463. // creater := c.GetAdminUserInfo().AdminUser.Id
  3464. //
  3465. // recordDateStr := time.Now().Format("2006-01-02")
  3466. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3467. // nowtime := recordDate.Unix()
  3468. // warehouseOut := models.WarehouseOut{
  3469. // WarehouseOutOrderNumber: warehousing_out_order,
  3470. // OperationTime: operation_time,
  3471. // OrgId: adminInfo.CurrentOrgId,
  3472. // Creater: creater,
  3473. // Ctime: time.Now().Unix(),
  3474. // Status: 1,
  3475. // WarehouseOutTime: nowtime,
  3476. // Type: 1,
  3477. // StorehouseId: storeConfig.StorehouseOutInfo,
  3478. // IsCheck: 1,
  3479. // IsSys: 1,
  3480. // }
  3481. // //查询是否生成出库单
  3482. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3483. //
  3484. // if out.ID == 0 {
  3485. // service.AddSigleWarehouseOut(&warehouseOut)
  3486. // }
  3487. //
  3488. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3489. //
  3490. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3491. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3492. //
  3493. // dialyPrepareOne := models.DialysisBeforePrepare{
  3494. // GoodTypeId: goodObj.GoodTypeId,
  3495. // GoodId: item.ProjectId,
  3496. // PatientId: item.PatientId,
  3497. // RecordDate: item.RecordDate,
  3498. // UserOrgId: adminInfo.CurrentOrgId,
  3499. // Count: parseIntCount,
  3500. // Ctime: time.Now().Unix(),
  3501. // Creater: creater,
  3502. // Status: 1,
  3503. // StorehouseId: houseConfig.StorehouseOutInfo,
  3504. // ProjectId: item.ID,
  3505. // }
  3506. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3507. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3508. //
  3509. // //查询历史出库数据
  3510. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3511. // var out_count int64
  3512. // for _, item := range flowGood {
  3513. // out_count += item.Count
  3514. // }
  3515. //
  3516. // //如果历史数和当前数据不想等才进行退库出库
  3517. // if out_count != parseIntCount {
  3518. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3519. //
  3520. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3521. // detail := models.AutomaticReduceDetail{
  3522. // WarehouseOutId: 0,
  3523. // WarehouseOutOrderNumber: "",
  3524. // PatientId: item.PatientId,
  3525. // Ctime: time.Now().Unix(),
  3526. // Mtime: 0,
  3527. // Status: 1,
  3528. // RecordTime: item.RecordDate,
  3529. // OrgId: item.UserOrgId,
  3530. // GoodId: item.ProjectId,
  3531. // GoodTypeId: 0,
  3532. // Count: parseIntCount,
  3533. // Type: 0,
  3534. // ProjectId: item.ID,
  3535. // StorehouseId: 0,
  3536. // }
  3537. //
  3538. // service.CreateAutoDetail(detail)
  3539. //
  3540. // //查询剩余库存
  3541. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3542. // var sum_count int64
  3543. // for _, item := range goodList {
  3544. // sum_count += item.StockCount
  3545. // }
  3546. //
  3547. // //更新剩余库存
  3548. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3549. //
  3550. // //耗材
  3551. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3552. // }
  3553. //
  3554. // }
  3555. //
  3556. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3557. // //查询历史出库数据
  3558. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3559. // var out_count int64
  3560. // for _, item := range flowGood {
  3561. // out_count += item.Count
  3562. // }
  3563. // //如果历史数和当前数据不想等才进行退库出库
  3564. // if out_count != parseIntCount {
  3565. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3566. //
  3567. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3568. // detail := models.AutomaticReduceDetail{
  3569. // WarehouseOutId: 0,
  3570. // WarehouseOutOrderNumber: "",
  3571. // PatientId: item.PatientId,
  3572. // Ctime: time.Now().Unix(),
  3573. // Mtime: 0,
  3574. // Status: 1,
  3575. // RecordTime: item.RecordDate,
  3576. // OrgId: item.UserOrgId,
  3577. // GoodId: item.ProjectId,
  3578. // GoodTypeId: 0,
  3579. // Count: parseIntCount,
  3580. // Type: 0,
  3581. // ProjectId: item.ID,
  3582. // StorehouseId: 0,
  3583. // }
  3584. //
  3585. // service.CreateAutoDetail(detail)
  3586. //
  3587. // //查询剩余库存
  3588. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3589. // var sum_count int64
  3590. // for _, item := range goodList {
  3591. // sum_count += item.StockCount
  3592. // }
  3593. //
  3594. // //更新剩余库存
  3595. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3596. //
  3597. // //耗材
  3598. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3599. // }
  3600. //
  3601. // }
  3602. //
  3603. // }
  3604. // }
  3605. //}
  3606. }
  3607. tx.Commit()
  3608. if err == nil {
  3609. c.ServeSuccessJSON(map[string]interface{}{
  3610. "msg": "保存成功",
  3611. })
  3612. return
  3613. } else {
  3614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3615. return
  3616. }
  3617. } else {
  3618. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3619. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3620. var tempPrescription *models.HisPrescription
  3621. if len(prescriptions) > 0 {
  3622. for _, item := range prescriptions {
  3623. items := item.(map[string]interface{})
  3624. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3625. utils.ErrorLog("id")
  3626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3627. return
  3628. }
  3629. id := int64(items["id"].(float64))
  3630. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3631. tempPrescription = &new_prescription
  3632. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3633. utils.ErrorLog("type")
  3634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3635. return
  3636. }
  3637. types := int64(items["type"].(float64))
  3638. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3639. utils.ErrorLog("med_type")
  3640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3641. return
  3642. }
  3643. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3644. if med_type == "0" {
  3645. med_type = "14"
  3646. }
  3647. //if order_status == 0 {
  3648. // order_status = 1
  3649. //}
  3650. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3651. utils.ErrorLog("pre_time")
  3652. }
  3653. preTime, _ := items["pre_time"].(string)
  3654. timeLayout := "2006-01-02"
  3655. loc, _ := time.LoadLocation("Local")
  3656. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3657. result := strings.Split(preTime, " ")
  3658. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3659. fmt.Println("theTime30000000000000000000000", theTime3.Unix())
  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. project := models.HisProject{
  10275. ProjectName: item.ProjectName,
  10276. Price: item.Price,
  10277. Unit: item.Unit,
  10278. CostClassify: item.CostClassify,
  10279. ExecutiveSection: item.ExecutiveSection,
  10280. MedicalCoverage: item.MedicalCoverage,
  10281. UserOrgId: orgId,
  10282. Status: 1,
  10283. CreatedTime: time.Now().Unix(),
  10284. Pinyin: item.Pinyin,
  10285. Wubi: item.Wubi,
  10286. StatisticalClassification: item.StatisticalClassification,
  10287. DiseaseDirectory: item.DiseaseDirectory,
  10288. IsRecord: item.IsRecord,
  10289. MedicalCode: item.MedicalCode,
  10290. TubeColor: item.TubeColor,
  10291. SingleDose: item.SingleDose,
  10292. DeliveryWay: item.DeliveryWay,
  10293. NumberDays: item.NumberDays,
  10294. Total: item.Total,
  10295. Category: item.Category,
  10296. MedicalStatus: item.MedicalStatus,
  10297. SpecailProject: item.SpecailProject,
  10298. RecordDate: item.RecordDate,
  10299. Remark: item.Remark,
  10300. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10301. ExecutionFrequency: item.ExecutionFrequency,
  10302. }
  10303. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10304. if errcodeproject == gorm.ErrRecordNotFound {
  10305. service.CreateProjectInfomation(&project)
  10306. } else if errcodeproject == nil {
  10307. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10308. }
  10309. log := models.ExportLog{
  10310. LogType: 6,
  10311. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10312. TotalNum: int64(len(total_goods)),
  10313. FailNum: int64(len(errLogs)),
  10314. SuccessNum: int64(len(projectList)),
  10315. CreateTime: time.Now().Unix(),
  10316. UpdateTime: time.Now().Unix(),
  10317. ExportTime: export_time,
  10318. Status: 1,
  10319. }
  10320. service.CreateExportLog(&log)
  10321. c.ServeSuccessJSON(map[string]interface{}{
  10322. "msg": "导入成功",
  10323. "total_num": len(total_goods),
  10324. "success_num": len(projectList),
  10325. "fail_num": int64(len(errLogs)),
  10326. })
  10327. }
  10328. } else {
  10329. log := models.ExportLog{
  10330. LogType: 6,
  10331. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10332. TotalNum: int64(len(total_goods)),
  10333. FailNum: int64(len(errLogs)),
  10334. SuccessNum: int64(len(projectList)),
  10335. CreateTime: time.Now().Unix(),
  10336. UpdateTime: time.Now().Unix(),
  10337. ExportTime: export_time,
  10338. Status: 1,
  10339. }
  10340. service.CreateExportLog(&log)
  10341. c.ServeSuccessJSON(map[string]interface{}{
  10342. "msg": "导入成功",
  10343. "total_num": len(total_goods),
  10344. "success_num": len(projectList),
  10345. "fail_num": int64(len(errLogs)),
  10346. })
  10347. }
  10348. }
  10349. //func (this *HisApiController) EditProjectInformation(){
  10350. //
  10351. // id, _ := this.GetInt64("id")
  10352. // project_team := this.GetString("project_team")
  10353. // price := this.GetString("price")
  10354. // price_float, _ := strconv.ParseFloat(price, 64)
  10355. // pinyin := this.GetString("pinyin")
  10356. // wubi := this.GetString("wubi")
  10357. // tube_color, _ := this.GetInt64("tube_color")
  10358. // team_type, _ := this.GetInt64("team_type")
  10359. // remark := this.GetString("remark")
  10360. // ids := this.GetString("ids")
  10361. // item_id := this.GetString("item_id")
  10362. // projectTeam := models.XtHisProjectTeam{
  10363. // ProjectTeam: project_team,
  10364. // Price: price_float,
  10365. // Pinyin: pinyin,
  10366. // Wubi: wubi,
  10367. // TubeColor: tube_color,
  10368. // TeamType: team_type,
  10369. // Remark: remark,
  10370. // ProjectId: ids,
  10371. // ItemId: item_id,
  10372. // }
  10373. //
  10374. //
  10375. // dataBody := make(map[string]interface{}, 0)
  10376. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10377. // if err != nil {
  10378. // utils.ErrorLog(err.Error())
  10379. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10380. // return
  10381. // }
  10382. //
  10383. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10384. //
  10385. //
  10386. // if err != nil {
  10387. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10388. // return
  10389. // }
  10390. //
  10391. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10392. // infos, _ := dataBody["info"].([]interface{})
  10393. // if len(infos) > 0 {
  10394. // var ids []string
  10395. //
  10396. // for _, item := range infos {
  10397. // items := item.(map[string]interface{})
  10398. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10399. // utils.ErrorLog("id")
  10400. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10401. // return
  10402. // }
  10403. // id := int64(items["id"].(float64))
  10404. //
  10405. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10406. // utils.ErrorLog("type")
  10407. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10408. // return
  10409. // }
  10410. // types := int64(items["type"].(float64))
  10411. //
  10412. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10413. // utils.ErrorLog("number")
  10414. // }
  10415. //
  10416. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10417. //
  10418. // projectList := models.XtHisProjectList{
  10419. // Number: number,
  10420. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10421. // ProjectId: id,
  10422. // Status: 1,
  10423. // CreatedTime: time.Now().Unix(),
  10424. // UpdatedTime: time.Now().Unix(),
  10425. // TeamId: projectTeam.ID,
  10426. // Type: types,
  10427. // }
  10428. // list := projectList
  10429. //
  10430. // service.CreateProjectList(&list)
  10431. //
  10432. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10433. //
  10434. // }
  10435. // ids_str := strings.Join(ids, ",")
  10436. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10437. // service.SaveProjectTeam(&projectTeam)
  10438. // this.ServeSuccessJSON(map[string]interface{}{
  10439. // "projectTeam": projectTeam,
  10440. // })
  10441. // }
  10442. // }
  10443. //}
  10444. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10445. name := c.GetString("name")
  10446. mode_id, _ := c.GetInt64("mode", 0)
  10447. types, _ := c.GetInt64("type", 0)
  10448. patient_id, _ := c.GetInt64("patient_id", 0)
  10449. types = 1
  10450. adminInfo := c.GetAdminUserInfo()
  10451. template := &models.HisPrescriptionTemplate{
  10452. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10453. PatientId: patient_id,
  10454. Type: types,
  10455. Status: 1,
  10456. Ctime: time.Now().Unix(),
  10457. Mtime: time.Now().Unix(),
  10458. Name: name,
  10459. Mode: mode_id,
  10460. }
  10461. dataBody := make(map[string]interface{}, 0)
  10462. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10463. if err != nil {
  10464. utils.ErrorLog(err.Error())
  10465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10466. return
  10467. }
  10468. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10469. //如果已经存在记录则删除处方
  10470. if template_one.ID > 0 {
  10471. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10472. var ids []int64
  10473. var org_id int64
  10474. for _, item := range ps {
  10475. org_id = c.GetAdminUserInfo().CurrentOrgId
  10476. ids = append(ids, item.ID)
  10477. }
  10478. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10479. if err2 == nil {
  10480. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10481. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10482. if len(prescriptions) > 0 {
  10483. for _, item := range prescriptions {
  10484. items := item.(map[string]interface{})
  10485. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10486. utils.ErrorLog("type")
  10487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10488. return
  10489. }
  10490. types := int64(items["type"].(float64))
  10491. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10492. utils.ErrorLog("med_type")
  10493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10494. return
  10495. }
  10496. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10497. ctime := time.Now().Unix()
  10498. prescription := &models.HisPrescriptionInfoTemplate{
  10499. PatientId: patient_id,
  10500. UserOrgId: adminInfo.CurrentOrgId,
  10501. Ctime: ctime,
  10502. Mtime: ctime,
  10503. Type: types,
  10504. Modifier: adminInfo.AdminUser.Id,
  10505. Creator: adminInfo.AdminUser.Id,
  10506. Status: 1,
  10507. PTemplateId: template_one.ID,
  10508. MedType: med_type,
  10509. }
  10510. service.CreateHisPrescriptionInfoTemplate(prescription)
  10511. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10512. advices := items["advices"].([]interface{})
  10513. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10514. ctime := time.Now().Unix()
  10515. mtime := ctime
  10516. if len(advices) > 0 {
  10517. for _, advice := range advices {
  10518. var s models.HisPrescriptionAdviceTemplate
  10519. s.PrescriptionId = prescription.ID
  10520. s.AdviceType = 2
  10521. s.StopState = 2
  10522. s.ExecutionState = 2
  10523. s.Status = 1
  10524. s.UserOrgId = adminInfo.CurrentOrgId
  10525. s.CreatedTime = ctime
  10526. s.UpdatedTime = mtime
  10527. s.PatientId = patient_id
  10528. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10529. if errcode > 0 {
  10530. c.ServeFailJSONWithSGJErrorCode(errcode)
  10531. return
  10532. }
  10533. service.CreateHisPrescriptionAdviceTemplate(&s)
  10534. }
  10535. }
  10536. }
  10537. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10538. projects := items["project"].([]interface{})
  10539. if len(projects) > 0 {
  10540. for _, project := range projects {
  10541. var p models.HisPrescriptionProjectTemplate
  10542. p.PrescriptionId = prescription.ID
  10543. p.Ctime = time.Now().Unix()
  10544. p.Mtime = time.Now().Unix()
  10545. p.PatientId = patient_id
  10546. p.UserOrgId = adminInfo.CurrentOrgId
  10547. p.Status = 1
  10548. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10549. if errcode > 0 {
  10550. c.ServeFailJSONWithSGJErrorCode(errcode)
  10551. return
  10552. }
  10553. service.CreateHisPrescriptionProjectTemplate(&p)
  10554. }
  10555. }
  10556. }
  10557. }
  10558. c.ServeSuccessJSON(map[string]interface{}{
  10559. "msg": "创建成功",
  10560. })
  10561. }
  10562. }
  10563. } else {
  10564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10565. return
  10566. }
  10567. } else {
  10568. err3 := service.CreateHisPrescriptionTemplate(template)
  10569. if err3 == nil {
  10570. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10571. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10572. if len(prescriptions) > 0 {
  10573. for _, item := range prescriptions {
  10574. items := item.(map[string]interface{})
  10575. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10576. utils.ErrorLog("type")
  10577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10578. return
  10579. }
  10580. types := int64(items["type"].(float64))
  10581. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10582. utils.ErrorLog("med_type")
  10583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10584. return
  10585. }
  10586. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10587. ctime := time.Now().Unix()
  10588. prescription := &models.HisPrescriptionInfoTemplate{
  10589. PatientId: patient_id,
  10590. UserOrgId: adminInfo.CurrentOrgId,
  10591. Ctime: ctime,
  10592. Mtime: ctime,
  10593. Type: types,
  10594. Modifier: adminInfo.AdminUser.Id,
  10595. Creator: adminInfo.AdminUser.Id,
  10596. Status: 1,
  10597. PTemplateId: template.ID,
  10598. MedType: med_type,
  10599. }
  10600. service.CreateHisPrescriptionInfoTemplate(prescription)
  10601. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10602. advices := items["advices"].([]interface{})
  10603. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10604. ctime := time.Now().Unix()
  10605. mtime := ctime
  10606. if len(advices) > 0 {
  10607. for _, advice := range advices {
  10608. var s models.HisPrescriptionAdviceTemplate
  10609. s.PrescriptionId = prescription.ID
  10610. s.AdviceType = 2
  10611. s.StopState = 2
  10612. s.ExecutionState = 2
  10613. s.Status = 1
  10614. s.UserOrgId = adminInfo.CurrentOrgId
  10615. s.CreatedTime = ctime
  10616. s.UpdatedTime = mtime
  10617. s.PatientId = patient_id
  10618. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10619. if errcode > 0 {
  10620. c.ServeFailJSONWithSGJErrorCode(errcode)
  10621. return
  10622. }
  10623. service.CreateHisPrescriptionAdviceTemplate(&s)
  10624. }
  10625. }
  10626. }
  10627. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10628. projects := items["project"].([]interface{})
  10629. if len(projects) > 0 {
  10630. for _, project := range projects {
  10631. var p models.HisPrescriptionProjectTemplate
  10632. p.PrescriptionId = prescription.ID
  10633. p.Ctime = time.Now().Unix()
  10634. p.Mtime = time.Now().Unix()
  10635. p.PatientId = patient_id
  10636. p.UserOrgId = adminInfo.CurrentOrgId
  10637. p.Status = 1
  10638. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10639. if errcode > 0 {
  10640. c.ServeFailJSONWithSGJErrorCode(errcode)
  10641. return
  10642. }
  10643. service.CreateHisPrescriptionProjectTemplate(&p)
  10644. }
  10645. }
  10646. }
  10647. }
  10648. c.ServeSuccessJSON(map[string]interface{}{
  10649. "msg": "创建成功",
  10650. })
  10651. }
  10652. }
  10653. } else {
  10654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10655. return
  10656. }
  10657. }
  10658. }
  10659. func (c *HisApiController) PreSettle() {
  10660. id, _ := c.GetInt64("id")
  10661. record_time := c.GetString("record_time")
  10662. his_patient_id, _ := c.GetInt64("his_patient_id")
  10663. timeLayout := "2006-01-02"
  10664. loc, _ := time.LoadLocation("Local")
  10665. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10666. diagnosis_id := c.GetString("diagnosis")
  10667. sick_type, _ := c.GetInt64("sick_type")
  10668. reg_type, _ := c.GetInt64("p_type")
  10669. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10671. if err != nil {
  10672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10673. return
  10674. }
  10675. recordDateTime := theTime.Unix()
  10676. adminUser := c.GetAdminUserInfo()
  10677. var prescriptions []*models.HisPrescription
  10678. var start_time int64
  10679. var end_time int64
  10680. ids_str := c.GetString("ids")
  10681. ids_arr := strings.Split(ids_str, ",")
  10682. fmt.Println(reg_type)
  10683. if settle_accounts_type == 1 { //日结
  10684. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10685. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10686. } else {
  10687. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10688. }
  10689. fmt.Println(prescriptions)
  10690. } else { //月结
  10691. start_time_str := c.GetString("start_time")
  10692. end_time_str := c.GetString("end_time")
  10693. timeLayout := "2006-01-02"
  10694. loc, _ := time.LoadLocation("Local")
  10695. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10696. if err != nil {
  10697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10698. return
  10699. }
  10700. recordStartTime := theStartTime.Unix()
  10701. start_time = recordStartTime
  10702. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10703. if err != nil {
  10704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10705. return
  10706. }
  10707. recordEndTime := theEndTime.Unix()
  10708. end_time = recordEndTime
  10709. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10710. }
  10711. if reg_type == 1111 || reg_type == 1112 {
  10712. reg_type = 11
  10713. }
  10714. timestamp := time.Now().Unix()
  10715. tempTime := time.Unix(timestamp, 0)
  10716. timeFormat := tempTime.Format("20060102150405")
  10717. chrgBchno := rand.Intn(100000) + 10000
  10718. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10719. strconv.FormatInt(his.PatientId, 10)
  10720. var ids []int64
  10721. for _, item := range prescriptions {
  10722. ids = append(ids, item.ID)
  10723. }
  10724. fmt.Println(ids)
  10725. var total float64
  10726. for _, item := range prescriptions {
  10727. fmt.Println(item)
  10728. if item.Type == 1 { //药品
  10729. for _, subItem := range item.HisDoctorAdviceInfo {
  10730. total = total + (subItem.Price * subItem.PrescribingNumber)
  10731. }
  10732. }
  10733. if item.Type == 2 { //项目
  10734. for _, subItem := range item.HisPrescriptionProject {
  10735. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10736. total = total + (subItem.Price * cnt)
  10737. }
  10738. }
  10739. for _, subItem := range item.HisAdditionalCharge {
  10740. total = total + (subItem.Price * float64(subItem.Count))
  10741. }
  10742. }
  10743. allTotal := fmt.Sprintf("%.2f", total)
  10744. totals, _ := strconv.ParseFloat(allTotal, 64)
  10745. order := &models.HisOrder{
  10746. UserOrgId: adminUser.CurrentOrgId,
  10747. HisPatientId: his.ID,
  10748. PatientId: id,
  10749. SettleAccountsDate: recordDateTime,
  10750. Ctime: time.Now().Unix(),
  10751. Mtime: time.Now().Unix(),
  10752. Status: 1,
  10753. OrderStatus: 1,
  10754. MdtrtId: his.Number,
  10755. Number: chrg_bchno,
  10756. MedfeeSumamt: totals,
  10757. SettleEndTime: end_time,
  10758. SettleStartTime: start_time,
  10759. SettleType: settle_accounts_type,
  10760. PsnPartAmt: totals,
  10761. PsnCashPay: totals,
  10762. PType: 2,
  10763. IsPre: 1,
  10764. MedType: strconv.Itoa(int(reg_type)),
  10765. Diagnosis: diagnosis_id,
  10766. }
  10767. err = service.CreateOrder(order)
  10768. if err != nil {
  10769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10770. return
  10771. }
  10772. var customs []*Custom
  10773. for _, item := range prescriptions {
  10774. fmt.Println(item.Type)
  10775. if item.Type == 1 { //药品
  10776. for _, subItem := range item.HisDoctorAdviceInfo {
  10777. cus := &Custom{
  10778. AdviceId: subItem.ID,
  10779. ProjectId: 0,
  10780. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10781. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10782. FeedetlSn: subItem.FeedetlSn,
  10783. Price: fmt.Sprintf("%.2f", subItem.Price),
  10784. MedListCodg: subItem.MedListCodg,
  10785. Type: 1,
  10786. }
  10787. customs = append(customs, cus)
  10788. }
  10789. }
  10790. if item.Type == 2 { //项目
  10791. for _, subItem := range item.HisPrescriptionProject {
  10792. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10793. cus := &Custom{
  10794. AdviceId: 0,
  10795. ProjectId: subItem.ID,
  10796. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10797. Cut: fmt.Sprintf("%.2f", cnt),
  10798. FeedetlSn: subItem.FeedetlSn,
  10799. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10800. MedListCodg: subItem.MedListCodg,
  10801. Type: 2,
  10802. }
  10803. customs = append(customs, cus)
  10804. }
  10805. }
  10806. for _, item := range item.HisAdditionalCharge {
  10807. cus := &Custom{
  10808. ItemId: item.ID,
  10809. AdviceId: 0,
  10810. ProjectId: 0,
  10811. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10812. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10813. FeedetlSn: item.FeedetlSn,
  10814. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10815. MedListCodg: item.XtHisAddtionConfig.Code,
  10816. Type: 3,
  10817. }
  10818. customs = append(customs, cus)
  10819. }
  10820. }
  10821. fmt.Println(customs)
  10822. for _, item := range customs {
  10823. var advice_id int64 = 0
  10824. var project_id int64 = 0
  10825. var item_id int64 = 0
  10826. var types int64 = 0
  10827. if item.Type == 1 {
  10828. advice_id = item.AdviceId
  10829. project_id = 0
  10830. item_id = 0
  10831. } else if item.Type == 2 {
  10832. advice_id = 0
  10833. item_id = 0
  10834. project_id = item.ProjectId
  10835. } else if item.Type == 3 {
  10836. advice_id = 0
  10837. item_id = item.ItemId
  10838. project_id = 0
  10839. }
  10840. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10841. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10842. pric, _ := strconv.ParseFloat(item.Price, 32)
  10843. info := &models.HisOrderInfo{
  10844. OrderNumber: order.Number,
  10845. UploadDate: time.Now().Unix(),
  10846. AdviceId: advice_id,
  10847. DetItemFeeSumamt: detItemFeeSumamt,
  10848. Cnt: cut,
  10849. Pric: pric,
  10850. PatientId: id,
  10851. Status: 1,
  10852. Mtime: time.Now().Unix(),
  10853. Ctime: time.Now().Unix(),
  10854. UserOrgId: adminUser.CurrentOrgId,
  10855. HisPatientId: his.ID,
  10856. OrderId: order.ID,
  10857. ProjectId: project_id,
  10858. Type: types,
  10859. ItemId: item_id,
  10860. }
  10861. service.CreateOrderInfo(info)
  10862. }
  10863. his.SickType = sick_type
  10864. service.UpdataHisPateint(&his)
  10865. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10866. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10867. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10868. if err == nil {
  10869. c.ServeSuccessJSON(map[string]interface{}{
  10870. "msg": "结算成功",
  10871. })
  10872. }
  10873. }
  10874. type CustomOrderInfo struct {
  10875. Name string
  10876. Spec string
  10877. Unit string
  10878. Count float64
  10879. Price float64
  10880. Total float64
  10881. }
  10882. func (c *HisApiController) GetPrivateExpensesInfo() {
  10883. order_id, _ := c.GetInt64("id", 0)
  10884. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10885. order, _ := service.GetHisOrderByID(order_id)
  10886. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10887. if order.ID == 0 {
  10888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10889. return
  10890. }
  10891. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10892. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10893. org_id := c.GetAdminUserInfo().CurrentOrgId
  10894. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10895. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10896. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10897. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10898. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10899. //var orderInfos_four []*models.HisOrderInfoTwo
  10900. //for _, item := range orderInfos_three {
  10901. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10902. // item.HisPrescriptionProject.IsCheckTeam = 1
  10903. // orderInfos_four = append(orderInfos_four, item)
  10904. //
  10905. // }
  10906. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10907. // item.HisPrescriptionProject.IsCheckTeam = 2
  10908. // orderInfos_two = append(orderInfos_two, item)
  10909. // }
  10910. //}
  10911. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10912. //var cus_slice []CustomOrderInfo
  10913. //for _, item := range new_order_info {
  10914. // var cus CustomOrderInfo
  10915. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10916. // cus.Unit = ""
  10917. // cus.Spec = ""
  10918. // var total float64
  10919. // for _, subItem := range orderInfos_four {
  10920. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10921. // total = total + subItem.DetItemFeeSumamt
  10922. // fmt.Println(subItem.DetItemFeeSumamt)
  10923. // }
  10924. // }
  10925. // cus.Count = 1
  10926. // cus.Total = total
  10927. // cus_slice = append(cus_slice, cus)
  10928. //}
  10929. orderInfos = append(orderInfos, orderInfos_two...)
  10930. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10931. //orderInfos = append(orderInfos, orderInfos_three...)
  10932. //}/**/
  10933. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10934. c.ServeSuccessJSON(map[string]interface{}{
  10935. "order": order,
  10936. "order_info": orderInfos,
  10937. "patient": patient,
  10938. "admin_info": adminInfo,
  10939. "his": his,
  10940. "current_admin": role,
  10941. "org_config": miConfig,
  10942. //"new_order_info": cus_slice,
  10943. })
  10944. }
  10945. func (this *HisApiController) ChangeMedType() {
  10946. med_type := this.GetString("med_type")
  10947. old_med_type := this.GetString("old_med_type")
  10948. ids := this.GetString("ids")
  10949. settle_type, _ := this.GetInt64("settle_type")
  10950. start_time := this.GetString("start_time")
  10951. end_time := this.GetString("end_time")
  10952. ids_arr := strings.Split(ids, ",")
  10953. if settle_type == 1 { //日结
  10954. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10955. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10956. prescription.MedType = med_type
  10957. err := service.SaveHisPrescriptionTwo(&prescription)
  10958. if err == nil {
  10959. this.ServeSuccessJSON(map[string]interface{}{
  10960. "msg": "修改成功",
  10961. })
  10962. } else {
  10963. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10964. return
  10965. }
  10966. } else if settle_type == 2 {
  10967. timeLayout := "2006-01-02"
  10968. loc, _ := time.LoadLocation("Local")
  10969. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10970. if err != nil {
  10971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10972. return
  10973. }
  10974. recordStartTime := theStartTime.Unix()
  10975. start_time_timestamp := recordStartTime
  10976. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10977. if err != nil {
  10978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10979. return
  10980. }
  10981. recordEndTime := theEndTime.Unix()
  10982. end_time_timestamp := recordEndTime
  10983. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10984. if updateErr == nil {
  10985. this.ServeSuccessJSON(map[string]interface{}{
  10986. "msg": "修改成功",
  10987. })
  10988. } else {
  10989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10990. return
  10991. }
  10992. }
  10993. }
  10994. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10995. patient_id, _ := c.GetInt64("patient_id")
  10996. his_patient_id, _ := c.GetInt64("his_patient_id")
  10997. record_date := c.GetString("record_date")
  10998. start_time := c.GetString("start_time")
  10999. end_time := c.GetString("end_time")
  11000. order_status, _ := c.GetInt64("type", 0)
  11001. p_type, _ := c.GetInt64("p_type", 0)
  11002. order_id, _ := c.GetInt64("order_id", 0)
  11003. timeLayout := "2006-01-02"
  11004. loc, _ := time.LoadLocation("Local")
  11005. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11006. if err != nil {
  11007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11008. return
  11009. }
  11010. recordDateTime := theTime.Unix()
  11011. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11012. if err != nil {
  11013. }
  11014. startRecordDateTime := startTime.Unix()
  11015. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11016. if err != nil {
  11017. }
  11018. endRecordDateTime := endTime.Unix()
  11019. admin := c.GetAdminUserInfo()
  11020. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11021. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11022. order, _ := service.GetHisOrderByID(order_id)
  11023. var monthPrescriptions []*models.HisPrescription
  11024. if order_status == 1 || order_status == 0 {
  11025. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11026. } else if order_status == 2 {
  11027. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11028. }
  11029. var settle_total float64
  11030. for _, item := range monthPrescriptions {
  11031. if len(item.HisPrescriptionProject) > 0 {
  11032. for _, subItem := range item.HisPrescriptionProject {
  11033. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11034. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11035. settle_total = settle_total + total
  11036. }
  11037. }
  11038. if len(item.HisDoctorAdviceInfo) > 0 {
  11039. for _, subItem := range item.HisDoctorAdviceInfo {
  11040. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11041. settle_total = settle_total + total
  11042. }
  11043. }
  11044. }
  11045. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11046. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11047. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11048. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11049. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11050. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11051. //获取所有科室信息
  11052. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11053. var dia string
  11054. for _, item := range month_p_info {
  11055. if len(dia) == 0 {
  11056. dia = item.Diagnosis
  11057. } else {
  11058. dia = dia + "," + item.Diagnosis
  11059. }
  11060. }
  11061. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11062. dia_arr = removeEmptyStrings(dia_arr)
  11063. c.ServeSuccessJSON(map[string]interface{}{
  11064. "his_info": his_patient_info,
  11065. "xt_info": xt_patient_info,
  11066. "case_history": case_history,
  11067. "info": patientPrescriptionInfo,
  11068. "last_info": lastPatientPrescriptionInfo,
  11069. "month_prescriptions": monthPrescriptions,
  11070. "order": order,
  11071. "doctors": doctors,
  11072. "department": department,
  11073. "settle_total": settle_total,
  11074. "dia_arr": dia_arr,
  11075. })
  11076. return
  11077. }
  11078. func removeEmptyStrings(input []string) []string {
  11079. var output []string
  11080. for _, s := range input {
  11081. if s != "" {
  11082. output = append(output, s)
  11083. }
  11084. }
  11085. return output
  11086. }
  11087. func removeDuplicates(input []string) []string {
  11088. seen := make(map[string]bool)
  11089. output := []string{}
  11090. for _, s := range input {
  11091. if _, exists := seen[s]; !exists {
  11092. seen[s] = true
  11093. output = append(output, s)
  11094. }
  11095. }
  11096. return output
  11097. }
  11098. func (c *HisApiController) GetHisMonthPatientInfo() {
  11099. patient_id, _ := c.GetInt64("patient_id")
  11100. his_patient_id, _ := c.GetInt64("his_patient_id")
  11101. record_date := c.GetString("record_date")
  11102. number := c.GetString("number")
  11103. start_time := c.GetString("start_time")
  11104. end_time := c.GetString("end_time")
  11105. p_type, _ := c.GetInt64("p_type")
  11106. timeLayout := "2006-01-02"
  11107. loc, _ := time.LoadLocation("Local")
  11108. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11109. if err != nil {
  11110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11111. return
  11112. }
  11113. recordDateTime := theTime.Unix()
  11114. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11115. if err != nil {
  11116. }
  11117. startRecordDateTime := startTime.Unix()
  11118. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11119. if err != nil {
  11120. }
  11121. endRecordDateTime := endTime.Unix()
  11122. admin := c.GetAdminUserInfo()
  11123. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11124. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11125. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11126. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11127. var settle_total float64
  11128. for _, item := range monthPrescriptions {
  11129. if len(item.HisPrescriptionProject) > 0 {
  11130. for _, subItem := range item.HisPrescriptionProject {
  11131. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11132. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11133. settle_total = settle_total + total
  11134. }
  11135. }
  11136. if len(item.HisDoctorAdviceInfo) > 0 {
  11137. for _, subItem := range item.HisDoctorAdviceInfo {
  11138. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11139. settle_total = settle_total + total
  11140. }
  11141. }
  11142. }
  11143. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11144. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11145. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11146. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11147. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11148. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11149. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11150. //获取所有科室信息
  11151. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11152. c.ServeSuccessJSON(map[string]interface{}{
  11153. "his_info": his_patient_info,
  11154. "xt_info": xt_patient_info,
  11155. "case_history": case_history,
  11156. "info": patientPrescriptionInfo,
  11157. "month_prescriptions": monthPrescriptions,
  11158. "order": order,
  11159. "doctors": doctors,
  11160. "department": department,
  11161. "count": count,
  11162. "drugStockConfig": drugStockConfig,
  11163. "last_info": lastPatientPrescriptionInfo,
  11164. "settle_total": settle_total,
  11165. })
  11166. return
  11167. }
  11168. func (c *HisApiController) GetAllOrder() {
  11169. org_id := c.GetAdminUserInfo().CurrentOrgId
  11170. orders, _ := service.GetNewHisOrderList(org_id)
  11171. c.ServeSuccessJSON(map[string]interface{}{
  11172. "order": orders,
  11173. })
  11174. return
  11175. }
  11176. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11177. newArr = make([]*models.HisOrderInfoTwo, 0)
  11178. for i := 0; i < len(arr); i++ {
  11179. repeat := false
  11180. for j := i + 1; j < len(arr); j++ {
  11181. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11182. repeat = true
  11183. break
  11184. }
  11185. }
  11186. if !repeat {
  11187. newArr = append(newArr, arr[i])
  11188. }
  11189. }
  11190. return
  11191. }
  11192. // 修改处方退库操作 参数传修改之前的处方数据
  11193. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11194. if advice.ExecutionState == 1 {
  11195. //查询该病人该药品是否有库存记录
  11196. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11197. if errcode == gorm.ErrRecordNotFound {
  11198. } else {
  11199. //退库
  11200. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11201. if advice.PrescribingNumberUnit == drug.MinUnit {
  11202. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11203. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11204. //退库
  11205. warehouseInfo := models.DrugWarehouseInfo{
  11206. StockMinNumber: prescribingNumber,
  11207. }
  11208. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11209. operation_time := time.Now().Unix()
  11210. creater := advice.AdviceDoctor
  11211. ctime := time.Now().Unix()
  11212. timeStr := time.Now().Format("2006-01-02")
  11213. timeArr := strings.Split(timeStr, "-")
  11214. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11215. total = total + 1
  11216. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11217. cancelStock := models.DrugCancelStock{
  11218. OrderNumber: orderNumber,
  11219. OperaTime: operation_time,
  11220. OrgId: advice.UserOrgId,
  11221. Creater: creater,
  11222. Ctime: ctime,
  11223. Status: 1,
  11224. ReturnTime: advice.AdviceDate,
  11225. Dealer: info.Dealer,
  11226. Manufacturer: info.Manufacturer,
  11227. Type: 1,
  11228. }
  11229. service.AddSigleDrugCancelStock(&cancelStock)
  11230. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11231. dealer, _ := service.GetDealerById(info.Dealer)
  11232. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11233. cancelStockInfo := models.DrugCancelStockInfo{
  11234. OrderNumber: cancelInfo.OrderNumber,
  11235. CancelStockId: cancelInfo.ID,
  11236. DrugId: info.DrugId,
  11237. Count: info.Count,
  11238. Status: 1,
  11239. Ctime: ctime,
  11240. OrgId: advice.UserOrgId,
  11241. Type: 1,
  11242. Manufacturer: manufactureName.ManufacturerName,
  11243. Dealer: dealer.DealerName,
  11244. Total: 0,
  11245. RetailPrice: info.RetailPrice,
  11246. RetailTotalPrice: info.RetailTotalPrice,
  11247. Price: info.Price,
  11248. RegisterAccount: "",
  11249. Remark: info.Remark,
  11250. BatchNumber: info.BatchNumber,
  11251. MaxUnit: info.CountUnit,
  11252. ProductDate: info.ProductDate,
  11253. ExpiryDate: info.ExpiryDate,
  11254. BatchNumberId: info.WarehouseInfoId,
  11255. }
  11256. flow := models.DrugFlow{
  11257. WarehousingId: 0,
  11258. DrugId: info.DrugId,
  11259. Number: "",
  11260. BatchNumber: info.BatchNumber,
  11261. Count: info.Count,
  11262. UserOrgId: advice.UserOrgId,
  11263. PatientId: 0,
  11264. SystemTime: ctime,
  11265. ConsumableType: 4,
  11266. IsSys: 0,
  11267. WarehousingOrder: "",
  11268. WarehouseOutId: 0,
  11269. WarehouseOutOrderNumber: "",
  11270. IsEdit: 0,
  11271. CancelStockId: cancelStock.ID,
  11272. CancelOrderNumber: cancelStock.OrderNumber,
  11273. Manufacturer: info.Manufacturer,
  11274. Dealer: info.Dealer,
  11275. Creator: advice.UserOrgId,
  11276. UpdateCreator: 0,
  11277. Status: 1,
  11278. Ctime: time.Now().Unix(),
  11279. Mtime: 0,
  11280. Price: info.Price,
  11281. WarehousingDetailId: 0,
  11282. WarehouseOutDetailId: 0,
  11283. CancelOutDetailId: 0,
  11284. ExpireDate: info.ExpiryDate,
  11285. ProductDate: info.ProductDate,
  11286. MaxUnit: info.CountUnit,
  11287. MinUnit: "",
  11288. }
  11289. service.CreatedCancelStock(cancelStockInfo)
  11290. service.CreateDrugFlowOne(flow)
  11291. } else {
  11292. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11293. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11294. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11295. warehouseInfo := models.DrugWarehouseInfo{
  11296. StockMinNumber: prescribingNumber,
  11297. }
  11298. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11299. }
  11300. operation_time := time.Now().Unix()
  11301. creater := advice.AdviceDoctor
  11302. ctime := time.Now().Unix()
  11303. timeStr := time.Now().Format("2006-01-02")
  11304. timeArr := strings.Split(timeStr, "-")
  11305. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11306. total = total + 1
  11307. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11308. cancelStock := models.DrugCancelStock{
  11309. OrderNumber: orderNumber,
  11310. OperaTime: operation_time,
  11311. OrgId: advice.UserOrgId,
  11312. Creater: creater,
  11313. Ctime: ctime,
  11314. Status: 1,
  11315. ReturnTime: advice.AdviceDate,
  11316. Dealer: info.Dealer,
  11317. Manufacturer: info.Manufacturer,
  11318. Type: 1,
  11319. }
  11320. service.AddSigleDrugCancelStock(&cancelStock)
  11321. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11322. dealer, _ := service.GetDealerById(info.Dealer)
  11323. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11324. cancelStockInfo := models.DrugCancelStockInfo{
  11325. OrderNumber: cancelInfo.OrderNumber,
  11326. CancelStockId: cancelInfo.ID,
  11327. DrugId: info.DrugId,
  11328. Count: info.Count,
  11329. Status: 1,
  11330. Ctime: ctime,
  11331. OrgId: advice.UserOrgId,
  11332. Type: 1,
  11333. Manufacturer: manufactureName.ManufacturerName,
  11334. Dealer: dealer.DealerName,
  11335. Total: 0,
  11336. RetailPrice: info.RetailPrice,
  11337. RetailTotalPrice: info.RetailTotalPrice,
  11338. Price: info.Price,
  11339. RegisterAccount: "",
  11340. Remark: info.Remark,
  11341. BatchNumber: info.BatchNumber,
  11342. MaxUnit: info.CountUnit,
  11343. ProductDate: info.ProductDate,
  11344. ExpiryDate: info.ExpiryDate,
  11345. BatchNumberId: info.WarehouseInfoId,
  11346. }
  11347. flow := models.DrugFlow{
  11348. WarehousingId: 0,
  11349. DrugId: info.DrugId,
  11350. Number: "",
  11351. BatchNumber: info.BatchNumber,
  11352. Count: info.Count,
  11353. UserOrgId: advice.UserOrgId,
  11354. PatientId: 0,
  11355. SystemTime: ctime,
  11356. ConsumableType: 4,
  11357. IsSys: 0,
  11358. WarehousingOrder: "",
  11359. WarehouseOutId: 0,
  11360. WarehouseOutOrderNumber: "",
  11361. IsEdit: 0,
  11362. CancelStockId: cancelStock.ID,
  11363. CancelOrderNumber: cancelStock.OrderNumber,
  11364. Manufacturer: info.Manufacturer,
  11365. Dealer: info.Dealer,
  11366. Creator: advice.AdviceDoctor,
  11367. UpdateCreator: 0,
  11368. Status: 1,
  11369. Ctime: time.Now().Unix(),
  11370. Mtime: 0,
  11371. Price: info.Price,
  11372. WarehousingDetailId: 0,
  11373. WarehouseOutDetailId: 0,
  11374. CancelOutDetailId: 0,
  11375. ExpireDate: info.ExpiryDate,
  11376. ProductDate: info.ProductDate,
  11377. MaxUnit: info.CountUnit,
  11378. MinUnit: "",
  11379. }
  11380. service.CreatedCancelStock(cancelStockInfo)
  11381. service.CreateDrugFlowOne(flow)
  11382. }
  11383. }
  11384. }
  11385. return err
  11386. }
  11387. func (this *HisApiController) DeleteNCDS() {
  11388. id, _ := this.GetInt64("id", 0)
  11389. if id > 0 {
  11390. service.DeletePsnNCDSRecordById(id)
  11391. this.ServeSuccessJSON(map[string]interface{}{
  11392. "msg": "删除成功",
  11393. })
  11394. } else {
  11395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11396. return
  11397. }
  11398. }
  11399. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11400. id, _ := c.GetInt64("id")
  11401. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11402. c.ServeSuccessJSON(map[string]interface{}{
  11403. "advice": advice,
  11404. })
  11405. return
  11406. }
  11407. func (c *HisApiController) GetHisMonthChargePatientList() {
  11408. record_date := c.GetString("record_date")
  11409. start_time := c.GetString("start_time")
  11410. end_time := c.GetString("end_time")
  11411. timeLayout := "2006-01-02"
  11412. loc, _ := time.LoadLocation("Local")
  11413. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11414. if err != nil {
  11415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11416. return
  11417. }
  11418. if err != nil {
  11419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11420. return
  11421. }
  11422. recordDateTime := theTime.Unix()
  11423. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11424. if err != nil {
  11425. }
  11426. startRecordDateTime := startTime.Unix()
  11427. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11428. if err != nil {
  11429. }
  11430. endRecordDateTime := endTime.Unix()
  11431. adminInfo := c.GetAdminUserInfo()
  11432. var tempMonthChargePatients []*service.MonthChargePatients
  11433. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11434. for _, item := range tempPatients {
  11435. //过滤没有处方的
  11436. if len(item.HisPrescription) == 0 {
  11437. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11438. }
  11439. }
  11440. c.ServeSuccessJSON(map[string]interface{}{
  11441. "list": tempMonthChargePatients,
  11442. })
  11443. }
  11444. // PrescriptionDifference 医嘱数量差值结构体
  11445. type PrescriptionDrugDifference struct {
  11446. DrugID int64 //基础库药品id
  11447. ID int64 //医嘱id
  11448. Difference float64 //差值
  11449. Unit string //单位
  11450. }
  11451. type PrescriptionGoodDifference struct {
  11452. GoodID int64 //基础库项目耗材id
  11453. ID int64 //医嘱id
  11454. Difference int64 //差值
  11455. Unit string //单位
  11456. Type int64 //类型
  11457. }
  11458. type EditCustomData struct {
  11459. adviceList []*models.HisDoctorAdviceInfo
  11460. projectList []*models.HisPrescriptionProject
  11461. }
  11462. type SrcCustomData struct {
  11463. adviceList []*models.HisDoctorAdviceInfo
  11464. projectList []*models.HisPrescriptionProject
  11465. }
  11466. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11467. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11468. differences := make([]*PrescriptionDrugDifference, 0)
  11469. // 创建一个 map 来存储第一个切片中的药品信息
  11470. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11471. for _, advice := range firstPrescription {
  11472. firstMap[advice.DrugId] = advice
  11473. }
  11474. // 遍历第二个切片中的药品信息,并比较数量差值
  11475. for _, advice := range secondPrescription {
  11476. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11477. diff := &PrescriptionDrugDifference{
  11478. DrugID: advice.DrugId,
  11479. ID: firstAdvice.ID,
  11480. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11481. Unit: firstAdvice.PrescribingNumberUnit,
  11482. }
  11483. differences = append(differences, diff)
  11484. }
  11485. }
  11486. return differences
  11487. }
  11488. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11489. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11490. differences := make([]*PrescriptionGoodDifference, 0)
  11491. // 创建一个 map 来存储第一个切片中的耗材信息
  11492. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11493. for _, good := range firstPrescription {
  11494. firstMap[good.ProjectId] = good
  11495. }
  11496. // 遍历第二个切片中的耗材信息,并比较数量差值
  11497. for _, good := range secondPrescription {
  11498. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11499. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11500. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11501. diff := &PrescriptionGoodDifference{
  11502. GoodID: good.ProjectId,
  11503. ID: firstGood.ID,
  11504. Difference: count - firstCount,
  11505. Unit: firstGood.Unit,
  11506. Type: firstGood.Type,
  11507. }
  11508. differences = append(differences, diff)
  11509. }
  11510. }
  11511. return differences
  11512. }
  11513. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11514. var adviceList []*models.HisDoctorAdviceInfo
  11515. var projectList []*models.HisPrescriptionProject
  11516. var advice_ids []int64
  11517. var project_ids []int64
  11518. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11519. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11520. //var tempPrescription *models.HisPrescriptionProjectscription
  11521. if len(prescriptions) > 0 {
  11522. for _, item := range prescriptions {
  11523. items := item.(map[string]interface{})
  11524. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11525. advices := items["advices"].([]interface{})
  11526. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11527. groupNo := int64(0)
  11528. ctime := time.Now().Unix()
  11529. mtime := ctime
  11530. if len(advices) > 0 {
  11531. for _, advice := range advices {
  11532. var s models.HisDoctorAdviceInfo
  11533. s.AdviceType = 2
  11534. s.StopState = 2
  11535. s.ExecutionState = 2
  11536. s.Status = 1
  11537. s.Groupno = groupNo
  11538. s.CreatedTime = ctime
  11539. s.UpdatedTime = mtime
  11540. s.IsSettle = 2
  11541. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11542. //存储切片中
  11543. if s.ID > 0 {
  11544. advice_ids = append(advice_ids, s.ID)
  11545. adviceList = append(adviceList, &s)
  11546. }
  11547. }
  11548. }
  11549. }
  11550. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11551. projects := items["project"].([]interface{})
  11552. if len(projects) > 0 {
  11553. for _, project := range projects {
  11554. var p models.HisPrescriptionProject
  11555. p.Ctime = time.Now().Unix()
  11556. p.Mtime = time.Now().Unix()
  11557. p.Status = 1
  11558. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11559. if p.ID > 0 {
  11560. project_ids = append(project_ids, p.ID)
  11561. projectList = append(projectList, &p)
  11562. }
  11563. }
  11564. }
  11565. }
  11566. }
  11567. }
  11568. }
  11569. editCustomData.projectList = projectList
  11570. editCustomData.adviceList = adviceList
  11571. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11572. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11573. srcCustomData.adviceList = list
  11574. srcCustomData.projectList = list2
  11575. return
  11576. }