his_api_controller.go 375KB

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