his_api_controller.go 513KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "his_info": his_patient_info,
  1461. "xt_info": xt_patient_info,
  1462. "prescription": prescriptions,
  1463. "case_history": case_history,
  1464. "info": patientPrescriptionInfo,
  1465. //"month_prescriptions": monthPrescriptions,
  1466. "order": order,
  1467. "doctors": doctors,
  1468. "department": department,
  1469. "sch_prescriptions": sch_prescriptions,
  1470. "last_prescriptions": last_prescriptions,
  1471. "schedule": sch,
  1472. "count": count,
  1473. "drugStockConfig": drugStockConfig,
  1474. "last_info": lastPatientPrescriptionInfo,
  1475. })
  1476. return
  1477. }
  1478. func (c *HisApiController) GetHisPrescriptionConfig() {
  1479. adminInfo := c.GetAdminUserInfo()
  1480. //获取医嘱模版
  1481. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1483. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1484. //获取所有基础药
  1485. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1486. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1487. if config.ID > 0 && config.IsOpen == 1 {
  1488. for _, item := range drugs {
  1489. var index = 0
  1490. for _, subItem := range item.OtherDrugWarehouseInfo {
  1491. if index == 0 {
  1492. index = index + 1
  1493. if subItem.RetailPrice > 0 {
  1494. item.MinPrice = subItem.RetailPrice
  1495. }
  1496. }
  1497. }
  1498. }
  1499. }
  1500. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1501. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1502. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1503. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1504. //获取所有科室信息
  1505. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1506. //获取诊断信息
  1507. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1508. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1509. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1510. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1511. //获取是否开启保存耗材出库的开关
  1512. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "drugs": drugs,
  1515. "advices_template": advices,
  1516. "drugways": drugways,
  1517. "efs": efs,
  1518. "doctors": doctors,
  1519. "department": department,
  1520. "sick": sick,
  1521. "additions": additions,
  1522. "diagnose": diagnose,
  1523. "manufacturers": manufacturers,
  1524. "goodOutOpen": goodOutOpen,
  1525. "patientDiagnose": patientDiagnose,
  1526. })
  1527. }
  1528. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1529. //获取所有基础药
  1530. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1531. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1532. if config.ID > 0 && config.IsOpen == 1 {
  1533. for _, item := range drugs {
  1534. var index = 0
  1535. for _, subItem := range item.OtherDrugWarehouseInfo {
  1536. if index == 0 {
  1537. index = index + 1
  1538. if subItem.RetailPrice > 0 {
  1539. item.MinPrice = subItem.RetailPrice
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1546. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1547. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1548. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1551. //获取诊断信息
  1552. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1553. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1554. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1555. //获取是否开启保存耗材出库的开关
  1556. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1557. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1558. c.ServeSuccessJSON(map[string]interface{}{
  1559. "drugs": drugs,
  1560. "advices_template": advices,
  1561. "drugways": drugways,
  1562. "efs": efs,
  1563. "doctors": doctors,
  1564. "department": department,
  1565. "sick": sick,
  1566. "additions": additions,
  1567. "diagnose": diagnose,
  1568. "manufacturers": manufacturers,
  1569. "goodOutOpen": goodOutOpen,
  1570. "patientDiagnose": patientDiagnose,
  1571. })
  1572. }
  1573. }
  1574. func (c *HisApiController) CreateHisPrescription() {
  1575. record_date := c.GetString("record_date")
  1576. patient_id, _ := c.GetInt64("patient_id")
  1577. reg_type, _ := c.GetInt64("reg_type")
  1578. diagnose := c.GetString("diagnose")
  1579. sick_type, _ := c.GetInt64("sick_type")
  1580. sick_history := c.GetString("sick_history")
  1581. doctor_id, _ := c.GetInt64("doctor", 0)
  1582. department, _ := c.GetInt64("department", 0)
  1583. his_patient_id, _ := c.GetInt64("his_patient_id")
  1584. p_type, _ := c.GetInt64("p_type")
  1585. patient_diagnose := c.GetString("patient_diagnose")
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //edit, src := GetCompareData(dataBody)
  1594. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1595. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1596. //fmt.Println(drugResult)
  1597. //fmt.Println(goodResult)
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. adminInfo := c.GetAdminUserInfo()
  1606. recordDateTime := theTime.Unix()
  1607. //查询默认出库仓库库存
  1608. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1610. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1611. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1612. if len(lists) == 1 {
  1613. his_patient_id = lists[0].ID
  1614. }
  1615. }
  1616. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1617. //自动出库的开关开启
  1618. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1619. //自动出库
  1620. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1621. //耗材保存处方出库
  1622. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1623. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1624. //已发药和已收费限制逻辑
  1625. isMidicine := false
  1626. isCharge := false
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1633. utils.ErrorLog("id")
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. id := int64(items["id"].(float64))
  1638. if id > 0 {
  1639. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1640. if err != nil {
  1641. if new_prescription.OrderStatus == 4 {
  1642. isCharge = true
  1643. }
  1644. }
  1645. }
  1646. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1647. advices := items["advices"].([]interface{})
  1648. if len(advices) > 0 {
  1649. for _, advice := range advices {
  1650. var adviceId int64
  1651. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1652. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1653. }
  1654. if adviceId > 0 {
  1655. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1656. if err == nil {
  1657. if his_advice_info.IsMedicine == 1 {
  1658. isMidicine = true
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. }
  1667. }
  1668. if isMidicine == true {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1670. return
  1671. }
  1672. if isCharge == true {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1674. return
  1675. }
  1676. // 开始主事务
  1677. db := service.XTWriteDB()
  1678. tx := db.Begin()
  1679. // 在函数结束时处理事务回滚
  1680. defer func() {
  1681. if r := recover(); r != nil {
  1682. tx.Rollback()
  1683. }
  1684. }()
  1685. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1686. //药品发药出库
  1687. if pharmacyConfig.IsOpen == 1 {
  1688. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1689. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1690. if len(prescriptions) > 0 {
  1691. for _, item := range prescriptions {
  1692. items := item.(map[string]interface{})
  1693. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1694. advices := items["advices"].([]interface{})
  1695. if len(advices) > 0 {
  1696. for _, advice := range advices {
  1697. var drug_id int64
  1698. var prescribing_number float64
  1699. var prescribingNumberUnit string
  1700. var adviceId int64
  1701. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1702. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1703. }
  1704. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1705. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1706. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1709. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1710. }
  1711. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1712. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1713. }
  1714. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1715. if drug.ID == 0 {
  1716. tx.Rollback()
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. //查询药品的所有库存
  1721. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1722. var total_count int64
  1723. for _, it := range list {
  1724. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1725. }
  1726. totals := strconv.FormatInt(total_count, 10)
  1727. //查询该药品是否存在开药记录
  1728. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1729. //新增处方盘点库存是否充足
  1730. if advicelist.ID == 0 {
  1731. all_count, _ := strconv.ParseFloat(totals, 64)
  1732. if prescribingNumberUnit == drug.MinUnit {
  1733. if drug.IsUse != 1 {
  1734. if drug.IsProject == 0 || drug.IsProject == 2 {
  1735. if all_count == 0 {
  1736. tx.Rollback()
  1737. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1738. return
  1739. }
  1740. if prescribing_number > all_count {
  1741. tx.Rollback()
  1742. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1743. return
  1744. }
  1745. }
  1746. }
  1747. }
  1748. if prescribingNumberUnit == drug.MaxUnit {
  1749. num := prescribing_number * float64(drug.MinNumber)
  1750. if drug.IsUse != 1 {
  1751. if drug.IsProject == 0 || drug.IsProject == 2 {
  1752. if all_count == 0 {
  1753. tx.Rollback()
  1754. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1755. return
  1756. }
  1757. if num > all_count {
  1758. tx.Rollback()
  1759. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1760. return
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1767. //不使用保存处方出库
  1768. if drugOutConfig.IsOpen != 1 {
  1769. //修改处方
  1770. for _, advice := range advices {
  1771. var drug_id int64
  1772. var prescribing_number float64
  1773. var prescribingNumberUnit string
  1774. var prescribingNumber string
  1775. var adviceId int64
  1776. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1777. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1778. }
  1779. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1780. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1781. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1782. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1783. }
  1784. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1785. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1786. }
  1787. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1788. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1789. }
  1790. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1791. if drug.ID == 0 {
  1792. tx.Rollback()
  1793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1794. return
  1795. }
  1796. //查询药品的所有库存
  1797. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1798. var total_count int64
  1799. for _, it := range list {
  1800. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1801. }
  1802. totals := strconv.FormatInt(total_count, 10)
  1803. //查询该药品是否存在开药记录
  1804. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1805. //新增处方
  1806. if advicelist.ID == 0 {
  1807. all_count, _ := strconv.ParseFloat(totals, 64)
  1808. if prescribingNumberUnit == drug.MinUnit {
  1809. if drug.IsUse != 1 {
  1810. if drug.IsProject == 0 || drug.IsProject == 2 {
  1811. if all_count == 0 {
  1812. tx.Rollback()
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. if prescribing_number > all_count {
  1817. tx.Rollback()
  1818. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1819. return
  1820. }
  1821. }
  1822. }
  1823. } else {
  1824. if prescribingNumberUnit == drug.MaxUnit {
  1825. num := prescribing_number * float64(drug.MinNumber)
  1826. if drug.IsUse != 1 {
  1827. if drug.IsProject == 0 || drug.IsProject == 2 {
  1828. if all_count == 0 {
  1829. tx.Rollback()
  1830. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1831. return
  1832. }
  1833. if num > all_count {
  1834. tx.Rollback()
  1835. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1836. return
  1837. }
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. //修改处方
  1844. if advicelist.ID > 0 {
  1845. var device_number int64
  1846. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1849. device_number = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1853. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1854. device_number = prescribingNumberInt
  1855. }
  1856. var number_count int64
  1857. if prescribingNumberUnit == drug.MaxUnit {
  1858. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1859. number_count = prescribingNumberInt * drug.MinNumber
  1860. }
  1861. if prescribingNumberUnit == drug.MinUnit {
  1862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1863. number_count = prescribingNumberInt
  1864. }
  1865. //如果修改的数量大于之前修改的数量
  1866. if (number_count - device_number) > 0 {
  1867. //如果修改的差数量 大于库存数量
  1868. if drug.IsUse != 1 {
  1869. if (number_count - device_number) > total_count {
  1870. tx.Rollback()
  1871. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1872. return
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. //已发药和已收费限制逻辑
  1887. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1888. //校验库存总量
  1889. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1890. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1891. if len(prescriptions) > 0 {
  1892. for _, item := range prescriptions {
  1893. items := item.(map[string]interface{})
  1894. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1895. advices := items["advices"].([]interface{})
  1896. if len(advices) > 0 {
  1897. for _, advice := range advices {
  1898. var drug_id int64
  1899. var prescribing_number float64
  1900. var prescribingNumberUnit string
  1901. var adviceId int64
  1902. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1903. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1904. }
  1905. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1906. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1907. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1908. }
  1909. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1910. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1911. }
  1912. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1913. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1914. }
  1915. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1916. if drug.ID == 0 {
  1917. tx.Rollback()
  1918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1919. return
  1920. }
  1921. //查询药品的所有库存
  1922. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1923. var total_count int64
  1924. for _, it := range list {
  1925. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1926. }
  1927. totals := strconv.FormatInt(total_count, 10)
  1928. //查询该药品是否存在开药记录
  1929. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1930. //查询最新批次库存
  1931. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1932. var batch_number_count int64
  1933. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1934. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1935. //新增处方
  1936. if advicelist.ID == 0 {
  1937. all_count, _ := strconv.ParseFloat(totals, 64)
  1938. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1939. if prescribingNumberUnit == drug.MinUnit {
  1940. if drug.IsUse != 1 {
  1941. if drug.IsProject == 0 || drug.IsProject == 2 {
  1942. if all_count == 0 {
  1943. tx.Rollback()
  1944. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1945. return
  1946. }
  1947. if prescribing_number > all_count {
  1948. tx.Rollback()
  1949. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1950. return
  1951. }
  1952. }
  1953. if adminInfo.CurrentOrgId == 10215 {
  1954. if prescribing_number > batch_number_all_count {
  1955. tx.Rollback()
  1956. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1957. return
  1958. }
  1959. }
  1960. }
  1961. }
  1962. if prescribingNumberUnit == drug.MaxUnit {
  1963. num := prescribing_number * float64(drug.MinNumber)
  1964. if drug.IsUse != 1 {
  1965. if drug.IsProject == 0 || drug.IsProject == 2 {
  1966. if all_count == 0 {
  1967. tx.Rollback()
  1968. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1969. return
  1970. }
  1971. if num > all_count {
  1972. tx.Rollback()
  1973. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1974. return
  1975. }
  1976. }
  1977. if adminInfo.CurrentOrgId == 10215 {
  1978. if num > batch_number_all_count {
  1979. tx.Rollback()
  1980. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1981. return
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1988. if drugOutConfig.IsOpen != 1 {
  1989. //修改处方
  1990. for _, advice := range advices {
  1991. var drug_id int64
  1992. var prescribing_number float64
  1993. var prescribingNumberUnit string
  1994. var prescribingNumber string
  1995. var adviceId int64
  1996. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1997. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1998. }
  1999. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2000. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2001. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2002. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2003. }
  2004. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2005. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2006. }
  2007. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2008. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2009. }
  2010. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2011. if drug.ID == 0 {
  2012. tx.Rollback()
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2014. return
  2015. }
  2016. //查询药品的所有库存
  2017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2018. var total_count int64
  2019. for _, it := range list {
  2020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2021. }
  2022. totals := strconv.FormatInt(total_count, 10)
  2023. //查询该药品是否存在开药记录
  2024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2025. //新增处方
  2026. if advicelist.ID == 0 {
  2027. //查询最新批次库存
  2028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2029. var batch_number_count int64
  2030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2032. all_count, _ := strconv.ParseFloat(totals, 64)
  2033. if prescribingNumberUnit == drug.MinUnit {
  2034. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2035. if drug.IsUse != 1 {
  2036. if drug.IsProject == 0 || drug.IsProject == 2 {
  2037. if all_count == 0 {
  2038. tx.Rollback()
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2040. return
  2041. }
  2042. if prescribing_number > all_count {
  2043. tx.Rollback()
  2044. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2045. return
  2046. }
  2047. }
  2048. if adminInfo.CurrentOrgId == 10215 {
  2049. if prescribing_number > batch_number_all_count {
  2050. tx.Rollback()
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2052. return
  2053. }
  2054. }
  2055. }
  2056. } else {
  2057. if prescribingNumberUnit == drug.MaxUnit {
  2058. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2059. num := prescribing_number * float64(drug.MinNumber)
  2060. if drug.IsUse != 1 {
  2061. if drug.IsProject == 0 || drug.IsProject == 2 {
  2062. if all_count == 0 {
  2063. tx.Rollback()
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2065. return
  2066. }
  2067. if num > all_count {
  2068. tx.Rollback()
  2069. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2070. return
  2071. }
  2072. }
  2073. if adminInfo.CurrentOrgId == 10215 {
  2074. if prescribing_number > batch_number_all_count {
  2075. tx.Rollback()
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2077. return
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. }
  2084. //修改处方
  2085. if advicelist.ID > 0 {
  2086. //查询最新批次库存
  2087. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2088. var batch_number_count int64
  2089. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2090. var device_number int64
  2091. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt * drug.MinNumber
  2095. }
  2096. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2097. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2099. device_number = prescribingNumberInt
  2100. }
  2101. var number_count int64
  2102. if prescribingNumberUnit == drug.MaxUnit {
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2104. number_count = prescribingNumberInt * drug.MinNumber
  2105. }
  2106. if prescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt
  2109. }
  2110. //如果修改的数量大于之前修改的数量
  2111. if (number_count - device_number) > 0 {
  2112. //如果修改的差数量 大于库存数量
  2113. if drug.IsUse != 1 {
  2114. if drug.IsProject == 0 || drug.IsProject == 2 {
  2115. if total_count == 0 {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if (number_count - device_number) > total_count {
  2121. tx.Rollback()
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2123. return
  2124. }
  2125. if (number_count - device_number) > batch_number_count {
  2126. tx.Rollback()
  2127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2128. return
  2129. }
  2130. }
  2131. if adminInfo.CurrentOrgId == 10215 {
  2132. // 查询该药品最后一次出库记录
  2133. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2134. var out_count int64
  2135. var in_count int64
  2136. var stock_max_number int64
  2137. var stock_min_number int64
  2138. for _, it := range outInfo {
  2139. if it.CountUnit == drug.MaxUnit {
  2140. it.Count = it.Count * drug.MinNumber
  2141. }
  2142. out_count += it.Count
  2143. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2144. stock_max_number = warehouseInfoList.StockMaxNumber
  2145. stock_min_number = warehouseInfoList.StockMinNumber
  2146. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2147. }
  2148. if out_count > 0 {
  2149. if (number_count - device_number) > in_count {
  2150. tx.Rollback()
  2151. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2152. return
  2153. }
  2154. }
  2155. // 未出库
  2156. if out_count == 0 {
  2157. var sum_in_count int64
  2158. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2159. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2160. fmt.Println("sum_in_count", sum_in_count)
  2161. //如果修改的数量大于有库存的第一个批次
  2162. if number_count > sum_in_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. if pharmacyConfig.IsOpen != 1 {
  2173. if device_number != number_count {
  2174. // 查询该药品最后一次出库记录
  2175. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2176. //回退库存
  2177. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2178. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2179. }
  2180. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2181. var stock_max_number int64
  2182. var stock_min_number int64
  2183. if number_count >= drug.MinNumber {
  2184. stock_max_number = device_number / drug.MinNumber
  2185. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2186. stock_min_number = device_number % drug.MinNumber
  2187. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2188. } else {
  2189. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2190. }
  2191. }
  2192. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2193. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2194. }
  2195. //删除记录
  2196. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2197. //查询默认仓库剩余多少库存
  2198. var sum_count int64
  2199. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2200. for _, its := range stockInfo {
  2201. if its.MaxUnit == drug.MaxUnit {
  2202. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2203. }
  2204. sum_count += its.StockMaxNumber + its.StockMinNumber
  2205. }
  2206. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. //保存处方开药
  2213. if drugOutConfig.IsOpen == 1 {
  2214. //修改处方
  2215. for _, advice := range advices {
  2216. var drug_id int64
  2217. var prescribing_number float64
  2218. var prescribingNumberUnit string
  2219. var prescribingNumber string
  2220. var adviceId int64
  2221. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2222. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2223. }
  2224. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2225. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2226. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2227. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2228. }
  2229. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2230. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2231. }
  2232. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2233. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2234. }
  2235. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2236. if drug.ID == 0 {
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2238. return
  2239. }
  2240. //查询药品的所有库存
  2241. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2242. var total_count int64
  2243. for _, it := range list {
  2244. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2245. }
  2246. totals := strconv.FormatInt(total_count, 10)
  2247. //查询该药品是否存在开药记录
  2248. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2249. //新增处方
  2250. if advicelist.ID == 0 {
  2251. //查询最新批次库存
  2252. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2253. var batch_number_count int64
  2254. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2255. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2256. all_count, _ := strconv.ParseFloat(totals, 64)
  2257. if prescribingNumberUnit == drug.MinUnit {
  2258. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2259. if drug.IsUse != 1 {
  2260. if drug.IsProject == 0 || drug.IsProject == 2 {
  2261. if all_count == 0 {
  2262. tx.Rollback()
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2264. return
  2265. }
  2266. if prescribing_number > all_count {
  2267. tx.Rollback()
  2268. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2269. return
  2270. }
  2271. }
  2272. if adminInfo.CurrentOrgId == 10215 {
  2273. if prescribing_number > batch_number_all_count {
  2274. tx.Rollback()
  2275. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2276. return
  2277. }
  2278. }
  2279. }
  2280. } else {
  2281. if prescribingNumberUnit == drug.MaxUnit {
  2282. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2283. num := prescribing_number * float64(drug.MinNumber)
  2284. if drug.IsUse != 1 {
  2285. if drug.IsProject == 0 || drug.IsProject == 2 {
  2286. if all_count == 0 {
  2287. tx.Rollback()
  2288. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2289. return
  2290. }
  2291. if num > all_count {
  2292. tx.Rollback()
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. }
  2297. if adminInfo.CurrentOrgId == 10215 {
  2298. if prescribing_number > batch_number_all_count {
  2299. tx.Rollback()
  2300. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2301. return
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. //修改处方
  2309. if advicelist.ID > 0 {
  2310. //查询最新批次库存
  2311. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2312. var batch_number_count int64
  2313. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2314. var device_number int64
  2315. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2316. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2317. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2318. device_number = prescribingNumberInt * drug.MinNumber
  2319. }
  2320. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2321. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2322. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2323. device_number = prescribingNumberInt
  2324. }
  2325. var number_count int64
  2326. if prescribingNumberUnit == drug.MaxUnit {
  2327. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2328. number_count = prescribingNumberInt * drug.MinNumber
  2329. }
  2330. if prescribingNumberUnit == drug.MinUnit {
  2331. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2332. number_count = prescribingNumberInt
  2333. }
  2334. fmt.Println("number_count--------------", number_count)
  2335. fmt.Println("device_number--------------", device_number)
  2336. fmt.Println("batch_number_count", batch_number_count)
  2337. //如果修改的数量大于之前修改的数量
  2338. if (number_count - device_number) > 0 {
  2339. //如果修改的差数量 大于库存数量
  2340. if drug.IsUse != 1 {
  2341. if drug.IsProject == 0 || drug.IsProject == 2 {
  2342. if total_count == 0 {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2345. return
  2346. }
  2347. if (number_count - device_number) > total_count {
  2348. tx.Rollback()
  2349. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2350. return
  2351. }
  2352. }
  2353. if adminInfo.CurrentOrgId == 10215 {
  2354. if (number_count - device_number) > batch_number_count {
  2355. tx.Rollback()
  2356. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2357. return
  2358. }
  2359. }
  2360. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2361. //查询历史出库数据总批次
  2362. // 查询该药品最后一次出库记录
  2363. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2364. var out_count int64
  2365. var in_count int64
  2366. var stock_max_number int64
  2367. var stock_min_number int64
  2368. for _, it := range outInfo {
  2369. if it.CountUnit == drug.MaxUnit {
  2370. it.Count = it.Count * drug.MinNumber
  2371. }
  2372. out_count += it.Count
  2373. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2374. stock_max_number = warehouseInfoList.StockMaxNumber
  2375. stock_min_number = warehouseInfoList.StockMinNumber
  2376. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2377. }
  2378. if out_count > 0 {
  2379. if (number_count - device_number) > in_count {
  2380. tx.Rollback()
  2381. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2382. return
  2383. }
  2384. }
  2385. // 未出库
  2386. if out_count == 0 {
  2387. var sum_in_count int64
  2388. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2389. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2390. if sum_in_count == 0 {
  2391. tx.Rollback()
  2392. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2393. return
  2394. }
  2395. //如果修改的数量大于有库存的第一个批次
  2396. if number_count > sum_in_count {
  2397. tx.Rollback()
  2398. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2399. return
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. //校验耗材库存
  2416. if goodOutConfig.IsOpen == 1 {
  2417. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2418. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2419. if len(prescriptions) > 0 {
  2420. for _, item := range prescriptions {
  2421. items := item.(map[string]interface{})
  2422. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2423. projects := items["project"].([]interface{})
  2424. if len(projects) > 0 {
  2425. for _, project := range projects {
  2426. var project_id int64
  2427. var project_type int64
  2428. var totals float64
  2429. var project_name string
  2430. var parsetotal int64
  2431. var id int64
  2432. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2433. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2434. }
  2435. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2436. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2437. }
  2438. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2439. total, _ := project.(map[string]interface{})["total"].(string)
  2440. totals, _ = strconv.ParseFloat(total, 64)
  2441. }
  2442. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2443. project_name = project.(map[string]interface{})["project_name"].(string)
  2444. }
  2445. if project_type == 3 {
  2446. //查找该耗材的出库记录
  2447. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2448. if len(goodWarehouseInfo) == 0 {
  2449. //查询耗材库存
  2450. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2451. var stock_count int64
  2452. for _, it := range list {
  2453. stock_count += it.StockCount
  2454. }
  2455. stock_counts := strconv.FormatInt(stock_count, 10)
  2456. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2457. if stock_total_count == 0 {
  2458. tx.Rollback()
  2459. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2460. return
  2461. }
  2462. if totals > stock_total_count {
  2463. tx.Rollback()
  2464. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2465. return
  2466. }
  2467. }
  2468. if len(goodWarehouseInfo) > 0 {
  2469. //查询该患者耗材的历史数据
  2470. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2471. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2472. //数量发生改变
  2473. if parsetotal != count {
  2474. //如果现在的数量大于历史数量,就要看库存是否足够
  2475. if parsetotal > count {
  2476. //查询耗材所有库存
  2477. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2478. var stock_count int64
  2479. for _, it := range list {
  2480. stock_count += it.StockCount
  2481. }
  2482. //库存不足
  2483. if stock_count == 0 {
  2484. tx.Rollback()
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. if (parsetotal - count) > stock_count {
  2489. tx.Rollback()
  2490. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2491. return
  2492. }
  2493. }
  2494. }
  2495. }
  2496. }
  2497. }
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. //不使用耗材保存处方出库
  2505. if goodOutConfig.IsOpen != 1 {
  2506. if stockConfig.IsOpen == 1 {
  2507. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2508. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2509. if len(prescriptions) > 0 {
  2510. for _, item := range prescriptions {
  2511. items := item.(map[string]interface{})
  2512. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2513. projects := items["project"].([]interface{})
  2514. if len(projects) > 0 {
  2515. for _, project := range projects {
  2516. var project_id int64
  2517. var project_type int64
  2518. var totals float64
  2519. var project_name string
  2520. var parsetotal int64
  2521. var id int64
  2522. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2523. id = int64(project.(map[string]interface{})["id"].(float64))
  2524. }
  2525. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2526. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2527. }
  2528. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2529. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2530. }
  2531. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2532. total, _ := project.(map[string]interface{})["total"].(string)
  2533. totals, _ = strconv.ParseFloat(total, 64)
  2534. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2535. }
  2536. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2537. project_name = project.(map[string]interface{})["project_name"].(string)
  2538. }
  2539. if project_type == 3 {
  2540. //查找该耗材的出库记录
  2541. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2542. //没有出库记录
  2543. if len(goodWarehouseInfo) == 0 {
  2544. //查询耗材库存
  2545. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2546. var stock_count int64
  2547. for _, it := range list {
  2548. stock_count += it.StockCount
  2549. }
  2550. stock_counts := strconv.FormatInt(stock_count, 10)
  2551. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2552. if stock_total_count == 0 {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2555. return
  2556. }
  2557. if totals > stock_total_count {
  2558. tx.Rollback()
  2559. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2560. return
  2561. }
  2562. //查找今日该患者已经出库的所有耗材
  2563. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2564. for _, item := range goodList {
  2565. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2566. var flush_count int64
  2567. for _, it := range goodListSix {
  2568. flush_count += it.StockCount
  2569. }
  2570. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2571. creater := adminInfo.AdminUser.Id
  2572. if errs != nil {
  2573. goodErrcode := models.XtGoodErrcode{
  2574. UserOrgId: item.OrgId,
  2575. Errcode: "手动出库更新剩余出库失败",
  2576. GoodId: item.GoodId,
  2577. Status: 1,
  2578. Ctime: time.Now().Unix(),
  2579. Mtime: 0,
  2580. Count: 0,
  2581. StockCount: 0,
  2582. Creater: creater,
  2583. BatchNumberId: 0,
  2584. WarehouseOutId: 0,
  2585. }
  2586. service.CreateGoodErrcode(goodErrcode)
  2587. }
  2588. }
  2589. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2590. }
  2591. //有出库记录
  2592. if len(goodWarehouseInfo) > 0 {
  2593. //查询该患者耗材的历史数据
  2594. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2595. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2596. //数量发生改变
  2597. if parsetotal != count {
  2598. //查找今日该患者已经出库的所有耗材
  2599. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2600. for _, item := range goodList {
  2601. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2602. var flush_count int64
  2603. for _, it := range goodListSix {
  2604. flush_count += it.StockCount
  2605. }
  2606. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2607. //减少出库数量
  2608. creater := adminInfo.AdminUser.Id
  2609. if errs != nil {
  2610. goodErrcode := models.XtGoodErrcode{
  2611. UserOrgId: item.OrgId,
  2612. Errcode: "手动出库更新剩余出库失败",
  2613. GoodId: item.GoodId,
  2614. Status: 1,
  2615. Ctime: time.Now().Unix(),
  2616. Mtime: 0,
  2617. Count: 0,
  2618. StockCount: 0,
  2619. Creater: creater,
  2620. BatchNumberId: 0,
  2621. WarehouseOutId: 0,
  2622. }
  2623. service.CreateGoodErrcode(goodErrcode)
  2624. }
  2625. //查询默认仓库
  2626. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2627. var total_count int64
  2628. for _, it := range stockList {
  2629. total_count += it.StockCount
  2630. }
  2631. //基础库插入数据
  2632. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2633. }
  2634. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2635. }
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2647. var hpInfo models.HisPrescriptionInfo
  2648. if info.ID == 0 {
  2649. var randNum int
  2650. randNum = rand.Intn(10000) + 1000
  2651. timestamp := time.Now().Unix()
  2652. tempTime := time.Unix(timestamp, 0)
  2653. timeFormat := tempTime.Format("20060102150405")
  2654. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2655. hpInfo = models.HisPrescriptionInfo{
  2656. HisPatientId: his_patient_id,
  2657. UserOrgId: adminInfo.CurrentOrgId,
  2658. RecordDate: theTime.Unix(),
  2659. PatientId: patient_id,
  2660. Status: 1,
  2661. Ctime: time.Now().Unix(),
  2662. Mtime: time.Now().Unix(),
  2663. Creator: adminInfo.AdminUser.Id,
  2664. Modifier: adminInfo.AdminUser.Id,
  2665. Diagnosis: diagnose,
  2666. SickHistory: sick_history,
  2667. Departments: department,
  2668. RegisterType: reg_type,
  2669. PrescriptionNumber: p_number,
  2670. PrescriptionStatus: 1,
  2671. Doctor: role.UserName,
  2672. DoctorId: doctor_id,
  2673. SickType: sick_type,
  2674. PType: p_type,
  2675. PatientDiagnosis: patient_diagnose,
  2676. }
  2677. service.SavePatientPrescriptionInfo(hpInfo)
  2678. //创建步骤表
  2679. finish := models.XtDialysisFinish{
  2680. IsFinish: 1,
  2681. UserOrgId: adminInfo.CurrentOrgId,
  2682. Status: 1,
  2683. Ctime: time.Now().Unix(),
  2684. Mtime: 0,
  2685. Module: 4,
  2686. RecordDate: theTime.Unix(),
  2687. Sourse: 1,
  2688. PatientId: patient_id,
  2689. }
  2690. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2691. if dialysisFinish.ID == 0 {
  2692. service.CreateDialysisFinish(finish)
  2693. }
  2694. redis := service.RedisClient()
  2695. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2696. redis.Set(key, "", time.Second)
  2697. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2698. redis.Set(keyOne, "", time.Second)
  2699. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2700. redis.Set(keySeven, "", time.Second)
  2701. defer redis.Close()
  2702. } else {
  2703. hpInfo = models.HisPrescriptionInfo{
  2704. ID: info.ID,
  2705. UserOrgId: adminInfo.CurrentOrgId,
  2706. RecordDate: info.RecordDate,
  2707. PatientId: info.PatientId,
  2708. Status: 1,
  2709. Ctime: info.Ctime,
  2710. Mtime: time.Now().Unix(),
  2711. Creator: info.Creator,
  2712. Modifier: adminInfo.AdminUser.Id,
  2713. Diagnosis: diagnose,
  2714. SickHistory: sick_history,
  2715. Departments: department,
  2716. RegisterType: reg_type,
  2717. PrescriptionNumber: info.PrescriptionNumber,
  2718. Doctor: role.UserName,
  2719. PrescriptionStatus: info.PrescriptionStatus,
  2720. DoctorId: doctor_id,
  2721. SickType: sick_type,
  2722. PType: info.PType,
  2723. HisPatientId: info.HisPatientId,
  2724. PatientDiagnosis: patient_diagnose,
  2725. }
  2726. service.SavePatientPrescriptionInfo(hpInfo)
  2727. //创建步骤表
  2728. finish := models.XtDialysisFinish{
  2729. IsFinish: 1,
  2730. UserOrgId: adminInfo.CurrentOrgId,
  2731. Status: 1,
  2732. Ctime: time.Now().Unix(),
  2733. Mtime: 0,
  2734. Module: 4,
  2735. RecordDate: info.RecordDate,
  2736. Sourse: 1,
  2737. PatientId: info.PatientId,
  2738. }
  2739. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2740. if dialysisFinish.ID == 0 {
  2741. service.CreateDialysisFinish(finish)
  2742. }
  2743. redis := service.RedisClient()
  2744. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2745. redis.Set(key, "", time.Second)
  2746. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2747. redis.Set(keyOne, "", time.Second)
  2748. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2749. redis.Set(keySeven, "", time.Second)
  2750. defer redis.Close()
  2751. }
  2752. //定义切片
  2753. var adviceList []models.HisDoctorAdviceInfo
  2754. var projectList []models.HisPrescriptionProject
  2755. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10610 {
  2756. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2757. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2758. var tempPrescription *models.HisPrescription
  2759. if len(prescriptions) > 0 {
  2760. for _, item := range prescriptions {
  2761. // 开始外部循环的事务
  2762. tx := db.Begin()
  2763. // 在函数结束时处理事务回滚
  2764. defer func() {
  2765. if r := recover(); r != nil {
  2766. tx.Rollback()
  2767. }
  2768. }()
  2769. items := item.(map[string]interface{})
  2770. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2771. utils.ErrorLog("id")
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2773. return
  2774. }
  2775. id := int64(items["id"].(float64))
  2776. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2777. tempPrescription = &new_prescription
  2778. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2779. utils.ErrorLog("type")
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2781. return
  2782. }
  2783. types := int64(items["type"].(float64))
  2784. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2785. utils.ErrorLog("med_type")
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. return
  2788. }
  2789. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2790. if med_type == "0" {
  2791. med_type = "14"
  2792. }
  2793. //if order_status == 0 {
  2794. // order_status = 1
  2795. //}
  2796. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2797. utils.ErrorLog("pre_time")
  2798. }
  2799. preTime, _ := items["pre_time"].(string)
  2800. fmt.Println("preTime", preTime)
  2801. timeLayout := "2006-01-02"
  2802. loc, _ := time.LoadLocation("Local")
  2803. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2804. result := strings.Split(preTime, " ")
  2805. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2806. if err != nil {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. pTime := theTime2.Unix()
  2811. ctime := time.Now().Unix()
  2812. if tempPrescription.ID == 0 {
  2813. prescription := &models.HisPrescription{
  2814. ID: 0,
  2815. PatientId: patient_id,
  2816. UserOrgId: adminInfo.CurrentOrgId,
  2817. RecordDate: recordDateTime,
  2818. Ctime: ctime,
  2819. Mtime: ctime,
  2820. Type: types,
  2821. Modifier: adminInfo.AdminUser.Id,
  2822. Creator: adminInfo.AdminUser.Id,
  2823. Status: 1,
  2824. Doctor: role.UserName,
  2825. HisPatientId: his_patient_id,
  2826. OrderStatus: 1,
  2827. BatchNumber: "",
  2828. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2829. PreTime: pTime,
  2830. PType: p_type,
  2831. MedType: med_type,
  2832. }
  2833. tempPrescription = prescription
  2834. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2835. redis := service.RedisClient()
  2836. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2837. redis.Set(key, "", time.Second)
  2838. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2839. redis.Set(keyOne, "", time.Second)
  2840. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2841. redis.Set(keySeven, "", time.Second)
  2842. defer redis.Close()
  2843. } else {
  2844. tempPrescription.ID = id
  2845. tempPrescription.Type = types
  2846. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2847. tempPrescription.Mtime = time.Now().Unix()
  2848. tempPrescription.Doctor = role.UserName
  2849. //tempPrescription.OrderStatus = order_status
  2850. tempPrescription.PreTime = pTime
  2851. tempPrescription.MedType = med_type
  2852. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2853. redis := service.RedisClient()
  2854. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2855. redis.Set(key, "", time.Second)
  2856. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2857. redis.Set(keyOne, "", time.Second)
  2858. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2859. redis.Set(keySeven, "", time.Second)
  2860. defer redis.Close()
  2861. }
  2862. //service.SaveHisPrescription(prescription)
  2863. //更改患者挂号状态
  2864. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2865. fmt.Println("更改失败", err2)
  2866. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2867. advices := items["advices"].([]interface{})
  2868. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2869. groupNo := int64(0)
  2870. if len(advices) > 0 {
  2871. for _, advice := range advices {
  2872. tx := db.Begin()
  2873. // 在函数结束时处理事务回滚
  2874. defer func() {
  2875. if r := recover(); r != nil {
  2876. tx.Rollback()
  2877. }
  2878. }()
  2879. var s models.HisDoctorAdviceInfo
  2880. s.PrescriptionId = tempPrescription.ID
  2881. s.AdviceType = 2
  2882. s.AdviceDoctor = doctor_id
  2883. s.StopState = 2
  2884. s.ExecutionState = 2
  2885. s.AdviceDate = theTime3.Unix()
  2886. s.Status = 1
  2887. s.UserOrgId = adminInfo.CurrentOrgId
  2888. s.RecordDate = theTime3.Unix()
  2889. s.StartTime = tempPrescription.PreTime
  2890. s.Groupno = groupNo
  2891. s.PatientId = patient_id
  2892. s.HisPatientId = his_patient_id
  2893. s.StartTime = pTime
  2894. s.IsSettle = 2
  2895. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2896. if errcode > 0 {
  2897. c.ServeFailJSONWithSGJErrorCode(errcode)
  2898. return
  2899. }
  2900. s.StartTime = pTime
  2901. var total_count int64 //处方总库存
  2902. //查询改药品信息
  2903. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2904. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2905. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2906. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2907. total_count += prescribingNumberSeven * medical.MinNumber
  2908. }
  2909. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2910. total_count += prescribingNumberSeven
  2911. }
  2912. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2913. total_count += prescribingNumberSeven
  2914. }
  2915. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2916. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2917. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2918. if s.Price != lastWarehouse.RetailPrice {
  2919. s.Price = lastWarehouse.RetailPrice
  2920. }
  2921. if s.Price == 0 {
  2922. if lastWarehouse.ID == 0 {
  2923. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2924. s.Price = lastWarehouseTwo.RetailPrice
  2925. }
  2926. }
  2927. }
  2928. //查询保存处方出库开关是否打开
  2929. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2930. if s.PatientId != 30038 {
  2931. if drugOutConfig.IsOpen == 1 {
  2932. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2933. // 查询该药品最后一次出库记录
  2934. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2935. var is_user_total int64
  2936. var no_user_total int64
  2937. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2938. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2939. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2940. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2941. }
  2942. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2943. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2944. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2945. no_user_total += prescribingNumberSevenTy
  2946. }
  2947. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2948. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2949. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2950. no_user_total += prescribingNumberSevenTy
  2951. }
  2952. if len(druginfo) > 0 {
  2953. for _, it := range druginfo {
  2954. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2955. it.Count = it.Count * drug.MinNumber
  2956. is_user_total += it.Count
  2957. }
  2958. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2959. is_user_total += it.Count
  2960. }
  2961. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2962. is_user_total += it.Count
  2963. }
  2964. }
  2965. }
  2966. if is_user_total != no_user_total {
  2967. //出库
  2968. if drug.IsUse == 2 {
  2969. creater := adminInfo.AdminUser.Id
  2970. newadviceInfo := &models.HisDoctorAdviceInfo{
  2971. ID: s.ID,
  2972. UserOrgId: s.UserOrgId,
  2973. PatientId: s.PatientId,
  2974. HisPatientId: s.HisPatientId,
  2975. AdviceType: s.AdviceType,
  2976. AdviceDate: s.AdviceDate,
  2977. StartTime: s.StartTime,
  2978. AdviceName: s.AdviceName,
  2979. AdviceDesc: s.AdviceDesc,
  2980. ReminderDate: s.ReminderDate,
  2981. SingleDose: s.SingleDose,
  2982. SingleDoseUnit: s.SingleDoseUnit,
  2983. PrescribingNumber: s.PrescribingNumber,
  2984. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2985. DeliveryWay: s.DeliveryWay,
  2986. ExecutionFrequency: s.ExecutionFrequency,
  2987. AdviceDoctor: s.AdviceDoctor,
  2988. Status: s.Status,
  2989. CreatedTime: s.CreatedTime,
  2990. UpdatedTime: s.UpdatedTime,
  2991. AdviceAffirm: s.AdviceAffirm,
  2992. Remark: s.Remark,
  2993. StopTime: s.StopTime,
  2994. StopReason: s.StopReason,
  2995. StopDoctor: s.StopDoctor,
  2996. StopState: s.StopState,
  2997. ParentId: s.ParentId,
  2998. ExecutionTime: s.ExecutionTime,
  2999. ExecutionStaff: s.ExecutionStaff,
  3000. ExecutionState: s.ExecutionState,
  3001. Checker: s.Checker,
  3002. RecordDate: s.RecordDate,
  3003. DialysisOrderId: s.DialysisOrderId,
  3004. CheckTime: s.CheckTime,
  3005. CheckState: s.CheckState,
  3006. DrugSpec: s.DrugSpec,
  3007. DrugSpecUnit: s.DrugSpecUnit,
  3008. Groupno: s.Groupno,
  3009. RemindType: s.RemindType,
  3010. FrequencyType: s.FrequencyType,
  3011. DayCount: s.DayCount,
  3012. WeekDay: s.WeekDay,
  3013. TemplateId: s.TemplateId,
  3014. Modifier: s.Modifier,
  3015. DrugId: s.DrugId,
  3016. Price: s.Price,
  3017. PrescriptionId: s.PrescriptionId,
  3018. MedListCodg: s.MedListCodg,
  3019. FeedetlSn: s.FeedetlSn,
  3020. Day: s.DayCount,
  3021. ChildDoctorAdvice: nil,
  3022. Drug: models.Drug{},
  3023. Diagnosis: s.Diagnosis,
  3024. Way: s.Way,
  3025. HospApprFlag: s.HospApprFlag,
  3026. LmtUsedFlag: s.LmtUsedFlag,
  3027. HisOrderInfo: models.HisOrderInfo{},
  3028. IsMedicine: s.IsMedicine,
  3029. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3030. Child: nil,
  3031. IsSettle: s.IsSettle,
  3032. IsMobile: s.IsMobile,
  3033. IsSelfDrug: s.IsSelfDrug,
  3034. DrugWayCount: s.DrugWayCount,
  3035. }
  3036. var history_count int64
  3037. var local_count int64
  3038. //查找已经开过的医嘱信息
  3039. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3040. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3041. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3042. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3043. local_count += prescribingNumberSevenTy * drug.MinNumber
  3044. }
  3045. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3046. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3047. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3048. local_count += prescribingNumberSevenTy
  3049. }
  3050. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3051. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3052. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3053. local_count += prescribingNumberSevenTy
  3054. }
  3055. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3056. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3057. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3058. history_count += prescribingNumberSevenTy * drug.MinNumber
  3059. }
  3060. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3061. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3062. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3063. history_count += prescribingNumberSevenTy
  3064. }
  3065. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3066. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3067. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3068. history_count += prescribingNumberSevenTy
  3069. }
  3070. //fmt.Println("local_count0000000000000000000000000000000000000000000", local_count)
  3071. //
  3072. //fmt.Println("history_count999999999999999999999999999999999999999", history_count)
  3073. //如果当前出库数量大于历史出库数量则需要出库
  3074. if local_count > history_count {
  3075. //按最小单位出库
  3076. var cha_count = local_count - history_count
  3077. //fmt.Println("cha_count000000000000000000000000000", cha_count)
  3078. newadviceInfo.PrescribingNumber = float64(cha_count)
  3079. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3080. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3081. }
  3082. //如果当前出库数量小于历史出库数量则需要退库
  3083. if local_count < history_count {
  3084. var cha_count = history_count - local_count
  3085. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3086. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3087. }
  3088. }
  3089. //更新字典里面的库存
  3090. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3091. var sum_count int64
  3092. for _, its := range stockInfo {
  3093. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3094. if its.MaxUnit == baseDrug.MaxUnit {
  3095. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3096. }
  3097. sum_count += its.StockMaxNumber + its.StockMinNumber
  3098. }
  3099. //更新基础库存
  3100. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3101. //剩余库存
  3102. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3103. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3104. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3105. //创建医嘱
  3106. service.CreateHisDoctorAdviceOne(&s, tx)
  3107. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3108. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3109. if len(outInfoTwo) > 0 {
  3110. for _, item := range outInfoTwo {
  3111. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3112. }
  3113. }
  3114. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3115. if len(drugAutoDetail) > 0 {
  3116. for _, item := range drugAutoDetail {
  3117. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3118. }
  3119. }
  3120. }
  3121. }
  3122. }
  3123. //记录日志
  3124. byterequest, _ := json.Marshal(s)
  3125. adviceLog := models.XtDoctorAdviceLog{
  3126. UserOrgId: s.UserOrgId,
  3127. PatientId: s.PatientId,
  3128. AdminUserId: adminInfo.AdminUser.Id,
  3129. Module: 1,
  3130. ErrLog: string(byterequest),
  3131. Status: 1,
  3132. Ctime: time.Now().Unix(),
  3133. Mtime: 0,
  3134. Source: "电脑端新建his医嘱",
  3135. RecordDate: s.AdviceDate,
  3136. }
  3137. service.CreateDoctorAdviceLog(adviceLog)
  3138. //存储切片中
  3139. adviceList = append(adviceList, s)
  3140. redis := service.RedisClient()
  3141. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3142. redis.Set(key, "", time.Second)
  3143. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3144. redis.Set(keyOne, "", time.Second)
  3145. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3146. redis.Set(keySeven, "", time.Second)
  3147. var randNum int
  3148. randNum = rand.Intn(10000) + 1000
  3149. timestamp := time.Now().Unix()
  3150. tempTime := time.Unix(timestamp, 0)
  3151. timeFormat := tempTime.Format("20060102150405")
  3152. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3153. //查询改药品是否已经停用
  3154. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3155. if base.ID > 0 {
  3156. tx.Rollback()
  3157. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3158. return
  3159. }
  3160. service.CreateHisDoctorAdviceOne(&s, tx)
  3161. tx.Commit()
  3162. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3163. redis.Set(keySix, "", time.Second)
  3164. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3165. redis.Set(keyFive, "", time.Second)
  3166. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3167. redis.Set(keyEight, "", time.Second)
  3168. defer redis.Close()
  3169. }
  3170. }
  3171. }
  3172. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3173. projects := items["project"].([]interface{})
  3174. if len(projects) > 0 {
  3175. for _, project := range projects {
  3176. tx := db.Begin()
  3177. // 在函数结束时处理事务回滚
  3178. defer func() {
  3179. if r := recover(); r != nil {
  3180. tx.Rollback()
  3181. }
  3182. }()
  3183. var p models.HisPrescriptionProject
  3184. p.PrescriptionId = tempPrescription.ID
  3185. p.PatientId = patient_id
  3186. p.RecordDate = theTime3.Unix()
  3187. p.Doctor = doctor_id
  3188. p.UserOrgId = adminInfo.CurrentOrgId
  3189. p.HisPatientId = his_patient_id
  3190. p.Status = 1
  3191. p.StartTime = pTime
  3192. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3193. if errcode > 0 {
  3194. c.ServeFailJSONWithSGJErrorCode(errcode)
  3195. return
  3196. }
  3197. if p.ID == 0 {
  3198. p.IsOut = 2
  3199. }
  3200. if p.ID > 0 {
  3201. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3202. p.IsOut = projectDetail.IsOut
  3203. }
  3204. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3205. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3206. if p.Type == 3 {
  3207. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3208. if p.Price != lastWarehouse.PackingPrice {
  3209. p.Price = lastWarehouse.PackingPrice
  3210. }
  3211. if p.Unit == "" {
  3212. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3213. p.Unit = goodInfoOne.PackingUnit
  3214. }
  3215. }
  3216. }
  3217. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3218. //
  3219. // if p.Type == 3 {
  3220. // //查询该耗材是否停用
  3221. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3222. // //表示该耗材已经停用,不能保存
  3223. // if goodInfoSeven.ID == 0 {
  3224. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3225. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3226. // return
  3227. // }
  3228. // }
  3229. //
  3230. //}
  3231. //查询保存耗材出库开关是否打开
  3232. if p.PatientId != 30038 {
  3233. if goodOutConfig.IsOpen == 1 {
  3234. //耗材出库
  3235. if p.Type == 3 {
  3236. //对比当前数据和历史出库数据
  3237. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3238. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3239. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3240. //如果当前处方数量大于历史数据,则需要出库
  3241. if nowCount > historyCount {
  3242. var cha_count int64
  3243. cha_count = nowCount - historyCount
  3244. timeStr := time.Now().Format("2006-01-02")
  3245. timeArr := strings.Split(timeStr, "-")
  3246. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3247. total = total + 1
  3248. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3249. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3250. number = number + total
  3251. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3252. operation_time := time.Now().Unix()
  3253. creater := c.GetAdminUserInfo().AdminUser.Id
  3254. recordDateStr := time.Now().Format("2006-01-02")
  3255. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3256. nowtime := recordDate.Unix()
  3257. warehouseOut := models.WarehouseOut{
  3258. WarehouseOutOrderNumber: warehousing_out_order,
  3259. OperationTime: operation_time,
  3260. OrgId: adminInfo.CurrentOrgId,
  3261. Creater: creater,
  3262. Ctime: time.Now().Unix(),
  3263. Status: 1,
  3264. WarehouseOutTime: nowtime,
  3265. Type: 1,
  3266. StorehouseId: storeConfig.StorehouseOutInfo,
  3267. IsCheck: 1,
  3268. IsSys: 1,
  3269. }
  3270. //查询是否生成出库单
  3271. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3272. if out.ID == 0 {
  3273. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3274. }
  3275. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3276. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3277. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3278. dialyPrepareOne := models.DialysisBeforePrepare{
  3279. GoodTypeId: goodObj.GoodTypeId,
  3280. GoodId: p.ProjectId,
  3281. PatientId: p.PatientId,
  3282. RecordDate: p.RecordDate,
  3283. UserOrgId: adminInfo.CurrentOrgId,
  3284. Count: cha_count,
  3285. Ctime: time.Now().Unix(),
  3286. Creater: creater,
  3287. Status: 1,
  3288. StorehouseId: houseConfig.StorehouseOutInfo,
  3289. ProjectId: p.ID,
  3290. }
  3291. //出库
  3292. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3293. }
  3294. //如果当前处方数量小于历史数据,怎需要退库
  3295. if nowCount < historyCount {
  3296. var cha_count int64
  3297. cha_count = historyCount - nowCount
  3298. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3299. creater := c.GetAdminUserInfo().AdminUser.Id
  3300. newPrescriptionProject := &models.HisPrescriptionProject{
  3301. ID: p.ID,
  3302. ProjectId: p.ProjectId,
  3303. Price: p.Price,
  3304. UserOrgId: p.UserOrgId,
  3305. Status: 1,
  3306. Ctime: time.Now().Unix(),
  3307. Mtime: time.Now().Unix(),
  3308. PatientId: p.PatientId,
  3309. HisPatientId: p.HisPatientId,
  3310. RecordDate: p.RecordDate,
  3311. PrescriptionId: p.PrescriptionId,
  3312. Count: p.Count,
  3313. FeedetlSn: p.FeedetlSn,
  3314. MedListCodg: p.MedListCodg,
  3315. SingleDose: p.SingleDose,
  3316. DeliveryWay: p.DeliveryWay,
  3317. ExecutionFrequency: p.ExecutionFrequency,
  3318. Day: p.Day,
  3319. HisProject: models.HisProject{},
  3320. GoodInfo: models.GoodInfo{},
  3321. Remark: p.Remark,
  3322. Unit: p.Unit,
  3323. Type: p.Type,
  3324. Doctor: p.Doctor,
  3325. ExecutionTime: p.ExecutionTime,
  3326. ExecutionStaff: p.ExecutionStaff,
  3327. ExecutionState: p.ExecutionState,
  3328. CheckTime: p.CheckTime,
  3329. CheckState: p.CheckState,
  3330. Checker: p.Checker,
  3331. StartTime: p.StartTime,
  3332. TeamId: p.TeamId,
  3333. XtHisProjectTeam: models.XtHisProjectTeam{},
  3334. FrequencyType: p.FrequencyType,
  3335. DayCount: p.DayCount,
  3336. WeekDay: p.WeekDay,
  3337. IsCheckTeam: p.IsCheckTeam,
  3338. HisOrderInfo: models.HisOrderInfo{},
  3339. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3340. IsOut: p.IsOut,
  3341. YbSyncStatus: p.YbSyncStatus,
  3342. }
  3343. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3344. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3345. }
  3346. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3347. ////查询历史出库数据
  3348. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3349. //
  3350. //var out_count_five int64
  3351. //for _, item := range flowGood {
  3352. // out_count_five += item.Count
  3353. //}
  3354. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3355. //
  3356. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3357. //if out_count_five != parseIntCount {
  3358. // //查询耗材最后一次出库记录
  3359. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3360. // //查询默认出库仓库库存
  3361. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3362. // if len(wareOut) > 0 {
  3363. //
  3364. // for _, it := range wareOut {
  3365. // //回退库存
  3366. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3367. //
  3368. // //删除出库记录
  3369. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3370. //
  3371. // }
  3372. // }
  3373. //
  3374. // timeStr := time.Now().Format("2006-01-02")
  3375. // timeArr := strings.Split(timeStr, "-")
  3376. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3377. //
  3378. // total = total + 1
  3379. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3380. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3381. // number = number + total
  3382. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3383. //
  3384. // operation_time := time.Now().Unix()
  3385. // creater := c.GetAdminUserInfo().AdminUser.Id
  3386. //
  3387. // recordDateStr := time.Now().Format("2006-01-02")
  3388. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3389. // nowtime := recordDate.Unix()
  3390. // warehouseOut := models.WarehouseOut{
  3391. // WarehouseOutOrderNumber: warehousing_out_order,
  3392. // OperationTime: operation_time,
  3393. // OrgId: adminInfo.CurrentOrgId,
  3394. // Creater: creater,
  3395. // Ctime: time.Now().Unix(),
  3396. // Status: 1,
  3397. // WarehouseOutTime: nowtime,
  3398. // Type: 1,
  3399. // StorehouseId: storeConfig.StorehouseOutInfo,
  3400. // IsCheck: 1,
  3401. // IsSys: 1,
  3402. // }
  3403. // //查询是否生成出库单
  3404. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3405. // if out.ID == 0 {
  3406. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3407. // }
  3408. //
  3409. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3410. //
  3411. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3412. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3413. //
  3414. // dialyPrepareOne := models.DialysisBeforePrepare{
  3415. // GoodTypeId: goodObj.GoodTypeId,
  3416. // GoodId: p.ProjectId,
  3417. // PatientId: p.PatientId,
  3418. // RecordDate: p.RecordDate,
  3419. // UserOrgId: adminInfo.CurrentOrgId,
  3420. // Count: parseIntCount,
  3421. // Ctime: time.Now().Unix(),
  3422. // Creater: creater,
  3423. // Status: 1,
  3424. // StorehouseId: houseConfig.StorehouseOutInfo,
  3425. // ProjectId: lastHisProject.ID,
  3426. // }
  3427. // //判断是否是零用耗材(非零用)
  3428. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3429. //
  3430. // //查询历史出库数据
  3431. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3432. // var out_count int64
  3433. // for _, item := range flowGood {
  3434. // out_count += item.Count
  3435. // }
  3436. // //如果历史数和当前数据不想等才进行退库出库
  3437. // if out_count != parseIntCount {
  3438. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3439. //
  3440. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3441. // detail := models.AutomaticReduceDetail{
  3442. // WarehouseOutId: 0,
  3443. // WarehouseOutOrderNumber: "",
  3444. // PatientId: p.PatientId,
  3445. // Ctime: time.Now().Unix(),
  3446. // Mtime: 0,
  3447. // Status: 1,
  3448. // RecordTime: p.RecordDate,
  3449. // OrgId: p.UserOrgId,
  3450. // GoodId: p.ProjectId,
  3451. // GoodTypeId: 0,
  3452. // Count: parseIntCount,
  3453. // Type: 0,
  3454. // ProjectId: lastHisProject.ID,
  3455. // StorehouseId: 0,
  3456. // }
  3457. //
  3458. // service.CreateNewAutoDetail(detail, tx)
  3459. //
  3460. // //查询剩余库存
  3461. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3462. // var sum_count int64
  3463. // for _, item := range goodList {
  3464. // sum_count += item.StockCount
  3465. // }
  3466. //
  3467. // //更新剩余库存
  3468. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3469. //
  3470. // //耗材
  3471. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3472. //
  3473. // }
  3474. // //判断是否是零用耗材(零用但是是出库耗材)
  3475. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3476. //
  3477. // //查询历史出库数据
  3478. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3479. // var out_count int64
  3480. // for _, item := range flowGood {
  3481. // out_count += item.Count
  3482. // }
  3483. // //如果历史数和当前数据不想等才进行退库出库
  3484. // if out_count != parseIntCount {
  3485. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3486. //
  3487. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3488. // detail := models.AutomaticReduceDetail{
  3489. // WarehouseOutId: 0,
  3490. // WarehouseOutOrderNumber: "",
  3491. // PatientId: p.PatientId,
  3492. // Ctime: time.Now().Unix(),
  3493. // Mtime: 0,
  3494. // Status: 1,
  3495. // RecordTime: p.RecordDate,
  3496. // OrgId: p.UserOrgId,
  3497. // GoodId: p.ProjectId,
  3498. // GoodTypeId: 0,
  3499. // Count: parseIntCount,
  3500. // Type: 0,
  3501. // ProjectId: p.ID,
  3502. // StorehouseId: 0,
  3503. // }
  3504. //
  3505. // service.CreateNewAutoDetail(detail, tx)
  3506. //
  3507. // //查询剩余库存
  3508. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3509. // var sum_count int64
  3510. // for _, item := range goodList {
  3511. // sum_count += item.StockCount
  3512. // }
  3513. //
  3514. // //更新剩余库存
  3515. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3516. //
  3517. // //耗材
  3518. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3519. // }
  3520. //
  3521. // }
  3522. //
  3523. // }
  3524. //
  3525. //}
  3526. //记录日志
  3527. byterequest, _ := json.Marshal(p)
  3528. adviceLog := models.XtDoctorAdviceLog{
  3529. UserOrgId: p.UserOrgId,
  3530. PatientId: p.PatientId,
  3531. AdminUserId: adminInfo.AdminUser.Id,
  3532. Module: 1,
  3533. ErrLog: string(byterequest),
  3534. Status: 1,
  3535. Ctime: time.Now().Unix(),
  3536. Mtime: 0,
  3537. Source: "电脑端新建his项目",
  3538. RecordDate: p.RecordDate,
  3539. }
  3540. service.CreateDoctorAdviceLog(adviceLog)
  3541. projectList = append(projectList, p)
  3542. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3543. //新增或者编辑项目,修改对应的标签数据
  3544. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3545. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3546. var label models.HisLabelPrintInfo
  3547. project, _ := service.GetProjectDetail(p.ProjectId)
  3548. if project.CostClassify == 3 { //类别为检验检查
  3549. if p.TeamId > 0 { //检验检查组套
  3550. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3551. if tempLabel.ID == 0 {
  3552. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3553. label.Number = tempPrescription.PrescriptionNumber
  3554. label.ProjectId = project.ID
  3555. label.Status = 1
  3556. label.IsPrint = 2
  3557. label.DoctorId = info.DoctorId
  3558. label.UserOrgId = p.UserOrgId
  3559. label.PatientId = patient_id
  3560. label.RecordDate = recordDateTime
  3561. label.Ctime = time.Now().Unix()
  3562. label.Mtime = time.Now().Unix()
  3563. label.ItemId = p.TeamId
  3564. label.FeedetlSn = p.FeedetlSn
  3565. label.PProjectId = p.ID
  3566. label.ProjectName = team.ProjectTeam
  3567. label.PatientName = patient.Name
  3568. service.CreateNewHisLabelRecord(&label, tx)
  3569. }
  3570. } else { //单条检验检查项目
  3571. label.Number = tempPrescription.PrescriptionNumber
  3572. label.ProjectId = project.ID
  3573. label.Status = 1
  3574. label.DoctorId = info.DoctorId
  3575. label.UserOrgId = p.UserOrgId
  3576. label.PatientId = patient_id
  3577. label.RecordDate = recordDateTime
  3578. label.IsPrint = 2
  3579. label.Ctime = time.Now().Unix()
  3580. label.Mtime = time.Now().Unix()
  3581. label.FeedetlSn = p.FeedetlSn
  3582. label.PProjectId = p.ID
  3583. label.ItemId = p.TeamId
  3584. label.ProjectName = project.ProjectName
  3585. label.PatientName = patient.Name
  3586. service.CreateNewHisLabelRecord(&label, tx)
  3587. }
  3588. }
  3589. }
  3590. }
  3591. }
  3592. }
  3593. }
  3594. service.CreateNewHisProjectTwo(&p, tx)
  3595. var randNum int
  3596. randNum = rand.Intn(10000) + 1000
  3597. timestamp := time.Now().Unix()
  3598. tempTime := time.Unix(timestamp, 0)
  3599. timeFormat := tempTime.Format("20060102150405")
  3600. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3601. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3602. if goodBase.ID > 0 {
  3603. tx.Rollback()
  3604. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3605. return
  3606. }
  3607. service.CreateNewHisProjectTwo(&p, tx)
  3608. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3609. //查询剩余库存
  3610. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3611. var sum_count int64
  3612. for _, item := range goodList {
  3613. sum_count += item.StockCount
  3614. }
  3615. //更新剩余库存
  3616. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3617. //耗材
  3618. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3619. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3620. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3621. if len(outInfoTwo) > 0 {
  3622. for _, item := range outInfoTwo {
  3623. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3624. }
  3625. }
  3626. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3627. if len(drugAutoDetail) > 0 {
  3628. for _, item := range drugAutoDetail {
  3629. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3630. }
  3631. }
  3632. tx.Commit()
  3633. }
  3634. }
  3635. }
  3636. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3637. // addition := items["addition"].([]interface{})
  3638. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3639. // ctime := time.Now().Unix()
  3640. // mtime := ctime
  3641. // if len(addition) > 0 {
  3642. // for _, item := range addition {
  3643. // var s models.HisAdditionalCharge
  3644. // s.PrescriptionId = tempPrescription.ID
  3645. // s.Status = 1
  3646. // s.UserOrgId = adminInfo.CurrentOrgId
  3647. // s.RecordDate = recordDateTime
  3648. // s.CreatedTime = ctime
  3649. // s.UpdatedTime = mtime
  3650. // s.PatientId = patient_id
  3651. // s.HisPatientId = his_patient_id
  3652. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3653. // if errcode > 0 {
  3654. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3655. // return
  3656. // }
  3657. // service.CreateAdditionalCharge(&s)
  3658. // var randNum int
  3659. // randNum = rand.Intn(10000) + 1000
  3660. // timestamp := time.Now().Unix()
  3661. // tempTime := time.Unix(timestamp, 0)
  3662. // timeFormat := tempTime.Format("20060102150405")
  3663. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3664. // service.CreateAdditionalCharge(&s)
  3665. //
  3666. // }
  3667. // }
  3668. //}
  3669. }
  3670. }
  3671. }
  3672. tx.Commit()
  3673. if err == nil {
  3674. c.ServeSuccessJSON(map[string]interface{}{
  3675. "msg": "保存成功",
  3676. })
  3677. return
  3678. } else {
  3679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3680. return
  3681. }
  3682. } else {
  3683. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3684. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3685. var tempPrescription *models.HisPrescription
  3686. if len(prescriptions) > 0 {
  3687. for _, item := range prescriptions {
  3688. items := item.(map[string]interface{})
  3689. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3690. utils.ErrorLog("id")
  3691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3692. return
  3693. }
  3694. id := int64(items["id"].(float64))
  3695. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3696. tempPrescription = &new_prescription
  3697. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3698. utils.ErrorLog("type")
  3699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3700. return
  3701. }
  3702. types := int64(items["type"].(float64))
  3703. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3704. utils.ErrorLog("med_type")
  3705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3706. return
  3707. }
  3708. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3709. if med_type == "0" {
  3710. med_type = "14"
  3711. }
  3712. //if order_status == 0 {
  3713. // order_status = 1
  3714. //}
  3715. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3716. utils.ErrorLog("pre_time")
  3717. }
  3718. preTime, _ := items["pre_time"].(string)
  3719. timeLayout := "2006-01-02"
  3720. loc, _ := time.LoadLocation("Local")
  3721. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3722. result := strings.Split(preTime, " ")
  3723. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3724. if err != nil {
  3725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3726. return
  3727. }
  3728. pTime := theTime2.Unix()
  3729. ctime := time.Now().Unix()
  3730. if tempPrescription.ID == 0 {
  3731. prescription := &models.HisPrescription{
  3732. ID: 0,
  3733. PatientId: patient_id,
  3734. UserOrgId: adminInfo.CurrentOrgId,
  3735. RecordDate: recordDateTime,
  3736. Ctime: ctime,
  3737. Mtime: ctime,
  3738. Type: types,
  3739. Modifier: adminInfo.AdminUser.Id,
  3740. Creator: adminInfo.AdminUser.Id,
  3741. Status: 1,
  3742. Doctor: role.UserName,
  3743. HisPatientId: his_patient_id,
  3744. OrderStatus: 1,
  3745. BatchNumber: "",
  3746. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3747. PreTime: pTime,
  3748. PType: p_type,
  3749. MedType: med_type,
  3750. }
  3751. tempPrescription = prescription
  3752. service.SaveHisPrescription(tempPrescription)
  3753. redis := service.RedisClient()
  3754. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3755. redis.Set(key, "", time.Second)
  3756. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3757. redis.Set(keyOne, "", time.Second)
  3758. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3759. redis.Set(keySeven, "", time.Second)
  3760. defer redis.Close()
  3761. } else {
  3762. tempPrescription.ID = id
  3763. tempPrescription.Type = types
  3764. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3765. tempPrescription.Mtime = time.Now().Unix()
  3766. tempPrescription.Doctor = role.UserName
  3767. //tempPrescription.OrderStatus = order_status
  3768. tempPrescription.PreTime = pTime
  3769. tempPrescription.MedType = med_type
  3770. service.SaveHisPrescription(tempPrescription)
  3771. redis := service.RedisClient()
  3772. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3773. redis.Set(key, "", time.Second)
  3774. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3775. redis.Set(keyOne, "", time.Second)
  3776. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3777. redis.Set(keySeven, "", time.Second)
  3778. defer redis.Close()
  3779. }
  3780. //service.SaveHisPrescription(prescription)
  3781. //更改患者挂号状态
  3782. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3783. fmt.Println("更改失败", err2)
  3784. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3785. advices := items["advices"].([]interface{})
  3786. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3787. groupNo := int64(0)
  3788. if len(advices) > 0 {
  3789. for _, advice := range advices {
  3790. var s models.HisDoctorAdviceInfo
  3791. s.PrescriptionId = tempPrescription.ID
  3792. s.AdviceType = 2
  3793. s.AdviceDoctor = doctor_id
  3794. s.StopState = 2
  3795. s.ExecutionState = 2
  3796. s.AdviceDate = theTime3.Unix()
  3797. s.Status = 1
  3798. s.UserOrgId = adminInfo.CurrentOrgId
  3799. s.RecordDate = theTime3.Unix()
  3800. s.StartTime = tempPrescription.PreTime
  3801. s.Groupno = groupNo
  3802. s.PatientId = patient_id
  3803. s.HisPatientId = his_patient_id
  3804. s.StartTime = pTime
  3805. s.IsSettle = 2
  3806. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3807. if errcode > 0 {
  3808. c.ServeFailJSONWithSGJErrorCode(errcode)
  3809. return
  3810. }
  3811. s.StartTime = pTime
  3812. var total_count int64 //处方总库存
  3813. //查询改药品信息
  3814. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3815. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3816. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3817. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3818. total_count += prescribingNumberSeven * medical.MinNumber
  3819. }
  3820. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3821. total_count += prescribingNumberSeven
  3822. }
  3823. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3824. total_count += prescribingNumberSeven
  3825. }
  3826. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3827. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3828. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3829. if s.Price != lastWarehouse.RetailPrice {
  3830. s.Price = lastWarehouse.RetailPrice
  3831. }
  3832. if s.Price == 0 {
  3833. s.Price = lastWarehouse.RetailPrice
  3834. }
  3835. }
  3836. service.CreateHisDoctorAdvice(&s)
  3837. //记录日志
  3838. byterequest, _ := json.Marshal(s)
  3839. adviceLog := models.XtDoctorAdviceLog{
  3840. UserOrgId: s.UserOrgId,
  3841. PatientId: s.PatientId,
  3842. AdminUserId: adminInfo.AdminUser.Id,
  3843. Module: 1,
  3844. ErrLog: string(byterequest),
  3845. Status: 1,
  3846. Ctime: time.Now().Unix(),
  3847. Mtime: 0,
  3848. Source: "电脑端新建his医嘱",
  3849. RecordDate: s.AdviceDate,
  3850. }
  3851. service.CreateDoctorAdviceLog(adviceLog)
  3852. //存储切片中
  3853. adviceList = append(adviceList, s)
  3854. redis := service.RedisClient()
  3855. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3856. redis.Set(key, "", time.Second)
  3857. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3858. redis.Set(keyOne, "", time.Second)
  3859. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3860. redis.Set(keySeven, "", time.Second)
  3861. var randNum int
  3862. randNum = rand.Intn(10000) + 1000
  3863. timestamp := time.Now().Unix()
  3864. tempTime := time.Unix(timestamp, 0)
  3865. timeFormat := tempTime.Format("20060102150405")
  3866. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3867. service.CreateHisDoctorAdvice(&s)
  3868. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3869. redis.Set(keySix, "", time.Second)
  3870. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3871. redis.Set(keyFive, "", time.Second)
  3872. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3873. redis.Set(keyEight, "", time.Second)
  3874. defer redis.Close()
  3875. }
  3876. }
  3877. }
  3878. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3879. projects := items["project"].([]interface{})
  3880. if len(projects) > 0 {
  3881. for _, project := range projects {
  3882. var p models.HisPrescriptionProject
  3883. p.PrescriptionId = tempPrescription.ID
  3884. p.PatientId = patient_id
  3885. p.RecordDate = theTime3.Unix()
  3886. p.Doctor = doctor_id
  3887. p.UserOrgId = adminInfo.CurrentOrgId
  3888. p.HisPatientId = his_patient_id
  3889. p.Status = 1
  3890. p.StartTime = pTime
  3891. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3892. if errcode > 0 {
  3893. c.ServeFailJSONWithSGJErrorCode(errcode)
  3894. return
  3895. }
  3896. if p.ID == 0 {
  3897. p.IsOut = 2
  3898. }
  3899. if p.ID > 0 {
  3900. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3901. p.IsOut = projectDetail.IsOut
  3902. }
  3903. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3904. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3905. if p.Type == 3 {
  3906. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3907. if p.Price != lastWarehouse.PackingPrice {
  3908. p.Price = lastWarehouse.PackingPrice
  3909. }
  3910. if p.Unit == "" {
  3911. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3912. p.Unit = goodInfoOne.PackingUnit
  3913. }
  3914. }
  3915. }
  3916. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3917. //
  3918. // if p.Type == 3 {
  3919. // //查询该耗材是否停用
  3920. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3921. // //表示该耗材已经停用,不能保存
  3922. // if goodInfoSeven.ID == 0 {
  3923. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3924. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3925. // return
  3926. // }
  3927. // }
  3928. //
  3929. //}
  3930. service.CreateHisProjectTwo(&p)
  3931. //记录日志
  3932. byterequest, _ := json.Marshal(p)
  3933. adviceLog := models.XtDoctorAdviceLog{
  3934. UserOrgId: p.UserOrgId,
  3935. PatientId: p.PatientId,
  3936. AdminUserId: adminInfo.AdminUser.Id,
  3937. Module: 1,
  3938. ErrLog: string(byterequest),
  3939. Status: 1,
  3940. Ctime: time.Now().Unix(),
  3941. Mtime: 0,
  3942. Source: "电脑端新建his项目",
  3943. RecordDate: p.RecordDate,
  3944. }
  3945. service.CreateDoctorAdviceLog(adviceLog)
  3946. projectList = append(projectList, p)
  3947. var randNum int
  3948. randNum = rand.Intn(10000) + 1000
  3949. timestamp := time.Now().Unix()
  3950. tempTime := time.Unix(timestamp, 0)
  3951. timeFormat := tempTime.Format("20060102150405")
  3952. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3953. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3954. //新增或者编辑项目,修改对应的标签数据
  3955. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3956. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3957. var label models.HisLabelPrintInfo
  3958. project, _ := service.GetProjectDetail(p.ProjectId)
  3959. if project.CostClassify == 3 { //类别为检验检查
  3960. if p.TeamId > 0 { //检验检查组套
  3961. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3962. if tempLabel.ID == 0 {
  3963. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3964. label.Number = tempPrescription.PrescriptionNumber
  3965. label.ProjectId = project.ID
  3966. label.Status = 1
  3967. label.IsPrint = 2
  3968. label.DoctorId = info.DoctorId
  3969. label.UserOrgId = p.UserOrgId
  3970. label.PatientId = patient_id
  3971. label.RecordDate = recordDateTime
  3972. label.Ctime = time.Now().Unix()
  3973. label.Mtime = time.Now().Unix()
  3974. label.ItemId = p.TeamId
  3975. label.FeedetlSn = p.FeedetlSn
  3976. label.PProjectId = p.ID
  3977. label.ProjectName = team.ProjectTeam
  3978. label.PatientName = patient.Name
  3979. service.CreateHisLabelRecord(&label)
  3980. }
  3981. } else { //单条检验检查项目
  3982. label.Number = tempPrescription.PrescriptionNumber
  3983. label.ProjectId = project.ID
  3984. label.Status = 1
  3985. label.DoctorId = info.DoctorId
  3986. label.UserOrgId = p.UserOrgId
  3987. label.PatientId = patient_id
  3988. label.RecordDate = recordDateTime
  3989. label.IsPrint = 2
  3990. label.Ctime = time.Now().Unix()
  3991. label.Mtime = time.Now().Unix()
  3992. label.FeedetlSn = p.FeedetlSn
  3993. label.PProjectId = p.ID
  3994. label.ItemId = p.TeamId
  3995. label.ProjectName = project.ProjectName
  3996. label.PatientName = patient.Name
  3997. service.CreateHisLabelRecord(&label)
  3998. }
  3999. }
  4000. }
  4001. }
  4002. service.SaveHisProjectTwo(&p)
  4003. }
  4004. }
  4005. }
  4006. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4007. // addition := items["addition"].([]interface{})
  4008. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4009. // ctime := time.Now().Unix()
  4010. // mtime := ctime
  4011. // if len(addition) > 0 {
  4012. // for _, item := range addition {
  4013. // var s models.HisAdditionalCharge
  4014. // s.PrescriptionId = tempPrescription.ID
  4015. // s.Status = 1
  4016. // s.UserOrgId = adminInfo.CurrentOrgId
  4017. // s.RecordDate = recordDateTime
  4018. // s.CreatedTime = ctime
  4019. // s.UpdatedTime = mtime
  4020. // s.PatientId = patient_id
  4021. // s.HisPatientId = his_patient_id
  4022. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4023. // if errcode > 0 {
  4024. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4025. // return
  4026. // }
  4027. // service.CreateAdditionalCharge(&s)
  4028. // var randNum int
  4029. // randNum = rand.Intn(10000) + 1000
  4030. // timestamp := time.Now().Unix()
  4031. // tempTime := time.Unix(timestamp, 0)
  4032. // timeFormat := tempTime.Format("20060102150405")
  4033. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4034. // service.CreateAdditionalCharge(&s)
  4035. //
  4036. // }
  4037. // }
  4038. //}
  4039. }
  4040. }
  4041. //查询今日该患者开的药品处方
  4042. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4043. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4044. //药品出库
  4045. if drugOutConfig.IsOpen == 1 {
  4046. for _, item := range hisdoctorlist {
  4047. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4048. // 查询该药品最后一次出库记录
  4049. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4050. if len(druginfo) > 0 {
  4051. //回退库存
  4052. for _, it := range druginfo {
  4053. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4054. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4055. }
  4056. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4057. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4058. }
  4059. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4060. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4061. }
  4062. }
  4063. }
  4064. //删除记录
  4065. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4066. //查询最后一次数据
  4067. if drugOutConfig.IsOpen == 1 {
  4068. //出库
  4069. if drug.IsUse == 2 {
  4070. creater := adminInfo.AdminUser.Id
  4071. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4072. }
  4073. //更新字典里面的库存
  4074. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4075. var sum_count int64
  4076. for _, its := range stockInfo {
  4077. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4078. if its.MaxUnit == baseDrug.MaxUnit {
  4079. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4080. }
  4081. sum_count += its.StockMaxNumber + its.StockMinNumber
  4082. }
  4083. //更新基础库存
  4084. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4085. //剩余库存
  4086. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4087. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4088. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4089. }
  4090. }
  4091. }
  4092. //耗材保存处方出库
  4093. if goodOutConfig.IsOpen == 1 {
  4094. //查询今日耗材出库数量
  4095. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4096. for _, item := range hisgoodlist {
  4097. //查询历史出库数据
  4098. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4099. var out_count_five int64
  4100. for _, item := range flowGood {
  4101. out_count_five += item.Count
  4102. }
  4103. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4104. if out_count_five != parseIntCount {
  4105. //查询耗材最后一次出库记录
  4106. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4107. //查询默认出库仓库库存
  4108. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4109. if len(wareOut) > 0 {
  4110. for _, it := range wareOut {
  4111. //回退库存
  4112. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4113. //删除出库记录
  4114. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4115. }
  4116. }
  4117. timeStr := time.Now().Format("2006-01-02")
  4118. timeArr := strings.Split(timeStr, "-")
  4119. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4120. total = total + 1
  4121. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4122. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4123. number = number + total
  4124. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4125. operation_time := time.Now().Unix()
  4126. creater := c.GetAdminUserInfo().AdminUser.Id
  4127. recordDateStr := time.Now().Format("2006-01-02")
  4128. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4129. nowtime := recordDate.Unix()
  4130. warehouseOut := models.WarehouseOut{
  4131. WarehouseOutOrderNumber: warehousing_out_order,
  4132. OperationTime: operation_time,
  4133. OrgId: adminInfo.CurrentOrgId,
  4134. Creater: creater,
  4135. Ctime: time.Now().Unix(),
  4136. Status: 1,
  4137. WarehouseOutTime: nowtime,
  4138. Type: 1,
  4139. StorehouseId: storeConfig.StorehouseOutInfo,
  4140. IsCheck: 1,
  4141. IsSys: 1,
  4142. }
  4143. //查询是否生成出库单
  4144. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4145. if out.ID == 0 {
  4146. service.AddSigleWarehouseOut(&warehouseOut)
  4147. }
  4148. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4149. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4150. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4151. dialyPrepareOne := models.DialysisBeforePrepare{
  4152. GoodTypeId: goodObj.GoodTypeId,
  4153. GoodId: item.ProjectId,
  4154. PatientId: item.PatientId,
  4155. RecordDate: item.RecordDate,
  4156. UserOrgId: adminInfo.CurrentOrgId,
  4157. Count: parseIntCount,
  4158. Ctime: time.Now().Unix(),
  4159. Creater: creater,
  4160. Status: 1,
  4161. StorehouseId: houseConfig.StorehouseOutInfo,
  4162. ProjectId: item.ID,
  4163. }
  4164. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4165. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4166. //查询历史出库数据
  4167. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4168. var out_count int64
  4169. for _, item := range flowGood {
  4170. out_count += item.Count
  4171. }
  4172. //如果历史数和当前数据不想等才进行退库出库
  4173. if out_count != parseIntCount {
  4174. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4175. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4176. detail := models.AutomaticReduceDetail{
  4177. WarehouseOutId: 0,
  4178. WarehouseOutOrderNumber: "",
  4179. PatientId: item.PatientId,
  4180. Ctime: time.Now().Unix(),
  4181. Mtime: 0,
  4182. Status: 1,
  4183. RecordTime: item.RecordDate,
  4184. OrgId: item.UserOrgId,
  4185. GoodId: item.ProjectId,
  4186. GoodTypeId: 0,
  4187. Count: parseIntCount,
  4188. Type: 0,
  4189. ProjectId: item.ID,
  4190. StorehouseId: 0,
  4191. }
  4192. service.CreateAutoDetail(detail)
  4193. //查询剩余库存
  4194. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4195. var sum_count int64
  4196. for _, item := range goodList {
  4197. sum_count += item.StockCount
  4198. }
  4199. //更新剩余库存
  4200. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4201. //耗材
  4202. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4203. }
  4204. }
  4205. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4206. //查询历史出库数据
  4207. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4208. var out_count int64
  4209. for _, item := range flowGood {
  4210. out_count += item.Count
  4211. }
  4212. //如果历史数和当前数据不想等才进行退库出库
  4213. if out_count != parseIntCount {
  4214. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4215. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4216. detail := models.AutomaticReduceDetail{
  4217. WarehouseOutId: 0,
  4218. WarehouseOutOrderNumber: "",
  4219. PatientId: item.PatientId,
  4220. Ctime: time.Now().Unix(),
  4221. Mtime: 0,
  4222. Status: 1,
  4223. RecordTime: item.RecordDate,
  4224. OrgId: item.UserOrgId,
  4225. GoodId: item.ProjectId,
  4226. GoodTypeId: 0,
  4227. Count: parseIntCount,
  4228. Type: 0,
  4229. ProjectId: item.ID,
  4230. StorehouseId: 0,
  4231. }
  4232. service.CreateAutoDetail(detail)
  4233. //查询剩余库存
  4234. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4235. var sum_count int64
  4236. for _, item := range goodList {
  4237. sum_count += item.StockCount
  4238. }
  4239. //更新剩余库存
  4240. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4241. //耗材
  4242. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4243. }
  4244. }
  4245. }
  4246. }
  4247. }
  4248. }
  4249. tx.Commit()
  4250. if err == nil {
  4251. c.ServeSuccessJSON(map[string]interface{}{
  4252. "msg": "保存成功",
  4253. })
  4254. return
  4255. } else {
  4256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4257. return
  4258. }
  4259. }
  4260. }
  4261. //func (c *HisApiController) EditHisPrescription() {
  4262. // record_date := c.GetString("record_date")
  4263. // patient_id, _ := c.GetInt64("patient_id")
  4264. // reg_type, _ := c.GetInt64("reg_type")
  4265. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4266. // diagnose := c.GetString("diagnose")
  4267. // sick_type, _ := c.GetInt64("sick_type")
  4268. // sick_history := c.GetString("sick_history")
  4269. // doctor_id, _ := c.GetInt64("doctor", 0)
  4270. // department, _ := c.GetInt64("department", 0)
  4271. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4272. // p_type, _ := c.GetInt64("p_type")
  4273. //
  4274. // dataBody := make(map[string]interface{}, 0)
  4275. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4276. // if err != nil {
  4277. // utils.ErrorLog(err.Error())
  4278. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4279. // return
  4280. // }
  4281. //
  4282. // timeLayout := "2006-01-02"
  4283. // loc, _ := time.LoadLocation("Local")
  4284. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4285. // if err != nil {
  4286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4287. // return
  4288. // }
  4289. // adminInfo := c.GetAdminUserInfo()
  4290. // recordDateTime := theTime.Unix()
  4291. //
  4292. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4293. //
  4294. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4295. // var hpInfo models.HisPrescriptionInfo
  4296. // if info.ID == 0 {
  4297. // var randNum int
  4298. // randNum = rand.Intn(10000) + 1000
  4299. // timestamp := time.Now().Unix()
  4300. // tempTime := time.Unix(timestamp, 0)
  4301. // timeFormat := tempTime.Format("20060102150405")
  4302. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4303. //
  4304. // hpInfo = models.HisPrescriptionInfo{
  4305. // UserOrgId: adminInfo.CurrentOrgId,
  4306. // RecordDate: theTime.Unix(),
  4307. // PatientId: patient_id,
  4308. // Status: 1,
  4309. // Ctime: time.Now().Unix(),
  4310. // Mtime: time.Now().Unix(),
  4311. // Creator: adminInfo.AdminUser.Id,
  4312. // Modifier: adminInfo.AdminUser.Id,
  4313. // Diagnosis: diagnose,
  4314. // SickHistory: sick_history,
  4315. // Departments: department,
  4316. // RegisterType: reg_type,
  4317. // PrescriptionNumber: p_number,
  4318. // PrescriptionStatus: 1,
  4319. // Doctor: role.UserName,
  4320. // DoctorId: doctor_id,
  4321. // SickType: sick_type,
  4322. // PType: p_type,
  4323. // }
  4324. // service.SavePatientPrescriptionInfo(hpInfo)
  4325. //
  4326. // } else {
  4327. // hpInfo = models.HisPrescriptionInfo{
  4328. // ID: info.ID,
  4329. // UserOrgId: adminInfo.CurrentOrgId,
  4330. // RecordDate: info.RecordDate,
  4331. // PatientId: info.PatientId,
  4332. // Status: 1,
  4333. // Ctime: info.Ctime,
  4334. // Mtime: time.Now().Unix(),
  4335. // Creator: info.Creator,
  4336. // Modifier: adminInfo.AdminUser.Id,
  4337. // Diagnosis: diagnose,
  4338. // SickHistory: sick_history,
  4339. // Departments: department,
  4340. // RegisterType: reg_type,
  4341. // PrescriptionNumber: info.PrescriptionNumber,
  4342. // Doctor: role.UserName,
  4343. // PrescriptionStatus: info.PrescriptionStatus,
  4344. // DoctorId: doctor_id,
  4345. // SickType: sick_type,
  4346. // PType: info.PType,
  4347. // }
  4348. // service.SavePatientPrescriptionInfo(hpInfo)
  4349. // }
  4350. //
  4351. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4352. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4353. //
  4354. // if len(prescriptions) > 0 {
  4355. // for _, item := range prescriptions {
  4356. // items := item.(map[string]interface{})
  4357. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4358. // utils.ErrorLog("id")
  4359. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4360. // return
  4361. // }
  4362. // id := int64(items["id"].(float64))
  4363. //
  4364. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4365. // utils.ErrorLog("type")
  4366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4367. // return
  4368. // }
  4369. // types := int64(items["type"].(float64))
  4370. //
  4371. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4372. // utils.ErrorLog("med_type")
  4373. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4374. // return
  4375. // }
  4376. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4377. //
  4378. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4379. //
  4380. // ctime := time.Now().Unix()
  4381. //
  4382. // prescription := &models.HisPrescription{
  4383. // ID: id,
  4384. // PatientId: patient_id,
  4385. // UserOrgId: adminInfo.CurrentOrgId,
  4386. // RecordDate: recordDateTime,
  4387. // Ctime: ctime,
  4388. // Mtime: ctime,
  4389. // Type: types,
  4390. // Modifier: adminInfo.AdminUser.Id,
  4391. // Creator: adminInfo.AdminUser.Id,
  4392. // Status: 1,
  4393. // Doctor: role.UserName,
  4394. // HisPatientId: his_patient_id,
  4395. // OrderStatus: 1,
  4396. // BatchNumber: "",
  4397. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4398. // PType: hpInfo.PType,
  4399. // MedType: med_type,
  4400. // }
  4401. //
  4402. // if historyPrescription.ID > 0 {
  4403. // prescription.PreTime = historyPrescription.PreTime
  4404. //
  4405. // }
  4406. //
  4407. // service.SaveHisPrescription(prescription)
  4408. //
  4409. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4410. // advices := items["advices"].([]interface{})
  4411. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4412. // groupNo := int64(0)
  4413. // ctime := time.Now().Unix()
  4414. // mtime := ctime
  4415. // if len(advices) > 0 {
  4416. // for _, advice := range advices {
  4417. // var s models.HisDoctorAdviceInfo
  4418. // s.PrescriptionId = prescription.ID
  4419. // s.AdviceType = 2
  4420. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4421. // s.StopState = 2
  4422. // s.ExecutionState = 2
  4423. // s.AdviceDate = recordDateTime
  4424. // s.Status = 1
  4425. // s.UserOrgId = adminInfo.CurrentOrgId
  4426. // s.RecordDate = recordDateTime
  4427. // s.StartTime = prescription.PreTime
  4428. // s.Groupno = groupNo
  4429. // s.CreatedTime = ctime
  4430. // s.UpdatedTime = mtime
  4431. // s.PatientId = patient_id
  4432. // s.HisPatientId = his_patient_id
  4433. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4434. // if errcode > 0 {
  4435. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4436. // return
  4437. // }
  4438. //
  4439. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4440. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4441. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4442. // if s.Price == 0 {
  4443. // s.Price = lastWarehouse.RetailPrice
  4444. // }
  4445. // }
  4446. //
  4447. // service.CreateHisDoctorAdvice(&s)
  4448. // //记录日志
  4449. // byterequest, _ := json.Marshal(s)
  4450. // adviceLog := models.XtDoctorAdviceLog{
  4451. // UserOrgId: s.UserOrgId,
  4452. // PatientId: s.PatientId,
  4453. // AdminUserId: adminInfo.AdminUser.Id,
  4454. // Module: 1,
  4455. // ErrLog: string(byterequest),
  4456. // Status: 1,
  4457. // Ctime: time.Now().Unix(),
  4458. // Mtime: 0,
  4459. // Source: "电脑端his医嘱修改",
  4460. // RecordDate: s.AdviceDate,
  4461. // }
  4462. // service.CreateDoctorAdviceLog(adviceLog)
  4463. // redis := service.RedisClient()
  4464. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4465. // redis.Set(key, "", time.Second)
  4466. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4467. // fmt.Println("keyOne", keyOne)
  4468. // redis.Set(keyOne, "", time.Second)
  4469. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4470. // redis.Set(keySeven, "", time.Second)
  4471. // redis.Close()
  4472. //
  4473. // }
  4474. // }
  4475. // }
  4476. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4477. // projects := items["project"].([]interface{})
  4478. // if len(projects) > 0 {
  4479. // for _, project := range projects {
  4480. // var p models.HisPrescriptionProject
  4481. // p.PrescriptionId = prescription.ID
  4482. // p.Ctime = time.Now().Unix()
  4483. // p.Mtime = time.Now().Unix()
  4484. // p.PatientId = patient_id
  4485. // p.RecordDate = recordDateTime
  4486. // p.UserOrgId = adminInfo.CurrentOrgId
  4487. // p.HisPatientId = his_patient_id
  4488. // p.Status = 1
  4489. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4490. // if errcode > 0 {
  4491. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4492. // return
  4493. // }
  4494. // service.CreateHisProjectTwo(&p)
  4495. //
  4496. // //记录日志
  4497. // byterequest, _ := json.Marshal(p)
  4498. // adviceLog := models.XtDoctorAdviceLog{
  4499. // UserOrgId: p.UserOrgId,
  4500. // PatientId: p.PatientId,
  4501. // AdminUserId: adminInfo.AdminUser.Id,
  4502. // Module: 1,
  4503. // ErrLog: string(byterequest),
  4504. // Status: 1,
  4505. // Ctime: time.Now().Unix(),
  4506. // Mtime: 0,
  4507. // Source: "电脑端his项目修改",
  4508. // RecordDate: p.RecordDate,
  4509. // }
  4510. // service.CreateDoctorAdviceLog(adviceLog)
  4511. // }
  4512. // }
  4513. // }
  4514. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4515. // addition := items["addition"].([]interface{})
  4516. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4517. // ctime := time.Now().Unix()
  4518. // mtime := ctime
  4519. // if len(addition) > 0 {
  4520. // for _, item := range addition {
  4521. // var s models.HisAdditionalCharge
  4522. // s.PrescriptionId = prescription.ID
  4523. // s.Status = 1
  4524. // s.UserOrgId = adminInfo.CurrentOrgId
  4525. // s.RecordDate = recordDateTime
  4526. // s.CreatedTime = ctime
  4527. // s.UpdatedTime = mtime
  4528. // s.PatientId = patient_id
  4529. // s.HisPatientId = his_patient_id
  4530. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4531. // if errcode > 0 {
  4532. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4533. // return
  4534. // }
  4535. // service.CreateAdditionalCharge(&s)
  4536. // }
  4537. // }
  4538. // }
  4539. //
  4540. // }
  4541. // }
  4542. // }
  4543. // if err == nil {
  4544. // c.ServeSuccessJSON(map[string]interface{}{
  4545. // "msg": "保存成功",
  4546. // })
  4547. // return
  4548. //
  4549. // } else {
  4550. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4551. // return
  4552. // }
  4553. //}
  4554. func (c *HisApiController) DeletePrescription() {
  4555. prescription_id, _ := c.GetInt64("id")
  4556. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4557. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4558. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4559. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4560. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4561. //耗材保存处方出库
  4562. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4563. //已收费和已发药限制逻辑
  4564. isCharge := false
  4565. isMedicine := false
  4566. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4567. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4568. for _, item := range new_prescriptions {
  4569. if item.IsMedicine == 1 {
  4570. isMedicine = true
  4571. }
  4572. }
  4573. for _, item := range new_prescriptions {
  4574. if item.OrderStatus == 4 {
  4575. isCharge = true
  4576. }
  4577. }
  4578. if p_err != nil {
  4579. if new_prescription.ID > 0 {
  4580. if new_prescription.OrderStatus == 2 {
  4581. isCharge = true
  4582. }
  4583. }
  4584. }
  4585. for _, item := range advices {
  4586. if item.IsMedicine == 1 {
  4587. isMedicine = true
  4588. }
  4589. }
  4590. if isCharge {
  4591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4592. return
  4593. }
  4594. if isMedicine {
  4595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4596. return
  4597. }
  4598. //已收费和已发药限制逻辑
  4599. if len(projects) > 0 {
  4600. for _, item := range projects {
  4601. service.DeletePrintInfo(item.ID) //删除打印信息
  4602. if goodOutConfig.IsOpen != 1 {
  4603. if stockConfig.IsOpen == 1 {
  4604. if item.Type == 3 && item.IsOut == 1 {
  4605. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4606. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4607. good.Total = good.Total + f_count
  4608. service.UpdateGoodInfo(&good)
  4609. operation_time := time.Now().Unix()
  4610. creater := c.GetAdminUserInfo().AdminUser.Id
  4611. //创建退库单
  4612. timeStr := time.Now().Format("2006-01-02")
  4613. timeArr := strings.Split(timeStr, "-")
  4614. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4615. total = total + 1
  4616. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4617. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4618. cancelStock := models.CancelStock{
  4619. OrderNumber: orderNumber,
  4620. OperaTime: operation_time,
  4621. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4622. Creater: creater,
  4623. Ctime: time.Now().Unix(),
  4624. Status: 1,
  4625. ReturnTime: item.RecordDate,
  4626. Type: 1,
  4627. StorehouseId: houseConfig.StorehouseOutInfo,
  4628. IsCheck: 1,
  4629. }
  4630. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4631. if msgerrkonde == gorm.ErrRecordNotFound {
  4632. service.AddSigleCancelStock(&cancelStock)
  4633. }
  4634. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4635. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4636. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4637. //查询该耗材是否出库
  4638. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4639. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4640. deaerler, _ := service.GetDealerById(info.Dealer)
  4641. var total_count int64
  4642. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4643. total_count += count
  4644. if info.ID > 0 {
  4645. if info.Count >= total_count {
  4646. //回退库存
  4647. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4648. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4649. var flush_count int64
  4650. for _, it := range goodList {
  4651. flush_count += it.StockCount
  4652. }
  4653. cancelStockInfo := models.CancelStockInfo{
  4654. GoodId: item.ProjectId,
  4655. CancelStockId: cancel.ID,
  4656. GoodTypeId: good.GoodTypeId,
  4657. Count: prescribingNumber,
  4658. Price: info.Price,
  4659. Total: 0,
  4660. ProductDate: info.ProductDate,
  4661. ExpiryDate: info.ExpiryDate,
  4662. Ctime: time.Now().Unix(),
  4663. Status: 1,
  4664. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4665. OrderNumber: cancel.OrderNumber,
  4666. Type: 0,
  4667. Dealer: deaerler.DealerName,
  4668. Manufacturer: manufacturer.ManufacturerName,
  4669. Number: info.Number,
  4670. RegisterAccount: "",
  4671. Remark: "",
  4672. WarehouseInfoId: info.WarehouseInfotId,
  4673. PatientId: info.PatientId,
  4674. RecordDate: info.SysRecordTime,
  4675. StorehouseId: houseConfig.StorehouseOutInfo,
  4676. IsCheck: 1,
  4677. }
  4678. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4679. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4680. flow := models.VmStockFlow{
  4681. WarehousingId: info.WarehouseInfotId,
  4682. GoodId: item.ProjectId,
  4683. Number: info.Number,
  4684. LicenseNumber: info.LicenseNumber,
  4685. Count: prescribingNumber,
  4686. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4687. PatientId: item.PatientId,
  4688. SystemTime: info.SysRecordTime,
  4689. ConsumableType: 7,
  4690. IsSys: 0,
  4691. WarehousingOrder: "",
  4692. WarehouseOutId: info.WarehouseOutId,
  4693. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4694. IsEdit: 0,
  4695. CancelStockId: cancel.ID,
  4696. CancelOrderNumber: cancel.OrderNumber,
  4697. Manufacturer: manufacturer.ID,
  4698. Dealer: 0,
  4699. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4700. UpdateCreator: 0,
  4701. Status: 1,
  4702. Ctime: time.Now().Unix(),
  4703. Mtime: 0,
  4704. Price: info.Price,
  4705. WarehousingDetailId: info.WarehouseInfotId,
  4706. WarehouseOutDetailId: info.ID,
  4707. CancelOutDetailId: cancelInfo.ID,
  4708. ProductDate: info.ProductDate,
  4709. ExpireDate: info.ExpiryDate,
  4710. StorehouseId: houseConfig.StorehouseOutInfo,
  4711. OverCount: flush_count,
  4712. OperateTime: time.Now().Unix(),
  4713. }
  4714. service.CreateStockFlowOne(flow)
  4715. //退库数量增加
  4716. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4717. //出库数量减少
  4718. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4719. }
  4720. if info.Count < total_count {
  4721. //回退库存
  4722. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4723. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4724. var flush_count int64
  4725. for _, it := range goodList {
  4726. flush_count += it.StockCount
  4727. }
  4728. cancelStockInfo := models.CancelStockInfo{
  4729. GoodId: item.ProjectId,
  4730. CancelStockId: cancel.ID,
  4731. GoodTypeId: good.GoodTypeId,
  4732. Count: info.Count,
  4733. Price: info.Price,
  4734. Total: 0,
  4735. ProductDate: info.ProductDate,
  4736. ExpiryDate: info.ExpiryDate,
  4737. Ctime: time.Now().Unix(),
  4738. Status: 1,
  4739. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4740. OrderNumber: cancel.OrderNumber,
  4741. Type: 0,
  4742. Dealer: deaerler.DealerName,
  4743. Manufacturer: manufacturer.ManufacturerName,
  4744. Number: info.Number,
  4745. RegisterAccount: "",
  4746. Remark: "",
  4747. WarehouseInfoId: info.WarehouseInfotId,
  4748. PatientId: info.PatientId,
  4749. RecordDate: info.SysRecordTime,
  4750. StorehouseId: houseConfig.StorehouseOutInfo,
  4751. IsCheck: 1,
  4752. }
  4753. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4754. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4755. flow := models.VmStockFlow{
  4756. WarehousingId: info.WarehouseInfotId,
  4757. GoodId: item.ProjectId,
  4758. Number: info.Number,
  4759. LicenseNumber: info.LicenseNumber,
  4760. Count: info.Count,
  4761. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4762. PatientId: item.PatientId,
  4763. SystemTime: info.SysRecordTime,
  4764. ConsumableType: 7,
  4765. IsSys: 0,
  4766. WarehousingOrder: "",
  4767. WarehouseOutId: info.WarehouseOutId,
  4768. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4769. IsEdit: 0,
  4770. CancelStockId: cancel.ID,
  4771. CancelOrderNumber: cancel.OrderNumber,
  4772. Manufacturer: manufacturer.ID,
  4773. Dealer: 0,
  4774. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4775. UpdateCreator: 0,
  4776. Status: 1,
  4777. Ctime: time.Now().Unix(),
  4778. Mtime: 0,
  4779. Price: info.Price,
  4780. WarehousingDetailId: info.WarehouseInfotId,
  4781. WarehouseOutDetailId: info.ID,
  4782. CancelOutDetailId: cancelInfo.ID,
  4783. ProductDate: info.ProductDate,
  4784. ExpireDate: info.ExpiryDate,
  4785. StorehouseId: houseConfig.StorehouseOutInfo,
  4786. OverCount: flush_count,
  4787. OperateTime: time.Now().Unix(),
  4788. }
  4789. service.CreateStockFlowOne(flow)
  4790. //退库数量增加
  4791. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4792. //出库数量减少
  4793. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4794. }
  4795. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4796. var flush_count int64
  4797. for _, it := range goodList {
  4798. flush_count += it.StockCount
  4799. }
  4800. //查询已出库数量
  4801. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4802. if prescribingNumber < dialysisInfo.Count {
  4803. //改变数量
  4804. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4805. }
  4806. if prescribingNumber >= dialysisInfo.Count {
  4807. //删除出库表
  4808. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4809. }
  4810. //更新库存
  4811. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4812. //更新基础库库存
  4813. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4814. }
  4815. }
  4816. }
  4817. }
  4818. //保存耗材出库
  4819. if goodOutConfig.IsOpen == 1 {
  4820. if item.Type == 3 {
  4821. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4822. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4823. good.Total = good.Total + f_count
  4824. service.UpdateGoodInfo(&good)
  4825. operation_time := time.Now().Unix()
  4826. creater := c.GetAdminUserInfo().AdminUser.Id
  4827. //创建退库单
  4828. timeStr := time.Now().Format("2006-01-02")
  4829. timeArr := strings.Split(timeStr, "-")
  4830. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4831. total = total + 1
  4832. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4833. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4834. cancelStock := models.CancelStock{
  4835. OrderNumber: orderNumber,
  4836. OperaTime: operation_time,
  4837. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4838. Creater: creater,
  4839. Ctime: time.Now().Unix(),
  4840. Status: 1,
  4841. ReturnTime: item.RecordDate,
  4842. Type: 1,
  4843. StorehouseId: houseConfig.StorehouseOutInfo,
  4844. IsCheck: 1,
  4845. }
  4846. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4847. if msgerrkonde == gorm.ErrRecordNotFound {
  4848. service.AddSigleCancelStock(&cancelStock)
  4849. }
  4850. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4851. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4852. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4853. //查询该耗材是否出库
  4854. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4855. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4856. deaerler, _ := service.GetDealerById(info.Dealer)
  4857. var total_count int64
  4858. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4859. total_count += count
  4860. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4861. var flush_count int64
  4862. for _, it := range goodList {
  4863. flush_count += it.StockCount
  4864. }
  4865. fmt.Println("历史出库数据", info.Count)
  4866. fmt.Println("出库数量", total_count)
  4867. if info.ID > 0 {
  4868. cancelStockInfo := models.CancelStockInfo{
  4869. GoodId: item.ProjectId,
  4870. CancelStockId: cancel.ID,
  4871. GoodTypeId: good.GoodTypeId,
  4872. Count: prescribingNumber,
  4873. Price: info.Price,
  4874. Total: 0,
  4875. ProductDate: info.ProductDate,
  4876. ExpiryDate: info.ExpiryDate,
  4877. Ctime: time.Now().Unix(),
  4878. Status: 1,
  4879. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4880. OrderNumber: cancel.OrderNumber,
  4881. Type: 0,
  4882. Dealer: deaerler.DealerName,
  4883. Manufacturer: manufacturer.ManufacturerName,
  4884. Number: info.Number,
  4885. RegisterAccount: "",
  4886. Remark: "",
  4887. WarehouseInfoId: info.WarehouseInfotId,
  4888. PatientId: info.PatientId,
  4889. RecordDate: info.SysRecordTime,
  4890. StorehouseId: houseConfig.StorehouseOutInfo,
  4891. IsCheck: 1,
  4892. }
  4893. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4894. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4895. //查询出库数量
  4896. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4897. //出库数据 大于 退库数量
  4898. if len(list) > 0 {
  4899. for _, it := range list {
  4900. //回退库存
  4901. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4902. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4903. var flush_count_one int64
  4904. for _, it := range goodList {
  4905. flush_count_one += it.StockCount
  4906. }
  4907. //查询该批次是否有退库数据
  4908. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4909. creater := c.GetAdminUserInfo().AdminUser.Id
  4910. flow := models.VmStockFlow{
  4911. WarehousingId: it.WarehouseInfotId,
  4912. GoodId: it.GoodId,
  4913. Number: it.Number,
  4914. LicenseNumber: it.LicenseNumber,
  4915. Count: it.Count,
  4916. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4917. PatientId: it.PatientId,
  4918. SystemTime: it.SysRecordTime,
  4919. ConsumableType: 7,
  4920. IsSys: 0,
  4921. WarehousingOrder: "",
  4922. WarehouseOutId: it.WarehouseOutId,
  4923. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4924. IsEdit: 0,
  4925. CancelStockId: cancel.ID,
  4926. CancelOrderNumber: cancel.OrderNumber,
  4927. Manufacturer: manufacturer.ID,
  4928. Dealer: 0,
  4929. Creator: creater,
  4930. UpdateCreator: 0,
  4931. Status: 1,
  4932. Ctime: time.Now().Unix(),
  4933. Mtime: 0,
  4934. Price: it.Price,
  4935. WarehousingDetailId: it.WarehouseInfotId,
  4936. WarehouseOutDetailId: it.ID,
  4937. CancelOutDetailId: cancelInfo.ID,
  4938. ProductDate: it.ProductDate,
  4939. ExpireDate: it.ExpiryDate,
  4940. StorehouseId: houseConfig.StorehouseOutInfo,
  4941. OverCount: flush_count_one,
  4942. }
  4943. service.CreateStockFlowOne(flow)
  4944. //if flow.ID > 0 {
  4945. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4946. //}
  4947. }
  4948. }
  4949. //flow := models.VmStockFlow{
  4950. // WarehousingId: info.WarehouseInfotId,
  4951. // GoodId: item.ProjectId,
  4952. // Number: info.Number,
  4953. // LicenseNumber: info.LicenseNumber,
  4954. // Count: prescribingNumber,
  4955. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4956. // PatientId: item.PatientId,
  4957. // SystemTime: info.SysRecordTime,
  4958. // ConsumableType: 7,
  4959. // IsSys: 0,
  4960. // WarehousingOrder: "",
  4961. // WarehouseOutId: info.WarehouseOutId,
  4962. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4963. // IsEdit: 0,
  4964. // CancelStockId: cancel.ID,
  4965. // CancelOrderNumber: cancel.OrderNumber,
  4966. // Manufacturer: manufacturer.ID,
  4967. // Dealer: 0,
  4968. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4969. // UpdateCreator: 0,
  4970. // Status: 1,
  4971. // Ctime: time.Now().Unix(),
  4972. // Mtime: 0,
  4973. // Price: info.Price,
  4974. // WarehousingDetailId: info.WarehouseInfotId,
  4975. // WarehouseOutDetailId: info.ID,
  4976. // CancelOutDetailId: cancelInfo.ID,
  4977. // ProductDate: info.ProductDate,
  4978. // ExpireDate: info.ExpiryDate,
  4979. // StorehouseId: houseConfig.StorehouseOutInfo,
  4980. // OverCount: flush_count,
  4981. //}
  4982. //service.CreateStockFlowOne(flow)
  4983. //退库数量增加
  4984. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4985. //出库数量减少
  4986. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4987. //查询已出库数量
  4988. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4989. if prescribingNumber < dialysisInfo.Count {
  4990. //改变数量
  4991. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4992. }
  4993. if prescribingNumber >= dialysisInfo.Count {
  4994. //删除出库表
  4995. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4996. }
  4997. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4998. var flush_count_one int64
  4999. for _, it := range goodList {
  5000. flush_count_one += it.StockCount
  5001. }
  5002. //更新库存
  5003. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5004. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5005. //更新基础库库存
  5006. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5007. }
  5008. }
  5009. }
  5010. }
  5011. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5012. fmt.Println(err)
  5013. }
  5014. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5015. fmt.Println(err)
  5016. if len(advices) > 0 {
  5017. for _, item := range advices {
  5018. redis := service.RedisClient()
  5019. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5020. redis.Set(keyFive, "", time.Second)
  5021. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5022. redis.Set(keyOne, "", time.Second)
  5023. redis.Close()
  5024. }
  5025. }
  5026. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5027. if len(advices) > 0 {
  5028. for _, item := range advices {
  5029. creater := c.GetAdminUserInfo().AdminUser.Id
  5030. service.DrugAutoAddCancelInfo(item, creater)
  5031. }
  5032. }
  5033. } else {
  5034. if drugOutConfig.IsOpen == 1 {
  5035. if len(advices) > 0 {
  5036. for _, item := range advices {
  5037. creater := c.GetAdminUserInfo().AdminUser.Id
  5038. service.DrugAutoAddCancelInfo(item, creater)
  5039. }
  5040. }
  5041. } else {
  5042. if len(advices) > 0 {
  5043. for _, item := range advices {
  5044. creater := c.GetAdminUserInfo().AdminUser.Id
  5045. service.DrugAutoAddCancelInfo(item, creater)
  5046. }
  5047. }
  5048. }
  5049. }
  5050. c.ServeSuccessJSON(map[string]interface{}{
  5051. "msg": "删除成功",
  5052. })
  5053. return
  5054. }
  5055. func (c *HisApiController) DeleteDoctorAdvice() {
  5056. id, _ := c.GetInt64("id")
  5057. advice, _ := service.GetHisDoctorAdvicesById(id)
  5058. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5059. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5060. //已收费和已发药的限制逻辑
  5061. isCharge := false
  5062. isMedicine := false
  5063. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5064. //获取今天该患者所有处方,判断是否发药或者收费
  5065. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5066. for _, item := range new_prescriptions {
  5067. if item.IsMedicine == 1 {
  5068. isMedicine = true
  5069. }
  5070. }
  5071. for _, item := range new_prescriptions {
  5072. if item.OrderStatus == 4 {
  5073. isCharge = true
  5074. }
  5075. }
  5076. if isMedicine {
  5077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5078. return
  5079. }
  5080. if isCharge {
  5081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5082. return
  5083. }
  5084. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5085. for _, item := range advices {
  5086. if item.IsMedicine == 1 {
  5087. isMedicine = true
  5088. }
  5089. }
  5090. if isMedicine {
  5091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5092. return
  5093. }
  5094. if new_prescription.ID > 0 {
  5095. if new_prescription.OrderStatus == 2 {
  5096. isCharge = true
  5097. }
  5098. }
  5099. if isCharge {
  5100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5101. return
  5102. }
  5103. //已收费和已发药的限制逻辑
  5104. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5105. redis := service.RedisClient()
  5106. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5107. redis.Set(keyFive, "", time.Second)
  5108. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5109. redis.Set(keyOne, "", time.Second)
  5110. defer redis.Close()
  5111. if err == nil {
  5112. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5113. //查询是否在处方中出库
  5114. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5115. if openConfig.IsOpen != 1 {
  5116. //判断该医嘱是否执行了
  5117. if advice.ExecutionState == 1 {
  5118. creater := c.GetAdminUserInfo().AdminUser.Id
  5119. service.DrugAutoAddCancelInfo(&advice, creater)
  5120. }
  5121. }
  5122. //开启保存处方扣减功能
  5123. if openConfig.IsOpen == 1 {
  5124. creater := c.GetAdminUserInfo().AdminUser.Id
  5125. service.DrugAutoAddCancelInfo(&advice, creater)
  5126. }
  5127. } else {
  5128. if drugOutConfig.IsOpen == 1 {
  5129. //查询是否在处方中出库
  5130. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5131. if openConfig.IsOpen != 1 {
  5132. //判断该医嘱是否执行了
  5133. if advice.ExecutionState == 1 {
  5134. creater := c.GetAdminUserInfo().AdminUser.Id
  5135. service.DrugAutoAddCancelInfo(&advice, creater)
  5136. }
  5137. }
  5138. //开启保存处方扣减功能
  5139. if openConfig.IsOpen == 1 {
  5140. creater := c.GetAdminUserInfo().AdminUser.Id
  5141. service.DrugAutoAddCancelInfo(&advice, creater)
  5142. }
  5143. } else {
  5144. //判断该医嘱是否执行了
  5145. if advice.ExecutionState == 1 {
  5146. creater := c.GetAdminUserInfo().AdminUser.Id
  5147. service.DrugAutoAddCancelInfo(&advice, creater)
  5148. }
  5149. }
  5150. }
  5151. c.ServeSuccessJSON(map[string]interface{}{
  5152. "msg": "删除成功",
  5153. })
  5154. return
  5155. } else {
  5156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5157. return
  5158. }
  5159. }
  5160. func (c *HisApiController) DeleteProject() {
  5161. id, _ := c.GetInt64("id")
  5162. adminInfo := c.GetAdminUserInfo()
  5163. project, _ := service.GetHisProjectByID(id)
  5164. // var consumable models.DialysisBeforePrepare
  5165. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5166. //耗材保存处方出库
  5167. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5168. isCharge := false
  5169. isMedicine := false
  5170. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5171. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5172. for _, item := range new_prescriptions {
  5173. if item.IsMedicine == 1 {
  5174. isMedicine = true
  5175. }
  5176. }
  5177. for _, item := range new_prescriptions {
  5178. if item.OrderStatus == 4 {
  5179. isCharge = true
  5180. }
  5181. }
  5182. if isMedicine {
  5183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5184. return
  5185. }
  5186. if isCharge {
  5187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5188. return
  5189. }
  5190. if new_prescription.ID > 0 {
  5191. if new_prescription.OrderStatus == 2 {
  5192. isCharge = true
  5193. }
  5194. }
  5195. if isCharge {
  5196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5197. return
  5198. }
  5199. service.DeletePrintInfo(id)
  5200. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5201. label.Status = 0
  5202. service.CreateHisLabelRecordTwo(&label)
  5203. fmt.Println(goodOutConfig.IsOpen)
  5204. if goodOutConfig.IsOpen != 1 {
  5205. if stockConfig.IsOpen == 1 {
  5206. if project.Type == 2 {
  5207. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5208. fmt.Println(err)
  5209. }
  5210. if project.Type == 3 && project.IsOut == 1 {
  5211. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5212. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5213. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5214. operation_time := time.Now().Unix()
  5215. creater := adminInfo.AdminUser.Id
  5216. //创建退库单
  5217. timeStr := time.Now().Format("2006-01-02")
  5218. timeArr := strings.Split(timeStr, "-")
  5219. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5220. total = total + 1
  5221. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5222. cancelStock := models.CancelStock{
  5223. OrderNumber: orderNumber,
  5224. OperaTime: operation_time,
  5225. OrgId: adminInfo.CurrentOrgId,
  5226. Creater: creater,
  5227. Ctime: time.Now().Unix(),
  5228. Status: 1,
  5229. ReturnTime: project.RecordDate,
  5230. Type: 1,
  5231. StorehouseId: houseConfig.StorehouseOutInfo,
  5232. IsCheck: 1,
  5233. }
  5234. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5235. if msgerrkonde == gorm.ErrRecordNotFound {
  5236. service.AddSigleCancelStock(&cancelStock)
  5237. }
  5238. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5239. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5240. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5241. //查询是否有出库
  5242. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5243. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5244. deaerler, _ := service.GetDealerById(info.Dealer)
  5245. if info.ID > 0 {
  5246. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5247. if info.Count >= prescribingNumber {
  5248. cancelStockInfo := models.CancelStockInfo{
  5249. GoodId: project.ProjectId,
  5250. CancelStockId: cancel.ID,
  5251. GoodTypeId: good.GoodTypeId,
  5252. Count: prescribingNumber,
  5253. Price: info.Price,
  5254. Total: 0,
  5255. ProductDate: info.ProductDate,
  5256. ExpiryDate: info.ExpiryDate,
  5257. Ctime: time.Now().Unix(),
  5258. Status: 1,
  5259. OrgId: adminInfo.CurrentOrgId,
  5260. OrderNumber: cancel.OrderNumber,
  5261. Type: 0,
  5262. Dealer: deaerler.DealerName,
  5263. Manufacturer: manufacturer.ManufacturerName,
  5264. Number: info.Number,
  5265. RegisterAccount: "",
  5266. Remark: "",
  5267. WarehouseInfoId: info.WarehouseInfotId,
  5268. PatientId: info.PatientId,
  5269. RecordDate: info.SysRecordTime,
  5270. StorehouseId: houseConfig.StorehouseOutInfo,
  5271. IsCheck: 1,
  5272. }
  5273. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5274. //回退库存
  5275. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5276. //退库数量增加
  5277. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5278. //出库数量减少
  5279. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5280. }
  5281. if info.Count < prescribingNumber {
  5282. cancelStockInfo := models.CancelStockInfo{
  5283. GoodId: project.ProjectId,
  5284. CancelStockId: cancel.ID,
  5285. GoodTypeId: good.GoodTypeId,
  5286. Count: info.Count,
  5287. Price: info.Price,
  5288. Total: 0,
  5289. ProductDate: info.ProductDate,
  5290. ExpiryDate: info.ExpiryDate,
  5291. Ctime: time.Now().Unix(),
  5292. Status: 1,
  5293. OrgId: adminInfo.CurrentOrgId,
  5294. OrderNumber: cancel.OrderNumber,
  5295. Type: 0,
  5296. Dealer: deaerler.DealerName,
  5297. Manufacturer: manufacturer.ManufacturerName,
  5298. Number: info.Number,
  5299. RegisterAccount: "",
  5300. Remark: "",
  5301. WarehouseInfoId: info.WarehouseInfotId,
  5302. PatientId: info.PatientId,
  5303. RecordDate: info.SysRecordTime,
  5304. StorehouseId: houseConfig.StorehouseOutInfo,
  5305. IsCheck: 1,
  5306. }
  5307. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5308. //回退库存
  5309. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5310. //退库数量增加
  5311. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5312. //出库数量减少
  5313. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5314. }
  5315. //查询剩余库存
  5316. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5317. var over_count int64
  5318. for _, it := range goodList {
  5319. over_count += it.StockCount
  5320. }
  5321. //出库数据 大于 退库数量
  5322. if info.Count >= prescribingNumber {
  5323. flow := models.VmStockFlow{
  5324. WarehousingId: info.WarehouseInfotId,
  5325. GoodId: project.ProjectId,
  5326. Number: info.Number,
  5327. LicenseNumber: info.LicenseNumber,
  5328. Count: prescribingNumber,
  5329. UserOrgId: adminInfo.CurrentOrgId,
  5330. PatientId: project.PatientId,
  5331. SystemTime: info.SysRecordTime,
  5332. ConsumableType: 7,
  5333. IsSys: 0,
  5334. WarehousingOrder: "",
  5335. WarehouseOutId: info.WarehouseOutId,
  5336. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5337. IsEdit: 0,
  5338. CancelStockId: cancel.ID,
  5339. CancelOrderNumber: cancel.OrderNumber,
  5340. Manufacturer: manufacturer.ID,
  5341. Dealer: 0,
  5342. Creator: adminInfo.AdminUser.Id,
  5343. UpdateCreator: 0,
  5344. Status: 1,
  5345. Ctime: time.Now().Unix(),
  5346. Mtime: 0,
  5347. Price: info.Price,
  5348. WarehousingDetailId: info.WarehouseInfotId,
  5349. WarehouseOutDetailId: info.ID,
  5350. CancelOutDetailId: cancelInfo.ID,
  5351. ProductDate: info.ProductDate,
  5352. ExpireDate: info.ExpiryDate,
  5353. StorehouseId: houseConfig.StorehouseOutInfo,
  5354. OverCount: over_count,
  5355. OperateTime: time.Now().Unix(),
  5356. }
  5357. service.CreateStockFlowOne(flow)
  5358. }
  5359. //出库数据小于退库数据
  5360. if info.Count < prescribingNumber {
  5361. flow := models.VmStockFlow{
  5362. WarehousingId: info.WarehouseInfotId,
  5363. GoodId: project.ProjectId,
  5364. Number: info.Number,
  5365. LicenseNumber: info.LicenseNumber,
  5366. Count: info.Count,
  5367. UserOrgId: adminInfo.CurrentOrgId,
  5368. PatientId: project.PatientId,
  5369. SystemTime: info.SysRecordTime,
  5370. ConsumableType: 7,
  5371. IsSys: 0,
  5372. WarehousingOrder: "",
  5373. WarehouseOutId: info.WarehouseOutId,
  5374. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5375. IsEdit: 0,
  5376. CancelStockId: cancel.ID,
  5377. CancelOrderNumber: cancel.OrderNumber,
  5378. Manufacturer: manufacturer.ID,
  5379. Dealer: 0,
  5380. Creator: adminInfo.AdminUser.Id,
  5381. UpdateCreator: 0,
  5382. Status: 1,
  5383. Ctime: time.Now().Unix(),
  5384. Mtime: 0,
  5385. Price: info.Price,
  5386. WarehousingDetailId: info.WarehouseInfotId,
  5387. WarehouseOutDetailId: info.ID,
  5388. CancelOutDetailId: cancelInfo.ID,
  5389. ProductDate: info.ProductDate,
  5390. ExpireDate: info.ExpiryDate,
  5391. StorehouseId: houseConfig.StorehouseOutInfo,
  5392. OverCount: over_count,
  5393. OperateTime: time.Now().Unix(),
  5394. }
  5395. service.CreateStockFlowOne(flow)
  5396. }
  5397. //查询已出库数量
  5398. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5399. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5400. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5401. if prescribingNumber < dialysisInfo.Count {
  5402. //改变数量
  5403. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5404. }
  5405. if prescribingNumber >= dialysisInfo.Count {
  5406. //删除出库表
  5407. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5408. }
  5409. //更新剩余库存
  5410. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5411. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5412. var total_count_one int64
  5413. for _, it := range stockList {
  5414. total_count_one += it.StockCount
  5415. }
  5416. //基础库插入数据
  5417. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5418. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5419. var flush_count int64
  5420. for _, it := range goodListOne {
  5421. flush_count += it.StockCount
  5422. }
  5423. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5424. if errs != nil {
  5425. goodErrcode := models.XtGoodErrcode{
  5426. UserOrgId: project.UserOrgId,
  5427. Errcode: "手动出库更新剩余出库失败",
  5428. GoodId: project.ProjectId,
  5429. Status: 1,
  5430. Ctime: time.Now().Unix(),
  5431. Mtime: 0,
  5432. Count: 0,
  5433. StockCount: 0,
  5434. Creater: creater,
  5435. BatchNumberId: 0,
  5436. WarehouseOutId: 0,
  5437. }
  5438. service.CreateGoodErrcode(goodErrcode)
  5439. }
  5440. }
  5441. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5442. fmt.Println(err)
  5443. } else {
  5444. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5445. fmt.Println(err)
  5446. }
  5447. } else {
  5448. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5449. fmt.Println(err)
  5450. }
  5451. }
  5452. //保存处方出库
  5453. if goodOutConfig.IsOpen == 1 {
  5454. if project.Type == 3 {
  5455. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5456. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5457. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5458. operation_time := time.Now().Unix()
  5459. creater := adminInfo.AdminUser.Id
  5460. //创建退库单
  5461. timeStr := time.Now().Format("2006-01-02")
  5462. timeArr := strings.Split(timeStr, "-")
  5463. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5464. total = total + 1
  5465. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5466. cancelStock := models.CancelStock{
  5467. OrderNumber: orderNumber,
  5468. OperaTime: operation_time,
  5469. OrgId: adminInfo.CurrentOrgId,
  5470. Creater: creater,
  5471. Ctime: time.Now().Unix(),
  5472. Status: 1,
  5473. ReturnTime: project.RecordDate,
  5474. Type: 1,
  5475. StorehouseId: houseConfig.StorehouseOutInfo,
  5476. IsCheck: 1,
  5477. }
  5478. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5479. if msgerrkonde == gorm.ErrRecordNotFound {
  5480. service.AddSigleCancelStock(&cancelStock)
  5481. }
  5482. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5483. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5484. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5485. //获取出库数据
  5486. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5487. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5488. deaerler, _ := service.GetDealerById(info.Dealer)
  5489. if info.ID > 0 {
  5490. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5491. if info.Count >= prescribingNumber {
  5492. cancelStockInfo := models.CancelStockInfo{
  5493. GoodId: project.ProjectId,
  5494. CancelStockId: cancel.ID,
  5495. GoodTypeId: good.GoodTypeId,
  5496. Count: prescribingNumber,
  5497. Price: info.Price,
  5498. Total: 0,
  5499. ProductDate: info.ProductDate,
  5500. ExpiryDate: info.ExpiryDate,
  5501. Ctime: time.Now().Unix(),
  5502. Status: 1,
  5503. OrgId: adminInfo.CurrentOrgId,
  5504. OrderNumber: cancel.OrderNumber,
  5505. Type: 0,
  5506. Dealer: deaerler.DealerName,
  5507. Manufacturer: manufacturer.ManufacturerName,
  5508. Number: info.Number,
  5509. RegisterAccount: "",
  5510. Remark: "",
  5511. WarehouseInfoId: info.WarehouseInfotId,
  5512. PatientId: info.PatientId,
  5513. RecordDate: info.SysRecordTime,
  5514. StorehouseId: houseConfig.StorehouseOutInfo,
  5515. IsCheck: 1,
  5516. }
  5517. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5518. //退库数量增加
  5519. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5520. //出库数量减少
  5521. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5522. }
  5523. if info.Count < prescribingNumber {
  5524. cancelStockInfo := models.CancelStockInfo{
  5525. GoodId: project.ProjectId,
  5526. CancelStockId: cancel.ID,
  5527. GoodTypeId: good.GoodTypeId,
  5528. Count: prescribingNumber,
  5529. Price: info.Price,
  5530. Total: 0,
  5531. ProductDate: info.ProductDate,
  5532. ExpiryDate: info.ExpiryDate,
  5533. Ctime: time.Now().Unix(),
  5534. Status: 1,
  5535. OrgId: adminInfo.CurrentOrgId,
  5536. OrderNumber: cancel.OrderNumber,
  5537. Type: 0,
  5538. Dealer: deaerler.DealerName,
  5539. Manufacturer: manufacturer.ManufacturerName,
  5540. Number: info.Number,
  5541. RegisterAccount: "",
  5542. Remark: "",
  5543. WarehouseInfoId: info.WarehouseInfotId,
  5544. PatientId: info.PatientId,
  5545. RecordDate: info.SysRecordTime,
  5546. StorehouseId: houseConfig.StorehouseOutInfo,
  5547. IsCheck: 1,
  5548. }
  5549. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5550. //回退库存
  5551. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5552. }
  5553. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5554. var over_count int64
  5555. for _, it := range goodList {
  5556. over_count += it.StockCount
  5557. }
  5558. //查询出库数量
  5559. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5560. //出库数据 大于 退库数量
  5561. if len(list) > 0 {
  5562. for _, it := range list {
  5563. //回退库存
  5564. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5565. //退库数量增加
  5566. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5567. //出库数量减少
  5568. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5569. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5570. var over_count_one int64
  5571. for _, it := range goodList {
  5572. over_count_one += it.StockCount
  5573. }
  5574. //查询该批次是否有退库数据
  5575. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5576. flow := models.VmStockFlow{
  5577. WarehousingId: it.WarehouseInfotId,
  5578. GoodId: it.GoodId,
  5579. Number: it.Number,
  5580. LicenseNumber: it.LicenseNumber,
  5581. Count: it.Count,
  5582. UserOrgId: adminInfo.CurrentOrgId,
  5583. PatientId: it.PatientId,
  5584. SystemTime: it.SysRecordTime,
  5585. ConsumableType: 7,
  5586. IsSys: 0,
  5587. WarehousingOrder: "",
  5588. WarehouseOutId: it.WarehouseOutId,
  5589. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5590. IsEdit: 0,
  5591. CancelStockId: cancel.ID,
  5592. CancelOrderNumber: cancel.OrderNumber,
  5593. Manufacturer: manufacturer.ID,
  5594. Dealer: 0,
  5595. Creator: adminInfo.AdminUser.Id,
  5596. UpdateCreator: 0,
  5597. Status: 1,
  5598. Ctime: time.Now().Unix(),
  5599. Mtime: 0,
  5600. Price: it.Price,
  5601. WarehousingDetailId: it.WarehouseInfotId,
  5602. WarehouseOutDetailId: it.ID,
  5603. CancelOutDetailId: cancelInfo.ID,
  5604. ProductDate: it.ProductDate,
  5605. ExpireDate: it.ExpiryDate,
  5606. StorehouseId: houseConfig.StorehouseOutInfo,
  5607. OverCount: over_count_one,
  5608. OperateTime: time.Now().Unix(),
  5609. }
  5610. service.CreateStockFlowOne(flow)
  5611. }
  5612. }
  5613. //查询已出库数量
  5614. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5615. if prescribingNumber < dialysisInfo.Count {
  5616. //改变数量
  5617. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5618. }
  5619. if prescribingNumber >= dialysisInfo.Count {
  5620. //删除出库表
  5621. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5622. }
  5623. //更新剩余库存
  5624. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5625. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5626. var total_count_one int64
  5627. for _, it := range stockList {
  5628. total_count_one += it.StockCount
  5629. }
  5630. //基础库插入数据
  5631. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5632. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5633. var flush_count int64
  5634. for _, it := range goodListOne {
  5635. flush_count += it.StockCount
  5636. }
  5637. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5638. if errs != nil {
  5639. goodErrcode := models.XtGoodErrcode{
  5640. UserOrgId: project.UserOrgId,
  5641. Errcode: "手动出库更新剩余出库失败",
  5642. GoodId: project.ProjectId,
  5643. Status: 1,
  5644. Ctime: time.Now().Unix(),
  5645. Mtime: 0,
  5646. Count: 0,
  5647. StockCount: 0,
  5648. Creater: creater,
  5649. BatchNumberId: 0,
  5650. WarehouseOutId: 0,
  5651. }
  5652. service.CreateGoodErrcode(goodErrcode)
  5653. }
  5654. }
  5655. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5656. fmt.Println(err)
  5657. } else {
  5658. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5659. fmt.Println(err)
  5660. }
  5661. }
  5662. c.ServeSuccessJSON(map[string]interface{}{
  5663. "msg": "删除成功",
  5664. })
  5665. return
  5666. }
  5667. func (c *HisApiController) CreateHisAdditionalCharge() {
  5668. his_patient_id, _ := c.GetInt64("his_patient_id")
  5669. patient_id, _ := c.GetInt64("patient_id")
  5670. record_date := c.GetString("record_date")
  5671. timeLayout := "2006-01-02"
  5672. loc, _ := time.LoadLocation("Local")
  5673. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5674. if err != nil {
  5675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5676. return
  5677. }
  5678. adminInfo := c.GetAdminUserInfo()
  5679. recordDateTime := theTime.Unix()
  5680. dataBody := make(map[string]interface{}, 0)
  5681. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5682. if err != nil {
  5683. utils.ErrorLog(err.Error())
  5684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5685. return
  5686. }
  5687. var additions []*models.HisAdditionalCharge
  5688. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5689. additions, _ := dataBody["addition"].([]interface{})
  5690. if len(additions) > 0 {
  5691. for _, item := range additions {
  5692. items := item.(map[string]interface{})
  5693. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5694. utils.ErrorLog("item_id")
  5695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5696. return
  5697. }
  5698. item_id := int64(items["item_id"].(float64))
  5699. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5700. utils.ErrorLog("item_name")
  5701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5702. return
  5703. }
  5704. item_name := items["item_name"].(string)
  5705. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5706. utils.ErrorLog("price")
  5707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5708. return
  5709. }
  5710. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5711. ctime := time.Now().Unix()
  5712. additional := &models.HisAdditionalCharge{
  5713. PatientId: patient_id,
  5714. HisPatientId: his_patient_id,
  5715. UserOrgId: adminInfo.CurrentOrgId,
  5716. RecordDate: recordDateTime,
  5717. CreatedTime: ctime,
  5718. UpdatedTime: ctime,
  5719. Modifier: adminInfo.AdminUser.Id,
  5720. Creator: adminInfo.AdminUser.Id,
  5721. Price: price,
  5722. ItemName: item_name,
  5723. ItemId: item_id,
  5724. Status: 1,
  5725. }
  5726. additions = append(additions, additional)
  5727. }
  5728. }
  5729. }
  5730. for _, item := range additions {
  5731. service.CreateAddtionalCharge(item)
  5732. }
  5733. c.ServeSuccessJSON(map[string]interface{}{
  5734. "msg": "创建成功",
  5735. })
  5736. }
  5737. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5738. blood_fat := c.GetString("blood_fat")
  5739. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5740. blood_sugar := c.GetString("blood_sugar")
  5741. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5742. chief_conplaint := c.GetString("chief_conplaint")
  5743. dbp := c.GetString("dbp")
  5744. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5745. delivery_way, _ := c.GetInt64("delivery_way")
  5746. diagnostic := c.GetString("diagnostic")
  5747. family_history := c.GetString("family_history")
  5748. height := c.GetString("height")
  5749. history_of_present_illness := c.GetString("history_of_present_illness")
  5750. is_infect, _ := c.GetInt64("is_infect")
  5751. past_history := c.GetString("past_history")
  5752. patient_id, _ := c.GetInt64("patient_id")
  5753. his_patient_id, _ := c.GetInt64("his_patient_id")
  5754. personal_history := c.GetString("personal_history")
  5755. pulse := c.GetString("pulse")
  5756. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5757. sbp := c.GetString("sbp")
  5758. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5759. heightfloat, _ := strconv.ParseFloat(height, 64)
  5760. sicktype := c.GetString("sick_type")
  5761. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5762. symptom := c.GetString("symptom")
  5763. sick_date := c.GetString("sick_date")
  5764. temperatures := c.GetString("temperature")
  5765. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5766. record_date := c.GetString("record_date")
  5767. breathing := c.GetString("breathing")
  5768. doctor_advice := c.GetString("doctor_advice")
  5769. remark := c.GetString("remark")
  5770. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5771. sick, _ := c.GetInt64("sick")
  5772. diagnose, _ := c.GetInt64("diagnose")
  5773. //id, _ := c.GetInt64("id")
  5774. timeLayout := "2006-01-02"
  5775. loc, _ := time.LoadLocation("Local")
  5776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5777. allergic_history := c.GetString("allergic_history")
  5778. if err != nil {
  5779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5780. return
  5781. }
  5782. recordDateTime := theTime.Unix()
  5783. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5784. if err != nil {
  5785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5786. return
  5787. }
  5788. sickTimes := sickTime.Unix()
  5789. ctime := time.Now().Unix()
  5790. primary_disease := c.GetString("primary_disease")
  5791. confirm_failure_date := c.GetString("confirm_failure_date")
  5792. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5793. drug_allergy_history := c.GetString("drug_allergy_history")
  5794. physical_examination := c.GetString("physical_examination")
  5795. special_inspection := c.GetString("special_inspection")
  5796. lab_apparatus := c.GetString("lab_apparatus")
  5797. caseHistory := models.HisPatientCaseHistory{
  5798. HisPatientId: his_patient_id,
  5799. PatientId: patient_id,
  5800. Temperature: temperature,
  5801. BloodSugar: bloodsugarfloat,
  5802. Pulse: pulsefloat,
  5803. Sbp: sbpfloat,
  5804. Dbp: dbpfloat,
  5805. Height: heightfloat,
  5806. BloodFat: bloodfatfloat,
  5807. SickType: sick_type,
  5808. Symptom: symptom,
  5809. SickDate: sickTimes,
  5810. IsInfect: is_infect,
  5811. HistoryOfPresentIllness: history_of_present_illness,
  5812. PastHistory: past_history,
  5813. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5814. ChiefConplaint: chief_conplaint,
  5815. PersonalHistory: personal_history,
  5816. FamilyHistory: family_history,
  5817. Diagnostic: diagnostic,
  5818. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5819. Status: 1,
  5820. Ctime: ctime,
  5821. Mtime: ctime,
  5822. RecordDate: recordDateTime,
  5823. DeliveryWay: delivery_way,
  5824. Breathing: breathingfloat,
  5825. DoctorAdvice: doctor_advice,
  5826. Remark: remark,
  5827. Sick: sick,
  5828. Diagnose: diagnose,
  5829. AllergicHistory: allergic_history,
  5830. PrimaryDisease: primary_disease,
  5831. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5832. DrugAllergyHistory: drug_allergy_history,
  5833. PhysicalExamination: physical_examination,
  5834. SpecialInspection: special_inspection,
  5835. LabApparatus: lab_apparatus,
  5836. }
  5837. //查询该患者是否有病历
  5838. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5839. if errcodes == gorm.ErrRecordNotFound {
  5840. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5841. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5842. if err != nil {
  5843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5844. return
  5845. }
  5846. c.ServeSuccessJSON(map[string]interface{}{
  5847. "caseHistory": caseHistory,
  5848. "historyInfo": historyInfo,
  5849. })
  5850. return
  5851. } else if errcodes == nil {
  5852. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5853. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5854. if err != nil {
  5855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5856. return
  5857. }
  5858. c.ServeSuccessJSON(map[string]interface{}{
  5859. "caseHistory": caseHistory,
  5860. "historyInfo": historyInfo,
  5861. })
  5862. }
  5863. //查询该患者是否有病历
  5864. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5865. //if errcode == gorm.ErrRecordNotFound {
  5866. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5867. // if err != nil {
  5868. // c.ServeSuccessJSON(map[string]interface{}{
  5869. // "msg": "保存成功",
  5870. // })
  5871. // }
  5872. //} else if errcode == nil {
  5873. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5874. // return
  5875. //}
  5876. }
  5877. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5878. patient_id, _ := c.GetInt64("patient_id", 0)
  5879. adminUser := c.GetAdminUserInfo()
  5880. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5881. c.ServeSuccessJSON(map[string]interface{}{
  5882. "list": caseHistorys,
  5883. })
  5884. }
  5885. func (c *HisApiController) GetHisPatientCaseHistory() {
  5886. record_date, _ := c.GetInt64("record_date", 0)
  5887. patient_id, _ := c.GetInt64("patient_id", 0)
  5888. admin := c.GetAdminUserInfo()
  5889. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5890. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5891. c.ServeSuccessJSON(map[string]interface{}{
  5892. "info": info,
  5893. "case_history": case_history,
  5894. })
  5895. }
  5896. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5897. template_name := c.GetString("template_name")
  5898. template_remark := c.GetString("template_remark")
  5899. doctor := c.GetAdminUserInfo().AdminUser.Id
  5900. diagnostic := c.GetString("diagnostic")
  5901. chief_conplaint := c.GetString("chief_conplain")
  5902. history_of_present_illness := c.GetString("history_of_present_illness")
  5903. past_history := c.GetString("past_history")
  5904. personal_history := c.GetString("personal_history")
  5905. family_history := c.GetString("family_history")
  5906. user_name := c.GetString("user_name")
  5907. doctor_advice := c.GetString("doctor_advice")
  5908. remark := c.GetString("remark")
  5909. //record_date := c.GetString("record_date")
  5910. //fmt.Println("record_date--------",record_date)
  5911. //timeLayout := "2006-01-02"
  5912. //loc, _ := time.LoadLocation("Local")
  5913. //
  5914. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5915. //if err != nil {
  5916. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5917. // return
  5918. //}
  5919. //recordDateTime := theTime.Unix()
  5920. ctime := time.Now().Unix()
  5921. template := models.HisCaseHistoryTemplate{
  5922. HistoryOfPresentIllness: history_of_present_illness,
  5923. PastHistory: past_history,
  5924. ChiefConplaint: chief_conplaint,
  5925. PersonalHistory: personal_history,
  5926. FamilyHistory: family_history,
  5927. Diagnostic: diagnostic,
  5928. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5929. Status: 1,
  5930. Ctime: ctime,
  5931. Mtime: ctime,
  5932. RecordDate: time.Now().Unix(),
  5933. TemplateName: template_name,
  5934. TemplateRemark: template_remark,
  5935. Creator: doctor,
  5936. Modifier: doctor,
  5937. UserName: user_name,
  5938. DoctorAdvice: doctor_advice,
  5939. Remark: remark,
  5940. }
  5941. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5942. if err == nil {
  5943. c.ServeSuccessJSON(map[string]interface{}{
  5944. "msg": "保存成功",
  5945. })
  5946. } else {
  5947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5948. return
  5949. }
  5950. }
  5951. func (c *HisApiController) GetCaseHistoryTemplate() {
  5952. timeLayout := "2006-01-02"
  5953. loc, _ := time.LoadLocation("Local")
  5954. keyword := c.GetString("keyword")
  5955. start_time := c.GetString("start_time")
  5956. end_time := c.GetString("end_time")
  5957. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5958. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5959. admin := c.GetAdminUserInfo()
  5960. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5961. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5962. c.ServeSuccessJSON(map[string]interface{}{
  5963. "template": template,
  5964. //"history": history,
  5965. })
  5966. }
  5967. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5968. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5969. utils.ErrorLog("drug_name")
  5970. return enums.ErrorCodeParamWrong
  5971. }
  5972. adviceName, _ := json["drug_name"].(string)
  5973. if len(adviceName) == 0 {
  5974. utils.ErrorLog("len(advice_name) == 0")
  5975. return enums.ErrorCodeParamWrong
  5976. }
  5977. advice.AdviceName = adviceName
  5978. adviceDesc, _ := json["advice_desc"].(string)
  5979. advice.AdviceDesc = adviceDesc
  5980. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5981. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5982. advice.DrugSpec = drugSpec
  5983. }
  5984. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5985. remark, _ := json["remark"].(string)
  5986. advice.Remark = remark
  5987. }
  5988. if json["id"] == nil {
  5989. advice.DrugId = 0
  5990. } else {
  5991. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5992. drug_id := int64(json["id"].(float64))
  5993. advice.DrugId = drug_id
  5994. }
  5995. }
  5996. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5997. advice_id := int64(json["advice_id"].(float64))
  5998. advice.ID = advice_id
  5999. if advice.ID > 0 {
  6000. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6001. if err == nil {
  6002. if hisAdvice.ID > 0 {
  6003. advice.ExecutionTime = hisAdvice.ExecutionTime
  6004. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6005. advice.ExecutionState = hisAdvice.ExecutionState
  6006. advice.CheckTime = hisAdvice.CheckTime
  6007. advice.Checker = hisAdvice.Checker
  6008. advice.CheckState = hisAdvice.CheckState
  6009. advice.StartTime = hisAdvice.StartTime
  6010. advice.FeedetlSn = hisAdvice.FeedetlSn
  6011. }
  6012. }
  6013. }
  6014. }
  6015. //
  6016. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6017. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6018. // advice.ExecutionTime = execution_time
  6019. //}
  6020. //
  6021. //
  6022. //
  6023. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6024. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6025. // advice.ExecutionStaff = execution_staff
  6026. //}
  6027. //
  6028. //
  6029. //
  6030. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6031. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6032. // advice.ExecutionState = execution_state
  6033. //}
  6034. //
  6035. //
  6036. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6037. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6038. // advice.CheckTime = check_time
  6039. //}
  6040. //
  6041. //
  6042. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6043. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6044. // advice.CheckState = check_state
  6045. //}
  6046. //
  6047. //
  6048. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6049. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6050. // advice.Checker = checker
  6051. //}
  6052. //
  6053. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6054. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6055. // advice.StartTime = start_time
  6056. //}
  6057. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6058. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6059. advice.IsSelfDrug = is_self_drug
  6060. }
  6061. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6062. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6063. drug_way_count, _ := json["drug_way_count"].(string)
  6064. advice.DrugWayCount = drug_way_count
  6065. }
  6066. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6067. drugSpecUnit, _ := json["min_unit"].(string)
  6068. advice.DrugSpecUnit = drugSpecUnit
  6069. }
  6070. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6071. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6072. advice.SingleDose = singleDose
  6073. }
  6074. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6075. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6076. advice.SingleDoseUnit = singleDoseUnit
  6077. }
  6078. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6079. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6080. advice.PrescribingNumber = prescribingNumber
  6081. }
  6082. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6083. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6084. advice.PrescribingNumberUnit = prescribingNumberUnit
  6085. }
  6086. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6087. deliveryWay, _ := json["delivery_way"].(string)
  6088. advice.DeliveryWay = deliveryWay
  6089. }
  6090. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6091. executionFrequency, _ := json["execution_frequency"].(string)
  6092. advice.ExecutionFrequency = executionFrequency
  6093. }
  6094. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6095. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6096. advice.Price = price
  6097. }
  6098. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6099. med_list_codg, _ := json["medical_insurance_number"].(string)
  6100. advice.MedListCodg = med_list_codg
  6101. }
  6102. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6103. day := int64(json["day"].(float64))
  6104. advice.Day = day
  6105. }
  6106. return 0
  6107. }
  6108. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6109. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6110. id := int64(json["id"].(float64))
  6111. project.ID = id
  6112. historyProject, _ := service.GetHisProjectByID(id)
  6113. project.FeedetlSn = historyProject.FeedetlSn
  6114. }
  6115. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6116. project_id := int64(json["project_id"].(float64))
  6117. project.ProjectId = project_id
  6118. }
  6119. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6120. // price := int64(json["price"].(float64))
  6121. // formatInt_price := strconv.FormatInt(price, 10)
  6122. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6123. // project.Price = float_price
  6124. // }
  6125. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6126. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6127. project.Price = price
  6128. }
  6129. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6130. total, _ := json["total"].(string)
  6131. project.Count = total
  6132. }
  6133. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6134. medical_code, _ := json["medical_code"].(string)
  6135. project.MedListCodg = medical_code
  6136. }
  6137. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6138. single_dose, _ := json["single_dose"].(string)
  6139. project.SingleDose = single_dose
  6140. }
  6141. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6142. delivery_way, _ := json["delivery_way"].(string)
  6143. project.DeliveryWay = delivery_way
  6144. }
  6145. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6146. execution_frequency, _ := json["execution_frequency"].(string)
  6147. project.ExecutionFrequency = execution_frequency
  6148. }
  6149. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6150. remark, _ := json["remark"].(string)
  6151. project.Remark = remark
  6152. }
  6153. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6154. day, _ := json["number_days"].(string)
  6155. project.Day = day
  6156. }
  6157. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6158. unit, _ := json["unit"].(string)
  6159. project.Unit = unit
  6160. }
  6161. return 0
  6162. }
  6163. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6164. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6165. id := int64(json["id"].(float64))
  6166. historyAddtions, _ := service.GetHisAdditionByID(id)
  6167. additionalCharge.ID = id
  6168. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6169. }
  6170. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6171. item_id := int64(json["item_id"].(float64))
  6172. additionalCharge.ItemId = item_id
  6173. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6174. if config.ID > 0 {
  6175. if len(config.Code) > 0 {
  6176. additionalCharge.MedListCodg = config.Code
  6177. }
  6178. }
  6179. }
  6180. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6181. // price := int64(json["price"].(float64))
  6182. // formatInt_price := strconv.FormatInt(price, 10)
  6183. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6184. // additionalCharge.Price = float_price
  6185. // }
  6186. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6187. // price := int64(json["price"].(float64))
  6188. // formatInt_price := strconv.FormatInt(price, 10)
  6189. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6190. // additionalCharge.Price = float_price
  6191. //}
  6192. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6193. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6194. additionalCharge.Price = price
  6195. }
  6196. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6197. count, _ := json["count"].(string)
  6198. counts, _ := strconv.ParseInt(count, 10, 64)
  6199. additionalCharge.Count = counts
  6200. }
  6201. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6202. item_name, _ := json["item_name"].(string)
  6203. additionalCharge.ItemName = item_name
  6204. }
  6205. return 0
  6206. }
  6207. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6208. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6209. utils.ErrorLog("drug_name")
  6210. return enums.ErrorCodeParamWrong
  6211. }
  6212. adviceName, _ := json["drug_name"].(string)
  6213. if len(adviceName) == 0 {
  6214. utils.ErrorLog("len(advice_name) == 0")
  6215. return enums.ErrorCodeParamWrong
  6216. }
  6217. advice.AdviceName = adviceName
  6218. adviceDesc, _ := json["advice_desc"].(string)
  6219. advice.AdviceDesc = adviceDesc
  6220. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6221. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6222. advice.DrugSpec = drugSpec
  6223. }
  6224. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6225. remark, _ := json["remark"].(string)
  6226. advice.Remark = remark
  6227. }
  6228. if json["id"] == nil {
  6229. advice.DrugId = 0
  6230. } else {
  6231. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6232. drug_id := int64(json["id"].(float64))
  6233. advice.DrugId = drug_id
  6234. }
  6235. }
  6236. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6237. groupno := int64(json["groupno"].(float64))
  6238. advice.Groupno = groupno
  6239. }
  6240. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6241. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6242. advice.IsSelfDrug = is_self_drug
  6243. }
  6244. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6245. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6246. drug_way_count, _ := json["drug_way_count"].(string)
  6247. advice.DrugWayCount = drug_way_count
  6248. }
  6249. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6250. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6251. advice.HospApprFlag = hosp_appr_flag
  6252. }
  6253. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6254. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6255. advice.PrescribingNumber = prescribingNumber
  6256. }
  6257. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6258. // frequency_type := int64(json["frequency_type"].(float64))
  6259. // advice.FrequencyType = frequency_type
  6260. //}
  6261. //
  6262. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6263. // day_count := int64(json["day_count"].(float64))
  6264. // advice.DayCount = day_count
  6265. //}
  6266. //
  6267. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6268. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6269. // week_day, _ := json["week_day"].(string)
  6270. // advice.WeekDay = week_day
  6271. //}
  6272. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6273. drugSpecUnit, _ := json["min_unit"].(string)
  6274. advice.DrugSpecUnit = drugSpecUnit
  6275. }
  6276. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6277. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6278. advice.SingleDose = singleDose
  6279. }
  6280. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6281. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6282. advice.SingleDoseUnit = singleDoseUnit
  6283. }
  6284. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6285. deliveryWay, _ := json["delivery_way"].(string)
  6286. advice.DeliveryWay = deliveryWay
  6287. }
  6288. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6289. executionFrequency, _ := json["execution_frequency"].(string)
  6290. advice.ExecutionFrequency = executionFrequency
  6291. }
  6292. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6293. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6294. advice.Price = price
  6295. }
  6296. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6297. med_list_codg, _ := json["medical_insurance_number"].(string)
  6298. advice.MedListCodg = med_list_codg
  6299. }
  6300. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6301. day := int64(json["day"].(float64))
  6302. advice.Day = day
  6303. }
  6304. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6305. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6306. advice.PrescribingNumberUnit = prescribingNumberUnit
  6307. }
  6308. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6309. advice_id := int64(json["advice_id"].(float64))
  6310. advice.ID = advice_id
  6311. if advice.ID > 0 {
  6312. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6313. if err == nil {
  6314. if hisAdvice.ID > 0 {
  6315. advice.ExecutionTime = hisAdvice.ExecutionTime
  6316. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6317. advice.ExecutionState = hisAdvice.ExecutionState
  6318. advice.CheckTime = hisAdvice.CheckTime
  6319. advice.Checker = hisAdvice.Checker
  6320. advice.CheckState = hisAdvice.CheckState
  6321. advice.StartTime = hisAdvice.StartTime
  6322. advice.HospApprFlag = hisAdvice.HospApprFlag
  6323. advice.IsMedicine = hisAdvice.IsMedicine
  6324. if hisAdvice.UserOrgId == 10028 {
  6325. 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 {
  6326. advice.ExecutionTime = 0
  6327. advice.ExecutionStaff = 0
  6328. advice.ExecutionState = 2
  6329. advice.CheckTime = 0
  6330. advice.Checker = 0
  6331. advice.CheckState = 2
  6332. }
  6333. } else {
  6334. 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 {
  6335. advice.ExecutionTime = 0
  6336. advice.ExecutionStaff = 0
  6337. advice.ExecutionState = 2
  6338. advice.CheckTime = 0
  6339. advice.Checker = 0
  6340. advice.CheckState = 2
  6341. advice.UpdatedTime = time.Now().Unix()
  6342. }
  6343. }
  6344. //advice.Groupno = hisAdvice.Groupno
  6345. }
  6346. }
  6347. }
  6348. }
  6349. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6350. //
  6351. //if drugStockConfig.IsOpen == 1 {
  6352. //
  6353. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6354. // if advice.ID == 0 { //医嘱不存在
  6355. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6356. // drug.Total = drug.Total - advice.PrescribingNumber
  6357. // service.UpdateBaseDrugLib(&drug)
  6358. //
  6359. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6360. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6361. // drug.Total = drug.Total - num
  6362. // service.UpdateBaseDrugLib(&drug)
  6363. // }
  6364. //
  6365. // } else if advice.ID > 0 { //医嘱存在
  6366. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6367. // var num float64
  6368. //
  6369. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6370. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6371. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6372. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6373. // drug.Total = drug.Total + num
  6374. // service.UpdateBaseDrugLib(&drug)
  6375. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6376. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6377. // drug.Total = drug.Total - num
  6378. // service.UpdateBaseDrugLib(&drug)
  6379. // }
  6380. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6381. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6382. // if num2 > advice.PrescribingNumber {
  6383. // num = num2 - advice.PrescribingNumber
  6384. // drug.Total = drug.Total + num
  6385. // service.UpdateBaseDrugLib(&drug)
  6386. // } else if num2 < advice.PrescribingNumber {
  6387. // num = advice.PrescribingNumber - num2
  6388. // drug.Total = drug.Total - num
  6389. // service.UpdateBaseDrugLib(&drug)
  6390. // }
  6391. //
  6392. // }
  6393. //
  6394. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6395. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6396. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6397. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6398. // if num1 > num2 {
  6399. // num = num1 - num2
  6400. // drug.Total = drug.Total + num
  6401. // service.UpdateBaseDrugLib(&drug)
  6402. // } else if num1 < num2 {
  6403. // num = num2 - num1
  6404. // drug.Total = drug.Total - num
  6405. // service.UpdateBaseDrugLib(&drug)
  6406. // }
  6407. //
  6408. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6409. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6410. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6411. // if hisAdvice.PrescribingNumber > num2 {
  6412. // num = hisAdvice.PrescribingNumber - num2
  6413. // drug.Total = drug.Total + num
  6414. // service.UpdateBaseDrugLib(&drug)
  6415. // } else if num2 < advice.PrescribingNumber {
  6416. // num = num2 - hisAdvice.PrescribingNumber
  6417. // drug.Total = drug.Total - num
  6418. // service.UpdateBaseDrugLib(&drug)
  6419. // }
  6420. //
  6421. // }
  6422. // }
  6423. // }
  6424. //}
  6425. //
  6426. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6427. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6428. // advice.ExecutionTime = execution_time
  6429. //}
  6430. //
  6431. //
  6432. //
  6433. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6434. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6435. // advice.ExecutionStaff = execution_staff
  6436. //}
  6437. //
  6438. //
  6439. //
  6440. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6441. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6442. // advice.ExecutionState = execution_state
  6443. //}
  6444. //
  6445. //
  6446. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6447. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6448. // advice.CheckTime = check_time
  6449. //}
  6450. //
  6451. //
  6452. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6453. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6454. // advice.CheckState = check_state
  6455. //}
  6456. //
  6457. //
  6458. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6459. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6460. // advice.Checker = checker
  6461. //}
  6462. //
  6463. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6464. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6465. // advice.StartTime = start_time
  6466. //}
  6467. return 0
  6468. }
  6469. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6470. project.ExecutionStaff = 0
  6471. project.ExecutionState = 2
  6472. project.ExecutionTime = 0
  6473. project.Checker = 0
  6474. project.CheckState = 2
  6475. project.CheckTime = 0
  6476. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6477. id := int64(json["id"].(float64))
  6478. project.ID = id
  6479. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6480. project.ExecutionStaff = temp_project.ExecutionStaff
  6481. project.ExecutionState = temp_project.ExecutionState
  6482. project.ExecutionTime = temp_project.ExecutionTime
  6483. project.Checker = temp_project.Checker
  6484. project.CheckState = temp_project.CheckState
  6485. project.CheckTime = temp_project.CheckTime
  6486. project.TeamId = temp_project.TeamId
  6487. }
  6488. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6489. types := int64(json["type"].(float64))
  6490. project.Type = types
  6491. }
  6492. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6493. project_id := int64(json["project_id"].(float64))
  6494. project.ProjectId = project_id
  6495. }
  6496. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6497. team_id := int64(json["team_id"].(float64))
  6498. project.TeamId = team_id
  6499. }
  6500. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6501. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6502. project.Price = price
  6503. }
  6504. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6505. total, _ := json["total"].(string)
  6506. //totals, _ := strconv.ParseInt(total, 10, 64)
  6507. project.Count = total
  6508. }
  6509. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6510. medical_code, _ := json["medical_code"].(string)
  6511. project.MedListCodg = medical_code
  6512. }
  6513. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6514. single_dose, _ := json["single_dose"].(string)
  6515. project.SingleDose = single_dose
  6516. }
  6517. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6518. delivery_way, _ := json["delivery_way"].(string)
  6519. project.DeliveryWay = delivery_way
  6520. }
  6521. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6522. execution_frequency, _ := json["execution_frequency"].(string)
  6523. project.ExecutionFrequency = execution_frequency
  6524. }
  6525. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6526. remark, _ := json["remark"].(string)
  6527. project.Remark = remark
  6528. }
  6529. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6530. day, _ := json["number_days"].(string)
  6531. project.Day = day
  6532. }
  6533. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6534. unit, _ := json["unit"].(string)
  6535. project.Unit = unit
  6536. }
  6537. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6538. // frequency_type := int64(json["frequency_type"].(float64))
  6539. // project.FrequencyType = frequency_type
  6540. //}
  6541. //
  6542. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6543. // day_count := int64(json["day_count"].(float64))
  6544. // project.DayCount = day_count
  6545. //}
  6546. //
  6547. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6548. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6549. // week_day, _ := json["week_day"].(string)
  6550. // project.WeekDay = week_day
  6551. //}
  6552. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6553. //
  6554. //if project.ID == 0 {
  6555. // if stockConfig.IsOpen == 1 {
  6556. // if project.Type == 3 {
  6557. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6558. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6559. // good.Total = good.Total - f_count
  6560. // service.UpdateGoodInfo(&good)
  6561. // }
  6562. // }
  6563. //
  6564. //} else {
  6565. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6566. //
  6567. // if stockConfig.IsOpen == 1 {
  6568. // if project.Type == 3 {
  6569. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6570. // if project.Count < temp_project.Count {
  6571. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6572. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6573. //
  6574. // other_count := f_count_two - f_count_one
  6575. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6576. // good.Total = good.Total + other_count_two
  6577. // service.UpdateGoodInfo(&good)
  6578. // } else if project.Count > temp_project.Count {
  6579. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6580. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6581. //
  6582. // other_count := f_count_one - f_count_two
  6583. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6584. // good.Total = good.Total - other_count_two
  6585. // service.UpdateGoodInfo(&good)
  6586. // }
  6587. //
  6588. // }
  6589. // }
  6590. //
  6591. //}
  6592. return 0
  6593. }
  6594. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6595. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6596. utils.ErrorLog("drug_name")
  6597. return enums.ErrorCodeParamWrong
  6598. }
  6599. adviceName, _ := json["drug_name"].(string)
  6600. if len(adviceName) == 0 {
  6601. utils.ErrorLog("len(advice_name) == 0")
  6602. return enums.ErrorCodeParamWrong
  6603. }
  6604. advice.AdviceName = adviceName
  6605. adviceDesc, _ := json["advice_desc"].(string)
  6606. advice.AdviceDesc = adviceDesc
  6607. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6608. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6609. advice.DrugSpec = drugSpec
  6610. }
  6611. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6612. remark, _ := json["remark"].(string)
  6613. advice.Remark = remark
  6614. }
  6615. if json["id"] == nil {
  6616. advice.DrugId = 0
  6617. } else {
  6618. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6619. drug_id := int64(json["id"].(float64))
  6620. advice.DrugId = drug_id
  6621. }
  6622. }
  6623. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6624. groupno := int64(json["groupno"].(float64))
  6625. advice.Groupno = groupno
  6626. }
  6627. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6628. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6629. advice.IsSelfDrug = is_self_drug
  6630. }
  6631. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6632. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6633. drug_way_count, _ := json["drug_way_count"].(string)
  6634. advice.DrugWayCount = drug_way_count
  6635. }
  6636. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6637. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6638. advice.HospApprFlag = hosp_appr_flag
  6639. }
  6640. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6641. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6642. advice.PrescribingNumber = prescribingNumber
  6643. }
  6644. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6645. // frequency_type := int64(json["frequency_type"].(float64))
  6646. // advice.FrequencyType = frequency_type
  6647. //}
  6648. //
  6649. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6650. // day_count := int64(json["day_count"].(float64))
  6651. // advice.DayCount = day_count
  6652. //}
  6653. //
  6654. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6655. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6656. // week_day, _ := json["week_day"].(string)
  6657. // advice.WeekDay = week_day
  6658. //}
  6659. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6660. drugSpecUnit, _ := json["min_unit"].(string)
  6661. advice.DrugSpecUnit = drugSpecUnit
  6662. }
  6663. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6664. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6665. advice.SingleDose = singleDose
  6666. }
  6667. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6668. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6669. advice.SingleDoseUnit = singleDoseUnit
  6670. }
  6671. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6672. deliveryWay, _ := json["delivery_way"].(string)
  6673. advice.DeliveryWay = deliveryWay
  6674. }
  6675. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6676. executionFrequency, _ := json["execution_frequency"].(string)
  6677. advice.ExecutionFrequency = executionFrequency
  6678. }
  6679. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6680. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6681. advice.Price = price
  6682. }
  6683. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6684. med_list_codg, _ := json["medical_insurance_number"].(string)
  6685. advice.MedListCodg = med_list_codg
  6686. }
  6687. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6688. day := int64(json["day"].(float64))
  6689. advice.Day = day
  6690. }
  6691. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6692. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6693. advice.PrescribingNumberUnit = prescribingNumberUnit
  6694. }
  6695. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6696. advice_id := int64(json["advice_id"].(float64))
  6697. advice.ID = advice_id
  6698. if advice.ID > 0 {
  6699. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6700. if err == nil {
  6701. if hisAdvice.ID > 0 {
  6702. advice.ExecutionTime = hisAdvice.ExecutionTime
  6703. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6704. advice.ExecutionState = hisAdvice.ExecutionState
  6705. advice.CheckTime = hisAdvice.CheckTime
  6706. advice.Checker = hisAdvice.Checker
  6707. advice.CheckState = hisAdvice.CheckState
  6708. advice.StartTime = hisAdvice.StartTime
  6709. advice.HospApprFlag = hisAdvice.HospApprFlag
  6710. advice.IsMedicine = hisAdvice.IsMedicine
  6711. if hisAdvice.UserOrgId == 10028 {
  6712. 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 {
  6713. advice.ExecutionTime = 0
  6714. advice.ExecutionStaff = 0
  6715. advice.ExecutionState = 2
  6716. advice.CheckTime = 0
  6717. advice.Checker = 0
  6718. advice.CheckState = 2
  6719. }
  6720. } else {
  6721. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
  6722. advice.ExecutionTime = 0
  6723. advice.ExecutionStaff = 0
  6724. advice.ExecutionState = 2
  6725. advice.CheckTime = 0
  6726. advice.Checker = 0
  6727. advice.CheckState = 2
  6728. //advice.UpdatedTime = time.Now().Unix()
  6729. advice.CreatedTime = hisAdvice.CreatedTime
  6730. advice.UpdatedTime = time.Now().Unix()
  6731. } else {
  6732. advice.CreatedTime = hisAdvice.CreatedTime
  6733. advice.UpdatedTime = hisAdvice.UpdatedTime
  6734. }
  6735. }
  6736. //advice.Groupno = hisAdvice.Groupno
  6737. } else {
  6738. ctime := time.Now().Unix()
  6739. advice.CreatedTime = ctime
  6740. advice.UpdatedTime = ctime
  6741. }
  6742. }
  6743. } else {
  6744. ctime := time.Now().Unix()
  6745. advice.CreatedTime = ctime
  6746. advice.UpdatedTime = ctime
  6747. }
  6748. }
  6749. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6750. //
  6751. //if drugStockConfig.IsOpen == 1 {
  6752. //
  6753. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6754. // if advice.ID == 0 { //医嘱不存在
  6755. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6756. // drug.Total = drug.Total - advice.PrescribingNumber
  6757. // service.UpdateBaseDrugLib(&drug)
  6758. //
  6759. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6760. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6761. // drug.Total = drug.Total - num
  6762. // service.UpdateBaseDrugLib(&drug)
  6763. // }
  6764. //
  6765. // } else if advice.ID > 0 { //医嘱存在
  6766. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6767. // var num float64
  6768. //
  6769. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6770. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6771. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6772. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6773. // drug.Total = drug.Total + num
  6774. // service.UpdateBaseDrugLib(&drug)
  6775. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6776. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6777. // drug.Total = drug.Total - num
  6778. // service.UpdateBaseDrugLib(&drug)
  6779. // }
  6780. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6781. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6782. // if num2 > advice.PrescribingNumber {
  6783. // num = num2 - advice.PrescribingNumber
  6784. // drug.Total = drug.Total + num
  6785. // service.UpdateBaseDrugLib(&drug)
  6786. // } else if num2 < advice.PrescribingNumber {
  6787. // num = advice.PrescribingNumber - num2
  6788. // drug.Total = drug.Total - num
  6789. // service.UpdateBaseDrugLib(&drug)
  6790. // }
  6791. //
  6792. // }
  6793. //
  6794. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6795. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6796. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6797. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6798. // if num1 > num2 {
  6799. // num = num1 - num2
  6800. // drug.Total = drug.Total + num
  6801. // service.UpdateBaseDrugLib(&drug)
  6802. // } else if num1 < num2 {
  6803. // num = num2 - num1
  6804. // drug.Total = drug.Total - num
  6805. // service.UpdateBaseDrugLib(&drug)
  6806. // }
  6807. //
  6808. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6809. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6810. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6811. // if hisAdvice.PrescribingNumber > num2 {
  6812. // num = hisAdvice.PrescribingNumber - num2
  6813. // drug.Total = drug.Total + num
  6814. // service.UpdateBaseDrugLib(&drug)
  6815. // } else if num2 < advice.PrescribingNumber {
  6816. // num = num2 - hisAdvice.PrescribingNumber
  6817. // drug.Total = drug.Total - num
  6818. // service.UpdateBaseDrugLib(&drug)
  6819. // }
  6820. //
  6821. // }
  6822. // }
  6823. // }
  6824. //}
  6825. //
  6826. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6827. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6828. // advice.ExecutionTime = execution_time
  6829. //}
  6830. //
  6831. //
  6832. //
  6833. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6834. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6835. // advice.ExecutionStaff = execution_staff
  6836. //}
  6837. //
  6838. //
  6839. //
  6840. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6841. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6842. // advice.ExecutionState = execution_state
  6843. //}
  6844. //
  6845. //
  6846. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6847. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6848. // advice.CheckTime = check_time
  6849. //}
  6850. //
  6851. //
  6852. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6853. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6854. // advice.CheckState = check_state
  6855. //}
  6856. //
  6857. //
  6858. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6859. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6860. // advice.Checker = checker
  6861. //}
  6862. //
  6863. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6864. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6865. // advice.StartTime = start_time
  6866. //}
  6867. return 0
  6868. }
  6869. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6870. project.ExecutionStaff = 0
  6871. project.ExecutionState = 2
  6872. project.ExecutionTime = 0
  6873. project.Checker = 0
  6874. project.CheckState = 2
  6875. project.CheckTime = 0
  6876. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6877. id := int64(json["id"].(float64))
  6878. project.ID = id
  6879. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6880. project.ExecutionStaff = temp_project.ExecutionStaff
  6881. project.ExecutionState = temp_project.ExecutionState
  6882. project.ExecutionTime = temp_project.ExecutionTime
  6883. project.Checker = temp_project.Checker
  6884. project.CheckState = temp_project.CheckState
  6885. project.CheckTime = temp_project.CheckTime
  6886. project.TeamId = temp_project.TeamId
  6887. }
  6888. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6889. types := int64(json["type"].(float64))
  6890. project.Type = types
  6891. }
  6892. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6893. project_id := int64(json["project_id"].(float64))
  6894. project.ProjectId = project_id
  6895. }
  6896. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6897. team_id := int64(json["team_id"].(float64))
  6898. project.TeamId = team_id
  6899. }
  6900. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6901. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6902. project.Price = price
  6903. }
  6904. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6905. total, _ := json["total"].(string)
  6906. //totals, _ := strconv.ParseInt(total, 10, 64)
  6907. project.Count = total
  6908. }
  6909. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6910. medical_code, _ := json["medical_code"].(string)
  6911. project.MedListCodg = medical_code
  6912. }
  6913. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6914. single_dose, _ := json["single_dose"].(string)
  6915. project.SingleDose = single_dose
  6916. }
  6917. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6918. delivery_way, _ := json["delivery_way"].(string)
  6919. project.DeliveryWay = delivery_way
  6920. }
  6921. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6922. execution_frequency, _ := json["execution_frequency"].(string)
  6923. project.ExecutionFrequency = execution_frequency
  6924. }
  6925. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6926. remark, _ := json["remark"].(string)
  6927. project.Remark = remark
  6928. }
  6929. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6930. day, _ := json["number_days"].(string)
  6931. project.Day = day
  6932. }
  6933. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6934. unit, _ := json["unit"].(string)
  6935. project.Unit = unit
  6936. }
  6937. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6938. // frequency_type := int64(json["frequency_type"].(float64))
  6939. // project.FrequencyType = frequency_type
  6940. //}
  6941. //
  6942. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6943. // day_count := int64(json["day_count"].(float64))
  6944. // project.DayCount = day_count
  6945. //}
  6946. //
  6947. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6948. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6949. // week_day, _ := json["week_day"].(string)
  6950. // project.WeekDay = week_day
  6951. //}
  6952. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6953. //
  6954. //if project.ID == 0 {
  6955. // if stockConfig.IsOpen == 1 {
  6956. // if project.Type == 3 {
  6957. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6958. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6959. // good.Total = good.Total - f_count
  6960. // service.UpdateGoodInfo(&good)
  6961. // }
  6962. // }
  6963. //
  6964. //} else {
  6965. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6966. //
  6967. // if stockConfig.IsOpen == 1 {
  6968. // if project.Type == 3 {
  6969. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6970. // if project.Count < temp_project.Count {
  6971. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6972. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6973. //
  6974. // other_count := f_count_two - f_count_one
  6975. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6976. // good.Total = good.Total + other_count_two
  6977. // service.UpdateGoodInfo(&good)
  6978. // } else if project.Count > temp_project.Count {
  6979. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6980. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6981. //
  6982. // other_count := f_count_one - f_count_two
  6983. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6984. // good.Total = good.Total - other_count_two
  6985. // service.UpdateGoodInfo(&good)
  6986. // }
  6987. //
  6988. // }
  6989. // }
  6990. //
  6991. //}
  6992. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6993. id := int64(json["id"].(float64))
  6994. if id > 0 {
  6995. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6996. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  6997. fmt.Println("666666")
  6998. project.Mtime = time.Now().Unix()
  6999. project.Ctime = temp_project.Ctime
  7000. } else {
  7001. project.Mtime = temp_project.Mtime
  7002. project.Ctime = temp_project.Ctime
  7003. }
  7004. } else {
  7005. ctime := time.Now().Unix()
  7006. project.Mtime = ctime
  7007. project.Ctime = ctime
  7008. }
  7009. }
  7010. return 0
  7011. }
  7012. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7013. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7014. id := int64(json["id"].(float64))
  7015. additionalCharge.ID = id
  7016. }
  7017. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7018. item_id := int64(json["item_id"].(float64))
  7019. additionalCharge.ItemId = item_id
  7020. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7021. if config.ID > 0 {
  7022. if len(config.Code) > 0 {
  7023. additionalCharge.MedListCodg = config.Code
  7024. }
  7025. }
  7026. }
  7027. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7028. // price := int64(json["price"].(float64))
  7029. // formatInt_price := strconv.FormatInt(price, 10)
  7030. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7031. // additionalCharge.Price = float_price
  7032. // }
  7033. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7034. // price := int64(json["price"].(float64))
  7035. // formatInt_price := strconv.FormatInt(price, 10)
  7036. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7037. // additionalCharge.Price = float_price
  7038. //}
  7039. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7040. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7041. additionalCharge.Price = price
  7042. }
  7043. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7044. count, _ := json["count"].(string)
  7045. counts, _ := strconv.ParseInt(count, 10, 64)
  7046. additionalCharge.Count = counts
  7047. }
  7048. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7049. item_name, _ := json["item_name"].(string)
  7050. additionalCharge.ItemName = item_name
  7051. }
  7052. return 0
  7053. }
  7054. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7055. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7056. utils.ErrorLog("drug_name")
  7057. return enums.ErrorCodeParamWrong
  7058. }
  7059. adviceName, _ := json["drug_name"].(string)
  7060. if len(adviceName) == 0 {
  7061. utils.ErrorLog("len(advice_name) == 0")
  7062. return enums.ErrorCodeParamWrong
  7063. }
  7064. advice.AdviceName = adviceName
  7065. adviceDesc, _ := json["advice_desc"].(string)
  7066. advice.AdviceDesc = adviceDesc
  7067. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7068. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7069. advice.DrugSpec = drugSpec
  7070. }
  7071. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7072. remark, _ := json["remark"].(string)
  7073. advice.Remark = remark
  7074. }
  7075. if json["id"] == nil {
  7076. advice.DrugId = 0
  7077. } else {
  7078. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7079. drug_id := int64(json["id"].(float64))
  7080. advice.DrugId = drug_id
  7081. }
  7082. }
  7083. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7084. groupno := int64(json["groupno"].(float64))
  7085. advice.Groupno = groupno
  7086. }
  7087. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7088. drugSpecUnit, _ := json["min_unit"].(string)
  7089. advice.DrugSpecUnit = drugSpecUnit
  7090. }
  7091. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7092. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7093. advice.SingleDose = singleDose
  7094. }
  7095. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7096. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7097. advice.SingleDoseUnit = singleDoseUnit
  7098. }
  7099. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7100. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7101. advice.PrescribingNumber = prescribingNumber
  7102. }
  7103. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7104. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7105. advice.PrescribingNumberUnit = prescribingNumberUnit
  7106. }
  7107. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7108. deliveryWay, _ := json["delivery_way"].(string)
  7109. advice.DeliveryWay = deliveryWay
  7110. }
  7111. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7112. executionFrequency, _ := json["execution_frequency"].(string)
  7113. advice.ExecutionFrequency = executionFrequency
  7114. }
  7115. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7116. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7117. advice.Price = price
  7118. }
  7119. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7120. med_list_codg, _ := json["medical_insurance_number"].(string)
  7121. advice.MedListCodg = med_list_codg
  7122. }
  7123. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7124. day := int64(json["day"].(float64))
  7125. advice.Day = day
  7126. }
  7127. advice.FrequencyType = 1
  7128. return 0
  7129. }
  7130. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7131. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7132. types := int64(json["type"].(float64))
  7133. project.Type = types
  7134. }
  7135. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7136. project_id := int64(json["project_id"].(float64))
  7137. project.ProjectId = project_id
  7138. }
  7139. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7140. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7141. project.Price = price
  7142. }
  7143. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7144. total, _ := json["total"].(string)
  7145. //totals, _ := strconv.ParseInt(total, 10, 64)
  7146. project.Count = total
  7147. }
  7148. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7149. medical_code, _ := json["medical_code"].(string)
  7150. project.MedListCodg = medical_code
  7151. }
  7152. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7153. single_dose, _ := json["single_dose"].(string)
  7154. project.SingleDose = single_dose
  7155. }
  7156. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7157. delivery_way, _ := json["delivery_way"].(string)
  7158. project.DeliveryWay = delivery_way
  7159. }
  7160. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7161. execution_frequency, _ := json["execution_frequency"].(string)
  7162. project.ExecutionFrequency = execution_frequency
  7163. }
  7164. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7165. remark, _ := json["remark"].(string)
  7166. project.Remark = remark
  7167. }
  7168. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7169. day, _ := json["number_days"].(string)
  7170. project.Day = day
  7171. }
  7172. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7173. unit, _ := json["unit"].(string)
  7174. project.Unit = unit
  7175. }
  7176. project.FrequencyType = 1
  7177. return 0
  7178. }
  7179. func (c *HisApiController) GetHisOrderListTwo() {
  7180. start_time := c.GetString("start_time")
  7181. end_time := c.GetString("end_time")
  7182. timeLayout := "2006-01-02"
  7183. loc, _ := time.LoadLocation("Local")
  7184. var startTime int64
  7185. if len(start_time) > 0 {
  7186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7187. if err != nil {
  7188. //fmt.Println(err)
  7189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7190. return
  7191. }
  7192. startTime = theTime.Unix()
  7193. }
  7194. var endTime int64
  7195. if len(end_time) > 0 {
  7196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7197. if err != nil {
  7198. utils.ErrorLog(err.Error())
  7199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7200. return
  7201. }
  7202. endTime = theTime.Unix()
  7203. }
  7204. adminUser := c.GetAdminUserInfo()
  7205. org_id := adminUser.CurrentOrgId
  7206. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7207. if err == nil {
  7208. c.ServeSuccessJSON(map[string]interface{}{
  7209. "order2": order,
  7210. })
  7211. } else {
  7212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7213. return
  7214. }
  7215. }
  7216. func (c *HisApiController) GetHisOrderList() {
  7217. page, _ := c.GetInt64("page", -1)
  7218. limit, _ := c.GetInt64("limit", -1)
  7219. start_time := c.GetString("start_time")
  7220. end_time := c.GetString("end_time")
  7221. types, _ := c.GetInt64("type", 0)
  7222. keywords := c.GetString("keywords")
  7223. p_type, _ := c.GetInt64("p_type", 0)
  7224. sort_type, _ := c.GetInt64("sort_type", 0)
  7225. charge_type, _ := c.GetInt64("charge_type", 0)
  7226. sch_type, _ := c.GetInt64("sch_type", 0)
  7227. zone_type, _ := c.GetInt64("zone_type", 0)
  7228. med_type, _ := c.GetInt64("med_type", 0)
  7229. timeLayout := "2006-01-02"
  7230. loc, _ := time.LoadLocation("Local")
  7231. var startTime int64
  7232. if len(start_time) > 0 {
  7233. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7234. if err != nil {
  7235. //fmt.Println(err)
  7236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7237. return
  7238. }
  7239. startTime = theTime.Unix()
  7240. }
  7241. var endTime int64
  7242. if len(end_time) > 0 {
  7243. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7244. if err != nil {
  7245. utils.ErrorLog(err.Error())
  7246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7247. return
  7248. }
  7249. endTime = theTime.Unix()
  7250. }
  7251. adminUser := c.GetAdminUserInfo()
  7252. org_id := adminUser.CurrentOrgId
  7253. 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)
  7254. for _, item := range order {
  7255. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7256. item.DoctorName = info.Doctor
  7257. item.DepartmentName = info.XtHisDepartment.Name
  7258. }
  7259. if err == nil {
  7260. c.ServeSuccessJSON(map[string]interface{}{
  7261. "order": order,
  7262. "total": total,
  7263. })
  7264. } else {
  7265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7266. return
  7267. }
  7268. }
  7269. func (c *HisApiController) GetHisOrder() {
  7270. patient_id, _ := c.GetInt64("patient_id", 0)
  7271. number := c.GetString("number")
  7272. adminInfo := c.GetAdminUserInfo()
  7273. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7274. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7275. if err == nil {
  7276. c.ServeSuccessJSON(map[string]interface{}{
  7277. "order": order,
  7278. "prescription": prescriptions,
  7279. })
  7280. } else {
  7281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7282. return
  7283. }
  7284. }
  7285. func (c *HisApiController) GetHisPrescriptionList() {
  7286. record_date := c.GetString("record_date")
  7287. keywords := c.GetString("keywords")
  7288. page, _ := c.GetInt64("page")
  7289. limit, _ := c.GetInt64("limit")
  7290. sch_type, _ := c.GetInt64("sch_type")
  7291. timeLayout := "2006-01-02"
  7292. loc, _ := time.LoadLocation("Local")
  7293. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7294. if err != nil {
  7295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7296. return
  7297. }
  7298. recordDateTime := theTime.Unix()
  7299. adminInfo := c.GetAdminUserInfo()
  7300. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7301. //adminInfo := c.GetAdminUserInfo()
  7302. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7303. //fmt.Println(prescriptionOrder)
  7304. if err == nil {
  7305. c.ServeSuccessJSON(map[string]interface{}{
  7306. "order": prescriptionOrder,
  7307. "total": total,
  7308. })
  7309. } else {
  7310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7311. return
  7312. }
  7313. }
  7314. func (c *HisApiController) GetHisPrescriptionInfo() {
  7315. id, _ := c.GetInt64("id")
  7316. adminInfo := c.GetAdminUserInfo()
  7317. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7318. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7319. if err == nil {
  7320. c.ServeSuccessJSON(map[string]interface{}{
  7321. "order": prescriptionOrder,
  7322. "prescription": prescription,
  7323. })
  7324. } else {
  7325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7326. return
  7327. }
  7328. }
  7329. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7330. adminUser := c.GetAdminUserInfo()
  7331. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7332. c.ServeSuccessJSON(map[string]interface{}{
  7333. "config": config,
  7334. })
  7335. }
  7336. type ResultTwo struct {
  7337. ErrMsg interface{} `json:"err_msg"`
  7338. InfRefmsgid string `json:"inf_refmsgid"`
  7339. Infcode int64 `json:"infcode"`
  7340. Output struct {
  7341. Baseinfo struct {
  7342. Age float64 `json:"age"`
  7343. Brdy string `json:"brdy"`
  7344. Certno string `json:"certno"`
  7345. Gend string `json:"gend"`
  7346. Naty string `json:"naty"`
  7347. PsnCertType string `json:"psn_cert_type"`
  7348. PsnName string `json:"psn_name"`
  7349. PsnNo string `json:"psn_no"`
  7350. } `json:"baseinfo"`
  7351. Idetinfo []interface{} `json:"idetinfo"`
  7352. Iinfo []struct {
  7353. Balc float64 `json:"balc"`
  7354. CvlservFlag string `json:"cvlserv_flag"`
  7355. EmpName string `json:"emp_name"`
  7356. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7357. Insutype string `json:"insutype"`
  7358. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7359. PausInsuDate interface{} `json:"paus_insu_date"`
  7360. PsnInsuDate string `json:"psn_insu_date"`
  7361. PsnInsuStas string `json:"psn_insu_stas"`
  7362. PsnType string `json:"psn_type"`
  7363. } `json:"insuinfo"`
  7364. } `json:"output"`
  7365. RefmsgTime string `json:"refmsg_time"`
  7366. RespondTime string `json:"respond_time"`
  7367. Signtype interface{} `json:"signtype"`
  7368. WarnInfo interface{} `json:"warn_info"`
  7369. }
  7370. type ResultThree struct {
  7371. Cainfo interface{} `json:"cainfo"`
  7372. ErrMsg interface{} `json:"err_msg"`
  7373. InfRefmsgid string `json:"inf_refmsgid"`
  7374. Infcode int64 `json:"infcode"`
  7375. Output struct {
  7376. Data struct {
  7377. IptOtpNo string `json:"ipt_otp_no"`
  7378. MdtrtID string `json:"mdtrt_id"`
  7379. PsnNo string `json:"psn_no"`
  7380. } `json:"data"`
  7381. } `json:"output"`
  7382. RefmsgTime string `json:"refmsg_time"`
  7383. RespondTime string `json:"respond_time"`
  7384. Signtype interface{} `json:"signtype"`
  7385. WarnMsg interface{} `json:"warn_msg"`
  7386. }
  7387. type ResultFour struct {
  7388. Cainfo string `json:"cainfo"`
  7389. ErrMsg string `json:"err_msg"`
  7390. InfRefmsgid string `json:"inf_refmsgid"`
  7391. Infcode int64 `json:"infcode"`
  7392. Output struct {
  7393. Result []struct {
  7394. BasMednFlag string `json:"bas_medn_flag"`
  7395. ChldMedcFlag string `json:"chld_medc_flag"`
  7396. ChrgitmLv string `json:"chrgitm_lv"`
  7397. Cnt float64 `json:"cnt"`
  7398. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7399. DrtReimFlag string `json:"drt_reim_flag"`
  7400. FeedetlSn string `json:"feedetl_sn"`
  7401. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7402. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7403. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7404. ListSpItemFlag string `json:"list_sp_item_flag"`
  7405. LmtUsedFlag string `json:"lmt_used_flag"`
  7406. MedChrgitmType string `json:"med_chrgitm_type"`
  7407. Memo string `json:"memo"`
  7408. OverlmtAmt float64 `json:"overlmt_amt"`
  7409. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7410. Pric float64 `json:"pric"`
  7411. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7412. SelfpayProp float64 `json:"selfpay_prop"`
  7413. } `json:"result"`
  7414. } `json:"output"`
  7415. RefmsgTime string `json:"refmsg_time"`
  7416. RespondTime string `json:"respond_time"`
  7417. Signtype string `json:"signtype"`
  7418. WarnMsg string `json:"warn_msg"`
  7419. }
  7420. type ResultFive struct {
  7421. Insutype string `json:"insutype"`
  7422. }
  7423. type ResultSix struct {
  7424. Cainfo interface{} `json:"cainfo"`
  7425. ErrMsg interface{} `json:"err_msg"`
  7426. InfRefmsgid string `json:"inf_refmsgid"`
  7427. Infcode int64 `json:"infcode"`
  7428. Output struct {
  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 ResultSeven 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. Setldetail []interface{} `json:"setldetail"`
  7442. Setlinfo struct {
  7443. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7444. AcctPay float64 `json:"acct_pay"`
  7445. ActPayDedc float64 `json:"act_pay_dedc"`
  7446. Age float64 `json:"age"`
  7447. Balc float64 `json:"balc"`
  7448. Brdy string `json:"brdy"`
  7449. Certno string `json:"certno"`
  7450. ClrOptins string `json:"clr_optins"`
  7451. ClrType string `json:"clr_type"`
  7452. ClrWay string `json:"clr_way"`
  7453. CvlservFlag string `json:"cvlserv_flag"`
  7454. CvlservPay float64 `json:"cvlserv_pay"`
  7455. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7456. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7457. Gend string `json:"gend"`
  7458. HifesPay float64 `json:"hifes_pay"`
  7459. HifmiPay float64 `json:"hifmi_pay"`
  7460. HifobPay float64 `json:"hifob_pay"`
  7461. HifpPay float64 `json:"hifp_pay"`
  7462. HospPartAmt float64 `json:"hosp_part_amt"`
  7463. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7464. Insutype string `json:"insutype"`
  7465. MafPay float64 `json:"maf_pay"`
  7466. MdtrtCertType string `json:"mdtrt_cert_type"`
  7467. MdtrtID string `json:"mdtrt_id"`
  7468. MedType string `json:"med_type"`
  7469. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7470. MedinsSetlID string `json:"medins_setl_id"`
  7471. Naty string `json:"naty"`
  7472. OthPay float64 `json:"oth_pay"`
  7473. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7474. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7475. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7476. PsnCashPay float64 `json:"psn_cash_pay"`
  7477. PsnCertType string `json:"psn_cert_type"`
  7478. PsnName string `json:"psn_name"`
  7479. PsnNo string `json:"psn_no"`
  7480. PsnPartAmt float64 `json:"psn_part_amt"`
  7481. PsnType string `json:"psn_type"`
  7482. SetlID string `json:"setl_id"`
  7483. SetlTime string `json:"setl_time"`
  7484. } `json:"setlinfo"`
  7485. } `json:"output"`
  7486. RefmsgTime string `json:"refmsg_time"`
  7487. RespondTime string `json:"respond_time"`
  7488. Signtype interface{} `json:"signtype"`
  7489. WarnMsg interface{} `json:"warn_msg"`
  7490. }
  7491. type ResultEight struct {
  7492. Cainfo string `json:"cainfo"`
  7493. ErrMsg string `json:"err_msg"`
  7494. InfRefmsgid string `json:"inf_refmsgid"`
  7495. Infcode int64 `json:"infcode"`
  7496. Output struct {
  7497. Stmtinfo struct {
  7498. SetlOptins string `json:"setl_optins"`
  7499. StmtRslt string `json:"stmt_rslt"`
  7500. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7501. } `json:"stmtinfo"`
  7502. } `json:"output"`
  7503. RefmsgTime string `json:"refmsg_time"`
  7504. RespondTime string `json:"respond_time"`
  7505. Signtype interface{} `json:"signtype"`
  7506. WarnMsg interface{} `json:"warn_msg"`
  7507. }
  7508. type ResultNine struct {
  7509. Cainfo string `json:"cainfo"`
  7510. ErrMsg string `json:"err_msg"`
  7511. InfRefmsgid string `json:"inf_refmsgid"`
  7512. Infcode int64 `json:"infcode"`
  7513. Output struct {
  7514. FileQuryNo string `json:"file_qury_no"`
  7515. } `json:"output"`
  7516. RefmsgTime string `json:"refmsg_time"`
  7517. RespondTime string `json:"respond_time"`
  7518. Signtype interface{} `json:"signtype"`
  7519. WarnMsg interface{} `json:"warn_msg"`
  7520. }
  7521. type ResultTen struct {
  7522. Cainfo string `json:"cainfo"`
  7523. ErrMsg string `json:"err_msg"`
  7524. InfRefmsgid string `json:"inf_refmsgid"`
  7525. Infcode int64 `json:"infcode"`
  7526. Output struct {
  7527. DldEndtime string `json:"dld_endtime"`
  7528. FileQuryNo string `json:"file_qury_no"`
  7529. Filename string `json:"filename"`
  7530. } `json:"output"`
  7531. RefmsgTime string `json:"refmsg_time"`
  7532. RespondTime string `json:"respond_time"`
  7533. Signtype interface{} `json:"signtype"`
  7534. WarnMsg interface{} `json:"warn_msg"`
  7535. }
  7536. type ResultEleven struct {
  7537. Cainfo string `json:"cainfo"`
  7538. ErrMsg string `json:"err_msg"`
  7539. InfRefmsgid string `json:"inf_refmsgid"`
  7540. Infcode int64 `json:"infcode"`
  7541. Output struct {
  7542. Setlinfo struct {
  7543. FixmedinsName string `json:"fixmedins_name"`
  7544. FixmedinsCode string `json:"fixmedins_code"`
  7545. PsnNo string `json:"psn_no"`
  7546. PsnName string `json:"psn_name"`
  7547. HifobPay float64 `json:"hifob_pay"`
  7548. Gend string `json:"gend"`
  7549. Brdy string `json:"brdy"`
  7550. PsnCertType string `json:"psn_cert_type"`
  7551. PsnType string `json:"psn_type"`
  7552. EmpName string `json:"emp_name"`
  7553. Certno string `json:"certno"`
  7554. Insutype string `json:"insutype"`
  7555. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7556. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7557. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7558. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7559. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7560. ActPayDedc float64 `json:"act_pay_dedc"`
  7561. HifpPay float64 `json:"hifp_pay"`
  7562. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7563. CvlservPay float64 `json:"cvlserv_pay"`
  7564. HifesPay float64 `json:"hifes_pay"`
  7565. HifmiPay float64 `json:"hifmi_pay"`
  7566. MafPay float64 `json:"maf_pay"`
  7567. OthPay float64 `json:"oth_pay"`
  7568. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7569. PsnPay float64 `json:"psn_pay"`
  7570. AcctPay float64 `json:"acct_pay"`
  7571. CashPayamt float64 `json:"cash_payamt"`
  7572. Balc float64 `json:"balc"`
  7573. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7574. MedinsSetlId string `json:"medins_setl_id"`
  7575. RefdSetlFlag string `json:"refd_setl_flag"`
  7576. SetlTime string `json:"setl_time"`
  7577. MedType string `json:"med_type"`
  7578. } `json:"setlinfo"`
  7579. } `json:"output"`
  7580. RefmsgTime string `json:"refmsg_time"`
  7581. RespondTime string `json:"respond_time"`
  7582. Signtype interface{} `json:"signtype"`
  7583. WarnMsg interface{} `json:"warn_msg"`
  7584. }
  7585. type Custom struct {
  7586. DetItemFeeSumamt string
  7587. Cut string
  7588. FeedetlSn string
  7589. Price string
  7590. MedListCodg string
  7591. Type int64
  7592. AdviceId int64
  7593. ProjectId int64
  7594. ItemId int64
  7595. }
  7596. // 获取个人信息----挂号-----上传就诊信息
  7597. func (c *HisApiController) GetRegisterInfo() {
  7598. id, _ := c.GetInt64("id")
  7599. record_time := c.GetString("record_time")
  7600. settlementValue, _ := c.GetInt64("settlement_value")
  7601. medical_insurance_card := c.GetString("medical_insurance_card")
  7602. name := c.GetString("name")
  7603. id_card_type, _ := c.GetInt64("id_card_type")
  7604. certificates, _ := c.GetInt64("certificates")
  7605. medical_care, _ := c.GetInt64("medical_care")
  7606. birthday := c.GetString("birthday")
  7607. age, _ := c.GetInt64("age")
  7608. id_card := c.GetString("id_card")
  7609. register_type, _ := c.GetInt64("register")
  7610. doctor, _ := c.GetInt64("doctor")
  7611. department, _ := c.GetInt64("department")
  7612. gender, _ := c.GetInt64("sex")
  7613. phone := c.GetString("phone")
  7614. registration_fee, _ := c.GetFloat("registration_fee")
  7615. medical_expenses, _ := c.GetFloat("medical_expenses")
  7616. social_type, _ := c.GetInt64("social_type")
  7617. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7618. diagnosis_ids := c.GetString("diagnosis")
  7619. sick_type, _ := c.GetInt64("sick_type")
  7620. reg_type := c.GetString("p_type")
  7621. timeLayout := "2006-01-02"
  7622. loc, _ := time.LoadLocation("Local")
  7623. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7624. birthUnix := birthdays.Unix()
  7625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7626. if err != nil {
  7627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7628. return
  7629. }
  7630. recordDateTime := theTime.Unix()
  7631. adminInfo := c.GetAdminUserInfo()
  7632. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7633. if tempPatient.ID == 0 {
  7634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7635. return
  7636. }
  7637. var patient service.Patients
  7638. if id == 0 {
  7639. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7640. } else {
  7641. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7642. }
  7643. if patient.ID == 0 {
  7644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7645. return
  7646. }
  7647. if len(patient.IdCardNo) == 0 {
  7648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7649. return
  7650. }
  7651. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7652. if len(his) >= 1 {
  7653. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7654. if len(his) >= 1 && order.ID == 0 {
  7655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7656. return
  7657. }
  7658. }
  7659. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7660. fmt.Println(timeStr)
  7661. timeArr := strings.Split(timeStr, " ")
  7662. fmt.Println(timeArr)
  7663. timeArrTwo := strings.Split(timeArr[0], "-")
  7664. timeArrThree := strings.Split(timeArr[1], ":")
  7665. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7666. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7667. if len(lists) == 0 {
  7668. var hisPatient models.XtHisPatient
  7669. hisPatient = models.XtHisPatient{
  7670. Name: name,
  7671. Age: age,
  7672. Gender: gender,
  7673. Birthday: birthUnix,
  7674. Phone: phone,
  7675. MedicalTreatmentType: medical_care,
  7676. IdType: certificates,
  7677. IdCardNo: id_card,
  7678. BalanceAccountsType: settlementValue,
  7679. SocialType: social_type,
  7680. MedicalInsuranceNumber: medical_insurance_card,
  7681. RegisterType: register_type,
  7682. RegisterCost: registration_fee,
  7683. TreatmentCost: medical_expenses,
  7684. AdminUserId: adminInfo.AdminUser.Id,
  7685. UserOrgId: adminInfo.CurrentOrgId,
  7686. Status: 1,
  7687. RecordDate: recordDateTime,
  7688. IsReturn: 1,
  7689. PatientId: patient.ID,
  7690. Ctime: time.Now().Unix(),
  7691. Mtime: time.Now().Unix(),
  7692. Number: str,
  7693. IdCardType: id_card_type,
  7694. Departments: department,
  7695. Doctor: doctor,
  7696. PType: reg_type,
  7697. Diagnosis: diagnosis_ids,
  7698. SickType: sick_type,
  7699. }
  7700. service.CreateHisPatient(&hisPatient)
  7701. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7702. c.ServeSuccessJSON(map[string]interface{}{
  7703. "his_info": hisPatient,
  7704. })
  7705. } else {
  7706. //chrgBchno := rand.Intn(1000000) + 10000
  7707. var hisPatient models.XtHisPatient
  7708. hisPatient = models.XtHisPatient{
  7709. Name: name,
  7710. Age: age,
  7711. Gender: gender,
  7712. Birthday: birthUnix,
  7713. Phone: phone,
  7714. MedicalTreatmentType: medical_care,
  7715. IdType: certificates,
  7716. IdCardNo: id_card,
  7717. BalanceAccountsType: settlementValue,
  7718. SocialType: social_type,
  7719. MedicalInsuranceNumber: medical_insurance_card,
  7720. RegisterType: register_type,
  7721. RegisterCost: registration_fee,
  7722. TreatmentCost: medical_expenses,
  7723. AdminUserId: adminInfo.AdminUser.Id,
  7724. UserOrgId: adminInfo.CurrentOrgId,
  7725. Status: 1,
  7726. RecordDate: recordDateTime,
  7727. IsReturn: 1,
  7728. PatientId: patient.ID,
  7729. Ctime: time.Now().Unix(),
  7730. Mtime: time.Now().Unix(),
  7731. Number: str,
  7732. IdCardType: id_card_type,
  7733. Departments: department,
  7734. Doctor: doctor,
  7735. PType: reg_type,
  7736. Diagnosis: diagnosis_ids,
  7737. SickType: sick_type,
  7738. }
  7739. service.CreateHisPatient(&hisPatient)
  7740. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7741. c.ServeSuccessJSON(map[string]interface{}{
  7742. "his_info": hisPatient,
  7743. })
  7744. }
  7745. }
  7746. // 上传明细----结算
  7747. func (c *HisApiController) GetUploadInfo() {
  7748. id, _ := c.GetInt64("id")
  7749. record_time := c.GetString("record_time")
  7750. his_patient_id, _ := c.GetInt64("his_patient_id")
  7751. oth_desc := c.GetString("oth_desc")
  7752. pay_way, _ := c.GetInt64("pay_way")
  7753. pay_ways := c.GetString("pay_ways")
  7754. pay_price, _ := c.GetFloat("pay_price")
  7755. pay_card_no := c.GetString("pay_card_no")
  7756. discount_price, _ := c.GetFloat("discount_price")
  7757. preferential_price, _ := c.GetFloat("preferential_price")
  7758. reality_price, _ := c.GetFloat("reality_price")
  7759. found_price, _ := c.GetFloat("found_price")
  7760. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7761. private_price, _ := c.GetFloat("private_price")
  7762. timeLayout := "2006-01-02"
  7763. loc, _ := time.LoadLocation("Local")
  7764. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7765. fapiao_code := c.GetString("fapiao_code")
  7766. fapiao_number := c.GetString("fapiao_number")
  7767. diagnosis_id := c.GetString("diagnosis")
  7768. sick_type, _ := c.GetInt64("sick_type")
  7769. reg_type, _ := c.GetInt64("p_type")
  7770. order_id, _ := c.GetInt64("order_id")
  7771. cash_pay := c.GetString("cash_pay")
  7772. wechat_pay := c.GetString("wechat_pay")
  7773. ali_pay := c.GetString("ali_pay")
  7774. jifen_pay := c.GetString("jifen_pay")
  7775. band_card_pay := c.GetString("band_card_pay")
  7776. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7777. tmp_decimal := c.GetString("tmp_decimal")
  7778. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7779. var decimal float64 //本次使用的押金
  7780. var errmsg error
  7781. tx := service.XTWriteDB().Begin() //开了事务
  7782. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7783. defer func() {
  7784. if errmsg != nil {
  7785. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7786. tx.Rollback()
  7787. } else {
  7788. tx.Commit()
  7789. }
  7790. }()
  7791. fmt.Println("dec_way", dec_way)
  7792. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7793. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7794. return
  7795. }
  7796. if len(tmp_decimal) > 0 {
  7797. if tmp_decimal[0] == 45 {
  7798. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7799. return
  7800. }
  7801. }
  7802. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7803. fmt.Println(errs)
  7804. decimal = tt
  7805. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7806. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7807. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7808. if err != nil {
  7809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7810. return
  7811. }
  7812. recordDateTime := theTime.Unix()
  7813. adminUser := c.GetAdminUserInfo()
  7814. var prescriptions []*models.HisPrescription
  7815. var prescriptionsOne []*models.HisPrescription
  7816. var start_time int64
  7817. var end_time int64
  7818. ids_str := c.GetString("ids")
  7819. ids_arr := strings.Split(ids_str, ",")
  7820. if tempOrder.ID == 0 {
  7821. if settle_accounts_type == 1 { //日结
  7822. fmt.Println(reg_type)
  7823. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7824. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7825. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7826. } else {
  7827. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7828. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7829. }
  7830. } else { //月结
  7831. start_time_str := c.GetString("start_time")
  7832. end_time_str := c.GetString("end_time")
  7833. timeLayout := "2006-01-02"
  7834. loc, _ := time.LoadLocation("Local")
  7835. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7836. if err != nil {
  7837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7838. return
  7839. }
  7840. recordStartTime := theStartTime.Unix()
  7841. start_time = recordStartTime
  7842. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7843. if err != nil {
  7844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7845. return
  7846. }
  7847. recordEndTime := theEndTime.Unix()
  7848. end_time = recordEndTime
  7849. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7850. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7851. }
  7852. var goods []*models.DialysisBeforePrepareGoods
  7853. var newGoods []*models.NewDialysisBeforePrepareGoods
  7854. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7855. var infos []*models.HisDoctorAdviceInfo
  7856. var infoList []*models.HisDoctorAdviceInfo
  7857. var hisAdvice []*models.HisDoctorAdviceInfo
  7858. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7859. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7860. //判断库存不足
  7861. //结算出库开关
  7862. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7863. if settConfig.IsOpen == 1 {
  7864. //判断库存的地方
  7865. for _, info := range prescriptions {
  7866. if info.Type == 1 {
  7867. infos = append(infos, info.HisDoctorAdviceInfo...)
  7868. }
  7869. if info.Type == 2 {
  7870. for _, sumItem := range info.HisPrescriptionProject {
  7871. if sumItem.Type == 3 {
  7872. var good models.DialysisBeforePrepareGoods
  7873. var newGood models.NewDialysisBeforePrepareGoods
  7874. good.GoodId = sumItem.GoodInfo.ID
  7875. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7876. count, _ := strconv.Atoi(sumItem.Count)
  7877. good.Count = int64(count)
  7878. good.StorehouseId = houseConfig.StorehouseOutInfo
  7879. good.ProjectId = sumItem.ID
  7880. goods = append(goods, &good)
  7881. newGood.GoodId = sumItem.GoodInfo.ID
  7882. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7883. count2, _ := strconv.Atoi(sumItem.Count)
  7884. newGood.Count = int64(count2)
  7885. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7886. newGood.ProjectId = sumItem.ID
  7887. newGoods = append(newGoods, &newGood)
  7888. }
  7889. }
  7890. }
  7891. }
  7892. for _, info := range prescriptionsOne {
  7893. if info.Type == 1 {
  7894. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7895. }
  7896. if info.Type == 2 {
  7897. for _, sumItem := range info.HisPrescriptionProject {
  7898. if sumItem.Type == 3 {
  7899. var newGood models.NewDialysisBeforePrepareGoods
  7900. newGood.GoodId = sumItem.GoodInfo.ID
  7901. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7902. count2, _ := strconv.Atoi(sumItem.Count)
  7903. newGood.Count = int64(count2)
  7904. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7905. newGood.ProjectId = sumItem.ID
  7906. newGoodOne = append(newGoodOne, &newGood)
  7907. }
  7908. }
  7909. }
  7910. }
  7911. //判断
  7912. for _, itemOne := range infos {
  7913. for _, itemTwo := range hisAdvice {
  7914. if itemOne.DrugId == itemTwo.DrugId {
  7915. itemTwo.Child = append(itemTwo.Child, itemOne)
  7916. }
  7917. }
  7918. }
  7919. for _, itemTwo := range hisAdvice {
  7920. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7921. var sum_out_count int64
  7922. for _, itemThree := range itemTwo.Child {
  7923. var prescribing_number int64
  7924. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7925. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7926. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7927. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7928. }
  7929. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7930. prescribing_number = parseIntPrescribingNumber
  7931. }
  7932. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7933. prescribing_number = parseIntPrescribingNumber
  7934. }
  7935. sum_out_count += prescribing_number
  7936. }
  7937. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7938. if sum_out_count > drugStockOut.FlushCount {
  7939. c.ServeSuccessJSON(map[string]interface{}{
  7940. "msg": "2",
  7941. "drug": medical,
  7942. })
  7943. return
  7944. }
  7945. }
  7946. for _, itemOne := range newGoods {
  7947. for _, item := range newGoodOne {
  7948. if itemOne.GoodId == item.GoodId {
  7949. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7950. }
  7951. }
  7952. }
  7953. for _, item := range newGoodOne {
  7954. var sum_out_count_one int64
  7955. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7956. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7957. sum_out_count_one += itemOne.Count
  7958. }
  7959. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7960. fmt.Println("sum_out_count_one", sum_out_count_one)
  7961. fmt.Println("list.FlushCount", list.FlushCount)
  7962. if sum_out_count_one > list.FlushCount {
  7963. c.ServeSuccessJSON(map[string]interface{}{
  7964. "msg": "3",
  7965. "good": good,
  7966. })
  7967. return
  7968. }
  7969. }
  7970. }
  7971. timestamp := time.Now().Unix()
  7972. tempTime := time.Unix(timestamp, 0)
  7973. timeFormat := tempTime.Format("20060102150405")
  7974. chrgBchno := rand.Intn(100000) + 10000
  7975. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7976. strconv.FormatInt(his.PatientId, 10)
  7977. var ids []int64
  7978. for _, item := range prescriptions {
  7979. ids = append(ids, item.ID)
  7980. }
  7981. var total float64
  7982. for _, item := range prescriptions {
  7983. fmt.Println(item)
  7984. if item.Type == 1 { //药品
  7985. for _, subItem := range item.HisDoctorAdviceInfo {
  7986. total = total + (subItem.Price * subItem.PrescribingNumber)
  7987. }
  7988. }
  7989. if item.Type == 2 { //项目
  7990. for _, subItem := range item.HisPrescriptionProject {
  7991. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7992. total = total + (subItem.Price * cnt)
  7993. }
  7994. }
  7995. for _, subItem := range item.HisAdditionalCharge {
  7996. total = total + (subItem.Price * float64(subItem.Count))
  7997. }
  7998. }
  7999. if reg_type == 1111 || reg_type == 1112 {
  8000. reg_type = 11
  8001. }
  8002. tm := time.Unix(time.Now().Unix(), 0)
  8003. allTotal := fmt.Sprintf("%.4f", total)
  8004. totals, _ := strconv.ParseFloat(allTotal, 64)
  8005. order := &models.HisOrder{
  8006. UserOrgId: adminUser.CurrentOrgId,
  8007. HisPatientId: his.ID,
  8008. PatientId: id,
  8009. SettleAccountsDate: recordDateTime,
  8010. Ctime: time.Now().Unix(),
  8011. Mtime: time.Now().Unix(),
  8012. Status: 1,
  8013. OrderStatus: 2,
  8014. MdtrtId: his.Number,
  8015. Number: chrg_bchno,
  8016. MedfeeSumamt: totals,
  8017. PayWay: pay_way,
  8018. PayWays: pay_ways,
  8019. PayPrice: pay_price,
  8020. MedType: strconv.Itoa(int(reg_type)),
  8021. PayCardNo: pay_card_no,
  8022. DiscountPrice: discount_price,
  8023. PreferentialPrice: preferential_price,
  8024. RealityPrice: reality_price,
  8025. FoundPrice: found_price,
  8026. MedicalInsurancePrice: medical_insurance_price,
  8027. PrivatePrice: private_price,
  8028. SettleEndTime: end_time,
  8029. SettleStartTime: start_time,
  8030. PsnPartAmt: totals,
  8031. PsnCashPay: totals,
  8032. SettleType: settle_accounts_type,
  8033. FaPiaoCode: fapiao_code,
  8034. FaPiaoNumber: fapiao_number,
  8035. Diagnosis: diagnosis_id,
  8036. PType: 2,
  8037. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8038. Decimal: decimal,
  8039. OthDesc: oth_desc,
  8040. CashPay: cash_pay,
  8041. WechatPay: wechat_pay,
  8042. AliPay: ali_pay,
  8043. JifenPay: jifen_pay,
  8044. BandCardPay: band_card_pay,
  8045. Creator: adminUser.AdminUser.Id,
  8046. }
  8047. err = service.CreateOrderTX(order, tx)
  8048. if err != nil {
  8049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8050. return
  8051. }
  8052. var customs []*Custom
  8053. for _, item := range prescriptions {
  8054. if item.Type == 1 { //药品a
  8055. for _, subItem := range item.HisDoctorAdviceInfo {
  8056. cus := &Custom{
  8057. AdviceId: subItem.ID,
  8058. ProjectId: 0,
  8059. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8060. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8061. FeedetlSn: subItem.FeedetlSn,
  8062. Price: fmt.Sprintf("%.4f", subItem.Price),
  8063. MedListCodg: subItem.MedListCodg,
  8064. Type: 1,
  8065. }
  8066. customs = append(customs, cus)
  8067. }
  8068. }
  8069. if item.Type == 2 { //项目
  8070. for _, subItem := range item.HisPrescriptionProject {
  8071. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8072. cus := &Custom{
  8073. AdviceId: 0,
  8074. ProjectId: subItem.ID,
  8075. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8076. Cut: fmt.Sprintf("%.4f", cnt),
  8077. FeedetlSn: subItem.FeedetlSn,
  8078. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8079. MedListCodg: subItem.MedListCodg,
  8080. Type: 2,
  8081. }
  8082. customs = append(customs, cus)
  8083. }
  8084. }
  8085. for _, item := range item.HisAdditionalCharge {
  8086. cus := &Custom{
  8087. ItemId: item.ID,
  8088. AdviceId: 0,
  8089. ProjectId: 0,
  8090. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8091. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8092. FeedetlSn: item.FeedetlSn,
  8093. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8094. MedListCodg: item.XtHisAddtionConfig.Code,
  8095. Type: 3,
  8096. }
  8097. customs = append(customs, cus)
  8098. }
  8099. }
  8100. for _, item := range customs {
  8101. var advice_id int64 = 0
  8102. var project_id int64 = 0
  8103. var item_id int64 = 0
  8104. var types int64 = 0
  8105. if item.Type == 1 {
  8106. advice_id = item.AdviceId
  8107. project_id = 0
  8108. item_id = 0
  8109. } else if item.Type == 2 {
  8110. advice_id = 0
  8111. item_id = 0
  8112. project_id = item.ProjectId
  8113. } else if item.Type == 3 {
  8114. advice_id = 0
  8115. item_id = item.ItemId
  8116. project_id = 0
  8117. }
  8118. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8119. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8120. pric, _ := strconv.ParseFloat(item.Price, 32)
  8121. info := &models.HisOrderInfo{
  8122. OrderNumber: order.Number,
  8123. UploadDate: time.Now().Unix(),
  8124. AdviceId: advice_id,
  8125. DetItemFeeSumamt: detItemFeeSumamt,
  8126. Cnt: cut,
  8127. Pric: pric,
  8128. PatientId: id,
  8129. Status: 1,
  8130. Mtime: time.Now().Unix(),
  8131. Ctime: time.Now().Unix(),
  8132. UserOrgId: adminUser.CurrentOrgId,
  8133. HisPatientId: his.ID,
  8134. OrderId: order.ID,
  8135. ProjectId: project_id,
  8136. Type: types,
  8137. ItemId: item_id,
  8138. }
  8139. service.CreateOrderInfoTX(info, tx)
  8140. }
  8141. his.Diagnosis = diagnosis_id
  8142. his.SickType = sick_type
  8143. his.RegisterType = reg_type
  8144. his.MedicalTreatmentType = reg_type
  8145. service.UpdataHisPateintTX(&his, tx)
  8146. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8147. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8148. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8149. //判断是否使用了押金
  8150. if dec_way == "true" {
  8151. tmpstring := strconv.FormatInt(order.ID, 10)
  8152. //扣押金
  8153. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8154. order.Decimal = decimal
  8155. service.UpDateOrderTwo(order, tx)
  8156. if errmsg != nil {
  8157. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8158. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8159. return
  8160. }
  8161. }
  8162. if err == nil {
  8163. for _, info := range prescriptions {
  8164. if info.Type == 1 {
  8165. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8166. }
  8167. if info.Type == 2 {
  8168. for _, sumItem := range info.HisPrescriptionProject {
  8169. if sumItem.Type == 3 {
  8170. var good models.DialysisBeforePrepareGoods
  8171. var newGood models.NewDialysisBeforePrepareGoods
  8172. var oldGood models.OldDialysisBeforePrepareGoods
  8173. good.GoodId = sumItem.GoodInfo.ID
  8174. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8175. count, _ := strconv.Atoi(sumItem.Count)
  8176. good.Count = int64(count)
  8177. good.StorehouseId = houseConfig.StorehouseOutInfo
  8178. good.ProjectId = sumItem.ID
  8179. good.PatientId = sumItem.PatientId
  8180. goods = append(goods, &good)
  8181. newGood.GoodId = sumItem.GoodInfo.ID
  8182. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8183. count2, _ := strconv.Atoi(sumItem.Count)
  8184. newGood.Count = int64(count2)
  8185. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8186. newGood.ProjectId = sumItem.ID
  8187. newGood.PatientId = sumItem.HisPatientId
  8188. newGoods = append(newGoods, &newGood)
  8189. oldGood.GoodId = sumItem.GoodInfo.ID
  8190. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8191. count3, _ := strconv.Atoi(sumItem.Count)
  8192. oldGood.Count = int64(count3)
  8193. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8194. oldGood.ProjectId = sumItem.ID
  8195. oldGood.RecordDate = sumItem.RecordDate
  8196. oldGood.PatientId = sumItem.HisPatientId
  8197. oldGoods = append(oldGoods, &oldGood)
  8198. }
  8199. }
  8200. }
  8201. }
  8202. if settConfig.IsOpen == 1 {
  8203. for _, item := range infoList {
  8204. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8205. if medical.IsUse == 2 {
  8206. //药品出库
  8207. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8208. //查询默认仓库
  8209. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8210. //查询默认仓库剩余多少库存
  8211. var sum_count int64
  8212. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8213. for _, its := range stockInfo {
  8214. if its.MaxUnit == medical.MaxUnit {
  8215. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8216. }
  8217. sum_count += its.StockMaxNumber + its.StockMinNumber
  8218. }
  8219. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8220. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8221. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8222. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8223. }
  8224. }
  8225. orgId := c.GetAdminUserInfo().CurrentOrgId
  8226. if len(oldGoods) > 0 {
  8227. timeStr := time.Now().Format("2006-01-02")
  8228. timeArr := strings.Split(timeStr, "-")
  8229. total, _ := service.FindAllWarehouseOut(orgId)
  8230. total = total + 1
  8231. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8232. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8233. number = number + total
  8234. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8235. operation_time := time.Now().Unix()
  8236. creater := c.GetAdminUserInfo().AdminUser.Id
  8237. //查询默认出库仓库库存
  8238. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8239. recordDateStr := time.Now().Format("2006-01-02")
  8240. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8241. nowtime := recordDate.Unix()
  8242. warehouseOut := models.WarehouseOut{
  8243. WarehouseOutOrderNumber: warehousing_out_order,
  8244. OperationTime: operation_time,
  8245. OrgId: orgId,
  8246. Creater: creater,
  8247. Ctime: time.Now().Unix(),
  8248. Status: 1,
  8249. WarehouseOutTime: nowtime,
  8250. Type: 1,
  8251. StorehouseId: storeConfig.StorehouseOutInfo,
  8252. IsCheck: 1,
  8253. OrderId: order.ID,
  8254. IsSys: 5,
  8255. }
  8256. //查询是否生成出库单
  8257. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8258. if out.ID == 0 {
  8259. service.AddSigleWarehouseOut(&warehouseOut)
  8260. }
  8261. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8262. for _, item := range oldGoods {
  8263. dialyPrepareOne := models.DialysisBeforePrepare{
  8264. GoodTypeId: item.GoodTypeId,
  8265. GoodId: item.GoodId,
  8266. PatientId: his.PatientId,
  8267. RecordDate: item.RecordDate,
  8268. UserOrgId: adminUser.CurrentOrgId,
  8269. Count: item.Count,
  8270. Ctime: time.Now().Unix(),
  8271. Creater: adminUser.AdminUser.Id,
  8272. CommdityCode: item.CommdityCode,
  8273. Status: 1,
  8274. StorehouseId: houseConfig.StorehouseOutInfo,
  8275. }
  8276. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8277. //非零用
  8278. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8279. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8280. //查询剩余库存
  8281. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8282. var sum_count int64
  8283. for _, item := range goodList {
  8284. sum_count += item.StockCount
  8285. }
  8286. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8287. //耗材
  8288. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8289. }
  8290. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8291. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8292. //查询剩余库存
  8293. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8294. var sum_count int64
  8295. for _, item := range goodList {
  8296. sum_count += item.StockCount
  8297. }
  8298. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8299. //耗材
  8300. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8301. }
  8302. }
  8303. }
  8304. }
  8305. c.ServeSuccessJSON(map[string]interface{}{
  8306. "msg": "结算成功",
  8307. })
  8308. }
  8309. }
  8310. }
  8311. // 退款
  8312. func (c *HisApiController) Refund() {
  8313. order_id, _ := c.GetInt64("order_id")
  8314. order, _ := service.GetHisOrderByID(order_id)
  8315. adminUser := c.GetAdminUserInfo()
  8316. orgid := c.GetAdminUserInfo().CurrentOrgId
  8317. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8318. if err != nil {
  8319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8320. return
  8321. }
  8322. tmp := strconv.FormatInt(order.ID, 10)
  8323. //当押金不为零时产生退费记录
  8324. if order.Decimal != 0 {
  8325. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8326. if err != nil {
  8327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8328. return
  8329. }
  8330. }
  8331. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8332. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8333. var goods []*models.DialysisBeforePrepareGoods
  8334. var newGoods []*models.NewDialysisBeforePrepareGoods
  8335. var infos []*models.HisDoctorAdviceInfo
  8336. for _, info := range orders {
  8337. if info.AdviceId > 0 && info.ProjectId == 0 {
  8338. infos = append(infos, &info.HisDoctorAdviceInfo)
  8339. }
  8340. if info.ProjectId > 0 && info.AdviceId == 0 {
  8341. if info.HisPrescriptionProject.Type == 3 {
  8342. var good models.DialysisBeforePrepareGoods
  8343. var newGood models.NewDialysisBeforePrepareGoods
  8344. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8345. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8346. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8347. good.Count = int64(count)
  8348. good.StorehouseId = houseConfig.StorehouseOutInfo
  8349. good.ProjectId = info.HisPrescriptionProject.ID
  8350. good.PatientId = info.PatientId
  8351. good.OrderId = order_id
  8352. goods = append(goods, &good)
  8353. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8354. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8355. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8356. newGood.Count = int64(count2)
  8357. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8358. newGood.ProjectId = info.HisPrescriptionProject.ID
  8359. newGood.RecordDate = order.SettleAccountsDate
  8360. newGood.UserOrgId = order.UserOrgId
  8361. newGood.PatientId = info.PatientId
  8362. newGood.OrderId = order_id
  8363. newGoods = append(newGoods, &newGood)
  8364. }
  8365. }
  8366. }
  8367. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8368. if settConfig.IsOpen == 1 {
  8369. for _, item := range infos {
  8370. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8371. }
  8372. for _, item := range newGoods {
  8373. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8374. }
  8375. }
  8376. c.ServeSuccessJSON(map[string]interface{}{
  8377. "msg": "退费成功",
  8378. })
  8379. }
  8380. func (c *HisApiController) RefundNumber() {
  8381. his_patient_id, _ := c.GetInt64("id")
  8382. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8383. info.Status = 0
  8384. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8385. if count > 0 {
  8386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8387. return
  8388. }
  8389. err := service.SaveHisPatient(info)
  8390. if err == nil {
  8391. c.ServeSuccessJSON(map[string]interface{}{
  8392. "msg": "退号成功",
  8393. })
  8394. } else {
  8395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8396. return
  8397. }
  8398. }
  8399. func (this *HisApiController) AdditionalCharge() {
  8400. dataBody := make(map[string]interface{}, 0)
  8401. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8402. fmt.Println(err)
  8403. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8404. patient_id := int64(dataBody["patient_id"].(float64))
  8405. medicineData, _ := dataBody["medicineData"].([]interface{})
  8406. adminUserInfo := this.GetAdminUserInfo()
  8407. orgId := adminUserInfo.CurrentOrgId
  8408. admin_user_id := adminUserInfo.AdminUser.Id
  8409. timeStr := time.Now().Format("2006-01-02")
  8410. timeLayout := "2006-01-02 15:04:05"
  8411. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8412. timenow := timeStringToTime.Unix()
  8413. var additionalCharges []*models.HisAdditionalCharge
  8414. for _, item := range medicineData {
  8415. var randNum int
  8416. randNum = rand.Intn(10000) + 1000
  8417. timestamp := time.Now().Unix()
  8418. tempTime := time.Unix(timestamp, 0)
  8419. timeFormat := tempTime.Format("20060102150405")
  8420. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8421. items := item.(map[string]interface{})
  8422. money := items["price"].(string)
  8423. item_id_str := items["item_id"].(string)
  8424. name := items["name"].(string)
  8425. id_str := items["id"].(string)
  8426. moneys, _ := strconv.ParseInt(money, 10, 64)
  8427. monStr := strconv.FormatInt(moneys, 10)
  8428. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8429. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8430. id, _ := strconv.ParseInt(id_str, 10, 64)
  8431. additionalCharge := &models.HisAdditionalCharge{
  8432. ID: id,
  8433. HisPatientId: his_patient_id,
  8434. UserOrgId: orgId,
  8435. PatientId: patient_id,
  8436. RecordDate: timenow,
  8437. Price: monneyStr,
  8438. Status: 1,
  8439. ItemName: name,
  8440. ItemId: item_id,
  8441. AdminUserId: admin_user_id,
  8442. CreatedTime: time.Now().Unix(),
  8443. OrderStatus: 0,
  8444. PrescriptionNumber: "",
  8445. BatchNumber: "",
  8446. FeedetlSn: p_number,
  8447. }
  8448. service.CreateAdditionalCharge(additionalCharge)
  8449. additionalCharges = append(additionalCharges, additionalCharge)
  8450. }
  8451. this.ServeSuccessJSON(map[string]interface{}{
  8452. "msg": "添加成功",
  8453. "additional_charges": additionalCharges,
  8454. })
  8455. }
  8456. func (this *HisApiController) DeleteAddition() {
  8457. id, _ := this.GetInt64("id")
  8458. //TODO 需要判断是否已经结算
  8459. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8460. if err == nil {
  8461. this.ServeSuccessJSON(map[string]interface{}{
  8462. "msg": "删除成功",
  8463. })
  8464. return
  8465. } else {
  8466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8467. return
  8468. }
  8469. }
  8470. func (this *HisApiController) GetAdminUsers() {
  8471. adminUser := this.GetAdminUserInfo()
  8472. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8473. this.ServeSuccessJSON(map[string]interface{}{
  8474. "doctors": doctors,
  8475. })
  8476. }
  8477. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8478. change_type, _ := this.GetInt64("type", 0)
  8479. record_date := this.GetString("record_time")
  8480. patient_id, _ := this.GetInt64("patient_id", 0)
  8481. p_type, _ := this.GetInt64("p_type", 0)
  8482. timeLayout := "2006-01-02"
  8483. loc, _ := time.LoadLocation("Local")
  8484. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8485. record_time := theAdviceRecordTime.Unix()
  8486. adminUserInfo := this.GetAdminUserInfo()
  8487. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8488. if err == nil {
  8489. if len(prescriptions) == 0 {
  8490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8491. return
  8492. } else {
  8493. this.ServeSuccessJSON(map[string]interface{}{
  8494. "prescriptions": prescriptions,
  8495. })
  8496. return
  8497. }
  8498. } else {
  8499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8500. return
  8501. }
  8502. }
  8503. func (this *HisApiController) GetCallHisPrescription() {
  8504. patient_id, _ := this.GetInt64("patient_id", 0)
  8505. timeLayout := "2006-01-02"
  8506. loc, _ := time.LoadLocation("Local")
  8507. start_time := this.GetString("start_time")
  8508. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8509. end_time := this.GetString("end_time")
  8510. p_type, _ := this.GetInt64("p_type")
  8511. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8512. adminUserInfo := this.GetAdminUserInfo()
  8513. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8514. if err == nil {
  8515. this.ServeSuccessJSON(map[string]interface{}{
  8516. "prescriptions": prescriptions,
  8517. })
  8518. return
  8519. } else {
  8520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8521. return
  8522. }
  8523. }
  8524. func (this *HisApiController) GetHisDayPrescription() {
  8525. timeLayout := "2006-01-02"
  8526. loc, _ := time.LoadLocation("Local")
  8527. start_time := this.GetString("start_time")
  8528. patient_id, _ := this.GetInt64("patient_id", 0)
  8529. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8530. end_time := this.GetString("end_time")
  8531. p_type, _ := this.GetInt64("p_type")
  8532. order_status, _ := this.GetInt64("type")
  8533. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8534. adminUserInfo := this.GetAdminUserInfo()
  8535. var dayHisPrescription []*models.HisPrescription
  8536. var err error
  8537. if order_status == 1 || order_status == 0 {
  8538. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8539. } else if order_status == 2 {
  8540. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8541. }
  8542. var settle_total float64
  8543. for _, item := range dayHisPrescription {
  8544. if len(item.HisPrescriptionProject) > 0 {
  8545. for _, subItem := range item.HisPrescriptionProject {
  8546. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8547. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8548. settle_total = settle_total + total
  8549. }
  8550. }
  8551. if len(item.HisDoctorAdviceInfo) > 0 {
  8552. for _, subItem := range item.HisDoctorAdviceInfo {
  8553. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8554. settle_total = settle_total + total
  8555. }
  8556. }
  8557. }
  8558. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8559. if err == nil {
  8560. this.ServeSuccessJSON(map[string]interface{}{
  8561. "day_prescription": dayHisPrescription,
  8562. "settle_total": settle_total,
  8563. })
  8564. return
  8565. } else {
  8566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8567. return
  8568. }
  8569. }
  8570. func (c *HisApiController) GetHisChargePatientList() {
  8571. record_date := c.GetString("record_date")
  8572. order_status, _ := c.GetInt64("type")
  8573. sch_type, _ := c.GetInt64("sch_type")
  8574. timeLayout := "2006-01-02"
  8575. loc, _ := time.LoadLocation("Local")
  8576. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8577. if err != nil {
  8578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8579. return
  8580. }
  8581. recordDateTime := theTime.Unix()
  8582. adminInfo := c.GetAdminUserInfo()
  8583. var tempPatients []*service.NewTempPatients
  8584. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8585. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8586. if order_status != 2 {
  8587. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8588. } else {
  8589. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8590. }
  8591. } else {
  8592. if order_status != 2 {
  8593. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8594. } else {
  8595. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8596. }
  8597. }
  8598. var patients []*service.NewTempPatients
  8599. var patients_two []*service.NewTempPatients
  8600. for _, item := range tempPatients {
  8601. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8602. //过滤掉没挂号的和没开处方的
  8603. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8604. patients = append(patients, item)
  8605. }
  8606. //过滤掉没挂号的
  8607. if len(item.HisPatient) > 0 {
  8608. patients_two = append(patients_two, item)
  8609. }
  8610. } else {
  8611. if len(item.HisPrescription) > 0 {
  8612. patients = append(patients, item)
  8613. }
  8614. }
  8615. }
  8616. c.ServeSuccessJSON(map[string]interface{}{
  8617. "list": patients,
  8618. "list_two": patients_two,
  8619. })
  8620. }
  8621. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8622. record_date := c.GetString("record_date")
  8623. timeLayout := "2006-01-02"
  8624. loc, _ := time.LoadLocation("Local")
  8625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8626. if err != nil {
  8627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8628. return
  8629. }
  8630. recordDateTime := theTime.Unix()
  8631. adminUser := c.GetAdminUserInfo()
  8632. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8633. var patients []*service.Patients
  8634. for _, item := range tempPatients {
  8635. if item.HisPatient.ID == 0 {
  8636. patients = append(patients, item)
  8637. }
  8638. }
  8639. c.ServeSuccessJSON(map[string]interface{}{
  8640. "list": patients,
  8641. //"list_two": patients_two,
  8642. })
  8643. }
  8644. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8645. newArr = make([]*service.Patients, 0)
  8646. for i := 0; i < len(patient); i++ {
  8647. repeat := false
  8648. for j := i + 1; j < len(patient); j++ {
  8649. if patient[i].ID == patient[j].ID {
  8650. repeat = true
  8651. break
  8652. }
  8653. }
  8654. if !repeat {
  8655. newArr = append(newArr, patient[i])
  8656. }
  8657. }
  8658. return
  8659. }
  8660. func (c *HisApiController) GetHisChargePatientInfo() {
  8661. patient_id, _ := c.GetInt64("patient_id")
  8662. his_patient_id, _ := c.GetInt64("his_patient_id")
  8663. record_date := c.GetString("record_date")
  8664. //start_time := c.GetString("start_time")
  8665. //end_time := c.GetString("end_time")
  8666. order_status, _ := c.GetInt64("type", 0)
  8667. p_type, _ := c.GetInt64("p_type", 0)
  8668. order_id, _ := c.GetInt64("order_id", 0)
  8669. timeLayout := "2006-01-02"
  8670. loc, _ := time.LoadLocation("Local")
  8671. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8672. if err != nil {
  8673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8674. return
  8675. }
  8676. recordDateTime := theTime.Unix()
  8677. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8678. //if err != nil {
  8679. //
  8680. //}
  8681. //startRecordDateTime := startTime.Unix()
  8682. //
  8683. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8684. //if err != nil {
  8685. //
  8686. //}
  8687. //endRecordDateTime := endTime.Unix()
  8688. admin := c.GetAdminUserInfo()
  8689. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8690. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8691. var prescriptions []*models.HisPrescription
  8692. //var unChargeMonthPrescriptions []*models.HisPrescription
  8693. order, _ := service.GetHisOrderByID(order_id)
  8694. if order_status == 1 || order_status == 0 {
  8695. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8696. } else if order_status == 2 {
  8697. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8698. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8699. }
  8700. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8701. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8702. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8703. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8704. //获取所有科室信息
  8705. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8706. c.ServeSuccessJSON(map[string]interface{}{
  8707. "his_info": his_patient_info,
  8708. "xt_info": xt_patient_info,
  8709. "prescription": prescriptions,
  8710. "case_history": case_history,
  8711. "info": patientPrescriptionInfo,
  8712. "last_info": lastPatientPrescriptionInfo,
  8713. "order": order,
  8714. "doctors": doctors,
  8715. "department": department,
  8716. })
  8717. return
  8718. }
  8719. func (c *HisApiController) GetAllOrderDetail() {
  8720. order_id, _ := c.GetInt64("id", 0)
  8721. order, _ := service.GetHisOrderByID(order_id)
  8722. if order.ID == 0 {
  8723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8724. return
  8725. }
  8726. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8727. org_id := c.GetAdminUserInfo().CurrentOrgId
  8728. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8729. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8730. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8731. c.ServeSuccessJSON(map[string]interface{}{
  8732. "order": order,
  8733. "order_info": order_info,
  8734. "patient": patient,
  8735. "admin_info": adminInfo,
  8736. "hospital_record": record,
  8737. })
  8738. return
  8739. }
  8740. func (c *HisApiController) GetAllOrderDetailCollect() {
  8741. order_id, _ := c.GetInt64("id", 0)
  8742. order, _ := service.GetHisOrderByID(order_id)
  8743. if order.ID == 0 {
  8744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8745. return
  8746. }
  8747. org_id := c.GetAdminUserInfo().CurrentOrgId
  8748. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8749. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8750. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8751. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8752. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8753. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8754. var bedCostTotal float64 = 0 //床位总费
  8755. //var bedCostSelfTotal float64 = 0 //床位自费
  8756. var operationCostTotal float64 = 0 //手术费
  8757. //var operationCostSelfTotal float64 = 0 //手术费
  8758. var otherCostTotal float64 = 0 //其他费用
  8759. //var otherCostSelfTotal float64 = 0 //其他费用
  8760. var materialCostTotal float64 = 0 //材料费
  8761. //var materialCostSelfTotal float64 = 0 //材料费
  8762. var westernMedicineCostTotal float64 = 0 //西药费
  8763. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8764. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8765. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8766. var checkCostTotal float64 = 0 //检查费
  8767. //var checkCostSelfTotal float64 = 0 //检查费
  8768. var laboratoryCostTotal float64 = 0 //化验费
  8769. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8770. var treatCostTotal float64 = 0 //治疗费用
  8771. //var treatCostSelfTotal float64 = 0 //治疗费用
  8772. var zhenChaCostTotal float64 = 0 //其他费用
  8773. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8774. decimal.DivisionPrecision = 2
  8775. var BalanceAccountsType int64
  8776. if his.ID > 0 {
  8777. BalanceAccountsType = his.BalanceAccountsType
  8778. } else {
  8779. BalanceAccountsType = record.BalanceAccountsType
  8780. }
  8781. if BalanceAccountsType != 2 {
  8782. for _, item := range order_info {
  8783. if org_id == 10215 {
  8784. if item.MedChrgitmType == "01" { //床位费
  8785. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8786. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8787. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8788. }
  8789. if item.MedChrgitmType == "02" { //诊察费
  8790. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8791. //zhenChaCostSelfTotal = zhenChaCostTotal
  8792. }
  8793. if item.MedChrgitmType == "03" { //检查费
  8794. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8795. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8796. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8797. }
  8798. //if item.MedChrgitmType == "02" { //检查费
  8799. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8800. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8801. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8802. //}
  8803. if item.MedChrgitmType == "04" { //化验费
  8804. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8805. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8806. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8807. }
  8808. if item.MedChrgitmType == "05" { //治疗费
  8809. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8810. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8811. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8812. }
  8813. if item.MedChrgitmType == "06" { //手术费
  8814. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8815. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8816. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8817. }
  8818. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8819. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8820. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8821. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8822. }
  8823. if item.MedChrgitmType == "09" { //西药费
  8824. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8825. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8826. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8827. }
  8828. if item.MedChrgitmType == "11" { //中成费
  8829. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8830. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8831. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8832. }
  8833. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8834. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8835. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8836. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8837. }
  8838. } else if org_id == 10188 || org_id == 10217 {
  8839. if item.MedChrgitmType == "01" { //床位费
  8840. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8841. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8842. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8843. }
  8844. if item.MedChrgitmType == "02" { //诊察费
  8845. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8846. //zhenChaCostSelfTotal = zhenChaCostTotal
  8847. }
  8848. if item.MedChrgitmType == "03" { //检查费
  8849. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8850. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8851. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8852. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8853. }
  8854. //if item.MedChrgitmType == "02" { //检查费
  8855. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8856. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8857. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8858. //}
  8859. if item.MedChrgitmType == "04" { //化验费
  8860. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8861. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8862. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8863. }
  8864. if item.MedChrgitmType == "05" { //治疗费
  8865. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8866. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8867. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8868. }
  8869. if item.MedChrgitmType == "06" { //手术费
  8870. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8871. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8872. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8873. }
  8874. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8875. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8876. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8877. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8878. }
  8879. if item.MedChrgitmType == "09" { //西药费
  8880. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8881. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8882. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8883. }
  8884. if item.MedChrgitmType == "11" { //中成费
  8885. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8886. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8887. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8888. }
  8889. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8890. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8891. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8892. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8893. }
  8894. } else {
  8895. if item.MedChrgitmType == "01" { //床位费
  8896. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8897. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8898. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8899. }
  8900. //if item.MedChrgitmType == "02" { //诊察费
  8901. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8902. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8903. //}
  8904. if item.MedChrgitmType == "03" { //检查费
  8905. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8906. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8907. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8908. }
  8909. //if item.MedChrgitmType == "02" { //检查费
  8910. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8911. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8912. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8913. //}
  8914. if item.MedChrgitmType == "04" { //化验费
  8915. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8916. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8917. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8918. }
  8919. if item.MedChrgitmType == "05" { //治疗费
  8920. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8921. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8922. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8923. }
  8924. if item.MedChrgitmType == "06" { //手术费
  8925. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8926. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8927. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8928. }
  8929. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8930. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8931. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8932. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8933. }
  8934. if item.MedChrgitmType == "09" { //西药费
  8935. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8936. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8937. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8938. }
  8939. if item.MedChrgitmType == "11" { //中成费
  8940. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8941. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8942. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8943. }
  8944. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8945. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8946. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8947. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8948. }
  8949. }
  8950. }
  8951. c.ServeSuccessJSON(map[string]interface{}{
  8952. "order": order,
  8953. "order_info": order_info,
  8954. "patient": patient,
  8955. "admin_info": adminInfo,
  8956. "his_hospital": record,
  8957. "bedCostTotal": bedCostTotal,
  8958. "operationCostTotal": operationCostTotal,
  8959. "otherCostTotal": otherCostTotal,
  8960. "materialCostTotal": materialCostTotal,
  8961. "westernMedicineCostTotal": westernMedicineCostTotal,
  8962. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8963. "checkCostTotal": checkCostTotal,
  8964. "zhenChaCostTotal": zhenChaCostTotal,
  8965. "laboratoryCostTotal": laboratoryCostTotal,
  8966. "treatCostTotal": treatCostTotal,
  8967. })
  8968. } else {
  8969. for _, item := range order_info {
  8970. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8971. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8972. item.MedChrgitmType = "09"
  8973. }
  8974. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8975. if item.HisPrescriptionProject.Type == 2 {
  8976. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8977. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8978. case 0:
  8979. item.MedChrgitmType = "0"
  8980. break
  8981. case 1:
  8982. item.MedChrgitmType = "14"
  8983. break
  8984. case 2:
  8985. item.MedChrgitmType = "05"
  8986. break
  8987. case 3:
  8988. item.MedChrgitmType = "03"
  8989. break
  8990. case 4:
  8991. item.MedChrgitmType = "03"
  8992. break
  8993. case 5:
  8994. item.MedChrgitmType = "08"
  8995. break
  8996. case 6:
  8997. item.MedChrgitmType = "14"
  8998. break
  8999. case 7:
  9000. item.MedChrgitmType = "14"
  9001. break
  9002. case 8:
  9003. item.MedChrgitmType = "03"
  9004. break
  9005. case 9:
  9006. item.MedChrgitmType = "14"
  9007. break
  9008. case 10:
  9009. item.MedChrgitmType = "14"
  9010. break
  9011. case 11:
  9012. item.MedChrgitmType = "06"
  9013. break
  9014. case 12:
  9015. item.MedChrgitmType = "12"
  9016. break
  9017. case 13:
  9018. item.MedChrgitmType = "01"
  9019. break
  9020. case 14:
  9021. item.MedChrgitmType = "04"
  9022. break
  9023. case 15:
  9024. item.MedChrgitmType = "14"
  9025. break
  9026. }
  9027. } else {
  9028. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9029. case 1:
  9030. item.MedChrgitmType = "14"
  9031. break
  9032. case 2:
  9033. item.MedChrgitmType = "05"
  9034. break
  9035. case 3:
  9036. item.MedChrgitmType = "04"
  9037. break
  9038. case 4:
  9039. item.MedChrgitmType = "14"
  9040. break
  9041. case 5:
  9042. item.MedChrgitmType = "08"
  9043. break
  9044. case 6:
  9045. item.MedChrgitmType = "14"
  9046. break
  9047. case 7:
  9048. item.MedChrgitmType = "14"
  9049. break
  9050. case 8:
  9051. item.MedChrgitmType = "03"
  9052. break
  9053. case 9:
  9054. item.MedChrgitmType = "14"
  9055. break
  9056. }
  9057. }
  9058. } else if item.HisPrescriptionProject.Type == 3 {
  9059. item.MedChrgitmType = "08"
  9060. }
  9061. }
  9062. }
  9063. for _, item := range order_info {
  9064. if org_id == 10215 {
  9065. if item.MedChrgitmType == "01" { //床位费
  9066. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9067. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9068. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9069. }
  9070. if item.MedChrgitmType == "02" { //诊察费
  9071. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9072. //zhenChaCostSelfTotal = zhenChaCostTotal
  9073. }
  9074. if item.MedChrgitmType == "03" { //检查费
  9075. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9076. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9077. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9078. }
  9079. //if item.MedChrgitmType == "02" { //检查费
  9080. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9081. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9082. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9083. //}
  9084. if item.MedChrgitmType == "04" { //化验费
  9085. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9086. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9087. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9088. }
  9089. if item.MedChrgitmType == "05" { //治疗费
  9090. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9091. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9092. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9093. }
  9094. if item.MedChrgitmType == "06" { //手术费
  9095. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9096. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9097. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9098. }
  9099. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9100. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9101. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9102. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9103. }
  9104. if item.MedChrgitmType == "09" { //西药费
  9105. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9106. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9107. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9108. }
  9109. if item.MedChrgitmType == "11" { //中成费
  9110. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9111. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9112. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9113. }
  9114. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9115. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9116. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9117. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9118. }
  9119. } else {
  9120. if item.MedChrgitmType == "01" { //床位费
  9121. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9122. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9123. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9124. }
  9125. //if item.MedChrgitmType == "02" { //诊察费
  9126. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9127. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9128. //}
  9129. if item.MedChrgitmType == "03" { //检查费
  9130. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9131. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9132. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9133. }
  9134. //if item.MedChrgitmType == "02" { //检查费
  9135. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9136. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9137. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9138. //}
  9139. if item.MedChrgitmType == "04" { //化验费
  9140. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9141. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9142. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9143. }
  9144. if item.MedChrgitmType == "05" { //治疗费
  9145. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9146. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9147. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9148. }
  9149. if item.MedChrgitmType == "06" { //手术费
  9150. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9151. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9152. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9153. }
  9154. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9155. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9156. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9157. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9158. }
  9159. if item.MedChrgitmType == "09" { //西药费
  9160. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9161. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9162. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9163. }
  9164. if item.MedChrgitmType == "11" { //中成费
  9165. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9166. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9167. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9168. }
  9169. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9170. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9171. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9172. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9173. }
  9174. }
  9175. }
  9176. c.ServeSuccessJSON(map[string]interface{}{
  9177. "order": order,
  9178. "order_info": order_info,
  9179. "patient": patient,
  9180. "admin_info": adminInfo,
  9181. "his_hospital": record,
  9182. "bedCostTotal": bedCostTotal,
  9183. "operationCostTotal": operationCostTotal,
  9184. "otherCostTotal": otherCostTotal,
  9185. "materialCostTotal": materialCostTotal,
  9186. "westernMedicineCostTotal": westernMedicineCostTotal,
  9187. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9188. "checkCostTotal": checkCostTotal,
  9189. "zhenChaCostTotal": zhenChaCostTotal,
  9190. "laboratoryCostTotal": laboratoryCostTotal,
  9191. "treatCostTotal": treatCostTotal,
  9192. })
  9193. }
  9194. }
  9195. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9196. page, _ := c.GetInt64("page")
  9197. limit, _ := c.GetInt64("limit")
  9198. keywords := c.GetString("keywords")
  9199. start_time := c.GetString("start_time")
  9200. end_time := c.GetString("end_time")
  9201. //clr_type := c.GetString("clr_type")
  9202. insutype := c.GetString("insutype")
  9203. timeLayout := "2006-01-02"
  9204. loc, _ := time.LoadLocation("Local")
  9205. var theStartTIme int64
  9206. if len(start_time) > 0 {
  9207. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9208. theStartTIme = theTime.Unix()
  9209. }
  9210. var theEndtTIme int64
  9211. if len(end_time) > 0 {
  9212. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9213. theEndtTIme = theTime.Unix()
  9214. }
  9215. if page <= 0 {
  9216. page = 1
  9217. }
  9218. if limit <= 0 {
  9219. limit = 10
  9220. }
  9221. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9222. c.ServeSuccessJSON(map[string]interface{}{
  9223. "total": total,
  9224. "list": list,
  9225. })
  9226. return
  9227. }
  9228. func (c *HisApiController) GetPutOnRecordList() {
  9229. page, _ := c.GetInt64("page")
  9230. limit, _ := c.GetInt64("limit")
  9231. keywords := c.GetString("keywords")
  9232. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9233. if page <= 0 {
  9234. page = 1
  9235. }
  9236. if limit <= 0 {
  9237. limit = 10
  9238. }
  9239. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9240. c.ServeSuccessJSON(map[string]interface{}{
  9241. "total": total,
  9242. "list": list,
  9243. })
  9244. return
  9245. }
  9246. func (c *HisApiController) GetCompareData() {
  9247. start_time := c.GetString("start_time")
  9248. end_time := c.GetString("end_time")
  9249. insutype := c.GetString("insutype")
  9250. clr_type := c.GetString("clr_type")
  9251. timeLayout := "2006-01-02"
  9252. loc, _ := time.LoadLocation("Local")
  9253. var theStartTIme int64
  9254. if len(start_time) > 0 {
  9255. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9256. if err != nil {
  9257. theStartTIme = 0
  9258. }
  9259. theStartTIme = theTime.Unix()
  9260. }
  9261. var theEndtTIme int64
  9262. if len(end_time) > 0 {
  9263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9264. if err != nil {
  9265. theEndtTIme = 0
  9266. }
  9267. theEndtTIme = theTime.Unix()
  9268. }
  9269. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9270. fmt.Println(err)
  9271. if err == nil {
  9272. c.ServeSuccessJSON(map[string]interface{}{
  9273. "list": formData,
  9274. })
  9275. } else {
  9276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9277. return
  9278. }
  9279. }
  9280. func (c *HisApiController) GetFaPiaoData() {
  9281. order_id, _ := c.GetInt64("order_id")
  9282. patient_id, _ := c.GetInt64("patient_id")
  9283. //number := c.GetString("number")
  9284. adminUser := c.GetAdminUserInfo()
  9285. order, _ := service.GetHisOrderByID(order_id)
  9286. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9287. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9288. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9289. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9290. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9291. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9292. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9293. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9294. var bedCostTotal float64 = 0 //床位总费
  9295. var bedCostSelfTotal float64 = 0 //床位自费
  9296. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9297. var operationCostTotal float64 = 0 //手术费
  9298. var operationCostSelfTotal float64 = 0 //手术费
  9299. var operationCostPartSelfTotal float64 = 0 //手术费
  9300. var otherCostTotal float64 = 0 //其他费用
  9301. var otherCostSelfTotal float64 = 0 //其他费用
  9302. var otherCostPartSelfTotal float64 = 0 //其他费用
  9303. var materialCostTotal float64 = 0 //材料费
  9304. var materialCostSelfTotal float64 = 0 //材料费
  9305. var materialCostPartSelfTotal float64 = 0 //材料费
  9306. var westernMedicineCostTotal float64 = 0 //西药费
  9307. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9308. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9309. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9310. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9311. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9312. var checkCostTotal float64 = 0 //检查费
  9313. var checkCostSelfTotal float64 = 0 //检查费
  9314. var checkCostPartSelfTotal float64 = 0 //检查费
  9315. var hiliCostTotal float64 = 0 //护理费
  9316. var hiliCostSelfTotal float64 = 0 //护理费
  9317. var hiliCostPartSelfTotal float64 = 0 //护理费
  9318. var laboratoryCostTotal float64 = 0 //化验费
  9319. var laboratoryCostSelfTotal float64 = 0 //化验费
  9320. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9321. var treatCostTotal float64 = 0 //治疗费用
  9322. var treatCostSelfTotal float64 = 0 //治疗费用
  9323. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9324. var zhenChaCostTotal float64 = 0 //其他费用
  9325. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9326. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9327. decimal.DivisionPrecision = 2
  9328. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9329. var balanceAccountsType int64
  9330. if his.ID > 0 {
  9331. balanceAccountsType = his.BalanceAccountsType
  9332. } else {
  9333. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9334. }
  9335. if balanceAccountsType == 2 {
  9336. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9337. for _, item := range orderInfos_two {
  9338. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9339. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9340. item.MedChrgitmType = "09"
  9341. }
  9342. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9343. if item.HisPrescriptionProject.Type == 2 {
  9344. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9345. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9346. case 0:
  9347. item.MedChrgitmType = "0"
  9348. break
  9349. case 1:
  9350. item.MedChrgitmType = "14"
  9351. break
  9352. case 2:
  9353. item.MedChrgitmType = "05"
  9354. break
  9355. case 3:
  9356. item.MedChrgitmType = "03"
  9357. break
  9358. case 4:
  9359. item.MedChrgitmType = "03"
  9360. break
  9361. case 5:
  9362. item.MedChrgitmType = "08"
  9363. break
  9364. case 6:
  9365. item.MedChrgitmType = "14"
  9366. break
  9367. case 7:
  9368. item.MedChrgitmType = "14"
  9369. break
  9370. case 8:
  9371. item.MedChrgitmType = "03"
  9372. break
  9373. case 9:
  9374. item.MedChrgitmType = "14"
  9375. break
  9376. case 10:
  9377. item.MedChrgitmType = "14"
  9378. break
  9379. case 11:
  9380. item.MedChrgitmType = "06"
  9381. break
  9382. case 12:
  9383. item.MedChrgitmType = "12"
  9384. break
  9385. case 13:
  9386. item.MedChrgitmType = "01"
  9387. break
  9388. case 14:
  9389. item.MedChrgitmType = "04"
  9390. break
  9391. case 15:
  9392. item.MedChrgitmType = "02"
  9393. break
  9394. }
  9395. } else {
  9396. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9397. case 1:
  9398. item.MedChrgitmType = "14"
  9399. break
  9400. case 2:
  9401. item.MedChrgitmType = "05"
  9402. break
  9403. case 3:
  9404. item.MedChrgitmType = "04"
  9405. break
  9406. case 4:
  9407. item.MedChrgitmType = "03"
  9408. break
  9409. case 5:
  9410. item.MedChrgitmType = "08"
  9411. break
  9412. case 6:
  9413. item.MedChrgitmType = "14"
  9414. break
  9415. case 7:
  9416. item.MedChrgitmType = "14"
  9417. break
  9418. case 8:
  9419. item.MedChrgitmType = "03"
  9420. break
  9421. case 9:
  9422. item.MedChrgitmType = "14"
  9423. break
  9424. }
  9425. }
  9426. } else if item.HisPrescriptionProject.Type == 3 {
  9427. item.MedChrgitmType = "08"
  9428. }
  9429. }
  9430. }
  9431. for _, item := range orderInfos_two {
  9432. fmt.Println(item.MedChrgitmType)
  9433. if item.MedChrgitmType == "07" { //床位费
  9434. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9435. hiliCostSelfTotal = hiliCostTotal
  9436. }
  9437. if item.MedChrgitmType == "01" { //床位费
  9438. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9439. bedCostSelfTotal = bedCostTotal
  9440. }
  9441. if item.MedChrgitmType == "02" { //诊察费
  9442. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9443. zhenChaCostSelfTotal = zhenChaCostTotal
  9444. }
  9445. if item.MedChrgitmType == "03" { //检查费
  9446. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9447. checkCostSelfTotal = checkCostTotal
  9448. }
  9449. if item.MedChrgitmType == "04" { //化验费
  9450. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9451. laboratoryCostSelfTotal = laboratoryCostTotal
  9452. }
  9453. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9454. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9455. treatCostSelfTotal = treatCostTotal
  9456. }
  9457. if item.MedChrgitmType == "06" { //手术费
  9458. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9459. operationCostSelfTotal = treatCostTotal
  9460. }
  9461. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9462. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9463. materialCostSelfTotal = materialCostTotal
  9464. }
  9465. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9466. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9467. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9468. }
  9469. if item.MedChrgitmType == "11" { //中成费
  9470. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9471. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9472. }
  9473. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9474. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9475. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9476. otherCostSelfTotal = otherCostTotal
  9477. }
  9478. } else {
  9479. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9480. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9481. otherCostSelfTotal = otherCostTotal
  9482. }
  9483. }
  9484. }
  9485. } else {
  9486. for _, item := range orderInfos {
  9487. if item.MedChrgitmType == "01" { //床位费
  9488. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9489. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9490. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9491. }
  9492. if item.MedChrgitmType == "02" { //诊察费
  9493. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9494. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9495. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9496. }
  9497. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9498. if item.MedChrgitmType == "03" { //检查费
  9499. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9500. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9501. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9502. }
  9503. } else {
  9504. if item.MedChrgitmType == "03" { //检查费
  9505. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9506. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9507. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9508. }
  9509. }
  9510. if item.MedChrgitmType == "04" { //化验费
  9511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9512. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9513. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9514. }
  9515. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9516. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9517. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9518. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9519. }
  9520. if item.MedChrgitmType == "06" { //手术费
  9521. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9522. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9523. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9524. }
  9525. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9526. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9527. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9528. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9529. }
  9530. if item.MedChrgitmType == "07" { //护理
  9531. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9532. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9533. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9534. }
  9535. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9536. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9537. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9538. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9539. }
  9540. if item.MedChrgitmType == "11" { //中成费
  9541. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9542. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9543. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9544. }
  9545. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9546. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9547. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9548. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9549. }
  9550. }
  9551. }
  9552. timeLayout := "2006-01-02"
  9553. loc, _ := time.LoadLocation("Local")
  9554. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9555. if err != nil {
  9556. }
  9557. startRecordDateTime := startTime.Unix()
  9558. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9559. if err != nil {
  9560. }
  9561. endRecordDateTime := endTime.Unix()
  9562. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9563. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9564. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9565. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9566. c.ServeSuccessJSON(map[string]interface{}{
  9567. "charge_admin_name": charge_admin.UserName,
  9568. "order_number": order.Number, //业务流水号
  9569. "id_card_no": his.IdCardNo, //社会保障号
  9570. "patient": patient,
  9571. "department_name": department.Name, //科室
  9572. "number": his.Number, //门诊号
  9573. "date": order.SettleAccountsDate, //结算日期
  9574. "name": order.PsnName, //姓名
  9575. "gender": patient.Gender, //性别
  9576. "psn_cash_money": order.PsnCashPay, //个人支付
  9577. "pay_way": "门诊", //结算方式
  9578. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9579. "admin_user_name": admin.UserName, //收款员
  9580. "order": order,
  9581. "order_info": orderInfos_two,
  9582. "his": his,
  9583. "bedCostTotal": bedCostTotal,
  9584. "bedCostSelfTotal": bedCostSelfTotal,
  9585. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9586. "operationCostTotal": operationCostTotal,
  9587. "operationCostSelfTotal": operationCostSelfTotal,
  9588. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9589. "otherCostTotal": otherCostTotal,
  9590. "otherCostSelfTotal": otherCostSelfTotal,
  9591. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9592. "materialCostTotal": materialCostTotal,
  9593. "materialCostSelfTotal": materialCostSelfTotal,
  9594. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9595. "westernMedicineCostTotal": westernMedicineCostTotal,
  9596. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9597. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9598. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9599. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9600. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9601. "checkCostTotal": checkCostTotal,
  9602. "checkCostSelfTotal": checkCostSelfTotal,
  9603. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9604. "laboratoryCostTotal": laboratoryCostTotal,
  9605. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9606. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9607. "treatCostTotal": treatCostTotal,
  9608. "treatCostSelfTotal": treatCostSelfTotal,
  9609. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9610. "zhenChaCostTotal": zhenChaCostTotal,
  9611. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9612. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9613. "his_hospital_record": his_hospital_record,
  9614. "pre_pay_money": pre_pay_money,
  9615. "refund_sum": sum,
  9616. "doctor_info": doctor_info,
  9617. "hiliCostTotal": hiliCostTotal,
  9618. "hiliCostSelfTotal": hiliCostSelfTotal,
  9619. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9620. })
  9621. }
  9622. //func (c *HisApiController) GetFaPiaoDatas() {
  9623. // order_ids := c.GetString("order_ids")
  9624. // patient_id, _ := c.GetInt64("patient_id")
  9625. // adminUser := c.GetAdminUserInfo()
  9626. //
  9627. // orders := strings.Split(order_ids, ",")
  9628. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9629. //
  9630. // for _, item := range orders {
  9631. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9632. // order, _ := service.GetHisOrderByID(order_id)
  9633. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9634. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9635. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9636. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9637. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9638. //
  9639. // }
  9640. //
  9641. // var bedCostTotal float64 = 0 //床位总费
  9642. // var bedCostSelfTotal float64 = 0 //床位自费
  9643. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9644. //
  9645. // var operationCostTotal float64 = 0 //手术费
  9646. // var operationCostSelfTotal float64 = 0 //手术费
  9647. // var operationCostPartSelfTotal float64 = 0 //手术费
  9648. //
  9649. // var otherCostTotal float64 = 0 //其他费用
  9650. // var otherCostSelfTotal float64 = 0 //其他费用
  9651. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9652. //
  9653. // var materialCostTotal float64 = 0 //材料费
  9654. // var materialCostSelfTotal float64 = 0 //材料费
  9655. // var materialCostPartSelfTotal float64 = 0 //材料费
  9656. //
  9657. // var westernMedicineCostTotal float64 = 0 //西药费
  9658. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9659. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9660. //
  9661. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9662. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9663. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9664. //
  9665. // var checkCostTotal float64 = 0 //检查费
  9666. // var checkCostSelfTotal float64 = 0 //检查费
  9667. // var checkCostPartSelfTotal float64 = 0 //检查费
  9668. //
  9669. // var laboratoryCostTotal float64 = 0 //化验费
  9670. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9671. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9672. //
  9673. // var treatCostTotal float64 = 0 //治疗费用
  9674. // var treatCostSelfTotal float64 = 0 //治疗费用
  9675. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9676. //
  9677. // var zhenChaCostTotal float64 = 0 //其他费用
  9678. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9679. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9680. //
  9681. // decimal.DivisionPrecision = 2
  9682. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9683. //
  9684. // var balanceAccountsType int64
  9685. // if his.ID > 0 {
  9686. // balanceAccountsType = his.BalanceAccountsType
  9687. // } else {
  9688. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9689. // }
  9690. // if balanceAccountsType == 2 {
  9691. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9692. // for _, item := range orderInfos_two {
  9693. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9694. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9695. // item.MedChrgitmType = "09"
  9696. // }
  9697. //
  9698. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9699. // if item.HisPrescriptionProject.Type == 2 {
  9700. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9701. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9702. // case 0:
  9703. // item.MedChrgitmType = "0"
  9704. // break
  9705. // case 1:
  9706. // item.MedChrgitmType = "14"
  9707. // break
  9708. // case 2:
  9709. // item.MedChrgitmType = "05"
  9710. //
  9711. // break
  9712. // case 3:
  9713. // item.MedChrgitmType = "03"
  9714. //
  9715. // break
  9716. // case 4:
  9717. // item.MedChrgitmType = "03"
  9718. //
  9719. // break
  9720. // case 5:
  9721. // item.MedChrgitmType = "08"
  9722. //
  9723. // break
  9724. // case 6:
  9725. // item.MedChrgitmType = "14"
  9726. //
  9727. // break
  9728. // case 7:
  9729. // item.MedChrgitmType = "14"
  9730. //
  9731. // break
  9732. // case 8:
  9733. // item.MedChrgitmType = "03"
  9734. // break
  9735. // case 9:
  9736. // item.MedChrgitmType = "14"
  9737. // break
  9738. // case 10:
  9739. // item.MedChrgitmType = "14"
  9740. // break
  9741. // case 11:
  9742. // item.MedChrgitmType = "06"
  9743. // break
  9744. // case 12:
  9745. // item.MedChrgitmType = "12"
  9746. // break
  9747. // case 13:
  9748. // item.MedChrgitmType = "01"
  9749. // break
  9750. // case 14:
  9751. // item.MedChrgitmType = "04"
  9752. // break
  9753. // case 15:
  9754. // item.MedChrgitmType = "02"
  9755. // break
  9756. //
  9757. // }
  9758. //
  9759. // } else {
  9760. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9761. //
  9762. // case 1:
  9763. // item.MedChrgitmType = "14"
  9764. // break
  9765. // case 2:
  9766. // item.MedChrgitmType = "05"
  9767. //
  9768. // break
  9769. // case 3:
  9770. // item.MedChrgitmType = "03"
  9771. //
  9772. // break
  9773. // case 4:
  9774. // item.MedChrgitmType = "03"
  9775. //
  9776. // break
  9777. // case 5:
  9778. // item.MedChrgitmType = "08"
  9779. //
  9780. // break
  9781. // case 6:
  9782. // item.MedChrgitmType = "14"
  9783. //
  9784. // break
  9785. // case 7:
  9786. // item.MedChrgitmType = "14"
  9787. //
  9788. // break
  9789. // case 8:
  9790. // item.MedChrgitmType = "03"
  9791. // break
  9792. // case 9:
  9793. // item.MedChrgitmType = "14"
  9794. // break
  9795. //
  9796. // }
  9797. //
  9798. // }
  9799. //
  9800. // } else if item.HisPrescriptionProject.Type == 3 {
  9801. // item.MedChrgitmType = "08"
  9802. // }
  9803. // }
  9804. // }
  9805. //
  9806. // for _, item := range orderInfos_two {
  9807. // fmt.Println(item.MedChrgitmType)
  9808. // if item.MedChrgitmType == "01" { //床位费
  9809. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9810. // bedCostSelfTotal = bedCostTotal
  9811. // }
  9812. //
  9813. // if item.MedChrgitmType == "02" { //诊察费
  9814. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9815. // zhenChaCostSelfTotal = zhenChaCostTotal
  9816. // }
  9817. //
  9818. // if item.MedChrgitmType == "03" { //检查费
  9819. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9820. // checkCostSelfTotal = checkCostTotal
  9821. // }
  9822. //
  9823. // if item.MedChrgitmType == "04" { //化验费
  9824. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9825. // laboratoryCostSelfTotal = laboratoryCostTotal
  9826. // }
  9827. //
  9828. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9829. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9830. // treatCostSelfTotal = treatCostTotal
  9831. // }
  9832. //
  9833. // if item.MedChrgitmType == "06" { //手术费
  9834. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9835. // operationCostSelfTotal = treatCostTotal
  9836. // }
  9837. //
  9838. // if item.MedChrgitmType == "08" { //材料费
  9839. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9840. // materialCostSelfTotal = materialCostTotal
  9841. // }
  9842. //
  9843. // if item.MedChrgitmType == "09" { //西药费
  9844. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9845. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9846. // }
  9847. //
  9848. // if item.MedChrgitmType == "11" { //中成费
  9849. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9850. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9851. // }
  9852. //
  9853. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9854. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9855. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9856. // otherCostSelfTotal = otherCostTotal
  9857. // }
  9858. // } else {
  9859. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9860. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9861. // otherCostSelfTotal = otherCostTotal
  9862. // }
  9863. //
  9864. // }
  9865. //
  9866. // }
  9867. //
  9868. // } else {
  9869. // for _, item := range orderInfos {
  9870. // if item.MedChrgitmType == "01" { //床位费
  9871. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9872. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9873. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9874. // }
  9875. //
  9876. // if item.MedChrgitmType == "02" { //诊察费
  9877. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9878. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9879. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9880. // }
  9881. //
  9882. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9883. // if item.MedChrgitmType == "03" { //检查费
  9884. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9885. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9886. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9887. //
  9888. // }
  9889. // } else {
  9890. // if item.MedChrgitmType == "03" { //检查费
  9891. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9892. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9893. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9894. // }
  9895. //
  9896. // }
  9897. //
  9898. // if item.MedChrgitmType == "04" { //化验费
  9899. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9900. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9901. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9902. //
  9903. // }
  9904. //
  9905. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9906. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9907. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9908. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9909. //
  9910. // }
  9911. //
  9912. // if item.MedChrgitmType == "06" { //手术费
  9913. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9914. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9915. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9916. // }
  9917. //
  9918. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9919. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9920. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9921. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9922. // }
  9923. //
  9924. // if item.MedChrgitmType == "09" { //西药费
  9925. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9926. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9927. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9928. // }
  9929. //
  9930. // if item.MedChrgitmType == "11" { //中成费
  9931. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9932. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9933. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9934. // }
  9935. //
  9936. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9937. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9938. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9939. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9940. // }
  9941. //
  9942. // }
  9943. // }
  9944. // timeLayout := "2006-01-02"
  9945. // loc, _ := time.LoadLocation("Local")
  9946. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9947. // if err != nil {
  9948. // }
  9949. // startRecordDateTime := startTime.Unix()
  9950. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9951. // if err != nil {
  9952. // }
  9953. // endRecordDateTime := endTime.Unix()
  9954. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9955. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9956. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9957. //
  9958. // c.ServeSuccessJSON(map[string]interface{}{
  9959. // "order_number": order.Number, //业务流水号
  9960. // "id_card_no": his.IdCardNo, //社会保障号
  9961. // "department_name": department.Name, //科室
  9962. // "number": his.Number, //门诊号
  9963. // "date": order.SettleAccountsDate, //结算日期
  9964. // "name": order.PsnName, //姓名
  9965. // "gender": patient.Gender, //性别
  9966. // "psn_cash_money": order.PsnCashPay, //个人支付
  9967. // "pay_way": "门诊", //结算方式
  9968. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9969. // "admin_user_name": admin.UserName, //收款员
  9970. // "order": order,
  9971. // "order_info": orderInfos_two,
  9972. // "his": his,
  9973. // "bedCostTotal": bedCostTotal,
  9974. // "bedCostSelfTotal": bedCostSelfTotal,
  9975. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9976. // "operationCostTotal": operationCostTotal,
  9977. // "operationCostSelfTotal": operationCostSelfTotal,
  9978. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9979. // "otherCostTotal": otherCostTotal,
  9980. // "otherCostSelfTotal": otherCostSelfTotal,
  9981. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9982. // "materialCostTotal": materialCostTotal,
  9983. // "materialCostSelfTotal": materialCostSelfTotal,
  9984. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9985. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9986. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9987. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9988. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9989. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9990. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9991. // "checkCostTotal": checkCostTotal,
  9992. // "checkCostSelfTotal": checkCostSelfTotal,
  9993. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9994. // "laboratoryCostTotal": laboratoryCostTotal,
  9995. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9996. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9997. // "treatCostTotal": treatCostTotal,
  9998. // "treatCostSelfTotal": treatCostSelfTotal,
  9999. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10000. // "zhenChaCostTotal": zhenChaCostTotal,
  10001. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10002. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10003. // "his_hospital_record": his_hospital_record,
  10004. // "pre_pay_money": pre_pay_money,
  10005. // "refund_sum": sum,
  10006. // })
  10007. //
  10008. //}
  10009. func (this *HisApiController) GetIncomeStatisticsData() {
  10010. start_time := this.GetString("start_time")
  10011. end_time := this.GetString("end_time")
  10012. key_words := this.GetString("key_words")
  10013. limit, _ := this.GetInt64("limit")
  10014. page, _ := this.GetInt64("page")
  10015. if page <= 0 {
  10016. page = 1
  10017. }
  10018. if limit <= 0 {
  10019. limit = 10
  10020. }
  10021. statistics_type, _ := this.GetInt64("statistics_type")
  10022. admin := this.GetAdminUserInfo()
  10023. timeLayout := "2006-01-02"
  10024. loc, _ := time.LoadLocation("Local")
  10025. var theStartTIme int64
  10026. if len(start_time) > 0 {
  10027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10028. if err != nil {
  10029. theStartTIme = 0
  10030. }
  10031. theStartTIme = theTime.Unix()
  10032. }
  10033. var theEndtTIme int64
  10034. if len(end_time) > 0 {
  10035. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10036. if err != nil {
  10037. theEndtTIme = 0
  10038. }
  10039. theEndtTIme = theTime.Unix()
  10040. }
  10041. if statistics_type == 1 {
  10042. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10043. this.ServeSuccessJSON(map[string]interface{}{
  10044. "list": list,
  10045. "total": total,
  10046. })
  10047. } else {
  10048. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10049. this.ServeSuccessJSON(map[string]interface{}{
  10050. "list": list,
  10051. "total": total,
  10052. })
  10053. }
  10054. }
  10055. func (c *HisApiController) PostProjectInformation() {
  10056. adminUser := c.GetAdminUserInfo()
  10057. orgId := adminUser.CurrentOrgId
  10058. dataBody := make(map[string]interface{}, 0)
  10059. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10060. if err != nil {
  10061. utils.ErrorLog(err.Error())
  10062. return
  10063. }
  10064. utils.ErrorLog("%v", dataBody)
  10065. var projectList []*models.HisProject
  10066. var total_goods []interface{}
  10067. tempProjects := dataBody["projects"].([]interface{})
  10068. total_goods = tempProjects
  10069. for index, projectMap := range tempProjects {
  10070. projectM := projectMap.(map[string]interface{})
  10071. var project models.HisProject
  10072. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10073. utils.ErrorLog("project_name")
  10074. return
  10075. }
  10076. project_name, _ := projectM["project_name"].(string)
  10077. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10078. err_log := models.ExportErrLog{
  10079. LogType: 6,
  10080. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10081. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10082. Status: 1,
  10083. CreateTime: time.Now().Unix(),
  10084. UpdateTime: time.Now().Unix(),
  10085. ExportTime: time.Now().Unix(),
  10086. }
  10087. service.CreateExportErrLog(&err_log)
  10088. continue
  10089. }
  10090. project.ProjectName = project_name
  10091. prices := projectM["price"].(string)
  10092. price, _ := strconv.ParseFloat(prices, 64)
  10093. if price <= 0 { //名字为空则生成一条导入错误日志
  10094. err_log := models.ExportErrLog{
  10095. LogType: 6,
  10096. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10097. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10098. Status: 1,
  10099. CreateTime: time.Now().Unix(),
  10100. UpdateTime: time.Now().Unix(),
  10101. ExportTime: time.Now().Unix(),
  10102. }
  10103. service.CreateExportErrLog(&err_log)
  10104. continue
  10105. }
  10106. project.Price = price
  10107. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10108. utils.ErrorLog("unit_id")
  10109. return
  10110. }
  10111. unit := projectM["unit"].(string)
  10112. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10113. err_log := models.ExportErrLog{
  10114. LogType: 6,
  10115. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10116. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10117. Status: 1,
  10118. CreateTime: time.Now().Unix(),
  10119. UpdateTime: time.Now().Unix(),
  10120. ExportTime: time.Now().Unix(),
  10121. }
  10122. service.CreateExportErrLog(&err_log)
  10123. continue
  10124. }
  10125. project.Unit = unit
  10126. cost_classify := projectM["cost_classify"].(string)
  10127. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10128. err_log := models.ExportErrLog{
  10129. LogType: 6,
  10130. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10131. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10132. Status: 1,
  10133. CreateTime: time.Now().Unix(),
  10134. UpdateTime: time.Now().Unix(),
  10135. ExportTime: time.Now().Unix(),
  10136. }
  10137. service.CreateExportErrLog(&err_log)
  10138. continue
  10139. }
  10140. var costClassify = "费用类别"
  10141. var cost_classify_id int64
  10142. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10143. if len(cost_classify) != 0 {
  10144. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10145. if errcode == gorm.ErrRecordNotFound {
  10146. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10147. dataconfig := models.DictDataconfig{
  10148. ParentId: costClassifyConfig.ID,
  10149. Module: "system",
  10150. OrgId: orgId,
  10151. Name: cost_classify,
  10152. FieldName: "",
  10153. Value: costConfig.Value + 1,
  10154. CreatedTime: "",
  10155. UpdatedTime: "",
  10156. CreateUserId: adminUser.AdminUser.Id,
  10157. Status: 1,
  10158. Remark: "",
  10159. DeleteIdSystem: 0,
  10160. Title: "",
  10161. Content: "",
  10162. Order: 0,
  10163. Code: "",
  10164. }
  10165. service.CreatedDicConfig(&dataconfig)
  10166. }
  10167. }
  10168. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10169. for _, it := range costClassList {
  10170. if cost_classify == it.Name {
  10171. cost_classify_id = int64(it.Value)
  10172. }
  10173. }
  10174. project.CostClassify = cost_classify_id
  10175. executive_section := projectM["executive_section"].(string)
  10176. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10177. err_log := models.ExportErrLog{
  10178. LogType: 6,
  10179. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10180. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10181. Status: 1,
  10182. CreateTime: time.Now().Unix(),
  10183. UpdateTime: time.Now().Unix(),
  10184. ExportTime: time.Now().Unix(),
  10185. }
  10186. service.CreateExportErrLog(&err_log)
  10187. continue
  10188. }
  10189. if len(executive_section) != 0 {
  10190. //查找科室是否有内容
  10191. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10192. if errcodedepart == gorm.ErrRecordNotFound {
  10193. department := models.XtHisDepartment{
  10194. Name: executive_section,
  10195. Status: 1,
  10196. UserOrgId: adminUser.CurrentOrgId,
  10197. CreatedTime: time.Now().Unix(),
  10198. }
  10199. service.CreateDePartment(&department)
  10200. }
  10201. }
  10202. var executive_section_id int64
  10203. departMentList, _ := service.GetAllDepartMent(orgId)
  10204. for _, it := range departMentList {
  10205. if executive_section == it.Name {
  10206. executive_section_id = it.ID
  10207. }
  10208. }
  10209. project.ExecutiveSection = executive_section_id
  10210. medical_coverage := projectM["medical_coverage"].(string)
  10211. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10212. err_log := models.ExportErrLog{
  10213. LogType: 6,
  10214. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10215. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10216. Status: 1,
  10217. CreateTime: time.Now().Unix(),
  10218. UpdateTime: time.Now().Unix(),
  10219. ExportTime: time.Now().Unix(),
  10220. }
  10221. service.CreateExportErrLog(&err_log)
  10222. continue
  10223. }
  10224. var medicalCoverage = "医保等级"
  10225. var medical_coverage_id int64
  10226. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10227. if len(medical_coverage) != 0 {
  10228. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10229. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10230. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10231. dataconfig := models.DictDataconfig{
  10232. ParentId: medicalCoverageConfig.ID,
  10233. Module: "system",
  10234. OrgId: orgId,
  10235. Name: medical_coverage,
  10236. FieldName: "",
  10237. Value: medicalCoverageConfig.Value + 1,
  10238. CreatedTime: "",
  10239. UpdatedTime: "",
  10240. CreateUserId: adminUser.AdminUser.Id,
  10241. Status: 1,
  10242. Remark: "",
  10243. DeleteIdSystem: 0,
  10244. Title: "",
  10245. Content: "",
  10246. Order: 0,
  10247. Code: "",
  10248. }
  10249. service.CreatedDicConfig(&dataconfig)
  10250. }
  10251. }
  10252. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10253. for _, it := range medicalCoverageList {
  10254. if medical_coverage == it.Name {
  10255. medical_coverage_id = int64(it.Value)
  10256. }
  10257. }
  10258. project.MedicalCoverage = medical_coverage_id
  10259. pinyin := projectM["pinyin"].(string)
  10260. project.Pinyin = pinyin
  10261. wubi := projectM["wubi"].(string)
  10262. project.Wubi = wubi
  10263. statistical_classification := projectM["statistical_classification"].(string)
  10264. var statisticalClassification = "统计分类"
  10265. var statistical_classification_id int64
  10266. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10267. if len(statistical_classification) != 0 {
  10268. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10269. if classificationerrcodes == gorm.ErrRecordNotFound {
  10270. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10271. dataconfig := models.DictDataconfig{
  10272. ParentId: classiFication.ID,
  10273. Module: "system",
  10274. OrgId: orgId,
  10275. Name: statistical_classification,
  10276. FieldName: "",
  10277. Value: classiFicationConfig.Value + 1,
  10278. CreatedTime: "",
  10279. UpdatedTime: "",
  10280. CreateUserId: adminUser.AdminUser.Id,
  10281. Status: 1,
  10282. Remark: "",
  10283. DeleteIdSystem: 0,
  10284. Title: "",
  10285. Content: "",
  10286. Order: 0,
  10287. Code: "",
  10288. }
  10289. service.CreatedDicConfig(&dataconfig)
  10290. }
  10291. }
  10292. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10293. for _, it := range classiFicationList {
  10294. if statistical_classification == it.Name {
  10295. statistical_classification_id = int64(it.Value)
  10296. }
  10297. }
  10298. project.StatisticalClassification = statistical_classification_id
  10299. disease_directory := int64(projectM["disease_directory"].(float64))
  10300. project.DiseaseDirectory = disease_directory
  10301. is_record := int64(projectM["is_record"].(float64))
  10302. project.IsRecord = is_record
  10303. medical_code := projectM["medical_code"].(string)
  10304. project.MedicalCode = medical_code
  10305. tube_color := projectM["tube_color"].(string)
  10306. var tubeColor = "试管颜色"
  10307. var tube_color_id int64
  10308. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10309. if len(tube_color) != 0 {
  10310. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10311. if errcodetube == gorm.ErrRecordNotFound {
  10312. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10313. dataconfig := models.DictDataconfig{
  10314. ParentId: tubeColorConfig.ID,
  10315. Module: "system",
  10316. OrgId: orgId,
  10317. Name: tube_color,
  10318. FieldName: "",
  10319. Value: tubeConfig.Value + 1,
  10320. CreatedTime: "",
  10321. UpdatedTime: "",
  10322. CreateUserId: adminUser.AdminUser.Id,
  10323. Status: 1,
  10324. Remark: "",
  10325. DeleteIdSystem: 0,
  10326. Title: "",
  10327. Content: "",
  10328. Order: 0,
  10329. Code: "",
  10330. }
  10331. service.CreatedDicConfig(&dataconfig)
  10332. }
  10333. }
  10334. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10335. for _, it := range tubeColorList {
  10336. if tube_color == it.Name {
  10337. tube_color_id = int64(it.Value)
  10338. }
  10339. }
  10340. project.TubeColor = tube_color_id
  10341. single_dose := projectM["single_dose"].(string)
  10342. project.SingleDose = single_dose
  10343. execution_frequency := projectM["execution_frequency"].(string)
  10344. project.ExecutionFrequency = execution_frequency
  10345. delivery_way := projectM["delivery_way"].(string)
  10346. project.DeliveryWay = delivery_way
  10347. number_days := projectM["number_days"].(string)
  10348. project.NumberDays = number_days
  10349. total := projectM["total"].(string)
  10350. project.Total = total
  10351. medical_status := int64(projectM["medical_status"].(float64))
  10352. project.MedicalStatus = medical_status
  10353. category := int64(projectM["category"].(float64))
  10354. project.Category = category
  10355. specail_project := int64(projectM["specail_project"].(float64))
  10356. project.SpecailProject = specail_project
  10357. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10358. project.SocialSecurityDirectoryCode = social_security_directory_code
  10359. remark := projectM["remark"].(string)
  10360. project.Remark = remark
  10361. record_date := projectM["record_date"].(string)
  10362. timeLayout := "2006-01-02"
  10363. loc, _ := time.LoadLocation("Local")
  10364. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10365. project.RecordDate = theTime.Unix()
  10366. projectList = append(projectList, &project)
  10367. }
  10368. export_time := time.Now().Unix()
  10369. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10370. if len(projectList) > 0 {
  10371. for _, item := range projectList {
  10372. hans := item.ProjectName // 要转换的汉字字符串
  10373. // 创建一个拼音转换器
  10374. p := pinyin.NewArgs()
  10375. // 将汉字转为拼音
  10376. pinyinSlice := pinyin.Pinyin(hans, p)
  10377. // 输出拼音
  10378. fmt.Println("Pinyin:", pinyinSlice)
  10379. // 获取首字母
  10380. firstLetter := ""
  10381. for _, py := range pinyinSlice {
  10382. if len(py) > 0 {
  10383. firstLetter += string(py[0][0])
  10384. }
  10385. }
  10386. item.FirstLetter = firstLetter
  10387. project := models.HisProject{
  10388. ProjectName: item.ProjectName,
  10389. Price: item.Price,
  10390. Unit: item.Unit,
  10391. CostClassify: item.CostClassify,
  10392. ExecutiveSection: item.ExecutiveSection,
  10393. MedicalCoverage: item.MedicalCoverage,
  10394. UserOrgId: orgId,
  10395. Status: 1,
  10396. CreatedTime: time.Now().Unix(),
  10397. Pinyin: item.Pinyin,
  10398. Wubi: item.Wubi,
  10399. StatisticalClassification: item.StatisticalClassification,
  10400. DiseaseDirectory: item.DiseaseDirectory,
  10401. IsRecord: item.IsRecord,
  10402. MedicalCode: item.MedicalCode,
  10403. TubeColor: item.TubeColor,
  10404. SingleDose: item.SingleDose,
  10405. DeliveryWay: item.DeliveryWay,
  10406. NumberDays: item.NumberDays,
  10407. Total: item.Total,
  10408. Category: item.Category,
  10409. MedicalStatus: item.MedicalStatus,
  10410. SpecailProject: item.SpecailProject,
  10411. RecordDate: item.RecordDate,
  10412. Remark: item.Remark,
  10413. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10414. ExecutionFrequency: item.ExecutionFrequency,
  10415. FirstLetter: item.FirstLetter,
  10416. }
  10417. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10418. if errcodeproject == gorm.ErrRecordNotFound {
  10419. service.CreateProjectInfomation(&project)
  10420. } else if errcodeproject == nil {
  10421. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10422. }
  10423. log := models.ExportLog{
  10424. LogType: 6,
  10425. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10426. TotalNum: int64(len(total_goods)),
  10427. FailNum: int64(len(errLogs)),
  10428. SuccessNum: int64(len(projectList)),
  10429. CreateTime: time.Now().Unix(),
  10430. UpdateTime: time.Now().Unix(),
  10431. ExportTime: export_time,
  10432. Status: 1,
  10433. }
  10434. service.CreateExportLog(&log)
  10435. c.ServeSuccessJSON(map[string]interface{}{
  10436. "msg": "导入成功",
  10437. "total_num": len(total_goods),
  10438. "success_num": len(projectList),
  10439. "fail_num": int64(len(errLogs)),
  10440. })
  10441. }
  10442. } else {
  10443. log := models.ExportLog{
  10444. LogType: 6,
  10445. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10446. TotalNum: int64(len(total_goods)),
  10447. FailNum: int64(len(errLogs)),
  10448. SuccessNum: int64(len(projectList)),
  10449. CreateTime: time.Now().Unix(),
  10450. UpdateTime: time.Now().Unix(),
  10451. ExportTime: export_time,
  10452. Status: 1,
  10453. }
  10454. service.CreateExportLog(&log)
  10455. c.ServeSuccessJSON(map[string]interface{}{
  10456. "msg": "导入成功",
  10457. "total_num": len(total_goods),
  10458. "success_num": len(projectList),
  10459. "fail_num": int64(len(errLogs)),
  10460. })
  10461. }
  10462. }
  10463. //func (this *HisApiController) EditProjectInformation(){
  10464. //
  10465. // id, _ := this.GetInt64("id")
  10466. // project_team := this.GetString("project_team")
  10467. // price := this.GetString("price")
  10468. // price_float, _ := strconv.ParseFloat(price, 64)
  10469. // pinyin := this.GetString("pinyin")
  10470. // wubi := this.GetString("wubi")
  10471. // tube_color, _ := this.GetInt64("tube_color")
  10472. // team_type, _ := this.GetInt64("team_type")
  10473. // remark := this.GetString("remark")
  10474. // ids := this.GetString("ids")
  10475. // item_id := this.GetString("item_id")
  10476. // projectTeam := models.XtHisProjectTeam{
  10477. // ProjectTeam: project_team,
  10478. // Price: price_float,
  10479. // Pinyin: pinyin,
  10480. // Wubi: wubi,
  10481. // TubeColor: tube_color,
  10482. // TeamType: team_type,
  10483. // Remark: remark,
  10484. // ProjectId: ids,
  10485. // ItemId: item_id,
  10486. // }
  10487. //
  10488. //
  10489. // dataBody := make(map[string]interface{}, 0)
  10490. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10491. // if err != nil {
  10492. // utils.ErrorLog(err.Error())
  10493. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10494. // return
  10495. // }
  10496. //
  10497. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10498. //
  10499. //
  10500. // if err != nil {
  10501. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10502. // return
  10503. // }
  10504. //
  10505. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10506. // infos, _ := dataBody["info"].([]interface{})
  10507. // if len(infos) > 0 {
  10508. // var ids []string
  10509. //
  10510. // for _, item := range infos {
  10511. // items := item.(map[string]interface{})
  10512. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10513. // utils.ErrorLog("id")
  10514. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10515. // return
  10516. // }
  10517. // id := int64(items["id"].(float64))
  10518. //
  10519. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10520. // utils.ErrorLog("type")
  10521. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10522. // return
  10523. // }
  10524. // types := int64(items["type"].(float64))
  10525. //
  10526. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10527. // utils.ErrorLog("number")
  10528. // }
  10529. //
  10530. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10531. //
  10532. // projectList := models.XtHisProjectList{
  10533. // Number: number,
  10534. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10535. // ProjectId: id,
  10536. // Status: 1,
  10537. // CreatedTime: time.Now().Unix(),
  10538. // UpdatedTime: time.Now().Unix(),
  10539. // TeamId: projectTeam.ID,
  10540. // Type: types,
  10541. // }
  10542. // list := projectList
  10543. //
  10544. // service.CreateProjectList(&list)
  10545. //
  10546. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10547. //
  10548. // }
  10549. // ids_str := strings.Join(ids, ",")
  10550. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10551. // service.SaveProjectTeam(&projectTeam)
  10552. // this.ServeSuccessJSON(map[string]interface{}{
  10553. // "projectTeam": projectTeam,
  10554. // })
  10555. // }
  10556. // }
  10557. //}
  10558. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10559. name := c.GetString("name")
  10560. mode_id, _ := c.GetInt64("mode", 0)
  10561. types, _ := c.GetInt64("type", 0)
  10562. patient_id, _ := c.GetInt64("patient_id", 0)
  10563. types = 1
  10564. adminInfo := c.GetAdminUserInfo()
  10565. template := &models.HisPrescriptionTemplate{
  10566. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10567. PatientId: patient_id,
  10568. Type: types,
  10569. Status: 1,
  10570. Ctime: time.Now().Unix(),
  10571. Mtime: time.Now().Unix(),
  10572. Name: name,
  10573. Mode: mode_id,
  10574. }
  10575. dataBody := make(map[string]interface{}, 0)
  10576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10577. if err != nil {
  10578. utils.ErrorLog(err.Error())
  10579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10580. return
  10581. }
  10582. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10583. //如果已经存在记录则删除处方
  10584. if template_one.ID > 0 {
  10585. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10586. var ids []int64
  10587. var org_id int64
  10588. for _, item := range ps {
  10589. org_id = c.GetAdminUserInfo().CurrentOrgId
  10590. ids = append(ids, item.ID)
  10591. }
  10592. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10593. if err2 == nil {
  10594. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10595. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10596. if len(prescriptions) > 0 {
  10597. for _, item := range prescriptions {
  10598. items := item.(map[string]interface{})
  10599. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10600. utils.ErrorLog("type")
  10601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10602. return
  10603. }
  10604. types := int64(items["type"].(float64))
  10605. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10606. utils.ErrorLog("med_type")
  10607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10608. return
  10609. }
  10610. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10611. ctime := time.Now().Unix()
  10612. prescription := &models.HisPrescriptionInfoTemplate{
  10613. PatientId: patient_id,
  10614. UserOrgId: adminInfo.CurrentOrgId,
  10615. Ctime: ctime,
  10616. Mtime: ctime,
  10617. Type: types,
  10618. Modifier: adminInfo.AdminUser.Id,
  10619. Creator: adminInfo.AdminUser.Id,
  10620. Status: 1,
  10621. PTemplateId: template_one.ID,
  10622. MedType: med_type,
  10623. }
  10624. service.CreateHisPrescriptionInfoTemplate(prescription)
  10625. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10626. advices := items["advices"].([]interface{})
  10627. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10628. ctime := time.Now().Unix()
  10629. mtime := ctime
  10630. if len(advices) > 0 {
  10631. for _, advice := range advices {
  10632. var s models.HisPrescriptionAdviceTemplate
  10633. s.PrescriptionId = prescription.ID
  10634. s.AdviceType = 2
  10635. s.StopState = 2
  10636. s.ExecutionState = 2
  10637. s.Status = 1
  10638. s.UserOrgId = adminInfo.CurrentOrgId
  10639. s.CreatedTime = ctime
  10640. s.UpdatedTime = mtime
  10641. s.PatientId = patient_id
  10642. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10643. if errcode > 0 {
  10644. c.ServeFailJSONWithSGJErrorCode(errcode)
  10645. return
  10646. }
  10647. service.CreateHisPrescriptionAdviceTemplate(&s)
  10648. }
  10649. }
  10650. }
  10651. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10652. projects := items["project"].([]interface{})
  10653. if len(projects) > 0 {
  10654. for _, project := range projects {
  10655. var p models.HisPrescriptionProjectTemplate
  10656. p.PrescriptionId = prescription.ID
  10657. p.Ctime = time.Now().Unix()
  10658. p.Mtime = time.Now().Unix()
  10659. p.PatientId = patient_id
  10660. p.UserOrgId = adminInfo.CurrentOrgId
  10661. p.Status = 1
  10662. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10663. if errcode > 0 {
  10664. c.ServeFailJSONWithSGJErrorCode(errcode)
  10665. return
  10666. }
  10667. service.CreateHisPrescriptionProjectTemplate(&p)
  10668. }
  10669. }
  10670. }
  10671. }
  10672. c.ServeSuccessJSON(map[string]interface{}{
  10673. "msg": "创建成功",
  10674. })
  10675. }
  10676. }
  10677. } else {
  10678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10679. return
  10680. }
  10681. } else {
  10682. err3 := service.CreateHisPrescriptionTemplate(template)
  10683. if err3 == nil {
  10684. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10685. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10686. if len(prescriptions) > 0 {
  10687. for _, item := range prescriptions {
  10688. items := item.(map[string]interface{})
  10689. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10690. utils.ErrorLog("type")
  10691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10692. return
  10693. }
  10694. types := int64(items["type"].(float64))
  10695. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10696. utils.ErrorLog("med_type")
  10697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10698. return
  10699. }
  10700. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10701. ctime := time.Now().Unix()
  10702. prescription := &models.HisPrescriptionInfoTemplate{
  10703. PatientId: patient_id,
  10704. UserOrgId: adminInfo.CurrentOrgId,
  10705. Ctime: ctime,
  10706. Mtime: ctime,
  10707. Type: types,
  10708. Modifier: adminInfo.AdminUser.Id,
  10709. Creator: adminInfo.AdminUser.Id,
  10710. Status: 1,
  10711. PTemplateId: template.ID,
  10712. MedType: med_type,
  10713. }
  10714. service.CreateHisPrescriptionInfoTemplate(prescription)
  10715. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10716. advices := items["advices"].([]interface{})
  10717. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10718. ctime := time.Now().Unix()
  10719. mtime := ctime
  10720. if len(advices) > 0 {
  10721. for _, advice := range advices {
  10722. var s models.HisPrescriptionAdviceTemplate
  10723. s.PrescriptionId = prescription.ID
  10724. s.AdviceType = 2
  10725. s.StopState = 2
  10726. s.ExecutionState = 2
  10727. s.Status = 1
  10728. s.UserOrgId = adminInfo.CurrentOrgId
  10729. s.CreatedTime = ctime
  10730. s.UpdatedTime = mtime
  10731. s.PatientId = patient_id
  10732. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10733. if errcode > 0 {
  10734. c.ServeFailJSONWithSGJErrorCode(errcode)
  10735. return
  10736. }
  10737. service.CreateHisPrescriptionAdviceTemplate(&s)
  10738. }
  10739. }
  10740. }
  10741. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10742. projects := items["project"].([]interface{})
  10743. if len(projects) > 0 {
  10744. for _, project := range projects {
  10745. var p models.HisPrescriptionProjectTemplate
  10746. p.PrescriptionId = prescription.ID
  10747. p.Ctime = time.Now().Unix()
  10748. p.Mtime = time.Now().Unix()
  10749. p.PatientId = patient_id
  10750. p.UserOrgId = adminInfo.CurrentOrgId
  10751. p.Status = 1
  10752. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10753. if errcode > 0 {
  10754. c.ServeFailJSONWithSGJErrorCode(errcode)
  10755. return
  10756. }
  10757. service.CreateHisPrescriptionProjectTemplate(&p)
  10758. }
  10759. }
  10760. }
  10761. }
  10762. c.ServeSuccessJSON(map[string]interface{}{
  10763. "msg": "创建成功",
  10764. })
  10765. }
  10766. }
  10767. } else {
  10768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10769. return
  10770. }
  10771. }
  10772. }
  10773. func (c *HisApiController) PreSettle() {
  10774. id, _ := c.GetInt64("id")
  10775. record_time := c.GetString("record_time")
  10776. his_patient_id, _ := c.GetInt64("his_patient_id")
  10777. timeLayout := "2006-01-02"
  10778. loc, _ := time.LoadLocation("Local")
  10779. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10780. diagnosis_id := c.GetString("diagnosis")
  10781. sick_type, _ := c.GetInt64("sick_type")
  10782. reg_type, _ := c.GetInt64("p_type")
  10783. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10784. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10785. if err != nil {
  10786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10787. return
  10788. }
  10789. recordDateTime := theTime.Unix()
  10790. adminUser := c.GetAdminUserInfo()
  10791. var prescriptions []*models.HisPrescription
  10792. var start_time int64
  10793. var end_time int64
  10794. ids_str := c.GetString("ids")
  10795. ids_arr := strings.Split(ids_str, ",")
  10796. fmt.Println(reg_type)
  10797. if settle_accounts_type == 1 { //日结
  10798. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10799. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10800. } else {
  10801. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10802. }
  10803. fmt.Println(prescriptions)
  10804. } else { //月结
  10805. start_time_str := c.GetString("start_time")
  10806. end_time_str := c.GetString("end_time")
  10807. timeLayout := "2006-01-02"
  10808. loc, _ := time.LoadLocation("Local")
  10809. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10810. if err != nil {
  10811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10812. return
  10813. }
  10814. recordStartTime := theStartTime.Unix()
  10815. start_time = recordStartTime
  10816. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10817. if err != nil {
  10818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10819. return
  10820. }
  10821. recordEndTime := theEndTime.Unix()
  10822. end_time = recordEndTime
  10823. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10824. }
  10825. if reg_type == 1111 || reg_type == 1112 {
  10826. reg_type = 11
  10827. }
  10828. timestamp := time.Now().Unix()
  10829. tempTime := time.Unix(timestamp, 0)
  10830. timeFormat := tempTime.Format("20060102150405")
  10831. chrgBchno := rand.Intn(100000) + 10000
  10832. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10833. strconv.FormatInt(his.PatientId, 10)
  10834. var ids []int64
  10835. for _, item := range prescriptions {
  10836. ids = append(ids, item.ID)
  10837. }
  10838. fmt.Println(ids)
  10839. var total float64
  10840. for _, item := range prescriptions {
  10841. fmt.Println(item)
  10842. if item.Type == 1 { //药品
  10843. for _, subItem := range item.HisDoctorAdviceInfo {
  10844. total = total + (subItem.Price * subItem.PrescribingNumber)
  10845. }
  10846. }
  10847. if item.Type == 2 { //项目
  10848. for _, subItem := range item.HisPrescriptionProject {
  10849. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10850. total = total + (subItem.Price * cnt)
  10851. }
  10852. }
  10853. for _, subItem := range item.HisAdditionalCharge {
  10854. total = total + (subItem.Price * float64(subItem.Count))
  10855. }
  10856. }
  10857. allTotal := fmt.Sprintf("%.2f", total)
  10858. totals, _ := strconv.ParseFloat(allTotal, 64)
  10859. order := &models.HisOrder{
  10860. UserOrgId: adminUser.CurrentOrgId,
  10861. HisPatientId: his.ID,
  10862. PatientId: id,
  10863. SettleAccountsDate: recordDateTime,
  10864. Ctime: time.Now().Unix(),
  10865. Mtime: time.Now().Unix(),
  10866. Status: 1,
  10867. OrderStatus: 1,
  10868. MdtrtId: his.Number,
  10869. Number: chrg_bchno,
  10870. MedfeeSumamt: totals,
  10871. SettleEndTime: end_time,
  10872. SettleStartTime: start_time,
  10873. SettleType: settle_accounts_type,
  10874. PsnPartAmt: totals,
  10875. PsnCashPay: totals,
  10876. PType: 2,
  10877. IsPre: 1,
  10878. MedType: strconv.Itoa(int(reg_type)),
  10879. Diagnosis: diagnosis_id,
  10880. }
  10881. err = service.CreateOrder(order)
  10882. if err != nil {
  10883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10884. return
  10885. }
  10886. var customs []*Custom
  10887. for _, item := range prescriptions {
  10888. fmt.Println(item.Type)
  10889. if item.Type == 1 { //药品
  10890. for _, subItem := range item.HisDoctorAdviceInfo {
  10891. cus := &Custom{
  10892. AdviceId: subItem.ID,
  10893. ProjectId: 0,
  10894. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10895. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10896. FeedetlSn: subItem.FeedetlSn,
  10897. Price: fmt.Sprintf("%.2f", subItem.Price),
  10898. MedListCodg: subItem.MedListCodg,
  10899. Type: 1,
  10900. }
  10901. customs = append(customs, cus)
  10902. }
  10903. }
  10904. if item.Type == 2 { //项目
  10905. for _, subItem := range item.HisPrescriptionProject {
  10906. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10907. cus := &Custom{
  10908. AdviceId: 0,
  10909. ProjectId: subItem.ID,
  10910. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10911. Cut: fmt.Sprintf("%.2f", cnt),
  10912. FeedetlSn: subItem.FeedetlSn,
  10913. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10914. MedListCodg: subItem.MedListCodg,
  10915. Type: 2,
  10916. }
  10917. customs = append(customs, cus)
  10918. }
  10919. }
  10920. for _, item := range item.HisAdditionalCharge {
  10921. cus := &Custom{
  10922. ItemId: item.ID,
  10923. AdviceId: 0,
  10924. ProjectId: 0,
  10925. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10926. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10927. FeedetlSn: item.FeedetlSn,
  10928. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10929. MedListCodg: item.XtHisAddtionConfig.Code,
  10930. Type: 3,
  10931. }
  10932. customs = append(customs, cus)
  10933. }
  10934. }
  10935. fmt.Println(customs)
  10936. for _, item := range customs {
  10937. var advice_id int64 = 0
  10938. var project_id int64 = 0
  10939. var item_id int64 = 0
  10940. var types int64 = 0
  10941. if item.Type == 1 {
  10942. advice_id = item.AdviceId
  10943. project_id = 0
  10944. item_id = 0
  10945. } else if item.Type == 2 {
  10946. advice_id = 0
  10947. item_id = 0
  10948. project_id = item.ProjectId
  10949. } else if item.Type == 3 {
  10950. advice_id = 0
  10951. item_id = item.ItemId
  10952. project_id = 0
  10953. }
  10954. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10955. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10956. pric, _ := strconv.ParseFloat(item.Price, 32)
  10957. info := &models.HisOrderInfo{
  10958. OrderNumber: order.Number,
  10959. UploadDate: time.Now().Unix(),
  10960. AdviceId: advice_id,
  10961. DetItemFeeSumamt: detItemFeeSumamt,
  10962. Cnt: cut,
  10963. Pric: pric,
  10964. PatientId: id,
  10965. Status: 1,
  10966. Mtime: time.Now().Unix(),
  10967. Ctime: time.Now().Unix(),
  10968. UserOrgId: adminUser.CurrentOrgId,
  10969. HisPatientId: his.ID,
  10970. OrderId: order.ID,
  10971. ProjectId: project_id,
  10972. Type: types,
  10973. ItemId: item_id,
  10974. }
  10975. service.CreateOrderInfo(info)
  10976. }
  10977. his.SickType = sick_type
  10978. service.UpdataHisPateint(&his)
  10979. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10980. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10981. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10982. if err == nil {
  10983. c.ServeSuccessJSON(map[string]interface{}{
  10984. "msg": "结算成功",
  10985. })
  10986. }
  10987. }
  10988. type CustomOrderInfo struct {
  10989. Name string
  10990. Spec string
  10991. Unit string
  10992. Count float64
  10993. Price float64
  10994. Total float64
  10995. }
  10996. func (c *HisApiController) GetPrivateExpensesInfo() {
  10997. order_id, _ := c.GetInt64("id", 0)
  10998. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10999. order, _ := service.GetHisOrderByID(order_id)
  11000. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11001. if order.ID == 0 {
  11002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11003. return
  11004. }
  11005. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11006. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11007. org_id := c.GetAdminUserInfo().CurrentOrgId
  11008. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11009. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11010. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11011. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11012. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11013. //var orderInfos_four []*models.HisOrderInfoTwo
  11014. //for _, item := range orderInfos_three {
  11015. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11016. // item.HisPrescriptionProject.IsCheckTeam = 1
  11017. // orderInfos_four = append(orderInfos_four, item)
  11018. //
  11019. // }
  11020. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11021. // item.HisPrescriptionProject.IsCheckTeam = 2
  11022. // orderInfos_two = append(orderInfos_two, item)
  11023. // }
  11024. //}
  11025. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11026. //var cus_slice []CustomOrderInfo
  11027. //for _, item := range new_order_info {
  11028. // var cus CustomOrderInfo
  11029. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11030. // cus.Unit = ""
  11031. // cus.Spec = ""
  11032. // var total float64
  11033. // for _, subItem := range orderInfos_four {
  11034. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11035. // total = total + subItem.DetItemFeeSumamt
  11036. // fmt.Println(subItem.DetItemFeeSumamt)
  11037. // }
  11038. // }
  11039. // cus.Count = 1
  11040. // cus.Total = total
  11041. // cus_slice = append(cus_slice, cus)
  11042. //}
  11043. orderInfos = append(orderInfos, orderInfos_two...)
  11044. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11045. //orderInfos = append(orderInfos, orderInfos_three...)
  11046. //}/**/
  11047. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11048. c.ServeSuccessJSON(map[string]interface{}{
  11049. "order": order,
  11050. "order_info": orderInfos,
  11051. "patient": patient,
  11052. "admin_info": adminInfo,
  11053. "his": his,
  11054. "current_admin": role,
  11055. "org_config": miConfig,
  11056. //"new_order_info": cus_slice,
  11057. })
  11058. }
  11059. func (this *HisApiController) ChangeMedType() {
  11060. med_type := this.GetString("med_type")
  11061. old_med_type := this.GetString("old_med_type")
  11062. ids := this.GetString("ids")
  11063. settle_type, _ := this.GetInt64("settle_type")
  11064. start_time := this.GetString("start_time")
  11065. end_time := this.GetString("end_time")
  11066. ids_arr := strings.Split(ids, ",")
  11067. if settle_type == 1 { //日结
  11068. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11069. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11070. prescription.MedType = med_type
  11071. err := service.SaveHisPrescriptionTwo(&prescription)
  11072. if err == nil {
  11073. this.ServeSuccessJSON(map[string]interface{}{
  11074. "msg": "修改成功",
  11075. })
  11076. } else {
  11077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11078. return
  11079. }
  11080. } else if settle_type == 2 {
  11081. timeLayout := "2006-01-02"
  11082. loc, _ := time.LoadLocation("Local")
  11083. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11084. if err != nil {
  11085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11086. return
  11087. }
  11088. recordStartTime := theStartTime.Unix()
  11089. start_time_timestamp := recordStartTime
  11090. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11091. if err != nil {
  11092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11093. return
  11094. }
  11095. recordEndTime := theEndTime.Unix()
  11096. end_time_timestamp := recordEndTime
  11097. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11098. if updateErr == nil {
  11099. this.ServeSuccessJSON(map[string]interface{}{
  11100. "msg": "修改成功",
  11101. })
  11102. } else {
  11103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11104. return
  11105. }
  11106. }
  11107. }
  11108. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11109. patient_id, _ := c.GetInt64("patient_id")
  11110. his_patient_id, _ := c.GetInt64("his_patient_id")
  11111. record_date := c.GetString("record_date")
  11112. start_time := c.GetString("start_time")
  11113. end_time := c.GetString("end_time")
  11114. order_status, _ := c.GetInt64("type", 0)
  11115. p_type, _ := c.GetInt64("p_type", 0)
  11116. order_id, _ := c.GetInt64("order_id", 0)
  11117. timeLayout := "2006-01-02"
  11118. loc, _ := time.LoadLocation("Local")
  11119. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11120. if err != nil {
  11121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11122. return
  11123. }
  11124. recordDateTime := theTime.Unix()
  11125. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11126. if err != nil {
  11127. }
  11128. startRecordDateTime := startTime.Unix()
  11129. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11130. if err != nil {
  11131. }
  11132. endRecordDateTime := endTime.Unix()
  11133. admin := c.GetAdminUserInfo()
  11134. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11135. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11136. order, _ := service.GetHisOrderByID(order_id)
  11137. var monthPrescriptions []*models.HisPrescription
  11138. if order_status == 1 || order_status == 0 {
  11139. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11140. } else if order_status == 2 {
  11141. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11142. }
  11143. var settle_total float64
  11144. for _, item := range monthPrescriptions {
  11145. if len(item.HisPrescriptionProject) > 0 {
  11146. for _, subItem := range item.HisPrescriptionProject {
  11147. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11148. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11149. settle_total = settle_total + total
  11150. }
  11151. }
  11152. if len(item.HisDoctorAdviceInfo) > 0 {
  11153. for _, subItem := range item.HisDoctorAdviceInfo {
  11154. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11155. settle_total = settle_total + total
  11156. }
  11157. }
  11158. }
  11159. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11160. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11161. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11162. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11163. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11164. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11165. //获取所有科室信息
  11166. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11167. var dia string
  11168. for _, item := range month_p_info {
  11169. if len(dia) == 0 {
  11170. dia = item.Diagnosis
  11171. } else {
  11172. dia = dia + "," + item.Diagnosis
  11173. }
  11174. }
  11175. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11176. dia_arr = removeEmptyStrings(dia_arr)
  11177. c.ServeSuccessJSON(map[string]interface{}{
  11178. "his_info": his_patient_info,
  11179. "xt_info": xt_patient_info,
  11180. "case_history": case_history,
  11181. "info": patientPrescriptionInfo,
  11182. "last_info": lastPatientPrescriptionInfo,
  11183. "month_prescriptions": monthPrescriptions,
  11184. "order": order,
  11185. "doctors": doctors,
  11186. "department": department,
  11187. "settle_total": settle_total,
  11188. "dia_arr": dia_arr,
  11189. })
  11190. return
  11191. }
  11192. func removeEmptyStrings(input []string) []string {
  11193. var output []string
  11194. for _, s := range input {
  11195. if s != "" {
  11196. output = append(output, s)
  11197. }
  11198. }
  11199. return output
  11200. }
  11201. func removeDuplicates(input []string) []string {
  11202. seen := make(map[string]bool)
  11203. output := []string{}
  11204. for _, s := range input {
  11205. if _, exists := seen[s]; !exists {
  11206. seen[s] = true
  11207. output = append(output, s)
  11208. }
  11209. }
  11210. return output
  11211. }
  11212. func (c *HisApiController) GetHisMonthPatientInfo() {
  11213. patient_id, _ := c.GetInt64("patient_id")
  11214. his_patient_id, _ := c.GetInt64("his_patient_id")
  11215. record_date := c.GetString("record_date")
  11216. number := c.GetString("number")
  11217. start_time := c.GetString("start_time")
  11218. end_time := c.GetString("end_time")
  11219. p_type, _ := c.GetInt64("p_type")
  11220. timeLayout := "2006-01-02"
  11221. loc, _ := time.LoadLocation("Local")
  11222. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11223. if err != nil {
  11224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11225. return
  11226. }
  11227. recordDateTime := theTime.Unix()
  11228. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11229. if err != nil {
  11230. }
  11231. startRecordDateTime := startTime.Unix()
  11232. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11233. if err != nil {
  11234. }
  11235. endRecordDateTime := endTime.Unix()
  11236. admin := c.GetAdminUserInfo()
  11237. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11238. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11239. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11240. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11241. var settle_total float64
  11242. for _, item := range monthPrescriptions {
  11243. if len(item.HisPrescriptionProject) > 0 {
  11244. for _, subItem := range item.HisPrescriptionProject {
  11245. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11246. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11247. settle_total = settle_total + total
  11248. }
  11249. }
  11250. if len(item.HisDoctorAdviceInfo) > 0 {
  11251. for _, subItem := range item.HisDoctorAdviceInfo {
  11252. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11253. settle_total = settle_total + total
  11254. }
  11255. }
  11256. }
  11257. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11258. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11259. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11260. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11261. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11262. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11263. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11264. //获取所有科室信息
  11265. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11266. c.ServeSuccessJSON(map[string]interface{}{
  11267. "his_info": his_patient_info,
  11268. "xt_info": xt_patient_info,
  11269. "case_history": case_history,
  11270. "info": patientPrescriptionInfo,
  11271. "month_prescriptions": monthPrescriptions,
  11272. "order": order,
  11273. "doctors": doctors,
  11274. "department": department,
  11275. "count": count,
  11276. "drugStockConfig": drugStockConfig,
  11277. "last_info": lastPatientPrescriptionInfo,
  11278. "settle_total": settle_total,
  11279. })
  11280. return
  11281. }
  11282. func (c *HisApiController) GetAllOrder() {
  11283. org_id := c.GetAdminUserInfo().CurrentOrgId
  11284. orders, _ := service.GetNewHisOrderList(org_id)
  11285. c.ServeSuccessJSON(map[string]interface{}{
  11286. "order": orders,
  11287. })
  11288. return
  11289. }
  11290. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11291. newArr = make([]*models.HisOrderInfoTwo, 0)
  11292. for i := 0; i < len(arr); i++ {
  11293. repeat := false
  11294. for j := i + 1; j < len(arr); j++ {
  11295. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11296. repeat = true
  11297. break
  11298. }
  11299. }
  11300. if !repeat {
  11301. newArr = append(newArr, arr[i])
  11302. }
  11303. }
  11304. return
  11305. }
  11306. // 修改处方退库操作 参数传修改之前的处方数据
  11307. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11308. if advice.ExecutionState == 1 {
  11309. //查询该病人该药品是否有库存记录
  11310. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11311. if errcode == gorm.ErrRecordNotFound {
  11312. } else {
  11313. //退库
  11314. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11315. if advice.PrescribingNumberUnit == drug.MinUnit {
  11316. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11317. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11318. //退库
  11319. warehouseInfo := models.DrugWarehouseInfo{
  11320. StockMinNumber: prescribingNumber,
  11321. }
  11322. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  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.UserOrgId,
  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. } else {
  11406. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11407. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11408. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11409. warehouseInfo := models.DrugWarehouseInfo{
  11410. StockMinNumber: prescribingNumber,
  11411. }
  11412. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11413. }
  11414. operation_time := time.Now().Unix()
  11415. creater := advice.AdviceDoctor
  11416. ctime := time.Now().Unix()
  11417. timeStr := time.Now().Format("2006-01-02")
  11418. timeArr := strings.Split(timeStr, "-")
  11419. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11420. total = total + 1
  11421. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11422. cancelStock := models.DrugCancelStock{
  11423. OrderNumber: orderNumber,
  11424. OperaTime: operation_time,
  11425. OrgId: advice.UserOrgId,
  11426. Creater: creater,
  11427. Ctime: ctime,
  11428. Status: 1,
  11429. ReturnTime: advice.AdviceDate,
  11430. Dealer: info.Dealer,
  11431. Manufacturer: info.Manufacturer,
  11432. Type: 1,
  11433. }
  11434. service.AddSigleDrugCancelStock(&cancelStock)
  11435. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11436. dealer, _ := service.GetDealerById(info.Dealer)
  11437. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11438. cancelStockInfo := models.DrugCancelStockInfo{
  11439. OrderNumber: cancelInfo.OrderNumber,
  11440. CancelStockId: cancelInfo.ID,
  11441. DrugId: info.DrugId,
  11442. Count: info.Count,
  11443. Status: 1,
  11444. Ctime: ctime,
  11445. OrgId: advice.UserOrgId,
  11446. Type: 1,
  11447. Manufacturer: manufactureName.ManufacturerName,
  11448. Dealer: dealer.DealerName,
  11449. Total: 0,
  11450. RetailPrice: info.RetailPrice,
  11451. RetailTotalPrice: info.RetailTotalPrice,
  11452. Price: info.Price,
  11453. RegisterAccount: "",
  11454. Remark: info.Remark,
  11455. BatchNumber: info.BatchNumber,
  11456. MaxUnit: info.CountUnit,
  11457. ProductDate: info.ProductDate,
  11458. ExpiryDate: info.ExpiryDate,
  11459. BatchNumberId: info.WarehouseInfoId,
  11460. }
  11461. flow := models.DrugFlow{
  11462. WarehousingId: 0,
  11463. DrugId: info.DrugId,
  11464. Number: "",
  11465. BatchNumber: info.BatchNumber,
  11466. Count: info.Count,
  11467. UserOrgId: advice.UserOrgId,
  11468. PatientId: 0,
  11469. SystemTime: ctime,
  11470. ConsumableType: 4,
  11471. IsSys: 0,
  11472. WarehousingOrder: "",
  11473. WarehouseOutId: 0,
  11474. WarehouseOutOrderNumber: "",
  11475. IsEdit: 0,
  11476. CancelStockId: cancelStock.ID,
  11477. CancelOrderNumber: cancelStock.OrderNumber,
  11478. Manufacturer: info.Manufacturer,
  11479. Dealer: info.Dealer,
  11480. Creator: advice.AdviceDoctor,
  11481. UpdateCreator: 0,
  11482. Status: 1,
  11483. Ctime: time.Now().Unix(),
  11484. Mtime: 0,
  11485. Price: info.Price,
  11486. WarehousingDetailId: 0,
  11487. WarehouseOutDetailId: 0,
  11488. CancelOutDetailId: 0,
  11489. ExpireDate: info.ExpiryDate,
  11490. ProductDate: info.ProductDate,
  11491. MaxUnit: info.CountUnit,
  11492. MinUnit: "",
  11493. }
  11494. service.CreatedCancelStock(cancelStockInfo)
  11495. service.CreateDrugFlowOne(flow)
  11496. }
  11497. }
  11498. }
  11499. return err
  11500. }
  11501. func (this *HisApiController) DeleteNCDS() {
  11502. id, _ := this.GetInt64("id", 0)
  11503. if id > 0 {
  11504. service.DeletePsnNCDSRecordById(id)
  11505. this.ServeSuccessJSON(map[string]interface{}{
  11506. "msg": "删除成功",
  11507. })
  11508. } else {
  11509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11510. return
  11511. }
  11512. }
  11513. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11514. id, _ := c.GetInt64("id")
  11515. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11516. c.ServeSuccessJSON(map[string]interface{}{
  11517. "advice": advice,
  11518. })
  11519. return
  11520. }
  11521. func (c *HisApiController) GetHisMonthChargePatientList() {
  11522. record_date := c.GetString("record_date")
  11523. start_time := c.GetString("start_time")
  11524. end_time := c.GetString("end_time")
  11525. timeLayout := "2006-01-02"
  11526. loc, _ := time.LoadLocation("Local")
  11527. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11528. if err != nil {
  11529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11530. return
  11531. }
  11532. if err != nil {
  11533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11534. return
  11535. }
  11536. recordDateTime := theTime.Unix()
  11537. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11538. if err != nil {
  11539. }
  11540. startRecordDateTime := startTime.Unix()
  11541. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11542. if err != nil {
  11543. }
  11544. endRecordDateTime := endTime.Unix()
  11545. adminInfo := c.GetAdminUserInfo()
  11546. var tempMonthChargePatients []*service.MonthChargePatients
  11547. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11548. for _, item := range tempPatients {
  11549. //过滤没有处方的
  11550. if len(item.HisPrescription) == 0 {
  11551. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11552. }
  11553. }
  11554. c.ServeSuccessJSON(map[string]interface{}{
  11555. "list": tempMonthChargePatients,
  11556. })
  11557. }
  11558. // PrescriptionDifference 医嘱数量差值结构体
  11559. type PrescriptionDrugDifference struct {
  11560. DrugID int64 //基础库药品id
  11561. ID int64 //医嘱id
  11562. Difference float64 //差值
  11563. Unit string //单位
  11564. }
  11565. type PrescriptionGoodDifference struct {
  11566. GoodID int64 //基础库项目耗材id
  11567. ID int64 //医嘱id
  11568. Difference int64 //差值
  11569. Unit string //单位
  11570. Type int64 //类型
  11571. }
  11572. type EditCustomData struct {
  11573. adviceList []*models.HisDoctorAdviceInfo
  11574. projectList []*models.HisPrescriptionProject
  11575. }
  11576. type SrcCustomData struct {
  11577. adviceList []*models.HisDoctorAdviceInfo
  11578. projectList []*models.HisPrescriptionProject
  11579. }
  11580. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11581. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11582. differences := make([]*PrescriptionDrugDifference, 0)
  11583. // 创建一个 map 来存储第一个切片中的药品信息
  11584. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11585. for _, advice := range firstPrescription {
  11586. firstMap[advice.DrugId] = advice
  11587. }
  11588. // 遍历第二个切片中的药品信息,并比较数量差值
  11589. for _, advice := range secondPrescription {
  11590. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11591. diff := &PrescriptionDrugDifference{
  11592. DrugID: advice.DrugId,
  11593. ID: firstAdvice.ID,
  11594. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11595. Unit: firstAdvice.PrescribingNumberUnit,
  11596. }
  11597. differences = append(differences, diff)
  11598. }
  11599. }
  11600. return differences
  11601. }
  11602. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11603. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11604. differences := make([]*PrescriptionGoodDifference, 0)
  11605. // 创建一个 map 来存储第一个切片中的耗材信息
  11606. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11607. for _, good := range firstPrescription {
  11608. firstMap[good.ProjectId] = good
  11609. }
  11610. // 遍历第二个切片中的耗材信息,并比较数量差值
  11611. for _, good := range secondPrescription {
  11612. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11613. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11614. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11615. diff := &PrescriptionGoodDifference{
  11616. GoodID: good.ProjectId,
  11617. ID: firstGood.ID,
  11618. Difference: count - firstCount,
  11619. Unit: firstGood.Unit,
  11620. Type: firstGood.Type,
  11621. }
  11622. differences = append(differences, diff)
  11623. }
  11624. }
  11625. return differences
  11626. }
  11627. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11628. var adviceList []*models.HisDoctorAdviceInfo
  11629. var projectList []*models.HisPrescriptionProject
  11630. var advice_ids []int64
  11631. var project_ids []int64
  11632. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11633. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11634. //var tempPrescription *models.HisPrescriptionProjectscription
  11635. if len(prescriptions) > 0 {
  11636. for _, item := range prescriptions {
  11637. items := item.(map[string]interface{})
  11638. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11639. advices := items["advices"].([]interface{})
  11640. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11641. groupNo := int64(0)
  11642. ctime := time.Now().Unix()
  11643. mtime := ctime
  11644. if len(advices) > 0 {
  11645. for _, advice := range advices {
  11646. var s models.HisDoctorAdviceInfo
  11647. s.AdviceType = 2
  11648. s.StopState = 2
  11649. s.ExecutionState = 2
  11650. s.Status = 1
  11651. s.Groupno = groupNo
  11652. s.CreatedTime = ctime
  11653. s.UpdatedTime = mtime
  11654. s.IsSettle = 2
  11655. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11656. //存储切片中
  11657. if s.ID > 0 {
  11658. advice_ids = append(advice_ids, s.ID)
  11659. adviceList = append(adviceList, &s)
  11660. }
  11661. }
  11662. }
  11663. }
  11664. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11665. projects := items["project"].([]interface{})
  11666. if len(projects) > 0 {
  11667. for _, project := range projects {
  11668. var p models.HisPrescriptionProject
  11669. p.Ctime = time.Now().Unix()
  11670. p.Mtime = time.Now().Unix()
  11671. p.Status = 1
  11672. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11673. if p.ID > 0 {
  11674. project_ids = append(project_ids, p.ID)
  11675. projectList = append(projectList, &p)
  11676. }
  11677. }
  11678. }
  11679. }
  11680. }
  11681. }
  11682. }
  11683. editCustomData.projectList = projectList
  11684. editCustomData.adviceList = adviceList
  11685. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11686. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11687. srcCustomData.adviceList = list
  11688. srcCustomData.projectList = list2
  11689. return
  11690. }