his_api_controller.go 305KB

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