his_api_controller.go 506KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. if number >= 1000 {
  187. zero = "0000" + strconv.FormatInt(number, 10)
  188. } else if number >= 10000 {
  189. zero = "000" + strconv.FormatInt(number, 10)
  190. } else if number >= 100000 {
  191. zero = "00" + strconv.FormatInt(number, 10)
  192. } else if number >= 1000000 {
  193. zero = "0" + strconv.FormatInt(number, 10)
  194. } else {
  195. zero = strconv.FormatInt(number, 10)
  196. }
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. order.PsnCashPay = order.MedfeeSumamt
  1021. for _, item := range orderInfos {
  1022. if item.MedChrgitmType == "01" { //床位费
  1023. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1024. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1025. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1026. }
  1027. if item.MedChrgitmType == "02" { //诊察费
  1028. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1029. //zhenChaCostSelfTotal = zhenChaCostTotal
  1030. }
  1031. if item.MedChrgitmType == "03" { //检查费
  1032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //检查费
  1037. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "04" { //化验费
  1042. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "05" { //治疗费
  1047. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "06" { //手术费
  1052. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1057. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "09" { //西药费
  1062. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1064. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1065. }
  1066. if item.MedChrgitmType == "11" { //中成费
  1067. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. }
  1071. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1072. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. }
  1076. }
  1077. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1078. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1080. var dia_config []*models.HisXtDiagnoseConfig
  1081. var diagnosis_ids []string
  1082. if his.ID > 0 {
  1083. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1084. } else {
  1085. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1086. }
  1087. for _, item := range diagnosis_ids {
  1088. id, _ := strconv.ParseInt(item, 10, 64)
  1089. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1090. dia_config = append(dia_config, diagnosisConfig)
  1091. }
  1092. var rf []CustomFundPay
  1093. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1094. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "patient": patient,
  1097. "order_infos": orderInfos,
  1098. "diagnosis": name,
  1099. "bedCostTotal": bedCostTotal,
  1100. "bedCostSelfTotal": bedCostTotal,
  1101. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1102. "operationCostTotal": operationCostTotal,
  1103. "operationCostSelfTotal": operationCostTotal,
  1104. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1105. "otherCostTotal": otherCostTotal,
  1106. "otherCostSelfTotal": otherCostTotal,
  1107. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1108. "materialCostTotal": materialCostTotal,
  1109. "materialCostSelfTotal": materialCostTotal,
  1110. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1111. "westernMedicineCostTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1117. "checkCostTotal": checkCostTotal,
  1118. "checkCostSelfTotal": checkCostTotal,
  1119. "zhenChaCostTotal": zhenChaCostTotal,
  1120. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1121. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1122. "laboratoryCostTotal": laboratoryCostTotal,
  1123. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1124. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1125. "treatCostTotal": treatCostTotal,
  1126. "treatCostSelfTotal": treatCostTotal,
  1127. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1128. "charge_admin": charge_admin,
  1129. "printor_admin": printor_admin,
  1130. "org_name": org.OrgName,
  1131. "org_code": miConfig.Code,
  1132. "name": patient.Name,
  1133. "number": order.MdtrtId,
  1134. "date": order.SettleAccountsDate,
  1135. "info": order,
  1136. "new_order": order,
  1137. "his_hospital": his_hospital,
  1138. "his": his,
  1139. "funds": rf,
  1140. "dia_config": dia_config,
  1141. })
  1142. }
  1143. func (c *HisApiController) RefudDetail() {
  1144. order_id, _ := c.GetInt64("order_id")
  1145. order, _ := service.GetHisOrderByID(order_id)
  1146. adminUser := c.GetAdminUserInfo()
  1147. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "msg": "撤销成功",
  1150. })
  1151. }
  1152. func (c *HisApiController) Sscard() {
  1153. //r := CardInit()
  1154. //if r == 0 {
  1155. // GetBaseInfo()
  1156. //}
  1157. //c.ServeSuccessJSON(map[string]interface{}{
  1158. // "list": "11",
  1159. //})
  1160. }
  1161. func GetBaseInfo() error {
  1162. //handle := syscall.MustLoadDLL("SSCard.dll")
  1163. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1164. //
  1165. //str := make([]byte, 256)
  1166. //str1 := make([]byte, 256)
  1167. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1168. //if ferr != nil {
  1169. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1170. // return ferr
  1171. //}
  1172. //
  1173. //fmt.Println(string(str))
  1174. //
  1175. //fmt.Println(r)
  1176. return nil
  1177. }
  1178. func CardInit() int {
  1179. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1180. //add := DllTestDef.MustFindProc("Init")
  1181. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1182. //if err != nil {
  1183. // fmt.Println("SSCard的运算结果为:", ret)
  1184. //}
  1185. //result := int(ret)
  1186. return 0
  1187. }
  1188. func IntPtr(n int) uintptr {
  1189. return uintptr(n)
  1190. }
  1191. func StrPtr(s string) uintptr {
  1192. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1193. }
  1194. func (c *HisApiController) GetHisPatientList() {
  1195. //types, _ := c.GetInt64("type", 0)
  1196. record_date := c.GetString("record_date")
  1197. sch_type, _ := c.GetInt64("sch_type")
  1198. timeLayout := "2006-01-02"
  1199. loc, _ := time.LoadLocation("Local")
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. recordDateTime := theTime.Unix()
  1206. adminInfo := c.GetAdminUserInfo()
  1207. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1208. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1209. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1210. //获取当前用户的信息
  1211. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1212. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1213. //获取所有科室信息
  1214. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "list": patients,
  1217. "list_two": patients_two,
  1218. "info": adminUserInfo,
  1219. "doctors": doctors,
  1220. "department": department,
  1221. })
  1222. }
  1223. type CustomTemplate struct {
  1224. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1225. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1228. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1229. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1230. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1231. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1232. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1235. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1236. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1237. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1238. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1239. }
  1240. func (c *HisApiController) GetHisPatientInfo() {
  1241. patient_id, _ := c.GetInt64("patient_id")
  1242. his_patient_id, _ := c.GetInt64("his_patient_id")
  1243. record_date := c.GetString("record_date")
  1244. number := c.GetString("number")
  1245. //start_time := c.GetString("start_time")
  1246. //end_time := c.GetString("end_time")
  1247. p_type, _ := c.GetInt64("p_type")
  1248. timeLayout := "2006-01-02"
  1249. loc, _ := time.LoadLocation("Local")
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. recordDateTime := theTime.Unix()
  1256. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1257. //if err != nil {
  1258. //
  1259. //}
  1260. //startRecordDateTime := startTime.Unix()
  1261. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1262. //if err != nil {
  1263. //
  1264. //}
  1265. //endRecordDateTime := endTime.Unix()
  1266. admin := c.GetAdminUserInfo()
  1267. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1271. var prescriptions []*models.HisPrescription
  1272. var last_prescriptions []*models.HisPrescription
  1273. var sch_prescriptions []CustomTemplate
  1274. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1275. if p_type == 1 { //住院
  1276. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1277. for _, item := range prescriptions {
  1278. for _, subItem := range item.HisDoctorAdviceInfo {
  1279. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1280. if info.RetailPrice > 0 {
  1281. subItem.Drug.MinPrice = info.RetailPrice
  1282. }
  1283. }
  1284. }
  1285. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1286. } else { //门诊
  1287. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1288. for _, item := range prescriptions {
  1289. for _, subItem := range item.HisDoctorAdviceInfo {
  1290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1291. if info.RetailPrice > 0 {
  1292. subItem.Drug.MinPrice = info.RetailPrice
  1293. }
  1294. }
  1295. }
  1296. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1297. }
  1298. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1299. if sch.ID > 0 {
  1300. var week string
  1301. t := time.Now()
  1302. switch t.Weekday().String() {
  1303. case "Monday":
  1304. week = "周一"
  1305. break
  1306. case "Tuesday":
  1307. week = "周二"
  1308. break
  1309. case "Wednesday":
  1310. week = "周三"
  1311. break
  1312. case "Thursday":
  1313. week = "周四"
  1314. break
  1315. case "Friday":
  1316. week = "周五"
  1317. break
  1318. case "Saturday":
  1319. week = "周六"
  1320. break
  1321. case "Sunday":
  1322. week = "周日"
  1323. break
  1324. }
  1325. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1326. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1327. //根据推送频率组装新的数组
  1328. for _, item := range temp_sch_prescriptions {
  1329. var cus CustomTemplate
  1330. cus.ID = item.ID
  1331. cus.UserOrgId = item.UserOrgId
  1332. cus.PatientId = item.PatientId
  1333. cus.MedType = item.MedType
  1334. cus.RecordDate = item.RecordDate
  1335. cus.Type = item.Type
  1336. cus.PType = item.PType
  1337. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1338. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1339. if subItem.FrequencyType == 1 { //每次必推
  1340. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 { //按照天数频率
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1353. if len(advices) == 0 {
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. }
  1359. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1360. if subItem.Type == 2 {
  1361. if subItem.XtHisProject.MedicalStatus != 1 {
  1362. if subItem.FrequencyType == 1 {
  1363. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1364. }
  1365. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 2 {
  1369. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1370. now := p.Unix()
  1371. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1372. dayStr2 := "-" + dayStr
  1373. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1374. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1375. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1376. if len(projects) == 0 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. }
  1380. }
  1381. } else if subItem.Type == 3 {
  1382. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1383. if subItem.FrequencyType == 1 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 2 {
  1390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1391. now := p.Unix()
  1392. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1393. dayStr2 := "-" + dayStr
  1394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1396. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1397. if len(projects) == 0 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. sch_prescriptions = append(sch_prescriptions, cus)
  1405. }
  1406. for _, item := range sch_prescriptions {
  1407. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1408. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1409. }
  1410. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1411. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1412. }
  1413. }
  1414. }
  1415. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1416. if config.ID > 0 && config.IsOpen == 1 {
  1417. for _, item := range sch_prescriptions {
  1418. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1419. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1420. if info.RetailPrice > 0 {
  1421. subItem.Drug.MinPrice = info.RetailPrice
  1422. }
  1423. }
  1424. }
  1425. }
  1426. if config.ID > 0 && config.IsOpen == 1 {
  1427. for _, item := range sch_prescriptions {
  1428. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1429. if subItem.Type == 3 {
  1430. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1431. if info.Price > 0 {
  1432. subItem.GoodInfo.PackingPrice = info.Price
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1439. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1440. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1441. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1442. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1443. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1444. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1445. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1446. //获取所有科室信息
  1447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1448. c.ServeSuccessJSON(map[string]interface{}{
  1449. "his_info": his_patient_info,
  1450. "xt_info": xt_patient_info,
  1451. "prescription": prescriptions,
  1452. "case_history": case_history,
  1453. "info": patientPrescriptionInfo,
  1454. //"month_prescriptions": monthPrescriptions,
  1455. "order": order,
  1456. "doctors": doctors,
  1457. "department": department,
  1458. "sch_prescriptions": sch_prescriptions,
  1459. "last_prescriptions": last_prescriptions,
  1460. "schedule": sch,
  1461. "count": count,
  1462. "drugStockConfig": drugStockConfig,
  1463. "last_info": lastPatientPrescriptionInfo,
  1464. })
  1465. return
  1466. }
  1467. func (c *HisApiController) GetHisPrescriptionConfig() {
  1468. adminInfo := c.GetAdminUserInfo()
  1469. //获取医嘱模版
  1470. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1472. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1473. //获取所有基础药
  1474. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1475. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1476. if config.ID > 0 && config.IsOpen == 1 {
  1477. for _, item := range drugs {
  1478. var index = 0
  1479. for _, subItem := range item.OtherDrugWarehouseInfo {
  1480. if index == 0 {
  1481. index = index + 1
  1482. if subItem.RetailPrice > 0 {
  1483. item.MinPrice = subItem.RetailPrice
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1490. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1491. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1492. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1493. //获取所有科室信息
  1494. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1495. //获取诊断信息
  1496. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1497. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1498. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1499. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1500. //获取是否开启保存耗材出库的开关
  1501. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "drugs": drugs,
  1504. "advices_template": advices,
  1505. "drugways": drugways,
  1506. "efs": efs,
  1507. "doctors": doctors,
  1508. "department": department,
  1509. "sick": sick,
  1510. "additions": additions,
  1511. "diagnose": diagnose,
  1512. "manufacturers": manufacturers,
  1513. "goodOutOpen": goodOutOpen,
  1514. "patientDiagnose": patientDiagnose,
  1515. })
  1516. }
  1517. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1518. //获取所有基础药
  1519. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1520. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1521. if config.ID > 0 && config.IsOpen == 1 {
  1522. for _, item := range drugs {
  1523. var index = 0
  1524. for _, subItem := range item.OtherDrugWarehouseInfo {
  1525. if index == 0 {
  1526. index = index + 1
  1527. if subItem.RetailPrice > 0 {
  1528. item.MinPrice = subItem.RetailPrice
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1535. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1536. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1537. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1538. //获取所有科室信息
  1539. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1540. //获取诊断信息
  1541. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1542. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1543. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1544. //获取是否开启保存耗材出库的开关
  1545. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1546. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "drugs": drugs,
  1549. "advices_template": advices,
  1550. "drugways": drugways,
  1551. "efs": efs,
  1552. "doctors": doctors,
  1553. "department": department,
  1554. "sick": sick,
  1555. "additions": additions,
  1556. "diagnose": diagnose,
  1557. "manufacturers": manufacturers,
  1558. "goodOutOpen": goodOutOpen,
  1559. "patientDiagnose": patientDiagnose,
  1560. })
  1561. }
  1562. }
  1563. func (c *HisApiController) CreateHisPrescription() {
  1564. record_date := c.GetString("record_date")
  1565. patient_id, _ := c.GetInt64("patient_id")
  1566. reg_type, _ := c.GetInt64("reg_type")
  1567. diagnose := c.GetString("diagnose")
  1568. sick_type, _ := c.GetInt64("sick_type")
  1569. sick_history := c.GetString("sick_history")
  1570. doctor_id, _ := c.GetInt64("doctor", 0)
  1571. department, _ := c.GetInt64("department", 0)
  1572. his_patient_id, _ := c.GetInt64("his_patient_id")
  1573. p_type, _ := c.GetInt64("p_type")
  1574. patient_diagnose := c.GetString("patient_diagnose")
  1575. dataBody := make(map[string]interface{}, 0)
  1576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1577. if err != nil {
  1578. utils.ErrorLog(err.Error())
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. //edit, src := GetCompareData(dataBody)
  1583. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1584. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1585. //fmt.Println(drugResult)
  1586. //fmt.Println(goodResult)
  1587. timeLayout := "2006-01-02"
  1588. loc, _ := time.LoadLocation("Local")
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. if err != nil {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminInfo := c.GetAdminUserInfo()
  1595. recordDateTime := theTime.Unix()
  1596. //查询默认出库仓库库存
  1597. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1598. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1599. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1600. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1601. if len(lists) == 1 {
  1602. his_patient_id = lists[0].ID
  1603. }
  1604. }
  1605. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1606. //保存处方出库
  1607. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1608. //自动出库
  1609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1610. //耗材保存处方出库
  1611. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1612. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. //已发药和已收费限制逻辑
  1614. isMidicine := false
  1615. isCharge := false
  1616. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1617. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1618. if len(prescriptions) > 0 {
  1619. for _, item := range prescriptions {
  1620. items := item.(map[string]interface{})
  1621. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1622. utils.ErrorLog("id")
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. id := int64(items["id"].(float64))
  1627. if id > 0 {
  1628. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. if new_prescription.OrderStatus == 4 {
  1631. isCharge = true
  1632. }
  1633. }
  1634. }
  1635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1636. advices := items["advices"].([]interface{})
  1637. if len(advices) > 0 {
  1638. for _, advice := range advices {
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1641. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1642. }
  1643. if adviceId > 0 {
  1644. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1645. if err == nil {
  1646. if his_advice_info.IsMedicine == 1 {
  1647. isMidicine = true
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1706. return
  1707. }
  1708. //查询药品的所有库存
  1709. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1710. var total_count int64
  1711. for _, it := range list {
  1712. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1713. }
  1714. totals := strconv.FormatInt(total_count, 10)
  1715. //查询该药品是否存在开药记录
  1716. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1717. //新增处方
  1718. if advicelist.ID == 0 {
  1719. all_count, _ := strconv.ParseFloat(totals, 64)
  1720. if prescribingNumberUnit == drug.MinUnit {
  1721. 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 = p.Ctime
  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. fmt.Println("out_count_five+=====================", out_count)
  3164. fmt.Println("pareIntCount============================", parseIntCount)
  3165. //如果历史数和当前数据不想等才进行退库出库
  3166. if out_count != parseIntCount {
  3167. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3168. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3169. detail := models.AutomaticReduceDetail{
  3170. WarehouseOutId: 0,
  3171. WarehouseOutOrderNumber: "",
  3172. PatientId: p.PatientId,
  3173. Ctime: time.Now().Unix(),
  3174. Mtime: 0,
  3175. Status: 1,
  3176. RecordTime: p.RecordDate,
  3177. OrgId: p.UserOrgId,
  3178. GoodId: p.ProjectId,
  3179. GoodTypeId: 0,
  3180. Count: parseIntCount,
  3181. Type: 0,
  3182. ProjectId: lastHisProject.ID,
  3183. StorehouseId: 0,
  3184. }
  3185. service.CreateNewAutoDetail(detail, tx)
  3186. //查询剩余库存
  3187. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3188. var sum_count int64
  3189. for _, item := range goodList {
  3190. sum_count += item.StockCount
  3191. }
  3192. //更新剩余库存
  3193. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3194. //耗材
  3195. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3196. }
  3197. //判断是否是零用耗材(零用但是是出库耗材)
  3198. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3199. //查询历史出库数据
  3200. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3201. var out_count int64
  3202. for _, item := range flowGood {
  3203. out_count += item.Count
  3204. }
  3205. //如果历史数和当前数据不想等才进行退库出库
  3206. if out_count != parseIntCount {
  3207. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3208. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3209. detail := models.AutomaticReduceDetail{
  3210. WarehouseOutId: 0,
  3211. WarehouseOutOrderNumber: "",
  3212. PatientId: p.PatientId,
  3213. Ctime: time.Now().Unix(),
  3214. Mtime: 0,
  3215. Status: 1,
  3216. RecordTime: p.RecordDate,
  3217. OrgId: p.UserOrgId,
  3218. GoodId: p.ProjectId,
  3219. GoodTypeId: 0,
  3220. Count: parseIntCount,
  3221. Type: 0,
  3222. ProjectId: p.ID,
  3223. StorehouseId: 0,
  3224. }
  3225. service.CreateNewAutoDetail(detail, tx)
  3226. //查询剩余库存
  3227. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3228. var sum_count int64
  3229. for _, item := range goodList {
  3230. sum_count += item.StockCount
  3231. }
  3232. //更新剩余库存
  3233. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3234. //耗材
  3235. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3236. }
  3237. }
  3238. }
  3239. }
  3240. //记录日志
  3241. byterequest, _ := json.Marshal(p)
  3242. adviceLog := models.XtDoctorAdviceLog{
  3243. UserOrgId: p.UserOrgId,
  3244. PatientId: p.PatientId,
  3245. AdminUserId: adminInfo.AdminUser.Id,
  3246. Module: 1,
  3247. ErrLog: string(byterequest),
  3248. Status: 1,
  3249. Ctime: time.Now().Unix(),
  3250. Mtime: 0,
  3251. Source: "电脑端新建his项目",
  3252. RecordDate: p.RecordDate,
  3253. }
  3254. service.CreateDoctorAdviceLog(adviceLog)
  3255. projectList = append(projectList, p)
  3256. var randNum int
  3257. randNum = rand.Intn(10000) + 1000
  3258. timestamp := time.Now().Unix()
  3259. tempTime := time.Unix(timestamp, 0)
  3260. timeFormat := tempTime.Format("20060102150405")
  3261. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3262. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3263. //新增或者编辑项目,修改对应的标签数据
  3264. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3265. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3266. var label models.HisLabelPrintInfo
  3267. project, _ := service.GetProjectDetail(p.ProjectId)
  3268. if project.CostClassify == 3 { //类别为检验检查
  3269. if p.TeamId > 0 { //检验检查组套
  3270. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3271. if tempLabel.ID == 0 {
  3272. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3273. label.Number = tempPrescription.PrescriptionNumber
  3274. label.ProjectId = project.ID
  3275. label.Status = 1
  3276. label.IsPrint = 2
  3277. label.DoctorId = info.DoctorId
  3278. label.UserOrgId = p.UserOrgId
  3279. label.PatientId = patient_id
  3280. label.RecordDate = recordDateTime
  3281. label.Ctime = time.Now().Unix()
  3282. label.Mtime = time.Now().Unix()
  3283. label.ItemId = p.TeamId
  3284. label.FeedetlSn = p.FeedetlSn
  3285. label.PProjectId = p.ID
  3286. label.ProjectName = team.ProjectTeam
  3287. label.PatientName = patient.Name
  3288. service.CreateNewHisLabelRecord(&label, tx)
  3289. }
  3290. } else { //单条检验检查项目
  3291. label.Number = tempPrescription.PrescriptionNumber
  3292. label.ProjectId = project.ID
  3293. label.Status = 1
  3294. label.DoctorId = info.DoctorId
  3295. label.UserOrgId = p.UserOrgId
  3296. label.PatientId = patient_id
  3297. label.RecordDate = recordDateTime
  3298. label.IsPrint = 2
  3299. label.Ctime = time.Now().Unix()
  3300. label.Mtime = time.Now().Unix()
  3301. label.FeedetlSn = p.FeedetlSn
  3302. label.PProjectId = p.ID
  3303. label.ItemId = p.TeamId
  3304. label.ProjectName = project.ProjectName
  3305. label.PatientName = patient.Name
  3306. service.CreateNewHisLabelRecord(&label, tx)
  3307. }
  3308. }
  3309. }
  3310. }
  3311. service.SaveNewHisProjectTwo(&p, tx)
  3312. }
  3313. }
  3314. tx.Commit()
  3315. }
  3316. }
  3317. }
  3318. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3319. // addition := items["addition"].([]interface{})
  3320. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3321. // ctime := time.Now().Unix()
  3322. // mtime := ctime
  3323. // if len(addition) > 0 {
  3324. // for _, item := range addition {
  3325. // var s models.HisAdditionalCharge
  3326. // s.PrescriptionId = tempPrescription.ID
  3327. // s.Status = 1
  3328. // s.UserOrgId = adminInfo.CurrentOrgId
  3329. // s.RecordDate = recordDateTime
  3330. // s.CreatedTime = ctime
  3331. // s.UpdatedTime = mtime
  3332. // s.PatientId = patient_id
  3333. // s.HisPatientId = his_patient_id
  3334. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3335. // if errcode > 0 {
  3336. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3337. // return
  3338. // }
  3339. // service.CreateAdditionalCharge(&s)
  3340. // var randNum int
  3341. // randNum = rand.Intn(10000) + 1000
  3342. // timestamp := time.Now().Unix()
  3343. // tempTime := time.Unix(timestamp, 0)
  3344. // timeFormat := tempTime.Format("20060102150405")
  3345. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3346. // service.CreateAdditionalCharge(&s)
  3347. //
  3348. // }
  3349. // }
  3350. //}
  3351. }
  3352. }
  3353. //查询今日该患者开的药品处方
  3354. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3355. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3356. //药品出库
  3357. //if drugOutConfig.IsOpen == 1 {
  3358. // for _, item := range hisdoctorlist {
  3359. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3360. //
  3361. // // 查询该药品最后一次出库记录
  3362. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3363. //
  3364. // if len(druginfo) > 0 {
  3365. // //回退库存
  3366. // for _, it := range druginfo {
  3367. //
  3368. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3369. //
  3370. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3371. //
  3372. // }
  3373. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3374. //
  3375. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3376. //
  3377. // }
  3378. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3379. //
  3380. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3381. //
  3382. // }
  3383. // }
  3384. // }
  3385. //
  3386. // //删除记录
  3387. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3388. // //查询最后一次数据
  3389. // if drugOutConfig.IsOpen == 1 {
  3390. // //出库
  3391. // if drug.IsUse == 2 {
  3392. // creater := adminInfo.AdminUser.Id
  3393. //
  3394. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3395. //
  3396. // }
  3397. //
  3398. // //更新字典里面的库存
  3399. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3400. // var sum_count int64
  3401. // for _, its := range stockInfo {
  3402. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3403. // if its.MaxUnit == baseDrug.MaxUnit {
  3404. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3405. // }
  3406. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3407. // }
  3408. // //更新基础库存
  3409. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3410. // //剩余库存
  3411. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3412. //
  3413. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3414. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3415. //
  3416. // }
  3417. // }
  3418. //}
  3419. //耗材保存处方出库
  3420. //if goodOutConfig.IsOpen == 1 {
  3421. //
  3422. // //查询今日耗材出库数量
  3423. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3424. //
  3425. // for _, item := range hisgoodlist {
  3426. //
  3427. // //查询历史出库数据
  3428. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3429. // var out_count_five int64
  3430. // for _, item := range flowGood {
  3431. // out_count_five += item.Count
  3432. // }
  3433. //
  3434. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3435. //
  3436. // if out_count_five != parseIntCount {
  3437. //
  3438. // //查询耗材最后一次出库记录
  3439. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3440. // //查询默认出库仓库库存
  3441. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3442. // if len(wareOut) > 0 {
  3443. //
  3444. // for _, it := range wareOut {
  3445. // //回退库存
  3446. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3447. //
  3448. // //删除出库记录
  3449. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3450. //
  3451. // }
  3452. // }
  3453. //
  3454. // timeStr := time.Now().Format("2006-01-02")
  3455. // timeArr := strings.Split(timeStr, "-")
  3456. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3457. //
  3458. // total = total + 1
  3459. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3460. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3461. // number = number + total
  3462. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3463. //
  3464. // operation_time := time.Now().Unix()
  3465. // creater := c.GetAdminUserInfo().AdminUser.Id
  3466. //
  3467. // recordDateStr := time.Now().Format("2006-01-02")
  3468. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3469. // nowtime := recordDate.Unix()
  3470. // warehouseOut := models.WarehouseOut{
  3471. // WarehouseOutOrderNumber: warehousing_out_order,
  3472. // OperationTime: operation_time,
  3473. // OrgId: adminInfo.CurrentOrgId,
  3474. // Creater: creater,
  3475. // Ctime: time.Now().Unix(),
  3476. // Status: 1,
  3477. // WarehouseOutTime: nowtime,
  3478. // Type: 1,
  3479. // StorehouseId: storeConfig.StorehouseOutInfo,
  3480. // IsCheck: 1,
  3481. // IsSys: 1,
  3482. // }
  3483. // //查询是否生成出库单
  3484. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3485. //
  3486. // if out.ID == 0 {
  3487. // service.AddSigleWarehouseOut(&warehouseOut)
  3488. // }
  3489. //
  3490. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3491. //
  3492. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3493. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3494. //
  3495. // dialyPrepareOne := models.DialysisBeforePrepare{
  3496. // GoodTypeId: goodObj.GoodTypeId,
  3497. // GoodId: item.ProjectId,
  3498. // PatientId: item.PatientId,
  3499. // RecordDate: item.RecordDate,
  3500. // UserOrgId: adminInfo.CurrentOrgId,
  3501. // Count: parseIntCount,
  3502. // Ctime: time.Now().Unix(),
  3503. // Creater: creater,
  3504. // Status: 1,
  3505. // StorehouseId: houseConfig.StorehouseOutInfo,
  3506. // ProjectId: item.ID,
  3507. // }
  3508. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3509. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3510. //
  3511. // //查询历史出库数据
  3512. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3513. // var out_count int64
  3514. // for _, item := range flowGood {
  3515. // out_count += item.Count
  3516. // }
  3517. //
  3518. // //如果历史数和当前数据不想等才进行退库出库
  3519. // if out_count != parseIntCount {
  3520. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3521. //
  3522. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3523. // detail := models.AutomaticReduceDetail{
  3524. // WarehouseOutId: 0,
  3525. // WarehouseOutOrderNumber: "",
  3526. // PatientId: item.PatientId,
  3527. // Ctime: time.Now().Unix(),
  3528. // Mtime: 0,
  3529. // Status: 1,
  3530. // RecordTime: item.RecordDate,
  3531. // OrgId: item.UserOrgId,
  3532. // GoodId: item.ProjectId,
  3533. // GoodTypeId: 0,
  3534. // Count: parseIntCount,
  3535. // Type: 0,
  3536. // ProjectId: item.ID,
  3537. // StorehouseId: 0,
  3538. // }
  3539. //
  3540. // service.CreateAutoDetail(detail)
  3541. //
  3542. // //查询剩余库存
  3543. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3544. // var sum_count int64
  3545. // for _, item := range goodList {
  3546. // sum_count += item.StockCount
  3547. // }
  3548. //
  3549. // //更新剩余库存
  3550. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3551. //
  3552. // //耗材
  3553. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3554. // }
  3555. //
  3556. // }
  3557. //
  3558. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3559. // //查询历史出库数据
  3560. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3561. // var out_count int64
  3562. // for _, item := range flowGood {
  3563. // out_count += item.Count
  3564. // }
  3565. // //如果历史数和当前数据不想等才进行退库出库
  3566. // if out_count != parseIntCount {
  3567. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3568. //
  3569. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3570. // detail := models.AutomaticReduceDetail{
  3571. // WarehouseOutId: 0,
  3572. // WarehouseOutOrderNumber: "",
  3573. // PatientId: item.PatientId,
  3574. // Ctime: time.Now().Unix(),
  3575. // Mtime: 0,
  3576. // Status: 1,
  3577. // RecordTime: item.RecordDate,
  3578. // OrgId: item.UserOrgId,
  3579. // GoodId: item.ProjectId,
  3580. // GoodTypeId: 0,
  3581. // Count: parseIntCount,
  3582. // Type: 0,
  3583. // ProjectId: item.ID,
  3584. // StorehouseId: 0,
  3585. // }
  3586. //
  3587. // service.CreateAutoDetail(detail)
  3588. //
  3589. // //查询剩余库存
  3590. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3591. // var sum_count int64
  3592. // for _, item := range goodList {
  3593. // sum_count += item.StockCount
  3594. // }
  3595. //
  3596. // //更新剩余库存
  3597. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3598. //
  3599. // //耗材
  3600. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3601. // }
  3602. //
  3603. // }
  3604. //
  3605. // }
  3606. // }
  3607. //}
  3608. }
  3609. tx.Commit()
  3610. if err == nil {
  3611. c.ServeSuccessJSON(map[string]interface{}{
  3612. "msg": "保存成功",
  3613. })
  3614. return
  3615. } else {
  3616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3617. return
  3618. }
  3619. } else {
  3620. // 开始主事务
  3621. db := service.XTWriteDB()
  3622. tx := db.Begin()
  3623. // 在函数结束时处理事务回滚
  3624. defer func() {
  3625. if r := recover(); r != nil {
  3626. tx.Rollback()
  3627. }
  3628. }()
  3629. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3630. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3631. var tempPrescription *models.HisPrescription
  3632. if len(prescriptions) > 0 {
  3633. for _, item := range prescriptions {
  3634. items := item.(map[string]interface{})
  3635. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3636. utils.ErrorLog("id")
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3638. return
  3639. }
  3640. id := int64(items["id"].(float64))
  3641. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3642. tempPrescription = &new_prescription
  3643. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3644. utils.ErrorLog("type")
  3645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3646. return
  3647. }
  3648. types := int64(items["type"].(float64))
  3649. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3650. utils.ErrorLog("med_type")
  3651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3652. return
  3653. }
  3654. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3655. if med_type == "0" {
  3656. med_type = "14"
  3657. }
  3658. //if order_status == 0 {
  3659. // order_status = 1
  3660. //}
  3661. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3662. utils.ErrorLog("pre_time")
  3663. }
  3664. preTime, _ := items["pre_time"].(string)
  3665. timeLayout := "2006-01-02"
  3666. loc, _ := time.LoadLocation("Local")
  3667. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3668. result := strings.Split(preTime, " ")
  3669. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3670. fmt.Println("theTime30000000000000000000000", theTime3.Unix())
  3671. if err != nil {
  3672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3673. return
  3674. }
  3675. pTime := theTime2.Unix()
  3676. ctime := time.Now().Unix()
  3677. if tempPrescription.ID == 0 {
  3678. prescription := &models.HisPrescription{
  3679. ID: 0,
  3680. PatientId: patient_id,
  3681. UserOrgId: adminInfo.CurrentOrgId,
  3682. RecordDate: recordDateTime,
  3683. Ctime: ctime,
  3684. Mtime: ctime,
  3685. Type: types,
  3686. Modifier: adminInfo.AdminUser.Id,
  3687. Creator: adminInfo.AdminUser.Id,
  3688. Status: 1,
  3689. Doctor: role.UserName,
  3690. HisPatientId: his_patient_id,
  3691. OrderStatus: 1,
  3692. BatchNumber: "",
  3693. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3694. PreTime: pTime,
  3695. PType: p_type,
  3696. MedType: med_type,
  3697. }
  3698. tempPrescription = prescription
  3699. service.SaveHisPrescription(tempPrescription)
  3700. redis := service.RedisClient()
  3701. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3702. redis.Set(key, "", time.Second)
  3703. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3704. redis.Set(keyOne, "", time.Second)
  3705. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3706. redis.Set(keySeven, "", time.Second)
  3707. defer redis.Close()
  3708. } else {
  3709. tempPrescription.ID = id
  3710. tempPrescription.Type = types
  3711. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3712. tempPrescription.Mtime = time.Now().Unix()
  3713. tempPrescription.Doctor = role.UserName
  3714. //tempPrescription.OrderStatus = order_status
  3715. tempPrescription.PreTime = pTime
  3716. tempPrescription.MedType = med_type
  3717. service.SaveHisPrescription(tempPrescription)
  3718. redis := service.RedisClient()
  3719. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3720. redis.Set(key, "", time.Second)
  3721. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3722. redis.Set(keyOne, "", time.Second)
  3723. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3724. redis.Set(keySeven, "", time.Second)
  3725. defer redis.Close()
  3726. }
  3727. //service.SaveHisPrescription(prescription)
  3728. //更改患者挂号状态
  3729. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3730. fmt.Println("更改失败", err2)
  3731. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3732. advices := items["advices"].([]interface{})
  3733. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3734. groupNo := int64(0)
  3735. ctime := time.Now().Unix()
  3736. mtime := ctime
  3737. if len(advices) > 0 {
  3738. for _, advice := range advices {
  3739. var s models.HisDoctorAdviceInfo
  3740. s.PrescriptionId = tempPrescription.ID
  3741. s.AdviceType = 2
  3742. s.AdviceDoctor = doctor_id
  3743. s.StopState = 2
  3744. s.ExecutionState = 2
  3745. s.AdviceDate = theTime3.Unix()
  3746. s.Status = 1
  3747. s.UserOrgId = adminInfo.CurrentOrgId
  3748. s.RecordDate = theTime3.Unix()
  3749. s.StartTime = tempPrescription.PreTime
  3750. s.Groupno = groupNo
  3751. s.CreatedTime = ctime
  3752. s.UpdatedTime = mtime
  3753. s.PatientId = patient_id
  3754. s.HisPatientId = his_patient_id
  3755. s.StartTime = pTime
  3756. s.IsSettle = 2
  3757. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3758. if errcode > 0 {
  3759. c.ServeFailJSONWithSGJErrorCode(errcode)
  3760. return
  3761. }
  3762. s.StartTime = pTime
  3763. var total_count int64 //处方总库存
  3764. //查询改药品信息
  3765. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3766. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3767. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3768. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3769. total_count += prescribingNumberSeven * medical.MinNumber
  3770. }
  3771. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3772. total_count += prescribingNumberSeven
  3773. }
  3774. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3775. total_count += prescribingNumberSeven
  3776. }
  3777. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3778. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3779. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3780. if s.Price != lastWarehouse.RetailPrice {
  3781. s.Price = lastWarehouse.RetailPrice
  3782. }
  3783. if s.Price == 0 {
  3784. s.Price = lastWarehouse.RetailPrice
  3785. }
  3786. }
  3787. service.CreateHisDoctorAdvice(&s)
  3788. //记录日志
  3789. byterequest, _ := json.Marshal(s)
  3790. adviceLog := models.XtDoctorAdviceLog{
  3791. UserOrgId: s.UserOrgId,
  3792. PatientId: s.PatientId,
  3793. AdminUserId: adminInfo.AdminUser.Id,
  3794. Module: 1,
  3795. ErrLog: string(byterequest),
  3796. Status: 1,
  3797. Ctime: time.Now().Unix(),
  3798. Mtime: 0,
  3799. Source: "电脑端新建his医嘱",
  3800. RecordDate: s.AdviceDate,
  3801. }
  3802. service.CreateDoctorAdviceLog(adviceLog)
  3803. //存储切片中
  3804. adviceList = append(adviceList, s)
  3805. redis := service.RedisClient()
  3806. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3807. redis.Set(key, "", time.Second)
  3808. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3809. redis.Set(keyOne, "", time.Second)
  3810. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3811. redis.Set(keySeven, "", time.Second)
  3812. var randNum int
  3813. randNum = rand.Intn(10000) + 1000
  3814. timestamp := time.Now().Unix()
  3815. tempTime := time.Unix(timestamp, 0)
  3816. timeFormat := tempTime.Format("20060102150405")
  3817. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3818. service.CreateHisDoctorAdvice(&s)
  3819. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3820. redis.Set(keySix, "", time.Second)
  3821. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3822. redis.Set(keyFive, "", time.Second)
  3823. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3824. redis.Set(keyEight, "", time.Second)
  3825. defer redis.Close()
  3826. }
  3827. }
  3828. }
  3829. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3830. projects := items["project"].([]interface{})
  3831. if len(projects) > 0 {
  3832. for _, project := range projects {
  3833. var p models.HisPrescriptionProject
  3834. p.PrescriptionId = tempPrescription.ID
  3835. p.Ctime = time.Now().Unix()
  3836. p.Mtime = time.Now().Unix()
  3837. p.PatientId = patient_id
  3838. p.RecordDate = theTime3.Unix()
  3839. p.Doctor = doctor_id
  3840. p.UserOrgId = adminInfo.CurrentOrgId
  3841. p.HisPatientId = his_patient_id
  3842. p.Status = 1
  3843. p.StartTime = pTime
  3844. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3845. if errcode > 0 {
  3846. c.ServeFailJSONWithSGJErrorCode(errcode)
  3847. return
  3848. }
  3849. if p.ID == 0 {
  3850. p.IsOut = 2
  3851. }
  3852. if p.ID > 0 {
  3853. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3854. p.IsOut = projectDetail.IsOut
  3855. }
  3856. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3857. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3858. if p.Type == 3 {
  3859. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3860. if p.Price != lastWarehouse.PackingPrice {
  3861. p.Price = lastWarehouse.PackingPrice
  3862. }
  3863. if p.Unit == "" {
  3864. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3865. p.Unit = goodInfoOne.PackingUnit
  3866. }
  3867. }
  3868. }
  3869. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3870. //
  3871. // if p.Type == 3 {
  3872. // //查询该耗材是否停用
  3873. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3874. // //表示该耗材已经停用,不能保存
  3875. // if goodInfoSeven.ID == 0 {
  3876. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3877. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3878. // return
  3879. // }
  3880. // }
  3881. //
  3882. //}
  3883. service.CreateHisProjectTwo(&p)
  3884. //记录日志
  3885. byterequest, _ := json.Marshal(p)
  3886. adviceLog := models.XtDoctorAdviceLog{
  3887. UserOrgId: p.UserOrgId,
  3888. PatientId: p.PatientId,
  3889. AdminUserId: adminInfo.AdminUser.Id,
  3890. Module: 1,
  3891. ErrLog: string(byterequest),
  3892. Status: 1,
  3893. Ctime: time.Now().Unix(),
  3894. Mtime: 0,
  3895. Source: "电脑端新建his项目",
  3896. RecordDate: p.RecordDate,
  3897. }
  3898. service.CreateDoctorAdviceLog(adviceLog)
  3899. projectList = append(projectList, p)
  3900. var randNum int
  3901. randNum = rand.Intn(10000) + 1000
  3902. timestamp := time.Now().Unix()
  3903. tempTime := time.Unix(timestamp, 0)
  3904. timeFormat := tempTime.Format("20060102150405")
  3905. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3906. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3907. //新增或者编辑项目,修改对应的标签数据
  3908. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3909. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3910. var label models.HisLabelPrintInfo
  3911. project, _ := service.GetProjectDetail(p.ProjectId)
  3912. if project.CostClassify == 3 { //类别为检验检查
  3913. if p.TeamId > 0 { //检验检查组套
  3914. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3915. if tempLabel.ID == 0 {
  3916. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3917. label.Number = tempPrescription.PrescriptionNumber
  3918. label.ProjectId = project.ID
  3919. label.Status = 1
  3920. label.IsPrint = 2
  3921. label.DoctorId = info.DoctorId
  3922. label.UserOrgId = p.UserOrgId
  3923. label.PatientId = patient_id
  3924. label.RecordDate = recordDateTime
  3925. label.Ctime = time.Now().Unix()
  3926. label.Mtime = time.Now().Unix()
  3927. label.ItemId = p.TeamId
  3928. label.FeedetlSn = p.FeedetlSn
  3929. label.PProjectId = p.ID
  3930. label.ProjectName = team.ProjectTeam
  3931. label.PatientName = patient.Name
  3932. service.CreateHisLabelRecord(&label)
  3933. }
  3934. } else { //单条检验检查项目
  3935. label.Number = tempPrescription.PrescriptionNumber
  3936. label.ProjectId = project.ID
  3937. label.Status = 1
  3938. label.DoctorId = info.DoctorId
  3939. label.UserOrgId = p.UserOrgId
  3940. label.PatientId = patient_id
  3941. label.RecordDate = recordDateTime
  3942. label.IsPrint = 2
  3943. label.Ctime = time.Now().Unix()
  3944. label.Mtime = time.Now().Unix()
  3945. label.FeedetlSn = p.FeedetlSn
  3946. label.PProjectId = p.ID
  3947. label.ItemId = p.TeamId
  3948. label.ProjectName = project.ProjectName
  3949. label.PatientName = patient.Name
  3950. service.CreateHisLabelRecord(&label)
  3951. }
  3952. }
  3953. }
  3954. }
  3955. service.SaveHisProjectTwo(&p)
  3956. }
  3957. }
  3958. }
  3959. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3960. // addition := items["addition"].([]interface{})
  3961. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3962. // ctime := time.Now().Unix()
  3963. // mtime := ctime
  3964. // if len(addition) > 0 {
  3965. // for _, item := range addition {
  3966. // var s models.HisAdditionalCharge
  3967. // s.PrescriptionId = tempPrescription.ID
  3968. // s.Status = 1
  3969. // s.UserOrgId = adminInfo.CurrentOrgId
  3970. // s.RecordDate = recordDateTime
  3971. // s.CreatedTime = ctime
  3972. // s.UpdatedTime = mtime
  3973. // s.PatientId = patient_id
  3974. // s.HisPatientId = his_patient_id
  3975. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3976. // if errcode > 0 {
  3977. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3978. // return
  3979. // }
  3980. // service.CreateAdditionalCharge(&s)
  3981. // var randNum int
  3982. // randNum = rand.Intn(10000) + 1000
  3983. // timestamp := time.Now().Unix()
  3984. // tempTime := time.Unix(timestamp, 0)
  3985. // timeFormat := tempTime.Format("20060102150405")
  3986. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3987. // service.CreateAdditionalCharge(&s)
  3988. //
  3989. // }
  3990. // }
  3991. //}
  3992. }
  3993. }
  3994. //查询今日该患者开的药品处方
  3995. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3996. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3997. //药品出库
  3998. if drugOutConfig.IsOpen == 1 {
  3999. for _, item := range hisdoctorlist {
  4000. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4001. // 查询该药品最后一次出库记录
  4002. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4003. if len(druginfo) > 0 {
  4004. //回退库存
  4005. for _, it := range druginfo {
  4006. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4007. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4008. }
  4009. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4010. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4011. }
  4012. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4013. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4014. }
  4015. }
  4016. }
  4017. //删除记录
  4018. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4019. //查询最后一次数据
  4020. if drugOutConfig.IsOpen == 1 {
  4021. //出库
  4022. if drug.IsUse == 2 {
  4023. creater := adminInfo.AdminUser.Id
  4024. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4025. }
  4026. //更新字典里面的库存
  4027. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4028. var sum_count int64
  4029. for _, its := range stockInfo {
  4030. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4031. if its.MaxUnit == baseDrug.MaxUnit {
  4032. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4033. }
  4034. sum_count += its.StockMaxNumber + its.StockMinNumber
  4035. }
  4036. //更新基础库存
  4037. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4038. //剩余库存
  4039. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4040. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4041. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4042. }
  4043. }
  4044. }
  4045. //耗材保存处方出库
  4046. if goodOutConfig.IsOpen == 1 {
  4047. //查询今日耗材出库数量
  4048. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4049. for _, item := range hisgoodlist {
  4050. //查询历史出库数据
  4051. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4052. var out_count_five int64
  4053. for _, item := range flowGood {
  4054. out_count_five += item.Count
  4055. }
  4056. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4057. if out_count_five != parseIntCount {
  4058. //查询耗材最后一次出库记录
  4059. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4060. //查询默认出库仓库库存
  4061. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4062. if len(wareOut) > 0 {
  4063. for _, it := range wareOut {
  4064. //回退库存
  4065. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4066. //删除出库记录
  4067. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4068. }
  4069. }
  4070. timeStr := time.Now().Format("2006-01-02")
  4071. timeArr := strings.Split(timeStr, "-")
  4072. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4073. total = total + 1
  4074. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4075. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4076. number = number + total
  4077. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4078. operation_time := time.Now().Unix()
  4079. creater := c.GetAdminUserInfo().AdminUser.Id
  4080. recordDateStr := time.Now().Format("2006-01-02")
  4081. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4082. nowtime := recordDate.Unix()
  4083. warehouseOut := models.WarehouseOut{
  4084. WarehouseOutOrderNumber: warehousing_out_order,
  4085. OperationTime: operation_time,
  4086. OrgId: adminInfo.CurrentOrgId,
  4087. Creater: creater,
  4088. Ctime: time.Now().Unix(),
  4089. Status: 1,
  4090. WarehouseOutTime: nowtime,
  4091. Type: 1,
  4092. StorehouseId: storeConfig.StorehouseOutInfo,
  4093. IsCheck: 1,
  4094. IsSys: 1,
  4095. }
  4096. //查询是否生成出库单
  4097. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4098. if out.ID == 0 {
  4099. service.AddSigleWarehouseOut(&warehouseOut)
  4100. }
  4101. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4102. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4103. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4104. dialyPrepareOne := models.DialysisBeforePrepare{
  4105. GoodTypeId: goodObj.GoodTypeId,
  4106. GoodId: item.ProjectId,
  4107. PatientId: item.PatientId,
  4108. RecordDate: item.RecordDate,
  4109. UserOrgId: adminInfo.CurrentOrgId,
  4110. Count: parseIntCount,
  4111. Ctime: time.Now().Unix(),
  4112. Creater: creater,
  4113. Status: 1,
  4114. StorehouseId: houseConfig.StorehouseOutInfo,
  4115. ProjectId: item.ID,
  4116. }
  4117. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4118. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4119. //查询历史出库数据
  4120. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4121. var out_count int64
  4122. for _, item := range flowGood {
  4123. out_count += item.Count
  4124. }
  4125. //如果历史数和当前数据不想等才进行退库出库
  4126. if out_count != parseIntCount {
  4127. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4128. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4129. detail := models.AutomaticReduceDetail{
  4130. WarehouseOutId: 0,
  4131. WarehouseOutOrderNumber: "",
  4132. PatientId: item.PatientId,
  4133. Ctime: time.Now().Unix(),
  4134. Mtime: 0,
  4135. Status: 1,
  4136. RecordTime: item.RecordDate,
  4137. OrgId: item.UserOrgId,
  4138. GoodId: item.ProjectId,
  4139. GoodTypeId: 0,
  4140. Count: parseIntCount,
  4141. Type: 0,
  4142. ProjectId: item.ID,
  4143. StorehouseId: 0,
  4144. }
  4145. service.CreateAutoDetail(detail)
  4146. //查询剩余库存
  4147. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4148. var sum_count int64
  4149. for _, item := range goodList {
  4150. sum_count += item.StockCount
  4151. }
  4152. //更新剩余库存
  4153. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4154. //耗材
  4155. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4156. }
  4157. }
  4158. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4159. //查询历史出库数据
  4160. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4161. var out_count int64
  4162. for _, item := range flowGood {
  4163. out_count += item.Count
  4164. }
  4165. //如果历史数和当前数据不想等才进行退库出库
  4166. if out_count != parseIntCount {
  4167. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4168. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4169. detail := models.AutomaticReduceDetail{
  4170. WarehouseOutId: 0,
  4171. WarehouseOutOrderNumber: "",
  4172. PatientId: item.PatientId,
  4173. Ctime: time.Now().Unix(),
  4174. Mtime: 0,
  4175. Status: 1,
  4176. RecordTime: item.RecordDate,
  4177. OrgId: item.UserOrgId,
  4178. GoodId: item.ProjectId,
  4179. GoodTypeId: 0,
  4180. Count: parseIntCount,
  4181. Type: 0,
  4182. ProjectId: item.ID,
  4183. StorehouseId: 0,
  4184. }
  4185. service.CreateAutoDetail(detail)
  4186. //查询剩余库存
  4187. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4188. var sum_count int64
  4189. for _, item := range goodList {
  4190. sum_count += item.StockCount
  4191. }
  4192. //更新剩余库存
  4193. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4194. //耗材
  4195. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4196. }
  4197. }
  4198. }
  4199. }
  4200. }
  4201. }
  4202. tx.Commit()
  4203. if err == nil {
  4204. c.ServeSuccessJSON(map[string]interface{}{
  4205. "msg": "保存成功",
  4206. })
  4207. return
  4208. } else {
  4209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4210. return
  4211. }
  4212. }
  4213. }
  4214. //func (c *HisApiController) EditHisPrescription() {
  4215. // record_date := c.GetString("record_date")
  4216. // patient_id, _ := c.GetInt64("patient_id")
  4217. // reg_type, _ := c.GetInt64("reg_type")
  4218. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4219. // diagnose := c.GetString("diagnose")
  4220. // sick_type, _ := c.GetInt64("sick_type")
  4221. // sick_history := c.GetString("sick_history")
  4222. // doctor_id, _ := c.GetInt64("doctor", 0)
  4223. // department, _ := c.GetInt64("department", 0)
  4224. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4225. // p_type, _ := c.GetInt64("p_type")
  4226. //
  4227. // dataBody := make(map[string]interface{}, 0)
  4228. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4229. // if err != nil {
  4230. // utils.ErrorLog(err.Error())
  4231. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4232. // return
  4233. // }
  4234. //
  4235. // timeLayout := "2006-01-02"
  4236. // loc, _ := time.LoadLocation("Local")
  4237. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4238. // if err != nil {
  4239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4240. // return
  4241. // }
  4242. // adminInfo := c.GetAdminUserInfo()
  4243. // recordDateTime := theTime.Unix()
  4244. //
  4245. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4246. //
  4247. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4248. // var hpInfo models.HisPrescriptionInfo
  4249. // if info.ID == 0 {
  4250. // var randNum int
  4251. // randNum = rand.Intn(10000) + 1000
  4252. // timestamp := time.Now().Unix()
  4253. // tempTime := time.Unix(timestamp, 0)
  4254. // timeFormat := tempTime.Format("20060102150405")
  4255. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4256. //
  4257. // hpInfo = models.HisPrescriptionInfo{
  4258. // UserOrgId: adminInfo.CurrentOrgId,
  4259. // RecordDate: theTime.Unix(),
  4260. // PatientId: patient_id,
  4261. // Status: 1,
  4262. // Ctime: time.Now().Unix(),
  4263. // Mtime: time.Now().Unix(),
  4264. // Creator: adminInfo.AdminUser.Id,
  4265. // Modifier: adminInfo.AdminUser.Id,
  4266. // Diagnosis: diagnose,
  4267. // SickHistory: sick_history,
  4268. // Departments: department,
  4269. // RegisterType: reg_type,
  4270. // PrescriptionNumber: p_number,
  4271. // PrescriptionStatus: 1,
  4272. // Doctor: role.UserName,
  4273. // DoctorId: doctor_id,
  4274. // SickType: sick_type,
  4275. // PType: p_type,
  4276. // }
  4277. // service.SavePatientPrescriptionInfo(hpInfo)
  4278. //
  4279. // } else {
  4280. // hpInfo = models.HisPrescriptionInfo{
  4281. // ID: info.ID,
  4282. // UserOrgId: adminInfo.CurrentOrgId,
  4283. // RecordDate: info.RecordDate,
  4284. // PatientId: info.PatientId,
  4285. // Status: 1,
  4286. // Ctime: info.Ctime,
  4287. // Mtime: time.Now().Unix(),
  4288. // Creator: info.Creator,
  4289. // Modifier: adminInfo.AdminUser.Id,
  4290. // Diagnosis: diagnose,
  4291. // SickHistory: sick_history,
  4292. // Departments: department,
  4293. // RegisterType: reg_type,
  4294. // PrescriptionNumber: info.PrescriptionNumber,
  4295. // Doctor: role.UserName,
  4296. // PrescriptionStatus: info.PrescriptionStatus,
  4297. // DoctorId: doctor_id,
  4298. // SickType: sick_type,
  4299. // PType: info.PType,
  4300. // }
  4301. // service.SavePatientPrescriptionInfo(hpInfo)
  4302. // }
  4303. //
  4304. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4305. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4306. //
  4307. // if len(prescriptions) > 0 {
  4308. // for _, item := range prescriptions {
  4309. // items := item.(map[string]interface{})
  4310. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4311. // utils.ErrorLog("id")
  4312. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4313. // return
  4314. // }
  4315. // id := int64(items["id"].(float64))
  4316. //
  4317. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4318. // utils.ErrorLog("type")
  4319. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4320. // return
  4321. // }
  4322. // types := int64(items["type"].(float64))
  4323. //
  4324. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4325. // utils.ErrorLog("med_type")
  4326. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4327. // return
  4328. // }
  4329. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4330. //
  4331. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4332. //
  4333. // ctime := time.Now().Unix()
  4334. //
  4335. // prescription := &models.HisPrescription{
  4336. // ID: id,
  4337. // PatientId: patient_id,
  4338. // UserOrgId: adminInfo.CurrentOrgId,
  4339. // RecordDate: recordDateTime,
  4340. // Ctime: ctime,
  4341. // Mtime: ctime,
  4342. // Type: types,
  4343. // Modifier: adminInfo.AdminUser.Id,
  4344. // Creator: adminInfo.AdminUser.Id,
  4345. // Status: 1,
  4346. // Doctor: role.UserName,
  4347. // HisPatientId: his_patient_id,
  4348. // OrderStatus: 1,
  4349. // BatchNumber: "",
  4350. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4351. // PType: hpInfo.PType,
  4352. // MedType: med_type,
  4353. // }
  4354. //
  4355. // if historyPrescription.ID > 0 {
  4356. // prescription.PreTime = historyPrescription.PreTime
  4357. //
  4358. // }
  4359. //
  4360. // service.SaveHisPrescription(prescription)
  4361. //
  4362. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4363. // advices := items["advices"].([]interface{})
  4364. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4365. // groupNo := int64(0)
  4366. // ctime := time.Now().Unix()
  4367. // mtime := ctime
  4368. // if len(advices) > 0 {
  4369. // for _, advice := range advices {
  4370. // var s models.HisDoctorAdviceInfo
  4371. // s.PrescriptionId = prescription.ID
  4372. // s.AdviceType = 2
  4373. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4374. // s.StopState = 2
  4375. // s.ExecutionState = 2
  4376. // s.AdviceDate = recordDateTime
  4377. // s.Status = 1
  4378. // s.UserOrgId = adminInfo.CurrentOrgId
  4379. // s.RecordDate = recordDateTime
  4380. // s.StartTime = prescription.PreTime
  4381. // s.Groupno = groupNo
  4382. // s.CreatedTime = ctime
  4383. // s.UpdatedTime = mtime
  4384. // s.PatientId = patient_id
  4385. // s.HisPatientId = his_patient_id
  4386. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4387. // if errcode > 0 {
  4388. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4389. // return
  4390. // }
  4391. //
  4392. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4393. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4394. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4395. // if s.Price == 0 {
  4396. // s.Price = lastWarehouse.RetailPrice
  4397. // }
  4398. // }
  4399. //
  4400. // service.CreateHisDoctorAdvice(&s)
  4401. // //记录日志
  4402. // byterequest, _ := json.Marshal(s)
  4403. // adviceLog := models.XtDoctorAdviceLog{
  4404. // UserOrgId: s.UserOrgId,
  4405. // PatientId: s.PatientId,
  4406. // AdminUserId: adminInfo.AdminUser.Id,
  4407. // Module: 1,
  4408. // ErrLog: string(byterequest),
  4409. // Status: 1,
  4410. // Ctime: time.Now().Unix(),
  4411. // Mtime: 0,
  4412. // Source: "电脑端his医嘱修改",
  4413. // RecordDate: s.AdviceDate,
  4414. // }
  4415. // service.CreateDoctorAdviceLog(adviceLog)
  4416. // redis := service.RedisClient()
  4417. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4418. // redis.Set(key, "", time.Second)
  4419. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4420. // fmt.Println("keyOne", keyOne)
  4421. // redis.Set(keyOne, "", time.Second)
  4422. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4423. // redis.Set(keySeven, "", time.Second)
  4424. // redis.Close()
  4425. //
  4426. // }
  4427. // }
  4428. // }
  4429. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4430. // projects := items["project"].([]interface{})
  4431. // if len(projects) > 0 {
  4432. // for _, project := range projects {
  4433. // var p models.HisPrescriptionProject
  4434. // p.PrescriptionId = prescription.ID
  4435. // p.Ctime = time.Now().Unix()
  4436. // p.Mtime = time.Now().Unix()
  4437. // p.PatientId = patient_id
  4438. // p.RecordDate = recordDateTime
  4439. // p.UserOrgId = adminInfo.CurrentOrgId
  4440. // p.HisPatientId = his_patient_id
  4441. // p.Status = 1
  4442. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4443. // if errcode > 0 {
  4444. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4445. // return
  4446. // }
  4447. // service.CreateHisProjectTwo(&p)
  4448. //
  4449. // //记录日志
  4450. // byterequest, _ := json.Marshal(p)
  4451. // adviceLog := models.XtDoctorAdviceLog{
  4452. // UserOrgId: p.UserOrgId,
  4453. // PatientId: p.PatientId,
  4454. // AdminUserId: adminInfo.AdminUser.Id,
  4455. // Module: 1,
  4456. // ErrLog: string(byterequest),
  4457. // Status: 1,
  4458. // Ctime: time.Now().Unix(),
  4459. // Mtime: 0,
  4460. // Source: "电脑端his项目修改",
  4461. // RecordDate: p.RecordDate,
  4462. // }
  4463. // service.CreateDoctorAdviceLog(adviceLog)
  4464. // }
  4465. // }
  4466. // }
  4467. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4468. // addition := items["addition"].([]interface{})
  4469. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4470. // ctime := time.Now().Unix()
  4471. // mtime := ctime
  4472. // if len(addition) > 0 {
  4473. // for _, item := range addition {
  4474. // var s models.HisAdditionalCharge
  4475. // s.PrescriptionId = prescription.ID
  4476. // s.Status = 1
  4477. // s.UserOrgId = adminInfo.CurrentOrgId
  4478. // s.RecordDate = recordDateTime
  4479. // s.CreatedTime = ctime
  4480. // s.UpdatedTime = mtime
  4481. // s.PatientId = patient_id
  4482. // s.HisPatientId = his_patient_id
  4483. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4484. // if errcode > 0 {
  4485. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4486. // return
  4487. // }
  4488. // service.CreateAdditionalCharge(&s)
  4489. // }
  4490. // }
  4491. // }
  4492. //
  4493. // }
  4494. // }
  4495. // }
  4496. // if err == nil {
  4497. // c.ServeSuccessJSON(map[string]interface{}{
  4498. // "msg": "保存成功",
  4499. // })
  4500. // return
  4501. //
  4502. // } else {
  4503. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4504. // return
  4505. // }
  4506. //}
  4507. func (c *HisApiController) DeletePrescription() {
  4508. prescription_id, _ := c.GetInt64("id")
  4509. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4510. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4511. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4512. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4513. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4514. //耗材保存处方出库
  4515. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4516. //已收费和已发药限制逻辑
  4517. isCharge := false
  4518. isMedicine := false
  4519. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4520. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4521. for _, item := range new_prescriptions {
  4522. if item.IsMedicine == 1 {
  4523. isMedicine = true
  4524. }
  4525. }
  4526. for _, item := range new_prescriptions {
  4527. if item.OrderStatus == 4 {
  4528. isCharge = true
  4529. }
  4530. }
  4531. if p_err != nil {
  4532. if new_prescription.ID > 0 {
  4533. if new_prescription.OrderStatus == 2 {
  4534. isCharge = true
  4535. }
  4536. }
  4537. }
  4538. for _, item := range advices {
  4539. if item.IsMedicine == 1 {
  4540. isMedicine = true
  4541. }
  4542. }
  4543. if isCharge {
  4544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4545. return
  4546. }
  4547. if isMedicine {
  4548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4549. return
  4550. }
  4551. //已收费和已发药限制逻辑
  4552. if len(projects) > 0 {
  4553. for _, item := range projects {
  4554. service.DeletePrintInfo(item.ID) //删除打印信息
  4555. if goodOutConfig.IsOpen != 1 {
  4556. if stockConfig.IsOpen == 1 {
  4557. if item.Type == 3 && item.IsOut == 1 {
  4558. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4559. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4560. good.Total = good.Total + f_count
  4561. service.UpdateGoodInfo(&good)
  4562. operation_time := time.Now().Unix()
  4563. creater := c.GetAdminUserInfo().AdminUser.Id
  4564. //创建退库单
  4565. timeStr := time.Now().Format("2006-01-02")
  4566. timeArr := strings.Split(timeStr, "-")
  4567. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4568. total = total + 1
  4569. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4570. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4571. cancelStock := models.CancelStock{
  4572. OrderNumber: orderNumber,
  4573. OperaTime: operation_time,
  4574. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4575. Creater: creater,
  4576. Ctime: time.Now().Unix(),
  4577. Status: 1,
  4578. ReturnTime: item.RecordDate,
  4579. Type: 1,
  4580. StorehouseId: houseConfig.StorehouseOutInfo,
  4581. IsCheck: 1,
  4582. }
  4583. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4584. if msgerrkonde == gorm.ErrRecordNotFound {
  4585. service.AddSigleCancelStock(&cancelStock)
  4586. }
  4587. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4588. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4589. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4590. //查询该耗材是否出库
  4591. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4592. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4593. deaerler, _ := service.GetDealerById(info.Dealer)
  4594. var total_count int64
  4595. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4596. total_count += count
  4597. if info.ID > 0 {
  4598. if info.Count >= total_count {
  4599. //回退库存
  4600. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4601. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4602. var flush_count int64
  4603. for _, it := range goodList {
  4604. flush_count += it.StockCount
  4605. }
  4606. cancelStockInfo := models.CancelStockInfo{
  4607. GoodId: item.ProjectId,
  4608. CancelStockId: cancel.ID,
  4609. GoodTypeId: good.GoodTypeId,
  4610. Count: prescribingNumber,
  4611. Price: info.Price,
  4612. Total: 0,
  4613. ProductDate: info.ProductDate,
  4614. ExpiryDate: info.ExpiryDate,
  4615. Ctime: time.Now().Unix(),
  4616. Status: 1,
  4617. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4618. OrderNumber: cancel.OrderNumber,
  4619. Type: 0,
  4620. Dealer: deaerler.DealerName,
  4621. Manufacturer: manufacturer.ManufacturerName,
  4622. Number: info.Number,
  4623. RegisterAccount: "",
  4624. Remark: "",
  4625. WarehouseInfoId: info.WarehouseInfotId,
  4626. PatientId: info.PatientId,
  4627. RecordDate: info.SysRecordTime,
  4628. StorehouseId: houseConfig.StorehouseOutInfo,
  4629. IsCheck: 1,
  4630. }
  4631. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4632. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4633. flow := models.VmStockFlow{
  4634. WarehousingId: info.WarehouseInfotId,
  4635. GoodId: item.ProjectId,
  4636. Number: info.Number,
  4637. LicenseNumber: info.LicenseNumber,
  4638. Count: prescribingNumber,
  4639. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4640. PatientId: item.PatientId,
  4641. SystemTime: info.SysRecordTime,
  4642. ConsumableType: 7,
  4643. IsSys: 0,
  4644. WarehousingOrder: "",
  4645. WarehouseOutId: info.WarehouseOutId,
  4646. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4647. IsEdit: 0,
  4648. CancelStockId: cancel.ID,
  4649. CancelOrderNumber: cancel.OrderNumber,
  4650. Manufacturer: manufacturer.ID,
  4651. Dealer: 0,
  4652. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4653. UpdateCreator: 0,
  4654. Status: 1,
  4655. Ctime: time.Now().Unix(),
  4656. Mtime: 0,
  4657. Price: info.Price,
  4658. WarehousingDetailId: info.WarehouseInfotId,
  4659. WarehouseOutDetailId: info.ID,
  4660. CancelOutDetailId: cancelInfo.ID,
  4661. ProductDate: info.ProductDate,
  4662. ExpireDate: info.ExpiryDate,
  4663. StorehouseId: houseConfig.StorehouseOutInfo,
  4664. OverCount: flush_count,
  4665. }
  4666. service.CreateStockFlowOne(flow)
  4667. //退库数量增加
  4668. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4669. //出库数量减少
  4670. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4671. }
  4672. if info.Count < total_count {
  4673. //回退库存
  4674. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4675. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4676. var flush_count int64
  4677. for _, it := range goodList {
  4678. flush_count += it.StockCount
  4679. }
  4680. cancelStockInfo := models.CancelStockInfo{
  4681. GoodId: item.ProjectId,
  4682. CancelStockId: cancel.ID,
  4683. GoodTypeId: good.GoodTypeId,
  4684. Count: info.Count,
  4685. Price: info.Price,
  4686. Total: 0,
  4687. ProductDate: info.ProductDate,
  4688. ExpiryDate: info.ExpiryDate,
  4689. Ctime: time.Now().Unix(),
  4690. Status: 1,
  4691. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4692. OrderNumber: cancel.OrderNumber,
  4693. Type: 0,
  4694. Dealer: deaerler.DealerName,
  4695. Manufacturer: manufacturer.ManufacturerName,
  4696. Number: info.Number,
  4697. RegisterAccount: "",
  4698. Remark: "",
  4699. WarehouseInfoId: info.WarehouseInfotId,
  4700. PatientId: info.PatientId,
  4701. RecordDate: info.SysRecordTime,
  4702. StorehouseId: houseConfig.StorehouseOutInfo,
  4703. IsCheck: 1,
  4704. }
  4705. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4706. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4707. flow := models.VmStockFlow{
  4708. WarehousingId: info.WarehouseInfotId,
  4709. GoodId: item.ProjectId,
  4710. Number: info.Number,
  4711. LicenseNumber: info.LicenseNumber,
  4712. Count: info.Count,
  4713. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4714. PatientId: item.PatientId,
  4715. SystemTime: info.SysRecordTime,
  4716. ConsumableType: 7,
  4717. IsSys: 0,
  4718. WarehousingOrder: "",
  4719. WarehouseOutId: info.WarehouseOutId,
  4720. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4721. IsEdit: 0,
  4722. CancelStockId: cancel.ID,
  4723. CancelOrderNumber: cancel.OrderNumber,
  4724. Manufacturer: manufacturer.ID,
  4725. Dealer: 0,
  4726. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4727. UpdateCreator: 0,
  4728. Status: 1,
  4729. Ctime: time.Now().Unix(),
  4730. Mtime: 0,
  4731. Price: info.Price,
  4732. WarehousingDetailId: info.WarehouseInfotId,
  4733. WarehouseOutDetailId: info.ID,
  4734. CancelOutDetailId: cancelInfo.ID,
  4735. ProductDate: info.ProductDate,
  4736. ExpireDate: info.ExpiryDate,
  4737. StorehouseId: houseConfig.StorehouseOutInfo,
  4738. OverCount: flush_count,
  4739. }
  4740. service.CreateStockFlowOne(flow)
  4741. //退库数量增加
  4742. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4743. //出库数量减少
  4744. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4745. }
  4746. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4747. var flush_count int64
  4748. for _, it := range goodList {
  4749. flush_count += it.StockCount
  4750. }
  4751. //查询已出库数量
  4752. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4753. if prescribingNumber < dialysisInfo.Count {
  4754. //改变数量
  4755. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4756. }
  4757. if prescribingNumber >= dialysisInfo.Count {
  4758. //删除出库表
  4759. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4760. }
  4761. //更新库存
  4762. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4763. //更新基础库库存
  4764. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4765. }
  4766. }
  4767. }
  4768. }
  4769. //保存耗材出库
  4770. if goodOutConfig.IsOpen == 1 {
  4771. if item.Type == 3 {
  4772. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4773. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4774. good.Total = good.Total + f_count
  4775. service.UpdateGoodInfo(&good)
  4776. operation_time := time.Now().Unix()
  4777. creater := c.GetAdminUserInfo().AdminUser.Id
  4778. //创建退库单
  4779. timeStr := time.Now().Format("2006-01-02")
  4780. timeArr := strings.Split(timeStr, "-")
  4781. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4782. total = total + 1
  4783. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4784. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4785. cancelStock := models.CancelStock{
  4786. OrderNumber: orderNumber,
  4787. OperaTime: operation_time,
  4788. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4789. Creater: creater,
  4790. Ctime: time.Now().Unix(),
  4791. Status: 1,
  4792. ReturnTime: item.RecordDate,
  4793. Type: 1,
  4794. StorehouseId: houseConfig.StorehouseOutInfo,
  4795. IsCheck: 1,
  4796. }
  4797. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4798. if msgerrkonde == gorm.ErrRecordNotFound {
  4799. service.AddSigleCancelStock(&cancelStock)
  4800. }
  4801. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4802. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4803. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4804. //查询该耗材是否出库
  4805. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4806. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4807. deaerler, _ := service.GetDealerById(info.Dealer)
  4808. var total_count int64
  4809. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4810. total_count += count
  4811. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4812. var flush_count int64
  4813. for _, it := range goodList {
  4814. flush_count += it.StockCount
  4815. }
  4816. fmt.Println("历史出库数据", info.Count)
  4817. fmt.Println("出库数量", total_count)
  4818. if info.ID > 0 {
  4819. cancelStockInfo := models.CancelStockInfo{
  4820. GoodId: item.ProjectId,
  4821. CancelStockId: cancel.ID,
  4822. GoodTypeId: good.GoodTypeId,
  4823. Count: prescribingNumber,
  4824. Price: info.Price,
  4825. Total: 0,
  4826. ProductDate: info.ProductDate,
  4827. ExpiryDate: info.ExpiryDate,
  4828. Ctime: time.Now().Unix(),
  4829. Status: 1,
  4830. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4831. OrderNumber: cancel.OrderNumber,
  4832. Type: 0,
  4833. Dealer: deaerler.DealerName,
  4834. Manufacturer: manufacturer.ManufacturerName,
  4835. Number: info.Number,
  4836. RegisterAccount: "",
  4837. Remark: "",
  4838. WarehouseInfoId: info.WarehouseInfotId,
  4839. PatientId: info.PatientId,
  4840. RecordDate: info.SysRecordTime,
  4841. StorehouseId: houseConfig.StorehouseOutInfo,
  4842. IsCheck: 1,
  4843. }
  4844. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4845. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4846. //查询出库数量
  4847. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4848. //出库数据 大于 退库数量
  4849. if len(list) > 0 {
  4850. for _, it := range list {
  4851. //回退库存
  4852. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4853. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4854. var flush_count_one int64
  4855. for _, it := range goodList {
  4856. flush_count_one += it.StockCount
  4857. }
  4858. //查询该批次是否有退库数据
  4859. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4860. creater := c.GetAdminUserInfo().AdminUser.Id
  4861. flow := models.VmStockFlow{
  4862. WarehousingId: it.WarehouseInfotId,
  4863. GoodId: it.GoodId,
  4864. Number: it.Number,
  4865. LicenseNumber: it.LicenseNumber,
  4866. Count: it.Count,
  4867. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4868. PatientId: it.PatientId,
  4869. SystemTime: it.SysRecordTime,
  4870. ConsumableType: 7,
  4871. IsSys: 0,
  4872. WarehousingOrder: "",
  4873. WarehouseOutId: it.WarehouseOutId,
  4874. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4875. IsEdit: 0,
  4876. CancelStockId: cancel.ID,
  4877. CancelOrderNumber: cancel.OrderNumber,
  4878. Manufacturer: manufacturer.ID,
  4879. Dealer: 0,
  4880. Creator: creater,
  4881. UpdateCreator: 0,
  4882. Status: 1,
  4883. Ctime: time.Now().Unix(),
  4884. Mtime: 0,
  4885. Price: it.Price,
  4886. WarehousingDetailId: it.WarehouseInfotId,
  4887. WarehouseOutDetailId: it.ID,
  4888. CancelOutDetailId: cancelInfo.ID,
  4889. ProductDate: it.ProductDate,
  4890. ExpireDate: it.ExpiryDate,
  4891. StorehouseId: houseConfig.StorehouseOutInfo,
  4892. OverCount: flush_count_one,
  4893. }
  4894. service.CreateStockFlowOne(flow)
  4895. //if flow.ID > 0 {
  4896. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4897. //}
  4898. }
  4899. }
  4900. //flow := models.VmStockFlow{
  4901. // WarehousingId: info.WarehouseInfotId,
  4902. // GoodId: item.ProjectId,
  4903. // Number: info.Number,
  4904. // LicenseNumber: info.LicenseNumber,
  4905. // Count: prescribingNumber,
  4906. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4907. // PatientId: item.PatientId,
  4908. // SystemTime: info.SysRecordTime,
  4909. // ConsumableType: 7,
  4910. // IsSys: 0,
  4911. // WarehousingOrder: "",
  4912. // WarehouseOutId: info.WarehouseOutId,
  4913. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4914. // IsEdit: 0,
  4915. // CancelStockId: cancel.ID,
  4916. // CancelOrderNumber: cancel.OrderNumber,
  4917. // Manufacturer: manufacturer.ID,
  4918. // Dealer: 0,
  4919. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4920. // UpdateCreator: 0,
  4921. // Status: 1,
  4922. // Ctime: time.Now().Unix(),
  4923. // Mtime: 0,
  4924. // Price: info.Price,
  4925. // WarehousingDetailId: info.WarehouseInfotId,
  4926. // WarehouseOutDetailId: info.ID,
  4927. // CancelOutDetailId: cancelInfo.ID,
  4928. // ProductDate: info.ProductDate,
  4929. // ExpireDate: info.ExpiryDate,
  4930. // StorehouseId: houseConfig.StorehouseOutInfo,
  4931. // OverCount: flush_count,
  4932. //}
  4933. //service.CreateStockFlowOne(flow)
  4934. //退库数量增加
  4935. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4936. //出库数量减少
  4937. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4938. //查询已出库数量
  4939. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4940. if prescribingNumber < dialysisInfo.Count {
  4941. //改变数量
  4942. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4943. }
  4944. if prescribingNumber >= dialysisInfo.Count {
  4945. //删除出库表
  4946. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4947. }
  4948. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4949. var flush_count_one int64
  4950. for _, it := range goodList {
  4951. flush_count_one += it.StockCount
  4952. }
  4953. //更新库存
  4954. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4955. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4956. //更新基础库库存
  4957. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4958. }
  4959. }
  4960. }
  4961. }
  4962. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4963. fmt.Println(err)
  4964. }
  4965. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4966. fmt.Println(err)
  4967. if len(advices) > 0 {
  4968. for _, item := range advices {
  4969. redis := service.RedisClient()
  4970. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4971. redis.Set(keyFive, "", time.Second)
  4972. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4973. redis.Set(keyOne, "", time.Second)
  4974. redis.Close()
  4975. }
  4976. }
  4977. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4978. if len(advices) > 0 {
  4979. for _, item := range advices {
  4980. creater := c.GetAdminUserInfo().AdminUser.Id
  4981. service.DrugAutoAddCancelInfo(item, creater)
  4982. }
  4983. }
  4984. } else {
  4985. if drugOutConfig.IsOpen == 1 {
  4986. if len(advices) > 0 {
  4987. for _, item := range advices {
  4988. creater := c.GetAdminUserInfo().AdminUser.Id
  4989. service.DrugAutoAddCancelInfo(item, creater)
  4990. }
  4991. }
  4992. } else {
  4993. if len(advices) > 0 {
  4994. for _, item := range advices {
  4995. creater := c.GetAdminUserInfo().AdminUser.Id
  4996. service.DrugAutoAddCancelInfo(item, creater)
  4997. }
  4998. }
  4999. }
  5000. }
  5001. c.ServeSuccessJSON(map[string]interface{}{
  5002. "msg": "删除成功",
  5003. })
  5004. return
  5005. }
  5006. func (c *HisApiController) DeleteDoctorAdvice() {
  5007. id, _ := c.GetInt64("id")
  5008. advice, _ := service.GetHisDoctorAdvicesById(id)
  5009. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5010. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5011. //已收费和已发药的限制逻辑
  5012. isCharge := false
  5013. isMedicine := false
  5014. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5015. //获取今天该患者所有处方,判断是否发药或者收费
  5016. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5017. for _, item := range new_prescriptions {
  5018. if item.IsMedicine == 1 {
  5019. isMedicine = true
  5020. }
  5021. }
  5022. for _, item := range new_prescriptions {
  5023. if item.OrderStatus == 4 {
  5024. isCharge = true
  5025. }
  5026. }
  5027. if isMedicine {
  5028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5029. return
  5030. }
  5031. if isCharge {
  5032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5033. return
  5034. }
  5035. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5036. for _, item := range advices {
  5037. if item.IsMedicine == 1 {
  5038. isMedicine = true
  5039. }
  5040. }
  5041. if isMedicine {
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5043. return
  5044. }
  5045. if new_prescription.ID > 0 {
  5046. if new_prescription.OrderStatus == 2 {
  5047. isCharge = true
  5048. }
  5049. }
  5050. if isCharge {
  5051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5052. return
  5053. }
  5054. //已收费和已发药的限制逻辑
  5055. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5056. redis := service.RedisClient()
  5057. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5058. redis.Set(keyFive, "", time.Second)
  5059. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5060. redis.Set(keyOne, "", time.Second)
  5061. defer redis.Close()
  5062. if err == nil {
  5063. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5064. //查询是否在处方中出库
  5065. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5066. if openConfig.IsOpen != 1 {
  5067. //判断该医嘱是否执行了
  5068. if advice.ExecutionState == 1 {
  5069. creater := c.GetAdminUserInfo().AdminUser.Id
  5070. service.DrugAutoAddCancelInfo(&advice, creater)
  5071. }
  5072. }
  5073. //开启保存处方扣减功能
  5074. if openConfig.IsOpen == 1 {
  5075. creater := c.GetAdminUserInfo().AdminUser.Id
  5076. service.DrugAutoAddCancelInfo(&advice, creater)
  5077. }
  5078. } else {
  5079. if drugOutConfig.IsOpen == 1 {
  5080. //查询是否在处方中出库
  5081. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5082. if openConfig.IsOpen != 1 {
  5083. //判断该医嘱是否执行了
  5084. if advice.ExecutionState == 1 {
  5085. creater := c.GetAdminUserInfo().AdminUser.Id
  5086. service.DrugAutoAddCancelInfo(&advice, creater)
  5087. }
  5088. }
  5089. //开启保存处方扣减功能
  5090. if openConfig.IsOpen == 1 {
  5091. creater := c.GetAdminUserInfo().AdminUser.Id
  5092. service.DrugAutoAddCancelInfo(&advice, creater)
  5093. }
  5094. } else {
  5095. //判断该医嘱是否执行了
  5096. if advice.ExecutionState == 1 {
  5097. creater := c.GetAdminUserInfo().AdminUser.Id
  5098. service.DrugAutoAddCancelInfo(&advice, creater)
  5099. }
  5100. }
  5101. }
  5102. c.ServeSuccessJSON(map[string]interface{}{
  5103. "msg": "删除成功",
  5104. })
  5105. return
  5106. } else {
  5107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5108. return
  5109. }
  5110. }
  5111. func (c *HisApiController) DeleteProject() {
  5112. id, _ := c.GetInt64("id")
  5113. adminInfo := c.GetAdminUserInfo()
  5114. project, _ := service.GetHisProjectByID(id)
  5115. // var consumable models.DialysisBeforePrepare
  5116. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5117. //耗材保存处方出库
  5118. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5119. isCharge := false
  5120. isMedicine := false
  5121. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5122. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5123. for _, item := range new_prescriptions {
  5124. if item.IsMedicine == 1 {
  5125. isMedicine = true
  5126. }
  5127. }
  5128. for _, item := range new_prescriptions {
  5129. if item.OrderStatus == 4 {
  5130. isCharge = true
  5131. }
  5132. }
  5133. if isMedicine {
  5134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5135. return
  5136. }
  5137. if isCharge {
  5138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5139. return
  5140. }
  5141. if new_prescription.ID > 0 {
  5142. if new_prescription.OrderStatus == 2 {
  5143. isCharge = true
  5144. }
  5145. }
  5146. if isCharge {
  5147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5148. return
  5149. }
  5150. service.DeletePrintInfo(id)
  5151. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5152. label.Status = 0
  5153. service.CreateHisLabelRecordTwo(&label)
  5154. fmt.Println(goodOutConfig.IsOpen)
  5155. if goodOutConfig.IsOpen != 1 {
  5156. if stockConfig.IsOpen == 1 {
  5157. if project.Type == 2 {
  5158. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5159. fmt.Println(err)
  5160. }
  5161. if project.Type == 3 && project.IsOut == 1 {
  5162. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5163. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5164. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5165. operation_time := time.Now().Unix()
  5166. creater := adminInfo.AdminUser.Id
  5167. //创建退库单
  5168. timeStr := time.Now().Format("2006-01-02")
  5169. timeArr := strings.Split(timeStr, "-")
  5170. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5171. total = total + 1
  5172. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5173. cancelStock := models.CancelStock{
  5174. OrderNumber: orderNumber,
  5175. OperaTime: operation_time,
  5176. OrgId: adminInfo.CurrentOrgId,
  5177. Creater: creater,
  5178. Ctime: time.Now().Unix(),
  5179. Status: 1,
  5180. ReturnTime: project.RecordDate,
  5181. Type: 1,
  5182. StorehouseId: houseConfig.StorehouseOutInfo,
  5183. IsCheck: 1,
  5184. }
  5185. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5186. if msgerrkonde == gorm.ErrRecordNotFound {
  5187. service.AddSigleCancelStock(&cancelStock)
  5188. }
  5189. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5190. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5191. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5192. //查询是否有出库
  5193. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5194. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5195. deaerler, _ := service.GetDealerById(info.Dealer)
  5196. if info.ID > 0 {
  5197. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5198. if info.Count >= prescribingNumber {
  5199. cancelStockInfo := models.CancelStockInfo{
  5200. GoodId: project.ProjectId,
  5201. CancelStockId: cancel.ID,
  5202. GoodTypeId: good.GoodTypeId,
  5203. Count: prescribingNumber,
  5204. Price: info.Price,
  5205. Total: 0,
  5206. ProductDate: info.ProductDate,
  5207. ExpiryDate: info.ExpiryDate,
  5208. Ctime: time.Now().Unix(),
  5209. Status: 1,
  5210. OrgId: adminInfo.CurrentOrgId,
  5211. OrderNumber: cancel.OrderNumber,
  5212. Type: 0,
  5213. Dealer: deaerler.DealerName,
  5214. Manufacturer: manufacturer.ManufacturerName,
  5215. Number: info.Number,
  5216. RegisterAccount: "",
  5217. Remark: "",
  5218. WarehouseInfoId: info.WarehouseInfotId,
  5219. PatientId: info.PatientId,
  5220. RecordDate: info.SysRecordTime,
  5221. StorehouseId: houseConfig.StorehouseOutInfo,
  5222. IsCheck: 1,
  5223. }
  5224. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5225. //回退库存
  5226. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5227. //退库数量增加
  5228. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5229. //出库数量减少
  5230. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5231. }
  5232. if info.Count < prescribingNumber {
  5233. cancelStockInfo := models.CancelStockInfo{
  5234. GoodId: project.ProjectId,
  5235. CancelStockId: cancel.ID,
  5236. GoodTypeId: good.GoodTypeId,
  5237. Count: info.Count,
  5238. Price: info.Price,
  5239. Total: 0,
  5240. ProductDate: info.ProductDate,
  5241. ExpiryDate: info.ExpiryDate,
  5242. Ctime: time.Now().Unix(),
  5243. Status: 1,
  5244. OrgId: adminInfo.CurrentOrgId,
  5245. OrderNumber: cancel.OrderNumber,
  5246. Type: 0,
  5247. Dealer: deaerler.DealerName,
  5248. Manufacturer: manufacturer.ManufacturerName,
  5249. Number: info.Number,
  5250. RegisterAccount: "",
  5251. Remark: "",
  5252. WarehouseInfoId: info.WarehouseInfotId,
  5253. PatientId: info.PatientId,
  5254. RecordDate: info.SysRecordTime,
  5255. StorehouseId: houseConfig.StorehouseOutInfo,
  5256. IsCheck: 1,
  5257. }
  5258. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5259. //回退库存
  5260. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5261. //退库数量增加
  5262. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5263. //出库数量减少
  5264. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5265. }
  5266. //查询剩余库存
  5267. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5268. var over_count int64
  5269. for _, it := range goodList {
  5270. over_count += it.StockCount
  5271. }
  5272. //出库数据 大于 退库数量
  5273. if info.Count >= prescribingNumber {
  5274. flow := models.VmStockFlow{
  5275. WarehousingId: info.WarehouseInfotId,
  5276. GoodId: project.ProjectId,
  5277. Number: info.Number,
  5278. LicenseNumber: info.LicenseNumber,
  5279. Count: prescribingNumber,
  5280. UserOrgId: adminInfo.CurrentOrgId,
  5281. PatientId: project.PatientId,
  5282. SystemTime: info.SysRecordTime,
  5283. ConsumableType: 7,
  5284. IsSys: 0,
  5285. WarehousingOrder: "",
  5286. WarehouseOutId: info.WarehouseOutId,
  5287. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5288. IsEdit: 0,
  5289. CancelStockId: cancel.ID,
  5290. CancelOrderNumber: cancel.OrderNumber,
  5291. Manufacturer: manufacturer.ID,
  5292. Dealer: 0,
  5293. Creator: adminInfo.AdminUser.Id,
  5294. UpdateCreator: 0,
  5295. Status: 1,
  5296. Ctime: time.Now().Unix(),
  5297. Mtime: 0,
  5298. Price: info.Price,
  5299. WarehousingDetailId: info.WarehouseInfotId,
  5300. WarehouseOutDetailId: info.ID,
  5301. CancelOutDetailId: cancelInfo.ID,
  5302. ProductDate: info.ProductDate,
  5303. ExpireDate: info.ExpiryDate,
  5304. StorehouseId: houseConfig.StorehouseOutInfo,
  5305. OverCount: over_count,
  5306. }
  5307. service.CreateStockFlowOne(flow)
  5308. }
  5309. //出库数据小于退库数据
  5310. if info.Count < prescribingNumber {
  5311. flow := models.VmStockFlow{
  5312. WarehousingId: info.WarehouseInfotId,
  5313. GoodId: project.ProjectId,
  5314. Number: info.Number,
  5315. LicenseNumber: info.LicenseNumber,
  5316. Count: info.Count,
  5317. UserOrgId: adminInfo.CurrentOrgId,
  5318. PatientId: project.PatientId,
  5319. SystemTime: info.SysRecordTime,
  5320. ConsumableType: 7,
  5321. IsSys: 0,
  5322. WarehousingOrder: "",
  5323. WarehouseOutId: info.WarehouseOutId,
  5324. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5325. IsEdit: 0,
  5326. CancelStockId: cancel.ID,
  5327. CancelOrderNumber: cancel.OrderNumber,
  5328. Manufacturer: manufacturer.ID,
  5329. Dealer: 0,
  5330. Creator: adminInfo.AdminUser.Id,
  5331. UpdateCreator: 0,
  5332. Status: 1,
  5333. Ctime: time.Now().Unix(),
  5334. Mtime: 0,
  5335. Price: info.Price,
  5336. WarehousingDetailId: info.WarehouseInfotId,
  5337. WarehouseOutDetailId: info.ID,
  5338. CancelOutDetailId: cancelInfo.ID,
  5339. ProductDate: info.ProductDate,
  5340. ExpireDate: info.ExpiryDate,
  5341. StorehouseId: houseConfig.StorehouseOutInfo,
  5342. OverCount: over_count,
  5343. }
  5344. service.CreateStockFlowOne(flow)
  5345. }
  5346. //查询已出库数量
  5347. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5348. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5349. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5350. if prescribingNumber < dialysisInfo.Count {
  5351. //改变数量
  5352. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5353. }
  5354. if prescribingNumber >= dialysisInfo.Count {
  5355. //删除出库表
  5356. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5357. }
  5358. //更新剩余库存
  5359. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5360. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5361. var total_count_one int64
  5362. for _, it := range stockList {
  5363. total_count_one += it.StockCount
  5364. }
  5365. //基础库插入数据
  5366. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5367. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5368. var flush_count int64
  5369. for _, it := range goodListOne {
  5370. flush_count += it.StockCount
  5371. }
  5372. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5373. if errs != nil {
  5374. goodErrcode := models.XtGoodErrcode{
  5375. UserOrgId: project.UserOrgId,
  5376. Errcode: "手动出库更新剩余出库失败",
  5377. GoodId: project.ProjectId,
  5378. Status: 1,
  5379. Ctime: time.Now().Unix(),
  5380. Mtime: 0,
  5381. Count: 0,
  5382. StockCount: 0,
  5383. Creater: creater,
  5384. BatchNumberId: 0,
  5385. WarehouseOutId: 0,
  5386. }
  5387. service.CreateGoodErrcode(goodErrcode)
  5388. }
  5389. }
  5390. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5391. fmt.Println(err)
  5392. } else {
  5393. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5394. fmt.Println(err)
  5395. }
  5396. } else {
  5397. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5398. fmt.Println(err)
  5399. }
  5400. }
  5401. //保存处方出库
  5402. if goodOutConfig.IsOpen == 1 {
  5403. if project.Type == 3 {
  5404. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5405. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5406. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5407. operation_time := time.Now().Unix()
  5408. creater := adminInfo.AdminUser.Id
  5409. //创建退库单
  5410. timeStr := time.Now().Format("2006-01-02")
  5411. timeArr := strings.Split(timeStr, "-")
  5412. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5413. total = total + 1
  5414. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5415. cancelStock := models.CancelStock{
  5416. OrderNumber: orderNumber,
  5417. OperaTime: operation_time,
  5418. OrgId: adminInfo.CurrentOrgId,
  5419. Creater: creater,
  5420. Ctime: time.Now().Unix(),
  5421. Status: 1,
  5422. ReturnTime: project.RecordDate,
  5423. Type: 1,
  5424. StorehouseId: houseConfig.StorehouseOutInfo,
  5425. IsCheck: 1,
  5426. }
  5427. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5428. if msgerrkonde == gorm.ErrRecordNotFound {
  5429. service.AddSigleCancelStock(&cancelStock)
  5430. }
  5431. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5432. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5433. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5434. //获取出库数据
  5435. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5436. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5437. deaerler, _ := service.GetDealerById(info.Dealer)
  5438. if info.ID > 0 {
  5439. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5440. if info.Count >= prescribingNumber {
  5441. cancelStockInfo := models.CancelStockInfo{
  5442. GoodId: project.ProjectId,
  5443. CancelStockId: cancel.ID,
  5444. GoodTypeId: good.GoodTypeId,
  5445. Count: prescribingNumber,
  5446. Price: info.Price,
  5447. Total: 0,
  5448. ProductDate: info.ProductDate,
  5449. ExpiryDate: info.ExpiryDate,
  5450. Ctime: time.Now().Unix(),
  5451. Status: 1,
  5452. OrgId: adminInfo.CurrentOrgId,
  5453. OrderNumber: cancel.OrderNumber,
  5454. Type: 0,
  5455. Dealer: deaerler.DealerName,
  5456. Manufacturer: manufacturer.ManufacturerName,
  5457. Number: info.Number,
  5458. RegisterAccount: "",
  5459. Remark: "",
  5460. WarehouseInfoId: info.WarehouseInfotId,
  5461. PatientId: info.PatientId,
  5462. RecordDate: info.SysRecordTime,
  5463. StorehouseId: houseConfig.StorehouseOutInfo,
  5464. IsCheck: 1,
  5465. }
  5466. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5467. //退库数量增加
  5468. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5469. //出库数量减少
  5470. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5471. }
  5472. if info.Count < prescribingNumber {
  5473. cancelStockInfo := models.CancelStockInfo{
  5474. GoodId: project.ProjectId,
  5475. CancelStockId: cancel.ID,
  5476. GoodTypeId: good.GoodTypeId,
  5477. Count: prescribingNumber,
  5478. Price: info.Price,
  5479. Total: 0,
  5480. ProductDate: info.ProductDate,
  5481. ExpiryDate: info.ExpiryDate,
  5482. Ctime: time.Now().Unix(),
  5483. Status: 1,
  5484. OrgId: adminInfo.CurrentOrgId,
  5485. OrderNumber: cancel.OrderNumber,
  5486. Type: 0,
  5487. Dealer: deaerler.DealerName,
  5488. Manufacturer: manufacturer.ManufacturerName,
  5489. Number: info.Number,
  5490. RegisterAccount: "",
  5491. Remark: "",
  5492. WarehouseInfoId: info.WarehouseInfotId,
  5493. PatientId: info.PatientId,
  5494. RecordDate: info.SysRecordTime,
  5495. StorehouseId: houseConfig.StorehouseOutInfo,
  5496. IsCheck: 1,
  5497. }
  5498. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5499. //回退库存
  5500. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5501. }
  5502. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5503. var over_count int64
  5504. for _, it := range goodList {
  5505. over_count += it.StockCount
  5506. }
  5507. //查询出库数量
  5508. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5509. //出库数据 大于 退库数量
  5510. if len(list) > 0 {
  5511. for _, it := range list {
  5512. //回退库存
  5513. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5514. //退库数量增加
  5515. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5516. //出库数量减少
  5517. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5518. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5519. var over_count_one int64
  5520. for _, it := range goodList {
  5521. over_count_one += it.StockCount
  5522. }
  5523. //查询该批次是否有退库数据
  5524. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5525. flow := models.VmStockFlow{
  5526. WarehousingId: it.WarehouseInfotId,
  5527. GoodId: it.GoodId,
  5528. Number: it.Number,
  5529. LicenseNumber: it.LicenseNumber,
  5530. Count: it.Count,
  5531. UserOrgId: adminInfo.CurrentOrgId,
  5532. PatientId: it.PatientId,
  5533. SystemTime: it.SysRecordTime,
  5534. ConsumableType: 7,
  5535. IsSys: 0,
  5536. WarehousingOrder: "",
  5537. WarehouseOutId: it.WarehouseOutId,
  5538. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5539. IsEdit: 0,
  5540. CancelStockId: cancel.ID,
  5541. CancelOrderNumber: cancel.OrderNumber,
  5542. Manufacturer: manufacturer.ID,
  5543. Dealer: 0,
  5544. Creator: adminInfo.AdminUser.Id,
  5545. UpdateCreator: 0,
  5546. Status: 1,
  5547. Ctime: time.Now().Unix(),
  5548. Mtime: 0,
  5549. Price: it.Price,
  5550. WarehousingDetailId: it.WarehouseInfotId,
  5551. WarehouseOutDetailId: it.ID,
  5552. CancelOutDetailId: cancelInfo.ID,
  5553. ProductDate: it.ProductDate,
  5554. ExpireDate: it.ExpiryDate,
  5555. StorehouseId: houseConfig.StorehouseOutInfo,
  5556. OverCount: over_count_one,
  5557. }
  5558. service.CreateStockFlowOne(flow)
  5559. }
  5560. }
  5561. //查询已出库数量
  5562. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5563. if prescribingNumber < dialysisInfo.Count {
  5564. //改变数量
  5565. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5566. }
  5567. if prescribingNumber >= dialysisInfo.Count {
  5568. //删除出库表
  5569. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5570. }
  5571. //更新剩余库存
  5572. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5573. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5574. var total_count_one int64
  5575. for _, it := range stockList {
  5576. total_count_one += it.StockCount
  5577. }
  5578. //基础库插入数据
  5579. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5580. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5581. var flush_count int64
  5582. for _, it := range goodListOne {
  5583. flush_count += it.StockCount
  5584. }
  5585. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5586. if errs != nil {
  5587. goodErrcode := models.XtGoodErrcode{
  5588. UserOrgId: project.UserOrgId,
  5589. Errcode: "手动出库更新剩余出库失败",
  5590. GoodId: project.ProjectId,
  5591. Status: 1,
  5592. Ctime: time.Now().Unix(),
  5593. Mtime: 0,
  5594. Count: 0,
  5595. StockCount: 0,
  5596. Creater: creater,
  5597. BatchNumberId: 0,
  5598. WarehouseOutId: 0,
  5599. }
  5600. service.CreateGoodErrcode(goodErrcode)
  5601. }
  5602. }
  5603. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5604. fmt.Println(err)
  5605. } else {
  5606. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5607. fmt.Println(err)
  5608. }
  5609. }
  5610. c.ServeSuccessJSON(map[string]interface{}{
  5611. "msg": "删除成功",
  5612. })
  5613. return
  5614. }
  5615. func (c *HisApiController) CreateHisAdditionalCharge() {
  5616. his_patient_id, _ := c.GetInt64("his_patient_id")
  5617. patient_id, _ := c.GetInt64("patient_id")
  5618. record_date := c.GetString("record_date")
  5619. timeLayout := "2006-01-02"
  5620. loc, _ := time.LoadLocation("Local")
  5621. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5622. if err != nil {
  5623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5624. return
  5625. }
  5626. adminInfo := c.GetAdminUserInfo()
  5627. recordDateTime := theTime.Unix()
  5628. dataBody := make(map[string]interface{}, 0)
  5629. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5630. if err != nil {
  5631. utils.ErrorLog(err.Error())
  5632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5633. return
  5634. }
  5635. var additions []*models.HisAdditionalCharge
  5636. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5637. additions, _ := dataBody["addition"].([]interface{})
  5638. if len(additions) > 0 {
  5639. for _, item := range additions {
  5640. items := item.(map[string]interface{})
  5641. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5642. utils.ErrorLog("item_id")
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5644. return
  5645. }
  5646. item_id := int64(items["item_id"].(float64))
  5647. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5648. utils.ErrorLog("item_name")
  5649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5650. return
  5651. }
  5652. item_name := items["item_name"].(string)
  5653. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5654. utils.ErrorLog("price")
  5655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5656. return
  5657. }
  5658. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5659. ctime := time.Now().Unix()
  5660. additional := &models.HisAdditionalCharge{
  5661. PatientId: patient_id,
  5662. HisPatientId: his_patient_id,
  5663. UserOrgId: adminInfo.CurrentOrgId,
  5664. RecordDate: recordDateTime,
  5665. CreatedTime: ctime,
  5666. UpdatedTime: ctime,
  5667. Modifier: adminInfo.AdminUser.Id,
  5668. Creator: adminInfo.AdminUser.Id,
  5669. Price: price,
  5670. ItemName: item_name,
  5671. ItemId: item_id,
  5672. Status: 1,
  5673. }
  5674. additions = append(additions, additional)
  5675. }
  5676. }
  5677. }
  5678. for _, item := range additions {
  5679. service.CreateAddtionalCharge(item)
  5680. }
  5681. c.ServeSuccessJSON(map[string]interface{}{
  5682. "msg": "创建成功",
  5683. })
  5684. }
  5685. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5686. blood_fat := c.GetString("blood_fat")
  5687. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5688. blood_sugar := c.GetString("blood_sugar")
  5689. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5690. chief_conplaint := c.GetString("chief_conplaint")
  5691. dbp := c.GetString("dbp")
  5692. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5693. delivery_way, _ := c.GetInt64("delivery_way")
  5694. diagnostic := c.GetString("diagnostic")
  5695. family_history := c.GetString("family_history")
  5696. height := c.GetString("height")
  5697. history_of_present_illness := c.GetString("history_of_present_illness")
  5698. is_infect, _ := c.GetInt64("is_infect")
  5699. past_history := c.GetString("past_history")
  5700. patient_id, _ := c.GetInt64("patient_id")
  5701. his_patient_id, _ := c.GetInt64("his_patient_id")
  5702. personal_history := c.GetString("personal_history")
  5703. pulse := c.GetString("pulse")
  5704. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5705. sbp := c.GetString("sbp")
  5706. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5707. heightfloat, _ := strconv.ParseFloat(height, 64)
  5708. sicktype := c.GetString("sick_type")
  5709. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5710. symptom := c.GetString("symptom")
  5711. sick_date := c.GetString("sick_date")
  5712. temperatures := c.GetString("temperature")
  5713. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5714. record_date := c.GetString("record_date")
  5715. breathing := c.GetString("breathing")
  5716. doctor_advice := c.GetString("doctor_advice")
  5717. remark := c.GetString("remark")
  5718. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5719. sick, _ := c.GetInt64("sick")
  5720. diagnose, _ := c.GetInt64("diagnose")
  5721. //id, _ := c.GetInt64("id")
  5722. timeLayout := "2006-01-02"
  5723. loc, _ := time.LoadLocation("Local")
  5724. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5725. allergic_history := c.GetString("allergic_history")
  5726. if err != nil {
  5727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5728. return
  5729. }
  5730. recordDateTime := theTime.Unix()
  5731. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5732. if err != nil {
  5733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5734. return
  5735. }
  5736. sickTimes := sickTime.Unix()
  5737. ctime := time.Now().Unix()
  5738. primary_disease := c.GetString("primary_disease")
  5739. confirm_failure_date := c.GetString("confirm_failure_date")
  5740. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5741. drug_allergy_history := c.GetString("drug_allergy_history")
  5742. physical_examination := c.GetString("physical_examination")
  5743. special_inspection := c.GetString("special_inspection")
  5744. lab_apparatus := c.GetString("lab_apparatus")
  5745. caseHistory := models.HisPatientCaseHistory{
  5746. HisPatientId: his_patient_id,
  5747. PatientId: patient_id,
  5748. Temperature: temperature,
  5749. BloodSugar: bloodsugarfloat,
  5750. Pulse: pulsefloat,
  5751. Sbp: sbpfloat,
  5752. Dbp: dbpfloat,
  5753. Height: heightfloat,
  5754. BloodFat: bloodfatfloat,
  5755. SickType: sick_type,
  5756. Symptom: symptom,
  5757. SickDate: sickTimes,
  5758. IsInfect: is_infect,
  5759. HistoryOfPresentIllness: history_of_present_illness,
  5760. PastHistory: past_history,
  5761. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5762. ChiefConplaint: chief_conplaint,
  5763. PersonalHistory: personal_history,
  5764. FamilyHistory: family_history,
  5765. Diagnostic: diagnostic,
  5766. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5767. Status: 1,
  5768. Ctime: ctime,
  5769. Mtime: ctime,
  5770. RecordDate: recordDateTime,
  5771. DeliveryWay: delivery_way,
  5772. Breathing: breathingfloat,
  5773. DoctorAdvice: doctor_advice,
  5774. Remark: remark,
  5775. Sick: sick,
  5776. Diagnose: diagnose,
  5777. AllergicHistory: allergic_history,
  5778. PrimaryDisease: primary_disease,
  5779. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5780. DrugAllergyHistory: drug_allergy_history,
  5781. PhysicalExamination: physical_examination,
  5782. SpecialInspection: special_inspection,
  5783. LabApparatus: lab_apparatus,
  5784. }
  5785. //查询该患者是否有病历
  5786. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5787. if errcodes == gorm.ErrRecordNotFound {
  5788. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5789. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5790. if err != nil {
  5791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5792. return
  5793. }
  5794. c.ServeSuccessJSON(map[string]interface{}{
  5795. "caseHistory": caseHistory,
  5796. "historyInfo": historyInfo,
  5797. })
  5798. return
  5799. } else if errcodes == nil {
  5800. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5801. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5802. if err != nil {
  5803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5804. return
  5805. }
  5806. c.ServeSuccessJSON(map[string]interface{}{
  5807. "caseHistory": caseHistory,
  5808. "historyInfo": historyInfo,
  5809. })
  5810. }
  5811. //查询该患者是否有病历
  5812. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5813. //if errcode == gorm.ErrRecordNotFound {
  5814. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5815. // if err != nil {
  5816. // c.ServeSuccessJSON(map[string]interface{}{
  5817. // "msg": "保存成功",
  5818. // })
  5819. // }
  5820. //} else if errcode == nil {
  5821. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5822. // return
  5823. //}
  5824. }
  5825. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5826. patient_id, _ := c.GetInt64("patient_id", 0)
  5827. adminUser := c.GetAdminUserInfo()
  5828. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5829. c.ServeSuccessJSON(map[string]interface{}{
  5830. "list": caseHistorys,
  5831. })
  5832. }
  5833. func (c *HisApiController) GetHisPatientCaseHistory() {
  5834. record_date, _ := c.GetInt64("record_date", 0)
  5835. patient_id, _ := c.GetInt64("patient_id", 0)
  5836. admin := c.GetAdminUserInfo()
  5837. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5838. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5839. c.ServeSuccessJSON(map[string]interface{}{
  5840. "info": info,
  5841. "case_history": case_history,
  5842. })
  5843. }
  5844. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5845. template_name := c.GetString("template_name")
  5846. template_remark := c.GetString("template_remark")
  5847. doctor := c.GetAdminUserInfo().AdminUser.Id
  5848. diagnostic := c.GetString("diagnostic")
  5849. chief_conplaint := c.GetString("chief_conplain")
  5850. history_of_present_illness := c.GetString("history_of_present_illness")
  5851. past_history := c.GetString("past_history")
  5852. personal_history := c.GetString("personal_history")
  5853. family_history := c.GetString("family_history")
  5854. user_name := c.GetString("user_name")
  5855. doctor_advice := c.GetString("doctor_advice")
  5856. remark := c.GetString("remark")
  5857. //record_date := c.GetString("record_date")
  5858. //fmt.Println("record_date--------",record_date)
  5859. //timeLayout := "2006-01-02"
  5860. //loc, _ := time.LoadLocation("Local")
  5861. //
  5862. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5863. //if err != nil {
  5864. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5865. // return
  5866. //}
  5867. //recordDateTime := theTime.Unix()
  5868. ctime := time.Now().Unix()
  5869. template := models.HisCaseHistoryTemplate{
  5870. HistoryOfPresentIllness: history_of_present_illness,
  5871. PastHistory: past_history,
  5872. ChiefConplaint: chief_conplaint,
  5873. PersonalHistory: personal_history,
  5874. FamilyHistory: family_history,
  5875. Diagnostic: diagnostic,
  5876. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5877. Status: 1,
  5878. Ctime: ctime,
  5879. Mtime: ctime,
  5880. RecordDate: time.Now().Unix(),
  5881. TemplateName: template_name,
  5882. TemplateRemark: template_remark,
  5883. Creator: doctor,
  5884. Modifier: doctor,
  5885. UserName: user_name,
  5886. DoctorAdvice: doctor_advice,
  5887. Remark: remark,
  5888. }
  5889. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5890. if err == nil {
  5891. c.ServeSuccessJSON(map[string]interface{}{
  5892. "msg": "保存成功",
  5893. })
  5894. } else {
  5895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5896. return
  5897. }
  5898. }
  5899. func (c *HisApiController) GetCaseHistoryTemplate() {
  5900. timeLayout := "2006-01-02"
  5901. loc, _ := time.LoadLocation("Local")
  5902. keyword := c.GetString("keyword")
  5903. start_time := c.GetString("start_time")
  5904. end_time := c.GetString("end_time")
  5905. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5906. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5907. admin := c.GetAdminUserInfo()
  5908. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5909. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5910. c.ServeSuccessJSON(map[string]interface{}{
  5911. "template": template,
  5912. //"history": history,
  5913. })
  5914. }
  5915. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5916. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5917. utils.ErrorLog("drug_name")
  5918. return enums.ErrorCodeParamWrong
  5919. }
  5920. adviceName, _ := json["drug_name"].(string)
  5921. if len(adviceName) == 0 {
  5922. utils.ErrorLog("len(advice_name) == 0")
  5923. return enums.ErrorCodeParamWrong
  5924. }
  5925. advice.AdviceName = adviceName
  5926. adviceDesc, _ := json["advice_desc"].(string)
  5927. advice.AdviceDesc = adviceDesc
  5928. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5929. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5930. advice.DrugSpec = drugSpec
  5931. }
  5932. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5933. remark, _ := json["remark"].(string)
  5934. advice.Remark = remark
  5935. }
  5936. if json["id"] == nil {
  5937. advice.DrugId = 0
  5938. } else {
  5939. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5940. drug_id := int64(json["id"].(float64))
  5941. advice.DrugId = drug_id
  5942. }
  5943. }
  5944. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5945. advice_id := int64(json["advice_id"].(float64))
  5946. advice.ID = advice_id
  5947. if advice.ID > 0 {
  5948. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5949. if err == nil {
  5950. if hisAdvice.ID > 0 {
  5951. advice.ExecutionTime = hisAdvice.ExecutionTime
  5952. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5953. advice.ExecutionState = hisAdvice.ExecutionState
  5954. advice.CheckTime = hisAdvice.CheckTime
  5955. advice.Checker = hisAdvice.Checker
  5956. advice.CheckState = hisAdvice.CheckState
  5957. advice.StartTime = hisAdvice.StartTime
  5958. advice.FeedetlSn = hisAdvice.FeedetlSn
  5959. }
  5960. }
  5961. }
  5962. }
  5963. //
  5964. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5965. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5966. // advice.ExecutionTime = execution_time
  5967. //}
  5968. //
  5969. //
  5970. //
  5971. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5972. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5973. // advice.ExecutionStaff = execution_staff
  5974. //}
  5975. //
  5976. //
  5977. //
  5978. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5979. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5980. // advice.ExecutionState = execution_state
  5981. //}
  5982. //
  5983. //
  5984. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5985. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5986. // advice.CheckTime = check_time
  5987. //}
  5988. //
  5989. //
  5990. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5991. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5992. // advice.CheckState = check_state
  5993. //}
  5994. //
  5995. //
  5996. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5997. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5998. // advice.Checker = checker
  5999. //}
  6000. //
  6001. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6002. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6003. // advice.StartTime = start_time
  6004. //}
  6005. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6006. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6007. advice.IsSelfDrug = is_self_drug
  6008. }
  6009. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6010. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6011. drug_way_count, _ := json["drug_way_count"].(string)
  6012. advice.DrugWayCount = drug_way_count
  6013. }
  6014. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6015. drugSpecUnit, _ := json["min_unit"].(string)
  6016. advice.DrugSpecUnit = drugSpecUnit
  6017. }
  6018. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6019. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6020. advice.SingleDose = singleDose
  6021. }
  6022. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6023. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6024. advice.SingleDoseUnit = singleDoseUnit
  6025. }
  6026. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6027. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6028. advice.PrescribingNumber = prescribingNumber
  6029. }
  6030. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6031. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6032. advice.PrescribingNumberUnit = prescribingNumberUnit
  6033. }
  6034. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6035. deliveryWay, _ := json["delivery_way"].(string)
  6036. advice.DeliveryWay = deliveryWay
  6037. }
  6038. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6039. executionFrequency, _ := json["execution_frequency"].(string)
  6040. advice.ExecutionFrequency = executionFrequency
  6041. }
  6042. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6043. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6044. advice.Price = price
  6045. }
  6046. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6047. med_list_codg, _ := json["medical_insurance_number"].(string)
  6048. advice.MedListCodg = med_list_codg
  6049. }
  6050. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6051. day := int64(json["day"].(float64))
  6052. advice.Day = day
  6053. }
  6054. return 0
  6055. }
  6056. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6057. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6058. id := int64(json["id"].(float64))
  6059. project.ID = id
  6060. historyProject, _ := service.GetHisProjectByID(id)
  6061. project.FeedetlSn = historyProject.FeedetlSn
  6062. }
  6063. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6064. project_id := int64(json["project_id"].(float64))
  6065. project.ProjectId = project_id
  6066. }
  6067. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6068. // price := int64(json["price"].(float64))
  6069. // formatInt_price := strconv.FormatInt(price, 10)
  6070. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6071. // project.Price = float_price
  6072. // }
  6073. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6074. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6075. project.Price = price
  6076. }
  6077. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6078. total, _ := json["total"].(string)
  6079. project.Count = total
  6080. }
  6081. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6082. medical_code, _ := json["medical_code"].(string)
  6083. project.MedListCodg = medical_code
  6084. }
  6085. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6086. single_dose, _ := json["single_dose"].(string)
  6087. project.SingleDose = single_dose
  6088. }
  6089. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6090. delivery_way, _ := json["delivery_way"].(string)
  6091. project.DeliveryWay = delivery_way
  6092. }
  6093. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6094. execution_frequency, _ := json["execution_frequency"].(string)
  6095. project.ExecutionFrequency = execution_frequency
  6096. }
  6097. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6098. remark, _ := json["remark"].(string)
  6099. project.Remark = remark
  6100. }
  6101. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6102. day, _ := json["number_days"].(string)
  6103. project.Day = day
  6104. }
  6105. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6106. unit, _ := json["unit"].(string)
  6107. project.Unit = unit
  6108. }
  6109. return 0
  6110. }
  6111. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6112. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6113. id := int64(json["id"].(float64))
  6114. historyAddtions, _ := service.GetHisAdditionByID(id)
  6115. additionalCharge.ID = id
  6116. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6117. }
  6118. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6119. item_id := int64(json["item_id"].(float64))
  6120. additionalCharge.ItemId = item_id
  6121. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6122. if config.ID > 0 {
  6123. if len(config.Code) > 0 {
  6124. additionalCharge.MedListCodg = config.Code
  6125. }
  6126. }
  6127. }
  6128. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6129. // price := int64(json["price"].(float64))
  6130. // formatInt_price := strconv.FormatInt(price, 10)
  6131. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6132. // additionalCharge.Price = float_price
  6133. // }
  6134. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6135. // price := int64(json["price"].(float64))
  6136. // formatInt_price := strconv.FormatInt(price, 10)
  6137. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6138. // additionalCharge.Price = float_price
  6139. //}
  6140. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6141. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6142. additionalCharge.Price = price
  6143. }
  6144. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6145. count, _ := json["count"].(string)
  6146. counts, _ := strconv.ParseInt(count, 10, 64)
  6147. additionalCharge.Count = counts
  6148. }
  6149. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6150. item_name, _ := json["item_name"].(string)
  6151. additionalCharge.ItemName = item_name
  6152. }
  6153. return 0
  6154. }
  6155. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6156. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6157. utils.ErrorLog("drug_name")
  6158. return enums.ErrorCodeParamWrong
  6159. }
  6160. adviceName, _ := json["drug_name"].(string)
  6161. if len(adviceName) == 0 {
  6162. utils.ErrorLog("len(advice_name) == 0")
  6163. return enums.ErrorCodeParamWrong
  6164. }
  6165. advice.AdviceName = adviceName
  6166. adviceDesc, _ := json["advice_desc"].(string)
  6167. advice.AdviceDesc = adviceDesc
  6168. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6169. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6170. advice.DrugSpec = drugSpec
  6171. }
  6172. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6173. remark, _ := json["remark"].(string)
  6174. advice.Remark = remark
  6175. }
  6176. if json["id"] == nil {
  6177. advice.DrugId = 0
  6178. } else {
  6179. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6180. drug_id := int64(json["id"].(float64))
  6181. advice.DrugId = drug_id
  6182. }
  6183. }
  6184. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6185. groupno := int64(json["groupno"].(float64))
  6186. advice.Groupno = groupno
  6187. }
  6188. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6189. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6190. advice.IsSelfDrug = is_self_drug
  6191. }
  6192. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6193. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6194. drug_way_count, _ := json["drug_way_count"].(string)
  6195. advice.DrugWayCount = drug_way_count
  6196. }
  6197. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6198. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6199. advice.HospApprFlag = hosp_appr_flag
  6200. }
  6201. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6202. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6203. advice.PrescribingNumber = prescribingNumber
  6204. }
  6205. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6206. // frequency_type := int64(json["frequency_type"].(float64))
  6207. // advice.FrequencyType = frequency_type
  6208. //}
  6209. //
  6210. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6211. // day_count := int64(json["day_count"].(float64))
  6212. // advice.DayCount = day_count
  6213. //}
  6214. //
  6215. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6216. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6217. // week_day, _ := json["week_day"].(string)
  6218. // advice.WeekDay = week_day
  6219. //}
  6220. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6221. drugSpecUnit, _ := json["min_unit"].(string)
  6222. advice.DrugSpecUnit = drugSpecUnit
  6223. }
  6224. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6225. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6226. advice.SingleDose = singleDose
  6227. }
  6228. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6229. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6230. advice.SingleDoseUnit = singleDoseUnit
  6231. }
  6232. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6233. deliveryWay, _ := json["delivery_way"].(string)
  6234. advice.DeliveryWay = deliveryWay
  6235. }
  6236. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6237. executionFrequency, _ := json["execution_frequency"].(string)
  6238. advice.ExecutionFrequency = executionFrequency
  6239. }
  6240. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6241. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6242. advice.Price = price
  6243. }
  6244. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6245. med_list_codg, _ := json["medical_insurance_number"].(string)
  6246. advice.MedListCodg = med_list_codg
  6247. }
  6248. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6249. day := int64(json["day"].(float64))
  6250. advice.Day = day
  6251. }
  6252. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6253. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6254. advice.PrescribingNumberUnit = prescribingNumberUnit
  6255. }
  6256. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6257. advice_id := int64(json["advice_id"].(float64))
  6258. advice.ID = advice_id
  6259. if advice.ID > 0 {
  6260. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6261. if err == nil {
  6262. if hisAdvice.ID > 0 {
  6263. advice.ExecutionTime = hisAdvice.ExecutionTime
  6264. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6265. advice.ExecutionState = hisAdvice.ExecutionState
  6266. advice.CheckTime = hisAdvice.CheckTime
  6267. advice.Checker = hisAdvice.Checker
  6268. advice.CheckState = hisAdvice.CheckState
  6269. advice.StartTime = hisAdvice.StartTime
  6270. advice.HospApprFlag = hisAdvice.HospApprFlag
  6271. advice.IsMedicine = hisAdvice.IsMedicine
  6272. if hisAdvice.UserOrgId == 10028 {
  6273. 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 {
  6274. advice.ExecutionTime = 0
  6275. advice.ExecutionStaff = 0
  6276. advice.ExecutionState = 2
  6277. advice.CheckTime = 0
  6278. advice.Checker = 0
  6279. advice.CheckState = 2
  6280. }
  6281. } else {
  6282. 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 {
  6283. advice.ExecutionTime = 0
  6284. advice.ExecutionStaff = 0
  6285. advice.ExecutionState = 2
  6286. advice.CheckTime = 0
  6287. advice.Checker = 0
  6288. advice.CheckState = 2
  6289. }
  6290. }
  6291. //advice.Groupno = hisAdvice.Groupno
  6292. }
  6293. }
  6294. }
  6295. }
  6296. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6297. //
  6298. //if drugStockConfig.IsOpen == 1 {
  6299. //
  6300. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6301. // if advice.ID == 0 { //医嘱不存在
  6302. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6303. // drug.Total = drug.Total - advice.PrescribingNumber
  6304. // service.UpdateBaseDrugLib(&drug)
  6305. //
  6306. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6307. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6308. // drug.Total = drug.Total - num
  6309. // service.UpdateBaseDrugLib(&drug)
  6310. // }
  6311. //
  6312. // } else if advice.ID > 0 { //医嘱存在
  6313. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6314. // var num float64
  6315. //
  6316. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6317. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6318. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6319. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6320. // drug.Total = drug.Total + num
  6321. // service.UpdateBaseDrugLib(&drug)
  6322. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6323. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6324. // drug.Total = drug.Total - num
  6325. // service.UpdateBaseDrugLib(&drug)
  6326. // }
  6327. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6328. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6329. // if num2 > advice.PrescribingNumber {
  6330. // num = num2 - advice.PrescribingNumber
  6331. // drug.Total = drug.Total + num
  6332. // service.UpdateBaseDrugLib(&drug)
  6333. // } else if num2 < advice.PrescribingNumber {
  6334. // num = advice.PrescribingNumber - num2
  6335. // drug.Total = drug.Total - num
  6336. // service.UpdateBaseDrugLib(&drug)
  6337. // }
  6338. //
  6339. // }
  6340. //
  6341. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6342. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6343. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6344. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6345. // if num1 > num2 {
  6346. // num = num1 - num2
  6347. // drug.Total = drug.Total + num
  6348. // service.UpdateBaseDrugLib(&drug)
  6349. // } else if num1 < num2 {
  6350. // num = num2 - num1
  6351. // drug.Total = drug.Total - num
  6352. // service.UpdateBaseDrugLib(&drug)
  6353. // }
  6354. //
  6355. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6356. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6357. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6358. // if hisAdvice.PrescribingNumber > num2 {
  6359. // num = hisAdvice.PrescribingNumber - num2
  6360. // drug.Total = drug.Total + num
  6361. // service.UpdateBaseDrugLib(&drug)
  6362. // } else if num2 < advice.PrescribingNumber {
  6363. // num = num2 - hisAdvice.PrescribingNumber
  6364. // drug.Total = drug.Total - num
  6365. // service.UpdateBaseDrugLib(&drug)
  6366. // }
  6367. //
  6368. // }
  6369. // }
  6370. // }
  6371. //}
  6372. //
  6373. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6374. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6375. // advice.ExecutionTime = execution_time
  6376. //}
  6377. //
  6378. //
  6379. //
  6380. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6381. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6382. // advice.ExecutionStaff = execution_staff
  6383. //}
  6384. //
  6385. //
  6386. //
  6387. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6388. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6389. // advice.ExecutionState = execution_state
  6390. //}
  6391. //
  6392. //
  6393. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6394. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6395. // advice.CheckTime = check_time
  6396. //}
  6397. //
  6398. //
  6399. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6400. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6401. // advice.CheckState = check_state
  6402. //}
  6403. //
  6404. //
  6405. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6406. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6407. // advice.Checker = checker
  6408. //}
  6409. //
  6410. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6411. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6412. // advice.StartTime = start_time
  6413. //}
  6414. return 0
  6415. }
  6416. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6417. project.ExecutionStaff = 0
  6418. project.ExecutionState = 2
  6419. project.ExecutionTime = 0
  6420. project.Checker = 0
  6421. project.CheckState = 2
  6422. project.CheckTime = 0
  6423. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6424. id := int64(json["id"].(float64))
  6425. project.ID = id
  6426. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6427. project.ExecutionStaff = temp_project.ExecutionStaff
  6428. project.ExecutionState = temp_project.ExecutionState
  6429. project.ExecutionTime = temp_project.ExecutionTime
  6430. project.Checker = temp_project.Checker
  6431. project.CheckState = temp_project.CheckState
  6432. project.CheckTime = temp_project.CheckTime
  6433. project.TeamId = temp_project.TeamId
  6434. }
  6435. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6436. types := int64(json["type"].(float64))
  6437. project.Type = types
  6438. }
  6439. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6440. project_id := int64(json["project_id"].(float64))
  6441. project.ProjectId = project_id
  6442. }
  6443. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6444. team_id := int64(json["team_id"].(float64))
  6445. project.TeamId = team_id
  6446. }
  6447. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6448. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6449. project.Price = price
  6450. }
  6451. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6452. total, _ := json["total"].(string)
  6453. //totals, _ := strconv.ParseInt(total, 10, 64)
  6454. project.Count = total
  6455. }
  6456. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6457. medical_code, _ := json["medical_code"].(string)
  6458. project.MedListCodg = medical_code
  6459. }
  6460. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6461. single_dose, _ := json["single_dose"].(string)
  6462. project.SingleDose = single_dose
  6463. }
  6464. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6465. delivery_way, _ := json["delivery_way"].(string)
  6466. project.DeliveryWay = delivery_way
  6467. }
  6468. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6469. execution_frequency, _ := json["execution_frequency"].(string)
  6470. project.ExecutionFrequency = execution_frequency
  6471. }
  6472. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6473. remark, _ := json["remark"].(string)
  6474. project.Remark = remark
  6475. }
  6476. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6477. day, _ := json["number_days"].(string)
  6478. project.Day = day
  6479. }
  6480. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6481. unit, _ := json["unit"].(string)
  6482. project.Unit = unit
  6483. }
  6484. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6485. // frequency_type := int64(json["frequency_type"].(float64))
  6486. // project.FrequencyType = frequency_type
  6487. //}
  6488. //
  6489. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6490. // day_count := int64(json["day_count"].(float64))
  6491. // project.DayCount = day_count
  6492. //}
  6493. //
  6494. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6495. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6496. // week_day, _ := json["week_day"].(string)
  6497. // project.WeekDay = week_day
  6498. //}
  6499. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6500. //
  6501. //if project.ID == 0 {
  6502. // if stockConfig.IsOpen == 1 {
  6503. // if project.Type == 3 {
  6504. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6505. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6506. // good.Total = good.Total - f_count
  6507. // service.UpdateGoodInfo(&good)
  6508. // }
  6509. // }
  6510. //
  6511. //} else {
  6512. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6513. //
  6514. // if stockConfig.IsOpen == 1 {
  6515. // if project.Type == 3 {
  6516. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6517. // if project.Count < temp_project.Count {
  6518. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6519. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6520. //
  6521. // other_count := f_count_two - f_count_one
  6522. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6523. // good.Total = good.Total + other_count_two
  6524. // service.UpdateGoodInfo(&good)
  6525. // } else if project.Count > temp_project.Count {
  6526. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6527. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6528. //
  6529. // other_count := f_count_one - f_count_two
  6530. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6531. // good.Total = good.Total - other_count_two
  6532. // service.UpdateGoodInfo(&good)
  6533. // }
  6534. //
  6535. // }
  6536. // }
  6537. //
  6538. //}
  6539. return 0
  6540. }
  6541. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6542. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6543. utils.ErrorLog("drug_name")
  6544. return enums.ErrorCodeParamWrong
  6545. }
  6546. adviceName, _ := json["drug_name"].(string)
  6547. if len(adviceName) == 0 {
  6548. utils.ErrorLog("len(advice_name) == 0")
  6549. return enums.ErrorCodeParamWrong
  6550. }
  6551. advice.AdviceName = adviceName
  6552. adviceDesc, _ := json["advice_desc"].(string)
  6553. advice.AdviceDesc = adviceDesc
  6554. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6555. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6556. advice.DrugSpec = drugSpec
  6557. }
  6558. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6559. remark, _ := json["remark"].(string)
  6560. advice.Remark = remark
  6561. }
  6562. if json["id"] == nil {
  6563. advice.DrugId = 0
  6564. } else {
  6565. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6566. drug_id := int64(json["id"].(float64))
  6567. advice.DrugId = drug_id
  6568. }
  6569. }
  6570. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6571. groupno := int64(json["groupno"].(float64))
  6572. advice.Groupno = groupno
  6573. }
  6574. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6575. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6576. advice.IsSelfDrug = is_self_drug
  6577. }
  6578. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6579. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6580. drug_way_count, _ := json["drug_way_count"].(string)
  6581. advice.DrugWayCount = drug_way_count
  6582. }
  6583. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6584. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6585. advice.HospApprFlag = hosp_appr_flag
  6586. }
  6587. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6588. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6589. advice.PrescribingNumber = prescribingNumber
  6590. }
  6591. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6592. // frequency_type := int64(json["frequency_type"].(float64))
  6593. // advice.FrequencyType = frequency_type
  6594. //}
  6595. //
  6596. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6597. // day_count := int64(json["day_count"].(float64))
  6598. // advice.DayCount = day_count
  6599. //}
  6600. //
  6601. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6602. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6603. // week_day, _ := json["week_day"].(string)
  6604. // advice.WeekDay = week_day
  6605. //}
  6606. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6607. drugSpecUnit, _ := json["min_unit"].(string)
  6608. advice.DrugSpecUnit = drugSpecUnit
  6609. }
  6610. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6611. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6612. advice.SingleDose = singleDose
  6613. }
  6614. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6615. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6616. advice.SingleDoseUnit = singleDoseUnit
  6617. }
  6618. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6619. deliveryWay, _ := json["delivery_way"].(string)
  6620. advice.DeliveryWay = deliveryWay
  6621. }
  6622. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6623. executionFrequency, _ := json["execution_frequency"].(string)
  6624. advice.ExecutionFrequency = executionFrequency
  6625. }
  6626. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6627. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6628. advice.Price = price
  6629. }
  6630. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6631. med_list_codg, _ := json["medical_insurance_number"].(string)
  6632. advice.MedListCodg = med_list_codg
  6633. }
  6634. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6635. day := int64(json["day"].(float64))
  6636. advice.Day = day
  6637. }
  6638. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6639. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6640. advice.PrescribingNumberUnit = prescribingNumberUnit
  6641. }
  6642. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6643. advice_id := int64(json["advice_id"].(float64))
  6644. advice.ID = advice_id
  6645. if advice.ID > 0 {
  6646. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6647. if err == nil {
  6648. if hisAdvice.ID > 0 {
  6649. if hisAdvice.YbSyncStatus == 1 {
  6650. advice.YbSyncStatus = 0
  6651. }
  6652. advice.UpdatedTime = time.Now().Unix()
  6653. advice.CreatedTime = hisAdvice.CreatedTime
  6654. advice.ExecutionTime = hisAdvice.ExecutionTime
  6655. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6656. advice.ExecutionState = hisAdvice.ExecutionState
  6657. advice.CheckTime = hisAdvice.CheckTime
  6658. advice.Checker = hisAdvice.Checker
  6659. advice.CheckState = hisAdvice.CheckState
  6660. advice.StartTime = hisAdvice.StartTime
  6661. advice.HospApprFlag = hisAdvice.HospApprFlag
  6662. advice.IsMedicine = hisAdvice.IsMedicine
  6663. if hisAdvice.UserOrgId == 10028 {
  6664. 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 {
  6665. advice.ExecutionTime = 0
  6666. advice.ExecutionStaff = 0
  6667. advice.ExecutionState = 2
  6668. advice.CheckTime = 0
  6669. advice.Checker = 0
  6670. advice.CheckState = 2
  6671. }
  6672. } else {
  6673. 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 {
  6674. advice.ExecutionTime = 0
  6675. advice.ExecutionStaff = 0
  6676. advice.ExecutionState = 2
  6677. advice.CheckTime = 0
  6678. advice.Checker = 0
  6679. advice.CheckState = 2
  6680. }
  6681. }
  6682. //advice.Groupno = hisAdvice.Groupno
  6683. }
  6684. }
  6685. }
  6686. }
  6687. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6688. //
  6689. //if drugStockConfig.IsOpen == 1 {
  6690. //
  6691. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6692. // if advice.ID == 0 { //医嘱不存在
  6693. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6694. // drug.Total = drug.Total - advice.PrescribingNumber
  6695. // service.UpdateBaseDrugLib(&drug)
  6696. //
  6697. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6698. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6699. // drug.Total = drug.Total - num
  6700. // service.UpdateBaseDrugLib(&drug)
  6701. // }
  6702. //
  6703. // } else if advice.ID > 0 { //医嘱存在
  6704. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6705. // var num float64
  6706. //
  6707. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6708. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6709. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6710. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6711. // drug.Total = drug.Total + num
  6712. // service.UpdateBaseDrugLib(&drug)
  6713. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6714. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6715. // drug.Total = drug.Total - num
  6716. // service.UpdateBaseDrugLib(&drug)
  6717. // }
  6718. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6719. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6720. // if num2 > advice.PrescribingNumber {
  6721. // num = num2 - advice.PrescribingNumber
  6722. // drug.Total = drug.Total + num
  6723. // service.UpdateBaseDrugLib(&drug)
  6724. // } else if num2 < advice.PrescribingNumber {
  6725. // num = advice.PrescribingNumber - num2
  6726. // drug.Total = drug.Total - num
  6727. // service.UpdateBaseDrugLib(&drug)
  6728. // }
  6729. //
  6730. // }
  6731. //
  6732. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6733. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6734. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6735. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6736. // if num1 > num2 {
  6737. // num = num1 - num2
  6738. // drug.Total = drug.Total + num
  6739. // service.UpdateBaseDrugLib(&drug)
  6740. // } else if num1 < num2 {
  6741. // num = num2 - num1
  6742. // drug.Total = drug.Total - num
  6743. // service.UpdateBaseDrugLib(&drug)
  6744. // }
  6745. //
  6746. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6747. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6748. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6749. // if hisAdvice.PrescribingNumber > num2 {
  6750. // num = hisAdvice.PrescribingNumber - num2
  6751. // drug.Total = drug.Total + num
  6752. // service.UpdateBaseDrugLib(&drug)
  6753. // } else if num2 < advice.PrescribingNumber {
  6754. // num = num2 - hisAdvice.PrescribingNumber
  6755. // drug.Total = drug.Total - num
  6756. // service.UpdateBaseDrugLib(&drug)
  6757. // }
  6758. //
  6759. // }
  6760. // }
  6761. // }
  6762. //}
  6763. //
  6764. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6765. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6766. // advice.ExecutionTime = execution_time
  6767. //}
  6768. //
  6769. //
  6770. //
  6771. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6772. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6773. // advice.ExecutionStaff = execution_staff
  6774. //}
  6775. //
  6776. //
  6777. //
  6778. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6779. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6780. // advice.ExecutionState = execution_state
  6781. //}
  6782. //
  6783. //
  6784. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6785. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6786. // advice.CheckTime = check_time
  6787. //}
  6788. //
  6789. //
  6790. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6791. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6792. // advice.CheckState = check_state
  6793. //}
  6794. //
  6795. //
  6796. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6797. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6798. // advice.Checker = checker
  6799. //}
  6800. //
  6801. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6802. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6803. // advice.StartTime = start_time
  6804. //}
  6805. return 0
  6806. }
  6807. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6808. project.ExecutionStaff = 0
  6809. project.ExecutionState = 2
  6810. project.ExecutionTime = 0
  6811. project.Checker = 0
  6812. project.CheckState = 2
  6813. project.CheckTime = 0
  6814. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6815. id := int64(json["id"].(float64))
  6816. project.ID = id
  6817. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6818. if temp_project.ID > 0 {
  6819. if temp_project.YbSyncStatus == 1 {
  6820. project.YbSyncStatus = 0
  6821. }
  6822. project.ExecutionStaff = temp_project.ExecutionStaff
  6823. project.ExecutionState = temp_project.ExecutionState
  6824. project.ExecutionTime = temp_project.ExecutionTime
  6825. project.Checker = temp_project.Checker
  6826. project.CheckState = temp_project.CheckState
  6827. project.CheckTime = temp_project.CheckTime
  6828. project.TeamId = temp_project.TeamId
  6829. project.Ctime = temp_project.Ctime
  6830. project.Mtime = time.Now().Unix()
  6831. }
  6832. }
  6833. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6834. types := int64(json["type"].(float64))
  6835. project.Type = types
  6836. }
  6837. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6838. project_id := int64(json["project_id"].(float64))
  6839. project.ProjectId = project_id
  6840. }
  6841. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6842. team_id := int64(json["team_id"].(float64))
  6843. project.TeamId = team_id
  6844. }
  6845. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6846. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6847. project.Price = price
  6848. }
  6849. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6850. total, _ := json["total"].(string)
  6851. //totals, _ := strconv.ParseInt(total, 10, 64)
  6852. project.Count = total
  6853. }
  6854. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6855. medical_code, _ := json["medical_code"].(string)
  6856. project.MedListCodg = medical_code
  6857. }
  6858. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6859. single_dose, _ := json["single_dose"].(string)
  6860. project.SingleDose = single_dose
  6861. }
  6862. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6863. delivery_way, _ := json["delivery_way"].(string)
  6864. project.DeliveryWay = delivery_way
  6865. }
  6866. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6867. execution_frequency, _ := json["execution_frequency"].(string)
  6868. project.ExecutionFrequency = execution_frequency
  6869. }
  6870. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6871. remark, _ := json["remark"].(string)
  6872. project.Remark = remark
  6873. }
  6874. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6875. day, _ := json["number_days"].(string)
  6876. project.Day = day
  6877. }
  6878. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6879. unit, _ := json["unit"].(string)
  6880. project.Unit = unit
  6881. }
  6882. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6883. // frequency_type := int64(json["frequency_type"].(float64))
  6884. // project.FrequencyType = frequency_type
  6885. //}
  6886. //
  6887. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6888. // day_count := int64(json["day_count"].(float64))
  6889. // project.DayCount = day_count
  6890. //}
  6891. //
  6892. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6893. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6894. // week_day, _ := json["week_day"].(string)
  6895. // project.WeekDay = week_day
  6896. //}
  6897. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6898. //
  6899. //if project.ID == 0 {
  6900. // if stockConfig.IsOpen == 1 {
  6901. // if project.Type == 3 {
  6902. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6903. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6904. // good.Total = good.Total - f_count
  6905. // service.UpdateGoodInfo(&good)
  6906. // }
  6907. // }
  6908. //
  6909. //} else {
  6910. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6911. //
  6912. // if stockConfig.IsOpen == 1 {
  6913. // if project.Type == 3 {
  6914. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6915. // if project.Count < temp_project.Count {
  6916. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6917. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6918. //
  6919. // other_count := f_count_two - f_count_one
  6920. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6921. // good.Total = good.Total + other_count_two
  6922. // service.UpdateGoodInfo(&good)
  6923. // } else if project.Count > temp_project.Count {
  6924. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6925. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6926. //
  6927. // other_count := f_count_one - f_count_two
  6928. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6929. // good.Total = good.Total - other_count_two
  6930. // service.UpdateGoodInfo(&good)
  6931. // }
  6932. //
  6933. // }
  6934. // }
  6935. //
  6936. //}
  6937. return 0
  6938. }
  6939. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6940. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6941. id := int64(json["id"].(float64))
  6942. additionalCharge.ID = id
  6943. }
  6944. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6945. item_id := int64(json["item_id"].(float64))
  6946. additionalCharge.ItemId = item_id
  6947. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6948. if config.ID > 0 {
  6949. if len(config.Code) > 0 {
  6950. additionalCharge.MedListCodg = config.Code
  6951. }
  6952. }
  6953. }
  6954. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6955. // price := int64(json["price"].(float64))
  6956. // formatInt_price := strconv.FormatInt(price, 10)
  6957. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6958. // additionalCharge.Price = float_price
  6959. // }
  6960. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6961. // price := int64(json["price"].(float64))
  6962. // formatInt_price := strconv.FormatInt(price, 10)
  6963. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6964. // additionalCharge.Price = float_price
  6965. //}
  6966. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6967. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6968. additionalCharge.Price = price
  6969. }
  6970. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6971. count, _ := json["count"].(string)
  6972. counts, _ := strconv.ParseInt(count, 10, 64)
  6973. additionalCharge.Count = counts
  6974. }
  6975. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6976. item_name, _ := json["item_name"].(string)
  6977. additionalCharge.ItemName = item_name
  6978. }
  6979. return 0
  6980. }
  6981. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6982. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6983. utils.ErrorLog("drug_name")
  6984. return enums.ErrorCodeParamWrong
  6985. }
  6986. adviceName, _ := json["drug_name"].(string)
  6987. if len(adviceName) == 0 {
  6988. utils.ErrorLog("len(advice_name) == 0")
  6989. return enums.ErrorCodeParamWrong
  6990. }
  6991. advice.AdviceName = adviceName
  6992. adviceDesc, _ := json["advice_desc"].(string)
  6993. advice.AdviceDesc = adviceDesc
  6994. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6995. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6996. advice.DrugSpec = drugSpec
  6997. }
  6998. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6999. remark, _ := json["remark"].(string)
  7000. advice.Remark = remark
  7001. }
  7002. if json["id"] == nil {
  7003. advice.DrugId = 0
  7004. } else {
  7005. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7006. drug_id := int64(json["id"].(float64))
  7007. advice.DrugId = drug_id
  7008. }
  7009. }
  7010. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7011. groupno := int64(json["groupno"].(float64))
  7012. advice.Groupno = groupno
  7013. }
  7014. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7015. drugSpecUnit, _ := json["min_unit"].(string)
  7016. advice.DrugSpecUnit = drugSpecUnit
  7017. }
  7018. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7019. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7020. advice.SingleDose = singleDose
  7021. }
  7022. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7023. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7024. advice.SingleDoseUnit = singleDoseUnit
  7025. }
  7026. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7027. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7028. advice.PrescribingNumber = prescribingNumber
  7029. }
  7030. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7031. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7032. advice.PrescribingNumberUnit = prescribingNumberUnit
  7033. }
  7034. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7035. deliveryWay, _ := json["delivery_way"].(string)
  7036. advice.DeliveryWay = deliveryWay
  7037. }
  7038. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7039. executionFrequency, _ := json["execution_frequency"].(string)
  7040. advice.ExecutionFrequency = executionFrequency
  7041. }
  7042. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7043. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7044. advice.Price = price
  7045. }
  7046. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7047. med_list_codg, _ := json["medical_insurance_number"].(string)
  7048. advice.MedListCodg = med_list_codg
  7049. }
  7050. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7051. day := int64(json["day"].(float64))
  7052. advice.Day = day
  7053. }
  7054. advice.FrequencyType = 1
  7055. return 0
  7056. }
  7057. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7058. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7059. types := int64(json["type"].(float64))
  7060. project.Type = types
  7061. }
  7062. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7063. project_id := int64(json["project_id"].(float64))
  7064. project.ProjectId = project_id
  7065. }
  7066. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7067. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7068. project.Price = price
  7069. }
  7070. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7071. total, _ := json["total"].(string)
  7072. //totals, _ := strconv.ParseInt(total, 10, 64)
  7073. project.Count = total
  7074. }
  7075. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7076. medical_code, _ := json["medical_code"].(string)
  7077. project.MedListCodg = medical_code
  7078. }
  7079. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7080. single_dose, _ := json["single_dose"].(string)
  7081. project.SingleDose = single_dose
  7082. }
  7083. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7084. delivery_way, _ := json["delivery_way"].(string)
  7085. project.DeliveryWay = delivery_way
  7086. }
  7087. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7088. execution_frequency, _ := json["execution_frequency"].(string)
  7089. project.ExecutionFrequency = execution_frequency
  7090. }
  7091. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7092. remark, _ := json["remark"].(string)
  7093. project.Remark = remark
  7094. }
  7095. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7096. day, _ := json["number_days"].(string)
  7097. project.Day = day
  7098. }
  7099. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7100. unit, _ := json["unit"].(string)
  7101. project.Unit = unit
  7102. }
  7103. project.FrequencyType = 1
  7104. return 0
  7105. }
  7106. func (c *HisApiController) GetHisOrderListTwo() {
  7107. start_time := c.GetString("start_time")
  7108. end_time := c.GetString("end_time")
  7109. timeLayout := "2006-01-02"
  7110. loc, _ := time.LoadLocation("Local")
  7111. var startTime int64
  7112. if len(start_time) > 0 {
  7113. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7114. if err != nil {
  7115. //fmt.Println(err)
  7116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7117. return
  7118. }
  7119. startTime = theTime.Unix()
  7120. }
  7121. var endTime int64
  7122. if len(end_time) > 0 {
  7123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7124. if err != nil {
  7125. utils.ErrorLog(err.Error())
  7126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7127. return
  7128. }
  7129. endTime = theTime.Unix()
  7130. }
  7131. adminUser := c.GetAdminUserInfo()
  7132. org_id := adminUser.CurrentOrgId
  7133. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7134. if err == nil {
  7135. c.ServeSuccessJSON(map[string]interface{}{
  7136. "order2": order,
  7137. })
  7138. } else {
  7139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7140. return
  7141. }
  7142. }
  7143. func (c *HisApiController) GetHisOrderList() {
  7144. page, _ := c.GetInt64("page", -1)
  7145. limit, _ := c.GetInt64("limit", -1)
  7146. start_time := c.GetString("start_time")
  7147. end_time := c.GetString("end_time")
  7148. types, _ := c.GetInt64("type", 0)
  7149. keywords := c.GetString("keywords")
  7150. p_type, _ := c.GetInt64("p_type", 0)
  7151. sort_type, _ := c.GetInt64("sort_type", 0)
  7152. charge_type, _ := c.GetInt64("charge_type", 0)
  7153. sch_type, _ := c.GetInt64("sch_type", 0)
  7154. zone_type, _ := c.GetInt64("zone_type", 0)
  7155. med_type, _ := c.GetInt64("med_type", 0)
  7156. timeLayout := "2006-01-02"
  7157. loc, _ := time.LoadLocation("Local")
  7158. var startTime int64
  7159. if len(start_time) > 0 {
  7160. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7161. if err != nil {
  7162. //fmt.Println(err)
  7163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7164. return
  7165. }
  7166. startTime = theTime.Unix()
  7167. }
  7168. var endTime int64
  7169. if len(end_time) > 0 {
  7170. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7171. if err != nil {
  7172. utils.ErrorLog(err.Error())
  7173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7174. return
  7175. }
  7176. endTime = theTime.Unix()
  7177. }
  7178. adminUser := c.GetAdminUserInfo()
  7179. org_id := adminUser.CurrentOrgId
  7180. 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)
  7181. for _, item := range order {
  7182. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7183. item.DoctorName = info.Doctor
  7184. item.DepartmentName = info.XtHisDepartment.Name
  7185. }
  7186. if err == nil {
  7187. c.ServeSuccessJSON(map[string]interface{}{
  7188. "order": order,
  7189. "total": total,
  7190. })
  7191. } else {
  7192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7193. return
  7194. }
  7195. }
  7196. func (c *HisApiController) GetHisOrder() {
  7197. patient_id, _ := c.GetInt64("patient_id", 0)
  7198. number := c.GetString("number")
  7199. adminInfo := c.GetAdminUserInfo()
  7200. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7201. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7202. if err == nil {
  7203. c.ServeSuccessJSON(map[string]interface{}{
  7204. "order": order,
  7205. "prescription": prescriptions,
  7206. })
  7207. } else {
  7208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7209. return
  7210. }
  7211. }
  7212. func (c *HisApiController) GetHisPrescriptionList() {
  7213. record_date := c.GetString("record_date")
  7214. keywords := c.GetString("keywords")
  7215. page, _ := c.GetInt64("page")
  7216. limit, _ := c.GetInt64("limit")
  7217. sch_type, _ := c.GetInt64("sch_type")
  7218. timeLayout := "2006-01-02"
  7219. loc, _ := time.LoadLocation("Local")
  7220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7221. if err != nil {
  7222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7223. return
  7224. }
  7225. recordDateTime := theTime.Unix()
  7226. adminInfo := c.GetAdminUserInfo()
  7227. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7228. //adminInfo := c.GetAdminUserInfo()
  7229. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7230. //fmt.Println(prescriptionOrder)
  7231. if err == nil {
  7232. c.ServeSuccessJSON(map[string]interface{}{
  7233. "order": prescriptionOrder,
  7234. "total": total,
  7235. })
  7236. } else {
  7237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7238. return
  7239. }
  7240. }
  7241. func (c *HisApiController) GetHisPrescriptionInfo() {
  7242. id, _ := c.GetInt64("id")
  7243. adminInfo := c.GetAdminUserInfo()
  7244. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7245. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7246. if err == nil {
  7247. c.ServeSuccessJSON(map[string]interface{}{
  7248. "order": prescriptionOrder,
  7249. "prescription": prescription,
  7250. })
  7251. } else {
  7252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7253. return
  7254. }
  7255. }
  7256. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7257. adminUser := c.GetAdminUserInfo()
  7258. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7259. c.ServeSuccessJSON(map[string]interface{}{
  7260. "config": config,
  7261. })
  7262. }
  7263. type ResultTwo struct {
  7264. ErrMsg interface{} `json:"err_msg"`
  7265. InfRefmsgid string `json:"inf_refmsgid"`
  7266. Infcode int64 `json:"infcode"`
  7267. Output struct {
  7268. Baseinfo struct {
  7269. Age float64 `json:"age"`
  7270. Brdy string `json:"brdy"`
  7271. Certno string `json:"certno"`
  7272. Gend string `json:"gend"`
  7273. Naty string `json:"naty"`
  7274. PsnCertType string `json:"psn_cert_type"`
  7275. PsnName string `json:"psn_name"`
  7276. PsnNo string `json:"psn_no"`
  7277. } `json:"baseinfo"`
  7278. Idetinfo []interface{} `json:"idetinfo"`
  7279. Iinfo []struct {
  7280. Balc float64 `json:"balc"`
  7281. CvlservFlag string `json:"cvlserv_flag"`
  7282. EmpName string `json:"emp_name"`
  7283. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7284. Insutype string `json:"insutype"`
  7285. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7286. PausInsuDate interface{} `json:"paus_insu_date"`
  7287. PsnInsuDate string `json:"psn_insu_date"`
  7288. PsnInsuStas string `json:"psn_insu_stas"`
  7289. PsnType string `json:"psn_type"`
  7290. } `json:"insuinfo"`
  7291. } `json:"output"`
  7292. RefmsgTime string `json:"refmsg_time"`
  7293. RespondTime string `json:"respond_time"`
  7294. Signtype interface{} `json:"signtype"`
  7295. WarnInfo interface{} `json:"warn_info"`
  7296. }
  7297. type ResultThree struct {
  7298. Cainfo interface{} `json:"cainfo"`
  7299. ErrMsg interface{} `json:"err_msg"`
  7300. InfRefmsgid string `json:"inf_refmsgid"`
  7301. Infcode int64 `json:"infcode"`
  7302. Output struct {
  7303. Data struct {
  7304. IptOtpNo string `json:"ipt_otp_no"`
  7305. MdtrtID string `json:"mdtrt_id"`
  7306. PsnNo string `json:"psn_no"`
  7307. } `json:"data"`
  7308. } `json:"output"`
  7309. RefmsgTime string `json:"refmsg_time"`
  7310. RespondTime string `json:"respond_time"`
  7311. Signtype interface{} `json:"signtype"`
  7312. WarnMsg interface{} `json:"warn_msg"`
  7313. }
  7314. type ResultFour struct {
  7315. Cainfo string `json:"cainfo"`
  7316. ErrMsg string `json:"err_msg"`
  7317. InfRefmsgid string `json:"inf_refmsgid"`
  7318. Infcode int64 `json:"infcode"`
  7319. Output struct {
  7320. Result []struct {
  7321. BasMednFlag string `json:"bas_medn_flag"`
  7322. ChldMedcFlag string `json:"chld_medc_flag"`
  7323. ChrgitmLv string `json:"chrgitm_lv"`
  7324. Cnt float64 `json:"cnt"`
  7325. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7326. DrtReimFlag string `json:"drt_reim_flag"`
  7327. FeedetlSn string `json:"feedetl_sn"`
  7328. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7329. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7330. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7331. ListSpItemFlag string `json:"list_sp_item_flag"`
  7332. LmtUsedFlag string `json:"lmt_used_flag"`
  7333. MedChrgitmType string `json:"med_chrgitm_type"`
  7334. Memo string `json:"memo"`
  7335. OverlmtAmt float64 `json:"overlmt_amt"`
  7336. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7337. Pric float64 `json:"pric"`
  7338. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7339. SelfpayProp float64 `json:"selfpay_prop"`
  7340. } `json:"result"`
  7341. } `json:"output"`
  7342. RefmsgTime string `json:"refmsg_time"`
  7343. RespondTime string `json:"respond_time"`
  7344. Signtype string `json:"signtype"`
  7345. WarnMsg string `json:"warn_msg"`
  7346. }
  7347. type ResultFive struct {
  7348. Insutype string `json:"insutype"`
  7349. }
  7350. type ResultSix struct {
  7351. Cainfo interface{} `json:"cainfo"`
  7352. ErrMsg interface{} `json:"err_msg"`
  7353. InfRefmsgid string `json:"inf_refmsgid"`
  7354. Infcode int64 `json:"infcode"`
  7355. Output struct {
  7356. } `json:"output"`
  7357. RefmsgTime string `json:"refmsg_time"`
  7358. RespondTime string `json:"respond_time"`
  7359. Signtype interface{} `json:"signtype"`
  7360. WarnMsg interface{} `json:"warn_msg"`
  7361. }
  7362. type ResultSeven struct {
  7363. Cainfo string `json:"cainfo"`
  7364. ErrMsg string `json:"err_msg"`
  7365. InfRefmsgid string `json:"inf_refmsgid"`
  7366. Infcode int64 `json:"infcode"`
  7367. Output struct {
  7368. Setldetail []interface{} `json:"setldetail"`
  7369. Setlinfo struct {
  7370. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7371. AcctPay float64 `json:"acct_pay"`
  7372. ActPayDedc float64 `json:"act_pay_dedc"`
  7373. Age float64 `json:"age"`
  7374. Balc float64 `json:"balc"`
  7375. Brdy string `json:"brdy"`
  7376. Certno string `json:"certno"`
  7377. ClrOptins string `json:"clr_optins"`
  7378. ClrType string `json:"clr_type"`
  7379. ClrWay string `json:"clr_way"`
  7380. CvlservFlag string `json:"cvlserv_flag"`
  7381. CvlservPay float64 `json:"cvlserv_pay"`
  7382. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7383. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7384. Gend string `json:"gend"`
  7385. HifesPay float64 `json:"hifes_pay"`
  7386. HifmiPay float64 `json:"hifmi_pay"`
  7387. HifobPay float64 `json:"hifob_pay"`
  7388. HifpPay float64 `json:"hifp_pay"`
  7389. HospPartAmt float64 `json:"hosp_part_amt"`
  7390. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7391. Insutype string `json:"insutype"`
  7392. MafPay float64 `json:"maf_pay"`
  7393. MdtrtCertType string `json:"mdtrt_cert_type"`
  7394. MdtrtID string `json:"mdtrt_id"`
  7395. MedType string `json:"med_type"`
  7396. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7397. MedinsSetlID string `json:"medins_setl_id"`
  7398. Naty string `json:"naty"`
  7399. OthPay float64 `json:"oth_pay"`
  7400. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7401. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7402. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7403. PsnCashPay float64 `json:"psn_cash_pay"`
  7404. PsnCertType string `json:"psn_cert_type"`
  7405. PsnName string `json:"psn_name"`
  7406. PsnNo string `json:"psn_no"`
  7407. PsnPartAmt float64 `json:"psn_part_amt"`
  7408. PsnType string `json:"psn_type"`
  7409. SetlID string `json:"setl_id"`
  7410. SetlTime string `json:"setl_time"`
  7411. } `json:"setlinfo"`
  7412. } `json:"output"`
  7413. RefmsgTime string `json:"refmsg_time"`
  7414. RespondTime string `json:"respond_time"`
  7415. Signtype interface{} `json:"signtype"`
  7416. WarnMsg interface{} `json:"warn_msg"`
  7417. }
  7418. type ResultEight struct {
  7419. Cainfo string `json:"cainfo"`
  7420. ErrMsg string `json:"err_msg"`
  7421. InfRefmsgid string `json:"inf_refmsgid"`
  7422. Infcode int64 `json:"infcode"`
  7423. Output struct {
  7424. Stmtinfo struct {
  7425. SetlOptins string `json:"setl_optins"`
  7426. StmtRslt string `json:"stmt_rslt"`
  7427. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7428. } `json:"stmtinfo"`
  7429. } `json:"output"`
  7430. RefmsgTime string `json:"refmsg_time"`
  7431. RespondTime string `json:"respond_time"`
  7432. Signtype interface{} `json:"signtype"`
  7433. WarnMsg interface{} `json:"warn_msg"`
  7434. }
  7435. type ResultNine struct {
  7436. Cainfo string `json:"cainfo"`
  7437. ErrMsg string `json:"err_msg"`
  7438. InfRefmsgid string `json:"inf_refmsgid"`
  7439. Infcode int64 `json:"infcode"`
  7440. Output struct {
  7441. FileQuryNo string `json:"file_qury_no"`
  7442. } `json:"output"`
  7443. RefmsgTime string `json:"refmsg_time"`
  7444. RespondTime string `json:"respond_time"`
  7445. Signtype interface{} `json:"signtype"`
  7446. WarnMsg interface{} `json:"warn_msg"`
  7447. }
  7448. type ResultTen struct {
  7449. Cainfo string `json:"cainfo"`
  7450. ErrMsg string `json:"err_msg"`
  7451. InfRefmsgid string `json:"inf_refmsgid"`
  7452. Infcode int64 `json:"infcode"`
  7453. Output struct {
  7454. DldEndtime string `json:"dld_endtime"`
  7455. FileQuryNo string `json:"file_qury_no"`
  7456. Filename string `json:"filename"`
  7457. } `json:"output"`
  7458. RefmsgTime string `json:"refmsg_time"`
  7459. RespondTime string `json:"respond_time"`
  7460. Signtype interface{} `json:"signtype"`
  7461. WarnMsg interface{} `json:"warn_msg"`
  7462. }
  7463. type ResultEleven struct {
  7464. Cainfo string `json:"cainfo"`
  7465. ErrMsg string `json:"err_msg"`
  7466. InfRefmsgid string `json:"inf_refmsgid"`
  7467. Infcode int64 `json:"infcode"`
  7468. Output struct {
  7469. Setlinfo struct {
  7470. FixmedinsName string `json:"fixmedins_name"`
  7471. FixmedinsCode string `json:"fixmedins_code"`
  7472. PsnNo string `json:"psn_no"`
  7473. PsnName string `json:"psn_name"`
  7474. HifobPay float64 `json:"hifob_pay"`
  7475. Gend string `json:"gend"`
  7476. Brdy string `json:"brdy"`
  7477. PsnCertType string `json:"psn_cert_type"`
  7478. PsnType string `json:"psn_type"`
  7479. EmpName string `json:"emp_name"`
  7480. Certno string `json:"certno"`
  7481. Insutype string `json:"insutype"`
  7482. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7483. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7484. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7485. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7486. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7487. ActPayDedc float64 `json:"act_pay_dedc"`
  7488. HifpPay float64 `json:"hifp_pay"`
  7489. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7490. CvlservPay float64 `json:"cvlserv_pay"`
  7491. HifesPay float64 `json:"hifes_pay"`
  7492. HifmiPay float64 `json:"hifmi_pay"`
  7493. MafPay float64 `json:"maf_pay"`
  7494. OthPay float64 `json:"oth_pay"`
  7495. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7496. PsnPay float64 `json:"psn_pay"`
  7497. AcctPay float64 `json:"acct_pay"`
  7498. CashPayamt float64 `json:"cash_payamt"`
  7499. Balc float64 `json:"balc"`
  7500. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7501. MedinsSetlId string `json:"medins_setl_id"`
  7502. RefdSetlFlag string `json:"refd_setl_flag"`
  7503. SetlTime string `json:"setl_time"`
  7504. MedType string `json:"med_type"`
  7505. } `json:"setlinfo"`
  7506. } `json:"output"`
  7507. RefmsgTime string `json:"refmsg_time"`
  7508. RespondTime string `json:"respond_time"`
  7509. Signtype interface{} `json:"signtype"`
  7510. WarnMsg interface{} `json:"warn_msg"`
  7511. }
  7512. type Custom struct {
  7513. DetItemFeeSumamt string
  7514. Cut string
  7515. FeedetlSn string
  7516. Price string
  7517. MedListCodg string
  7518. Type int64
  7519. AdviceId int64
  7520. ProjectId int64
  7521. ItemId int64
  7522. }
  7523. // 获取个人信息----挂号-----上传就诊信息
  7524. func (c *HisApiController) GetRegisterInfo() {
  7525. id, _ := c.GetInt64("id")
  7526. record_time := c.GetString("record_time")
  7527. settlementValue, _ := c.GetInt64("settlement_value")
  7528. medical_insurance_card := c.GetString("medical_insurance_card")
  7529. name := c.GetString("name")
  7530. id_card_type, _ := c.GetInt64("id_card_type")
  7531. certificates, _ := c.GetInt64("certificates")
  7532. medical_care, _ := c.GetInt64("medical_care")
  7533. birthday := c.GetString("birthday")
  7534. age, _ := c.GetInt64("age")
  7535. id_card := c.GetString("id_card")
  7536. register_type, _ := c.GetInt64("register")
  7537. doctor, _ := c.GetInt64("doctor")
  7538. department, _ := c.GetInt64("department")
  7539. gender, _ := c.GetInt64("sex")
  7540. phone := c.GetString("phone")
  7541. registration_fee, _ := c.GetFloat("registration_fee")
  7542. medical_expenses, _ := c.GetFloat("medical_expenses")
  7543. social_type, _ := c.GetInt64("social_type")
  7544. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7545. diagnosis_ids := c.GetString("diagnosis")
  7546. sick_type, _ := c.GetInt64("sick_type")
  7547. reg_type := c.GetString("p_type")
  7548. timeLayout := "2006-01-02"
  7549. loc, _ := time.LoadLocation("Local")
  7550. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7551. birthUnix := birthdays.Unix()
  7552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7553. if err != nil {
  7554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7555. return
  7556. }
  7557. recordDateTime := theTime.Unix()
  7558. adminInfo := c.GetAdminUserInfo()
  7559. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7560. if tempPatient.ID == 0 {
  7561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7562. return
  7563. }
  7564. var patient service.Patients
  7565. if id == 0 {
  7566. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7567. } else {
  7568. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7569. }
  7570. if patient.ID == 0 {
  7571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7572. return
  7573. }
  7574. if len(patient.IdCardNo) == 0 {
  7575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7576. return
  7577. }
  7578. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7579. if len(his) >= 1 {
  7580. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7581. if len(his) >= 1 && order.ID == 0 {
  7582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7583. return
  7584. }
  7585. }
  7586. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7587. fmt.Println(timeStr)
  7588. timeArr := strings.Split(timeStr, " ")
  7589. fmt.Println(timeArr)
  7590. timeArrTwo := strings.Split(timeArr[0], "-")
  7591. timeArrThree := strings.Split(timeArr[1], ":")
  7592. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7593. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7594. if len(lists) == 0 {
  7595. var hisPatient models.XtHisPatient
  7596. hisPatient = models.XtHisPatient{
  7597. Name: name,
  7598. Age: age,
  7599. Gender: gender,
  7600. Birthday: birthUnix,
  7601. Phone: phone,
  7602. MedicalTreatmentType: medical_care,
  7603. IdType: certificates,
  7604. IdCardNo: id_card,
  7605. BalanceAccountsType: settlementValue,
  7606. SocialType: social_type,
  7607. MedicalInsuranceNumber: medical_insurance_card,
  7608. RegisterType: register_type,
  7609. RegisterCost: registration_fee,
  7610. TreatmentCost: medical_expenses,
  7611. AdminUserId: adminInfo.AdminUser.Id,
  7612. UserOrgId: adminInfo.CurrentOrgId,
  7613. Status: 1,
  7614. RecordDate: recordDateTime,
  7615. IsReturn: 1,
  7616. PatientId: patient.ID,
  7617. Ctime: time.Now().Unix(),
  7618. Mtime: time.Now().Unix(),
  7619. Number: str,
  7620. IdCardType: id_card_type,
  7621. Departments: department,
  7622. Doctor: doctor,
  7623. PType: reg_type,
  7624. Diagnosis: diagnosis_ids,
  7625. SickType: sick_type,
  7626. }
  7627. service.CreateHisPatient(&hisPatient)
  7628. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7629. c.ServeSuccessJSON(map[string]interface{}{
  7630. "his_info": hisPatient,
  7631. })
  7632. } else {
  7633. //chrgBchno := rand.Intn(1000000) + 10000
  7634. var hisPatient models.XtHisPatient
  7635. hisPatient = models.XtHisPatient{
  7636. Name: name,
  7637. Age: age,
  7638. Gender: gender,
  7639. Birthday: birthUnix,
  7640. Phone: phone,
  7641. MedicalTreatmentType: medical_care,
  7642. IdType: certificates,
  7643. IdCardNo: id_card,
  7644. BalanceAccountsType: settlementValue,
  7645. SocialType: social_type,
  7646. MedicalInsuranceNumber: medical_insurance_card,
  7647. RegisterType: register_type,
  7648. RegisterCost: registration_fee,
  7649. TreatmentCost: medical_expenses,
  7650. AdminUserId: adminInfo.AdminUser.Id,
  7651. UserOrgId: adminInfo.CurrentOrgId,
  7652. Status: 1,
  7653. RecordDate: recordDateTime,
  7654. IsReturn: 1,
  7655. PatientId: patient.ID,
  7656. Ctime: time.Now().Unix(),
  7657. Mtime: time.Now().Unix(),
  7658. Number: str,
  7659. IdCardType: id_card_type,
  7660. Departments: department,
  7661. Doctor: doctor,
  7662. PType: reg_type,
  7663. Diagnosis: diagnosis_ids,
  7664. SickType: sick_type,
  7665. }
  7666. service.CreateHisPatient(&hisPatient)
  7667. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7668. c.ServeSuccessJSON(map[string]interface{}{
  7669. "his_info": hisPatient,
  7670. })
  7671. }
  7672. }
  7673. // 上传明细----结算
  7674. func (c *HisApiController) GetUploadInfo() {
  7675. id, _ := c.GetInt64("id")
  7676. record_time := c.GetString("record_time")
  7677. his_patient_id, _ := c.GetInt64("his_patient_id")
  7678. oth_desc := c.GetString("oth_desc")
  7679. pay_way, _ := c.GetInt64("pay_way")
  7680. pay_ways := c.GetString("pay_ways")
  7681. pay_price, _ := c.GetFloat("pay_price")
  7682. pay_card_no := c.GetString("pay_card_no")
  7683. discount_price, _ := c.GetFloat("discount_price")
  7684. preferential_price, _ := c.GetFloat("preferential_price")
  7685. reality_price, _ := c.GetFloat("reality_price")
  7686. found_price, _ := c.GetFloat("found_price")
  7687. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7688. private_price, _ := c.GetFloat("private_price")
  7689. timeLayout := "2006-01-02"
  7690. loc, _ := time.LoadLocation("Local")
  7691. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7692. fapiao_code := c.GetString("fapiao_code")
  7693. fapiao_number := c.GetString("fapiao_number")
  7694. diagnosis_id := c.GetString("diagnosis")
  7695. sick_type, _ := c.GetInt64("sick_type")
  7696. reg_type, _ := c.GetInt64("p_type")
  7697. order_id, _ := c.GetInt64("order_id")
  7698. cash_pay := c.GetString("cash_pay")
  7699. wechat_pay := c.GetString("wechat_pay")
  7700. ali_pay := c.GetString("ali_pay")
  7701. jifen_pay := c.GetString("jifen_pay")
  7702. band_card_pay := c.GetString("band_card_pay")
  7703. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7704. tmp_decimal := c.GetString("tmp_decimal")
  7705. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7706. var decimal float64 //本次使用的押金
  7707. var errmsg error
  7708. tx := service.XTWriteDB().Begin() //开了事务
  7709. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7710. defer func() {
  7711. if errmsg != nil {
  7712. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7713. tx.Rollback()
  7714. } else {
  7715. tx.Commit()
  7716. }
  7717. }()
  7718. fmt.Println("dec_way", dec_way)
  7719. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7720. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7721. return
  7722. }
  7723. if len(tmp_decimal) > 0 {
  7724. if tmp_decimal[0] == 45 {
  7725. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7726. return
  7727. }
  7728. }
  7729. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7730. fmt.Println(errs)
  7731. decimal = tt
  7732. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7733. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7735. if err != nil {
  7736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7737. return
  7738. }
  7739. recordDateTime := theTime.Unix()
  7740. adminUser := c.GetAdminUserInfo()
  7741. var prescriptions []*models.HisPrescription
  7742. var prescriptionsOne []*models.HisPrescription
  7743. var start_time int64
  7744. var end_time int64
  7745. ids_str := c.GetString("ids")
  7746. ids_arr := strings.Split(ids_str, ",")
  7747. if tempOrder.ID == 0 {
  7748. if settle_accounts_type == 1 { //日结
  7749. fmt.Println(reg_type)
  7750. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7751. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7752. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7753. } else {
  7754. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7755. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7756. }
  7757. } else { //月结
  7758. start_time_str := c.GetString("start_time")
  7759. end_time_str := c.GetString("end_time")
  7760. timeLayout := "2006-01-02"
  7761. loc, _ := time.LoadLocation("Local")
  7762. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7763. if err != nil {
  7764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7765. return
  7766. }
  7767. recordStartTime := theStartTime.Unix()
  7768. start_time = recordStartTime
  7769. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7770. if err != nil {
  7771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7772. return
  7773. }
  7774. recordEndTime := theEndTime.Unix()
  7775. end_time = recordEndTime
  7776. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7777. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7778. }
  7779. var goods []*models.DialysisBeforePrepareGoods
  7780. var newGoods []*models.NewDialysisBeforePrepareGoods
  7781. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7782. var infos []*models.HisDoctorAdviceInfo
  7783. var infoList []*models.HisDoctorAdviceInfo
  7784. var hisAdvice []*models.HisDoctorAdviceInfo
  7785. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7786. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7787. //判断库存不足
  7788. //结算出库开关
  7789. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7790. if settConfig.IsOpen == 1 {
  7791. //判断库存的地方
  7792. for _, info := range prescriptions {
  7793. if info.Type == 1 {
  7794. infos = append(infos, info.HisDoctorAdviceInfo...)
  7795. }
  7796. if info.Type == 2 {
  7797. for _, sumItem := range info.HisPrescriptionProject {
  7798. if sumItem.Type == 3 {
  7799. var good models.DialysisBeforePrepareGoods
  7800. var newGood models.NewDialysisBeforePrepareGoods
  7801. good.GoodId = sumItem.GoodInfo.ID
  7802. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7803. count, _ := strconv.Atoi(sumItem.Count)
  7804. good.Count = int64(count)
  7805. good.StorehouseId = houseConfig.StorehouseOutInfo
  7806. good.ProjectId = sumItem.ID
  7807. goods = append(goods, &good)
  7808. newGood.GoodId = sumItem.GoodInfo.ID
  7809. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7810. count2, _ := strconv.Atoi(sumItem.Count)
  7811. newGood.Count = int64(count2)
  7812. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7813. newGood.ProjectId = sumItem.ID
  7814. newGoods = append(newGoods, &newGood)
  7815. }
  7816. }
  7817. }
  7818. }
  7819. for _, info := range prescriptionsOne {
  7820. if info.Type == 1 {
  7821. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7822. }
  7823. if info.Type == 2 {
  7824. for _, sumItem := range info.HisPrescriptionProject {
  7825. if sumItem.Type == 3 {
  7826. var newGood models.NewDialysisBeforePrepareGoods
  7827. newGood.GoodId = sumItem.GoodInfo.ID
  7828. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7829. count2, _ := strconv.Atoi(sumItem.Count)
  7830. newGood.Count = int64(count2)
  7831. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7832. newGood.ProjectId = sumItem.ID
  7833. newGoodOne = append(newGoodOne, &newGood)
  7834. }
  7835. }
  7836. }
  7837. }
  7838. //判断
  7839. for _, itemOne := range infos {
  7840. for _, itemTwo := range hisAdvice {
  7841. if itemOne.DrugId == itemTwo.DrugId {
  7842. itemTwo.Child = append(itemTwo.Child, itemOne)
  7843. }
  7844. }
  7845. }
  7846. for _, itemTwo := range hisAdvice {
  7847. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7848. var sum_out_count int64
  7849. for _, itemThree := range itemTwo.Child {
  7850. var prescribing_number int64
  7851. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7852. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7853. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7854. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7855. }
  7856. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7857. prescribing_number = parseIntPrescribingNumber
  7858. }
  7859. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7860. prescribing_number = parseIntPrescribingNumber
  7861. }
  7862. sum_out_count += prescribing_number
  7863. }
  7864. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7865. if sum_out_count > drugStockOut.FlushCount {
  7866. c.ServeSuccessJSON(map[string]interface{}{
  7867. "msg": "2",
  7868. "drug": medical,
  7869. })
  7870. return
  7871. }
  7872. }
  7873. for _, itemOne := range newGoods {
  7874. for _, item := range newGoodOne {
  7875. if itemOne.GoodId == item.GoodId {
  7876. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7877. }
  7878. }
  7879. }
  7880. for _, item := range newGoodOne {
  7881. var sum_out_count_one int64
  7882. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7883. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7884. sum_out_count_one += itemOne.Count
  7885. }
  7886. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7887. fmt.Println("sum_out_count_one", sum_out_count_one)
  7888. fmt.Println("list.FlushCount", list.FlushCount)
  7889. if sum_out_count_one > list.FlushCount {
  7890. c.ServeSuccessJSON(map[string]interface{}{
  7891. "msg": "3",
  7892. "good": good,
  7893. })
  7894. return
  7895. }
  7896. }
  7897. }
  7898. timestamp := time.Now().Unix()
  7899. tempTime := time.Unix(timestamp, 0)
  7900. timeFormat := tempTime.Format("20060102150405")
  7901. chrgBchno := rand.Intn(100000) + 10000
  7902. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7903. strconv.FormatInt(his.PatientId, 10)
  7904. var ids []int64
  7905. for _, item := range prescriptions {
  7906. ids = append(ids, item.ID)
  7907. }
  7908. var total float64
  7909. for _, item := range prescriptions {
  7910. fmt.Println(item)
  7911. if item.Type == 1 { //药品
  7912. for _, subItem := range item.HisDoctorAdviceInfo {
  7913. total = total + (subItem.Price * subItem.PrescribingNumber)
  7914. }
  7915. }
  7916. if item.Type == 2 { //项目
  7917. for _, subItem := range item.HisPrescriptionProject {
  7918. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7919. total = total + (subItem.Price * cnt)
  7920. }
  7921. }
  7922. for _, subItem := range item.HisAdditionalCharge {
  7923. total = total + (subItem.Price * float64(subItem.Count))
  7924. }
  7925. }
  7926. if reg_type == 1111 || reg_type == 1112 {
  7927. reg_type = 11
  7928. }
  7929. tm := time.Unix(time.Now().Unix(), 0)
  7930. allTotal := fmt.Sprintf("%.4f", total)
  7931. totals, _ := strconv.ParseFloat(allTotal, 64)
  7932. order := &models.HisOrder{
  7933. UserOrgId: adminUser.CurrentOrgId,
  7934. HisPatientId: his.ID,
  7935. PatientId: id,
  7936. SettleAccountsDate: recordDateTime,
  7937. Ctime: time.Now().Unix(),
  7938. Mtime: time.Now().Unix(),
  7939. Status: 1,
  7940. OrderStatus: 2,
  7941. MdtrtId: his.Number,
  7942. Number: chrg_bchno,
  7943. MedfeeSumamt: totals,
  7944. PayWay: pay_way,
  7945. PayWays: pay_ways,
  7946. PayPrice: pay_price,
  7947. MedType: strconv.Itoa(int(reg_type)),
  7948. PayCardNo: pay_card_no,
  7949. DiscountPrice: discount_price,
  7950. PreferentialPrice: preferential_price,
  7951. RealityPrice: reality_price,
  7952. FoundPrice: found_price,
  7953. MedicalInsurancePrice: medical_insurance_price,
  7954. PrivatePrice: private_price,
  7955. SettleEndTime: end_time,
  7956. SettleStartTime: start_time,
  7957. PsnPartAmt: totals,
  7958. PsnCashPay: totals,
  7959. SettleType: settle_accounts_type,
  7960. FaPiaoCode: fapiao_code,
  7961. FaPiaoNumber: fapiao_number,
  7962. Diagnosis: diagnosis_id,
  7963. PType: 2,
  7964. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7965. Decimal: decimal,
  7966. OthDesc: oth_desc,
  7967. CashPay: cash_pay,
  7968. WechatPay: wechat_pay,
  7969. AliPay: ali_pay,
  7970. JifenPay: jifen_pay,
  7971. BandCardPay: band_card_pay,
  7972. Creator: adminUser.AdminUser.Id,
  7973. }
  7974. err = service.CreateOrderTX(order, tx)
  7975. if err != nil {
  7976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7977. return
  7978. }
  7979. var customs []*Custom
  7980. for _, item := range prescriptions {
  7981. if item.Type == 1 { //药品a
  7982. for _, subItem := range item.HisDoctorAdviceInfo {
  7983. cus := &Custom{
  7984. AdviceId: subItem.ID,
  7985. ProjectId: 0,
  7986. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7987. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7988. FeedetlSn: subItem.FeedetlSn,
  7989. Price: fmt.Sprintf("%.4f", subItem.Price),
  7990. MedListCodg: subItem.MedListCodg,
  7991. Type: 1,
  7992. }
  7993. customs = append(customs, cus)
  7994. }
  7995. }
  7996. if item.Type == 2 { //项目
  7997. for _, subItem := range item.HisPrescriptionProject {
  7998. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7999. cus := &Custom{
  8000. AdviceId: 0,
  8001. ProjectId: subItem.ID,
  8002. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8003. Cut: fmt.Sprintf("%.4f", cnt),
  8004. FeedetlSn: subItem.FeedetlSn,
  8005. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8006. MedListCodg: subItem.MedListCodg,
  8007. Type: 2,
  8008. }
  8009. customs = append(customs, cus)
  8010. }
  8011. }
  8012. for _, item := range item.HisAdditionalCharge {
  8013. cus := &Custom{
  8014. ItemId: item.ID,
  8015. AdviceId: 0,
  8016. ProjectId: 0,
  8017. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8018. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8019. FeedetlSn: item.FeedetlSn,
  8020. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8021. MedListCodg: item.XtHisAddtionConfig.Code,
  8022. Type: 3,
  8023. }
  8024. customs = append(customs, cus)
  8025. }
  8026. }
  8027. for _, item := range customs {
  8028. var advice_id int64 = 0
  8029. var project_id int64 = 0
  8030. var item_id int64 = 0
  8031. var types int64 = 0
  8032. if item.Type == 1 {
  8033. advice_id = item.AdviceId
  8034. project_id = 0
  8035. item_id = 0
  8036. } else if item.Type == 2 {
  8037. advice_id = 0
  8038. item_id = 0
  8039. project_id = item.ProjectId
  8040. } else if item.Type == 3 {
  8041. advice_id = 0
  8042. item_id = item.ItemId
  8043. project_id = 0
  8044. }
  8045. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8046. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8047. pric, _ := strconv.ParseFloat(item.Price, 32)
  8048. info := &models.HisOrderInfo{
  8049. OrderNumber: order.Number,
  8050. UploadDate: time.Now().Unix(),
  8051. AdviceId: advice_id,
  8052. DetItemFeeSumamt: detItemFeeSumamt,
  8053. Cnt: cut,
  8054. Pric: pric,
  8055. PatientId: id,
  8056. Status: 1,
  8057. Mtime: time.Now().Unix(),
  8058. Ctime: time.Now().Unix(),
  8059. UserOrgId: adminUser.CurrentOrgId,
  8060. HisPatientId: his.ID,
  8061. OrderId: order.ID,
  8062. ProjectId: project_id,
  8063. Type: types,
  8064. ItemId: item_id,
  8065. }
  8066. service.CreateOrderInfoTX(info, tx)
  8067. }
  8068. his.Diagnosis = diagnosis_id
  8069. his.SickType = sick_type
  8070. his.RegisterType = reg_type
  8071. his.MedicalTreatmentType = reg_type
  8072. service.UpdataHisPateintTX(&his, tx)
  8073. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8074. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8075. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8076. //判断是否使用了押金
  8077. if dec_way == "true" {
  8078. tmpstring := strconv.FormatInt(order.ID, 10)
  8079. //扣押金
  8080. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8081. order.Decimal = decimal
  8082. service.UpDateOrderTwo(order, tx)
  8083. if errmsg != nil {
  8084. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8085. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8086. return
  8087. }
  8088. }
  8089. if err == nil {
  8090. for _, info := range prescriptions {
  8091. if info.Type == 1 {
  8092. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8093. }
  8094. if info.Type == 2 {
  8095. for _, sumItem := range info.HisPrescriptionProject {
  8096. if sumItem.Type == 3 {
  8097. var good models.DialysisBeforePrepareGoods
  8098. var newGood models.NewDialysisBeforePrepareGoods
  8099. var oldGood models.OldDialysisBeforePrepareGoods
  8100. good.GoodId = sumItem.GoodInfo.ID
  8101. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8102. count, _ := strconv.Atoi(sumItem.Count)
  8103. good.Count = int64(count)
  8104. good.StorehouseId = houseConfig.StorehouseOutInfo
  8105. good.ProjectId = sumItem.ID
  8106. good.PatientId = sumItem.PatientId
  8107. goods = append(goods, &good)
  8108. newGood.GoodId = sumItem.GoodInfo.ID
  8109. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8110. count2, _ := strconv.Atoi(sumItem.Count)
  8111. newGood.Count = int64(count2)
  8112. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8113. newGood.ProjectId = sumItem.ID
  8114. newGood.PatientId = sumItem.HisPatientId
  8115. newGoods = append(newGoods, &newGood)
  8116. oldGood.GoodId = sumItem.GoodInfo.ID
  8117. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8118. count3, _ := strconv.Atoi(sumItem.Count)
  8119. oldGood.Count = int64(count3)
  8120. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8121. oldGood.ProjectId = sumItem.ID
  8122. oldGood.RecordDate = sumItem.RecordDate
  8123. oldGood.PatientId = sumItem.HisPatientId
  8124. oldGoods = append(oldGoods, &oldGood)
  8125. }
  8126. }
  8127. }
  8128. }
  8129. if settConfig.IsOpen == 1 {
  8130. for _, item := range infoList {
  8131. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8132. if medical.IsUse == 2 {
  8133. //药品出库
  8134. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8135. //查询默认仓库
  8136. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8137. //查询默认仓库剩余多少库存
  8138. var sum_count int64
  8139. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8140. for _, its := range stockInfo {
  8141. if its.MaxUnit == medical.MaxUnit {
  8142. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8143. }
  8144. sum_count += its.StockMaxNumber + its.StockMinNumber
  8145. }
  8146. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8147. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8148. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8149. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8150. }
  8151. }
  8152. orgId := c.GetAdminUserInfo().CurrentOrgId
  8153. if len(oldGoods) > 0 {
  8154. timeStr := time.Now().Format("2006-01-02")
  8155. timeArr := strings.Split(timeStr, "-")
  8156. total, _ := service.FindAllWarehouseOut(orgId)
  8157. total = total + 1
  8158. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8159. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8160. number = number + total
  8161. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8162. operation_time := time.Now().Unix()
  8163. creater := c.GetAdminUserInfo().AdminUser.Id
  8164. //查询默认出库仓库库存
  8165. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8166. recordDateStr := time.Now().Format("2006-01-02")
  8167. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8168. nowtime := recordDate.Unix()
  8169. warehouseOut := models.WarehouseOut{
  8170. WarehouseOutOrderNumber: warehousing_out_order,
  8171. OperationTime: operation_time,
  8172. OrgId: orgId,
  8173. Creater: creater,
  8174. Ctime: time.Now().Unix(),
  8175. Status: 1,
  8176. WarehouseOutTime: nowtime,
  8177. Type: 1,
  8178. StorehouseId: storeConfig.StorehouseOutInfo,
  8179. IsCheck: 1,
  8180. OrderId: order.ID,
  8181. IsSys: 5,
  8182. }
  8183. //查询是否生成出库单
  8184. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8185. if out.ID == 0 {
  8186. service.AddSigleWarehouseOut(&warehouseOut)
  8187. }
  8188. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8189. for _, item := range oldGoods {
  8190. dialyPrepareOne := models.DialysisBeforePrepare{
  8191. GoodTypeId: item.GoodTypeId,
  8192. GoodId: item.GoodId,
  8193. PatientId: his.PatientId,
  8194. RecordDate: item.RecordDate,
  8195. UserOrgId: adminUser.CurrentOrgId,
  8196. Count: item.Count,
  8197. Ctime: time.Now().Unix(),
  8198. Creater: adminUser.AdminUser.Id,
  8199. CommdityCode: item.CommdityCode,
  8200. Status: 1,
  8201. StorehouseId: houseConfig.StorehouseOutInfo,
  8202. }
  8203. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8204. //非零用
  8205. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8206. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8207. //查询剩余库存
  8208. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8209. var sum_count int64
  8210. for _, item := range goodList {
  8211. sum_count += item.StockCount
  8212. }
  8213. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8214. //耗材
  8215. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8216. }
  8217. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8218. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8219. //查询剩余库存
  8220. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8221. var sum_count int64
  8222. for _, item := range goodList {
  8223. sum_count += item.StockCount
  8224. }
  8225. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8226. //耗材
  8227. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8228. }
  8229. }
  8230. }
  8231. }
  8232. c.ServeSuccessJSON(map[string]interface{}{
  8233. "msg": "结算成功",
  8234. })
  8235. }
  8236. }
  8237. }
  8238. // 退款
  8239. func (c *HisApiController) Refund() {
  8240. order_id, _ := c.GetInt64("order_id")
  8241. order, _ := service.GetHisOrderByID(order_id)
  8242. adminUser := c.GetAdminUserInfo()
  8243. orgid := c.GetAdminUserInfo().CurrentOrgId
  8244. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8245. if err != nil {
  8246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8247. return
  8248. }
  8249. tmp := strconv.FormatInt(order.ID, 10)
  8250. //当押金不为零时产生退费记录
  8251. if order.Decimal != 0 {
  8252. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8253. if err != nil {
  8254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8255. return
  8256. }
  8257. }
  8258. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8259. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8260. var goods []*models.DialysisBeforePrepareGoods
  8261. var newGoods []*models.NewDialysisBeforePrepareGoods
  8262. var infos []*models.HisDoctorAdviceInfo
  8263. for _, info := range orders {
  8264. if info.AdviceId > 0 && info.ProjectId == 0 {
  8265. infos = append(infos, &info.HisDoctorAdviceInfo)
  8266. }
  8267. if info.ProjectId > 0 && info.AdviceId == 0 {
  8268. if info.HisPrescriptionProject.Type == 3 {
  8269. var good models.DialysisBeforePrepareGoods
  8270. var newGood models.NewDialysisBeforePrepareGoods
  8271. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8272. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8273. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8274. good.Count = int64(count)
  8275. good.StorehouseId = houseConfig.StorehouseOutInfo
  8276. good.ProjectId = info.HisPrescriptionProject.ID
  8277. good.PatientId = info.PatientId
  8278. good.OrderId = order_id
  8279. goods = append(goods, &good)
  8280. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8281. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8282. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8283. newGood.Count = int64(count2)
  8284. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8285. newGood.ProjectId = info.HisPrescriptionProject.ID
  8286. newGood.RecordDate = order.SettleAccountsDate
  8287. newGood.UserOrgId = order.UserOrgId
  8288. newGood.PatientId = info.PatientId
  8289. newGood.OrderId = order_id
  8290. newGoods = append(newGoods, &newGood)
  8291. }
  8292. }
  8293. }
  8294. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8295. if settConfig.IsOpen == 1 {
  8296. for _, item := range infos {
  8297. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8298. }
  8299. for _, item := range newGoods {
  8300. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8301. }
  8302. }
  8303. c.ServeSuccessJSON(map[string]interface{}{
  8304. "msg": "退费成功",
  8305. })
  8306. }
  8307. func (c *HisApiController) RefundNumber() {
  8308. his_patient_id, _ := c.GetInt64("id")
  8309. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8310. info.Status = 0
  8311. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8312. if count > 0 {
  8313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8314. return
  8315. }
  8316. err := service.SaveHisPatient(info)
  8317. if err == nil {
  8318. c.ServeSuccessJSON(map[string]interface{}{
  8319. "msg": "退号成功",
  8320. })
  8321. } else {
  8322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8323. return
  8324. }
  8325. }
  8326. func (this *HisApiController) AdditionalCharge() {
  8327. dataBody := make(map[string]interface{}, 0)
  8328. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8329. fmt.Println(err)
  8330. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8331. patient_id := int64(dataBody["patient_id"].(float64))
  8332. medicineData, _ := dataBody["medicineData"].([]interface{})
  8333. adminUserInfo := this.GetAdminUserInfo()
  8334. orgId := adminUserInfo.CurrentOrgId
  8335. admin_user_id := adminUserInfo.AdminUser.Id
  8336. timeStr := time.Now().Format("2006-01-02")
  8337. timeLayout := "2006-01-02 15:04:05"
  8338. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8339. timenow := timeStringToTime.Unix()
  8340. var additionalCharges []*models.HisAdditionalCharge
  8341. for _, item := range medicineData {
  8342. var randNum int
  8343. randNum = rand.Intn(10000) + 1000
  8344. timestamp := time.Now().Unix()
  8345. tempTime := time.Unix(timestamp, 0)
  8346. timeFormat := tempTime.Format("20060102150405")
  8347. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8348. items := item.(map[string]interface{})
  8349. money := items["price"].(string)
  8350. item_id_str := items["item_id"].(string)
  8351. name := items["name"].(string)
  8352. id_str := items["id"].(string)
  8353. moneys, _ := strconv.ParseInt(money, 10, 64)
  8354. monStr := strconv.FormatInt(moneys, 10)
  8355. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8356. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8357. id, _ := strconv.ParseInt(id_str, 10, 64)
  8358. additionalCharge := &models.HisAdditionalCharge{
  8359. ID: id,
  8360. HisPatientId: his_patient_id,
  8361. UserOrgId: orgId,
  8362. PatientId: patient_id,
  8363. RecordDate: timenow,
  8364. Price: monneyStr,
  8365. Status: 1,
  8366. ItemName: name,
  8367. ItemId: item_id,
  8368. AdminUserId: admin_user_id,
  8369. CreatedTime: time.Now().Unix(),
  8370. OrderStatus: 0,
  8371. PrescriptionNumber: "",
  8372. BatchNumber: "",
  8373. FeedetlSn: p_number,
  8374. }
  8375. service.CreateAdditionalCharge(additionalCharge)
  8376. additionalCharges = append(additionalCharges, additionalCharge)
  8377. }
  8378. this.ServeSuccessJSON(map[string]interface{}{
  8379. "msg": "添加成功",
  8380. "additional_charges": additionalCharges,
  8381. })
  8382. }
  8383. func (this *HisApiController) DeleteAddition() {
  8384. id, _ := this.GetInt64("id")
  8385. //TODO 需要判断是否已经结算
  8386. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8387. if err == nil {
  8388. this.ServeSuccessJSON(map[string]interface{}{
  8389. "msg": "删除成功",
  8390. })
  8391. return
  8392. } else {
  8393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8394. return
  8395. }
  8396. }
  8397. func (this *HisApiController) GetAdminUsers() {
  8398. adminUser := this.GetAdminUserInfo()
  8399. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8400. this.ServeSuccessJSON(map[string]interface{}{
  8401. "doctors": doctors,
  8402. })
  8403. }
  8404. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8405. change_type, _ := this.GetInt64("type", 0)
  8406. record_date := this.GetString("record_time")
  8407. patient_id, _ := this.GetInt64("patient_id", 0)
  8408. p_type, _ := this.GetInt64("p_type", 0)
  8409. timeLayout := "2006-01-02"
  8410. loc, _ := time.LoadLocation("Local")
  8411. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8412. record_time := theAdviceRecordTime.Unix()
  8413. adminUserInfo := this.GetAdminUserInfo()
  8414. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8415. if err == nil {
  8416. if len(prescriptions) == 0 {
  8417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8418. return
  8419. } else {
  8420. this.ServeSuccessJSON(map[string]interface{}{
  8421. "prescriptions": prescriptions,
  8422. })
  8423. return
  8424. }
  8425. } else {
  8426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8427. return
  8428. }
  8429. }
  8430. func (this *HisApiController) GetCallHisPrescription() {
  8431. patient_id, _ := this.GetInt64("patient_id", 0)
  8432. timeLayout := "2006-01-02"
  8433. loc, _ := time.LoadLocation("Local")
  8434. start_time := this.GetString("start_time")
  8435. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8436. end_time := this.GetString("end_time")
  8437. p_type, _ := this.GetInt64("p_type")
  8438. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8439. adminUserInfo := this.GetAdminUserInfo()
  8440. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8441. if err == nil {
  8442. this.ServeSuccessJSON(map[string]interface{}{
  8443. "prescriptions": prescriptions,
  8444. })
  8445. return
  8446. } else {
  8447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8448. return
  8449. }
  8450. }
  8451. func (this *HisApiController) GetHisDayPrescription() {
  8452. timeLayout := "2006-01-02"
  8453. loc, _ := time.LoadLocation("Local")
  8454. start_time := this.GetString("start_time")
  8455. patient_id, _ := this.GetInt64("patient_id", 0)
  8456. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8457. end_time := this.GetString("end_time")
  8458. p_type, _ := this.GetInt64("p_type")
  8459. order_status, _ := this.GetInt64("type")
  8460. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8461. adminUserInfo := this.GetAdminUserInfo()
  8462. var dayHisPrescription []*models.HisPrescription
  8463. var err error
  8464. if order_status == 1 || order_status == 0 {
  8465. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8466. } else if order_status == 2 {
  8467. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8468. }
  8469. var settle_total float64
  8470. for _, item := range dayHisPrescription {
  8471. if len(item.HisPrescriptionProject) > 0 {
  8472. for _, subItem := range item.HisPrescriptionProject {
  8473. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8474. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8475. settle_total = settle_total + total
  8476. }
  8477. }
  8478. if len(item.HisDoctorAdviceInfo) > 0 {
  8479. for _, subItem := range item.HisDoctorAdviceInfo {
  8480. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8481. settle_total = settle_total + total
  8482. }
  8483. }
  8484. }
  8485. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8486. if err == nil {
  8487. this.ServeSuccessJSON(map[string]interface{}{
  8488. "day_prescription": dayHisPrescription,
  8489. "settle_total": settle_total,
  8490. })
  8491. return
  8492. } else {
  8493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8494. return
  8495. }
  8496. }
  8497. func (c *HisApiController) GetHisChargePatientList() {
  8498. record_date := c.GetString("record_date")
  8499. order_status, _ := c.GetInt64("type")
  8500. sch_type, _ := c.GetInt64("sch_type")
  8501. timeLayout := "2006-01-02"
  8502. loc, _ := time.LoadLocation("Local")
  8503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8504. if err != nil {
  8505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8506. return
  8507. }
  8508. recordDateTime := theTime.Unix()
  8509. adminInfo := c.GetAdminUserInfo()
  8510. var tempPatients []*service.NewTempPatients
  8511. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8512. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8513. if order_status != 2 {
  8514. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8515. } else {
  8516. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8517. }
  8518. } else {
  8519. if order_status != 2 {
  8520. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8521. } else {
  8522. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8523. }
  8524. }
  8525. var patients []*service.NewTempPatients
  8526. var patients_two []*service.NewTempPatients
  8527. for _, item := range tempPatients {
  8528. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8529. //过滤掉没挂号的和没开处方的
  8530. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8531. patients = append(patients, item)
  8532. }
  8533. //过滤掉没挂号的
  8534. if len(item.HisPatient) > 0 {
  8535. patients_two = append(patients_two, item)
  8536. }
  8537. } else {
  8538. if len(item.HisPrescription) > 0 {
  8539. patients = append(patients, item)
  8540. }
  8541. }
  8542. }
  8543. c.ServeSuccessJSON(map[string]interface{}{
  8544. "list": patients,
  8545. "list_two": patients_two,
  8546. })
  8547. }
  8548. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8549. record_date := c.GetString("record_date")
  8550. timeLayout := "2006-01-02"
  8551. loc, _ := time.LoadLocation("Local")
  8552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8553. if err != nil {
  8554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8555. return
  8556. }
  8557. recordDateTime := theTime.Unix()
  8558. adminUser := c.GetAdminUserInfo()
  8559. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8560. var patients []*service.Patients
  8561. for _, item := range tempPatients {
  8562. if item.HisPatient.ID == 0 {
  8563. patients = append(patients, item)
  8564. }
  8565. }
  8566. c.ServeSuccessJSON(map[string]interface{}{
  8567. "list": patients,
  8568. //"list_two": patients_two,
  8569. })
  8570. }
  8571. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8572. newArr = make([]*service.Patients, 0)
  8573. for i := 0; i < len(patient); i++ {
  8574. repeat := false
  8575. for j := i + 1; j < len(patient); j++ {
  8576. if patient[i].ID == patient[j].ID {
  8577. repeat = true
  8578. break
  8579. }
  8580. }
  8581. if !repeat {
  8582. newArr = append(newArr, patient[i])
  8583. }
  8584. }
  8585. return
  8586. }
  8587. func (c *HisApiController) GetHisChargePatientInfo() {
  8588. patient_id, _ := c.GetInt64("patient_id")
  8589. his_patient_id, _ := c.GetInt64("his_patient_id")
  8590. record_date := c.GetString("record_date")
  8591. //start_time := c.GetString("start_time")
  8592. //end_time := c.GetString("end_time")
  8593. order_status, _ := c.GetInt64("type", 0)
  8594. p_type, _ := c.GetInt64("p_type", 0)
  8595. order_id, _ := c.GetInt64("order_id", 0)
  8596. timeLayout := "2006-01-02"
  8597. loc, _ := time.LoadLocation("Local")
  8598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8599. if err != nil {
  8600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8601. return
  8602. }
  8603. recordDateTime := theTime.Unix()
  8604. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8605. //if err != nil {
  8606. //
  8607. //}
  8608. //startRecordDateTime := startTime.Unix()
  8609. //
  8610. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8611. //if err != nil {
  8612. //
  8613. //}
  8614. //endRecordDateTime := endTime.Unix()
  8615. admin := c.GetAdminUserInfo()
  8616. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8617. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8618. var prescriptions []*models.HisPrescription
  8619. //var unChargeMonthPrescriptions []*models.HisPrescription
  8620. order, _ := service.GetHisOrderByID(order_id)
  8621. if order_status == 1 || order_status == 0 {
  8622. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8623. } else if order_status == 2 {
  8624. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8625. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8626. }
  8627. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8628. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8629. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8630. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8631. //获取所有科室信息
  8632. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8633. c.ServeSuccessJSON(map[string]interface{}{
  8634. "his_info": his_patient_info,
  8635. "xt_info": xt_patient_info,
  8636. "prescription": prescriptions,
  8637. "case_history": case_history,
  8638. "info": patientPrescriptionInfo,
  8639. "last_info": lastPatientPrescriptionInfo,
  8640. "order": order,
  8641. "doctors": doctors,
  8642. "department": department,
  8643. })
  8644. return
  8645. }
  8646. func (c *HisApiController) GetAllOrderDetail() {
  8647. order_id, _ := c.GetInt64("id", 0)
  8648. order, _ := service.GetHisOrderByID(order_id)
  8649. if order.ID == 0 {
  8650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8651. return
  8652. }
  8653. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8654. org_id := c.GetAdminUserInfo().CurrentOrgId
  8655. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8656. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8657. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8658. c.ServeSuccessJSON(map[string]interface{}{
  8659. "order": order,
  8660. "order_info": order_info,
  8661. "patient": patient,
  8662. "admin_info": adminInfo,
  8663. "hospital_record": record,
  8664. })
  8665. return
  8666. }
  8667. func (c *HisApiController) GetAllOrderDetailCollect() {
  8668. order_id, _ := c.GetInt64("id", 0)
  8669. order, _ := service.GetHisOrderByID(order_id)
  8670. if order.ID == 0 {
  8671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8672. return
  8673. }
  8674. org_id := c.GetAdminUserInfo().CurrentOrgId
  8675. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8676. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8677. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8678. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8679. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8680. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8681. var bedCostTotal float64 = 0 //床位总费
  8682. //var bedCostSelfTotal float64 = 0 //床位自费
  8683. var operationCostTotal float64 = 0 //手术费
  8684. //var operationCostSelfTotal float64 = 0 //手术费
  8685. var otherCostTotal float64 = 0 //其他费用
  8686. //var otherCostSelfTotal float64 = 0 //其他费用
  8687. var materialCostTotal float64 = 0 //材料费
  8688. //var materialCostSelfTotal float64 = 0 //材料费
  8689. var westernMedicineCostTotal float64 = 0 //西药费
  8690. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8691. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8692. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8693. var checkCostTotal float64 = 0 //检查费
  8694. //var checkCostSelfTotal float64 = 0 //检查费
  8695. var laboratoryCostTotal float64 = 0 //化验费
  8696. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8697. var treatCostTotal float64 = 0 //治疗费用
  8698. //var treatCostSelfTotal float64 = 0 //治疗费用
  8699. var zhenChaCostTotal float64 = 0 //其他费用
  8700. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8701. decimal.DivisionPrecision = 2
  8702. var BalanceAccountsType int64
  8703. if his.ID > 0 {
  8704. BalanceAccountsType = his.BalanceAccountsType
  8705. } else {
  8706. BalanceAccountsType = record.BalanceAccountsType
  8707. }
  8708. if BalanceAccountsType != 2 {
  8709. for _, item := range order_info {
  8710. if org_id == 10215 {
  8711. if item.MedChrgitmType == "01" { //床位费
  8712. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8713. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8714. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8715. }
  8716. if item.MedChrgitmType == "02" { //诊察费
  8717. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8718. //zhenChaCostSelfTotal = zhenChaCostTotal
  8719. }
  8720. if item.MedChrgitmType == "03" { //检查费
  8721. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8722. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8723. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8724. }
  8725. //if item.MedChrgitmType == "02" { //检查费
  8726. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8727. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8728. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8729. //}
  8730. if item.MedChrgitmType == "04" { //化验费
  8731. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8732. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8733. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8734. }
  8735. if item.MedChrgitmType == "05" { //治疗费
  8736. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8737. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8738. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8739. }
  8740. if item.MedChrgitmType == "06" { //手术费
  8741. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8742. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8743. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8744. }
  8745. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8746. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8747. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8748. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8749. }
  8750. if item.MedChrgitmType == "09" { //西药费
  8751. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8752. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8753. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8754. }
  8755. if item.MedChrgitmType == "11" { //中成费
  8756. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8757. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8758. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8759. }
  8760. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8761. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8762. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8763. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8764. }
  8765. } else if org_id == 10188 || org_id == 10217 {
  8766. if item.MedChrgitmType == "01" { //床位费
  8767. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8768. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8769. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8770. }
  8771. if item.MedChrgitmType == "02" { //诊察费
  8772. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8773. //zhenChaCostSelfTotal = zhenChaCostTotal
  8774. }
  8775. if item.MedChrgitmType == "03" { //检查费
  8776. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8777. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8778. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8779. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8780. }
  8781. //if item.MedChrgitmType == "02" { //检查费
  8782. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8783. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8784. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8785. //}
  8786. if item.MedChrgitmType == "04" { //化验费
  8787. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8788. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8789. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8790. }
  8791. if item.MedChrgitmType == "05" { //治疗费
  8792. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8793. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8794. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8795. }
  8796. if item.MedChrgitmType == "06" { //手术费
  8797. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8798. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8799. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8800. }
  8801. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8802. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8803. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8804. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8805. }
  8806. if item.MedChrgitmType == "09" { //西药费
  8807. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8808. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8809. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8810. }
  8811. if item.MedChrgitmType == "11" { //中成费
  8812. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8813. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8814. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8815. }
  8816. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8817. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8818. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8819. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8820. }
  8821. } else {
  8822. if item.MedChrgitmType == "01" { //床位费
  8823. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8824. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8825. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8826. }
  8827. //if item.MedChrgitmType == "02" { //诊察费
  8828. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8829. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8830. //}
  8831. if item.MedChrgitmType == "03" { //检查费
  8832. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8833. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8834. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8835. }
  8836. //if item.MedChrgitmType == "02" { //检查费
  8837. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8838. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8839. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8840. //}
  8841. if item.MedChrgitmType == "04" { //化验费
  8842. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8843. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8844. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8845. }
  8846. if item.MedChrgitmType == "05" { //治疗费
  8847. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8848. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8849. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8850. }
  8851. if item.MedChrgitmType == "06" { //手术费
  8852. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8853. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8854. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8855. }
  8856. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8857. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8858. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8859. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8860. }
  8861. if item.MedChrgitmType == "09" { //西药费
  8862. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8863. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8864. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8865. }
  8866. if item.MedChrgitmType == "11" { //中成费
  8867. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8868. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8869. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8870. }
  8871. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8872. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8873. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8874. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8875. }
  8876. }
  8877. }
  8878. c.ServeSuccessJSON(map[string]interface{}{
  8879. "order": order,
  8880. "order_info": order_info,
  8881. "patient": patient,
  8882. "admin_info": adminInfo,
  8883. "his_hospital": record,
  8884. "bedCostTotal": bedCostTotal,
  8885. "operationCostTotal": operationCostTotal,
  8886. "otherCostTotal": otherCostTotal,
  8887. "materialCostTotal": materialCostTotal,
  8888. "westernMedicineCostTotal": westernMedicineCostTotal,
  8889. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8890. "checkCostTotal": checkCostTotal,
  8891. "zhenChaCostTotal": zhenChaCostTotal,
  8892. "laboratoryCostTotal": laboratoryCostTotal,
  8893. "treatCostTotal": treatCostTotal,
  8894. })
  8895. } else {
  8896. for _, item := range order_info {
  8897. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8898. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8899. item.MedChrgitmType = "09"
  8900. }
  8901. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8902. if item.HisPrescriptionProject.Type == 2 {
  8903. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8904. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8905. case 0:
  8906. item.MedChrgitmType = "0"
  8907. break
  8908. case 1:
  8909. item.MedChrgitmType = "14"
  8910. break
  8911. case 2:
  8912. item.MedChrgitmType = "05"
  8913. break
  8914. case 3:
  8915. item.MedChrgitmType = "03"
  8916. break
  8917. case 4:
  8918. item.MedChrgitmType = "03"
  8919. break
  8920. case 5:
  8921. item.MedChrgitmType = "08"
  8922. break
  8923. case 6:
  8924. item.MedChrgitmType = "14"
  8925. break
  8926. case 7:
  8927. item.MedChrgitmType = "14"
  8928. break
  8929. case 8:
  8930. item.MedChrgitmType = "03"
  8931. break
  8932. case 9:
  8933. item.MedChrgitmType = "14"
  8934. break
  8935. case 10:
  8936. item.MedChrgitmType = "14"
  8937. break
  8938. case 11:
  8939. item.MedChrgitmType = "06"
  8940. break
  8941. case 12:
  8942. item.MedChrgitmType = "12"
  8943. break
  8944. case 13:
  8945. item.MedChrgitmType = "01"
  8946. break
  8947. case 14:
  8948. item.MedChrgitmType = "04"
  8949. break
  8950. case 15:
  8951. item.MedChrgitmType = "14"
  8952. break
  8953. }
  8954. } else {
  8955. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8956. case 1:
  8957. item.MedChrgitmType = "14"
  8958. break
  8959. case 2:
  8960. item.MedChrgitmType = "05"
  8961. break
  8962. case 3:
  8963. item.MedChrgitmType = "04"
  8964. break
  8965. case 4:
  8966. item.MedChrgitmType = "14"
  8967. break
  8968. case 5:
  8969. item.MedChrgitmType = "08"
  8970. break
  8971. case 6:
  8972. item.MedChrgitmType = "14"
  8973. break
  8974. case 7:
  8975. item.MedChrgitmType = "14"
  8976. break
  8977. case 8:
  8978. item.MedChrgitmType = "03"
  8979. break
  8980. case 9:
  8981. item.MedChrgitmType = "14"
  8982. break
  8983. }
  8984. }
  8985. } else if item.HisPrescriptionProject.Type == 3 {
  8986. item.MedChrgitmType = "08"
  8987. }
  8988. }
  8989. }
  8990. for _, item := range order_info {
  8991. if org_id == 10215 {
  8992. if item.MedChrgitmType == "01" { //床位费
  8993. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8994. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8995. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8996. }
  8997. if item.MedChrgitmType == "02" { //诊察费
  8998. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8999. //zhenChaCostSelfTotal = zhenChaCostTotal
  9000. }
  9001. if item.MedChrgitmType == "03" { //检查费
  9002. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9003. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9004. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9005. }
  9006. //if item.MedChrgitmType == "02" { //检查费
  9007. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9008. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9009. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9010. //}
  9011. if item.MedChrgitmType == "04" { //化验费
  9012. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9013. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9014. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9015. }
  9016. if item.MedChrgitmType == "05" { //治疗费
  9017. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9018. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9019. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9020. }
  9021. if item.MedChrgitmType == "06" { //手术费
  9022. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9023. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9024. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9025. }
  9026. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9027. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9028. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9029. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9030. }
  9031. if item.MedChrgitmType == "09" { //西药费
  9032. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9033. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9034. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9035. }
  9036. if item.MedChrgitmType == "11" { //中成费
  9037. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9038. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9039. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9040. }
  9041. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9042. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9043. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9044. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9045. }
  9046. } else {
  9047. if item.MedChrgitmType == "01" { //床位费
  9048. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9049. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9050. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9051. }
  9052. //if item.MedChrgitmType == "02" { //诊察费
  9053. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9054. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9055. //}
  9056. if item.MedChrgitmType == "03" { //检查费
  9057. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9058. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9059. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9060. }
  9061. //if item.MedChrgitmType == "02" { //检查费
  9062. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9063. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9064. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9065. //}
  9066. if item.MedChrgitmType == "04" { //化验费
  9067. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9068. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9069. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9070. }
  9071. if item.MedChrgitmType == "05" { //治疗费
  9072. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9073. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9074. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9075. }
  9076. if item.MedChrgitmType == "06" { //手术费
  9077. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9078. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9079. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9080. }
  9081. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9082. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9083. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9084. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9085. }
  9086. if item.MedChrgitmType == "09" { //西药费
  9087. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9088. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9089. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9090. }
  9091. if item.MedChrgitmType == "11" { //中成费
  9092. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9093. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9094. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9095. }
  9096. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9097. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9098. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9099. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9100. }
  9101. }
  9102. }
  9103. c.ServeSuccessJSON(map[string]interface{}{
  9104. "order": order,
  9105. "order_info": order_info,
  9106. "patient": patient,
  9107. "admin_info": adminInfo,
  9108. "his_hospital": record,
  9109. "bedCostTotal": bedCostTotal,
  9110. "operationCostTotal": operationCostTotal,
  9111. "otherCostTotal": otherCostTotal,
  9112. "materialCostTotal": materialCostTotal,
  9113. "westernMedicineCostTotal": westernMedicineCostTotal,
  9114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9115. "checkCostTotal": checkCostTotal,
  9116. "zhenChaCostTotal": zhenChaCostTotal,
  9117. "laboratoryCostTotal": laboratoryCostTotal,
  9118. "treatCostTotal": treatCostTotal,
  9119. })
  9120. }
  9121. }
  9122. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9123. page, _ := c.GetInt64("page")
  9124. limit, _ := c.GetInt64("limit")
  9125. keywords := c.GetString("keywords")
  9126. start_time := c.GetString("start_time")
  9127. end_time := c.GetString("end_time")
  9128. //clr_type := c.GetString("clr_type")
  9129. insutype := c.GetString("insutype")
  9130. timeLayout := "2006-01-02"
  9131. loc, _ := time.LoadLocation("Local")
  9132. var theStartTIme int64
  9133. if len(start_time) > 0 {
  9134. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9135. theStartTIme = theTime.Unix()
  9136. }
  9137. var theEndtTIme int64
  9138. if len(end_time) > 0 {
  9139. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9140. theEndtTIme = theTime.Unix()
  9141. }
  9142. if page <= 0 {
  9143. page = 1
  9144. }
  9145. if limit <= 0 {
  9146. limit = 10
  9147. }
  9148. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9149. c.ServeSuccessJSON(map[string]interface{}{
  9150. "total": total,
  9151. "list": list,
  9152. })
  9153. return
  9154. }
  9155. func (c *HisApiController) GetPutOnRecordList() {
  9156. page, _ := c.GetInt64("page")
  9157. limit, _ := c.GetInt64("limit")
  9158. keywords := c.GetString("keywords")
  9159. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9160. if page <= 0 {
  9161. page = 1
  9162. }
  9163. if limit <= 0 {
  9164. limit = 10
  9165. }
  9166. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9167. c.ServeSuccessJSON(map[string]interface{}{
  9168. "total": total,
  9169. "list": list,
  9170. })
  9171. return
  9172. }
  9173. func (c *HisApiController) GetCompareData() {
  9174. start_time := c.GetString("start_time")
  9175. end_time := c.GetString("end_time")
  9176. insutype := c.GetString("insutype")
  9177. clr_type := c.GetString("clr_type")
  9178. timeLayout := "2006-01-02"
  9179. loc, _ := time.LoadLocation("Local")
  9180. var theStartTIme int64
  9181. if len(start_time) > 0 {
  9182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9183. if err != nil {
  9184. theStartTIme = 0
  9185. }
  9186. theStartTIme = theTime.Unix()
  9187. }
  9188. var theEndtTIme int64
  9189. if len(end_time) > 0 {
  9190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9191. if err != nil {
  9192. theEndtTIme = 0
  9193. }
  9194. theEndtTIme = theTime.Unix()
  9195. }
  9196. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9197. fmt.Println(err)
  9198. if err == nil {
  9199. c.ServeSuccessJSON(map[string]interface{}{
  9200. "list": formData,
  9201. })
  9202. } else {
  9203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9204. return
  9205. }
  9206. }
  9207. func (c *HisApiController) GetFaPiaoData() {
  9208. order_id, _ := c.GetInt64("order_id")
  9209. patient_id, _ := c.GetInt64("patient_id")
  9210. //number := c.GetString("number")
  9211. adminUser := c.GetAdminUserInfo()
  9212. order, _ := service.GetHisOrderByID(order_id)
  9213. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9214. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9215. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9216. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9217. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9218. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9219. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9220. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9221. var bedCostTotal float64 = 0 //床位总费
  9222. var bedCostSelfTotal float64 = 0 //床位自费
  9223. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9224. var operationCostTotal float64 = 0 //手术费
  9225. var operationCostSelfTotal float64 = 0 //手术费
  9226. var operationCostPartSelfTotal float64 = 0 //手术费
  9227. var otherCostTotal float64 = 0 //其他费用
  9228. var otherCostSelfTotal float64 = 0 //其他费用
  9229. var otherCostPartSelfTotal float64 = 0 //其他费用
  9230. var materialCostTotal float64 = 0 //材料费
  9231. var materialCostSelfTotal float64 = 0 //材料费
  9232. var materialCostPartSelfTotal float64 = 0 //材料费
  9233. var westernMedicineCostTotal float64 = 0 //西药费
  9234. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9235. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9236. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9237. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9238. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9239. var checkCostTotal float64 = 0 //检查费
  9240. var checkCostSelfTotal float64 = 0 //检查费
  9241. var checkCostPartSelfTotal float64 = 0 //检查费
  9242. var hiliCostTotal float64 = 0 //护理费
  9243. var hiliCostSelfTotal float64 = 0 //护理费
  9244. var hiliCostPartSelfTotal float64 = 0 //护理费
  9245. var laboratoryCostTotal float64 = 0 //化验费
  9246. var laboratoryCostSelfTotal float64 = 0 //化验费
  9247. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9248. var treatCostTotal float64 = 0 //治疗费用
  9249. var treatCostSelfTotal float64 = 0 //治疗费用
  9250. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9251. var zhenChaCostTotal float64 = 0 //其他费用
  9252. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9253. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9254. decimal.DivisionPrecision = 2
  9255. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9256. var balanceAccountsType int64
  9257. if his.ID > 0 {
  9258. balanceAccountsType = his.BalanceAccountsType
  9259. } else {
  9260. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9261. }
  9262. if balanceAccountsType == 2 {
  9263. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9264. for _, item := range orderInfos_two {
  9265. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9266. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9267. item.MedChrgitmType = "09"
  9268. }
  9269. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9270. if item.HisPrescriptionProject.Type == 2 {
  9271. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9272. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9273. case 0:
  9274. item.MedChrgitmType = "0"
  9275. break
  9276. case 1:
  9277. item.MedChrgitmType = "14"
  9278. break
  9279. case 2:
  9280. item.MedChrgitmType = "05"
  9281. break
  9282. case 3:
  9283. item.MedChrgitmType = "03"
  9284. break
  9285. case 4:
  9286. item.MedChrgitmType = "03"
  9287. break
  9288. case 5:
  9289. item.MedChrgitmType = "08"
  9290. break
  9291. case 6:
  9292. item.MedChrgitmType = "14"
  9293. break
  9294. case 7:
  9295. item.MedChrgitmType = "14"
  9296. break
  9297. case 8:
  9298. item.MedChrgitmType = "03"
  9299. break
  9300. case 9:
  9301. item.MedChrgitmType = "14"
  9302. break
  9303. case 10:
  9304. item.MedChrgitmType = "14"
  9305. break
  9306. case 11:
  9307. item.MedChrgitmType = "06"
  9308. break
  9309. case 12:
  9310. item.MedChrgitmType = "12"
  9311. break
  9312. case 13:
  9313. item.MedChrgitmType = "01"
  9314. break
  9315. case 14:
  9316. item.MedChrgitmType = "04"
  9317. break
  9318. case 15:
  9319. item.MedChrgitmType = "02"
  9320. break
  9321. }
  9322. } else {
  9323. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9324. case 1:
  9325. item.MedChrgitmType = "14"
  9326. break
  9327. case 2:
  9328. item.MedChrgitmType = "05"
  9329. break
  9330. case 3:
  9331. item.MedChrgitmType = "03"
  9332. break
  9333. case 4:
  9334. item.MedChrgitmType = "03"
  9335. break
  9336. case 5:
  9337. item.MedChrgitmType = "08"
  9338. break
  9339. case 6:
  9340. item.MedChrgitmType = "14"
  9341. break
  9342. case 7:
  9343. item.MedChrgitmType = "14"
  9344. break
  9345. case 8:
  9346. item.MedChrgitmType = "03"
  9347. break
  9348. case 9:
  9349. item.MedChrgitmType = "14"
  9350. break
  9351. }
  9352. }
  9353. } else if item.HisPrescriptionProject.Type == 3 {
  9354. item.MedChrgitmType = "08"
  9355. }
  9356. }
  9357. }
  9358. for _, item := range orderInfos_two {
  9359. fmt.Println(item.MedChrgitmType)
  9360. if item.MedChrgitmType == "07" { //床位费
  9361. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9362. hiliCostSelfTotal = hiliCostTotal
  9363. }
  9364. if item.MedChrgitmType == "01" { //床位费
  9365. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9366. bedCostSelfTotal = bedCostTotal
  9367. }
  9368. if item.MedChrgitmType == "02" { //诊察费
  9369. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9370. zhenChaCostSelfTotal = zhenChaCostTotal
  9371. }
  9372. if item.MedChrgitmType == "03" { //检查费
  9373. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9374. checkCostSelfTotal = checkCostTotal
  9375. }
  9376. if item.MedChrgitmType == "04" { //化验费
  9377. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9378. laboratoryCostSelfTotal = laboratoryCostTotal
  9379. }
  9380. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9381. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9382. treatCostSelfTotal = treatCostTotal
  9383. }
  9384. if item.MedChrgitmType == "06" { //手术费
  9385. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9386. operationCostSelfTotal = treatCostTotal
  9387. }
  9388. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9389. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9390. materialCostSelfTotal = materialCostTotal
  9391. }
  9392. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9393. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9394. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9395. }
  9396. if item.MedChrgitmType == "11" { //中成费
  9397. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9398. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9399. }
  9400. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9401. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9402. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9403. otherCostSelfTotal = otherCostTotal
  9404. }
  9405. } else {
  9406. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9407. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9408. otherCostSelfTotal = otherCostTotal
  9409. }
  9410. }
  9411. }
  9412. } else {
  9413. for _, item := range orderInfos {
  9414. if item.MedChrgitmType == "01" { //床位费
  9415. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9416. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9417. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9418. }
  9419. if item.MedChrgitmType == "02" { //诊察费
  9420. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9421. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9422. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9423. }
  9424. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9425. if item.MedChrgitmType == "03" { //检查费
  9426. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9427. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9428. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9429. }
  9430. } else {
  9431. if item.MedChrgitmType == "03" { //检查费
  9432. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9433. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9434. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9435. }
  9436. }
  9437. if item.MedChrgitmType == "04" { //化验费
  9438. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9439. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9440. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9441. }
  9442. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9443. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9444. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9445. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9446. }
  9447. if item.MedChrgitmType == "06" { //手术费
  9448. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9449. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9450. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9451. }
  9452. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9453. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9454. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9455. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9456. }
  9457. if item.MedChrgitmType == "07" { //护理
  9458. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9459. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9460. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9461. }
  9462. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9463. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9464. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9465. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9466. }
  9467. if item.MedChrgitmType == "11" { //中成费
  9468. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9469. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9470. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9471. }
  9472. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9473. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9474. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9475. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9476. }
  9477. }
  9478. }
  9479. timeLayout := "2006-01-02"
  9480. loc, _ := time.LoadLocation("Local")
  9481. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9482. if err != nil {
  9483. }
  9484. startRecordDateTime := startTime.Unix()
  9485. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9486. if err != nil {
  9487. }
  9488. endRecordDateTime := endTime.Unix()
  9489. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9490. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9491. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9492. c.ServeSuccessJSON(map[string]interface{}{
  9493. "order_number": order.Number, //业务流水号
  9494. "id_card_no": his.IdCardNo, //社会保障号
  9495. "patient": patient,
  9496. "department_name": department.Name, //科室
  9497. "number": his.Number, //门诊号
  9498. "date": order.SettleAccountsDate, //结算日期
  9499. "name": order.PsnName, //姓名
  9500. "gender": patient.Gender, //性别
  9501. "psn_cash_money": order.PsnCashPay, //个人支付
  9502. "pay_way": "门诊", //结算方式
  9503. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9504. "admin_user_name": admin.UserName, //收款员
  9505. "order": order,
  9506. "order_info": orderInfos_two,
  9507. "his": his,
  9508. "bedCostTotal": bedCostTotal,
  9509. "bedCostSelfTotal": bedCostSelfTotal,
  9510. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9511. "operationCostTotal": operationCostTotal,
  9512. "operationCostSelfTotal": operationCostSelfTotal,
  9513. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9514. "otherCostTotal": otherCostTotal,
  9515. "otherCostSelfTotal": otherCostSelfTotal,
  9516. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9517. "materialCostTotal": materialCostTotal,
  9518. "materialCostSelfTotal": materialCostSelfTotal,
  9519. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9520. "westernMedicineCostTotal": westernMedicineCostTotal,
  9521. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9522. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9523. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9524. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9525. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9526. "checkCostTotal": checkCostTotal,
  9527. "checkCostSelfTotal": checkCostSelfTotal,
  9528. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9529. "laboratoryCostTotal": laboratoryCostTotal,
  9530. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9531. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9532. "treatCostTotal": treatCostTotal,
  9533. "treatCostSelfTotal": treatCostSelfTotal,
  9534. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9535. "zhenChaCostTotal": zhenChaCostTotal,
  9536. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9537. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9538. "his_hospital_record": his_hospital_record,
  9539. "pre_pay_money": pre_pay_money,
  9540. "refund_sum": sum,
  9541. "doctor_info": doctor_info,
  9542. "hiliCostTotal": hiliCostTotal,
  9543. "hiliCostSelfTotal": hiliCostSelfTotal,
  9544. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9545. })
  9546. }
  9547. //func (c *HisApiController) GetFaPiaoDatas() {
  9548. // order_ids := c.GetString("order_ids")
  9549. // patient_id, _ := c.GetInt64("patient_id")
  9550. // adminUser := c.GetAdminUserInfo()
  9551. //
  9552. // orders := strings.Split(order_ids, ",")
  9553. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9554. //
  9555. // for _, item := range orders {
  9556. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9557. // order, _ := service.GetHisOrderByID(order_id)
  9558. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9559. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9560. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9561. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9562. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9563. //
  9564. // }
  9565. //
  9566. // var bedCostTotal float64 = 0 //床位总费
  9567. // var bedCostSelfTotal float64 = 0 //床位自费
  9568. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9569. //
  9570. // var operationCostTotal float64 = 0 //手术费
  9571. // var operationCostSelfTotal float64 = 0 //手术费
  9572. // var operationCostPartSelfTotal float64 = 0 //手术费
  9573. //
  9574. // var otherCostTotal float64 = 0 //其他费用
  9575. // var otherCostSelfTotal float64 = 0 //其他费用
  9576. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9577. //
  9578. // var materialCostTotal float64 = 0 //材料费
  9579. // var materialCostSelfTotal float64 = 0 //材料费
  9580. // var materialCostPartSelfTotal float64 = 0 //材料费
  9581. //
  9582. // var westernMedicineCostTotal float64 = 0 //西药费
  9583. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9584. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9585. //
  9586. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9587. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9588. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9589. //
  9590. // var checkCostTotal float64 = 0 //检查费
  9591. // var checkCostSelfTotal float64 = 0 //检查费
  9592. // var checkCostPartSelfTotal float64 = 0 //检查费
  9593. //
  9594. // var laboratoryCostTotal float64 = 0 //化验费
  9595. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9596. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9597. //
  9598. // var treatCostTotal float64 = 0 //治疗费用
  9599. // var treatCostSelfTotal float64 = 0 //治疗费用
  9600. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9601. //
  9602. // var zhenChaCostTotal float64 = 0 //其他费用
  9603. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9604. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9605. //
  9606. // decimal.DivisionPrecision = 2
  9607. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9608. //
  9609. // var balanceAccountsType int64
  9610. // if his.ID > 0 {
  9611. // balanceAccountsType = his.BalanceAccountsType
  9612. // } else {
  9613. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9614. // }
  9615. // if balanceAccountsType == 2 {
  9616. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9617. // for _, item := range orderInfos_two {
  9618. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9619. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9620. // item.MedChrgitmType = "09"
  9621. // }
  9622. //
  9623. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9624. // if item.HisPrescriptionProject.Type == 2 {
  9625. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9626. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9627. // case 0:
  9628. // item.MedChrgitmType = "0"
  9629. // break
  9630. // case 1:
  9631. // item.MedChrgitmType = "14"
  9632. // break
  9633. // case 2:
  9634. // item.MedChrgitmType = "05"
  9635. //
  9636. // break
  9637. // case 3:
  9638. // item.MedChrgitmType = "03"
  9639. //
  9640. // break
  9641. // case 4:
  9642. // item.MedChrgitmType = "03"
  9643. //
  9644. // break
  9645. // case 5:
  9646. // item.MedChrgitmType = "08"
  9647. //
  9648. // break
  9649. // case 6:
  9650. // item.MedChrgitmType = "14"
  9651. //
  9652. // break
  9653. // case 7:
  9654. // item.MedChrgitmType = "14"
  9655. //
  9656. // break
  9657. // case 8:
  9658. // item.MedChrgitmType = "03"
  9659. // break
  9660. // case 9:
  9661. // item.MedChrgitmType = "14"
  9662. // break
  9663. // case 10:
  9664. // item.MedChrgitmType = "14"
  9665. // break
  9666. // case 11:
  9667. // item.MedChrgitmType = "06"
  9668. // break
  9669. // case 12:
  9670. // item.MedChrgitmType = "12"
  9671. // break
  9672. // case 13:
  9673. // item.MedChrgitmType = "01"
  9674. // break
  9675. // case 14:
  9676. // item.MedChrgitmType = "04"
  9677. // break
  9678. // case 15:
  9679. // item.MedChrgitmType = "02"
  9680. // break
  9681. //
  9682. // }
  9683. //
  9684. // } else {
  9685. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9686. //
  9687. // case 1:
  9688. // item.MedChrgitmType = "14"
  9689. // break
  9690. // case 2:
  9691. // item.MedChrgitmType = "05"
  9692. //
  9693. // break
  9694. // case 3:
  9695. // item.MedChrgitmType = "03"
  9696. //
  9697. // break
  9698. // case 4:
  9699. // item.MedChrgitmType = "03"
  9700. //
  9701. // break
  9702. // case 5:
  9703. // item.MedChrgitmType = "08"
  9704. //
  9705. // break
  9706. // case 6:
  9707. // item.MedChrgitmType = "14"
  9708. //
  9709. // break
  9710. // case 7:
  9711. // item.MedChrgitmType = "14"
  9712. //
  9713. // break
  9714. // case 8:
  9715. // item.MedChrgitmType = "03"
  9716. // break
  9717. // case 9:
  9718. // item.MedChrgitmType = "14"
  9719. // break
  9720. //
  9721. // }
  9722. //
  9723. // }
  9724. //
  9725. // } else if item.HisPrescriptionProject.Type == 3 {
  9726. // item.MedChrgitmType = "08"
  9727. // }
  9728. // }
  9729. // }
  9730. //
  9731. // for _, item := range orderInfos_two {
  9732. // fmt.Println(item.MedChrgitmType)
  9733. // if item.MedChrgitmType == "01" { //床位费
  9734. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9735. // bedCostSelfTotal = bedCostTotal
  9736. // }
  9737. //
  9738. // if item.MedChrgitmType == "02" { //诊察费
  9739. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9740. // zhenChaCostSelfTotal = zhenChaCostTotal
  9741. // }
  9742. //
  9743. // if item.MedChrgitmType == "03" { //检查费
  9744. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9745. // checkCostSelfTotal = checkCostTotal
  9746. // }
  9747. //
  9748. // if item.MedChrgitmType == "04" { //化验费
  9749. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9750. // laboratoryCostSelfTotal = laboratoryCostTotal
  9751. // }
  9752. //
  9753. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9754. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9755. // treatCostSelfTotal = treatCostTotal
  9756. // }
  9757. //
  9758. // if item.MedChrgitmType == "06" { //手术费
  9759. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9760. // operationCostSelfTotal = treatCostTotal
  9761. // }
  9762. //
  9763. // if item.MedChrgitmType == "08" { //材料费
  9764. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9765. // materialCostSelfTotal = materialCostTotal
  9766. // }
  9767. //
  9768. // if item.MedChrgitmType == "09" { //西药费
  9769. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9770. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9771. // }
  9772. //
  9773. // if item.MedChrgitmType == "11" { //中成费
  9774. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9775. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9776. // }
  9777. //
  9778. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9779. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9780. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. // otherCostSelfTotal = otherCostTotal
  9782. // }
  9783. // } else {
  9784. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9785. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9786. // otherCostSelfTotal = otherCostTotal
  9787. // }
  9788. //
  9789. // }
  9790. //
  9791. // }
  9792. //
  9793. // } else {
  9794. // for _, item := range orderInfos {
  9795. // if item.MedChrgitmType == "01" { //床位费
  9796. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9797. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9798. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9799. // }
  9800. //
  9801. // if item.MedChrgitmType == "02" { //诊察费
  9802. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9803. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9804. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9805. // }
  9806. //
  9807. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9808. // if item.MedChrgitmType == "03" { //检查费
  9809. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9810. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9811. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9812. //
  9813. // }
  9814. // } else {
  9815. // if item.MedChrgitmType == "03" { //检查费
  9816. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9817. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9818. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9819. // }
  9820. //
  9821. // }
  9822. //
  9823. // if item.MedChrgitmType == "04" { //化验费
  9824. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9825. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9826. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9827. //
  9828. // }
  9829. //
  9830. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9831. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9832. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9833. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9834. //
  9835. // }
  9836. //
  9837. // if item.MedChrgitmType == "06" { //手术费
  9838. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9839. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9840. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9841. // }
  9842. //
  9843. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9844. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9845. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9846. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9847. // }
  9848. //
  9849. // if item.MedChrgitmType == "09" { //西药费
  9850. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9851. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9852. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9853. // }
  9854. //
  9855. // if item.MedChrgitmType == "11" { //中成费
  9856. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9857. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9858. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9859. // }
  9860. //
  9861. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9862. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9863. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9864. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9865. // }
  9866. //
  9867. // }
  9868. // }
  9869. // timeLayout := "2006-01-02"
  9870. // loc, _ := time.LoadLocation("Local")
  9871. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9872. // if err != nil {
  9873. // }
  9874. // startRecordDateTime := startTime.Unix()
  9875. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9876. // if err != nil {
  9877. // }
  9878. // endRecordDateTime := endTime.Unix()
  9879. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9880. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9881. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9882. //
  9883. // c.ServeSuccessJSON(map[string]interface{}{
  9884. // "order_number": order.Number, //业务流水号
  9885. // "id_card_no": his.IdCardNo, //社会保障号
  9886. // "department_name": department.Name, //科室
  9887. // "number": his.Number, //门诊号
  9888. // "date": order.SettleAccountsDate, //结算日期
  9889. // "name": order.PsnName, //姓名
  9890. // "gender": patient.Gender, //性别
  9891. // "psn_cash_money": order.PsnCashPay, //个人支付
  9892. // "pay_way": "门诊", //结算方式
  9893. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9894. // "admin_user_name": admin.UserName, //收款员
  9895. // "order": order,
  9896. // "order_info": orderInfos_two,
  9897. // "his": his,
  9898. // "bedCostTotal": bedCostTotal,
  9899. // "bedCostSelfTotal": bedCostSelfTotal,
  9900. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9901. // "operationCostTotal": operationCostTotal,
  9902. // "operationCostSelfTotal": operationCostSelfTotal,
  9903. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9904. // "otherCostTotal": otherCostTotal,
  9905. // "otherCostSelfTotal": otherCostSelfTotal,
  9906. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9907. // "materialCostTotal": materialCostTotal,
  9908. // "materialCostSelfTotal": materialCostSelfTotal,
  9909. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9910. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9911. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9912. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9913. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9914. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9915. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9916. // "checkCostTotal": checkCostTotal,
  9917. // "checkCostSelfTotal": checkCostSelfTotal,
  9918. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9919. // "laboratoryCostTotal": laboratoryCostTotal,
  9920. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9921. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9922. // "treatCostTotal": treatCostTotal,
  9923. // "treatCostSelfTotal": treatCostSelfTotal,
  9924. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9925. // "zhenChaCostTotal": zhenChaCostTotal,
  9926. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9927. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9928. // "his_hospital_record": his_hospital_record,
  9929. // "pre_pay_money": pre_pay_money,
  9930. // "refund_sum": sum,
  9931. // })
  9932. //
  9933. //}
  9934. func (this *HisApiController) GetIncomeStatisticsData() {
  9935. start_time := this.GetString("start_time")
  9936. end_time := this.GetString("end_time")
  9937. key_words := this.GetString("key_words")
  9938. limit, _ := this.GetInt64("limit")
  9939. page, _ := this.GetInt64("page")
  9940. if page <= 0 {
  9941. page = 1
  9942. }
  9943. if limit <= 0 {
  9944. limit = 10
  9945. }
  9946. statistics_type, _ := this.GetInt64("statistics_type")
  9947. admin := this.GetAdminUserInfo()
  9948. timeLayout := "2006-01-02"
  9949. loc, _ := time.LoadLocation("Local")
  9950. var theStartTIme int64
  9951. if len(start_time) > 0 {
  9952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9953. if err != nil {
  9954. theStartTIme = 0
  9955. }
  9956. theStartTIme = theTime.Unix()
  9957. }
  9958. var theEndtTIme int64
  9959. if len(end_time) > 0 {
  9960. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9961. if err != nil {
  9962. theEndtTIme = 0
  9963. }
  9964. theEndtTIme = theTime.Unix()
  9965. }
  9966. if statistics_type == 1 {
  9967. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9968. this.ServeSuccessJSON(map[string]interface{}{
  9969. "list": list,
  9970. "total": total,
  9971. })
  9972. } else {
  9973. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9974. this.ServeSuccessJSON(map[string]interface{}{
  9975. "list": list,
  9976. "total": total,
  9977. })
  9978. }
  9979. }
  9980. func (c *HisApiController) PostProjectInformation() {
  9981. adminUser := c.GetAdminUserInfo()
  9982. orgId := adminUser.CurrentOrgId
  9983. dataBody := make(map[string]interface{}, 0)
  9984. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9985. if err != nil {
  9986. utils.ErrorLog(err.Error())
  9987. return
  9988. }
  9989. utils.ErrorLog("%v", dataBody)
  9990. var projectList []*models.HisProject
  9991. var total_goods []interface{}
  9992. tempProjects := dataBody["projects"].([]interface{})
  9993. total_goods = tempProjects
  9994. for index, projectMap := range tempProjects {
  9995. projectM := projectMap.(map[string]interface{})
  9996. var project models.HisProject
  9997. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9998. utils.ErrorLog("project_name")
  9999. return
  10000. }
  10001. project_name, _ := projectM["project_name"].(string)
  10002. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10003. err_log := models.ExportErrLog{
  10004. LogType: 6,
  10005. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10006. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10007. Status: 1,
  10008. CreateTime: time.Now().Unix(),
  10009. UpdateTime: time.Now().Unix(),
  10010. ExportTime: time.Now().Unix(),
  10011. }
  10012. service.CreateExportErrLog(&err_log)
  10013. continue
  10014. }
  10015. project.ProjectName = project_name
  10016. prices := projectM["price"].(string)
  10017. price, _ := strconv.ParseFloat(prices, 64)
  10018. if price <= 0 { //名字为空则生成一条导入错误日志
  10019. err_log := models.ExportErrLog{
  10020. LogType: 6,
  10021. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10022. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10023. Status: 1,
  10024. CreateTime: time.Now().Unix(),
  10025. UpdateTime: time.Now().Unix(),
  10026. ExportTime: time.Now().Unix(),
  10027. }
  10028. service.CreateExportErrLog(&err_log)
  10029. continue
  10030. }
  10031. project.Price = price
  10032. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10033. utils.ErrorLog("unit_id")
  10034. return
  10035. }
  10036. unit := projectM["unit"].(string)
  10037. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10038. err_log := models.ExportErrLog{
  10039. LogType: 6,
  10040. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10041. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10042. Status: 1,
  10043. CreateTime: time.Now().Unix(),
  10044. UpdateTime: time.Now().Unix(),
  10045. ExportTime: time.Now().Unix(),
  10046. }
  10047. service.CreateExportErrLog(&err_log)
  10048. continue
  10049. }
  10050. project.Unit = unit
  10051. cost_classify := projectM["cost_classify"].(string)
  10052. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10053. err_log := models.ExportErrLog{
  10054. LogType: 6,
  10055. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10056. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10057. Status: 1,
  10058. CreateTime: time.Now().Unix(),
  10059. UpdateTime: time.Now().Unix(),
  10060. ExportTime: time.Now().Unix(),
  10061. }
  10062. service.CreateExportErrLog(&err_log)
  10063. continue
  10064. }
  10065. var costClassify = "费用类别"
  10066. var cost_classify_id int64
  10067. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10068. if len(cost_classify) != 0 {
  10069. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10070. if errcode == gorm.ErrRecordNotFound {
  10071. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10072. dataconfig := models.DictDataconfig{
  10073. ParentId: costClassifyConfig.ID,
  10074. Module: "system",
  10075. OrgId: orgId,
  10076. Name: cost_classify,
  10077. FieldName: "",
  10078. Value: costConfig.Value + 1,
  10079. CreatedTime: "",
  10080. UpdatedTime: "",
  10081. CreateUserId: adminUser.AdminUser.Id,
  10082. Status: 1,
  10083. Remark: "",
  10084. DeleteIdSystem: 0,
  10085. Title: "",
  10086. Content: "",
  10087. Order: 0,
  10088. Code: "",
  10089. }
  10090. service.CreatedDicConfig(&dataconfig)
  10091. }
  10092. }
  10093. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10094. for _, it := range costClassList {
  10095. if cost_classify == it.Name {
  10096. cost_classify_id = int64(it.Value)
  10097. }
  10098. }
  10099. project.CostClassify = cost_classify_id
  10100. executive_section := projectM["executive_section"].(string)
  10101. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10102. err_log := models.ExportErrLog{
  10103. LogType: 6,
  10104. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10105. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10106. Status: 1,
  10107. CreateTime: time.Now().Unix(),
  10108. UpdateTime: time.Now().Unix(),
  10109. ExportTime: time.Now().Unix(),
  10110. }
  10111. service.CreateExportErrLog(&err_log)
  10112. continue
  10113. }
  10114. if len(executive_section) != 0 {
  10115. //查找科室是否有内容
  10116. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10117. if errcodedepart == gorm.ErrRecordNotFound {
  10118. department := models.XtHisDepartment{
  10119. Name: executive_section,
  10120. Status: 1,
  10121. UserOrgId: adminUser.CurrentOrgId,
  10122. CreatedTime: time.Now().Unix(),
  10123. }
  10124. service.CreateDePartment(&department)
  10125. }
  10126. }
  10127. var executive_section_id int64
  10128. departMentList, _ := service.GetAllDepartMent(orgId)
  10129. for _, it := range departMentList {
  10130. if executive_section == it.Name {
  10131. executive_section_id = it.ID
  10132. }
  10133. }
  10134. project.ExecutiveSection = executive_section_id
  10135. medical_coverage := projectM["medical_coverage"].(string)
  10136. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10137. err_log := models.ExportErrLog{
  10138. LogType: 6,
  10139. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10140. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10141. Status: 1,
  10142. CreateTime: time.Now().Unix(),
  10143. UpdateTime: time.Now().Unix(),
  10144. ExportTime: time.Now().Unix(),
  10145. }
  10146. service.CreateExportErrLog(&err_log)
  10147. continue
  10148. }
  10149. var medicalCoverage = "医保等级"
  10150. var medical_coverage_id int64
  10151. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10152. if len(medical_coverage) != 0 {
  10153. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10154. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10155. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10156. dataconfig := models.DictDataconfig{
  10157. ParentId: medicalCoverageConfig.ID,
  10158. Module: "system",
  10159. OrgId: orgId,
  10160. Name: medical_coverage,
  10161. FieldName: "",
  10162. Value: medicalCoverageConfig.Value + 1,
  10163. CreatedTime: "",
  10164. UpdatedTime: "",
  10165. CreateUserId: adminUser.AdminUser.Id,
  10166. Status: 1,
  10167. Remark: "",
  10168. DeleteIdSystem: 0,
  10169. Title: "",
  10170. Content: "",
  10171. Order: 0,
  10172. Code: "",
  10173. }
  10174. service.CreatedDicConfig(&dataconfig)
  10175. }
  10176. }
  10177. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10178. for _, it := range medicalCoverageList {
  10179. if medical_coverage == it.Name {
  10180. medical_coverage_id = int64(it.Value)
  10181. }
  10182. }
  10183. project.MedicalCoverage = medical_coverage_id
  10184. pinyin := projectM["pinyin"].(string)
  10185. project.Pinyin = pinyin
  10186. wubi := projectM["wubi"].(string)
  10187. project.Wubi = wubi
  10188. statistical_classification := projectM["statistical_classification"].(string)
  10189. var statisticalClassification = "统计分类"
  10190. var statistical_classification_id int64
  10191. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10192. if len(statistical_classification) != 0 {
  10193. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10194. if classificationerrcodes == gorm.ErrRecordNotFound {
  10195. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10196. dataconfig := models.DictDataconfig{
  10197. ParentId: classiFication.ID,
  10198. Module: "system",
  10199. OrgId: orgId,
  10200. Name: statistical_classification,
  10201. FieldName: "",
  10202. Value: classiFicationConfig.Value + 1,
  10203. CreatedTime: "",
  10204. UpdatedTime: "",
  10205. CreateUserId: adminUser.AdminUser.Id,
  10206. Status: 1,
  10207. Remark: "",
  10208. DeleteIdSystem: 0,
  10209. Title: "",
  10210. Content: "",
  10211. Order: 0,
  10212. Code: "",
  10213. }
  10214. service.CreatedDicConfig(&dataconfig)
  10215. }
  10216. }
  10217. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10218. for _, it := range classiFicationList {
  10219. if statistical_classification == it.Name {
  10220. statistical_classification_id = int64(it.Value)
  10221. }
  10222. }
  10223. project.StatisticalClassification = statistical_classification_id
  10224. disease_directory := int64(projectM["disease_directory"].(float64))
  10225. project.DiseaseDirectory = disease_directory
  10226. is_record := int64(projectM["is_record"].(float64))
  10227. project.IsRecord = is_record
  10228. medical_code := projectM["medical_code"].(string)
  10229. project.MedicalCode = medical_code
  10230. tube_color := projectM["tube_color"].(string)
  10231. var tubeColor = "试管颜色"
  10232. var tube_color_id int64
  10233. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10234. if len(tube_color) != 0 {
  10235. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10236. if errcodetube == gorm.ErrRecordNotFound {
  10237. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10238. dataconfig := models.DictDataconfig{
  10239. ParentId: tubeColorConfig.ID,
  10240. Module: "system",
  10241. OrgId: orgId,
  10242. Name: tube_color,
  10243. FieldName: "",
  10244. Value: tubeConfig.Value + 1,
  10245. CreatedTime: "",
  10246. UpdatedTime: "",
  10247. CreateUserId: adminUser.AdminUser.Id,
  10248. Status: 1,
  10249. Remark: "",
  10250. DeleteIdSystem: 0,
  10251. Title: "",
  10252. Content: "",
  10253. Order: 0,
  10254. Code: "",
  10255. }
  10256. service.CreatedDicConfig(&dataconfig)
  10257. }
  10258. }
  10259. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10260. for _, it := range tubeColorList {
  10261. if tube_color == it.Name {
  10262. tube_color_id = int64(it.Value)
  10263. }
  10264. }
  10265. project.TubeColor = tube_color_id
  10266. single_dose := projectM["single_dose"].(string)
  10267. project.SingleDose = single_dose
  10268. execution_frequency := projectM["execution_frequency"].(string)
  10269. project.ExecutionFrequency = execution_frequency
  10270. delivery_way := projectM["delivery_way"].(string)
  10271. project.DeliveryWay = delivery_way
  10272. number_days := projectM["number_days"].(string)
  10273. project.NumberDays = number_days
  10274. total := projectM["total"].(string)
  10275. project.Total = total
  10276. medical_status := int64(projectM["medical_status"].(float64))
  10277. project.MedicalStatus = medical_status
  10278. category := int64(projectM["category"].(float64))
  10279. project.Category = category
  10280. specail_project := int64(projectM["specail_project"].(float64))
  10281. project.SpecailProject = specail_project
  10282. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10283. project.SocialSecurityDirectoryCode = social_security_directory_code
  10284. remark := projectM["remark"].(string)
  10285. project.Remark = remark
  10286. record_date := projectM["record_date"].(string)
  10287. timeLayout := "2006-01-02"
  10288. loc, _ := time.LoadLocation("Local")
  10289. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10290. project.RecordDate = theTime.Unix()
  10291. projectList = append(projectList, &project)
  10292. }
  10293. export_time := time.Now().Unix()
  10294. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10295. if len(projectList) > 0 {
  10296. for _, item := range projectList {
  10297. project := models.HisProject{
  10298. ProjectName: item.ProjectName,
  10299. Price: item.Price,
  10300. Unit: item.Unit,
  10301. CostClassify: item.CostClassify,
  10302. ExecutiveSection: item.ExecutiveSection,
  10303. MedicalCoverage: item.MedicalCoverage,
  10304. UserOrgId: orgId,
  10305. Status: 1,
  10306. CreatedTime: time.Now().Unix(),
  10307. Pinyin: item.Pinyin,
  10308. Wubi: item.Wubi,
  10309. StatisticalClassification: item.StatisticalClassification,
  10310. DiseaseDirectory: item.DiseaseDirectory,
  10311. IsRecord: item.IsRecord,
  10312. MedicalCode: item.MedicalCode,
  10313. TubeColor: item.TubeColor,
  10314. SingleDose: item.SingleDose,
  10315. DeliveryWay: item.DeliveryWay,
  10316. NumberDays: item.NumberDays,
  10317. Total: item.Total,
  10318. Category: item.Category,
  10319. MedicalStatus: item.MedicalStatus,
  10320. SpecailProject: item.SpecailProject,
  10321. RecordDate: item.RecordDate,
  10322. Remark: item.Remark,
  10323. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10324. ExecutionFrequency: item.ExecutionFrequency,
  10325. }
  10326. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10327. if errcodeproject == gorm.ErrRecordNotFound {
  10328. service.CreateProjectInfomation(&project)
  10329. } else if errcodeproject == nil {
  10330. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10331. }
  10332. log := models.ExportLog{
  10333. LogType: 6,
  10334. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10335. TotalNum: int64(len(total_goods)),
  10336. FailNum: int64(len(errLogs)),
  10337. SuccessNum: int64(len(projectList)),
  10338. CreateTime: time.Now().Unix(),
  10339. UpdateTime: time.Now().Unix(),
  10340. ExportTime: export_time,
  10341. Status: 1,
  10342. }
  10343. service.CreateExportLog(&log)
  10344. c.ServeSuccessJSON(map[string]interface{}{
  10345. "msg": "导入成功",
  10346. "total_num": len(total_goods),
  10347. "success_num": len(projectList),
  10348. "fail_num": int64(len(errLogs)),
  10349. })
  10350. }
  10351. } else {
  10352. log := models.ExportLog{
  10353. LogType: 6,
  10354. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10355. TotalNum: int64(len(total_goods)),
  10356. FailNum: int64(len(errLogs)),
  10357. SuccessNum: int64(len(projectList)),
  10358. CreateTime: time.Now().Unix(),
  10359. UpdateTime: time.Now().Unix(),
  10360. ExportTime: export_time,
  10361. Status: 1,
  10362. }
  10363. service.CreateExportLog(&log)
  10364. c.ServeSuccessJSON(map[string]interface{}{
  10365. "msg": "导入成功",
  10366. "total_num": len(total_goods),
  10367. "success_num": len(projectList),
  10368. "fail_num": int64(len(errLogs)),
  10369. })
  10370. }
  10371. }
  10372. //func (this *HisApiController) EditProjectInformation(){
  10373. //
  10374. // id, _ := this.GetInt64("id")
  10375. // project_team := this.GetString("project_team")
  10376. // price := this.GetString("price")
  10377. // price_float, _ := strconv.ParseFloat(price, 64)
  10378. // pinyin := this.GetString("pinyin")
  10379. // wubi := this.GetString("wubi")
  10380. // tube_color, _ := this.GetInt64("tube_color")
  10381. // team_type, _ := this.GetInt64("team_type")
  10382. // remark := this.GetString("remark")
  10383. // ids := this.GetString("ids")
  10384. // item_id := this.GetString("item_id")
  10385. // projectTeam := models.XtHisProjectTeam{
  10386. // ProjectTeam: project_team,
  10387. // Price: price_float,
  10388. // Pinyin: pinyin,
  10389. // Wubi: wubi,
  10390. // TubeColor: tube_color,
  10391. // TeamType: team_type,
  10392. // Remark: remark,
  10393. // ProjectId: ids,
  10394. // ItemId: item_id,
  10395. // }
  10396. //
  10397. //
  10398. // dataBody := make(map[string]interface{}, 0)
  10399. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10400. // if err != nil {
  10401. // utils.ErrorLog(err.Error())
  10402. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10403. // return
  10404. // }
  10405. //
  10406. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10407. //
  10408. //
  10409. // if err != nil {
  10410. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10411. // return
  10412. // }
  10413. //
  10414. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10415. // infos, _ := dataBody["info"].([]interface{})
  10416. // if len(infos) > 0 {
  10417. // var ids []string
  10418. //
  10419. // for _, item := range infos {
  10420. // items := item.(map[string]interface{})
  10421. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10422. // utils.ErrorLog("id")
  10423. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10424. // return
  10425. // }
  10426. // id := int64(items["id"].(float64))
  10427. //
  10428. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10429. // utils.ErrorLog("type")
  10430. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10431. // return
  10432. // }
  10433. // types := int64(items["type"].(float64))
  10434. //
  10435. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10436. // utils.ErrorLog("number")
  10437. // }
  10438. //
  10439. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10440. //
  10441. // projectList := models.XtHisProjectList{
  10442. // Number: number,
  10443. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10444. // ProjectId: id,
  10445. // Status: 1,
  10446. // CreatedTime: time.Now().Unix(),
  10447. // UpdatedTime: time.Now().Unix(),
  10448. // TeamId: projectTeam.ID,
  10449. // Type: types,
  10450. // }
  10451. // list := projectList
  10452. //
  10453. // service.CreateProjectList(&list)
  10454. //
  10455. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10456. //
  10457. // }
  10458. // ids_str := strings.Join(ids, ",")
  10459. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10460. // service.SaveProjectTeam(&projectTeam)
  10461. // this.ServeSuccessJSON(map[string]interface{}{
  10462. // "projectTeam": projectTeam,
  10463. // })
  10464. // }
  10465. // }
  10466. //}
  10467. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10468. name := c.GetString("name")
  10469. mode_id, _ := c.GetInt64("mode", 0)
  10470. types, _ := c.GetInt64("type", 0)
  10471. patient_id, _ := c.GetInt64("patient_id", 0)
  10472. types = 1
  10473. adminInfo := c.GetAdminUserInfo()
  10474. template := &models.HisPrescriptionTemplate{
  10475. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10476. PatientId: patient_id,
  10477. Type: types,
  10478. Status: 1,
  10479. Ctime: time.Now().Unix(),
  10480. Mtime: time.Now().Unix(),
  10481. Name: name,
  10482. Mode: mode_id,
  10483. }
  10484. dataBody := make(map[string]interface{}, 0)
  10485. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10486. if err != nil {
  10487. utils.ErrorLog(err.Error())
  10488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10489. return
  10490. }
  10491. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10492. //如果已经存在记录则删除处方
  10493. if template_one.ID > 0 {
  10494. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10495. var ids []int64
  10496. var org_id int64
  10497. for _, item := range ps {
  10498. org_id = c.GetAdminUserInfo().CurrentOrgId
  10499. ids = append(ids, item.ID)
  10500. }
  10501. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10502. if err2 == nil {
  10503. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10504. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10505. if len(prescriptions) > 0 {
  10506. for _, item := range prescriptions {
  10507. items := item.(map[string]interface{})
  10508. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10509. utils.ErrorLog("type")
  10510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10511. return
  10512. }
  10513. types := int64(items["type"].(float64))
  10514. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10515. utils.ErrorLog("med_type")
  10516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10517. return
  10518. }
  10519. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10520. ctime := time.Now().Unix()
  10521. prescription := &models.HisPrescriptionInfoTemplate{
  10522. PatientId: patient_id,
  10523. UserOrgId: adminInfo.CurrentOrgId,
  10524. Ctime: ctime,
  10525. Mtime: ctime,
  10526. Type: types,
  10527. Modifier: adminInfo.AdminUser.Id,
  10528. Creator: adminInfo.AdminUser.Id,
  10529. Status: 1,
  10530. PTemplateId: template_one.ID,
  10531. MedType: med_type,
  10532. }
  10533. service.CreateHisPrescriptionInfoTemplate(prescription)
  10534. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10535. advices := items["advices"].([]interface{})
  10536. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10537. ctime := time.Now().Unix()
  10538. mtime := ctime
  10539. if len(advices) > 0 {
  10540. for _, advice := range advices {
  10541. var s models.HisPrescriptionAdviceTemplate
  10542. s.PrescriptionId = prescription.ID
  10543. s.AdviceType = 2
  10544. s.StopState = 2
  10545. s.ExecutionState = 2
  10546. s.Status = 1
  10547. s.UserOrgId = adminInfo.CurrentOrgId
  10548. s.CreatedTime = ctime
  10549. s.UpdatedTime = mtime
  10550. s.PatientId = patient_id
  10551. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10552. if errcode > 0 {
  10553. c.ServeFailJSONWithSGJErrorCode(errcode)
  10554. return
  10555. }
  10556. service.CreateHisPrescriptionAdviceTemplate(&s)
  10557. }
  10558. }
  10559. }
  10560. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10561. projects := items["project"].([]interface{})
  10562. if len(projects) > 0 {
  10563. for _, project := range projects {
  10564. var p models.HisPrescriptionProjectTemplate
  10565. p.PrescriptionId = prescription.ID
  10566. p.Ctime = time.Now().Unix()
  10567. p.Mtime = time.Now().Unix()
  10568. p.PatientId = patient_id
  10569. p.UserOrgId = adminInfo.CurrentOrgId
  10570. p.Status = 1
  10571. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10572. if errcode > 0 {
  10573. c.ServeFailJSONWithSGJErrorCode(errcode)
  10574. return
  10575. }
  10576. service.CreateHisPrescriptionProjectTemplate(&p)
  10577. }
  10578. }
  10579. }
  10580. }
  10581. c.ServeSuccessJSON(map[string]interface{}{
  10582. "msg": "创建成功",
  10583. })
  10584. }
  10585. }
  10586. } else {
  10587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10588. return
  10589. }
  10590. } else {
  10591. err3 := service.CreateHisPrescriptionTemplate(template)
  10592. if err3 == nil {
  10593. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10594. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10595. if len(prescriptions) > 0 {
  10596. for _, item := range prescriptions {
  10597. items := item.(map[string]interface{})
  10598. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10599. utils.ErrorLog("type")
  10600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10601. return
  10602. }
  10603. types := int64(items["type"].(float64))
  10604. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10605. utils.ErrorLog("med_type")
  10606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10607. return
  10608. }
  10609. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10610. ctime := time.Now().Unix()
  10611. prescription := &models.HisPrescriptionInfoTemplate{
  10612. PatientId: patient_id,
  10613. UserOrgId: adminInfo.CurrentOrgId,
  10614. Ctime: ctime,
  10615. Mtime: ctime,
  10616. Type: types,
  10617. Modifier: adminInfo.AdminUser.Id,
  10618. Creator: adminInfo.AdminUser.Id,
  10619. Status: 1,
  10620. PTemplateId: template.ID,
  10621. MedType: med_type,
  10622. }
  10623. service.CreateHisPrescriptionInfoTemplate(prescription)
  10624. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10625. advices := items["advices"].([]interface{})
  10626. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10627. ctime := time.Now().Unix()
  10628. mtime := ctime
  10629. if len(advices) > 0 {
  10630. for _, advice := range advices {
  10631. var s models.HisPrescriptionAdviceTemplate
  10632. s.PrescriptionId = prescription.ID
  10633. s.AdviceType = 2
  10634. s.StopState = 2
  10635. s.ExecutionState = 2
  10636. s.Status = 1
  10637. s.UserOrgId = adminInfo.CurrentOrgId
  10638. s.CreatedTime = ctime
  10639. s.UpdatedTime = mtime
  10640. s.PatientId = patient_id
  10641. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10642. if errcode > 0 {
  10643. c.ServeFailJSONWithSGJErrorCode(errcode)
  10644. return
  10645. }
  10646. service.CreateHisPrescriptionAdviceTemplate(&s)
  10647. }
  10648. }
  10649. }
  10650. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10651. projects := items["project"].([]interface{})
  10652. if len(projects) > 0 {
  10653. for _, project := range projects {
  10654. var p models.HisPrescriptionProjectTemplate
  10655. p.PrescriptionId = prescription.ID
  10656. p.Ctime = time.Now().Unix()
  10657. p.Mtime = time.Now().Unix()
  10658. p.PatientId = patient_id
  10659. p.UserOrgId = adminInfo.CurrentOrgId
  10660. p.Status = 1
  10661. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10662. if errcode > 0 {
  10663. c.ServeFailJSONWithSGJErrorCode(errcode)
  10664. return
  10665. }
  10666. service.CreateHisPrescriptionProjectTemplate(&p)
  10667. }
  10668. }
  10669. }
  10670. }
  10671. c.ServeSuccessJSON(map[string]interface{}{
  10672. "msg": "创建成功",
  10673. })
  10674. }
  10675. }
  10676. } else {
  10677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10678. return
  10679. }
  10680. }
  10681. }
  10682. func (c *HisApiController) PreSettle() {
  10683. id, _ := c.GetInt64("id")
  10684. record_time := c.GetString("record_time")
  10685. his_patient_id, _ := c.GetInt64("his_patient_id")
  10686. timeLayout := "2006-01-02"
  10687. loc, _ := time.LoadLocation("Local")
  10688. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10689. diagnosis_id := c.GetString("diagnosis")
  10690. sick_type, _ := c.GetInt64("sick_type")
  10691. reg_type, _ := c.GetInt64("p_type")
  10692. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10694. if err != nil {
  10695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10696. return
  10697. }
  10698. recordDateTime := theTime.Unix()
  10699. adminUser := c.GetAdminUserInfo()
  10700. var prescriptions []*models.HisPrescription
  10701. var start_time int64
  10702. var end_time int64
  10703. ids_str := c.GetString("ids")
  10704. ids_arr := strings.Split(ids_str, ",")
  10705. fmt.Println(reg_type)
  10706. if settle_accounts_type == 1 { //日结
  10707. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10708. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10709. } else {
  10710. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10711. }
  10712. fmt.Println(prescriptions)
  10713. } else { //月结
  10714. start_time_str := c.GetString("start_time")
  10715. end_time_str := c.GetString("end_time")
  10716. timeLayout := "2006-01-02"
  10717. loc, _ := time.LoadLocation("Local")
  10718. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10719. if err != nil {
  10720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10721. return
  10722. }
  10723. recordStartTime := theStartTime.Unix()
  10724. start_time = recordStartTime
  10725. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10726. if err != nil {
  10727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10728. return
  10729. }
  10730. recordEndTime := theEndTime.Unix()
  10731. end_time = recordEndTime
  10732. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10733. }
  10734. if reg_type == 1111 || reg_type == 1112 {
  10735. reg_type = 11
  10736. }
  10737. timestamp := time.Now().Unix()
  10738. tempTime := time.Unix(timestamp, 0)
  10739. timeFormat := tempTime.Format("20060102150405")
  10740. chrgBchno := rand.Intn(100000) + 10000
  10741. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10742. strconv.FormatInt(his.PatientId, 10)
  10743. var ids []int64
  10744. for _, item := range prescriptions {
  10745. ids = append(ids, item.ID)
  10746. }
  10747. fmt.Println(ids)
  10748. var total float64
  10749. for _, item := range prescriptions {
  10750. fmt.Println(item)
  10751. if item.Type == 1 { //药品
  10752. for _, subItem := range item.HisDoctorAdviceInfo {
  10753. total = total + (subItem.Price * subItem.PrescribingNumber)
  10754. }
  10755. }
  10756. if item.Type == 2 { //项目
  10757. for _, subItem := range item.HisPrescriptionProject {
  10758. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10759. total = total + (subItem.Price * cnt)
  10760. }
  10761. }
  10762. for _, subItem := range item.HisAdditionalCharge {
  10763. total = total + (subItem.Price * float64(subItem.Count))
  10764. }
  10765. }
  10766. allTotal := fmt.Sprintf("%.2f", total)
  10767. totals, _ := strconv.ParseFloat(allTotal, 64)
  10768. order := &models.HisOrder{
  10769. UserOrgId: adminUser.CurrentOrgId,
  10770. HisPatientId: his.ID,
  10771. PatientId: id,
  10772. SettleAccountsDate: recordDateTime,
  10773. Ctime: time.Now().Unix(),
  10774. Mtime: time.Now().Unix(),
  10775. Status: 1,
  10776. OrderStatus: 1,
  10777. MdtrtId: his.Number,
  10778. Number: chrg_bchno,
  10779. MedfeeSumamt: totals,
  10780. SettleEndTime: end_time,
  10781. SettleStartTime: start_time,
  10782. SettleType: settle_accounts_type,
  10783. PsnPartAmt: totals,
  10784. PsnCashPay: totals,
  10785. PType: 2,
  10786. IsPre: 1,
  10787. MedType: strconv.Itoa(int(reg_type)),
  10788. Diagnosis: diagnosis_id,
  10789. }
  10790. err = service.CreateOrder(order)
  10791. if err != nil {
  10792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10793. return
  10794. }
  10795. var customs []*Custom
  10796. for _, item := range prescriptions {
  10797. fmt.Println(item.Type)
  10798. if item.Type == 1 { //药品
  10799. for _, subItem := range item.HisDoctorAdviceInfo {
  10800. cus := &Custom{
  10801. AdviceId: subItem.ID,
  10802. ProjectId: 0,
  10803. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10804. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10805. FeedetlSn: subItem.FeedetlSn,
  10806. Price: fmt.Sprintf("%.2f", subItem.Price),
  10807. MedListCodg: subItem.MedListCodg,
  10808. Type: 1,
  10809. }
  10810. customs = append(customs, cus)
  10811. }
  10812. }
  10813. if item.Type == 2 { //项目
  10814. for _, subItem := range item.HisPrescriptionProject {
  10815. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10816. cus := &Custom{
  10817. AdviceId: 0,
  10818. ProjectId: subItem.ID,
  10819. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10820. Cut: fmt.Sprintf("%.2f", cnt),
  10821. FeedetlSn: subItem.FeedetlSn,
  10822. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10823. MedListCodg: subItem.MedListCodg,
  10824. Type: 2,
  10825. }
  10826. customs = append(customs, cus)
  10827. }
  10828. }
  10829. for _, item := range item.HisAdditionalCharge {
  10830. cus := &Custom{
  10831. ItemId: item.ID,
  10832. AdviceId: 0,
  10833. ProjectId: 0,
  10834. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10835. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10836. FeedetlSn: item.FeedetlSn,
  10837. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10838. MedListCodg: item.XtHisAddtionConfig.Code,
  10839. Type: 3,
  10840. }
  10841. customs = append(customs, cus)
  10842. }
  10843. }
  10844. fmt.Println(customs)
  10845. for _, item := range customs {
  10846. var advice_id int64 = 0
  10847. var project_id int64 = 0
  10848. var item_id int64 = 0
  10849. var types int64 = 0
  10850. if item.Type == 1 {
  10851. advice_id = item.AdviceId
  10852. project_id = 0
  10853. item_id = 0
  10854. } else if item.Type == 2 {
  10855. advice_id = 0
  10856. item_id = 0
  10857. project_id = item.ProjectId
  10858. } else if item.Type == 3 {
  10859. advice_id = 0
  10860. item_id = item.ItemId
  10861. project_id = 0
  10862. }
  10863. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10864. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10865. pric, _ := strconv.ParseFloat(item.Price, 32)
  10866. info := &models.HisOrderInfo{
  10867. OrderNumber: order.Number,
  10868. UploadDate: time.Now().Unix(),
  10869. AdviceId: advice_id,
  10870. DetItemFeeSumamt: detItemFeeSumamt,
  10871. Cnt: cut,
  10872. Pric: pric,
  10873. PatientId: id,
  10874. Status: 1,
  10875. Mtime: time.Now().Unix(),
  10876. Ctime: time.Now().Unix(),
  10877. UserOrgId: adminUser.CurrentOrgId,
  10878. HisPatientId: his.ID,
  10879. OrderId: order.ID,
  10880. ProjectId: project_id,
  10881. Type: types,
  10882. ItemId: item_id,
  10883. }
  10884. service.CreateOrderInfo(info)
  10885. }
  10886. his.SickType = sick_type
  10887. service.UpdataHisPateint(&his)
  10888. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10889. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10890. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10891. if err == nil {
  10892. c.ServeSuccessJSON(map[string]interface{}{
  10893. "msg": "结算成功",
  10894. })
  10895. }
  10896. }
  10897. type CustomOrderInfo struct {
  10898. Name string
  10899. Spec string
  10900. Unit string
  10901. Count float64
  10902. Price float64
  10903. Total float64
  10904. }
  10905. func (c *HisApiController) GetPrivateExpensesInfo() {
  10906. order_id, _ := c.GetInt64("id", 0)
  10907. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10908. order, _ := service.GetHisOrderByID(order_id)
  10909. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10910. if order.ID == 0 {
  10911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10912. return
  10913. }
  10914. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10915. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10916. org_id := c.GetAdminUserInfo().CurrentOrgId
  10917. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10918. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10919. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10920. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10921. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10922. //var orderInfos_four []*models.HisOrderInfoTwo
  10923. //for _, item := range orderInfos_three {
  10924. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10925. // item.HisPrescriptionProject.IsCheckTeam = 1
  10926. // orderInfos_four = append(orderInfos_four, item)
  10927. //
  10928. // }
  10929. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10930. // item.HisPrescriptionProject.IsCheckTeam = 2
  10931. // orderInfos_two = append(orderInfos_two, item)
  10932. // }
  10933. //}
  10934. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10935. //var cus_slice []CustomOrderInfo
  10936. //for _, item := range new_order_info {
  10937. // var cus CustomOrderInfo
  10938. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10939. // cus.Unit = ""
  10940. // cus.Spec = ""
  10941. // var total float64
  10942. // for _, subItem := range orderInfos_four {
  10943. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10944. // total = total + subItem.DetItemFeeSumamt
  10945. // fmt.Println(subItem.DetItemFeeSumamt)
  10946. // }
  10947. // }
  10948. // cus.Count = 1
  10949. // cus.Total = total
  10950. // cus_slice = append(cus_slice, cus)
  10951. //}
  10952. orderInfos = append(orderInfos, orderInfos_two...)
  10953. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10954. //orderInfos = append(orderInfos, orderInfos_three...)
  10955. //}/**/
  10956. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10957. c.ServeSuccessJSON(map[string]interface{}{
  10958. "order": order,
  10959. "order_info": orderInfos,
  10960. "patient": patient,
  10961. "admin_info": adminInfo,
  10962. "his": his,
  10963. "current_admin": role,
  10964. "org_config": miConfig,
  10965. //"new_order_info": cus_slice,
  10966. })
  10967. }
  10968. func (this *HisApiController) ChangeMedType() {
  10969. med_type := this.GetString("med_type")
  10970. old_med_type := this.GetString("old_med_type")
  10971. ids := this.GetString("ids")
  10972. settle_type, _ := this.GetInt64("settle_type")
  10973. start_time := this.GetString("start_time")
  10974. end_time := this.GetString("end_time")
  10975. ids_arr := strings.Split(ids, ",")
  10976. if settle_type == 1 { //日结
  10977. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10978. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10979. prescription.MedType = med_type
  10980. err := service.SaveHisPrescriptionTwo(&prescription)
  10981. if err == nil {
  10982. this.ServeSuccessJSON(map[string]interface{}{
  10983. "msg": "修改成功",
  10984. })
  10985. } else {
  10986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10987. return
  10988. }
  10989. } else if settle_type == 2 {
  10990. timeLayout := "2006-01-02"
  10991. loc, _ := time.LoadLocation("Local")
  10992. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10993. if err != nil {
  10994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10995. return
  10996. }
  10997. recordStartTime := theStartTime.Unix()
  10998. start_time_timestamp := recordStartTime
  10999. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11000. if err != nil {
  11001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11002. return
  11003. }
  11004. recordEndTime := theEndTime.Unix()
  11005. end_time_timestamp := recordEndTime
  11006. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11007. if updateErr == nil {
  11008. this.ServeSuccessJSON(map[string]interface{}{
  11009. "msg": "修改成功",
  11010. })
  11011. } else {
  11012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11013. return
  11014. }
  11015. }
  11016. }
  11017. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11018. patient_id, _ := c.GetInt64("patient_id")
  11019. his_patient_id, _ := c.GetInt64("his_patient_id")
  11020. record_date := c.GetString("record_date")
  11021. start_time := c.GetString("start_time")
  11022. end_time := c.GetString("end_time")
  11023. order_status, _ := c.GetInt64("type", 0)
  11024. p_type, _ := c.GetInt64("p_type", 0)
  11025. order_id, _ := c.GetInt64("order_id", 0)
  11026. timeLayout := "2006-01-02"
  11027. loc, _ := time.LoadLocation("Local")
  11028. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11029. if err != nil {
  11030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11031. return
  11032. }
  11033. recordDateTime := theTime.Unix()
  11034. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11035. if err != nil {
  11036. }
  11037. startRecordDateTime := startTime.Unix()
  11038. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11039. if err != nil {
  11040. }
  11041. endRecordDateTime := endTime.Unix()
  11042. admin := c.GetAdminUserInfo()
  11043. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11044. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11045. order, _ := service.GetHisOrderByID(order_id)
  11046. var monthPrescriptions []*models.HisPrescription
  11047. if order_status == 1 || order_status == 0 {
  11048. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11049. } else if order_status == 2 {
  11050. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11051. }
  11052. var settle_total float64
  11053. for _, item := range monthPrescriptions {
  11054. if len(item.HisPrescriptionProject) > 0 {
  11055. for _, subItem := range item.HisPrescriptionProject {
  11056. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11057. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11058. settle_total = settle_total + total
  11059. }
  11060. }
  11061. if len(item.HisDoctorAdviceInfo) > 0 {
  11062. for _, subItem := range item.HisDoctorAdviceInfo {
  11063. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11064. settle_total = settle_total + total
  11065. }
  11066. }
  11067. }
  11068. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11069. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11070. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11071. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11072. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11073. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11074. //获取所有科室信息
  11075. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11076. var dia string
  11077. for _, item := range month_p_info {
  11078. if len(dia) == 0 {
  11079. dia = item.Diagnosis
  11080. } else {
  11081. dia = dia + "," + item.Diagnosis
  11082. }
  11083. }
  11084. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11085. dia_arr = removeEmptyStrings(dia_arr)
  11086. c.ServeSuccessJSON(map[string]interface{}{
  11087. "his_info": his_patient_info,
  11088. "xt_info": xt_patient_info,
  11089. "case_history": case_history,
  11090. "info": patientPrescriptionInfo,
  11091. "last_info": lastPatientPrescriptionInfo,
  11092. "month_prescriptions": monthPrescriptions,
  11093. "order": order,
  11094. "doctors": doctors,
  11095. "department": department,
  11096. "settle_total": settle_total,
  11097. "dia_arr": dia_arr,
  11098. })
  11099. return
  11100. }
  11101. func removeEmptyStrings(input []string) []string {
  11102. var output []string
  11103. for _, s := range input {
  11104. if s != "" {
  11105. output = append(output, s)
  11106. }
  11107. }
  11108. return output
  11109. }
  11110. func removeDuplicates(input []string) []string {
  11111. seen := make(map[string]bool)
  11112. output := []string{}
  11113. for _, s := range input {
  11114. if _, exists := seen[s]; !exists {
  11115. seen[s] = true
  11116. output = append(output, s)
  11117. }
  11118. }
  11119. return output
  11120. }
  11121. func (c *HisApiController) GetHisMonthPatientInfo() {
  11122. patient_id, _ := c.GetInt64("patient_id")
  11123. his_patient_id, _ := c.GetInt64("his_patient_id")
  11124. record_date := c.GetString("record_date")
  11125. number := c.GetString("number")
  11126. start_time := c.GetString("start_time")
  11127. end_time := c.GetString("end_time")
  11128. p_type, _ := c.GetInt64("p_type")
  11129. timeLayout := "2006-01-02"
  11130. loc, _ := time.LoadLocation("Local")
  11131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11132. if err != nil {
  11133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11134. return
  11135. }
  11136. recordDateTime := theTime.Unix()
  11137. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11138. if err != nil {
  11139. }
  11140. startRecordDateTime := startTime.Unix()
  11141. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11142. if err != nil {
  11143. }
  11144. endRecordDateTime := endTime.Unix()
  11145. admin := c.GetAdminUserInfo()
  11146. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11147. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11148. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11149. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11150. var settle_total float64
  11151. for _, item := range monthPrescriptions {
  11152. if len(item.HisPrescriptionProject) > 0 {
  11153. for _, subItem := range item.HisPrescriptionProject {
  11154. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11155. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11156. settle_total = settle_total + total
  11157. }
  11158. }
  11159. if len(item.HisDoctorAdviceInfo) > 0 {
  11160. for _, subItem := range item.HisDoctorAdviceInfo {
  11161. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11162. settle_total = settle_total + total
  11163. }
  11164. }
  11165. }
  11166. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11167. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11168. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11169. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11170. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11171. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11172. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11173. //获取所有科室信息
  11174. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11175. c.ServeSuccessJSON(map[string]interface{}{
  11176. "his_info": his_patient_info,
  11177. "xt_info": xt_patient_info,
  11178. "case_history": case_history,
  11179. "info": patientPrescriptionInfo,
  11180. "month_prescriptions": monthPrescriptions,
  11181. "order": order,
  11182. "doctors": doctors,
  11183. "department": department,
  11184. "count": count,
  11185. "drugStockConfig": drugStockConfig,
  11186. "last_info": lastPatientPrescriptionInfo,
  11187. "settle_total": settle_total,
  11188. })
  11189. return
  11190. }
  11191. func (c *HisApiController) GetAllOrder() {
  11192. org_id := c.GetAdminUserInfo().CurrentOrgId
  11193. orders, _ := service.GetNewHisOrderList(org_id)
  11194. c.ServeSuccessJSON(map[string]interface{}{
  11195. "order": orders,
  11196. })
  11197. return
  11198. }
  11199. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11200. newArr = make([]*models.HisOrderInfoTwo, 0)
  11201. for i := 0; i < len(arr); i++ {
  11202. repeat := false
  11203. for j := i + 1; j < len(arr); j++ {
  11204. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11205. repeat = true
  11206. break
  11207. }
  11208. }
  11209. if !repeat {
  11210. newArr = append(newArr, arr[i])
  11211. }
  11212. }
  11213. return
  11214. }
  11215. // 修改处方退库操作 参数传修改之前的处方数据
  11216. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11217. if advice.ExecutionState == 1 {
  11218. //查询该病人该药品是否有库存记录
  11219. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11220. if errcode == gorm.ErrRecordNotFound {
  11221. } else {
  11222. //退库
  11223. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11224. if advice.PrescribingNumberUnit == drug.MinUnit {
  11225. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11226. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11227. //退库
  11228. warehouseInfo := models.DrugWarehouseInfo{
  11229. StockMinNumber: prescribingNumber,
  11230. }
  11231. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11232. operation_time := time.Now().Unix()
  11233. creater := advice.AdviceDoctor
  11234. ctime := time.Now().Unix()
  11235. timeStr := time.Now().Format("2006-01-02")
  11236. timeArr := strings.Split(timeStr, "-")
  11237. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11238. total = total + 1
  11239. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11240. cancelStock := models.DrugCancelStock{
  11241. OrderNumber: orderNumber,
  11242. OperaTime: operation_time,
  11243. OrgId: advice.UserOrgId,
  11244. Creater: creater,
  11245. Ctime: ctime,
  11246. Status: 1,
  11247. ReturnTime: advice.AdviceDate,
  11248. Dealer: info.Dealer,
  11249. Manufacturer: info.Manufacturer,
  11250. Type: 1,
  11251. }
  11252. service.AddSigleDrugCancelStock(&cancelStock)
  11253. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11254. dealer, _ := service.GetDealerById(info.Dealer)
  11255. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11256. cancelStockInfo := models.DrugCancelStockInfo{
  11257. OrderNumber: cancelInfo.OrderNumber,
  11258. CancelStockId: cancelInfo.ID,
  11259. DrugId: info.DrugId,
  11260. Count: info.Count,
  11261. Status: 1,
  11262. Ctime: ctime,
  11263. OrgId: advice.UserOrgId,
  11264. Type: 1,
  11265. Manufacturer: manufactureName.ManufacturerName,
  11266. Dealer: dealer.DealerName,
  11267. Total: 0,
  11268. RetailPrice: info.RetailPrice,
  11269. RetailTotalPrice: info.RetailTotalPrice,
  11270. Price: info.Price,
  11271. RegisterAccount: "",
  11272. Remark: info.Remark,
  11273. BatchNumber: info.BatchNumber,
  11274. MaxUnit: info.CountUnit,
  11275. ProductDate: info.ProductDate,
  11276. ExpiryDate: info.ExpiryDate,
  11277. BatchNumberId: info.WarehouseInfoId,
  11278. }
  11279. flow := models.DrugFlow{
  11280. WarehousingId: 0,
  11281. DrugId: info.DrugId,
  11282. Number: "",
  11283. BatchNumber: info.BatchNumber,
  11284. Count: info.Count,
  11285. UserOrgId: advice.UserOrgId,
  11286. PatientId: 0,
  11287. SystemTime: ctime,
  11288. ConsumableType: 4,
  11289. IsSys: 0,
  11290. WarehousingOrder: "",
  11291. WarehouseOutId: 0,
  11292. WarehouseOutOrderNumber: "",
  11293. IsEdit: 0,
  11294. CancelStockId: cancelStock.ID,
  11295. CancelOrderNumber: cancelStock.OrderNumber,
  11296. Manufacturer: info.Manufacturer,
  11297. Dealer: info.Dealer,
  11298. Creator: advice.UserOrgId,
  11299. UpdateCreator: 0,
  11300. Status: 1,
  11301. Ctime: time.Now().Unix(),
  11302. Mtime: 0,
  11303. Price: info.Price,
  11304. WarehousingDetailId: 0,
  11305. WarehouseOutDetailId: 0,
  11306. CancelOutDetailId: 0,
  11307. ExpireDate: info.ExpiryDate,
  11308. ProductDate: info.ProductDate,
  11309. MaxUnit: info.CountUnit,
  11310. MinUnit: "",
  11311. }
  11312. service.CreatedCancelStock(cancelStockInfo)
  11313. service.CreateDrugFlowOne(flow)
  11314. } else {
  11315. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11316. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11317. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11318. warehouseInfo := models.DrugWarehouseInfo{
  11319. StockMinNumber: prescribingNumber,
  11320. }
  11321. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11322. }
  11323. operation_time := time.Now().Unix()
  11324. creater := advice.AdviceDoctor
  11325. ctime := time.Now().Unix()
  11326. timeStr := time.Now().Format("2006-01-02")
  11327. timeArr := strings.Split(timeStr, "-")
  11328. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11329. total = total + 1
  11330. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11331. cancelStock := models.DrugCancelStock{
  11332. OrderNumber: orderNumber,
  11333. OperaTime: operation_time,
  11334. OrgId: advice.UserOrgId,
  11335. Creater: creater,
  11336. Ctime: ctime,
  11337. Status: 1,
  11338. ReturnTime: advice.AdviceDate,
  11339. Dealer: info.Dealer,
  11340. Manufacturer: info.Manufacturer,
  11341. Type: 1,
  11342. }
  11343. service.AddSigleDrugCancelStock(&cancelStock)
  11344. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11345. dealer, _ := service.GetDealerById(info.Dealer)
  11346. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11347. cancelStockInfo := models.DrugCancelStockInfo{
  11348. OrderNumber: cancelInfo.OrderNumber,
  11349. CancelStockId: cancelInfo.ID,
  11350. DrugId: info.DrugId,
  11351. Count: info.Count,
  11352. Status: 1,
  11353. Ctime: ctime,
  11354. OrgId: advice.UserOrgId,
  11355. Type: 1,
  11356. Manufacturer: manufactureName.ManufacturerName,
  11357. Dealer: dealer.DealerName,
  11358. Total: 0,
  11359. RetailPrice: info.RetailPrice,
  11360. RetailTotalPrice: info.RetailTotalPrice,
  11361. Price: info.Price,
  11362. RegisterAccount: "",
  11363. Remark: info.Remark,
  11364. BatchNumber: info.BatchNumber,
  11365. MaxUnit: info.CountUnit,
  11366. ProductDate: info.ProductDate,
  11367. ExpiryDate: info.ExpiryDate,
  11368. BatchNumberId: info.WarehouseInfoId,
  11369. }
  11370. flow := models.DrugFlow{
  11371. WarehousingId: 0,
  11372. DrugId: info.DrugId,
  11373. Number: "",
  11374. BatchNumber: info.BatchNumber,
  11375. Count: info.Count,
  11376. UserOrgId: advice.UserOrgId,
  11377. PatientId: 0,
  11378. SystemTime: ctime,
  11379. ConsumableType: 4,
  11380. IsSys: 0,
  11381. WarehousingOrder: "",
  11382. WarehouseOutId: 0,
  11383. WarehouseOutOrderNumber: "",
  11384. IsEdit: 0,
  11385. CancelStockId: cancelStock.ID,
  11386. CancelOrderNumber: cancelStock.OrderNumber,
  11387. Manufacturer: info.Manufacturer,
  11388. Dealer: info.Dealer,
  11389. Creator: advice.AdviceDoctor,
  11390. UpdateCreator: 0,
  11391. Status: 1,
  11392. Ctime: time.Now().Unix(),
  11393. Mtime: 0,
  11394. Price: info.Price,
  11395. WarehousingDetailId: 0,
  11396. WarehouseOutDetailId: 0,
  11397. CancelOutDetailId: 0,
  11398. ExpireDate: info.ExpiryDate,
  11399. ProductDate: info.ProductDate,
  11400. MaxUnit: info.CountUnit,
  11401. MinUnit: "",
  11402. }
  11403. service.CreatedCancelStock(cancelStockInfo)
  11404. service.CreateDrugFlowOne(flow)
  11405. }
  11406. }
  11407. }
  11408. return err
  11409. }
  11410. func (this *HisApiController) DeleteNCDS() {
  11411. id, _ := this.GetInt64("id", 0)
  11412. if id > 0 {
  11413. service.DeletePsnNCDSRecordById(id)
  11414. this.ServeSuccessJSON(map[string]interface{}{
  11415. "msg": "删除成功",
  11416. })
  11417. } else {
  11418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11419. return
  11420. }
  11421. }
  11422. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11423. id, _ := c.GetInt64("id")
  11424. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11425. c.ServeSuccessJSON(map[string]interface{}{
  11426. "advice": advice,
  11427. })
  11428. return
  11429. }
  11430. func (c *HisApiController) GetHisMonthChargePatientList() {
  11431. record_date := c.GetString("record_date")
  11432. start_time := c.GetString("start_time")
  11433. end_time := c.GetString("end_time")
  11434. timeLayout := "2006-01-02"
  11435. loc, _ := time.LoadLocation("Local")
  11436. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11437. if err != nil {
  11438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11439. return
  11440. }
  11441. if err != nil {
  11442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11443. return
  11444. }
  11445. recordDateTime := theTime.Unix()
  11446. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11447. if err != nil {
  11448. }
  11449. startRecordDateTime := startTime.Unix()
  11450. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11451. if err != nil {
  11452. }
  11453. endRecordDateTime := endTime.Unix()
  11454. adminInfo := c.GetAdminUserInfo()
  11455. var tempMonthChargePatients []*service.MonthChargePatients
  11456. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11457. for _, item := range tempPatients {
  11458. //过滤没有处方的
  11459. if len(item.HisPrescription) == 0 {
  11460. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11461. }
  11462. }
  11463. c.ServeSuccessJSON(map[string]interface{}{
  11464. "list": tempMonthChargePatients,
  11465. })
  11466. }
  11467. // PrescriptionDifference 医嘱数量差值结构体
  11468. type PrescriptionDrugDifference struct {
  11469. DrugID int64 //基础库药品id
  11470. ID int64 //医嘱id
  11471. Difference float64 //差值
  11472. Unit string //单位
  11473. }
  11474. type PrescriptionGoodDifference struct {
  11475. GoodID int64 //基础库项目耗材id
  11476. ID int64 //医嘱id
  11477. Difference int64 //差值
  11478. Unit string //单位
  11479. Type int64 //类型
  11480. }
  11481. type EditCustomData struct {
  11482. adviceList []*models.HisDoctorAdviceInfo
  11483. projectList []*models.HisPrescriptionProject
  11484. }
  11485. type SrcCustomData struct {
  11486. adviceList []*models.HisDoctorAdviceInfo
  11487. projectList []*models.HisPrescriptionProject
  11488. }
  11489. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11490. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11491. differences := make([]*PrescriptionDrugDifference, 0)
  11492. // 创建一个 map 来存储第一个切片中的药品信息
  11493. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11494. for _, advice := range firstPrescription {
  11495. firstMap[advice.DrugId] = advice
  11496. }
  11497. // 遍历第二个切片中的药品信息,并比较数量差值
  11498. for _, advice := range secondPrescription {
  11499. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11500. diff := &PrescriptionDrugDifference{
  11501. DrugID: advice.DrugId,
  11502. ID: firstAdvice.ID,
  11503. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11504. Unit: firstAdvice.PrescribingNumberUnit,
  11505. }
  11506. differences = append(differences, diff)
  11507. }
  11508. }
  11509. return differences
  11510. }
  11511. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11512. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11513. differences := make([]*PrescriptionGoodDifference, 0)
  11514. // 创建一个 map 来存储第一个切片中的耗材信息
  11515. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11516. for _, good := range firstPrescription {
  11517. firstMap[good.ProjectId] = good
  11518. }
  11519. // 遍历第二个切片中的耗材信息,并比较数量差值
  11520. for _, good := range secondPrescription {
  11521. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11522. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11523. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11524. diff := &PrescriptionGoodDifference{
  11525. GoodID: good.ProjectId,
  11526. ID: firstGood.ID,
  11527. Difference: count - firstCount,
  11528. Unit: firstGood.Unit,
  11529. Type: firstGood.Type,
  11530. }
  11531. differences = append(differences, diff)
  11532. }
  11533. }
  11534. return differences
  11535. }
  11536. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11537. var adviceList []*models.HisDoctorAdviceInfo
  11538. var projectList []*models.HisPrescriptionProject
  11539. var advice_ids []int64
  11540. var project_ids []int64
  11541. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11542. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11543. //var tempPrescription *models.HisPrescriptionProjectscription
  11544. if len(prescriptions) > 0 {
  11545. for _, item := range prescriptions {
  11546. items := item.(map[string]interface{})
  11547. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11548. advices := items["advices"].([]interface{})
  11549. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11550. groupNo := int64(0)
  11551. ctime := time.Now().Unix()
  11552. mtime := ctime
  11553. if len(advices) > 0 {
  11554. for _, advice := range advices {
  11555. var s models.HisDoctorAdviceInfo
  11556. s.AdviceType = 2
  11557. s.StopState = 2
  11558. s.ExecutionState = 2
  11559. s.Status = 1
  11560. s.Groupno = groupNo
  11561. s.CreatedTime = ctime
  11562. s.UpdatedTime = mtime
  11563. s.IsSettle = 2
  11564. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11565. //存储切片中
  11566. if s.ID > 0 {
  11567. advice_ids = append(advice_ids, s.ID)
  11568. adviceList = append(adviceList, &s)
  11569. }
  11570. }
  11571. }
  11572. }
  11573. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11574. projects := items["project"].([]interface{})
  11575. if len(projects) > 0 {
  11576. for _, project := range projects {
  11577. var p models.HisPrescriptionProject
  11578. p.Ctime = time.Now().Unix()
  11579. p.Mtime = time.Now().Unix()
  11580. p.Status = 1
  11581. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11582. if p.ID > 0 {
  11583. project_ids = append(project_ids, p.ID)
  11584. projectList = append(projectList, &p)
  11585. }
  11586. }
  11587. }
  11588. }
  11589. }
  11590. }
  11591. }
  11592. editCustomData.projectList = projectList
  11593. editCustomData.adviceList = adviceList
  11594. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11595. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11596. srcCustomData.adviceList = list
  11597. srcCustomData.projectList = list2
  11598. return
  11599. }