his_api_controller.go 297KB

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