his_api_controller.go 296KB

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