his_api_controller.go 297KB

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