his_api_controller.go 301KB

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