his_api_controller.go 314KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. for _, item := range prescriptions {
  540. for _, subItem := range item.HisDoctorAdviceInfo {
  541. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  542. if info.RetailPrice > 0 {
  543. subItem.Drug.MinPrice = info.RetailPrice
  544. }
  545. }
  546. }
  547. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  548. } else { //门诊
  549. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  550. for _, item := range prescriptions {
  551. for _, subItem := range item.HisDoctorAdviceInfo {
  552. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  553. if info.RetailPrice > 0 {
  554. subItem.Drug.MinPrice = info.RetailPrice
  555. }
  556. }
  557. }
  558. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  559. }
  560. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  561. if sch.ID > 0 {
  562. var week string
  563. t := time.Now()
  564. switch t.Weekday().String() {
  565. case "Monday":
  566. week = "周一"
  567. break
  568. case "Tuesday":
  569. week = "周二"
  570. break
  571. case "Wednesday":
  572. week = "周三"
  573. break
  574. case "Thursday":
  575. week = "周四"
  576. break
  577. case "Friday":
  578. week = "周五"
  579. break
  580. case "Saturday":
  581. week = "周六"
  582. break
  583. case "Sunday":
  584. week = "周日"
  585. break
  586. }
  587. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  588. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  589. //根据推送频率组装新的数组
  590. for _, item := range temp_sch_prescriptions {
  591. var cus CustomTemplate
  592. cus.ID = item.ID
  593. cus.UserOrgId = item.UserOrgId
  594. cus.PatientId = item.PatientId
  595. cus.MedType = item.MedType
  596. cus.RecordDate = item.RecordDate
  597. cus.Type = item.Type
  598. cus.PType = item.PType
  599. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  600. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  601. if subItem.FrequencyType == 1 { //每次必推
  602. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  603. }
  604. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  605. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  606. }
  607. if subItem.FrequencyType == 2 { //按照天数频率
  608. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  609. now := p.Unix()
  610. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  611. dayStr2 := "-" + dayStr
  612. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  613. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  614. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  615. if len(advices) == 0 {
  616. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  617. }
  618. }
  619. }
  620. }
  621. for _, subItem := range item.HisPrescriptionProjectTemplate {
  622. if subItem.Type == 2 {
  623. if subItem.XtHisProject.MedicalStatus != 1 {
  624. if subItem.FrequencyType == 1 {
  625. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  626. }
  627. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  628. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  629. }
  630. if subItem.FrequencyType == 2 {
  631. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  632. now := p.Unix()
  633. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  634. dayStr2 := "-" + dayStr
  635. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  636. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  637. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  638. if len(projects) == 0 {
  639. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  640. }
  641. }
  642. }
  643. } else if subItem.Type == 3 {
  644. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  645. if subItem.FrequencyType == 1 {
  646. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  647. }
  648. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  649. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  650. }
  651. if subItem.FrequencyType == 2 {
  652. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  653. now := p.Unix()
  654. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  655. dayStr2 := "-" + dayStr
  656. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  657. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  658. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  659. if len(projects) == 0 {
  660. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  661. }
  662. }
  663. }
  664. }
  665. }
  666. sch_prescriptions = append(sch_prescriptions, cus)
  667. }
  668. for _, item := range sch_prescriptions {
  669. if len(item.HisPrescriptionProjectTemplate) == 0 {
  670. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  671. }
  672. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  673. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  674. }
  675. }
  676. }
  677. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  678. if config.ID > 0 && config.IsOpen == 1 {
  679. for _, item := range sch_prescriptions {
  680. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  681. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  682. if info.RetailPrice > 0 {
  683. subItem.Drug.MinPrice = info.RetailPrice
  684. }
  685. }
  686. }
  687. }
  688. if config.ID > 0 && config.IsOpen == 1 {
  689. for _, item := range sch_prescriptions {
  690. for _, subItem := range item.HisPrescriptionProjectTemplate {
  691. if subItem.Type == 3 {
  692. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  693. if info.Price > 0 {
  694. subItem.GoodInfo.PackingPrice = info.Price
  695. }
  696. }
  697. }
  698. }
  699. }
  700. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  701. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  702. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  703. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  704. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  705. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  706. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  707. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  708. //获取所有科室信息
  709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "his_info": his_patient_info,
  712. "xt_info": xt_patient_info,
  713. "prescription": prescriptions,
  714. "case_history": case_history,
  715. "info": patientPrescriptionInfo,
  716. //"month_prescriptions": monthPrescriptions,
  717. "order": order,
  718. "doctors": doctors,
  719. "department": department,
  720. "sch_prescriptions": sch_prescriptions,
  721. "last_prescriptions": last_prescriptions,
  722. "schedule": sch,
  723. "count": count,
  724. "drugStockConfig": drugStockConfig,
  725. "last_info": lastPatientPrescriptionInfo,
  726. })
  727. return
  728. }
  729. func (c *HisApiController) GetHisPrescriptionConfig() {
  730. adminInfo := c.GetAdminUserInfo()
  731. //获取医嘱模版
  732. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  733. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  734. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  735. //获取所有基础药
  736. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  737. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  738. if config.ID > 0 && config.IsOpen == 1 {
  739. for _, item := range drugs {
  740. var index = 0
  741. for _, subItem := range item.OtherDrugWarehouseInfo {
  742. if index == 0 {
  743. index = index + 1
  744. if subItem.RetailPrice > 0 {
  745. item.MinPrice = subItem.RetailPrice
  746. }
  747. }
  748. }
  749. }
  750. }
  751. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  752. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  753. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  754. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  755. //获取所有科室信息
  756. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  757. //获取诊断信息
  758. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  759. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  760. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  761. c.ServeSuccessJSON(map[string]interface{}{
  762. "drugs": drugs,
  763. "advices_template": advices,
  764. "drugways": drugways,
  765. "efs": efs,
  766. "doctors": doctors,
  767. "department": department,
  768. "sick": sick,
  769. "additions": additions,
  770. "diagnose": diagnose,
  771. "manufacturers": manufacturers,
  772. })
  773. }
  774. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  775. //获取所有基础药
  776. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  777. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  778. if config.ID > 0 && config.IsOpen == 1 {
  779. for _, item := range drugs {
  780. var index = 0
  781. for _, subItem := range item.OtherDrugWarehouseInfo {
  782. if index == 0 {
  783. index = index + 1
  784. if subItem.RetailPrice > 0 {
  785. item.MinPrice = subItem.RetailPrice
  786. }
  787. }
  788. }
  789. }
  790. }
  791. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  792. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  793. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  794. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  795. //获取所有科室信息
  796. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  797. //获取诊断信息
  798. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  799. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  800. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  801. c.ServeSuccessJSON(map[string]interface{}{
  802. "drugs": drugs,
  803. "advices_template": advices,
  804. "drugways": drugways,
  805. "efs": efs,
  806. "doctors": doctors,
  807. "department": department,
  808. "sick": sick,
  809. "additions": additions,
  810. "diagnose": diagnose,
  811. "manufacturers": manufacturers,
  812. })
  813. }
  814. }
  815. func (c *HisApiController) CreateHisPrescription() {
  816. record_date := c.GetString("record_date")
  817. patient_id, _ := c.GetInt64("patient_id")
  818. reg_type, _ := c.GetInt64("reg_type")
  819. diagnose := c.GetString("diagnose")
  820. sick_type, _ := c.GetInt64("sick_type")
  821. sick_history := c.GetString("sick_history")
  822. doctor_id, _ := c.GetInt64("doctor", 0)
  823. department, _ := c.GetInt64("department", 0)
  824. his_patient_id, _ := c.GetInt64("his_patient_id")
  825. p_type, _ := c.GetInt64("p_type")
  826. dataBody := make(map[string]interface{}, 0)
  827. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  828. if err != nil {
  829. utils.ErrorLog(err.Error())
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. adminInfo := c.GetAdminUserInfo()
  841. recordDateTime := theTime.Unix()
  842. //查询默认出库仓库库存
  843. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  844. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  845. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  846. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  847. if len(lists) == 1 {
  848. his_patient_id = lists[0].ID
  849. }
  850. }
  851. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  852. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  853. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  854. //已发药和已收费限制逻辑
  855. isMidicine := false
  856. isCharge := false
  857. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  858. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  859. if len(prescriptions) > 0 {
  860. for _, item := range prescriptions {
  861. items := item.(map[string]interface{})
  862. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  863. utils.ErrorLog("id")
  864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  865. return
  866. }
  867. id := int64(items["id"].(float64))
  868. if id > 0 {
  869. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  870. if err != nil {
  871. if new_prescription.OrderStatus == 4 {
  872. isCharge = true
  873. }
  874. }
  875. }
  876. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  877. advices := items["advices"].([]interface{})
  878. if len(advices) > 0 {
  879. for _, advice := range advices {
  880. var adviceId int64
  881. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  882. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  883. }
  884. if adviceId > 0 {
  885. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  886. if err == nil {
  887. if his_advice_info.IsMedicine == 1 {
  888. isMidicine = true
  889. }
  890. }
  891. }
  892. }
  893. }
  894. }
  895. }
  896. }
  897. }
  898. if isMidicine == true {
  899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  900. return
  901. }
  902. if isCharge == true {
  903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  904. return
  905. }
  906. //已发药和已收费限制逻辑
  907. if drugStockConfig.IsOpen == 1 {
  908. //校验库存总量
  909. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  910. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  911. if len(prescriptions) > 0 {
  912. for _, item := range prescriptions {
  913. items := item.(map[string]interface{})
  914. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  915. advices := items["advices"].([]interface{})
  916. if len(advices) > 0 {
  917. for _, advice := range advices {
  918. var drug_id int64
  919. var prescribing_number float64
  920. var prescribingNumberUnit string
  921. var adviceId int64
  922. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  923. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  924. }
  925. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  926. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  927. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  928. }
  929. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  930. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  931. }
  932. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  933. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  934. }
  935. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  936. if drug.ID == 0 {
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  938. return
  939. }
  940. //查询药品的所有库存
  941. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  942. var total_count int64
  943. for _, it := range list {
  944. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  945. }
  946. totals := strconv.FormatInt(total_count, 10)
  947. //查询该药品是否存在开药记录
  948. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  949. //查询最新批次库存
  950. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  951. var batch_number_count int64
  952. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  953. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  954. //新增处方
  955. if advicelist.ID == 0 {
  956. all_count, _ := strconv.ParseFloat(totals, 64)
  957. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  958. if prescribingNumberUnit == drug.MinUnit {
  959. if drug.IsUse != 1 {
  960. if prescribing_number > all_count {
  961. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  962. return
  963. }
  964. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  965. if prescribing_number > batch_number_all_count {
  966. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  967. return
  968. }
  969. }
  970. }
  971. }
  972. if prescribingNumberUnit == drug.MaxUnit {
  973. num := prescribing_number * float64(drug.MinNumber)
  974. if drug.IsUse != 1 {
  975. if num > all_count {
  976. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  977. return
  978. }
  979. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  980. if num > batch_number_all_count {
  981. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  982. return
  983. }
  984. }
  985. }
  986. }
  987. }
  988. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  989. if drugOutConfig.IsOpen != 1 {
  990. //修改处方
  991. for _, advice := range advices {
  992. var drug_id int64
  993. var prescribing_number float64
  994. var prescribingNumberUnit string
  995. var prescribingNumber string
  996. var adviceId int64
  997. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  998. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  999. }
  1000. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1001. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1002. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1003. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1004. }
  1005. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1006. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1007. }
  1008. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1009. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1010. }
  1011. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1012. if drug.ID == 0 {
  1013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1014. return
  1015. }
  1016. //查询药品的所有库存
  1017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1018. var total_count int64
  1019. for _, it := range list {
  1020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1021. }
  1022. totals := strconv.FormatInt(total_count, 10)
  1023. //查询该药品是否存在开药记录
  1024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1025. //新增处方
  1026. if advicelist.ID == 0 {
  1027. //查询最新批次库存
  1028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1029. var batch_number_count int64
  1030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1032. all_count, _ := strconv.ParseFloat(totals, 64)
  1033. if prescribingNumberUnit == drug.MinUnit {
  1034. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1035. if drug.IsUse != 1 {
  1036. if prescribing_number > all_count {
  1037. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1038. return
  1039. }
  1040. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1041. if prescribing_number > batch_number_all_count {
  1042. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1043. return
  1044. }
  1045. }
  1046. }
  1047. } else {
  1048. if prescribingNumberUnit == drug.MaxUnit {
  1049. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1050. num := prescribing_number * float64(drug.MinNumber)
  1051. if drug.IsUse != 1 {
  1052. if num > all_count {
  1053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1054. return
  1055. }
  1056. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1057. if prescribing_number > batch_number_all_count {
  1058. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1059. return
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. //修改处方
  1067. if advicelist.ID > 0 {
  1068. //查询最新批次库存
  1069. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1070. var batch_number_count int64
  1071. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1072. var device_number int64
  1073. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1074. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1075. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1076. device_number = prescribingNumberInt * drug.MinNumber
  1077. }
  1078. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1079. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1080. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1081. device_number = prescribingNumberInt
  1082. }
  1083. var number_count int64
  1084. if prescribingNumberUnit == drug.MaxUnit {
  1085. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1086. number_count = prescribingNumberInt * drug.MinNumber
  1087. }
  1088. if prescribingNumberUnit == drug.MinUnit {
  1089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1090. number_count = prescribingNumberInt
  1091. }
  1092. //如果修改的数量大于之前修改的数量
  1093. if (number_count - device_number) > 0 {
  1094. //如果修改的差数量 大于库存数量
  1095. if drug.IsUse != 1 {
  1096. if (number_count - device_number) > total_count {
  1097. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1098. return
  1099. }
  1100. if (number_count - device_number) > batch_number_count {
  1101. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1102. return
  1103. }
  1104. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1105. // 查询该药品最后一次出库记录
  1106. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1107. var out_count int64
  1108. var in_count int64
  1109. var stock_max_number int64
  1110. var stock_min_number int64
  1111. for _, it := range outInfo {
  1112. if it.CountUnit == drug.MaxUnit {
  1113. it.Count = it.Count * drug.MinNumber
  1114. }
  1115. out_count += it.Count
  1116. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1117. stock_max_number = warehouseInfoList.StockMaxNumber
  1118. stock_min_number = warehouseInfoList.StockMinNumber
  1119. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1120. }
  1121. if out_count > 0 {
  1122. if (number_count - device_number) > in_count {
  1123. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1124. return
  1125. }
  1126. }
  1127. // 未出库
  1128. if out_count == 0 {
  1129. var sum_in_count int64
  1130. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1131. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1132. fmt.Println("sum_in_count", sum_in_count)
  1133. //如果修改的数量大于有库存的第一个批次
  1134. if number_count > sum_in_count {
  1135. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1136. return
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1143. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1144. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1145. if pharmacyConfig.IsOpen != 1 {
  1146. if device_number != number_count {
  1147. // 查询该药品最后一次出库记录
  1148. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1149. //回退库存
  1150. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1151. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1152. }
  1153. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1154. var stock_max_number int64
  1155. var stock_min_number int64
  1156. if number_count >= drug.MinNumber {
  1157. stock_max_number = device_number / drug.MinNumber
  1158. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1159. stock_min_number = device_number % drug.MinNumber
  1160. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1161. } else {
  1162. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1163. }
  1164. }
  1165. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1166. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1167. }
  1168. //删除记录
  1169. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1170. //查询默认仓库剩余多少库存
  1171. var sum_count int64
  1172. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1173. for _, its := range stockInfo {
  1174. sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
  1175. }
  1176. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. //保存处方开药
  1183. if drugOutConfig.IsOpen == 1 {
  1184. //修改处方
  1185. for _, advice := range advices {
  1186. var drug_id int64
  1187. var prescribing_number float64
  1188. var prescribingNumberUnit string
  1189. var prescribingNumber string
  1190. var adviceId int64
  1191. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1192. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1193. }
  1194. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1195. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1196. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1197. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1198. }
  1199. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1200. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1201. }
  1202. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1203. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1204. }
  1205. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1206. if drug.ID == 0 {
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. //查询药品的所有库存
  1211. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1212. var total_count int64
  1213. for _, it := range list {
  1214. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1215. }
  1216. totals := strconv.FormatInt(total_count, 10)
  1217. //查询该药品是否存在开药记录
  1218. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1219. //新增处方
  1220. if advicelist.ID == 0 {
  1221. //查询最新批次库存
  1222. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1223. var batch_number_count int64
  1224. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1225. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1226. all_count, _ := strconv.ParseFloat(totals, 64)
  1227. if prescribingNumberUnit == drug.MinUnit {
  1228. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1229. if drug.IsUse != 1 {
  1230. if prescribing_number > all_count {
  1231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1232. return
  1233. }
  1234. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1235. if prescribing_number > batch_number_all_count {
  1236. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1237. return
  1238. }
  1239. }
  1240. }
  1241. } else {
  1242. if prescribingNumberUnit == drug.MaxUnit {
  1243. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1244. num := prescribing_number * float64(drug.MinNumber)
  1245. if drug.IsUse != 1 {
  1246. if num > all_count {
  1247. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1248. return
  1249. }
  1250. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1251. if prescribing_number > batch_number_all_count {
  1252. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1253. return
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. //修改处方
  1261. if advicelist.ID > 0 {
  1262. //查询最新批次库存
  1263. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1264. var batch_number_count int64
  1265. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1266. var device_number int64
  1267. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1268. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1269. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1270. device_number = prescribingNumberInt * drug.MinNumber
  1271. }
  1272. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1273. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1274. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1275. device_number = prescribingNumberInt
  1276. }
  1277. var number_count int64
  1278. if prescribingNumberUnit == drug.MaxUnit {
  1279. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1280. number_count = prescribingNumberInt * drug.MinNumber
  1281. }
  1282. if prescribingNumberUnit == drug.MinUnit {
  1283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1284. number_count = prescribingNumberInt
  1285. }
  1286. //如果修改的数量大于之前修改的数量
  1287. if (number_count - device_number) > 0 {
  1288. //如果修改的差数量 大于库存数量
  1289. if drug.IsUse != 1 {
  1290. if (number_count - device_number) > total_count {
  1291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1292. return
  1293. }
  1294. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1295. if (number_count - device_number) > batch_number_count {
  1296. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1297. return
  1298. }
  1299. }
  1300. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1301. //查询历史出库数据总批次
  1302. // 查询该药品最后一次出库记录
  1303. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1304. var out_count int64
  1305. var in_count int64
  1306. var stock_max_number int64
  1307. var stock_min_number int64
  1308. for _, it := range outInfo {
  1309. if it.CountUnit == drug.MaxUnit {
  1310. it.Count = it.Count * drug.MinNumber
  1311. }
  1312. out_count += it.Count
  1313. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1314. stock_max_number = warehouseInfoList.StockMaxNumber
  1315. stock_min_number = warehouseInfoList.StockMinNumber
  1316. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1317. }
  1318. if out_count > 0 {
  1319. if (number_count - device_number) > in_count {
  1320. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1321. return
  1322. }
  1323. }
  1324. // 未出库
  1325. if out_count == 0 {
  1326. var sum_in_count int64
  1327. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1328. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1329. //如果修改的数量大于有库存的第一个批次
  1330. if number_count > sum_in_count {
  1331. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1332. return
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. if stockConfig.IsOpen == 1 {
  1349. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1350. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1351. if len(prescriptions) > 0 {
  1352. for _, item := range prescriptions {
  1353. items := item.(map[string]interface{})
  1354. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1355. projects := items["project"].([]interface{})
  1356. if len(projects) > 0 {
  1357. for _, project := range projects {
  1358. var project_id int64
  1359. var project_type int64
  1360. var totals float64
  1361. var project_name string
  1362. var parsetotal int64
  1363. var id int64
  1364. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1365. id = int64(project.(map[string]interface{})["id"].(float64))
  1366. }
  1367. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1368. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1369. }
  1370. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1371. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1372. }
  1373. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1374. total, _ := project.(map[string]interface{})["total"].(string)
  1375. totals, _ = strconv.ParseFloat(total, 64)
  1376. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1377. }
  1378. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1379. project_name = project.(map[string]interface{})["project_name"].(string)
  1380. }
  1381. if project_type == 3 {
  1382. //查找该耗材的出库记录
  1383. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1384. if len(goodWarehouseInfo) == 0 {
  1385. //查询耗材库存
  1386. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1387. var stock_count int64
  1388. for _, it := range list {
  1389. stock_count += it.StockCount
  1390. }
  1391. stock_counts := strconv.FormatInt(stock_count, 10)
  1392. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1393. if totals > stock_total_count {
  1394. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1395. return
  1396. }
  1397. //查找今日该患者已经出库的所有耗材
  1398. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1399. for _, item := range goodList {
  1400. //回退库存
  1401. //service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1402. //service.ModifyReduceGoodSumCount(item.StorehouseId,item.Count,item.OrgId,item.GoodId)
  1403. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1404. var flush_count int64
  1405. for _, it := range goodListSix {
  1406. flush_count += it.StockCount
  1407. }
  1408. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1409. creater := adminInfo.AdminUser.Id
  1410. if errs != nil {
  1411. goodErrcode := models.XtGoodErrcode{
  1412. UserOrgId: item.OrgId,
  1413. Errcode: "手动出库更新剩余出库失败",
  1414. GoodId: item.GoodId,
  1415. Status: 1,
  1416. Ctime: time.Now().Unix(),
  1417. Mtime: 0,
  1418. Count: 0,
  1419. StockCount: 0,
  1420. Creater: creater,
  1421. BatchNumberId: 0,
  1422. WarehouseOutId: 0,
  1423. }
  1424. service.CreateGoodErrcode(goodErrcode)
  1425. }
  1426. }
  1427. //删除记录
  1428. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1429. }
  1430. if len(goodWarehouseInfo) > 0 {
  1431. //查询该患者耗材的历史数据
  1432. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1433. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1434. //数量发生改变
  1435. if parsetotal != count {
  1436. //查找今日该患者已经出库的所有耗材
  1437. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1438. for _, item := range goodList {
  1439. //回退库存
  1440. //service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1441. //扣减出库数量
  1442. //service.ModifyReduceGoodSumCount(item.StorehouseId,item.Count,item.OrgId,item.GoodId)
  1443. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1444. var flush_count int64
  1445. for _, it := range goodListSix {
  1446. flush_count += it.StockCount
  1447. }
  1448. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1449. //减少出库数量
  1450. creater := adminInfo.AdminUser.Id
  1451. if errs != nil {
  1452. goodErrcode := models.XtGoodErrcode{
  1453. UserOrgId: item.OrgId,
  1454. Errcode: "手动出库更新剩余出库失败",
  1455. GoodId: item.GoodId,
  1456. Status: 1,
  1457. Ctime: time.Now().Unix(),
  1458. Mtime: 0,
  1459. Count: 0,
  1460. StockCount: 0,
  1461. Creater: creater,
  1462. BatchNumberId: 0,
  1463. WarehouseOutId: 0,
  1464. }
  1465. service.CreateGoodErrcode(goodErrcode)
  1466. }
  1467. //查询默认仓库
  1468. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1469. var total_count int64
  1470. for _, it := range stockList {
  1471. total_count += it.StockCount
  1472. }
  1473. //基础库插入数据
  1474. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1475. }
  1476. //删除记录
  1477. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1489. var hpInfo models.HisPrescriptionInfo
  1490. if info.ID == 0 {
  1491. var randNum int
  1492. randNum = rand.Intn(10000) + 1000
  1493. timestamp := time.Now().Unix()
  1494. tempTime := time.Unix(timestamp, 0)
  1495. timeFormat := tempTime.Format("20060102150405")
  1496. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1497. hpInfo = models.HisPrescriptionInfo{
  1498. HisPatientId: his_patient_id,
  1499. UserOrgId: adminInfo.CurrentOrgId,
  1500. RecordDate: theTime.Unix(),
  1501. PatientId: patient_id,
  1502. Status: 1,
  1503. Ctime: time.Now().Unix(),
  1504. Mtime: time.Now().Unix(),
  1505. Creator: adminInfo.AdminUser.Id,
  1506. Modifier: adminInfo.AdminUser.Id,
  1507. Diagnosis: diagnose,
  1508. SickHistory: sick_history,
  1509. Departments: department,
  1510. RegisterType: reg_type,
  1511. PrescriptionNumber: p_number,
  1512. PrescriptionStatus: 1,
  1513. Doctor: role.UserName,
  1514. DoctorId: doctor_id,
  1515. SickType: sick_type,
  1516. PType: p_type,
  1517. }
  1518. service.SavePatientPrescriptionInfo(hpInfo)
  1519. redis := service.RedisClient()
  1520. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1521. redis.Set(key, "", time.Second)
  1522. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1523. redis.Set(keyOne, "", time.Second)
  1524. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1525. redis.Set(keySeven, "", time.Second)
  1526. defer redis.Close()
  1527. } else {
  1528. hpInfo = models.HisPrescriptionInfo{
  1529. ID: info.ID,
  1530. UserOrgId: adminInfo.CurrentOrgId,
  1531. RecordDate: info.RecordDate,
  1532. PatientId: info.PatientId,
  1533. Status: 1,
  1534. Ctime: info.Ctime,
  1535. Mtime: time.Now().Unix(),
  1536. Creator: info.Creator,
  1537. Modifier: adminInfo.AdminUser.Id,
  1538. Diagnosis: diagnose,
  1539. SickHistory: sick_history,
  1540. Departments: department,
  1541. RegisterType: reg_type,
  1542. PrescriptionNumber: info.PrescriptionNumber,
  1543. Doctor: role.UserName,
  1544. PrescriptionStatus: info.PrescriptionStatus,
  1545. DoctorId: doctor_id,
  1546. SickType: sick_type,
  1547. PType: info.PType,
  1548. HisPatientId: info.HisPatientId,
  1549. }
  1550. service.SavePatientPrescriptionInfo(hpInfo)
  1551. redis := service.RedisClient()
  1552. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1553. redis.Set(key, "", time.Second)
  1554. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1555. redis.Set(keyOne, "", time.Second)
  1556. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1557. redis.Set(keySeven, "", time.Second)
  1558. defer redis.Close()
  1559. }
  1560. //定义切片
  1561. var adviceList []models.HisDoctorAdviceInfo
  1562. var projectList []models.HisPrescriptionProject
  1563. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1564. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1565. var tempPrescription *models.HisPrescription
  1566. if len(prescriptions) > 0 {
  1567. for _, item := range prescriptions {
  1568. items := item.(map[string]interface{})
  1569. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1570. utils.ErrorLog("id")
  1571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1572. return
  1573. }
  1574. id := int64(items["id"].(float64))
  1575. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1576. tempPrescription = &new_prescription
  1577. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1578. utils.ErrorLog("type")
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. types := int64(items["type"].(float64))
  1583. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1584. utils.ErrorLog("med_type")
  1585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1586. return
  1587. }
  1588. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1589. if med_type == "0" {
  1590. med_type = "14"
  1591. }
  1592. //if order_status == 0 {
  1593. // order_status = 1
  1594. //}
  1595. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1596. utils.ErrorLog("pre_time")
  1597. }
  1598. preTime, _ := items["pre_time"].(string)
  1599. timeLayout := "2006-01-02"
  1600. loc, _ := time.LoadLocation("Local")
  1601. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1602. if err != nil {
  1603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1604. return
  1605. }
  1606. pTime := theTime2.Unix()
  1607. ctime := time.Now().Unix()
  1608. if tempPrescription.ID == 0 {
  1609. prescription := &models.HisPrescription{
  1610. ID: 0,
  1611. PatientId: patient_id,
  1612. UserOrgId: adminInfo.CurrentOrgId,
  1613. RecordDate: recordDateTime,
  1614. Ctime: ctime,
  1615. Mtime: ctime,
  1616. Type: types,
  1617. Modifier: adminInfo.AdminUser.Id,
  1618. Creator: adminInfo.AdminUser.Id,
  1619. Status: 1,
  1620. Doctor: role.UserName,
  1621. HisPatientId: his_patient_id,
  1622. OrderStatus: 1,
  1623. BatchNumber: "",
  1624. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1625. PreTime: pTime,
  1626. PType: p_type,
  1627. MedType: med_type,
  1628. }
  1629. tempPrescription = prescription
  1630. service.SaveHisPrescription(tempPrescription)
  1631. redis := service.RedisClient()
  1632. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1633. redis.Set(key, "", time.Second)
  1634. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1635. redis.Set(keyOne, "", time.Second)
  1636. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1637. redis.Set(keySeven, "", time.Second)
  1638. defer redis.Close()
  1639. } else {
  1640. tempPrescription.ID = id
  1641. tempPrescription.Type = types
  1642. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1643. tempPrescription.Mtime = time.Now().Unix()
  1644. tempPrescription.Doctor = role.UserName
  1645. //tempPrescription.OrderStatus = order_status
  1646. tempPrescription.PreTime = pTime
  1647. tempPrescription.MedType = med_type
  1648. service.SaveHisPrescription(tempPrescription)
  1649. redis := service.RedisClient()
  1650. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1651. redis.Set(key, "", time.Second)
  1652. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1653. redis.Set(keyOne, "", time.Second)
  1654. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1655. redis.Set(keySeven, "", time.Second)
  1656. defer redis.Close()
  1657. }
  1658. //service.SaveHisPrescription(prescription)
  1659. //更改患者挂号状态
  1660. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1661. fmt.Println("更改失败", err2)
  1662. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1663. advices := items["advices"].([]interface{})
  1664. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1665. groupNo := int64(0)
  1666. ctime := time.Now().Unix()
  1667. mtime := ctime
  1668. if len(advices) > 0 {
  1669. for _, advice := range advices {
  1670. var s models.HisDoctorAdviceInfo
  1671. s.PrescriptionId = tempPrescription.ID
  1672. s.AdviceType = 2
  1673. s.AdviceDoctor = doctor_id
  1674. s.StopState = 2
  1675. s.ExecutionState = 2
  1676. s.AdviceDate = recordDateTime
  1677. s.Status = 1
  1678. s.UserOrgId = adminInfo.CurrentOrgId
  1679. s.RecordDate = recordDateTime
  1680. s.StartTime = tempPrescription.PreTime
  1681. s.Groupno = groupNo
  1682. s.CreatedTime = ctime
  1683. s.UpdatedTime = mtime
  1684. s.PatientId = patient_id
  1685. s.HisPatientId = his_patient_id
  1686. s.StartTime = pTime
  1687. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1688. if errcode > 0 {
  1689. c.ServeFailJSONWithSGJErrorCode(errcode)
  1690. return
  1691. }
  1692. s.StartTime = pTime
  1693. var total_count int64 //处方总库存
  1694. //查询改药品信息
  1695. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  1696. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  1697. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  1698. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1699. total_count += prescribingNumberSeven * medical.MinNumber
  1700. }
  1701. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1702. total_count += prescribingNumberSeven
  1703. }
  1704. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1705. total_count += prescribingNumberSeven
  1706. }
  1707. service.CreateHisDoctorAdvice(&s)
  1708. //存储切片中
  1709. adviceList = append(adviceList, s)
  1710. redis := service.RedisClient()
  1711. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1712. redis.Set(key, "", time.Second)
  1713. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1714. redis.Set(keyOne, "", time.Second)
  1715. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1716. redis.Set(keySeven, "", time.Second)
  1717. var randNum int
  1718. randNum = rand.Intn(10000) + 1000
  1719. timestamp := time.Now().Unix()
  1720. tempTime := time.Unix(timestamp, 0)
  1721. timeFormat := tempTime.Format("20060102150405")
  1722. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1723. service.CreateHisDoctorAdvice(&s)
  1724. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1725. redis.Set(keySix, "", time.Second)
  1726. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1727. redis.Set(keyFive, "", time.Second)
  1728. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1729. redis.Set(keyEight, "", time.Second)
  1730. defer redis.Close()
  1731. }
  1732. }
  1733. }
  1734. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1735. projects := items["project"].([]interface{})
  1736. if len(projects) > 0 {
  1737. for _, project := range projects {
  1738. var p models.HisPrescriptionProject
  1739. p.PrescriptionId = tempPrescription.ID
  1740. p.Ctime = time.Now().Unix()
  1741. p.Mtime = time.Now().Unix()
  1742. p.PatientId = patient_id
  1743. p.RecordDate = recordDateTime
  1744. p.Doctor = doctor_id
  1745. p.UserOrgId = adminInfo.CurrentOrgId
  1746. p.HisPatientId = his_patient_id
  1747. p.Status = 1
  1748. p.StartTime = pTime
  1749. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1750. if errcode > 0 {
  1751. c.ServeFailJSONWithSGJErrorCode(errcode)
  1752. return
  1753. }
  1754. service.CreateHisProjectTwo(&p)
  1755. projectList = append(projectList, p)
  1756. var randNum int
  1757. randNum = rand.Intn(10000) + 1000
  1758. timestamp := time.Now().Unix()
  1759. tempTime := time.Unix(timestamp, 0)
  1760. timeFormat := tempTime.Format("20060102150405")
  1761. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1762. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1763. //新增或者编辑项目,修改对应的标签数据
  1764. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1765. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1766. var label models.HisLabelPrintInfo
  1767. project, _ := service.GetProjectDetail(p.ProjectId)
  1768. if project.CostClassify == 3 { //类别为检验检查
  1769. if p.TeamId > 0 { //检验检查组套
  1770. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1771. if tempLabel.ID == 0 {
  1772. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1773. label.Number = tempPrescription.PrescriptionNumber
  1774. label.ProjectId = project.ID
  1775. label.Status = 1
  1776. label.IsPrint = 2
  1777. label.DoctorId = info.DoctorId
  1778. label.UserOrgId = p.UserOrgId
  1779. label.PatientId = patient_id
  1780. label.RecordDate = recordDateTime
  1781. label.Ctime = time.Now().Unix()
  1782. label.Mtime = time.Now().Unix()
  1783. label.ItemId = p.TeamId
  1784. label.FeedetlSn = p.FeedetlSn
  1785. label.PProjectId = p.ID
  1786. label.ProjectName = team.ProjectTeam
  1787. label.PatientName = patient.Name
  1788. service.CreateHisLabelRecord(&label)
  1789. }
  1790. } else { //单条检验检查项目
  1791. label.Number = tempPrescription.PrescriptionNumber
  1792. label.ProjectId = project.ID
  1793. label.Status = 1
  1794. label.DoctorId = info.DoctorId
  1795. label.UserOrgId = p.UserOrgId
  1796. label.PatientId = patient_id
  1797. label.RecordDate = recordDateTime
  1798. label.IsPrint = 2
  1799. label.Ctime = time.Now().Unix()
  1800. label.Mtime = time.Now().Unix()
  1801. label.FeedetlSn = p.FeedetlSn
  1802. label.PProjectId = p.ID
  1803. label.ItemId = p.TeamId
  1804. label.ProjectName = project.ProjectName
  1805. label.PatientName = patient.Name
  1806. service.CreateHisLabelRecord(&label)
  1807. }
  1808. }
  1809. }
  1810. }
  1811. service.SaveHisProjectTwo(&p)
  1812. }
  1813. }
  1814. }
  1815. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1816. // addition := items["addition"].([]interface{})
  1817. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1818. // ctime := time.Now().Unix()
  1819. // mtime := ctime
  1820. // if len(addition) > 0 {
  1821. // for _, item := range addition {
  1822. // var s models.HisAdditionalCharge
  1823. // s.PrescriptionId = tempPrescription.ID
  1824. // s.Status = 1
  1825. // s.UserOrgId = adminInfo.CurrentOrgId
  1826. // s.RecordDate = recordDateTime
  1827. // s.CreatedTime = ctime
  1828. // s.UpdatedTime = mtime
  1829. // s.PatientId = patient_id
  1830. // s.HisPatientId = his_patient_id
  1831. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1832. // if errcode > 0 {
  1833. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1834. // return
  1835. // }
  1836. // service.CreateAdditionalCharge(&s)
  1837. // var randNum int
  1838. // randNum = rand.Intn(10000) + 1000
  1839. // timestamp := time.Now().Unix()
  1840. // tempTime := time.Unix(timestamp, 0)
  1841. // timeFormat := tempTime.Format("20060102150405")
  1842. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1843. // service.CreateAdditionalCharge(&s)
  1844. //
  1845. // }
  1846. // }
  1847. //}
  1848. }
  1849. }
  1850. //查询今日该患者开的药品处方
  1851. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1852. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1853. if drugOutConfig.IsOpen == 1 {
  1854. for _, item := range hisdoctorlist {
  1855. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  1856. // 查询该药品最后一次出库记录
  1857. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  1858. if len(druginfo) > 0 {
  1859. //回退库存
  1860. for _, it := range druginfo {
  1861. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1862. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1863. }
  1864. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1865. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1866. }
  1867. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  1868. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1869. }
  1870. }
  1871. }
  1872. //删除记录
  1873. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  1874. //查询最后一次数据
  1875. if drugOutConfig.IsOpen == 1 {
  1876. //出库
  1877. if drug.IsUse == 2 {
  1878. creater := adminInfo.AdminUser.Id
  1879. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  1880. }
  1881. //更新字典里面的库存
  1882. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1883. var sum_count int64
  1884. for _, its := range stockInfo {
  1885. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1886. if its.MaxUnit == baseDrug.MaxUnit {
  1887. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1888. }
  1889. sum_count += its.StockMaxNumber + its.StockMinNumber
  1890. }
  1891. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1892. //剩余库存
  1893. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  1894. }
  1895. }
  1896. }
  1897. }
  1898. //redisClient := service.RedisClient()
  1899. //defer redisClient.Close()
  1900. //
  1901. //list := models.HisList{
  1902. // Patient_id: patient_id,
  1903. // Advice_id:0,
  1904. // Record_date: 0,
  1905. // Advice: adviceList,
  1906. // Project: nil,
  1907. //}
  1908. //hisLis = append(hisLis, list)
  1909. //
  1910. //advice_json, _ := json.Marshal(&hisLis)
  1911. //redisClient.RPush("111", advice_json).Result()
  1912. //result, _ := redisClient.RPop("111").Result()
  1913. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1914. //
  1915. //var dat []map[string]interface{}
  1916. //json.Unmarshal([]byte(result), &dat)
  1917. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1918. //
  1919. //for k,v:=range dat{
  1920. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1921. //}
  1922. //project_json, _ := json.Marshal(&projectList)
  1923. //redisClient.LPush("222", project_json).Result()
  1924. if err == nil {
  1925. c.ServeSuccessJSON(map[string]interface{}{
  1926. "msg": "保存成功",
  1927. })
  1928. return
  1929. } else {
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1931. return
  1932. }
  1933. }
  1934. func (c *HisApiController) EditHisPrescription() {
  1935. record_date := c.GetString("record_date")
  1936. patient_id, _ := c.GetInt64("patient_id")
  1937. reg_type, _ := c.GetInt64("reg_type")
  1938. //diagnose, _ := c.GetInt64("diagnose", 0)
  1939. diagnose := c.GetString("diagnose")
  1940. sick_type, _ := c.GetInt64("sick_type")
  1941. sick_history := c.GetString("sick_history")
  1942. doctor_id, _ := c.GetInt64("doctor", 0)
  1943. department, _ := c.GetInt64("department", 0)
  1944. his_patient_id, _ := c.GetInt64("his_patient_id")
  1945. p_type, _ := c.GetInt64("p_type")
  1946. dataBody := make(map[string]interface{}, 0)
  1947. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1948. if err != nil {
  1949. utils.ErrorLog(err.Error())
  1950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1951. return
  1952. }
  1953. timeLayout := "2006-01-02"
  1954. loc, _ := time.LoadLocation("Local")
  1955. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1956. if err != nil {
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1958. return
  1959. }
  1960. adminInfo := c.GetAdminUserInfo()
  1961. recordDateTime := theTime.Unix()
  1962. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1963. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1964. var hpInfo models.HisPrescriptionInfo
  1965. if info.ID == 0 {
  1966. var randNum int
  1967. randNum = rand.Intn(10000) + 1000
  1968. timestamp := time.Now().Unix()
  1969. tempTime := time.Unix(timestamp, 0)
  1970. timeFormat := tempTime.Format("20060102150405")
  1971. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1972. hpInfo = models.HisPrescriptionInfo{
  1973. UserOrgId: adminInfo.CurrentOrgId,
  1974. RecordDate: theTime.Unix(),
  1975. PatientId: patient_id,
  1976. Status: 1,
  1977. Ctime: time.Now().Unix(),
  1978. Mtime: time.Now().Unix(),
  1979. Creator: adminInfo.AdminUser.Id,
  1980. Modifier: adminInfo.AdminUser.Id,
  1981. Diagnosis: diagnose,
  1982. SickHistory: sick_history,
  1983. Departments: department,
  1984. RegisterType: reg_type,
  1985. PrescriptionNumber: p_number,
  1986. PrescriptionStatus: 1,
  1987. Doctor: role.UserName,
  1988. DoctorId: doctor_id,
  1989. SickType: sick_type,
  1990. PType: p_type,
  1991. }
  1992. service.SavePatientPrescriptionInfo(hpInfo)
  1993. } else {
  1994. hpInfo = models.HisPrescriptionInfo{
  1995. ID: info.ID,
  1996. UserOrgId: adminInfo.CurrentOrgId,
  1997. RecordDate: info.RecordDate,
  1998. PatientId: info.PatientId,
  1999. Status: 1,
  2000. Ctime: info.Ctime,
  2001. Mtime: time.Now().Unix(),
  2002. Creator: info.Creator,
  2003. Modifier: adminInfo.AdminUser.Id,
  2004. Diagnosis: diagnose,
  2005. SickHistory: sick_history,
  2006. Departments: department,
  2007. RegisterType: reg_type,
  2008. PrescriptionNumber: info.PrescriptionNumber,
  2009. Doctor: role.UserName,
  2010. PrescriptionStatus: info.PrescriptionStatus,
  2011. DoctorId: doctor_id,
  2012. SickType: sick_type,
  2013. PType: info.PType,
  2014. }
  2015. service.SavePatientPrescriptionInfo(hpInfo)
  2016. }
  2017. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2018. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2019. if len(prescriptions) > 0 {
  2020. for _, item := range prescriptions {
  2021. items := item.(map[string]interface{})
  2022. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2023. utils.ErrorLog("id")
  2024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2025. return
  2026. }
  2027. id := int64(items["id"].(float64))
  2028. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2029. utils.ErrorLog("type")
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2031. return
  2032. }
  2033. types := int64(items["type"].(float64))
  2034. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2035. utils.ErrorLog("med_type")
  2036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2037. return
  2038. }
  2039. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2040. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2041. ctime := time.Now().Unix()
  2042. prescription := &models.HisPrescription{
  2043. ID: id,
  2044. PatientId: patient_id,
  2045. UserOrgId: adminInfo.CurrentOrgId,
  2046. RecordDate: recordDateTime,
  2047. Ctime: ctime,
  2048. Mtime: ctime,
  2049. Type: types,
  2050. Modifier: adminInfo.AdminUser.Id,
  2051. Creator: adminInfo.AdminUser.Id,
  2052. Status: 1,
  2053. Doctor: role.UserName,
  2054. HisPatientId: his_patient_id,
  2055. OrderStatus: 1,
  2056. BatchNumber: "",
  2057. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2058. PType: hpInfo.PType,
  2059. MedType: med_type,
  2060. }
  2061. if historyPrescription.ID > 0 {
  2062. prescription.PreTime = historyPrescription.PreTime
  2063. }
  2064. service.SaveHisPrescription(prescription)
  2065. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2066. advices := items["advices"].([]interface{})
  2067. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2068. groupNo := int64(0)
  2069. ctime := time.Now().Unix()
  2070. mtime := ctime
  2071. if len(advices) > 0 {
  2072. for _, advice := range advices {
  2073. var s models.HisDoctorAdviceInfo
  2074. s.PrescriptionId = prescription.ID
  2075. s.AdviceType = 2
  2076. s.AdviceDoctor = adminInfo.AdminUser.Id
  2077. s.StopState = 2
  2078. s.ExecutionState = 2
  2079. s.AdviceDate = recordDateTime
  2080. s.Status = 1
  2081. s.UserOrgId = adminInfo.CurrentOrgId
  2082. s.RecordDate = recordDateTime
  2083. s.StartTime = prescription.PreTime
  2084. s.Groupno = groupNo
  2085. s.CreatedTime = ctime
  2086. s.UpdatedTime = mtime
  2087. s.PatientId = patient_id
  2088. s.HisPatientId = his_patient_id
  2089. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2090. if errcode > 0 {
  2091. c.ServeFailJSONWithSGJErrorCode(errcode)
  2092. return
  2093. }
  2094. service.CreateHisDoctorAdvice(&s)
  2095. redis := service.RedisClient()
  2096. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2097. redis.Set(key, "", time.Second)
  2098. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2099. fmt.Println("keyOne", keyOne)
  2100. redis.Set(keyOne, "", time.Second)
  2101. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2102. redis.Set(keySeven, "", time.Second)
  2103. redis.Close()
  2104. }
  2105. }
  2106. }
  2107. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2108. projects := items["project"].([]interface{})
  2109. if len(projects) > 0 {
  2110. for _, project := range projects {
  2111. var p models.HisPrescriptionProject
  2112. p.PrescriptionId = prescription.ID
  2113. p.Ctime = time.Now().Unix()
  2114. p.Mtime = time.Now().Unix()
  2115. p.PatientId = patient_id
  2116. p.RecordDate = recordDateTime
  2117. p.UserOrgId = adminInfo.CurrentOrgId
  2118. p.HisPatientId = his_patient_id
  2119. p.Status = 1
  2120. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2121. if errcode > 0 {
  2122. c.ServeFailJSONWithSGJErrorCode(errcode)
  2123. return
  2124. }
  2125. service.CreateHisProjectTwo(&p)
  2126. }
  2127. }
  2128. }
  2129. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2130. addition := items["addition"].([]interface{})
  2131. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2132. ctime := time.Now().Unix()
  2133. mtime := ctime
  2134. if len(addition) > 0 {
  2135. for _, item := range addition {
  2136. var s models.HisAdditionalCharge
  2137. s.PrescriptionId = prescription.ID
  2138. s.Status = 1
  2139. s.UserOrgId = adminInfo.CurrentOrgId
  2140. s.RecordDate = recordDateTime
  2141. s.CreatedTime = ctime
  2142. s.UpdatedTime = mtime
  2143. s.PatientId = patient_id
  2144. s.HisPatientId = his_patient_id
  2145. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2146. if errcode > 0 {
  2147. c.ServeFailJSONWithSGJErrorCode(errcode)
  2148. return
  2149. }
  2150. service.CreateAdditionalCharge(&s)
  2151. }
  2152. }
  2153. }
  2154. }
  2155. }
  2156. }
  2157. if err == nil {
  2158. c.ServeSuccessJSON(map[string]interface{}{
  2159. "msg": "保存成功",
  2160. })
  2161. return
  2162. } else {
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2164. return
  2165. }
  2166. }
  2167. func (c *HisApiController) DeletePrescription() {
  2168. prescription_id, _ := c.GetInt64("id")
  2169. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2170. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2171. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2172. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2173. //已收费和已发药限制逻辑
  2174. isCharge := false
  2175. isMedicine := false
  2176. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2177. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2178. for _, item := range new_prescriptions {
  2179. if item.IsMedicine == 1 {
  2180. isMedicine = true
  2181. }
  2182. }
  2183. for _, item := range new_prescriptions {
  2184. if item.OrderStatus == 4 {
  2185. isCharge = true
  2186. }
  2187. }
  2188. if p_err != nil {
  2189. if new_prescription.ID > 0 {
  2190. if new_prescription.OrderStatus == 2 {
  2191. isCharge = true
  2192. }
  2193. }
  2194. }
  2195. for _, item := range advices {
  2196. if item.IsMedicine == 1 {
  2197. isMedicine = true
  2198. }
  2199. }
  2200. if isCharge {
  2201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2202. return
  2203. }
  2204. if isMedicine {
  2205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2206. return
  2207. }
  2208. //已收费和已发药限制逻辑
  2209. if len(projects) > 0 {
  2210. for _, item := range projects {
  2211. service.DeletePrintInfo(item.ID) //删除打印信息
  2212. if stockConfig.IsOpen == 1 {
  2213. if item.Type == 3 {
  2214. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2215. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2216. good.Total = good.Total + f_count
  2217. service.UpdateGoodInfo(&good)
  2218. operation_time := time.Now().Unix()
  2219. creater := c.GetAdminUserInfo().AdminUser.Id
  2220. //创建退库单
  2221. timeStr := time.Now().Format("2006-01-02")
  2222. timeArr := strings.Split(timeStr, "-")
  2223. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2224. total = total + 1
  2225. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2226. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2227. cancelStock := models.CancelStock{
  2228. OrderNumber: orderNumber,
  2229. OperaTime: operation_time,
  2230. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2231. Creater: creater,
  2232. Ctime: time.Now().Unix(),
  2233. Status: 1,
  2234. ReturnTime: item.RecordDate,
  2235. Type: 1,
  2236. StorehouseId: houseConfig.StorehouseOutInfo,
  2237. IsCheck: 1,
  2238. }
  2239. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2240. if msgerrkonde == gorm.ErrRecordNotFound {
  2241. service.AddSigleCancelStock(&cancelStock)
  2242. }
  2243. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2244. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2245. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2246. //查询该耗材是否出库
  2247. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2248. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2249. deaerler, _ := service.GetDealerById(info.Dealer)
  2250. //查询今日该患者开了多少耗材
  2251. //projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2252. //
  2253. var total_count int64
  2254. //var cha_count int64
  2255. //for _, item := range projectList {
  2256. // count, _ := strconv.ParseInt(item.Count, 10, 64)
  2257. // total_count += count
  2258. //}
  2259. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2260. total_count += count
  2261. //回退库存
  2262. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, info.ProjectId)
  2263. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, info.ProjectId)
  2264. var flush_count int64
  2265. for _, it := range goodList {
  2266. flush_count += it.StockCount
  2267. }
  2268. if info.ID > 0 {
  2269. cancelStockInfo := models.CancelStockInfo{
  2270. GoodId: item.ProjectId,
  2271. CancelStockId: cancel.ID,
  2272. GoodTypeId: good.GoodTypeId,
  2273. Count: prescribingNumber,
  2274. Price: info.Price,
  2275. Total: 0,
  2276. ProductDate: info.ProductDate,
  2277. ExpiryDate: info.ExpiryDate,
  2278. Ctime: time.Now().Unix(),
  2279. Status: 1,
  2280. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2281. OrderNumber: cancel.OrderNumber,
  2282. Type: 0,
  2283. Dealer: deaerler.DealerName,
  2284. Manufacturer: manufacturer.ManufacturerName,
  2285. Number: info.Number,
  2286. RegisterAccount: "",
  2287. Remark: "",
  2288. WarehouseInfoId: info.WarehouseInfotId,
  2289. PatientId: info.PatientId,
  2290. RecordDate: info.SysRecordTime,
  2291. StorehouseId: houseConfig.StorehouseOutInfo,
  2292. IsCheck: 1,
  2293. }
  2294. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2295. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2296. flow := models.VmStockFlow{
  2297. WarehousingId: info.WarehouseInfotId,
  2298. GoodId: item.ProjectId,
  2299. Number: info.Number,
  2300. LicenseNumber: info.LicenseNumber,
  2301. Count: prescribingNumber,
  2302. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2303. PatientId: item.PatientId,
  2304. SystemTime: info.SysRecordTime,
  2305. ConsumableType: 7,
  2306. IsSys: 0,
  2307. WarehousingOrder: "",
  2308. WarehouseOutId: info.WarehouseOutId,
  2309. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2310. IsEdit: 0,
  2311. CancelStockId: cancel.ID,
  2312. CancelOrderNumber: cancel.OrderNumber,
  2313. Manufacturer: manufacturer.ID,
  2314. Dealer: 0,
  2315. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2316. UpdateCreator: 0,
  2317. Status: 1,
  2318. Ctime: time.Now().Unix(),
  2319. Mtime: 0,
  2320. Price: info.Price,
  2321. WarehousingDetailId: info.WarehouseInfotId,
  2322. WarehouseOutDetailId: info.ID,
  2323. CancelOutDetailId: cancelInfo.ID,
  2324. ProductDate: info.ProductDate,
  2325. ExpireDate: info.ExpiryDate,
  2326. StorehouseId: houseConfig.StorehouseOutInfo,
  2327. OverCount: flush_count,
  2328. }
  2329. service.CreateStockFlowOne(flow)
  2330. //查询已出库数量
  2331. dialysisInfo, _ := service.GetGoodDialysisOutInfo(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2332. if prescribingNumber < dialysisInfo.Count {
  2333. //改变数量
  2334. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2335. }
  2336. if prescribingNumber == dialysisInfo.Count {
  2337. //删除出库表
  2338. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2339. }
  2340. ////删除出库表
  2341. //service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2342. //退库数量增加
  2343. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2344. //出库数量减少
  2345. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2346. //更新库存
  2347. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  2348. //查询今日该耗材退库数量
  2349. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2350. //var cancel_Count int64
  2351. //for _, items := range cancelInfoOne {
  2352. // cancel_Count += items.Count
  2353. //}
  2354. //
  2355. //cha_count = total_count - cancel_Count
  2356. //
  2357. //if total_count > cancel_Count {
  2358. //
  2359. // out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  2360. // if err == gorm.ErrRecordNotFound {
  2361. // //没有记录,则创建出库单
  2362. // timeStr := time.Now().Format("2006-01-02")
  2363. // timeArr := strings.Split(timeStr, "-")
  2364. // total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  2365. // total = total + 1
  2366. // warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2367. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2368. // number = number + total
  2369. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2370. // warehouseOut := models.WarehouseOut{
  2371. // WarehouseOutOrderNumber: warehousing_out_order,
  2372. // OperationTime: time.Now().Unix(),
  2373. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2374. // Creater: creater,
  2375. // Ctime: time.Now().Unix(),
  2376. // Status: 1,
  2377. // WarehouseOutTime: info.SysRecordTime,
  2378. // Dealer: 0,
  2379. // Manufacturer: 0,
  2380. // Type: 1,
  2381. // IsSys: 1,
  2382. // StorehouseId: houseConfig.StorehouseOutInfo,
  2383. // IsCheck: 1,
  2384. // }
  2385. // err := service.AddSigleWarehouseOut(&warehouseOut)
  2386. // if err != nil {
  2387. // utils.TraceLog("创建出库单失败 err = %v", err)
  2388. // return
  2389. // }
  2390. // prepare := &models.DialysisBeforePrepare{
  2391. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2392. // PatientId: info.PatientId,
  2393. // RecordDate: info.SysRecordTime,
  2394. // GoodId: item.ProjectId,
  2395. // GoodTypeId: info.GoodTypeId,
  2396. // Count: cha_count,
  2397. // StorehouseId: houseConfig.StorehouseOutInfo,
  2398. // }
  2399. // //出库
  2400. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2401. // } else if err == nil {
  2402. //
  2403. // prepare := &models.DialysisBeforePrepare{
  2404. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2405. // PatientId: info.PatientId,
  2406. // RecordDate: info.SysRecordTime,
  2407. // GoodId: item.ProjectId,
  2408. // GoodTypeId: info.GoodTypeId,
  2409. // Count: cha_count,
  2410. // StorehouseId: houseConfig.StorehouseOutInfo,
  2411. // }
  2412. // //出库
  2413. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2414. // }
  2415. //
  2416. //}
  2417. }
  2418. }
  2419. }
  2420. }
  2421. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2422. fmt.Println(err)
  2423. }
  2424. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2425. fmt.Println(err)
  2426. if len(advices) > 0 {
  2427. for _, item := range advices {
  2428. redis := service.RedisClient()
  2429. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2430. redis.Set(keyFive, "", time.Second)
  2431. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2432. redis.Set(keyOne, "", time.Second)
  2433. redis.Close()
  2434. }
  2435. }
  2436. if drugStockConfig.IsOpen == 1 {
  2437. if len(advices) > 0 {
  2438. for _, item := range advices {
  2439. creater := c.GetAdminUserInfo().AdminUser.Id
  2440. service.DrugAutoAddCancelInfo(item, creater)
  2441. }
  2442. }
  2443. }
  2444. c.ServeSuccessJSON(map[string]interface{}{
  2445. "msg": "删除成功",
  2446. })
  2447. return
  2448. }
  2449. func (c *HisApiController) DeleteDoctorAdvice() {
  2450. id, _ := c.GetInt64("id")
  2451. advice, _ := service.GetHisDoctorAdvicesById(id)
  2452. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2453. //已收费和已发药的限制逻辑
  2454. isCharge := false
  2455. isMedicine := false
  2456. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2457. //获取今天该患者所有处方,判断是否发药或者收费
  2458. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2459. for _, item := range new_prescriptions {
  2460. if item.IsMedicine == 1 {
  2461. isMedicine = true
  2462. }
  2463. }
  2464. for _, item := range new_prescriptions {
  2465. if item.OrderStatus == 4 {
  2466. isCharge = true
  2467. }
  2468. }
  2469. if isMedicine {
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2471. return
  2472. }
  2473. if isCharge {
  2474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2475. return
  2476. }
  2477. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  2478. for _, item := range advices {
  2479. if item.IsMedicine == 1 {
  2480. isMedicine = true
  2481. }
  2482. }
  2483. if isMedicine {
  2484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  2485. return
  2486. }
  2487. if new_prescription.ID > 0 {
  2488. if new_prescription.OrderStatus == 2 {
  2489. isCharge = true
  2490. }
  2491. }
  2492. if isCharge {
  2493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2494. return
  2495. }
  2496. //已收费和已发药的限制逻辑
  2497. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2498. redis := service.RedisClient()
  2499. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2500. redis.Set(keyFive, "", time.Second)
  2501. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2502. redis.Set(keyOne, "", time.Second)
  2503. defer redis.Close()
  2504. if err == nil {
  2505. if drugStockConfig.IsOpen == 1 {
  2506. //查询是否在处方中出库
  2507. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2508. if openConfig.IsOpen != 1 {
  2509. //判断该医嘱是否执行了
  2510. if advice.ExecutionState == 1 {
  2511. creater := c.GetAdminUserInfo().AdminUser.Id
  2512. service.DrugAutoAddCancelInfo(&advice, creater)
  2513. }
  2514. }
  2515. //开启保存处方扣减功能
  2516. if openConfig.IsOpen == 1 {
  2517. creater := c.GetAdminUserInfo().AdminUser.Id
  2518. service.DrugAutoAddCancelInfo(&advice, creater)
  2519. }
  2520. }
  2521. c.ServeSuccessJSON(map[string]interface{}{
  2522. "msg": "删除成功",
  2523. })
  2524. return
  2525. } else {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2527. return
  2528. }
  2529. }
  2530. func (c *HisApiController) DeleteProject() {
  2531. id, _ := c.GetInt64("id")
  2532. adminInfo := c.GetAdminUserInfo()
  2533. project, _ := service.GetHisProjectByID(id)
  2534. // var consumable models.DialysisBeforePrepare
  2535. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2536. isCharge := false
  2537. isMedicine := false
  2538. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2539. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2540. for _, item := range new_prescriptions {
  2541. if item.IsMedicine == 1 {
  2542. isMedicine = true
  2543. }
  2544. }
  2545. for _, item := range new_prescriptions {
  2546. if item.OrderStatus == 4 {
  2547. isCharge = true
  2548. }
  2549. }
  2550. if isMedicine {
  2551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2552. return
  2553. }
  2554. if isCharge {
  2555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2556. return
  2557. }
  2558. if new_prescription.ID > 0 {
  2559. if new_prescription.OrderStatus == 2 {
  2560. isCharge = true
  2561. }
  2562. }
  2563. if isCharge {
  2564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2565. return
  2566. }
  2567. service.DeletePrintInfo(id)
  2568. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2569. label.Status = 0
  2570. service.CreateHisLabelRecord(&label)
  2571. if stockConfig.IsOpen == 1 {
  2572. if project.Type == 2 {
  2573. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2574. fmt.Println(err)
  2575. }
  2576. if project.Type == 3 {
  2577. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2578. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2579. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2580. operation_time := time.Now().Unix()
  2581. creater := adminInfo.AdminUser.Id
  2582. //创建退库单
  2583. timeStr := time.Now().Format("2006-01-02")
  2584. timeArr := strings.Split(timeStr, "-")
  2585. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2586. total = total + 1
  2587. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2588. cancelStock := models.CancelStock{
  2589. OrderNumber: orderNumber,
  2590. OperaTime: operation_time,
  2591. OrgId: adminInfo.CurrentOrgId,
  2592. Creater: creater,
  2593. Ctime: time.Now().Unix(),
  2594. Status: 1,
  2595. ReturnTime: project.RecordDate,
  2596. Type: 1,
  2597. StorehouseId: houseConfig.StorehouseOutInfo,
  2598. IsCheck: 1,
  2599. }
  2600. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2601. if msgerrkonde == gorm.ErrRecordNotFound {
  2602. service.AddSigleCancelStock(&cancelStock)
  2603. }
  2604. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2605. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2606. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2607. //获取出库数据
  2608. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2609. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2610. deaerler, _ := service.GetDealerById(info.Dealer)
  2611. if info.ID > 0 {
  2612. cancelStockInfo := models.CancelStockInfo{
  2613. GoodId: project.ProjectId,
  2614. CancelStockId: cancel.ID,
  2615. GoodTypeId: good.GoodTypeId,
  2616. Count: prescribingNumber,
  2617. Price: info.Price,
  2618. Total: 0,
  2619. ProductDate: info.ProductDate,
  2620. ExpiryDate: info.ExpiryDate,
  2621. Ctime: time.Now().Unix(),
  2622. Status: 1,
  2623. OrgId: adminInfo.CurrentOrgId,
  2624. OrderNumber: cancel.OrderNumber,
  2625. Type: 0,
  2626. Dealer: deaerler.DealerName,
  2627. Manufacturer: manufacturer.ManufacturerName,
  2628. Number: info.Number,
  2629. RegisterAccount: "",
  2630. Remark: "",
  2631. WarehouseInfoId: info.WarehouseInfotId,
  2632. PatientId: info.PatientId,
  2633. RecordDate: info.SysRecordTime,
  2634. StorehouseId: houseConfig.StorehouseOutInfo,
  2635. IsCheck: 1,
  2636. }
  2637. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2638. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2639. //回退库存
  2640. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  2641. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  2642. var over_count int64
  2643. for _, it := range goodList {
  2644. over_count += it.StockCount
  2645. }
  2646. flow := models.VmStockFlow{
  2647. WarehousingId: info.WarehouseInfotId,
  2648. GoodId: project.ProjectId,
  2649. Number: info.Number,
  2650. LicenseNumber: info.LicenseNumber,
  2651. Count: prescribingNumber,
  2652. UserOrgId: adminInfo.CurrentOrgId,
  2653. PatientId: project.PatientId,
  2654. SystemTime: time.Now().Unix(),
  2655. ConsumableType: 7,
  2656. IsSys: 0,
  2657. WarehousingOrder: "",
  2658. WarehouseOutId: info.WarehouseOutId,
  2659. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2660. IsEdit: 0,
  2661. CancelStockId: cancel.ID,
  2662. CancelOrderNumber: cancel.OrderNumber,
  2663. Manufacturer: manufacturer.ID,
  2664. Dealer: 0,
  2665. Creator: adminInfo.AdminUser.Id,
  2666. UpdateCreator: 0,
  2667. Status: 1,
  2668. Ctime: time.Now().Unix(),
  2669. Mtime: 0,
  2670. Price: info.Price,
  2671. WarehousingDetailId: info.WarehouseInfotId,
  2672. WarehouseOutDetailId: info.ID,
  2673. CancelOutDetailId: cancelInfo.ID,
  2674. ProductDate: info.ProductDate,
  2675. ExpireDate: info.ExpiryDate,
  2676. StorehouseId: houseConfig.StorehouseOutInfo,
  2677. OverCount: over_count,
  2678. }
  2679. service.CreateStockFlowOne(flow)
  2680. //查询已出库数量
  2681. dialysisInfo, _ := service.GetGoodDialysisOutInfo(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2682. if prescribingNumber < dialysisInfo.Count {
  2683. //改变数量
  2684. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  2685. }
  2686. if prescribingNumber == dialysisInfo.Count {
  2687. //删除出库表
  2688. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2689. }
  2690. //退库数量增加
  2691. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  2692. //出库数量减少
  2693. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  2694. //更新剩余库存
  2695. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  2696. //查询今日该患者开了多少耗材
  2697. //projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2698. //
  2699. //var total_count int64
  2700. //var cha_count int64
  2701. //for _, item := range projectList {
  2702. // count, _ := strconv.ParseInt(item.Count, 10, 64)
  2703. // total_count += count
  2704. //}
  2705. //
  2706. ////查询今日该耗材退库数量
  2707. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2708. //var cancel_count int64
  2709. //for _, items := range cancelInfoOne {
  2710. // cancel_count += items.Count
  2711. //}
  2712. //
  2713. //cha_count = total_count - cancel_count
  2714. //
  2715. //if total_count > cancel_count {
  2716. //
  2717. // out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2718. // if err == gorm.ErrRecordNotFound {
  2719. // //没有记录,则创建出库单
  2720. // timeStr := time.Now().Format("2006-01-02")
  2721. // timeArr := strings.Split(timeStr, "-")
  2722. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2723. // total = total + 1
  2724. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2725. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2726. // number = number + total
  2727. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2728. // warehouseOut := models.WarehouseOut{
  2729. // WarehouseOutOrderNumber: warehousing_out_order,
  2730. // OperationTime: time.Now().Unix(),
  2731. // OrgId: adminInfo.CurrentOrgId,
  2732. // Creater: creater,
  2733. // Ctime: time.Now().Unix(),
  2734. // Status: 1,
  2735. // WarehouseOutTime: info.SysRecordTime,
  2736. // Dealer: 0,
  2737. // Manufacturer: 0,
  2738. // Type: 1,
  2739. // IsSys: 1,
  2740. // StorehouseId: houseConfig.StorehouseOutInfo,
  2741. // }
  2742. // err := service.AddSigleWarehouseOut(&warehouseOut)
  2743. // if err != nil {
  2744. // utils.TraceLog("创建出库单失败 err = %v", err)
  2745. // return
  2746. // }
  2747. // prepare := &models.DialysisBeforePrepare{
  2748. // UserOrgId: adminInfo.CurrentOrgId,
  2749. // PatientId: info.PatientId,
  2750. // RecordDate: info.SysRecordTime,
  2751. // GoodId: project.ProjectId,
  2752. // GoodTypeId: info.GoodTypeId,
  2753. // Count: cha_count,
  2754. // StorehouseId: houseConfig.StorehouseOutInfo,
  2755. // }
  2756. // //出库
  2757. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2758. // } else if err == nil {
  2759. // prepare := &models.DialysisBeforePrepare{
  2760. // UserOrgId: adminInfo.CurrentOrgId,
  2761. // PatientId: info.PatientId,
  2762. // RecordDate: info.SysRecordTime,
  2763. // GoodId: project.ProjectId,
  2764. // GoodTypeId: info.GoodTypeId,
  2765. // Count: cha_count,
  2766. // StorehouseId: houseConfig.StorehouseOutInfo,
  2767. // }
  2768. // //出库
  2769. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2770. // }
  2771. //
  2772. //}
  2773. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  2774. var total_count_one int64
  2775. for _, it := range stockList {
  2776. total_count_one += it.StockCount
  2777. }
  2778. //基础库插入数据
  2779. service.UpdateGoodInfoSumCount(project.ProjectId, total_count_one, project.UserOrgId)
  2780. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  2781. var flush_count int64
  2782. for _, it := range goodListOne {
  2783. flush_count += it.StockCount
  2784. }
  2785. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  2786. if errs != nil {
  2787. goodErrcode := models.XtGoodErrcode{
  2788. UserOrgId: project.UserOrgId,
  2789. Errcode: "手动出库更新剩余出库失败",
  2790. GoodId: project.ProjectId,
  2791. Status: 1,
  2792. Ctime: time.Now().Unix(),
  2793. Mtime: 0,
  2794. Count: 0,
  2795. StockCount: 0,
  2796. Creater: creater,
  2797. BatchNumberId: 0,
  2798. WarehouseOutId: 0,
  2799. }
  2800. service.CreateGoodErrcode(goodErrcode)
  2801. }
  2802. }
  2803. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2804. fmt.Println(err)
  2805. }
  2806. }
  2807. c.ServeSuccessJSON(map[string]interface{}{
  2808. "msg": "删除成功",
  2809. })
  2810. return
  2811. }
  2812. func (c *HisApiController) CreateHisAdditionalCharge() {
  2813. his_patient_id, _ := c.GetInt64("his_patient_id")
  2814. patient_id, _ := c.GetInt64("patient_id")
  2815. record_date := c.GetString("record_date")
  2816. timeLayout := "2006-01-02"
  2817. loc, _ := time.LoadLocation("Local")
  2818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2819. if err != nil {
  2820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2821. return
  2822. }
  2823. adminInfo := c.GetAdminUserInfo()
  2824. recordDateTime := theTime.Unix()
  2825. dataBody := make(map[string]interface{}, 0)
  2826. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2827. if err != nil {
  2828. utils.ErrorLog(err.Error())
  2829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2830. return
  2831. }
  2832. var additions []*models.HisAdditionalCharge
  2833. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2834. additions, _ := dataBody["addition"].([]interface{})
  2835. if len(additions) > 0 {
  2836. for _, item := range additions {
  2837. items := item.(map[string]interface{})
  2838. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2839. utils.ErrorLog("item_id")
  2840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2841. return
  2842. }
  2843. item_id := int64(items["item_id"].(float64))
  2844. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2845. utils.ErrorLog("item_name")
  2846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2847. return
  2848. }
  2849. item_name := items["item_name"].(string)
  2850. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2851. utils.ErrorLog("price")
  2852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2853. return
  2854. }
  2855. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2856. ctime := time.Now().Unix()
  2857. additional := &models.HisAdditionalCharge{
  2858. PatientId: patient_id,
  2859. HisPatientId: his_patient_id,
  2860. UserOrgId: adminInfo.CurrentOrgId,
  2861. RecordDate: recordDateTime,
  2862. CreatedTime: ctime,
  2863. UpdatedTime: ctime,
  2864. Modifier: adminInfo.AdminUser.Id,
  2865. Creator: adminInfo.AdminUser.Id,
  2866. Price: price,
  2867. ItemName: item_name,
  2868. ItemId: item_id,
  2869. Status: 1,
  2870. }
  2871. additions = append(additions, additional)
  2872. }
  2873. }
  2874. }
  2875. for _, item := range additions {
  2876. service.CreateAddtionalCharge(item)
  2877. }
  2878. c.ServeSuccessJSON(map[string]interface{}{
  2879. "msg": "创建成功",
  2880. })
  2881. }
  2882. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2883. blood_fat := c.GetString("blood_fat")
  2884. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2885. blood_sugar := c.GetString("blood_sugar")
  2886. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2887. chief_conplaint := c.GetString("chief_conplaint")
  2888. dbp := c.GetString("dbp")
  2889. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2890. delivery_way, _ := c.GetInt64("delivery_way")
  2891. diagnostic := c.GetString("diagnostic")
  2892. family_history := c.GetString("family_history")
  2893. height := c.GetString("height")
  2894. history_of_present_illness := c.GetString("history_of_present_illness")
  2895. is_infect, _ := c.GetInt64("is_infect")
  2896. past_history := c.GetString("past_history")
  2897. patient_id, _ := c.GetInt64("patient_id")
  2898. his_patient_id, _ := c.GetInt64("his_patient_id")
  2899. personal_history := c.GetString("personal_history")
  2900. pulse := c.GetString("pulse")
  2901. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2902. sbp := c.GetString("sbp")
  2903. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2904. heightfloat, _ := strconv.ParseFloat(height, 64)
  2905. sicktype := c.GetString("sick_type")
  2906. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2907. symptom := c.GetString("symptom")
  2908. sick_date := c.GetString("sick_date")
  2909. temperatures := c.GetString("temperature")
  2910. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2911. record_date := c.GetString("record_date")
  2912. breathing := c.GetString("breathing")
  2913. doctor_advice := c.GetString("doctor_advice")
  2914. remark := c.GetString("remark")
  2915. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2916. sick, _ := c.GetInt64("sick")
  2917. diagnose, _ := c.GetInt64("diagnose")
  2918. //id, _ := c.GetInt64("id")
  2919. timeLayout := "2006-01-02"
  2920. loc, _ := time.LoadLocation("Local")
  2921. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2922. allergic_history := c.GetString("allergic_history")
  2923. if err != nil {
  2924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2925. return
  2926. }
  2927. recordDateTime := theTime.Unix()
  2928. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2929. if err != nil {
  2930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2931. return
  2932. }
  2933. sickTimes := sickTime.Unix()
  2934. ctime := time.Now().Unix()
  2935. primary_disease := c.GetString("primary_disease")
  2936. confirm_failure_date := c.GetString("confirm_failure_date")
  2937. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  2938. drug_allergy_history := c.GetString("drug_allergy_history")
  2939. physical_examination := c.GetString("physical_examination")
  2940. special_inspection := c.GetString("special_inspection")
  2941. lab_apparatus := c.GetString("lab_apparatus")
  2942. caseHistory := models.HisPatientCaseHistory{
  2943. HisPatientId: his_patient_id,
  2944. PatientId: patient_id,
  2945. Temperature: temperature,
  2946. BloodSugar: bloodsugarfloat,
  2947. Pulse: pulsefloat,
  2948. Sbp: sbpfloat,
  2949. Dbp: dbpfloat,
  2950. Height: heightfloat,
  2951. BloodFat: bloodfatfloat,
  2952. SickType: sick_type,
  2953. Symptom: symptom,
  2954. SickDate: sickTimes,
  2955. IsInfect: is_infect,
  2956. HistoryOfPresentIllness: history_of_present_illness,
  2957. PastHistory: past_history,
  2958. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2959. ChiefConplaint: chief_conplaint,
  2960. PersonalHistory: personal_history,
  2961. FamilyHistory: family_history,
  2962. Diagnostic: diagnostic,
  2963. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2964. Status: 1,
  2965. Ctime: ctime,
  2966. Mtime: ctime,
  2967. RecordDate: recordDateTime,
  2968. DeliveryWay: delivery_way,
  2969. Breathing: breathingfloat,
  2970. DoctorAdvice: doctor_advice,
  2971. Remark: remark,
  2972. Sick: sick,
  2973. Diagnose: diagnose,
  2974. AllergicHistory: allergic_history,
  2975. PrimaryDisease: primary_disease,
  2976. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  2977. DrugAllergyHistory: drug_allergy_history,
  2978. PhysicalExamination: physical_examination,
  2979. SpecialInspection: special_inspection,
  2980. LabApparatus: lab_apparatus,
  2981. }
  2982. //查询该患者是否有病历
  2983. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  2984. if errcodes == gorm.ErrRecordNotFound {
  2985. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2986. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2987. if err != nil {
  2988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2989. return
  2990. }
  2991. c.ServeSuccessJSON(map[string]interface{}{
  2992. "caseHistory": caseHistory,
  2993. "historyInfo": historyInfo,
  2994. })
  2995. return
  2996. } else if errcodes == nil {
  2997. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  2998. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2999. if err != nil {
  3000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3001. return
  3002. }
  3003. c.ServeSuccessJSON(map[string]interface{}{
  3004. "caseHistory": caseHistory,
  3005. "historyInfo": historyInfo,
  3006. })
  3007. }
  3008. //查询该患者是否有病历
  3009. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  3010. //if errcode == gorm.ErrRecordNotFound {
  3011. // err = service.SaveHisPatientCaseHistory(caseHistory)
  3012. // if err != nil {
  3013. // c.ServeSuccessJSON(map[string]interface{}{
  3014. // "msg": "保存成功",
  3015. // })
  3016. // }
  3017. //} else if errcode == nil {
  3018. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3019. // return
  3020. //}
  3021. }
  3022. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  3023. patient_id, _ := c.GetInt64("patient_id", 0)
  3024. adminUser := c.GetAdminUserInfo()
  3025. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  3026. c.ServeSuccessJSON(map[string]interface{}{
  3027. "list": caseHistorys,
  3028. })
  3029. }
  3030. func (c *HisApiController) GetHisPatientCaseHistory() {
  3031. record_date, _ := c.GetInt64("record_date", 0)
  3032. patient_id, _ := c.GetInt64("patient_id", 0)
  3033. admin := c.GetAdminUserInfo()
  3034. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  3035. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  3036. c.ServeSuccessJSON(map[string]interface{}{
  3037. "info": info,
  3038. "case_history": case_history,
  3039. })
  3040. }
  3041. func (c *HisApiController) CreateCaseHistoryTemplate() {
  3042. template_name := c.GetString("template_name")
  3043. template_remark := c.GetString("template_remark")
  3044. doctor := c.GetAdminUserInfo().AdminUser.Id
  3045. diagnostic := c.GetString("diagnostic")
  3046. chief_conplaint := c.GetString("chief_conplain")
  3047. history_of_present_illness := c.GetString("history_of_present_illness")
  3048. past_history := c.GetString("past_history")
  3049. personal_history := c.GetString("personal_history")
  3050. family_history := c.GetString("family_history")
  3051. user_name := c.GetString("user_name")
  3052. doctor_advice := c.GetString("doctor_advice")
  3053. remark := c.GetString("remark")
  3054. //record_date := c.GetString("record_date")
  3055. //fmt.Println("record_date--------",record_date)
  3056. //timeLayout := "2006-01-02"
  3057. //loc, _ := time.LoadLocation("Local")
  3058. //
  3059. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3060. //if err != nil {
  3061. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3062. // return
  3063. //}
  3064. //recordDateTime := theTime.Unix()
  3065. ctime := time.Now().Unix()
  3066. template := models.HisCaseHistoryTemplate{
  3067. HistoryOfPresentIllness: history_of_present_illness,
  3068. PastHistory: past_history,
  3069. ChiefConplaint: chief_conplaint,
  3070. PersonalHistory: personal_history,
  3071. FamilyHistory: family_history,
  3072. Diagnostic: diagnostic,
  3073. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3074. Status: 1,
  3075. Ctime: ctime,
  3076. Mtime: ctime,
  3077. RecordDate: time.Now().Unix(),
  3078. TemplateName: template_name,
  3079. TemplateRemark: template_remark,
  3080. Creator: doctor,
  3081. Modifier: doctor,
  3082. UserName: user_name,
  3083. DoctorAdvice: doctor_advice,
  3084. Remark: remark,
  3085. }
  3086. err := service.SaveHisPatientCaseHistoryTemplate(template)
  3087. if err == nil {
  3088. c.ServeSuccessJSON(map[string]interface{}{
  3089. "msg": "保存成功",
  3090. })
  3091. } else {
  3092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3093. return
  3094. }
  3095. }
  3096. func (c *HisApiController) GetCaseHistoryTemplate() {
  3097. timeLayout := "2006-01-02"
  3098. loc, _ := time.LoadLocation("Local")
  3099. keyword := c.GetString("keyword")
  3100. start_time := c.GetString("start_time")
  3101. end_time := c.GetString("end_time")
  3102. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3103. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3104. admin := c.GetAdminUserInfo()
  3105. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  3106. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  3107. c.ServeSuccessJSON(map[string]interface{}{
  3108. "template": template,
  3109. //"history": history,
  3110. })
  3111. }
  3112. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3113. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3114. utils.ErrorLog("drug_name")
  3115. return enums.ErrorCodeParamWrong
  3116. }
  3117. adviceName, _ := json["drug_name"].(string)
  3118. if len(adviceName) == 0 {
  3119. utils.ErrorLog("len(advice_name) == 0")
  3120. return enums.ErrorCodeParamWrong
  3121. }
  3122. advice.AdviceName = adviceName
  3123. adviceDesc, _ := json["advice_desc"].(string)
  3124. advice.AdviceDesc = adviceDesc
  3125. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3126. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3127. advice.DrugSpec = drugSpec
  3128. }
  3129. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3130. remark, _ := json["remark"].(string)
  3131. advice.Remark = remark
  3132. }
  3133. if json["id"] == nil {
  3134. advice.DrugId = 0
  3135. } else {
  3136. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3137. drug_id := int64(json["id"].(float64))
  3138. advice.DrugId = drug_id
  3139. }
  3140. }
  3141. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3142. advice_id := int64(json["advice_id"].(float64))
  3143. advice.ID = advice_id
  3144. if advice.ID > 0 {
  3145. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3146. if err == nil {
  3147. if hisAdvice.ID > 0 {
  3148. advice.ExecutionTime = hisAdvice.ExecutionTime
  3149. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3150. advice.ExecutionState = hisAdvice.ExecutionState
  3151. advice.CheckTime = hisAdvice.CheckTime
  3152. advice.Checker = hisAdvice.Checker
  3153. advice.CheckState = hisAdvice.CheckState
  3154. advice.StartTime = hisAdvice.StartTime
  3155. advice.FeedetlSn = hisAdvice.FeedetlSn
  3156. }
  3157. }
  3158. }
  3159. }
  3160. //
  3161. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3162. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3163. // advice.ExecutionTime = execution_time
  3164. //}
  3165. //
  3166. //
  3167. //
  3168. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3169. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3170. // advice.ExecutionStaff = execution_staff
  3171. //}
  3172. //
  3173. //
  3174. //
  3175. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3176. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3177. // advice.ExecutionState = execution_state
  3178. //}
  3179. //
  3180. //
  3181. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3182. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3183. // advice.CheckTime = check_time
  3184. //}
  3185. //
  3186. //
  3187. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3188. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3189. // advice.CheckState = check_state
  3190. //}
  3191. //
  3192. //
  3193. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3194. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3195. // advice.Checker = checker
  3196. //}
  3197. //
  3198. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3199. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3200. // advice.StartTime = start_time
  3201. //}
  3202. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3203. drugSpecUnit, _ := json["min_unit"].(string)
  3204. advice.DrugSpecUnit = drugSpecUnit
  3205. }
  3206. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3207. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3208. advice.SingleDose = singleDose
  3209. }
  3210. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3211. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3212. advice.SingleDoseUnit = singleDoseUnit
  3213. }
  3214. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3215. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3216. advice.PrescribingNumber = prescribingNumber
  3217. }
  3218. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3219. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3220. advice.PrescribingNumberUnit = prescribingNumberUnit
  3221. }
  3222. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3223. deliveryWay, _ := json["delivery_way"].(string)
  3224. advice.DeliveryWay = deliveryWay
  3225. }
  3226. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3227. executionFrequency, _ := json["execution_frequency"].(string)
  3228. advice.ExecutionFrequency = executionFrequency
  3229. }
  3230. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3231. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3232. advice.Price = price
  3233. }
  3234. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3235. med_list_codg, _ := json["medical_insurance_number"].(string)
  3236. advice.MedListCodg = med_list_codg
  3237. }
  3238. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3239. day := int64(json["day"].(float64))
  3240. advice.Day = day
  3241. }
  3242. return 0
  3243. }
  3244. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3245. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3246. id := int64(json["id"].(float64))
  3247. project.ID = id
  3248. historyProject, _ := service.GetHisProjectByID(id)
  3249. project.FeedetlSn = historyProject.FeedetlSn
  3250. }
  3251. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3252. project_id := int64(json["project_id"].(float64))
  3253. project.ProjectId = project_id
  3254. }
  3255. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3256. // price := int64(json["price"].(float64))
  3257. // formatInt_price := strconv.FormatInt(price, 10)
  3258. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3259. // project.Price = float_price
  3260. // }
  3261. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3262. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3263. project.Price = price
  3264. }
  3265. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3266. total, _ := json["total"].(string)
  3267. project.Count = total
  3268. }
  3269. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3270. medical_code, _ := json["medical_code"].(string)
  3271. project.MedListCodg = medical_code
  3272. }
  3273. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3274. single_dose, _ := json["single_dose"].(string)
  3275. project.SingleDose = single_dose
  3276. }
  3277. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3278. delivery_way, _ := json["delivery_way"].(string)
  3279. project.DeliveryWay = delivery_way
  3280. }
  3281. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3282. execution_frequency, _ := json["execution_frequency"].(string)
  3283. project.ExecutionFrequency = execution_frequency
  3284. }
  3285. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3286. remark, _ := json["remark"].(string)
  3287. project.Remark = remark
  3288. }
  3289. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3290. day, _ := json["number_days"].(string)
  3291. project.Day = day
  3292. }
  3293. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3294. unit, _ := json["unit"].(string)
  3295. project.Unit = unit
  3296. }
  3297. return 0
  3298. }
  3299. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3300. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3301. id := int64(json["id"].(float64))
  3302. historyAddtions, _ := service.GetHisAdditionByID(id)
  3303. additionalCharge.ID = id
  3304. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  3305. }
  3306. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3307. item_id := int64(json["item_id"].(float64))
  3308. additionalCharge.ItemId = item_id
  3309. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3310. if config.ID > 0 {
  3311. if len(config.Code) > 0 {
  3312. additionalCharge.MedListCodg = config.Code
  3313. }
  3314. }
  3315. }
  3316. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3317. // price := int64(json["price"].(float64))
  3318. // formatInt_price := strconv.FormatInt(price, 10)
  3319. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3320. // additionalCharge.Price = float_price
  3321. // }
  3322. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3323. // price := int64(json["price"].(float64))
  3324. // formatInt_price := strconv.FormatInt(price, 10)
  3325. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3326. // additionalCharge.Price = float_price
  3327. //}
  3328. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3329. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3330. additionalCharge.Price = price
  3331. }
  3332. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3333. count, _ := json["count"].(string)
  3334. counts, _ := strconv.ParseInt(count, 10, 64)
  3335. additionalCharge.Count = counts
  3336. }
  3337. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3338. item_name, _ := json["item_name"].(string)
  3339. additionalCharge.ItemName = item_name
  3340. }
  3341. return 0
  3342. }
  3343. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3344. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3345. utils.ErrorLog("drug_name")
  3346. return enums.ErrorCodeParamWrong
  3347. }
  3348. adviceName, _ := json["drug_name"].(string)
  3349. if len(adviceName) == 0 {
  3350. utils.ErrorLog("len(advice_name) == 0")
  3351. return enums.ErrorCodeParamWrong
  3352. }
  3353. advice.AdviceName = adviceName
  3354. adviceDesc, _ := json["advice_desc"].(string)
  3355. advice.AdviceDesc = adviceDesc
  3356. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3357. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3358. advice.DrugSpec = drugSpec
  3359. }
  3360. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3361. remark, _ := json["remark"].(string)
  3362. advice.Remark = remark
  3363. }
  3364. if json["id"] == nil {
  3365. advice.DrugId = 0
  3366. } else {
  3367. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3368. drug_id := int64(json["id"].(float64))
  3369. advice.DrugId = drug_id
  3370. }
  3371. }
  3372. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3373. groupno := int64(json["groupno"].(float64))
  3374. advice.Groupno = groupno
  3375. }
  3376. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3377. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3378. advice.HospApprFlag = hosp_appr_flag
  3379. }
  3380. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3381. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3382. advice.PrescribingNumber = prescribingNumber
  3383. }
  3384. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3385. // frequency_type := int64(json["frequency_type"].(float64))
  3386. // advice.FrequencyType = frequency_type
  3387. //}
  3388. //
  3389. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3390. // day_count := int64(json["day_count"].(float64))
  3391. // advice.DayCount = day_count
  3392. //}
  3393. //
  3394. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3395. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3396. // week_day, _ := json["week_day"].(string)
  3397. // advice.WeekDay = week_day
  3398. //}
  3399. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3400. drugSpecUnit, _ := json["min_unit"].(string)
  3401. advice.DrugSpecUnit = drugSpecUnit
  3402. }
  3403. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3404. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3405. advice.SingleDose = singleDose
  3406. }
  3407. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3408. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3409. advice.SingleDoseUnit = singleDoseUnit
  3410. }
  3411. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3412. deliveryWay, _ := json["delivery_way"].(string)
  3413. advice.DeliveryWay = deliveryWay
  3414. }
  3415. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3416. executionFrequency, _ := json["execution_frequency"].(string)
  3417. advice.ExecutionFrequency = executionFrequency
  3418. }
  3419. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3420. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3421. advice.Price = price
  3422. }
  3423. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3424. med_list_codg, _ := json["medical_insurance_number"].(string)
  3425. advice.MedListCodg = med_list_codg
  3426. }
  3427. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3428. day := int64(json["day"].(float64))
  3429. advice.Day = day
  3430. }
  3431. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3432. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3433. advice.PrescribingNumberUnit = prescribingNumberUnit
  3434. }
  3435. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3436. advice_id := int64(json["advice_id"].(float64))
  3437. advice.ID = advice_id
  3438. if advice.ID > 0 {
  3439. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3440. if err == nil {
  3441. if hisAdvice.ID > 0 {
  3442. advice.ExecutionTime = hisAdvice.ExecutionTime
  3443. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3444. advice.ExecutionState = hisAdvice.ExecutionState
  3445. advice.CheckTime = hisAdvice.CheckTime
  3446. advice.Checker = hisAdvice.Checker
  3447. advice.CheckState = hisAdvice.CheckState
  3448. advice.StartTime = hisAdvice.StartTime
  3449. advice.HospApprFlag = hisAdvice.HospApprFlag
  3450. advice.IsMedicine = hisAdvice.IsMedicine
  3451. if hisAdvice.UserOrgId == 10028 {
  3452. 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 {
  3453. advice.ExecutionTime = 0
  3454. advice.ExecutionStaff = 0
  3455. advice.ExecutionState = 2
  3456. advice.CheckTime = 0
  3457. advice.Checker = 0
  3458. advice.CheckState = 2
  3459. }
  3460. } else {
  3461. 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 {
  3462. advice.ExecutionTime = 0
  3463. advice.ExecutionStaff = 0
  3464. advice.ExecutionState = 2
  3465. advice.CheckTime = 0
  3466. advice.Checker = 0
  3467. advice.CheckState = 2
  3468. }
  3469. }
  3470. //advice.Groupno = hisAdvice.Groupno
  3471. }
  3472. }
  3473. }
  3474. }
  3475. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3476. //
  3477. //if drugStockConfig.IsOpen == 1 {
  3478. //
  3479. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3480. // if advice.ID == 0 { //医嘱不存在
  3481. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3482. // drug.Total = drug.Total - advice.PrescribingNumber
  3483. // service.UpdateBaseDrugLib(&drug)
  3484. //
  3485. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3486. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3487. // drug.Total = drug.Total - num
  3488. // service.UpdateBaseDrugLib(&drug)
  3489. // }
  3490. //
  3491. // } else if advice.ID > 0 { //医嘱存在
  3492. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3493. // var num float64
  3494. //
  3495. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3496. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3497. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3498. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3499. // drug.Total = drug.Total + num
  3500. // service.UpdateBaseDrugLib(&drug)
  3501. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3502. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3503. // drug.Total = drug.Total - num
  3504. // service.UpdateBaseDrugLib(&drug)
  3505. // }
  3506. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3507. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3508. // if num2 > advice.PrescribingNumber {
  3509. // num = num2 - advice.PrescribingNumber
  3510. // drug.Total = drug.Total + num
  3511. // service.UpdateBaseDrugLib(&drug)
  3512. // } else if num2 < advice.PrescribingNumber {
  3513. // num = advice.PrescribingNumber - num2
  3514. // drug.Total = drug.Total - num
  3515. // service.UpdateBaseDrugLib(&drug)
  3516. // }
  3517. //
  3518. // }
  3519. //
  3520. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3521. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3522. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3523. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3524. // if num1 > num2 {
  3525. // num = num1 - num2
  3526. // drug.Total = drug.Total + num
  3527. // service.UpdateBaseDrugLib(&drug)
  3528. // } else if num1 < num2 {
  3529. // num = num2 - num1
  3530. // drug.Total = drug.Total - num
  3531. // service.UpdateBaseDrugLib(&drug)
  3532. // }
  3533. //
  3534. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3535. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3536. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3537. // if hisAdvice.PrescribingNumber > num2 {
  3538. // num = hisAdvice.PrescribingNumber - num2
  3539. // drug.Total = drug.Total + num
  3540. // service.UpdateBaseDrugLib(&drug)
  3541. // } else if num2 < advice.PrescribingNumber {
  3542. // num = num2 - hisAdvice.PrescribingNumber
  3543. // drug.Total = drug.Total - num
  3544. // service.UpdateBaseDrugLib(&drug)
  3545. // }
  3546. //
  3547. // }
  3548. // }
  3549. // }
  3550. //}
  3551. //
  3552. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3553. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3554. // advice.ExecutionTime = execution_time
  3555. //}
  3556. //
  3557. //
  3558. //
  3559. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3560. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3561. // advice.ExecutionStaff = execution_staff
  3562. //}
  3563. //
  3564. //
  3565. //
  3566. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3567. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3568. // advice.ExecutionState = execution_state
  3569. //}
  3570. //
  3571. //
  3572. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3573. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3574. // advice.CheckTime = check_time
  3575. //}
  3576. //
  3577. //
  3578. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3579. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3580. // advice.CheckState = check_state
  3581. //}
  3582. //
  3583. //
  3584. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3585. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3586. // advice.Checker = checker
  3587. //}
  3588. //
  3589. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3590. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3591. // advice.StartTime = start_time
  3592. //}
  3593. return 0
  3594. }
  3595. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3596. project.ExecutionStaff = 0
  3597. project.ExecutionState = 2
  3598. project.ExecutionTime = 0
  3599. project.Checker = 0
  3600. project.CheckState = 2
  3601. project.CheckTime = 0
  3602. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3603. id := int64(json["id"].(float64))
  3604. project.ID = id
  3605. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3606. project.ExecutionStaff = temp_project.ExecutionStaff
  3607. project.ExecutionState = temp_project.ExecutionState
  3608. project.ExecutionTime = temp_project.ExecutionTime
  3609. project.Checker = temp_project.Checker
  3610. project.CheckState = temp_project.CheckState
  3611. project.CheckTime = temp_project.CheckTime
  3612. project.TeamId = temp_project.TeamId
  3613. }
  3614. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3615. types := int64(json["type"].(float64))
  3616. project.Type = types
  3617. }
  3618. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3619. project_id := int64(json["project_id"].(float64))
  3620. project.ProjectId = project_id
  3621. }
  3622. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3623. team_id := int64(json["team_id"].(float64))
  3624. project.TeamId = team_id
  3625. }
  3626. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3627. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3628. project.Price = price
  3629. }
  3630. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3631. total, _ := json["total"].(string)
  3632. //totals, _ := strconv.ParseInt(total, 10, 64)
  3633. project.Count = total
  3634. }
  3635. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3636. medical_code, _ := json["medical_code"].(string)
  3637. project.MedListCodg = medical_code
  3638. }
  3639. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3640. single_dose, _ := json["single_dose"].(string)
  3641. project.SingleDose = single_dose
  3642. }
  3643. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3644. delivery_way, _ := json["delivery_way"].(string)
  3645. project.DeliveryWay = delivery_way
  3646. }
  3647. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3648. execution_frequency, _ := json["execution_frequency"].(string)
  3649. project.ExecutionFrequency = execution_frequency
  3650. }
  3651. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3652. remark, _ := json["remark"].(string)
  3653. project.Remark = remark
  3654. }
  3655. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3656. day, _ := json["number_days"].(string)
  3657. project.Day = day
  3658. }
  3659. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3660. unit, _ := json["unit"].(string)
  3661. project.Unit = unit
  3662. }
  3663. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3664. // frequency_type := int64(json["frequency_type"].(float64))
  3665. // project.FrequencyType = frequency_type
  3666. //}
  3667. //
  3668. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3669. // day_count := int64(json["day_count"].(float64))
  3670. // project.DayCount = day_count
  3671. //}
  3672. //
  3673. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3674. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3675. // week_day, _ := json["week_day"].(string)
  3676. // project.WeekDay = week_day
  3677. //}
  3678. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3679. //
  3680. //if project.ID == 0 {
  3681. // if stockConfig.IsOpen == 1 {
  3682. // if project.Type == 3 {
  3683. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3684. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3685. // good.Total = good.Total - f_count
  3686. // service.UpdateGoodInfo(&good)
  3687. // }
  3688. // }
  3689. //
  3690. //} else {
  3691. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3692. //
  3693. // if stockConfig.IsOpen == 1 {
  3694. // if project.Type == 3 {
  3695. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3696. // if project.Count < temp_project.Count {
  3697. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3698. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3699. //
  3700. // other_count := f_count_two - f_count_one
  3701. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3702. // good.Total = good.Total + other_count_two
  3703. // service.UpdateGoodInfo(&good)
  3704. // } else if project.Count > temp_project.Count {
  3705. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3706. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3707. //
  3708. // other_count := f_count_one - f_count_two
  3709. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3710. // good.Total = good.Total - other_count_two
  3711. // service.UpdateGoodInfo(&good)
  3712. // }
  3713. //
  3714. // }
  3715. // }
  3716. //
  3717. //}
  3718. return 0
  3719. }
  3720. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3721. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3722. id := int64(json["id"].(float64))
  3723. additionalCharge.ID = id
  3724. }
  3725. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3726. item_id := int64(json["item_id"].(float64))
  3727. additionalCharge.ItemId = item_id
  3728. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3729. if config.ID > 0 {
  3730. if len(config.Code) > 0 {
  3731. additionalCharge.MedListCodg = config.Code
  3732. }
  3733. }
  3734. }
  3735. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3736. // price := int64(json["price"].(float64))
  3737. // formatInt_price := strconv.FormatInt(price, 10)
  3738. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3739. // additionalCharge.Price = float_price
  3740. // }
  3741. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3742. // price := int64(json["price"].(float64))
  3743. // formatInt_price := strconv.FormatInt(price, 10)
  3744. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3745. // additionalCharge.Price = float_price
  3746. //}
  3747. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3748. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3749. additionalCharge.Price = price
  3750. }
  3751. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3752. count, _ := json["count"].(string)
  3753. counts, _ := strconv.ParseInt(count, 10, 64)
  3754. additionalCharge.Count = counts
  3755. }
  3756. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3757. item_name, _ := json["item_name"].(string)
  3758. additionalCharge.ItemName = item_name
  3759. }
  3760. return 0
  3761. }
  3762. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3763. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3764. utils.ErrorLog("drug_name")
  3765. return enums.ErrorCodeParamWrong
  3766. }
  3767. adviceName, _ := json["drug_name"].(string)
  3768. if len(adviceName) == 0 {
  3769. utils.ErrorLog("len(advice_name) == 0")
  3770. return enums.ErrorCodeParamWrong
  3771. }
  3772. advice.AdviceName = adviceName
  3773. adviceDesc, _ := json["advice_desc"].(string)
  3774. advice.AdviceDesc = adviceDesc
  3775. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3776. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3777. advice.DrugSpec = drugSpec
  3778. }
  3779. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3780. remark, _ := json["remark"].(string)
  3781. advice.Remark = remark
  3782. }
  3783. if json["id"] == nil {
  3784. advice.DrugId = 0
  3785. } else {
  3786. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3787. drug_id := int64(json["id"].(float64))
  3788. advice.DrugId = drug_id
  3789. }
  3790. }
  3791. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3792. drugSpecUnit, _ := json["min_unit"].(string)
  3793. advice.DrugSpecUnit = drugSpecUnit
  3794. }
  3795. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3796. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3797. advice.SingleDose = singleDose
  3798. }
  3799. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3800. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3801. advice.SingleDoseUnit = singleDoseUnit
  3802. }
  3803. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3804. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3805. advice.PrescribingNumber = prescribingNumber
  3806. }
  3807. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3808. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3809. advice.PrescribingNumberUnit = prescribingNumberUnit
  3810. }
  3811. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3812. deliveryWay, _ := json["delivery_way"].(string)
  3813. advice.DeliveryWay = deliveryWay
  3814. }
  3815. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3816. executionFrequency, _ := json["execution_frequency"].(string)
  3817. advice.ExecutionFrequency = executionFrequency
  3818. }
  3819. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3820. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3821. advice.Price = price
  3822. }
  3823. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3824. med_list_codg, _ := json["medical_insurance_number"].(string)
  3825. advice.MedListCodg = med_list_codg
  3826. }
  3827. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3828. day := int64(json["day"].(float64))
  3829. advice.Day = day
  3830. }
  3831. return 0
  3832. }
  3833. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3834. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3835. types := int64(json["type"].(float64))
  3836. project.Type = types
  3837. }
  3838. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3839. project_id := int64(json["project_id"].(float64))
  3840. project.ProjectId = project_id
  3841. }
  3842. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3843. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3844. project.Price = price
  3845. }
  3846. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3847. total, _ := json["total"].(string)
  3848. //totals, _ := strconv.ParseInt(total, 10, 64)
  3849. project.Count = total
  3850. }
  3851. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3852. medical_code, _ := json["medical_code"].(string)
  3853. project.MedListCodg = medical_code
  3854. }
  3855. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3856. single_dose, _ := json["single_dose"].(string)
  3857. project.SingleDose = single_dose
  3858. }
  3859. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3860. delivery_way, _ := json["delivery_way"].(string)
  3861. project.DeliveryWay = delivery_way
  3862. }
  3863. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3864. execution_frequency, _ := json["execution_frequency"].(string)
  3865. project.ExecutionFrequency = execution_frequency
  3866. }
  3867. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3868. remark, _ := json["remark"].(string)
  3869. project.Remark = remark
  3870. }
  3871. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3872. day, _ := json["number_days"].(string)
  3873. project.Day = day
  3874. }
  3875. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3876. unit, _ := json["unit"].(string)
  3877. project.Unit = unit
  3878. }
  3879. return 0
  3880. }
  3881. func (c *HisApiController) GetHisOrderList() {
  3882. page, _ := c.GetInt64("page", -1)
  3883. limit, _ := c.GetInt64("limit", -1)
  3884. start_time := c.GetString("start_time")
  3885. end_time := c.GetString("end_time")
  3886. types, _ := c.GetInt64("type", 0)
  3887. keywords := c.GetString("keywords")
  3888. p_type, _ := c.GetInt64("p_type", 0)
  3889. sort_type, _ := c.GetInt64("sort_type", 0)
  3890. charge_type, _ := c.GetInt64("charge_type", 0)
  3891. timeLayout := "2006-01-02"
  3892. loc, _ := time.LoadLocation("Local")
  3893. var startTime int64
  3894. if len(start_time) > 0 {
  3895. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3896. if err != nil {
  3897. //fmt.Println(err)
  3898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3899. return
  3900. }
  3901. startTime = theTime.Unix()
  3902. }
  3903. var endTime int64
  3904. if len(end_time) > 0 {
  3905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3906. if err != nil {
  3907. utils.ErrorLog(err.Error())
  3908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3909. return
  3910. }
  3911. endTime = theTime.Unix()
  3912. }
  3913. adminUser := c.GetAdminUserInfo()
  3914. org_id := adminUser.CurrentOrgId
  3915. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  3916. for _, item := range order {
  3917. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3918. item.DoctorName = info.Doctor
  3919. item.DepartmentName = info.XtHisDepartment.Name
  3920. }
  3921. if err == nil {
  3922. c.ServeSuccessJSON(map[string]interface{}{
  3923. "order": order,
  3924. "total": total,
  3925. })
  3926. } else {
  3927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3928. return
  3929. }
  3930. }
  3931. func (c *HisApiController) GetHisOrder() {
  3932. patient_id, _ := c.GetInt64("patient_id", 0)
  3933. number := c.GetString("number")
  3934. adminInfo := c.GetAdminUserInfo()
  3935. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3936. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3937. if err == nil {
  3938. c.ServeSuccessJSON(map[string]interface{}{
  3939. "order": order,
  3940. "prescription": prescriptions,
  3941. })
  3942. } else {
  3943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3944. return
  3945. }
  3946. }
  3947. func (c *HisApiController) GetHisPrescriptionList() {
  3948. record_date := c.GetString("record_date")
  3949. keywords := c.GetString("keywords")
  3950. page, _ := c.GetInt64("page")
  3951. limit, _ := c.GetInt64("limit")
  3952. timeLayout := "2006-01-02"
  3953. loc, _ := time.LoadLocation("Local")
  3954. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3955. if err != nil {
  3956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3957. return
  3958. }
  3959. recordDateTime := theTime.Unix()
  3960. adminInfo := c.GetAdminUserInfo()
  3961. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3962. //adminInfo := c.GetAdminUserInfo()
  3963. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3964. //fmt.Println(prescriptionOrder)
  3965. if err == nil {
  3966. c.ServeSuccessJSON(map[string]interface{}{
  3967. "order": prescriptionOrder,
  3968. "total": total,
  3969. })
  3970. } else {
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3972. return
  3973. }
  3974. }
  3975. func (c *HisApiController) GetHisPrescriptionInfo() {
  3976. id, _ := c.GetInt64("id")
  3977. adminInfo := c.GetAdminUserInfo()
  3978. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3979. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3980. if err == nil {
  3981. c.ServeSuccessJSON(map[string]interface{}{
  3982. "order": prescriptionOrder,
  3983. "prescription": prescription,
  3984. })
  3985. } else {
  3986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3987. return
  3988. }
  3989. }
  3990. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3991. adminUser := c.GetAdminUserInfo()
  3992. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3993. c.ServeSuccessJSON(map[string]interface{}{
  3994. "config": config,
  3995. })
  3996. }
  3997. type ResultTwo struct {
  3998. ErrMsg interface{} `json:"err_msg"`
  3999. InfRefmsgid string `json:"inf_refmsgid"`
  4000. Infcode int64 `json:"infcode"`
  4001. Output struct {
  4002. Baseinfo struct {
  4003. Age float64 `json:"age"`
  4004. Brdy string `json:"brdy"`
  4005. Certno string `json:"certno"`
  4006. Gend string `json:"gend"`
  4007. Naty string `json:"naty"`
  4008. PsnCertType string `json:"psn_cert_type"`
  4009. PsnName string `json:"psn_name"`
  4010. PsnNo string `json:"psn_no"`
  4011. } `json:"baseinfo"`
  4012. Idetinfo []interface{} `json:"idetinfo"`
  4013. Iinfo []struct {
  4014. Balc float64 `json:"balc"`
  4015. CvlservFlag string `json:"cvlserv_flag"`
  4016. EmpName string `json:"emp_name"`
  4017. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  4018. Insutype string `json:"insutype"`
  4019. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  4020. PausInsuDate interface{} `json:"paus_insu_date"`
  4021. PsnInsuDate string `json:"psn_insu_date"`
  4022. PsnInsuStas string `json:"psn_insu_stas"`
  4023. PsnType string `json:"psn_type"`
  4024. } `json:"insuinfo"`
  4025. } `json:"output"`
  4026. RefmsgTime string `json:"refmsg_time"`
  4027. RespondTime string `json:"respond_time"`
  4028. Signtype interface{} `json:"signtype"`
  4029. WarnInfo interface{} `json:"warn_info"`
  4030. }
  4031. type ResultThree struct {
  4032. Cainfo interface{} `json:"cainfo"`
  4033. ErrMsg interface{} `json:"err_msg"`
  4034. InfRefmsgid string `json:"inf_refmsgid"`
  4035. Infcode int64 `json:"infcode"`
  4036. Output struct {
  4037. Data struct {
  4038. IptOtpNo string `json:"ipt_otp_no"`
  4039. MdtrtID string `json:"mdtrt_id"`
  4040. PsnNo string `json:"psn_no"`
  4041. } `json:"data"`
  4042. } `json:"output"`
  4043. RefmsgTime string `json:"refmsg_time"`
  4044. RespondTime string `json:"respond_time"`
  4045. Signtype interface{} `json:"signtype"`
  4046. WarnMsg interface{} `json:"warn_msg"`
  4047. }
  4048. type ResultFour struct {
  4049. Cainfo string `json:"cainfo"`
  4050. ErrMsg string `json:"err_msg"`
  4051. InfRefmsgid string `json:"inf_refmsgid"`
  4052. Infcode int64 `json:"infcode"`
  4053. Output struct {
  4054. Result []struct {
  4055. BasMednFlag string `json:"bas_medn_flag"`
  4056. ChldMedcFlag string `json:"chld_medc_flag"`
  4057. ChrgitmLv string `json:"chrgitm_lv"`
  4058. Cnt float64 `json:"cnt"`
  4059. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  4060. DrtReimFlag string `json:"drt_reim_flag"`
  4061. FeedetlSn string `json:"feedetl_sn"`
  4062. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4063. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  4064. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4065. ListSpItemFlag string `json:"list_sp_item_flag"`
  4066. LmtUsedFlag string `json:"lmt_used_flag"`
  4067. MedChrgitmType string `json:"med_chrgitm_type"`
  4068. Memo string `json:"memo"`
  4069. OverlmtAmt float64 `json:"overlmt_amt"`
  4070. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4071. Pric float64 `json:"pric"`
  4072. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  4073. SelfpayProp float64 `json:"selfpay_prop"`
  4074. } `json:"result"`
  4075. } `json:"output"`
  4076. RefmsgTime string `json:"refmsg_time"`
  4077. RespondTime string `json:"respond_time"`
  4078. Signtype string `json:"signtype"`
  4079. WarnMsg string `json:"warn_msg"`
  4080. }
  4081. type ResultFive struct {
  4082. Insutype string `json:"insutype"`
  4083. }
  4084. type ResultSix struct {
  4085. Cainfo interface{} `json:"cainfo"`
  4086. ErrMsg interface{} `json:"err_msg"`
  4087. InfRefmsgid string `json:"inf_refmsgid"`
  4088. Infcode int64 `json:"infcode"`
  4089. Output struct {
  4090. } `json:"output"`
  4091. RefmsgTime string `json:"refmsg_time"`
  4092. RespondTime string `json:"respond_time"`
  4093. Signtype interface{} `json:"signtype"`
  4094. WarnMsg interface{} `json:"warn_msg"`
  4095. }
  4096. type ResultSeven struct {
  4097. Cainfo string `json:"cainfo"`
  4098. ErrMsg string `json:"err_msg"`
  4099. InfRefmsgid string `json:"inf_refmsgid"`
  4100. Infcode int64 `json:"infcode"`
  4101. Output struct {
  4102. Setldetail []interface{} `json:"setldetail"`
  4103. Setlinfo struct {
  4104. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4105. AcctPay float64 `json:"acct_pay"`
  4106. ActPayDedc float64 `json:"act_pay_dedc"`
  4107. Age float64 `json:"age"`
  4108. Balc float64 `json:"balc"`
  4109. Brdy string `json:"brdy"`
  4110. Certno string `json:"certno"`
  4111. ClrOptins string `json:"clr_optins"`
  4112. ClrType string `json:"clr_type"`
  4113. ClrWay string `json:"clr_way"`
  4114. CvlservFlag string `json:"cvlserv_flag"`
  4115. CvlservPay float64 `json:"cvlserv_pay"`
  4116. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4117. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4118. Gend string `json:"gend"`
  4119. HifesPay float64 `json:"hifes_pay"`
  4120. HifmiPay float64 `json:"hifmi_pay"`
  4121. HifobPay float64 `json:"hifob_pay"`
  4122. HifpPay float64 `json:"hifp_pay"`
  4123. HospPartAmt float64 `json:"hosp_part_amt"`
  4124. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4125. Insutype string `json:"insutype"`
  4126. MafPay float64 `json:"maf_pay"`
  4127. MdtrtCertType string `json:"mdtrt_cert_type"`
  4128. MdtrtID string `json:"mdtrt_id"`
  4129. MedType string `json:"med_type"`
  4130. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4131. MedinsSetlID string `json:"medins_setl_id"`
  4132. Naty string `json:"naty"`
  4133. OthPay float64 `json:"oth_pay"`
  4134. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4135. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4136. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4137. PsnCashPay float64 `json:"psn_cash_pay"`
  4138. PsnCertType string `json:"psn_cert_type"`
  4139. PsnName string `json:"psn_name"`
  4140. PsnNo string `json:"psn_no"`
  4141. PsnPartAmt float64 `json:"psn_part_amt"`
  4142. PsnType string `json:"psn_type"`
  4143. SetlID string `json:"setl_id"`
  4144. SetlTime string `json:"setl_time"`
  4145. } `json:"setlinfo"`
  4146. } `json:"output"`
  4147. RefmsgTime string `json:"refmsg_time"`
  4148. RespondTime string `json:"respond_time"`
  4149. Signtype interface{} `json:"signtype"`
  4150. WarnMsg interface{} `json:"warn_msg"`
  4151. }
  4152. type ResultEight struct {
  4153. Cainfo string `json:"cainfo"`
  4154. ErrMsg string `json:"err_msg"`
  4155. InfRefmsgid string `json:"inf_refmsgid"`
  4156. Infcode int64 `json:"infcode"`
  4157. Output struct {
  4158. Stmtinfo struct {
  4159. SetlOptins string `json:"setl_optins"`
  4160. StmtRslt string `json:"stmt_rslt"`
  4161. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4162. } `json:"stmtinfo"`
  4163. } `json:"output"`
  4164. RefmsgTime string `json:"refmsg_time"`
  4165. RespondTime string `json:"respond_time"`
  4166. Signtype interface{} `json:"signtype"`
  4167. WarnMsg interface{} `json:"warn_msg"`
  4168. }
  4169. type ResultNine struct {
  4170. Cainfo string `json:"cainfo"`
  4171. ErrMsg string `json:"err_msg"`
  4172. InfRefmsgid string `json:"inf_refmsgid"`
  4173. Infcode int64 `json:"infcode"`
  4174. Output struct {
  4175. FileQuryNo string `json:"file_qury_no"`
  4176. } `json:"output"`
  4177. RefmsgTime string `json:"refmsg_time"`
  4178. RespondTime string `json:"respond_time"`
  4179. Signtype interface{} `json:"signtype"`
  4180. WarnMsg interface{} `json:"warn_msg"`
  4181. }
  4182. type ResultTen struct {
  4183. Cainfo string `json:"cainfo"`
  4184. ErrMsg string `json:"err_msg"`
  4185. InfRefmsgid string `json:"inf_refmsgid"`
  4186. Infcode int64 `json:"infcode"`
  4187. Output struct {
  4188. DldEndtime string `json:"dld_endtime"`
  4189. FileQuryNo string `json:"file_qury_no"`
  4190. Filename string `json:"filename"`
  4191. } `json:"output"`
  4192. RefmsgTime string `json:"refmsg_time"`
  4193. RespondTime string `json:"respond_time"`
  4194. Signtype interface{} `json:"signtype"`
  4195. WarnMsg interface{} `json:"warn_msg"`
  4196. }
  4197. type ResultEleven struct {
  4198. Cainfo string `json:"cainfo"`
  4199. ErrMsg string `json:"err_msg"`
  4200. InfRefmsgid string `json:"inf_refmsgid"`
  4201. Infcode int64 `json:"infcode"`
  4202. Output struct {
  4203. Setlinfo struct {
  4204. FixmedinsName string `json:"fixmedins_name"`
  4205. FixmedinsCode string `json:"fixmedins_code"`
  4206. PsnNo string `json:"psn_no"`
  4207. PsnName string `json:"psn_name"`
  4208. HifobPay float64 `json:"hifob_pay"`
  4209. Gend string `json:"gend"`
  4210. Brdy string `json:"brdy"`
  4211. PsnCertType string `json:"psn_cert_type"`
  4212. PsnType string `json:"psn_type"`
  4213. EmpName string `json:"emp_name"`
  4214. Certno string `json:"certno"`
  4215. Insutype string `json:"insutype"`
  4216. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4217. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4218. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4219. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4220. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4221. ActPayDedc float64 `json:"act_pay_dedc"`
  4222. HifpPay float64 `json:"hifp_pay"`
  4223. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4224. CvlservPay float64 `json:"cvlserv_pay"`
  4225. HifesPay float64 `json:"hifes_pay"`
  4226. HifmiPay float64 `json:"hifmi_pay"`
  4227. MafPay float64 `json:"maf_pay"`
  4228. OthPay float64 `json:"oth_pay"`
  4229. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4230. PsnPay float64 `json:"psn_pay"`
  4231. AcctPay float64 `json:"acct_pay"`
  4232. CashPayamt float64 `json:"cash_payamt"`
  4233. Balc float64 `json:"balc"`
  4234. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4235. MedinsSetlId string `json:"medins_setl_id"`
  4236. RefdSetlFlag string `json:"refd_setl_flag"`
  4237. SetlTime string `json:"setl_time"`
  4238. MedType string `json:"med_type"`
  4239. } `json:"setlinfo"`
  4240. } `json:"output"`
  4241. RefmsgTime string `json:"refmsg_time"`
  4242. RespondTime string `json:"respond_time"`
  4243. Signtype interface{} `json:"signtype"`
  4244. WarnMsg interface{} `json:"warn_msg"`
  4245. }
  4246. type Custom struct {
  4247. DetItemFeeSumamt string
  4248. Cut string
  4249. FeedetlSn string
  4250. Price string
  4251. MedListCodg string
  4252. Type int64
  4253. AdviceId int64
  4254. ProjectId int64
  4255. ItemId int64
  4256. }
  4257. //获取个人信息----挂号-----上传就诊信息
  4258. func (c *HisApiController) GetRegisterInfo() {
  4259. id, _ := c.GetInt64("id")
  4260. record_time := c.GetString("record_time")
  4261. settlementValue, _ := c.GetInt64("settlement_value")
  4262. medical_insurance_card := c.GetString("medical_insurance_card")
  4263. name := c.GetString("name")
  4264. id_card_type, _ := c.GetInt64("id_card_type")
  4265. certificates, _ := c.GetInt64("certificates")
  4266. medical_care, _ := c.GetInt64("medical_care")
  4267. birthday := c.GetString("birthday")
  4268. age, _ := c.GetInt64("age")
  4269. id_card := c.GetString("id_card")
  4270. register_type, _ := c.GetInt64("register")
  4271. doctor, _ := c.GetInt64("doctor")
  4272. department, _ := c.GetInt64("department")
  4273. gender, _ := c.GetInt64("sex")
  4274. phone := c.GetString("phone")
  4275. registration_fee, _ := c.GetFloat("registration_fee")
  4276. medical_expenses, _ := c.GetFloat("medical_expenses")
  4277. social_type, _ := c.GetInt64("social_type")
  4278. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4279. diagnosis_ids := c.GetString("diagnosis")
  4280. sick_type, _ := c.GetInt64("sick_type")
  4281. reg_type := c.GetString("p_type")
  4282. timeLayout := "2006-01-02"
  4283. loc, _ := time.LoadLocation("Local")
  4284. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4285. birthUnix := birthdays.Unix()
  4286. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4287. if err != nil {
  4288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4289. return
  4290. }
  4291. recordDateTime := theTime.Unix()
  4292. adminInfo := c.GetAdminUserInfo()
  4293. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  4294. if tempPatient.ID == 0 {
  4295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  4296. return
  4297. }
  4298. var patient service.Patients
  4299. if id == 0 {
  4300. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  4301. } else {
  4302. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  4303. }
  4304. if patient.ID == 0 {
  4305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4306. return
  4307. }
  4308. if len(patient.IdCardNo) == 0 {
  4309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4310. return
  4311. }
  4312. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4313. if len(his) >= 1 {
  4314. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  4315. if len(his) >= 1 && order.ID == 0 {
  4316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  4317. return
  4318. }
  4319. }
  4320. timeStr := time.Now().Format("2006-01-02 15:04:05")
  4321. fmt.Println(timeStr)
  4322. timeArr := strings.Split(timeStr, " ")
  4323. fmt.Println(timeArr)
  4324. timeArrTwo := strings.Split(timeArr[0], "-")
  4325. timeArrThree := strings.Split(timeArr[1], ":")
  4326. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4327. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4328. if len(lists) == 0 {
  4329. var hisPatient models.XtHisPatient
  4330. hisPatient = models.XtHisPatient{
  4331. Name: name,
  4332. Age: age,
  4333. Gender: gender,
  4334. Birthday: birthUnix,
  4335. Phone: phone,
  4336. MedicalTreatmentType: medical_care,
  4337. IdType: certificates,
  4338. IdCardNo: id_card,
  4339. BalanceAccountsType: settlementValue,
  4340. SocialType: social_type,
  4341. MedicalInsuranceNumber: medical_insurance_card,
  4342. RegisterType: register_type,
  4343. RegisterCost: registration_fee,
  4344. TreatmentCost: medical_expenses,
  4345. AdminUserId: adminInfo.AdminUser.Id,
  4346. UserOrgId: adminInfo.CurrentOrgId,
  4347. Status: 1,
  4348. RecordDate: recordDateTime,
  4349. IsReturn: 1,
  4350. PatientId: patient.ID,
  4351. Ctime: time.Now().Unix(),
  4352. Mtime: time.Now().Unix(),
  4353. Number: str,
  4354. IdCardType: id_card_type,
  4355. Departments: department,
  4356. Doctor: doctor,
  4357. PType: reg_type,
  4358. Diagnosis: diagnosis_ids,
  4359. SickType: sick_type,
  4360. }
  4361. service.CreateHisPatient(&hisPatient)
  4362. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4363. c.ServeSuccessJSON(map[string]interface{}{
  4364. "his_info": hisPatient,
  4365. })
  4366. } else {
  4367. //chrgBchno := rand.Intn(1000000) + 10000
  4368. var hisPatient models.XtHisPatient
  4369. hisPatient = models.XtHisPatient{
  4370. Name: name,
  4371. Age: age,
  4372. Gender: gender,
  4373. Birthday: birthUnix,
  4374. Phone: phone,
  4375. MedicalTreatmentType: medical_care,
  4376. IdType: certificates,
  4377. IdCardNo: id_card,
  4378. BalanceAccountsType: settlementValue,
  4379. SocialType: social_type,
  4380. MedicalInsuranceNumber: medical_insurance_card,
  4381. RegisterType: register_type,
  4382. RegisterCost: registration_fee,
  4383. TreatmentCost: medical_expenses,
  4384. AdminUserId: adminInfo.AdminUser.Id,
  4385. UserOrgId: adminInfo.CurrentOrgId,
  4386. Status: 1,
  4387. RecordDate: recordDateTime,
  4388. IsReturn: 1,
  4389. PatientId: patient.ID,
  4390. Ctime: time.Now().Unix(),
  4391. Mtime: time.Now().Unix(),
  4392. Number: str,
  4393. IdCardType: id_card_type,
  4394. Departments: department,
  4395. Doctor: doctor,
  4396. PType: reg_type,
  4397. Diagnosis: diagnosis_ids,
  4398. SickType: sick_type,
  4399. }
  4400. service.CreateHisPatient(&hisPatient)
  4401. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4402. c.ServeSuccessJSON(map[string]interface{}{
  4403. "his_info": hisPatient,
  4404. })
  4405. }
  4406. }
  4407. //上传明细----结算
  4408. func (c *HisApiController) GetUploadInfo() {
  4409. id, _ := c.GetInt64("id")
  4410. record_time := c.GetString("record_time")
  4411. his_patient_id, _ := c.GetInt64("his_patient_id")
  4412. pay_way, _ := c.GetInt64("pay_way")
  4413. pay_price, _ := c.GetFloat("pay_price")
  4414. pay_card_no := c.GetString("pay_card_no")
  4415. discount_price, _ := c.GetFloat("discount_price")
  4416. preferential_price, _ := c.GetFloat("preferential_price")
  4417. reality_price, _ := c.GetFloat("reality_price")
  4418. found_price, _ := c.GetFloat("found_price")
  4419. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4420. private_price, _ := c.GetFloat("private_price")
  4421. timeLayout := "2006-01-02"
  4422. loc, _ := time.LoadLocation("Local")
  4423. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4424. fapiao_code := c.GetString("fapiao_code")
  4425. fapiao_number := c.GetString("fapiao_number")
  4426. diagnosis_id := c.GetString("diagnosis")
  4427. sick_type, _ := c.GetInt64("sick_type")
  4428. reg_type, _ := c.GetInt64("p_type")
  4429. order_id, _ := c.GetInt64("order_id")
  4430. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  4431. tmp_decimal := c.GetString("tmp_decimal")
  4432. var decimal float64 //本次使用的押金
  4433. var errmsg error
  4434. tx := service.XTWriteDB().Begin() //开了事务
  4435. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  4436. defer func() {
  4437. if errmsg != nil {
  4438. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  4439. tx.Rollback()
  4440. } else {
  4441. tx.Commit()
  4442. }
  4443. }()
  4444. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  4445. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  4446. return
  4447. }
  4448. if len(tmp_decimal) > 0 {
  4449. if tmp_decimal[0] == 45 {
  4450. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  4451. return
  4452. }
  4453. }
  4454. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  4455. fmt.Println(errs)
  4456. //if errs != nil {
  4457. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  4458. // return
  4459. //}
  4460. decimal = tt
  4461. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  4462. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  4463. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4464. if err != nil {
  4465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4466. return
  4467. }
  4468. recordDateTime := theTime.Unix()
  4469. adminUser := c.GetAdminUserInfo()
  4470. var prescriptions []*models.HisPrescription
  4471. var start_time int64
  4472. var end_time int64
  4473. ids_str := c.GetString("ids")
  4474. ids_arr := strings.Split(ids_str, ",")
  4475. if tempOrder.ID == 0 {
  4476. if settle_accounts_type == 1 { //日结
  4477. fmt.Println(reg_type)
  4478. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4479. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  4480. } else {
  4481. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  4482. }
  4483. } else { //月结
  4484. start_time_str := c.GetString("start_time")
  4485. end_time_str := c.GetString("end_time")
  4486. timeLayout := "2006-01-02"
  4487. loc, _ := time.LoadLocation("Local")
  4488. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4489. if err != nil {
  4490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4491. return
  4492. }
  4493. recordStartTime := theStartTime.Unix()
  4494. start_time = recordStartTime
  4495. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4496. if err != nil {
  4497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4498. return
  4499. }
  4500. recordEndTime := theEndTime.Unix()
  4501. end_time = recordEndTime
  4502. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  4503. }
  4504. timestamp := time.Now().Unix()
  4505. tempTime := time.Unix(timestamp, 0)
  4506. timeFormat := tempTime.Format("20060102150405")
  4507. chrgBchno := rand.Intn(100000) + 10000
  4508. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4509. strconv.FormatInt(his.PatientId, 10)
  4510. var ids []int64
  4511. for _, item := range prescriptions {
  4512. ids = append(ids, item.ID)
  4513. }
  4514. var total float64
  4515. for _, item := range prescriptions {
  4516. fmt.Println(item)
  4517. if item.Type == 1 { //药品
  4518. for _, subItem := range item.HisDoctorAdviceInfo {
  4519. total = total + (subItem.Price * subItem.PrescribingNumber)
  4520. }
  4521. }
  4522. if item.Type == 2 { //项目
  4523. for _, subItem := range item.HisPrescriptionProject {
  4524. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4525. total = total + (subItem.Price * cnt)
  4526. }
  4527. }
  4528. for _, subItem := range item.HisAdditionalCharge {
  4529. total = total + (subItem.Price * float64(subItem.Count))
  4530. }
  4531. }
  4532. if reg_type == 1111 || reg_type == 1112 {
  4533. reg_type = 11
  4534. }
  4535. tm := time.Unix(time.Now().Unix(), 0)
  4536. allTotal := fmt.Sprintf("%.4f", total)
  4537. totals, _ := strconv.ParseFloat(allTotal, 64)
  4538. order := &models.HisOrder{
  4539. UserOrgId: adminUser.CurrentOrgId,
  4540. HisPatientId: his.ID,
  4541. PatientId: id,
  4542. SettleAccountsDate: recordDateTime,
  4543. Ctime: time.Now().Unix(),
  4544. Mtime: time.Now().Unix(),
  4545. Status: 1,
  4546. OrderStatus: 2,
  4547. MdtrtId: his.Number,
  4548. Number: chrg_bchno,
  4549. MedfeeSumamt: totals,
  4550. PayWay: pay_way,
  4551. PayPrice: pay_price,
  4552. MedType: strconv.Itoa(int(reg_type)),
  4553. PayCardNo: pay_card_no,
  4554. DiscountPrice: discount_price,
  4555. PreferentialPrice: preferential_price,
  4556. RealityPrice: reality_price,
  4557. FoundPrice: found_price,
  4558. MedicalInsurancePrice: medical_insurance_price,
  4559. PrivatePrice: private_price,
  4560. SettleEndTime: end_time,
  4561. SettleStartTime: start_time,
  4562. SettleType: settle_accounts_type,
  4563. FaPiaoCode: fapiao_code,
  4564. FaPiaoNumber: fapiao_number,
  4565. Diagnosis: diagnosis_id,
  4566. PType: 2,
  4567. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4568. Decimal: decimal,
  4569. }
  4570. err = service.CreateOrderTX(order, tx)
  4571. if err != nil {
  4572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4573. return
  4574. }
  4575. var customs []*Custom
  4576. for _, item := range prescriptions {
  4577. if item.Type == 1 { //药品a
  4578. for _, subItem := range item.HisDoctorAdviceInfo {
  4579. cus := &Custom{
  4580. AdviceId: subItem.ID,
  4581. ProjectId: 0,
  4582. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4583. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4584. FeedetlSn: subItem.FeedetlSn,
  4585. Price: fmt.Sprintf("%.2f", subItem.Price),
  4586. MedListCodg: subItem.MedListCodg,
  4587. Type: 1,
  4588. }
  4589. customs = append(customs, cus)
  4590. }
  4591. }
  4592. if item.Type == 2 { //项目
  4593. for _, subItem := range item.HisPrescriptionProject {
  4594. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4595. cus := &Custom{
  4596. AdviceId: 0,
  4597. ProjectId: subItem.ID,
  4598. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4599. Cut: fmt.Sprintf("%.4f", cnt),
  4600. FeedetlSn: subItem.FeedetlSn,
  4601. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4602. MedListCodg: subItem.MedListCodg,
  4603. Type: 2,
  4604. }
  4605. customs = append(customs, cus)
  4606. }
  4607. }
  4608. for _, item := range item.HisAdditionalCharge {
  4609. cus := &Custom{
  4610. ItemId: item.ID,
  4611. AdviceId: 0,
  4612. ProjectId: 0,
  4613. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4614. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4615. FeedetlSn: item.FeedetlSn,
  4616. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4617. MedListCodg: item.XtHisAddtionConfig.Code,
  4618. Type: 3,
  4619. }
  4620. customs = append(customs, cus)
  4621. }
  4622. }
  4623. for _, item := range customs {
  4624. var advice_id int64 = 0
  4625. var project_id int64 = 0
  4626. var item_id int64 = 0
  4627. var types int64 = 0
  4628. if item.Type == 1 {
  4629. advice_id = item.AdviceId
  4630. project_id = 0
  4631. item_id = 0
  4632. } else if item.Type == 2 {
  4633. advice_id = 0
  4634. item_id = 0
  4635. project_id = item.ProjectId
  4636. } else if item.Type == 3 {
  4637. advice_id = 0
  4638. item_id = item.ItemId
  4639. project_id = 0
  4640. }
  4641. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4642. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4643. pric, _ := strconv.ParseFloat(item.Price, 32)
  4644. info := &models.HisOrderInfo{
  4645. OrderNumber: order.Number,
  4646. UploadDate: time.Now().Unix(),
  4647. AdviceId: advice_id,
  4648. DetItemFeeSumamt: detItemFeeSumamt,
  4649. Cnt: cut,
  4650. Pric: pric,
  4651. PatientId: id,
  4652. Status: 1,
  4653. Mtime: time.Now().Unix(),
  4654. Ctime: time.Now().Unix(),
  4655. UserOrgId: adminUser.CurrentOrgId,
  4656. HisPatientId: his.ID,
  4657. OrderId: order.ID,
  4658. ProjectId: project_id,
  4659. Type: types,
  4660. ItemId: item_id,
  4661. }
  4662. service.CreateOrderInfoTX(info, tx)
  4663. }
  4664. his.Diagnosis = diagnosis_id
  4665. his.SickType = sick_type
  4666. his.RegisterType = reg_type
  4667. his.MedicalTreatmentType = reg_type
  4668. service.UpdataHisPateintTX(&his, tx)
  4669. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  4670. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  4671. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  4672. //判断是否使用了押金
  4673. if dec_way == "true" {
  4674. tmpstring := strconv.FormatInt(order.ID, 10)
  4675. //扣押金
  4676. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  4677. order.Decimal = decimal
  4678. service.UpDateOrderTwo(order)
  4679. if errmsg != nil {
  4680. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  4681. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4682. return
  4683. }
  4684. }
  4685. if err == nil {
  4686. c.ServeSuccessJSON(map[string]interface{}{
  4687. "msg": "结算成功",
  4688. })
  4689. }
  4690. } else {
  4691. if tempOrder.IsPre > 0 {
  4692. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4693. totals, _ := strconv.ParseFloat(allTotal, 64)
  4694. tempOrder.OrderStatus = 2
  4695. tempOrder.PayWay = pay_way
  4696. tempOrder.PayPrice = pay_price
  4697. tempOrder.PayCardNo = pay_card_no
  4698. tempOrder.DiscountPrice = discount_price
  4699. tempOrder.PreferentialPrice = preferential_price
  4700. tempOrder.RealityPrice = reality_price
  4701. tempOrder.FoundPrice = found_price
  4702. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4703. tempOrder.PrivatePrice = private_price
  4704. tempOrder.FaPiaoCode = fapiao_code
  4705. tempOrder.FaPiaoNumber = fapiao_number
  4706. tempOrder.PType = 2
  4707. tempOrder.MedfeeSumamt = totals
  4708. tempOrder.Diagnosis = diagnosis_id
  4709. err = service.SaveHisOrder(&tempOrder)
  4710. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4711. if err != nil {
  4712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4713. return
  4714. }
  4715. if err == nil {
  4716. c.ServeSuccessJSON(map[string]interface{}{
  4717. "msg": "结算成功",
  4718. })
  4719. }
  4720. }
  4721. }
  4722. }
  4723. //退款
  4724. func (c *HisApiController) Refund() {
  4725. order_id, _ := c.GetInt64("order_id")
  4726. order, _ := service.GetHisOrderByID(order_id)
  4727. adminUser := c.GetAdminUserInfo()
  4728. orgid := c.GetAdminUserInfo().CurrentOrgId
  4729. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4730. if err != nil {
  4731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4732. return
  4733. }
  4734. tmp := strconv.FormatInt(order.ID, 10)
  4735. //当押金不为零时产生退费记录
  4736. if order.Decimal != 0 {
  4737. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  4738. if err != nil {
  4739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4740. return
  4741. }
  4742. }
  4743. c.ServeSuccessJSON(map[string]interface{}{
  4744. "msg": "退费成功",
  4745. })
  4746. }
  4747. func (c *HisApiController) RefundNumber() {
  4748. his_patient_id, _ := c.GetInt64("id")
  4749. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4750. info.Status = 0
  4751. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4752. if count > 0 {
  4753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4754. return
  4755. }
  4756. err := service.SaveHisPatient(info)
  4757. if err == nil {
  4758. c.ServeSuccessJSON(map[string]interface{}{
  4759. "msg": "退号成功",
  4760. })
  4761. } else {
  4762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4763. return
  4764. }
  4765. }
  4766. func (this *HisApiController) AdditionalCharge() {
  4767. dataBody := make(map[string]interface{}, 0)
  4768. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4769. fmt.Println(err)
  4770. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4771. patient_id := int64(dataBody["patient_id"].(float64))
  4772. medicineData, _ := dataBody["medicineData"].([]interface{})
  4773. adminUserInfo := this.GetAdminUserInfo()
  4774. orgId := adminUserInfo.CurrentOrgId
  4775. admin_user_id := adminUserInfo.AdminUser.Id
  4776. timeStr := time.Now().Format("2006-01-02")
  4777. timeLayout := "2006-01-02 15:04:05"
  4778. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4779. timenow := timeStringToTime.Unix()
  4780. var additionalCharges []*models.HisAdditionalCharge
  4781. for _, item := range medicineData {
  4782. var randNum int
  4783. randNum = rand.Intn(10000) + 1000
  4784. timestamp := time.Now().Unix()
  4785. tempTime := time.Unix(timestamp, 0)
  4786. timeFormat := tempTime.Format("20060102150405")
  4787. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4788. items := item.(map[string]interface{})
  4789. money := items["price"].(string)
  4790. item_id_str := items["item_id"].(string)
  4791. name := items["name"].(string)
  4792. id_str := items["id"].(string)
  4793. moneys, _ := strconv.ParseInt(money, 10, 64)
  4794. monStr := strconv.FormatInt(moneys, 10)
  4795. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4796. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4797. id, _ := strconv.ParseInt(id_str, 10, 64)
  4798. additionalCharge := &models.HisAdditionalCharge{
  4799. ID: id,
  4800. HisPatientId: his_patient_id,
  4801. UserOrgId: orgId,
  4802. PatientId: patient_id,
  4803. RecordDate: timenow,
  4804. Price: monneyStr,
  4805. Status: 1,
  4806. ItemName: name,
  4807. ItemId: item_id,
  4808. AdminUserId: admin_user_id,
  4809. CreatedTime: time.Now().Unix(),
  4810. OrderStatus: 0,
  4811. PrescriptionNumber: "",
  4812. BatchNumber: "",
  4813. FeedetlSn: p_number,
  4814. }
  4815. service.CreateAdditionalCharge(additionalCharge)
  4816. additionalCharges = append(additionalCharges, additionalCharge)
  4817. }
  4818. this.ServeSuccessJSON(map[string]interface{}{
  4819. "msg": "添加成功",
  4820. "additional_charges": additionalCharges,
  4821. })
  4822. }
  4823. func (this *HisApiController) DeleteAddition() {
  4824. id, _ := this.GetInt64("id")
  4825. //TODO 需要判断是否已经结算
  4826. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4827. if err == nil {
  4828. this.ServeSuccessJSON(map[string]interface{}{
  4829. "msg": "删除成功",
  4830. })
  4831. return
  4832. } else {
  4833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4834. return
  4835. }
  4836. }
  4837. func (this *HisApiController) GetAdminUsers() {
  4838. adminUser := this.GetAdminUserInfo()
  4839. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4840. this.ServeSuccessJSON(map[string]interface{}{
  4841. "doctors": doctors,
  4842. })
  4843. }
  4844. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4845. change_type, _ := this.GetInt64("type", 0)
  4846. record_date := this.GetString("record_time")
  4847. patient_id, _ := this.GetInt64("patient_id", 0)
  4848. p_type, _ := this.GetInt64("p_type", 0)
  4849. timeLayout := "2006-01-02"
  4850. loc, _ := time.LoadLocation("Local")
  4851. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4852. record_time := theAdviceRecordTime.Unix()
  4853. adminUserInfo := this.GetAdminUserInfo()
  4854. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4855. if err == nil {
  4856. if len(prescriptions) == 0 {
  4857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4858. return
  4859. } else {
  4860. this.ServeSuccessJSON(map[string]interface{}{
  4861. "prescriptions": prescriptions,
  4862. })
  4863. return
  4864. }
  4865. } else {
  4866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4867. return
  4868. }
  4869. }
  4870. func (this *HisApiController) GetCallHisPrescription() {
  4871. patient_id, _ := this.GetInt64("patient_id", 0)
  4872. timeLayout := "2006-01-02"
  4873. loc, _ := time.LoadLocation("Local")
  4874. start_time := this.GetString("start_time")
  4875. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4876. end_time := this.GetString("end_time")
  4877. p_type, _ := this.GetInt64("p_type")
  4878. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4879. adminUserInfo := this.GetAdminUserInfo()
  4880. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4881. if err == nil {
  4882. this.ServeSuccessJSON(map[string]interface{}{
  4883. "prescriptions": prescriptions,
  4884. })
  4885. return
  4886. } else {
  4887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4888. return
  4889. }
  4890. }
  4891. func (this *HisApiController) GetHisDayPrescription() {
  4892. timeLayout := "2006-01-02"
  4893. loc, _ := time.LoadLocation("Local")
  4894. start_time := this.GetString("start_time")
  4895. patient_id, _ := this.GetInt64("patient_id", 0)
  4896. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4897. end_time := this.GetString("end_time")
  4898. p_type, _ := this.GetInt64("p_type")
  4899. order_status, _ := this.GetInt64("type")
  4900. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4901. adminUserInfo := this.GetAdminUserInfo()
  4902. var dayHisPrescription []*models.HisPrescription
  4903. var err error
  4904. if order_status == 1 || order_status == 0 {
  4905. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4906. } else if order_status == 2 {
  4907. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4908. }
  4909. var settle_total float64
  4910. for _, item := range dayHisPrescription {
  4911. if len(item.HisPrescriptionProject) > 0 {
  4912. for _, subItem := range item.HisPrescriptionProject {
  4913. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4914. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4915. settle_total = settle_total + total
  4916. }
  4917. }
  4918. if len(item.HisDoctorAdviceInfo) > 0 {
  4919. for _, subItem := range item.HisDoctorAdviceInfo {
  4920. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4921. settle_total = settle_total + total
  4922. }
  4923. }
  4924. }
  4925. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4926. if err == nil {
  4927. this.ServeSuccessJSON(map[string]interface{}{
  4928. "day_prescription": dayHisPrescription,
  4929. "settle_total": settle_total,
  4930. })
  4931. return
  4932. } else {
  4933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4934. return
  4935. }
  4936. }
  4937. func (c *HisApiController) GetHisChargePatientList() {
  4938. record_date := c.GetString("record_date")
  4939. order_status, _ := c.GetInt64("type")
  4940. timeLayout := "2006-01-02"
  4941. loc, _ := time.LoadLocation("Local")
  4942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4943. if err != nil {
  4944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4945. return
  4946. }
  4947. recordDateTime := theTime.Unix()
  4948. adminInfo := c.GetAdminUserInfo()
  4949. var tempPatients []*service.NewTempPatients
  4950. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4951. if order_status != 2 {
  4952. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4953. } else {
  4954. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4955. }
  4956. var patients []*service.NewTempPatients
  4957. var patients_two []*service.NewTempPatients
  4958. for _, item := range tempPatients {
  4959. //过滤掉没挂号的和没开处方的
  4960. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4961. patients = append(patients, item)
  4962. }
  4963. //过滤掉没挂号的
  4964. if len(item.HisPatient) > 0 {
  4965. patients_two = append(patients_two, item)
  4966. }
  4967. }
  4968. c.ServeSuccessJSON(map[string]interface{}{
  4969. "list": patients,
  4970. "list_two": patients_two,
  4971. })
  4972. }
  4973. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4974. record_date := c.GetString("record_date")
  4975. timeLayout := "2006-01-02"
  4976. loc, _ := time.LoadLocation("Local")
  4977. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4978. if err != nil {
  4979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4980. return
  4981. }
  4982. recordDateTime := theTime.Unix()
  4983. adminUser := c.GetAdminUserInfo()
  4984. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4985. var patients []*service.Patients
  4986. for _, item := range tempPatients {
  4987. if item.HisPatient.ID == 0 {
  4988. patients = append(patients, item)
  4989. }
  4990. }
  4991. c.ServeSuccessJSON(map[string]interface{}{
  4992. "list": patients,
  4993. //"list_two": patients_two,
  4994. })
  4995. }
  4996. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4997. newArr = make([]*service.Patients, 0)
  4998. for i := 0; i < len(patient); i++ {
  4999. repeat := false
  5000. for j := i + 1; j < len(patient); j++ {
  5001. if patient[i].ID == patient[j].ID {
  5002. repeat = true
  5003. break
  5004. }
  5005. }
  5006. if !repeat {
  5007. newArr = append(newArr, patient[i])
  5008. }
  5009. }
  5010. return
  5011. }
  5012. func (c *HisApiController) GetHisChargePatientInfo() {
  5013. patient_id, _ := c.GetInt64("patient_id")
  5014. his_patient_id, _ := c.GetInt64("his_patient_id")
  5015. record_date := c.GetString("record_date")
  5016. //start_time := c.GetString("start_time")
  5017. //end_time := c.GetString("end_time")
  5018. order_status, _ := c.GetInt64("type", 0)
  5019. p_type, _ := c.GetInt64("p_type", 0)
  5020. order_id, _ := c.GetInt64("order_id", 0)
  5021. timeLayout := "2006-01-02"
  5022. loc, _ := time.LoadLocation("Local")
  5023. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5024. if err != nil {
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5026. return
  5027. }
  5028. recordDateTime := theTime.Unix()
  5029. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5030. //if err != nil {
  5031. //
  5032. //}
  5033. //startRecordDateTime := startTime.Unix()
  5034. //
  5035. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5036. //if err != nil {
  5037. //
  5038. //}
  5039. //endRecordDateTime := endTime.Unix()
  5040. admin := c.GetAdminUserInfo()
  5041. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5042. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5043. var prescriptions []*models.HisPrescription
  5044. //var unChargeMonthPrescriptions []*models.HisPrescription
  5045. order, _ := service.GetHisOrderByID(order_id)
  5046. if order_status == 1 || order_status == 0 {
  5047. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  5048. } else if order_status == 2 {
  5049. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  5050. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5051. }
  5052. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5053. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5054. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5055. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5056. //获取所有科室信息
  5057. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5058. c.ServeSuccessJSON(map[string]interface{}{
  5059. "his_info": his_patient_info,
  5060. "xt_info": xt_patient_info,
  5061. "prescription": prescriptions,
  5062. "case_history": case_history,
  5063. "info": patientPrescriptionInfo,
  5064. "last_info": lastPatientPrescriptionInfo,
  5065. "order": order,
  5066. "doctors": doctors,
  5067. "department": department,
  5068. })
  5069. return
  5070. }
  5071. func (c *HisApiController) GetAllOrderDetail() {
  5072. order_id, _ := c.GetInt64("id", 0)
  5073. order, _ := service.GetHisOrderByID(order_id)
  5074. if order.ID == 0 {
  5075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5076. return
  5077. }
  5078. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5079. org_id := c.GetAdminUserInfo().CurrentOrgId
  5080. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5081. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5082. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5083. c.ServeSuccessJSON(map[string]interface{}{
  5084. "order": order,
  5085. "order_info": order_info,
  5086. "patient": patient,
  5087. "admin_info": adminInfo,
  5088. "hospital_record": record,
  5089. })
  5090. return
  5091. }
  5092. func (c *HisApiController) GetAllOrderDetailCollect() {
  5093. order_id, _ := c.GetInt64("id", 0)
  5094. order, _ := service.GetHisOrderByID(order_id)
  5095. if order.ID == 0 {
  5096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5097. return
  5098. }
  5099. org_id := c.GetAdminUserInfo().CurrentOrgId
  5100. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5101. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5102. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5103. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  5104. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  5105. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5106. var bedCostTotal float64 = 0 //床位总费
  5107. //var bedCostSelfTotal float64 = 0 //床位自费
  5108. var operationCostTotal float64 = 0 //手术费
  5109. //var operationCostSelfTotal float64 = 0 //手术费
  5110. var otherCostTotal float64 = 0 //其他费用
  5111. //var otherCostSelfTotal float64 = 0 //其他费用
  5112. var materialCostTotal float64 = 0 //材料费
  5113. //var materialCostSelfTotal float64 = 0 //材料费
  5114. var westernMedicineCostTotal float64 = 0 //西药费
  5115. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  5116. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5117. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5118. var checkCostTotal float64 = 0 //检查费
  5119. //var checkCostSelfTotal float64 = 0 //检查费
  5120. var laboratoryCostTotal float64 = 0 //化验费
  5121. //var laboratoryCostSelfTotal float64 = 0 //化验费
  5122. var treatCostTotal float64 = 0 //治疗费用
  5123. //var treatCostSelfTotal float64 = 0 //治疗费用
  5124. var zhenChaCostTotal float64 = 0 //其他费用
  5125. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5126. decimal.DivisionPrecision = 2
  5127. var BalanceAccountsType int64
  5128. if his.ID > 0 {
  5129. BalanceAccountsType = his.BalanceAccountsType
  5130. } else {
  5131. BalanceAccountsType = record.BalanceAccountsType
  5132. }
  5133. if BalanceAccountsType != 2 {
  5134. for _, item := range order_info {
  5135. if org_id == 10215 {
  5136. if item.MedChrgitmType == "01" { //床位费
  5137. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5138. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5139. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5140. }
  5141. if item.MedChrgitmType == "02" { //诊察费
  5142. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5143. //zhenChaCostSelfTotal = zhenChaCostTotal
  5144. }
  5145. if item.MedChrgitmType == "03" { //检查费
  5146. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5147. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5148. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5149. }
  5150. //if item.MedChrgitmType == "02" { //检查费
  5151. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5152. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5153. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5154. //}
  5155. if item.MedChrgitmType == "04" { //化验费
  5156. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5157. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5158. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5159. }
  5160. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5161. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5162. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5163. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5164. }
  5165. if item.MedChrgitmType == "06" { //手术费
  5166. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5167. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5168. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5169. }
  5170. if item.MedChrgitmType == "08" { //材料费
  5171. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5172. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5173. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5174. }
  5175. if item.MedChrgitmType == "09" { //西药费
  5176. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5177. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5178. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5179. }
  5180. if item.MedChrgitmType == "11" { //中成费
  5181. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5182. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5183. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5184. }
  5185. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5186. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5187. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5188. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5189. }
  5190. } else if org_id == 10188 || org_id == 10217 {
  5191. if item.MedChrgitmType == "01" { //床位费
  5192. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5193. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5194. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5195. }
  5196. if item.MedChrgitmType == "02" { //诊察费
  5197. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5198. //zhenChaCostSelfTotal = zhenChaCostTotal
  5199. }
  5200. if item.MedChrgitmType == "03" { //检查费
  5201. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5202. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5203. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5204. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5205. }
  5206. //if item.MedChrgitmType == "02" { //检查费
  5207. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5208. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5209. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5210. //}
  5211. if item.MedChrgitmType == "04" { //化验费
  5212. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5213. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5214. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5215. }
  5216. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5217. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5218. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5219. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5220. }
  5221. if item.MedChrgitmType == "06" { //手术费
  5222. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5223. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5224. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5225. }
  5226. if item.MedChrgitmType == "08" { //材料费
  5227. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5228. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5229. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5230. }
  5231. if item.MedChrgitmType == "09" { //西药费
  5232. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5233. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5234. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5235. }
  5236. if item.MedChrgitmType == "11" { //中成费
  5237. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5238. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5239. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5240. }
  5241. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5242. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5243. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5244. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5245. }
  5246. } else {
  5247. if item.MedChrgitmType == "01" { //床位费
  5248. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5249. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5250. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5251. }
  5252. //if item.MedChrgitmType == "02" { //诊察费
  5253. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5254. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5255. //}
  5256. if item.MedChrgitmType == "03" { //检查费
  5257. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5258. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5259. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5260. }
  5261. //if item.MedChrgitmType == "02" { //检查费
  5262. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5263. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5264. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5265. //}
  5266. if item.MedChrgitmType == "04" { //化验费
  5267. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5268. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5269. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5270. }
  5271. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5272. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5273. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5274. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5275. }
  5276. if item.MedChrgitmType == "06" { //手术费
  5277. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5278. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5279. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5280. }
  5281. if item.MedChrgitmType == "08" { //材料费
  5282. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5283. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5284. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5285. }
  5286. if item.MedChrgitmType == "09" { //西药费
  5287. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5288. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5289. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5290. }
  5291. if item.MedChrgitmType == "11" { //中成费
  5292. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5293. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5294. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5295. }
  5296. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5297. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5298. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5299. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5300. }
  5301. }
  5302. }
  5303. c.ServeSuccessJSON(map[string]interface{}{
  5304. "order": order,
  5305. "order_info": order_info,
  5306. "patient": patient,
  5307. "admin_info": adminInfo,
  5308. "his_hospital": record,
  5309. "bedCostTotal": bedCostTotal,
  5310. "operationCostTotal": operationCostTotal,
  5311. "otherCostTotal": otherCostTotal,
  5312. "materialCostTotal": materialCostTotal,
  5313. "westernMedicineCostTotal": westernMedicineCostTotal,
  5314. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5315. "checkCostTotal": checkCostTotal,
  5316. "zhenChaCostTotal": zhenChaCostTotal,
  5317. "laboratoryCostTotal": laboratoryCostTotal,
  5318. "treatCostTotal": treatCostTotal,
  5319. })
  5320. } else {
  5321. for _, item := range order_info {
  5322. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5323. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5324. item.MedChrgitmType = "09"
  5325. }
  5326. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5327. if item.HisPrescriptionProject.Type == 2 {
  5328. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5329. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5330. case 0:
  5331. item.MedChrgitmType = "0"
  5332. break
  5333. case 1:
  5334. item.MedChrgitmType = "14"
  5335. break
  5336. case 2:
  5337. item.MedChrgitmType = "05"
  5338. break
  5339. case 3:
  5340. item.MedChrgitmType = "03"
  5341. break
  5342. case 4:
  5343. item.MedChrgitmType = "03"
  5344. break
  5345. case 5:
  5346. item.MedChrgitmType = "08"
  5347. break
  5348. case 6:
  5349. item.MedChrgitmType = "14"
  5350. break
  5351. case 7:
  5352. item.MedChrgitmType = "14"
  5353. break
  5354. case 8:
  5355. item.MedChrgitmType = "03"
  5356. break
  5357. case 9:
  5358. item.MedChrgitmType = "14"
  5359. break
  5360. case 10:
  5361. item.MedChrgitmType = "14"
  5362. break
  5363. case 11:
  5364. item.MedChrgitmType = "06"
  5365. break
  5366. case 12:
  5367. item.MedChrgitmType = "12"
  5368. break
  5369. case 13:
  5370. item.MedChrgitmType = "01"
  5371. break
  5372. case 14:
  5373. item.MedChrgitmType = "04"
  5374. break
  5375. case 15:
  5376. item.MedChrgitmType = "14"
  5377. break
  5378. }
  5379. } else {
  5380. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5381. case 1:
  5382. item.MedChrgitmType = "14"
  5383. break
  5384. case 2:
  5385. item.MedChrgitmType = "05"
  5386. break
  5387. case 3:
  5388. item.MedChrgitmType = "04"
  5389. break
  5390. case 4:
  5391. item.MedChrgitmType = "14"
  5392. break
  5393. case 5:
  5394. item.MedChrgitmType = "08"
  5395. break
  5396. case 6:
  5397. item.MedChrgitmType = "14"
  5398. break
  5399. case 7:
  5400. item.MedChrgitmType = "14"
  5401. break
  5402. case 8:
  5403. item.MedChrgitmType = "03"
  5404. break
  5405. case 9:
  5406. item.MedChrgitmType = "14"
  5407. break
  5408. }
  5409. }
  5410. } else if item.HisPrescriptionProject.Type == 3 {
  5411. item.MedChrgitmType = "08"
  5412. }
  5413. }
  5414. }
  5415. for _, item := range order_info {
  5416. if org_id == 10215 {
  5417. if item.MedChrgitmType == "01" { //床位费
  5418. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5419. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5420. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5421. }
  5422. if item.MedChrgitmType == "02" { //诊察费
  5423. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5424. //zhenChaCostSelfTotal = zhenChaCostTotal
  5425. }
  5426. if item.MedChrgitmType == "03" { //检查费
  5427. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5428. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5429. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5430. }
  5431. //if item.MedChrgitmType == "02" { //检查费
  5432. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5433. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5434. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5435. //}
  5436. if item.MedChrgitmType == "04" { //化验费
  5437. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5438. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5439. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5440. }
  5441. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5442. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5443. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5444. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5445. }
  5446. if item.MedChrgitmType == "06" { //手术费
  5447. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5448. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5449. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5450. }
  5451. if item.MedChrgitmType == "08" { //材料费
  5452. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5453. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5454. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5455. }
  5456. if item.MedChrgitmType == "09" { //西药费
  5457. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5458. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5459. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5460. }
  5461. if item.MedChrgitmType == "11" { //中成费
  5462. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5463. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5464. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5465. }
  5466. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5467. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5468. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5469. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5470. }
  5471. } else {
  5472. if item.MedChrgitmType == "01" { //床位费
  5473. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5474. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5475. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5476. }
  5477. //if item.MedChrgitmType == "02" { //诊察费
  5478. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5479. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5480. //}
  5481. if item.MedChrgitmType == "03" { //检查费
  5482. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5483. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5484. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5485. }
  5486. //if item.MedChrgitmType == "02" { //检查费
  5487. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5488. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5489. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5490. //}
  5491. if item.MedChrgitmType == "04" { //化验费
  5492. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5493. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5494. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5495. }
  5496. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5497. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5498. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5499. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5500. }
  5501. if item.MedChrgitmType == "06" { //手术费
  5502. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5503. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5504. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5505. }
  5506. if item.MedChrgitmType == "08" { //材料费
  5507. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5508. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5509. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5510. }
  5511. if item.MedChrgitmType == "09" { //西药费
  5512. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5513. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5514. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5515. }
  5516. if item.MedChrgitmType == "11" { //中成费
  5517. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5518. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5519. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5520. }
  5521. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5522. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5523. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5524. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5525. }
  5526. }
  5527. }
  5528. c.ServeSuccessJSON(map[string]interface{}{
  5529. "order": order,
  5530. "order_info": order_info,
  5531. "patient": patient,
  5532. "admin_info": adminInfo,
  5533. "his_hospital": record,
  5534. "bedCostTotal": bedCostTotal,
  5535. "operationCostTotal": operationCostTotal,
  5536. "otherCostTotal": otherCostTotal,
  5537. "materialCostTotal": materialCostTotal,
  5538. "westernMedicineCostTotal": westernMedicineCostTotal,
  5539. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5540. "checkCostTotal": checkCostTotal,
  5541. "zhenChaCostTotal": zhenChaCostTotal,
  5542. "laboratoryCostTotal": laboratoryCostTotal,
  5543. "treatCostTotal": treatCostTotal,
  5544. })
  5545. }
  5546. }
  5547. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5548. page, _ := c.GetInt64("page")
  5549. limit, _ := c.GetInt64("limit")
  5550. keywords := c.GetString("keywords")
  5551. start_time := c.GetString("start_time")
  5552. end_time := c.GetString("end_time")
  5553. //clr_type := c.GetString("clr_type")
  5554. insutype := c.GetString("insutype")
  5555. timeLayout := "2006-01-02"
  5556. loc, _ := time.LoadLocation("Local")
  5557. var theStartTIme int64
  5558. if len(start_time) > 0 {
  5559. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5560. theStartTIme = theTime.Unix()
  5561. }
  5562. var theEndtTIme int64
  5563. if len(end_time) > 0 {
  5564. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5565. theEndtTIme = theTime.Unix()
  5566. }
  5567. if page <= 0 {
  5568. page = 1
  5569. }
  5570. if limit <= 0 {
  5571. limit = 10
  5572. }
  5573. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5574. c.ServeSuccessJSON(map[string]interface{}{
  5575. "total": total,
  5576. "list": list,
  5577. })
  5578. return
  5579. }
  5580. func (c *HisApiController) GetPutOnRecordList() {
  5581. page, _ := c.GetInt64("page")
  5582. limit, _ := c.GetInt64("limit")
  5583. keywords := c.GetString("keywords")
  5584. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5585. if page <= 0 {
  5586. page = 1
  5587. }
  5588. if limit <= 0 {
  5589. limit = 10
  5590. }
  5591. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5592. c.ServeSuccessJSON(map[string]interface{}{
  5593. "total": total,
  5594. "list": list,
  5595. })
  5596. return
  5597. }
  5598. func (c *HisApiController) GetCompareData() {
  5599. start_time := c.GetString("start_time")
  5600. end_time := c.GetString("end_time")
  5601. insutype := c.GetString("insutype")
  5602. clr_type := c.GetString("clr_type")
  5603. timeLayout := "2006-01-02"
  5604. loc, _ := time.LoadLocation("Local")
  5605. var theStartTIme int64
  5606. if len(start_time) > 0 {
  5607. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5608. if err != nil {
  5609. theStartTIme = 0
  5610. }
  5611. theStartTIme = theTime.Unix()
  5612. }
  5613. var theEndtTIme int64
  5614. if len(end_time) > 0 {
  5615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5616. if err != nil {
  5617. theEndtTIme = 0
  5618. }
  5619. theEndtTIme = theTime.Unix()
  5620. }
  5621. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5622. fmt.Println(err)
  5623. if err == nil {
  5624. c.ServeSuccessJSON(map[string]interface{}{
  5625. "list": formData,
  5626. })
  5627. } else {
  5628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5629. return
  5630. }
  5631. }
  5632. func (c *HisApiController) GetFaPiaoData() {
  5633. order_id, _ := c.GetInt64("order_id")
  5634. patient_id, _ := c.GetInt64("patient_id")
  5635. number := c.GetString("number")
  5636. adminUser := c.GetAdminUserInfo()
  5637. order, _ := service.GetHisOrderByID(order_id)
  5638. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5639. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5640. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5641. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5642. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5643. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5644. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5645. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5646. var bedCostTotal float64 = 0 //床位总费
  5647. var bedCostSelfTotal float64 = 0 //床位自费
  5648. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5649. var operationCostTotal float64 = 0 //手术费
  5650. var operationCostSelfTotal float64 = 0 //手术费
  5651. var operationCostPartSelfTotal float64 = 0 //手术费
  5652. var otherCostTotal float64 = 0 //其他费用
  5653. var otherCostSelfTotal float64 = 0 //其他费用
  5654. var otherCostPartSelfTotal float64 = 0 //其他费用
  5655. var materialCostTotal float64 = 0 //材料费
  5656. var materialCostSelfTotal float64 = 0 //材料费
  5657. var materialCostPartSelfTotal float64 = 0 //材料费
  5658. var westernMedicineCostTotal float64 = 0 //西药费
  5659. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5660. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5661. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5662. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5663. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5664. var checkCostTotal float64 = 0 //检查费
  5665. var checkCostSelfTotal float64 = 0 //检查费
  5666. var checkCostPartSelfTotal float64 = 0 //检查费
  5667. var laboratoryCostTotal float64 = 0 //化验费
  5668. var laboratoryCostSelfTotal float64 = 0 //化验费
  5669. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5670. var treatCostTotal float64 = 0 //治疗费用
  5671. var treatCostSelfTotal float64 = 0 //治疗费用
  5672. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5673. var zhenChaCostTotal float64 = 0 //其他费用
  5674. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5675. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5676. decimal.DivisionPrecision = 2
  5677. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5678. var balanceAccountsType int64
  5679. if his.ID > 0 {
  5680. balanceAccountsType = his.BalanceAccountsType
  5681. } else {
  5682. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5683. }
  5684. if balanceAccountsType == 2 {
  5685. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5686. for _, item := range orderInfos_two {
  5687. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5688. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5689. item.MedChrgitmType = "09"
  5690. }
  5691. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5692. if item.HisPrescriptionProject.Type == 2 {
  5693. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5694. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5695. case 0:
  5696. item.MedChrgitmType = "0"
  5697. break
  5698. case 1:
  5699. item.MedChrgitmType = "14"
  5700. break
  5701. case 2:
  5702. item.MedChrgitmType = "05"
  5703. break
  5704. case 3:
  5705. item.MedChrgitmType = "03"
  5706. break
  5707. case 4:
  5708. item.MedChrgitmType = "03"
  5709. break
  5710. case 5:
  5711. item.MedChrgitmType = "08"
  5712. break
  5713. case 6:
  5714. item.MedChrgitmType = "14"
  5715. break
  5716. case 7:
  5717. item.MedChrgitmType = "14"
  5718. break
  5719. case 8:
  5720. item.MedChrgitmType = "03"
  5721. break
  5722. case 9:
  5723. item.MedChrgitmType = "14"
  5724. break
  5725. case 10:
  5726. item.MedChrgitmType = "14"
  5727. break
  5728. case 11:
  5729. item.MedChrgitmType = "06"
  5730. break
  5731. case 12:
  5732. item.MedChrgitmType = "12"
  5733. break
  5734. case 13:
  5735. item.MedChrgitmType = "01"
  5736. break
  5737. case 14:
  5738. item.MedChrgitmType = "04"
  5739. break
  5740. case 15:
  5741. item.MedChrgitmType = "02"
  5742. break
  5743. }
  5744. } else {
  5745. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5746. case 1:
  5747. item.MedChrgitmType = "14"
  5748. break
  5749. case 2:
  5750. item.MedChrgitmType = "05"
  5751. break
  5752. case 3:
  5753. item.MedChrgitmType = "03"
  5754. break
  5755. case 4:
  5756. item.MedChrgitmType = "03"
  5757. break
  5758. case 5:
  5759. item.MedChrgitmType = "08"
  5760. break
  5761. case 6:
  5762. item.MedChrgitmType = "14"
  5763. break
  5764. case 7:
  5765. item.MedChrgitmType = "14"
  5766. break
  5767. case 8:
  5768. item.MedChrgitmType = "03"
  5769. break
  5770. case 9:
  5771. item.MedChrgitmType = "14"
  5772. break
  5773. }
  5774. }
  5775. } else if item.HisPrescriptionProject.Type == 3 {
  5776. item.MedChrgitmType = "08"
  5777. }
  5778. }
  5779. }
  5780. for _, item := range orderInfos_two {
  5781. fmt.Println(item.MedChrgitmType)
  5782. if item.MedChrgitmType == "01" { //床位费
  5783. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5784. bedCostSelfTotal = bedCostTotal
  5785. }
  5786. if item.MedChrgitmType == "02" { //诊察费
  5787. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5788. zhenChaCostSelfTotal = zhenChaCostTotal
  5789. }
  5790. if item.MedChrgitmType == "03" { //检查费
  5791. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5792. checkCostSelfTotal = checkCostTotal
  5793. }
  5794. if item.MedChrgitmType == "04" { //化验费
  5795. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5796. laboratoryCostSelfTotal = laboratoryCostTotal
  5797. }
  5798. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5799. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5800. treatCostSelfTotal = treatCostTotal
  5801. }
  5802. if item.MedChrgitmType == "06" { //手术费
  5803. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5804. operationCostSelfTotal = treatCostTotal
  5805. }
  5806. if item.MedChrgitmType == "08" { //材料费
  5807. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5808. materialCostSelfTotal = materialCostTotal
  5809. }
  5810. if item.MedChrgitmType == "09" { //西药费
  5811. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5812. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5813. }
  5814. if item.MedChrgitmType == "11" { //中成费
  5815. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5816. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5817. }
  5818. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  5819. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5820. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5821. otherCostSelfTotal = otherCostTotal
  5822. }
  5823. } else {
  5824. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5825. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5826. otherCostSelfTotal = otherCostTotal
  5827. }
  5828. }
  5829. }
  5830. } else {
  5831. for _, item := range orderInfos {
  5832. if item.MedChrgitmType == "01" { //床位费
  5833. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5834. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5835. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5836. }
  5837. if item.MedChrgitmType == "02" { //诊察费
  5838. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5839. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5840. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5841. }
  5842. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  5843. if item.MedChrgitmType == "03" { //检查费
  5844. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5845. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5846. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5847. }
  5848. } else {
  5849. if item.MedChrgitmType == "03" { //检查费
  5850. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5851. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5852. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5853. }
  5854. }
  5855. if item.MedChrgitmType == "04" { //化验费
  5856. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5857. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5858. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5859. }
  5860. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5861. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5862. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5863. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5864. }
  5865. if item.MedChrgitmType == "06" { //手术费
  5866. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5867. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5868. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5869. }
  5870. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  5871. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5872. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5873. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5874. }
  5875. if item.MedChrgitmType == "09" { //西药费
  5876. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5877. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5878. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5879. }
  5880. if item.MedChrgitmType == "11" { //中成费
  5881. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5882. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5883. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5884. }
  5885. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5886. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5887. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5888. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5889. }
  5890. }
  5891. }
  5892. timeLayout := "2006-01-02"
  5893. loc, _ := time.LoadLocation("Local")
  5894. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  5895. if err != nil {
  5896. }
  5897. startRecordDateTime := startTime.Unix()
  5898. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  5899. if err != nil {
  5900. }
  5901. endRecordDateTime := endTime.Unix()
  5902. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  5903. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  5904. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5905. c.ServeSuccessJSON(map[string]interface{}{
  5906. "order_number": order.Number, //业务流水号
  5907. "id_card_no": his.IdCardNo, //社会保障号
  5908. "department_name": department.Name, //科室
  5909. "number": his.Number, //门诊号
  5910. "date": order.SettleAccountsDate, //结算日期
  5911. "name": order.PsnName, //姓名
  5912. "gender": patient.Gender, //性别
  5913. "psn_cash_money": order.PsnCashPay, //个人支付
  5914. "pay_way": "门诊", //结算方式
  5915. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5916. "admin_user_name": admin.UserName, //收款员
  5917. "order": order,
  5918. "order_info": orderInfos_two,
  5919. "his": his,
  5920. "bedCostTotal": bedCostTotal,
  5921. "bedCostSelfTotal": bedCostSelfTotal,
  5922. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5923. "operationCostTotal": operationCostTotal,
  5924. "operationCostSelfTotal": operationCostSelfTotal,
  5925. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5926. "otherCostTotal": otherCostTotal,
  5927. "otherCostSelfTotal": otherCostSelfTotal,
  5928. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5929. "materialCostTotal": materialCostTotal,
  5930. "materialCostSelfTotal": materialCostSelfTotal,
  5931. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5932. "westernMedicineCostTotal": westernMedicineCostTotal,
  5933. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5934. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5935. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5936. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5937. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5938. "checkCostTotal": checkCostTotal,
  5939. "checkCostSelfTotal": checkCostSelfTotal,
  5940. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5941. "laboratoryCostTotal": laboratoryCostTotal,
  5942. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5943. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5944. "treatCostTotal": treatCostTotal,
  5945. "treatCostSelfTotal": treatCostSelfTotal,
  5946. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5947. "zhenChaCostTotal": zhenChaCostTotal,
  5948. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5949. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5950. "his_hospital_record": his_hospital_record,
  5951. "pre_pay_money": pre_pay_money,
  5952. "refund_sum": sum,
  5953. })
  5954. }
  5955. func (this *HisApiController) GetIncomeStatisticsData() {
  5956. start_time := this.GetString("start_time")
  5957. end_time := this.GetString("end_time")
  5958. key_words := this.GetString("key_words")
  5959. limit, _ := this.GetInt64("limit")
  5960. page, _ := this.GetInt64("page")
  5961. if page <= 0 {
  5962. page = 1
  5963. }
  5964. if limit <= 0 {
  5965. limit = 10
  5966. }
  5967. statistics_type, _ := this.GetInt64("statistics_type")
  5968. admin := this.GetAdminUserInfo()
  5969. timeLayout := "2006-01-02"
  5970. loc, _ := time.LoadLocation("Local")
  5971. var theStartTIme int64
  5972. if len(start_time) > 0 {
  5973. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5974. if err != nil {
  5975. theStartTIme = 0
  5976. }
  5977. theStartTIme = theTime.Unix()
  5978. }
  5979. var theEndtTIme int64
  5980. if len(end_time) > 0 {
  5981. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5982. if err != nil {
  5983. theEndtTIme = 0
  5984. }
  5985. theEndtTIme = theTime.Unix()
  5986. }
  5987. if statistics_type == 1 {
  5988. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5989. this.ServeSuccessJSON(map[string]interface{}{
  5990. "list": list,
  5991. "total": total,
  5992. })
  5993. } else {
  5994. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5995. this.ServeSuccessJSON(map[string]interface{}{
  5996. "list": list,
  5997. "total": total,
  5998. })
  5999. }
  6000. }
  6001. func (c *HisApiController) PostProjectInformation() {
  6002. adminUser := c.GetAdminUserInfo()
  6003. orgId := adminUser.CurrentOrgId
  6004. dataBody := make(map[string]interface{}, 0)
  6005. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6006. if err != nil {
  6007. utils.ErrorLog(err.Error())
  6008. return
  6009. }
  6010. utils.ErrorLog("%v", dataBody)
  6011. var projectList []*models.HisProject
  6012. var total_goods []interface{}
  6013. tempProjects := dataBody["projects"].([]interface{})
  6014. total_goods = tempProjects
  6015. for index, projectMap := range tempProjects {
  6016. projectM := projectMap.(map[string]interface{})
  6017. var project models.HisProject
  6018. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  6019. utils.ErrorLog("project_name")
  6020. return
  6021. }
  6022. project_name, _ := projectM["project_name"].(string)
  6023. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  6024. err_log := models.ExportErrLog{
  6025. LogType: 6,
  6026. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6027. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  6028. Status: 1,
  6029. CreateTime: time.Now().Unix(),
  6030. UpdateTime: time.Now().Unix(),
  6031. ExportTime: time.Now().Unix(),
  6032. }
  6033. service.CreateExportErrLog(&err_log)
  6034. continue
  6035. }
  6036. project.ProjectName = project_name
  6037. prices := projectM["price"].(string)
  6038. price, _ := strconv.ParseFloat(prices, 64)
  6039. if price <= 0 { //名字为空则生成一条导入错误日志
  6040. err_log := models.ExportErrLog{
  6041. LogType: 6,
  6042. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6043. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  6044. Status: 1,
  6045. CreateTime: time.Now().Unix(),
  6046. UpdateTime: time.Now().Unix(),
  6047. ExportTime: time.Now().Unix(),
  6048. }
  6049. service.CreateExportErrLog(&err_log)
  6050. continue
  6051. }
  6052. project.Price = price
  6053. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  6054. utils.ErrorLog("unit_id")
  6055. return
  6056. }
  6057. unit := projectM["unit"].(string)
  6058. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  6059. err_log := models.ExportErrLog{
  6060. LogType: 6,
  6061. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6062. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  6063. Status: 1,
  6064. CreateTime: time.Now().Unix(),
  6065. UpdateTime: time.Now().Unix(),
  6066. ExportTime: time.Now().Unix(),
  6067. }
  6068. service.CreateExportErrLog(&err_log)
  6069. continue
  6070. }
  6071. project.Unit = unit
  6072. cost_classify := projectM["cost_classify"].(string)
  6073. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  6074. err_log := models.ExportErrLog{
  6075. LogType: 6,
  6076. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6077. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  6078. Status: 1,
  6079. CreateTime: time.Now().Unix(),
  6080. UpdateTime: time.Now().Unix(),
  6081. ExportTime: time.Now().Unix(),
  6082. }
  6083. service.CreateExportErrLog(&err_log)
  6084. continue
  6085. }
  6086. var costClassify = "费用类别"
  6087. var cost_classify_id int64
  6088. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  6089. if len(cost_classify) != 0 {
  6090. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  6091. if errcode == gorm.ErrRecordNotFound {
  6092. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  6093. dataconfig := models.DictDataconfig{
  6094. ParentId: costClassifyConfig.ID,
  6095. Module: "system",
  6096. OrgId: orgId,
  6097. Name: cost_classify,
  6098. FieldName: "",
  6099. Value: costConfig.Value + 1,
  6100. CreatedTime: "",
  6101. UpdatedTime: "",
  6102. CreateUserId: adminUser.AdminUser.Id,
  6103. Status: 1,
  6104. Remark: "",
  6105. DeleteIdSystem: 0,
  6106. Title: "",
  6107. Content: "",
  6108. Order: 0,
  6109. Code: "",
  6110. }
  6111. service.CreatedDicConfig(&dataconfig)
  6112. }
  6113. }
  6114. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  6115. for _, it := range costClassList {
  6116. if cost_classify == it.Name {
  6117. cost_classify_id = int64(it.Value)
  6118. }
  6119. }
  6120. project.CostClassify = cost_classify_id
  6121. executive_section := projectM["executive_section"].(string)
  6122. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  6123. err_log := models.ExportErrLog{
  6124. LogType: 6,
  6125. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6126. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  6127. Status: 1,
  6128. CreateTime: time.Now().Unix(),
  6129. UpdateTime: time.Now().Unix(),
  6130. ExportTime: time.Now().Unix(),
  6131. }
  6132. service.CreateExportErrLog(&err_log)
  6133. continue
  6134. }
  6135. if len(executive_section) != 0 {
  6136. //查找科室是否有内容
  6137. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  6138. if errcodedepart == gorm.ErrRecordNotFound {
  6139. department := models.XtHisDepartment{
  6140. Name: executive_section,
  6141. Status: 1,
  6142. UserOrgId: adminUser.CurrentOrgId,
  6143. CreatedTime: time.Now().Unix(),
  6144. }
  6145. service.CreateDePartment(&department)
  6146. }
  6147. }
  6148. var executive_section_id int64
  6149. departMentList, _ := service.GetAllDepartMent(orgId)
  6150. for _, it := range departMentList {
  6151. if executive_section == it.Name {
  6152. executive_section_id = it.ID
  6153. }
  6154. }
  6155. project.ExecutiveSection = executive_section_id
  6156. medical_coverage := projectM["medical_coverage"].(string)
  6157. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  6158. err_log := models.ExportErrLog{
  6159. LogType: 6,
  6160. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6161. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  6162. Status: 1,
  6163. CreateTime: time.Now().Unix(),
  6164. UpdateTime: time.Now().Unix(),
  6165. ExportTime: time.Now().Unix(),
  6166. }
  6167. service.CreateExportErrLog(&err_log)
  6168. continue
  6169. }
  6170. var medicalCoverage = "医保等级"
  6171. var medical_coverage_id int64
  6172. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  6173. if len(medical_coverage) != 0 {
  6174. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  6175. if errormedicalcoverage == gorm.ErrRecordNotFound {
  6176. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  6177. dataconfig := models.DictDataconfig{
  6178. ParentId: medicalCoverageConfig.ID,
  6179. Module: "system",
  6180. OrgId: orgId,
  6181. Name: medical_coverage,
  6182. FieldName: "",
  6183. Value: medicalCoverageConfig.Value + 1,
  6184. CreatedTime: "",
  6185. UpdatedTime: "",
  6186. CreateUserId: adminUser.AdminUser.Id,
  6187. Status: 1,
  6188. Remark: "",
  6189. DeleteIdSystem: 0,
  6190. Title: "",
  6191. Content: "",
  6192. Order: 0,
  6193. Code: "",
  6194. }
  6195. service.CreatedDicConfig(&dataconfig)
  6196. }
  6197. }
  6198. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  6199. for _, it := range medicalCoverageList {
  6200. if medical_coverage == it.Name {
  6201. medical_coverage_id = int64(it.Value)
  6202. }
  6203. }
  6204. project.MedicalCoverage = medical_coverage_id
  6205. pinyin := projectM["pinyin"].(string)
  6206. project.Pinyin = pinyin
  6207. wubi := projectM["wubi"].(string)
  6208. project.Wubi = wubi
  6209. statistical_classification := projectM["statistical_classification"].(string)
  6210. var statisticalClassification = "统计分类"
  6211. var statistical_classification_id int64
  6212. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  6213. if len(statistical_classification) != 0 {
  6214. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  6215. if classificationerrcodes == gorm.ErrRecordNotFound {
  6216. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  6217. dataconfig := models.DictDataconfig{
  6218. ParentId: classiFication.ID,
  6219. Module: "system",
  6220. OrgId: orgId,
  6221. Name: statistical_classification,
  6222. FieldName: "",
  6223. Value: classiFicationConfig.Value + 1,
  6224. CreatedTime: "",
  6225. UpdatedTime: "",
  6226. CreateUserId: adminUser.AdminUser.Id,
  6227. Status: 1,
  6228. Remark: "",
  6229. DeleteIdSystem: 0,
  6230. Title: "",
  6231. Content: "",
  6232. Order: 0,
  6233. Code: "",
  6234. }
  6235. service.CreatedDicConfig(&dataconfig)
  6236. }
  6237. }
  6238. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  6239. for _, it := range classiFicationList {
  6240. if statistical_classification == it.Name {
  6241. statistical_classification_id = int64(it.Value)
  6242. }
  6243. }
  6244. project.StatisticalClassification = statistical_classification_id
  6245. disease_directory := int64(projectM["disease_directory"].(float64))
  6246. project.DiseaseDirectory = disease_directory
  6247. is_record := int64(projectM["is_record"].(float64))
  6248. project.IsRecord = is_record
  6249. medical_code := projectM["medical_code"].(string)
  6250. project.MedicalCode = medical_code
  6251. tube_color := projectM["tube_color"].(string)
  6252. var tubeColor = "试管颜色"
  6253. var tube_color_id int64
  6254. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  6255. if len(tube_color) != 0 {
  6256. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  6257. if errcodetube == gorm.ErrRecordNotFound {
  6258. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  6259. dataconfig := models.DictDataconfig{
  6260. ParentId: tubeColorConfig.ID,
  6261. Module: "system",
  6262. OrgId: orgId,
  6263. Name: tube_color,
  6264. FieldName: "",
  6265. Value: tubeConfig.Value + 1,
  6266. CreatedTime: "",
  6267. UpdatedTime: "",
  6268. CreateUserId: adminUser.AdminUser.Id,
  6269. Status: 1,
  6270. Remark: "",
  6271. DeleteIdSystem: 0,
  6272. Title: "",
  6273. Content: "",
  6274. Order: 0,
  6275. Code: "",
  6276. }
  6277. service.CreatedDicConfig(&dataconfig)
  6278. }
  6279. }
  6280. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  6281. for _, it := range tubeColorList {
  6282. if tube_color == it.Name {
  6283. tube_color_id = int64(it.Value)
  6284. }
  6285. }
  6286. project.TubeColor = tube_color_id
  6287. single_dose := projectM["single_dose"].(string)
  6288. project.SingleDose = single_dose
  6289. execution_frequency := projectM["execution_frequency"].(string)
  6290. project.ExecutionFrequency = execution_frequency
  6291. delivery_way := projectM["delivery_way"].(string)
  6292. project.DeliveryWay = delivery_way
  6293. number_days := projectM["number_days"].(string)
  6294. project.NumberDays = number_days
  6295. total := projectM["total"].(string)
  6296. project.Total = total
  6297. medical_status := int64(projectM["medical_status"].(float64))
  6298. project.MedicalStatus = medical_status
  6299. category := int64(projectM["category"].(float64))
  6300. project.Category = category
  6301. specail_project := int64(projectM["specail_project"].(float64))
  6302. project.SpecailProject = specail_project
  6303. social_security_directory_code := projectM["social_security_directory_code"].(string)
  6304. project.SocialSecurityDirectoryCode = social_security_directory_code
  6305. remark := projectM["remark"].(string)
  6306. project.Remark = remark
  6307. record_date := projectM["record_date"].(string)
  6308. timeLayout := "2006-01-02"
  6309. loc, _ := time.LoadLocation("Local")
  6310. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6311. project.RecordDate = theTime.Unix()
  6312. projectList = append(projectList, &project)
  6313. }
  6314. export_time := time.Now().Unix()
  6315. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  6316. if len(projectList) > 0 {
  6317. for _, item := range projectList {
  6318. project := models.HisProject{
  6319. ProjectName: item.ProjectName,
  6320. Price: item.Price,
  6321. Unit: item.Unit,
  6322. CostClassify: item.CostClassify,
  6323. ExecutiveSection: item.ExecutiveSection,
  6324. MedicalCoverage: item.MedicalCoverage,
  6325. UserOrgId: orgId,
  6326. Status: 1,
  6327. CreatedTime: time.Now().Unix(),
  6328. Pinyin: item.Pinyin,
  6329. Wubi: item.Wubi,
  6330. StatisticalClassification: item.StatisticalClassification,
  6331. DiseaseDirectory: item.DiseaseDirectory,
  6332. IsRecord: item.IsRecord,
  6333. MedicalCode: item.MedicalCode,
  6334. TubeColor: item.TubeColor,
  6335. SingleDose: item.SingleDose,
  6336. DeliveryWay: item.DeliveryWay,
  6337. NumberDays: item.NumberDays,
  6338. Total: item.Total,
  6339. Category: item.Category,
  6340. MedicalStatus: item.MedicalStatus,
  6341. SpecailProject: item.SpecailProject,
  6342. RecordDate: item.RecordDate,
  6343. Remark: item.Remark,
  6344. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  6345. ExecutionFrequency: item.ExecutionFrequency,
  6346. }
  6347. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  6348. if errcodeproject == gorm.ErrRecordNotFound {
  6349. service.CreateProjectInfomation(&project)
  6350. } else if errcodeproject == nil {
  6351. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  6352. }
  6353. log := models.ExportLog{
  6354. LogType: 6,
  6355. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6356. TotalNum: int64(len(total_goods)),
  6357. FailNum: int64(len(errLogs)),
  6358. SuccessNum: int64(len(projectList)),
  6359. CreateTime: time.Now().Unix(),
  6360. UpdateTime: time.Now().Unix(),
  6361. ExportTime: export_time,
  6362. Status: 1,
  6363. }
  6364. service.CreateExportLog(&log)
  6365. c.ServeSuccessJSON(map[string]interface{}{
  6366. "msg": "导入成功",
  6367. "total_num": len(total_goods),
  6368. "success_num": len(projectList),
  6369. "fail_num": int64(len(errLogs)),
  6370. })
  6371. }
  6372. } else {
  6373. log := models.ExportLog{
  6374. LogType: 6,
  6375. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6376. TotalNum: int64(len(total_goods)),
  6377. FailNum: int64(len(errLogs)),
  6378. SuccessNum: int64(len(projectList)),
  6379. CreateTime: time.Now().Unix(),
  6380. UpdateTime: time.Now().Unix(),
  6381. ExportTime: export_time,
  6382. Status: 1,
  6383. }
  6384. service.CreateExportLog(&log)
  6385. c.ServeSuccessJSON(map[string]interface{}{
  6386. "msg": "导入成功",
  6387. "total_num": len(total_goods),
  6388. "success_num": len(projectList),
  6389. "fail_num": int64(len(errLogs)),
  6390. })
  6391. }
  6392. }
  6393. //func (this *HisApiController) EditProjectInformation(){
  6394. //
  6395. // id, _ := this.GetInt64("id")
  6396. // project_team := this.GetString("project_team")
  6397. // price := this.GetString("price")
  6398. // price_float, _ := strconv.ParseFloat(price, 64)
  6399. // pinyin := this.GetString("pinyin")
  6400. // wubi := this.GetString("wubi")
  6401. // tube_color, _ := this.GetInt64("tube_color")
  6402. // team_type, _ := this.GetInt64("team_type")
  6403. // remark := this.GetString("remark")
  6404. // ids := this.GetString("ids")
  6405. // item_id := this.GetString("item_id")
  6406. // projectTeam := models.XtHisProjectTeam{
  6407. // ProjectTeam: project_team,
  6408. // Price: price_float,
  6409. // Pinyin: pinyin,
  6410. // Wubi: wubi,
  6411. // TubeColor: tube_color,
  6412. // TeamType: team_type,
  6413. // Remark: remark,
  6414. // ProjectId: ids,
  6415. // ItemId: item_id,
  6416. // }
  6417. //
  6418. //
  6419. // dataBody := make(map[string]interface{}, 0)
  6420. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6421. // if err != nil {
  6422. // utils.ErrorLog(err.Error())
  6423. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6424. // return
  6425. // }
  6426. //
  6427. // err = service.UpdatedProjectTeam(id, &projectTeam)
  6428. //
  6429. //
  6430. // if err != nil {
  6431. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6432. // return
  6433. // }
  6434. //
  6435. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  6436. // infos, _ := dataBody["info"].([]interface{})
  6437. // if len(infos) > 0 {
  6438. // var ids []string
  6439. //
  6440. // for _, item := range infos {
  6441. // items := item.(map[string]interface{})
  6442. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6443. // utils.ErrorLog("id")
  6444. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6445. // return
  6446. // }
  6447. // id := int64(items["id"].(float64))
  6448. //
  6449. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6450. // utils.ErrorLog("type")
  6451. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6452. // return
  6453. // }
  6454. // types := int64(items["type"].(float64))
  6455. //
  6456. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6457. // utils.ErrorLog("number")
  6458. // }
  6459. //
  6460. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  6461. //
  6462. // projectList := models.XtHisProjectList{
  6463. // Number: number,
  6464. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  6465. // ProjectId: id,
  6466. // Status: 1,
  6467. // CreatedTime: time.Now().Unix(),
  6468. // UpdatedTime: time.Now().Unix(),
  6469. // TeamId: projectTeam.ID,
  6470. // Type: types,
  6471. // }
  6472. // list := projectList
  6473. //
  6474. // service.CreateProjectList(&list)
  6475. //
  6476. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  6477. //
  6478. // }
  6479. // ids_str := strings.Join(ids, ",")
  6480. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  6481. // service.SaveProjectTeam(&projectTeam)
  6482. // this.ServeSuccessJSON(map[string]interface{}{
  6483. // "projectTeam": projectTeam,
  6484. // })
  6485. // }
  6486. // }
  6487. //}
  6488. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6489. name := c.GetString("name")
  6490. mode_id, _ := c.GetInt64("mode", 0)
  6491. types, _ := c.GetInt64("type", 0)
  6492. patient_id, _ := c.GetInt64("patient_id", 0)
  6493. types = 1
  6494. adminInfo := c.GetAdminUserInfo()
  6495. template := &models.HisPrescriptionTemplate{
  6496. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6497. PatientId: patient_id,
  6498. Type: types,
  6499. Status: 1,
  6500. Ctime: time.Now().Unix(),
  6501. Mtime: time.Now().Unix(),
  6502. Name: name,
  6503. Mode: mode_id,
  6504. }
  6505. dataBody := make(map[string]interface{}, 0)
  6506. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6507. if err != nil {
  6508. utils.ErrorLog(err.Error())
  6509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6510. return
  6511. }
  6512. err = service.CreateHisPrescriptionTemplate(template)
  6513. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6514. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6515. if len(prescriptions) > 0 {
  6516. for _, item := range prescriptions {
  6517. items := item.(map[string]interface{})
  6518. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6519. utils.ErrorLog("type")
  6520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6521. return
  6522. }
  6523. types := int64(items["type"].(float64))
  6524. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6525. utils.ErrorLog("med_type")
  6526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6527. return
  6528. }
  6529. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6530. ctime := time.Now().Unix()
  6531. prescription := &models.HisPrescriptionInfoTemplate{
  6532. PatientId: patient_id,
  6533. UserOrgId: adminInfo.CurrentOrgId,
  6534. Ctime: ctime,
  6535. Mtime: ctime,
  6536. Type: types,
  6537. Modifier: adminInfo.AdminUser.Id,
  6538. Creator: adminInfo.AdminUser.Id,
  6539. Status: 1,
  6540. PTemplateId: template.ID,
  6541. MedType: med_type,
  6542. }
  6543. service.CreateHisPrescriptionInfoTemplate(prescription)
  6544. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6545. advices := items["advices"].([]interface{})
  6546. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6547. ctime := time.Now().Unix()
  6548. mtime := ctime
  6549. if len(advices) > 0 {
  6550. for _, advice := range advices {
  6551. var s models.HisPrescriptionAdviceTemplate
  6552. s.PrescriptionId = prescription.ID
  6553. s.AdviceType = 2
  6554. s.StopState = 2
  6555. s.ExecutionState = 2
  6556. s.Status = 1
  6557. s.UserOrgId = adminInfo.CurrentOrgId
  6558. s.CreatedTime = ctime
  6559. s.UpdatedTime = mtime
  6560. s.PatientId = patient_id
  6561. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6562. if errcode > 0 {
  6563. c.ServeFailJSONWithSGJErrorCode(errcode)
  6564. return
  6565. }
  6566. service.CreateHisPrescriptionAdviceTemplate(&s)
  6567. }
  6568. }
  6569. }
  6570. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6571. projects := items["project"].([]interface{})
  6572. if len(projects) > 0 {
  6573. for _, project := range projects {
  6574. var p models.HisPrescriptionProjectTemplate
  6575. p.PrescriptionId = prescription.ID
  6576. p.Ctime = time.Now().Unix()
  6577. p.Mtime = time.Now().Unix()
  6578. p.PatientId = patient_id
  6579. p.UserOrgId = adminInfo.CurrentOrgId
  6580. p.Status = 1
  6581. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6582. if errcode > 0 {
  6583. c.ServeFailJSONWithSGJErrorCode(errcode)
  6584. return
  6585. }
  6586. service.CreateHisPrescriptionProjectTemplate(&p)
  6587. }
  6588. }
  6589. }
  6590. }
  6591. c.ServeSuccessJSON(map[string]interface{}{
  6592. "msg": "创建成功",
  6593. })
  6594. }
  6595. }
  6596. }
  6597. func (c *HisApiController) PreSettle() {
  6598. id, _ := c.GetInt64("id")
  6599. record_time := c.GetString("record_time")
  6600. his_patient_id, _ := c.GetInt64("his_patient_id")
  6601. timeLayout := "2006-01-02"
  6602. loc, _ := time.LoadLocation("Local")
  6603. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6604. diagnosis_id := c.GetString("diagnosis")
  6605. sick_type, _ := c.GetInt64("sick_type")
  6606. reg_type, _ := c.GetInt64("p_type")
  6607. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6609. if err != nil {
  6610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6611. return
  6612. }
  6613. recordDateTime := theTime.Unix()
  6614. adminUser := c.GetAdminUserInfo()
  6615. var prescriptions []*models.HisPrescription
  6616. var start_time int64
  6617. var end_time int64
  6618. ids_str := c.GetString("ids")
  6619. ids_arr := strings.Split(ids_str, ",")
  6620. fmt.Println(reg_type)
  6621. if settle_accounts_type == 1 { //日结
  6622. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6623. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6624. } else {
  6625. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6626. }
  6627. fmt.Println(prescriptions)
  6628. } else { //月结
  6629. start_time_str := c.GetString("start_time")
  6630. end_time_str := c.GetString("end_time")
  6631. timeLayout := "2006-01-02"
  6632. loc, _ := time.LoadLocation("Local")
  6633. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6634. if err != nil {
  6635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6636. return
  6637. }
  6638. recordStartTime := theStartTime.Unix()
  6639. start_time = recordStartTime
  6640. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6641. if err != nil {
  6642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6643. return
  6644. }
  6645. recordEndTime := theEndTime.Unix()
  6646. end_time = recordEndTime
  6647. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6648. }
  6649. if reg_type == 1111 || reg_type == 1112 {
  6650. reg_type = 11
  6651. }
  6652. timestamp := time.Now().Unix()
  6653. tempTime := time.Unix(timestamp, 0)
  6654. timeFormat := tempTime.Format("20060102150405")
  6655. chrgBchno := rand.Intn(100000) + 10000
  6656. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6657. strconv.FormatInt(his.PatientId, 10)
  6658. var ids []int64
  6659. for _, item := range prescriptions {
  6660. ids = append(ids, item.ID)
  6661. }
  6662. fmt.Println(ids)
  6663. var total float64
  6664. for _, item := range prescriptions {
  6665. fmt.Println(item)
  6666. if item.Type == 1 { //药品
  6667. for _, subItem := range item.HisDoctorAdviceInfo {
  6668. total = total + (subItem.Price * subItem.PrescribingNumber)
  6669. }
  6670. }
  6671. if item.Type == 2 { //项目
  6672. for _, subItem := range item.HisPrescriptionProject {
  6673. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6674. total = total + (subItem.Price * cnt)
  6675. }
  6676. }
  6677. for _, subItem := range item.HisAdditionalCharge {
  6678. total = total + (subItem.Price * float64(subItem.Count))
  6679. }
  6680. }
  6681. allTotal := fmt.Sprintf("%.2f", total)
  6682. totals, _ := strconv.ParseFloat(allTotal, 64)
  6683. order := &models.HisOrder{
  6684. UserOrgId: adminUser.CurrentOrgId,
  6685. HisPatientId: his.ID,
  6686. PatientId: id,
  6687. SettleAccountsDate: recordDateTime,
  6688. Ctime: time.Now().Unix(),
  6689. Mtime: time.Now().Unix(),
  6690. Status: 1,
  6691. OrderStatus: 1,
  6692. MdtrtId: his.Number,
  6693. Number: chrg_bchno,
  6694. MedfeeSumamt: totals,
  6695. SettleEndTime: end_time,
  6696. SettleStartTime: start_time,
  6697. SettleType: settle_accounts_type,
  6698. PType: 2,
  6699. IsPre: 1,
  6700. MedType: strconv.Itoa(int(reg_type)),
  6701. Diagnosis: diagnosis_id,
  6702. }
  6703. err = service.CreateOrder(order)
  6704. if err != nil {
  6705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6706. return
  6707. }
  6708. var customs []*Custom
  6709. for _, item := range prescriptions {
  6710. fmt.Println(item.Type)
  6711. if item.Type == 1 { //药品
  6712. for _, subItem := range item.HisDoctorAdviceInfo {
  6713. cus := &Custom{
  6714. AdviceId: subItem.ID,
  6715. ProjectId: 0,
  6716. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6717. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6718. FeedetlSn: subItem.FeedetlSn,
  6719. Price: fmt.Sprintf("%.2f", subItem.Price),
  6720. MedListCodg: subItem.MedListCodg,
  6721. Type: 1,
  6722. }
  6723. customs = append(customs, cus)
  6724. }
  6725. }
  6726. if item.Type == 2 { //项目
  6727. for _, subItem := range item.HisPrescriptionProject {
  6728. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6729. cus := &Custom{
  6730. AdviceId: 0,
  6731. ProjectId: subItem.ID,
  6732. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6733. Cut: fmt.Sprintf("%.2f", cnt),
  6734. FeedetlSn: subItem.FeedetlSn,
  6735. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6736. MedListCodg: subItem.MedListCodg,
  6737. Type: 2,
  6738. }
  6739. customs = append(customs, cus)
  6740. }
  6741. }
  6742. for _, item := range item.HisAdditionalCharge {
  6743. cus := &Custom{
  6744. ItemId: item.ID,
  6745. AdviceId: 0,
  6746. ProjectId: 0,
  6747. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6748. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6749. FeedetlSn: item.FeedetlSn,
  6750. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6751. MedListCodg: item.XtHisAddtionConfig.Code,
  6752. Type: 3,
  6753. }
  6754. customs = append(customs, cus)
  6755. }
  6756. }
  6757. fmt.Println(customs)
  6758. for _, item := range customs {
  6759. var advice_id int64 = 0
  6760. var project_id int64 = 0
  6761. var item_id int64 = 0
  6762. var types int64 = 0
  6763. if item.Type == 1 {
  6764. advice_id = item.AdviceId
  6765. project_id = 0
  6766. item_id = 0
  6767. } else if item.Type == 2 {
  6768. advice_id = 0
  6769. item_id = 0
  6770. project_id = item.ProjectId
  6771. } else if item.Type == 3 {
  6772. advice_id = 0
  6773. item_id = item.ItemId
  6774. project_id = 0
  6775. }
  6776. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6777. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6778. pric, _ := strconv.ParseFloat(item.Price, 32)
  6779. info := &models.HisOrderInfo{
  6780. OrderNumber: order.Number,
  6781. UploadDate: time.Now().Unix(),
  6782. AdviceId: advice_id,
  6783. DetItemFeeSumamt: detItemFeeSumamt,
  6784. Cnt: cut,
  6785. Pric: pric,
  6786. PatientId: id,
  6787. Status: 1,
  6788. Mtime: time.Now().Unix(),
  6789. Ctime: time.Now().Unix(),
  6790. UserOrgId: adminUser.CurrentOrgId,
  6791. HisPatientId: his.ID,
  6792. OrderId: order.ID,
  6793. ProjectId: project_id,
  6794. Type: types,
  6795. ItemId: item_id,
  6796. }
  6797. service.CreateOrderInfo(info)
  6798. }
  6799. his.SickType = sick_type
  6800. service.UpdataHisPateint(&his)
  6801. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6802. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6803. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6804. if err == nil {
  6805. c.ServeSuccessJSON(map[string]interface{}{
  6806. "msg": "结算成功",
  6807. })
  6808. }
  6809. }
  6810. type CustomOrderInfo struct {
  6811. Name string
  6812. Spec string
  6813. Unit string
  6814. Count float64
  6815. Price float64
  6816. Total float64
  6817. }
  6818. func (c *HisApiController) GetPrivateExpensesInfo() {
  6819. order_id, _ := c.GetInt64("id", 0)
  6820. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6821. order, _ := service.GetHisOrderByID(order_id)
  6822. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6823. if order.ID == 0 {
  6824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6825. return
  6826. }
  6827. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6828. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6829. org_id := c.GetAdminUserInfo().CurrentOrgId
  6830. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6831. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6832. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6833. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6834. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6835. var orderInfos_four []*models.HisOrderInfoTwo
  6836. for _, item := range orderInfos_three {
  6837. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6838. item.HisPrescriptionProject.IsCheckTeam = 1
  6839. orderInfos_four = append(orderInfos_four, item)
  6840. }
  6841. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6842. item.HisPrescriptionProject.IsCheckTeam = 2
  6843. orderInfos_two = append(orderInfos_two, item)
  6844. }
  6845. }
  6846. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6847. var cus_slice []CustomOrderInfo
  6848. for _, item := range new_order_info {
  6849. var cus CustomOrderInfo
  6850. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6851. cus.Unit = ""
  6852. cus.Spec = ""
  6853. var total float64
  6854. for _, subItem := range orderInfos_four {
  6855. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6856. total = total + subItem.DetItemFeeSumamt
  6857. fmt.Println(subItem.DetItemFeeSumamt)
  6858. }
  6859. }
  6860. cus.Count = 1
  6861. cus.Total = total
  6862. cus_slice = append(cus_slice, cus)
  6863. }
  6864. orderInfos = append(orderInfos, orderInfos_two...)
  6865. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6866. orderInfos = append(orderInfos, orderInfos_three...)
  6867. }
  6868. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6869. c.ServeSuccessJSON(map[string]interface{}{
  6870. "order": order,
  6871. "order_info": orderInfos,
  6872. "patient": patient,
  6873. "admin_info": adminInfo,
  6874. "his": his,
  6875. "current_admin": role,
  6876. "org_config": miConfig,
  6877. "new_order_info": cus_slice,
  6878. })
  6879. }
  6880. func (this *HisApiController) ChangeMedType() {
  6881. med_type := this.GetString("med_type")
  6882. old_med_type := this.GetString("old_med_type")
  6883. ids := this.GetString("ids")
  6884. settle_type, _ := this.GetInt64("settle_type")
  6885. start_time := this.GetString("start_time")
  6886. end_time := this.GetString("end_time")
  6887. ids_arr := strings.Split(ids, ",")
  6888. if settle_type == 1 { //日结
  6889. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6890. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6891. prescription.MedType = med_type
  6892. err := service.SaveHisPrescription(&prescription)
  6893. if err == nil {
  6894. this.ServeSuccessJSON(map[string]interface{}{
  6895. "msg": "修改成功",
  6896. })
  6897. } else {
  6898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6899. return
  6900. }
  6901. } else if settle_type == 2 {
  6902. timeLayout := "2006-01-02"
  6903. loc, _ := time.LoadLocation("Local")
  6904. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6905. if err != nil {
  6906. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6907. return
  6908. }
  6909. recordStartTime := theStartTime.Unix()
  6910. start_time_timestamp := recordStartTime
  6911. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6912. if err != nil {
  6913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6914. return
  6915. }
  6916. recordEndTime := theEndTime.Unix()
  6917. end_time_timestamp := recordEndTime
  6918. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6919. if updateErr == nil {
  6920. this.ServeSuccessJSON(map[string]interface{}{
  6921. "msg": "修改成功",
  6922. })
  6923. } else {
  6924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6925. return
  6926. }
  6927. }
  6928. }
  6929. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6930. patient_id, _ := c.GetInt64("patient_id")
  6931. his_patient_id, _ := c.GetInt64("his_patient_id")
  6932. record_date := c.GetString("record_date")
  6933. start_time := c.GetString("start_time")
  6934. end_time := c.GetString("end_time")
  6935. order_status, _ := c.GetInt64("type", 0)
  6936. p_type, _ := c.GetInt64("p_type", 0)
  6937. order_id, _ := c.GetInt64("order_id", 0)
  6938. timeLayout := "2006-01-02"
  6939. loc, _ := time.LoadLocation("Local")
  6940. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6941. if err != nil {
  6942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6943. return
  6944. }
  6945. recordDateTime := theTime.Unix()
  6946. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6947. if err != nil {
  6948. }
  6949. startRecordDateTime := startTime.Unix()
  6950. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6951. if err != nil {
  6952. }
  6953. endRecordDateTime := endTime.Unix()
  6954. admin := c.GetAdminUserInfo()
  6955. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6956. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6957. order, _ := service.GetHisOrderByID(order_id)
  6958. var monthPrescriptions []*models.HisPrescription
  6959. if order_status == 1 || order_status == 0 {
  6960. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6961. } else if order_status == 2 {
  6962. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6963. }
  6964. var settle_total float64
  6965. for _, item := range monthPrescriptions {
  6966. if len(item.HisPrescriptionProject) > 0 {
  6967. for _, subItem := range item.HisPrescriptionProject {
  6968. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6969. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6970. settle_total = settle_total + total
  6971. }
  6972. }
  6973. if len(item.HisDoctorAdviceInfo) > 0 {
  6974. for _, subItem := range item.HisDoctorAdviceInfo {
  6975. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6976. settle_total = settle_total + total
  6977. }
  6978. }
  6979. }
  6980. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6981. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6982. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6983. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6984. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6985. //获取所有科室信息
  6986. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6987. c.ServeSuccessJSON(map[string]interface{}{
  6988. "his_info": his_patient_info,
  6989. "xt_info": xt_patient_info,
  6990. "case_history": case_history,
  6991. "info": patientPrescriptionInfo,
  6992. "last_info": lastPatientPrescriptionInfo,
  6993. "month_prescriptions": monthPrescriptions,
  6994. "order": order,
  6995. "doctors": doctors,
  6996. "department": department,
  6997. "settle_total": settle_total,
  6998. })
  6999. return
  7000. }
  7001. func (c *HisApiController) GetHisMonthPatientInfo() {
  7002. patient_id, _ := c.GetInt64("patient_id")
  7003. his_patient_id, _ := c.GetInt64("his_patient_id")
  7004. record_date := c.GetString("record_date")
  7005. number := c.GetString("number")
  7006. start_time := c.GetString("start_time")
  7007. end_time := c.GetString("end_time")
  7008. p_type, _ := c.GetInt64("p_type")
  7009. timeLayout := "2006-01-02"
  7010. loc, _ := time.LoadLocation("Local")
  7011. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7012. if err != nil {
  7013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7014. return
  7015. }
  7016. recordDateTime := theTime.Unix()
  7017. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7018. if err != nil {
  7019. }
  7020. startRecordDateTime := startTime.Unix()
  7021. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7022. if err != nil {
  7023. }
  7024. endRecordDateTime := endTime.Unix()
  7025. admin := c.GetAdminUserInfo()
  7026. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  7027. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7028. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  7029. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7030. var settle_total float64
  7031. for _, item := range monthPrescriptions {
  7032. if len(item.HisPrescriptionProject) > 0 {
  7033. for _, subItem := range item.HisPrescriptionProject {
  7034. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7035. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7036. settle_total = settle_total + total
  7037. }
  7038. }
  7039. if len(item.HisDoctorAdviceInfo) > 0 {
  7040. for _, subItem := range item.HisDoctorAdviceInfo {
  7041. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7042. settle_total = settle_total + total
  7043. }
  7044. }
  7045. }
  7046. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7047. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7048. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7049. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7050. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  7051. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7052. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  7053. //获取所有科室信息
  7054. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7055. c.ServeSuccessJSON(map[string]interface{}{
  7056. "his_info": his_patient_info,
  7057. "xt_info": xt_patient_info,
  7058. "case_history": case_history,
  7059. "info": patientPrescriptionInfo,
  7060. "month_prescriptions": monthPrescriptions,
  7061. "order": order,
  7062. "doctors": doctors,
  7063. "department": department,
  7064. "count": count,
  7065. "drugStockConfig": drugStockConfig,
  7066. "last_info": lastPatientPrescriptionInfo,
  7067. "settle_total": settle_total,
  7068. })
  7069. return
  7070. }
  7071. func (c *HisApiController) GetAllOrder() {
  7072. org_id := c.GetAdminUserInfo().CurrentOrgId
  7073. orders, _ := service.GetNewHisOrderList(org_id)
  7074. c.ServeSuccessJSON(map[string]interface{}{
  7075. "order": orders,
  7076. })
  7077. return
  7078. }
  7079. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  7080. newArr = make([]*models.HisOrderInfoTwo, 0)
  7081. for i := 0; i < len(arr); i++ {
  7082. repeat := false
  7083. for j := i + 1; j < len(arr); j++ {
  7084. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  7085. repeat = true
  7086. break
  7087. }
  7088. }
  7089. if !repeat {
  7090. newArr = append(newArr, arr[i])
  7091. }
  7092. }
  7093. return
  7094. }
  7095. //修改处方退库操作 参数传修改之前的处方数据
  7096. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  7097. if advice.ExecutionState == 1 {
  7098. //查询该病人该药品是否有库存记录
  7099. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  7100. if errcode == gorm.ErrRecordNotFound {
  7101. } else {
  7102. //退库
  7103. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7104. if advice.PrescribingNumberUnit == drug.MinUnit {
  7105. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  7106. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7107. //退库
  7108. warehouseInfo := models.DrugWarehouseInfo{
  7109. StockMinNumber: prescribingNumber,
  7110. }
  7111. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  7112. operation_time := time.Now().Unix()
  7113. creater := advice.AdviceDoctor
  7114. ctime := time.Now().Unix()
  7115. timeStr := time.Now().Format("2006-01-02")
  7116. timeArr := strings.Split(timeStr, "-")
  7117. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  7118. total = total + 1
  7119. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7120. cancelStock := models.DrugCancelStock{
  7121. OrderNumber: orderNumber,
  7122. OperaTime: operation_time,
  7123. OrgId: advice.UserOrgId,
  7124. Creater: creater,
  7125. Ctime: ctime,
  7126. Status: 1,
  7127. ReturnTime: advice.AdviceDate,
  7128. Dealer: info.Dealer,
  7129. Manufacturer: info.Manufacturer,
  7130. Type: 1,
  7131. }
  7132. service.AddSigleDrugCancelStock(&cancelStock)
  7133. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  7134. dealer, _ := service.GetDealerById(info.Dealer)
  7135. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  7136. cancelStockInfo := models.DrugCancelStockInfo{
  7137. OrderNumber: cancelInfo.OrderNumber,
  7138. CancelStockId: cancelInfo.ID,
  7139. DrugId: info.DrugId,
  7140. Count: info.Count,
  7141. Status: 1,
  7142. Ctime: ctime,
  7143. OrgId: advice.UserOrgId,
  7144. Type: 1,
  7145. Manufacturer: manufactureName.ManufacturerName,
  7146. Dealer: dealer.DealerName,
  7147. Total: 0,
  7148. RetailPrice: info.RetailPrice,
  7149. RetailTotalPrice: info.RetailTotalPrice,
  7150. Price: info.Price,
  7151. RegisterAccount: "",
  7152. Remark: info.Remark,
  7153. BatchNumber: info.BatchNumber,
  7154. MaxUnit: info.CountUnit,
  7155. ProductDate: info.ProductDate,
  7156. ExpiryDate: info.ExpiryDate,
  7157. BatchNumberId: info.WarehouseInfoId,
  7158. }
  7159. flow := models.DrugFlow{
  7160. WarehousingId: 0,
  7161. DrugId: info.DrugId,
  7162. Number: "",
  7163. BatchNumber: info.BatchNumber,
  7164. Count: info.Count,
  7165. UserOrgId: advice.UserOrgId,
  7166. PatientId: 0,
  7167. SystemTime: ctime,
  7168. ConsumableType: 4,
  7169. IsSys: 0,
  7170. WarehousingOrder: "",
  7171. WarehouseOutId: 0,
  7172. WarehouseOutOrderNumber: "",
  7173. IsEdit: 0,
  7174. CancelStockId: cancelStock.ID,
  7175. CancelOrderNumber: cancelStock.OrderNumber,
  7176. Manufacturer: info.Manufacturer,
  7177. Dealer: info.Dealer,
  7178. Creator: advice.UserOrgId,
  7179. UpdateCreator: 0,
  7180. Status: 1,
  7181. Ctime: time.Now().Unix(),
  7182. Mtime: 0,
  7183. Price: info.Price,
  7184. WarehousingDetailId: 0,
  7185. WarehouseOutDetailId: 0,
  7186. CancelOutDetailId: 0,
  7187. ExpireDate: info.ExpiryDate,
  7188. ProductDate: info.ProductDate,
  7189. MaxUnit: info.CountUnit,
  7190. MinUnit: "",
  7191. }
  7192. service.CreatedCancelStock(cancelStockInfo)
  7193. service.CreateDrugFlowOne(flow)
  7194. } else {
  7195. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  7196. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7197. if advice.PrescribingNumberUnit == drug.MaxUnit {
  7198. warehouseInfo := models.DrugWarehouseInfo{
  7199. StockMinNumber: prescribingNumber,
  7200. }
  7201. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  7202. }
  7203. operation_time := time.Now().Unix()
  7204. creater := advice.AdviceDoctor
  7205. ctime := time.Now().Unix()
  7206. timeStr := time.Now().Format("2006-01-02")
  7207. timeArr := strings.Split(timeStr, "-")
  7208. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  7209. total = total + 1
  7210. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7211. cancelStock := models.DrugCancelStock{
  7212. OrderNumber: orderNumber,
  7213. OperaTime: operation_time,
  7214. OrgId: advice.UserOrgId,
  7215. Creater: creater,
  7216. Ctime: ctime,
  7217. Status: 1,
  7218. ReturnTime: advice.AdviceDate,
  7219. Dealer: info.Dealer,
  7220. Manufacturer: info.Manufacturer,
  7221. Type: 1,
  7222. }
  7223. service.AddSigleDrugCancelStock(&cancelStock)
  7224. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  7225. dealer, _ := service.GetDealerById(info.Dealer)
  7226. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  7227. cancelStockInfo := models.DrugCancelStockInfo{
  7228. OrderNumber: cancelInfo.OrderNumber,
  7229. CancelStockId: cancelInfo.ID,
  7230. DrugId: info.DrugId,
  7231. Count: info.Count,
  7232. Status: 1,
  7233. Ctime: ctime,
  7234. OrgId: advice.UserOrgId,
  7235. Type: 1,
  7236. Manufacturer: manufactureName.ManufacturerName,
  7237. Dealer: dealer.DealerName,
  7238. Total: 0,
  7239. RetailPrice: info.RetailPrice,
  7240. RetailTotalPrice: info.RetailTotalPrice,
  7241. Price: info.Price,
  7242. RegisterAccount: "",
  7243. Remark: info.Remark,
  7244. BatchNumber: info.BatchNumber,
  7245. MaxUnit: info.CountUnit,
  7246. ProductDate: info.ProductDate,
  7247. ExpiryDate: info.ExpiryDate,
  7248. BatchNumberId: info.WarehouseInfoId,
  7249. }
  7250. flow := models.DrugFlow{
  7251. WarehousingId: 0,
  7252. DrugId: info.DrugId,
  7253. Number: "",
  7254. BatchNumber: info.BatchNumber,
  7255. Count: info.Count,
  7256. UserOrgId: advice.UserOrgId,
  7257. PatientId: 0,
  7258. SystemTime: ctime,
  7259. ConsumableType: 4,
  7260. IsSys: 0,
  7261. WarehousingOrder: "",
  7262. WarehouseOutId: 0,
  7263. WarehouseOutOrderNumber: "",
  7264. IsEdit: 0,
  7265. CancelStockId: cancelStock.ID,
  7266. CancelOrderNumber: cancelStock.OrderNumber,
  7267. Manufacturer: info.Manufacturer,
  7268. Dealer: info.Dealer,
  7269. Creator: advice.AdviceDoctor,
  7270. UpdateCreator: 0,
  7271. Status: 1,
  7272. Ctime: time.Now().Unix(),
  7273. Mtime: 0,
  7274. Price: info.Price,
  7275. WarehousingDetailId: 0,
  7276. WarehouseOutDetailId: 0,
  7277. CancelOutDetailId: 0,
  7278. ExpireDate: info.ExpiryDate,
  7279. ProductDate: info.ProductDate,
  7280. MaxUnit: info.CountUnit,
  7281. MinUnit: "",
  7282. }
  7283. service.CreatedCancelStock(cancelStockInfo)
  7284. service.CreateDrugFlowOne(flow)
  7285. }
  7286. }
  7287. }
  7288. return err
  7289. }
  7290. func (this *HisApiController) DeleteNCDS() {
  7291. id, _ := this.GetInt64("id", 0)
  7292. if id > 0 {
  7293. service.DeletePsnNCDSRecordById(id)
  7294. this.ServeSuccessJSON(map[string]interface{}{
  7295. "msg": "删除成功",
  7296. })
  7297. } else {
  7298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  7299. return
  7300. }
  7301. }
  7302. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  7303. id, _ := c.GetInt64("id")
  7304. advice, _ := service.GetHisDoctorAdviceInfo(id)
  7305. c.ServeSuccessJSON(map[string]interface{}{
  7306. "advice": advice,
  7307. })
  7308. return
  7309. }
  7310. func (c *HisApiController) GetHisMonthChargePatientList() {
  7311. record_date := c.GetString("record_date")
  7312. start_time := c.GetString("start_time")
  7313. end_time := c.GetString("end_time")
  7314. timeLayout := "2006-01-02"
  7315. loc, _ := time.LoadLocation("Local")
  7316. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7317. if err != nil {
  7318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7319. return
  7320. }
  7321. if err != nil {
  7322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7323. return
  7324. }
  7325. recordDateTime := theTime.Unix()
  7326. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7327. if err != nil {
  7328. }
  7329. startRecordDateTime := startTime.Unix()
  7330. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7331. if err != nil {
  7332. }
  7333. endRecordDateTime := endTime.Unix()
  7334. adminInfo := c.GetAdminUserInfo()
  7335. var tempMonthChargePatients []*service.MonthChargePatients
  7336. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  7337. for _, item := range tempPatients {
  7338. //过滤没有处方的
  7339. if len(item.HisPrescription) == 0 {
  7340. tempMonthChargePatients = append(tempMonthChargePatients, item)
  7341. }
  7342. }
  7343. c.ServeSuccessJSON(map[string]interface{}{
  7344. "list": tempMonthChargePatients,
  7345. })
  7346. }