his_api_controller.go 245KB

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